This commit is contained in:
2025-07-11 20:41:50 +03:00
parent 6a22412a72
commit 49bd1b84ff
15 changed files with 95 additions and 556 deletions

View File

@@ -29,7 +29,7 @@ pub fn (mut s DocSite) build() ! {
osal.exec( osal.exec(
cmd: ' cmd: '
cd ${s.path_build.path} cd ${s.path_build.path}
bash build.sh exit 1
' '
retry: 0 retry: 0
)! )!
@@ -40,7 +40,7 @@ pub fn (mut s DocSite) build_dev_publish() ! {
osal.exec( osal.exec(
cmd: ' cmd: '
cd ${s.path_build.path} cd ${s.path_build.path}
bash build_dev_publish.sh exit 1
' '
retry: 0 retry: 0
)! )!
@@ -51,7 +51,7 @@ pub fn (mut s DocSite) build_publish() ! {
osal.exec( osal.exec(
cmd: ' cmd: '
cd ${s.path_build.path} cd ${s.path_build.path}
bash build_publish.sh exit 1
' '
retry: 0 retry: 0
)! )!
@@ -72,6 +72,18 @@ pub fn (mut s DocSite) open(args DevArgs) ! {
pub fn (mut s DocSite) dev(args DevArgs) ! { pub fn (mut s DocSite) dev(args DevArgs) ! {
s.generate()! s.generate()!
osal.exec(
cmd: '
cd ${s.path_build.path}
bun run start -p ${args.port} -h ${args.host}
'
retry: 0
)!
}
pub fn (mut s DocSite) dev_watch(args DevArgs) ! {
s.generate()!
// Create screen session for docusaurus development server // Create screen session for docusaurus development server
mut screen_name := 'docusaurus' mut screen_name := 'docusaurus'
@@ -202,54 +214,3 @@ fn (mut site DocSite) check() ! {
check_item(item)! check_item(item)!
} }
} }
fn (mut site DocSite) template_install() ! {
mut gs := gittools.new()!
site.factory.template_install(template_update: false, install: true, delete: false)!
cfg := site.config
mut myhome := '\$\{HOME\}' // for usage in bash
profile_include := osal.profile_path_source()!.replace(os.home_dir(), myhome)
mydir := site.path_build.path.replace(os.home_dir(), myhome)
for item in ['src', 'static'] {
mut aa := site.path_src.dir_get(item) or { continue }
aa.copy(dest: '${site.factory.path_build.path}/${item}', delete: false)!
}
develop := $tmpl('templates/develop.sh')
build := $tmpl('templates/build.sh')
// build_dev_publish := $tmpl('templates/build_dev_publish.sh')
build_publish := $tmpl('templates/build_publish.sh')
mut develop_ := site.path_build.file_get_new('develop.sh')!
develop_.template_write(develop, true)!
develop_.chmod(0o700)!
mut build_ := site.path_build.file_get_new('build.sh')!
build_.template_write(build, true)!
build_.chmod(0o700)!
mut build_publish_ := site.path_build.file_get_new('build_publish.sh')!
build_publish_.template_write(build_publish, true)!
build_publish_.chmod(0o700)!
// TODO: implement
// mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
// build_dev_publish_.template_write(build_dev_publish, true)!
// build_dev_publish_.chmod(0o700)!
develop_templ := $tmpl('templates/develop_src.sh')
mut develop2_ := site.path_src.file_get_new('develop.sh')!
develop2_.template_write(develop_templ, true)!
develop2_.chmod(0o700)!
build_templ := $tmpl('templates/build_src.sh')
mut build2_ := site.path_src.file_get_new('build.sh')!
build2_.template_write(build_templ, true)!
build2_.chmod(0o700)!
}

View File

@@ -1,229 +0,0 @@
module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.web.bun
import freeflowuniverse.herolib.core.pathlib
import json
import os
import freeflowuniverse.herolib.ui.console
@[params]
struct TemplateInstallArgs {
template_update bool = true
install bool = true
delete bool = true
}
pub fn (mut site DocSite) generate() ! {
console.print_header(' site generate: ${site.name} on ${site.path_build.path}')
console.print_header(' site source on ${site.path_src.path}')
site.check()!
site.template_install()!
site.config = fix_configuration(site.config)!
generate_configuration(site.path_build.path, site.config)!
generate_docusaurus_config_ts(site.path_build.path, site.config)!
// Now copy all directories that exist in src to build
for item in ['src', 'static', 'cfg'] {
if os.exists('${site.path_src.path}/${item}') {
mut aa := site.path_src.dir_get(item)!
aa.copy(dest: '${site.path_build.path}/${item}')!
}
}
for item in ['docs'] {
if os.exists('${site.path_src.path}/${item}') {
mut aa := site.path_src.dir_get(item)!
aa.copy(dest: '${site.path_build.path}/${item}', delete: true)!
}
}
mut gs := gittools.new()!
// for item in site.config.import_sources {
// mypath := gs.get_path(
// pull: false
// reset: false
// url: item.url
// )!
// mut mypatho := pathlib.get(mypath)
// site.process_md(mut mypatho, item)!
// }
}
fn generate_configuration(path string, config Configuration) ! {
cfg_path := os.join_path(path, 'cfg')
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
main_file.write(json.encode(config.main))!
mut navbar_file := pathlib.get_file(path: '${cfg_path}/navbar.json', create: true)!
navbar_file.write(json.encode(config.navbar))!
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
footer_file.write(json.encode(config.footer))!
}
fn generate_docusaurus_config_ts(path string, config Configuration) ! {
mut config_file := pathlib.get_file(
path: os.join_path(path, 'docusaurus.config.ts')
create: true
)!
content := $tmpl('templates/docusaurus.config.ts')
config_file.write(content)!
}
fn (mut self DocusaurusFactory) template_install(args TemplateInstallArgs) ! {
mut gs := gittools.new()!
mut r := gs.get_repo(
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
pull: args.template_update
)!
mut template_path := r.patho()!
// always start from template first for static assets and source files
for item in ['src', 'static'] {
mut aa := template_path.dir_get(item)!
aa.copy(dest: '${self.path_build.path}/${item}', delete: args.delete)!
}
// Generate config files dynamically from config
self.generate_package_json()!
self.generate_tsconfig_json()!
self.generate_sidebars_ts()!
self.generate_gitignore()!
if args.install {
// install bun
mut installer := bun.get()!
installer.install()!
osal.exec(
cmd: '
${osal.profile_path_source_and()!}
export PATH=/tmp/docusaurus_build/node_modules/.bin:${os.home_dir()}/.bun/bin/:??PATH
cd ${self.path_build.path}
bun install
'
)!
}
}
fn (mut self DocusaurusFactory) generate_gitignore() ! {
mut gitignore := pathlib.get_file(
path: os.join_path(self.path_build.path, '.gitignore')
create: true
)!
content := $tmpl('templates/.gitignore')
gitignore.write(content)!
}
// Generate package.json based on the configuration
fn (mut self DocusaurusFactory) generate_package_json() ! {
// Build package.json content as a structured JSON string
mut name := 'docusaurus-site'
if self.config.main.name != '' {
name = self.config.main.name
} else if self.config.navbar.title != '' {
name = self.config.navbar.title.to_lower().replace(' ', '-')
}
// Load package.json from template
// The 'name' variable is defined in this function's scope and will be used by $tmpl.
content := $tmpl('templates/package.json')
mut package_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'package.json')
create: true
)!
package_file.write(content)!
}
// Generate tsconfig.json based on the configuration
fn (mut self DocusaurusFactory) generate_tsconfig_json() ! {
// Load tsconfig.json from template
content := $tmpl('templates/tsconfig.json')
mut tsconfig_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'tsconfig.json')
create: true
)!
tsconfig_file.write(content)!
}
// Generate sidebars.ts based on the configuration
fn (mut self DocusaurusFactory) generate_sidebars_ts() ! {
// Load sidebars.ts from template
content := $tmpl('templates/sidebars.ts')
mut sidebars_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'sidebars.ts')
create: true
)!
sidebars_file.write(content)!
}
// // Generate docusaurus.config.ts based on the configuration
// fn (mut self DocusaurusFactory) generate_docusaurus_config_ts() ! {
// // Use config values with fallbacks
// title := if self.config.main.title != '' { self.config.main.title } else { 'Docusaurus Site' }
// // Format navbar items from config
// mut navbar_items_list_temp := []string{}
// for item in self.config.navbar.items {
// navbar_items_list_temp << "{
// label: '${item.label}',
// href: '${item.href}',
// position: '${item.position}'
// }"
// }
// // Generate footer links if available
// mut footer_links_list_temp := []string{}
// for link in self.config.footer.links {
// mut items_temp := []string{}
// for item in link.items {
// mut item_str := '{'
// if item.label != '' {
// item_str += "label: '${item.label}', "
// }
// if item.href != '' {
// item_str += "href: '${item.href}'"
// } else if item.to != '' {
// item_str += "to: '${item.to}'"
// } else {
// item_str += "to: '/docs'" // Default link
// }
// item_str += '}'
// items_temp << item_str
// }
// footer_links_list_temp << "{
// title: '${link.title}',
// items: [
// ${items_temp.join(',\n ')}
// ]
// }"
// }
// // Year for copyright
// year := time.now().year.str()
// // Copyright string (variable `copyright` must be in scope for the template)
// // `title` is defined at line 181, `year` is defined above.
// copyright := if self.config.main.copyright != '' {
// self.config.main.copyright
// } else {
// 'Copyright © ${year} ${title}'
// }
// // Load docusaurus.config.ts from template
// // All required variables (title, tagline, favicon, url, base_url,
// // projectName, navbarTitle, navbarItems, footerLinks, copyright)
// // are in scope for $tmpl.
// content := $tmpl('templates/docusaurus.config.ts')
// mut config_file := pathlib.get_file(
// path: os.join_path(self.path_build.path, 'docusaurus.config.ts')
// create: true
// )!
// config_file.write(content)!
// }

View File

@@ -0,0 +1,48 @@
module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.core.pathlib
import json
import os
import freeflowuniverse.herolib.ui.console
@[params]
struct TemplateInstallArgs {
template_update bool = true
install bool = true
delete bool = true
}
pub fn (mut site DocSite) generate() ! {
console.print_header(' site generate: ${site.name} on ${site.path_build.path}')
console.print_header(' site source on ${site.path_src.path}')
site.check()!
site.template_install()!
site.config = fix_configuration(site.config)!
cfg_path := os.join_path(site.path_build.path, 'cfg')
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
main_file.write(json.encode(site.config.main))!
mut navbar_file := pathlib.get_file(path: '${cfg_path}/navbar.json', create: true)!
navbar_file.write(json.encode(site.config.navbar))!
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
footer_file.write(json.encode(site.config.footer))!
mut aa := site.path_src.dir_get("docs")!
aa.copy(dest: '${site.path_build.path}/docs', delete: true)!
// mut gs := gittools.new()!
// for item in site.config.import_sources {
// mypath := gs.get_path(
// pull: false
// reset: false
// url: item.url
// )!
// mut mypatho := pathlib.get(mypath)
// site.process_md(mut mypatho, item)!
// }
}

View File

@@ -0,0 +1,32 @@
module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.web.bun
fn (mut self DocusaurusFactory) template_install(args TemplateInstallArgs) ! {
mut gs := gittools.new()!
mut r := gs.get_repo(
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
pull: args.template_update
)!
mut template_path := r.patho()!
template_path.copy(dest: '${self.path_build.path}/template/', delete: args.delete)!
if args.install {
// install bun
mut installer := bun.get()!
installer.install()!
osal.exec(
//always stay in the context of the build directory
cmd: '
${osal.profile_path_source_and()!}
export PATH=${self.path_build}/node_modules/.bin::??{HOME}/.bun/bin/:??PATH
cd ${self.path_build.path}
bun install
'
)!
}
}

View File

@@ -1,21 +0,0 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
.pnp
.pnp.js
# build output
build
.docusaurus
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -1,22 +0,0 @@
#!/bin/bash
set -ex
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd "${mydir}"
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
rm -rf ${site.path_build.path}/build/
${profile_include}
bun docusaurus build
mkdir -p ${site.args.publish_path.trim_right("/")}
echo SYNC TO ${site.args.publish_path.trim_right("/")}
rsync -rv --delete ${site.path_build.path}/build/ ${site.args.publish_path.trim_right("/")}/

View File

@@ -1,22 +0,0 @@
#!/bin/bash
set -ex
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd "${mydir}"
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
rm -rf ${site.path_build.path}/build/
${profile_include}
bun docusaurus build
@for dest in cfg.main.build_dest
rsync -rv --delete ${site.path_build.path}/build/ ${dest.trim_right("/")}/
@end

View File

@@ -1,6 +0,0 @@
#!/bin/bash -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
hero docusaurus -bp

View File

@@ -1,16 +0,0 @@
#!/bin/bash
set -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd "${mydir}"
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
${profile_include}
bun run start -p 3100

View File

@@ -1,6 +0,0 @@
#!/bin/bash -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
hero docusaurus -d

View File

@@ -1,105 +0,0 @@
import { themes as prismThemes } from 'prism-react-renderer';
import type { Configuration } from '@@docusaurus/types';
import type * as Preset from '@@docusaurus/preset-classic';
const config: Configuration = {
title: '@{config.main.title}',
tagline: '@{config.main.tagline}',
favicon: '@{config.main.favicon}',
// Set the production url of your site here
url: '@{config.main.url}',
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: '@{config.main.base_url}',
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: 'freeflowuniverse', // Usually your GitHub org/user name.
projectName: '@{config.main.name}', // Usually your repo name.
onBrokenLinks: 'warn',
onBrokenMarkdownLinks: 'warn',
// Enable for i18n
// i18n: {
// defaultLocale: 'en',
// locales: ['en'],
// },
themes: ["@@docusaurus/theme-mermaid"],
markdown: {
mermaid: true,
},
presets: [
[
'classic',
{
docs: {
sidebarPath: './sidebars.ts',
},
theme: {
customCss: './src/css/custom.css',
},
} satisfies Preset.Options,
],
],
themeConfig: {
// Replace with your project's social card
image: 'img/docusaurus-social-card.jpg',
colorMode: {
defaultMode: 'dark',
},
navbar: {
title: '@{config.navbar.title}',
logo: {
alt: '@{config.navbar.logo.alt}',
src: '@{config.navbar.logo.src}',
srcDark: '@{config.navbar.logo.src_dark}',
},
items: [
@for item in config.navbar.items
{
label: '@{item.label}',
href: '@{item.href}',
position: '@{item.position}'
},
@end
],
},
footer: {
style: '@{config.footer.style}',
links: [
@for link_group in config.footer.links
{
title: '@{link_group.title}',
items: [
@for item in link_group.items
{
label: '@{item.label}',
@if item.href != ''
href: '@{item.href}'
@else if item.to != ''
to: '@{item.to}'
@else
to: '/docs'
@end
},
@end
]
},
@end
],
copyright: '@{config.main.copyright}',
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
},
} satisfies Preset.ThemeConfig,
};
export default config;

View File

@@ -1,49 +0,0 @@
{
"name": "@{name}",
"version": "0.0.1",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
},
"dependencies": {
"@@docusaurus/core": "^3.1.0",
"@@docusaurus/preset-classic": "^3.1.0",
"@@docusaurus/theme-mermaid": "^3.1.0",
"@@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"echarts": "^5.4.3",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@@docusaurus/module-type-aliases": "^3.1.0",
"@@docusaurus/tsconfig": "^3.1.0",
"@@docusaurus/types": "^3.1.0",
"typescript": "^5.2.2"
},
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"engines": {
"node": ">=18.0"
}
}

View File

@@ -1,18 +0,0 @@
import type {SidebarsConfig} from '@@docusaurus/plugin-content-docs';
/**
* Creating a sidebar enables you to:
- create an ordered group of docs
- render a sidebar for each doc of that group
- provide next/previous navigation
The sidebars can be generated from the filesystem, or explicitly defined here.
Create as many sidebars as you want.
*/
const sidebars: SidebarsConfig = {
// By default, Docusaurus generates a sidebar from the docs folder structure
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
};
export default sidebars;

View File

@@ -1,8 +0,0 @@
{
"extends": "@@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"resolveJsonModule": true
},
"include": ["src/**/*", "docusaurus.config.ts"]
}