This commit is contained in:
2025-08-12 10:58:53 +02:00
parent d5753ee794
commit dd37eeaa29

View File

@@ -3,6 +3,8 @@ module herocmds
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.web.docusaurus
import freeflowuniverse.herolib.core.playcmds
import freeflowuniverse.herolib.develop.gittools
import os
import cli { Command, Flag }
import freeflowuniverse.herolib.core.playbook
@@ -106,13 +108,6 @@ pub fn cmd_docusaurus(mut cmdroot Command) Command {
description: 'Run your dev environment on local browser.'
})
// cmd_run.add_flag(Flag{
// flag: .bool
// required: false
// name: 'new'
// abbrev: 'n'
// description: 'create a new docusaurus site.'
// })
cmdroot.add_command(cmd_run)
return cmdroot
@@ -125,80 +120,41 @@ fn cmd_docusaurus_execute(cmd Command) ! {
mut builddevpublish := cmd.flags.get_bool('builddevpublish') or { false }
mut dev := cmd.flags.get_bool('dev') or { false }
mut reset := cmd.flags.get_bool('reset') or { false }
// (the earlier duplicate reset flag has been removed)
mut update := cmd.flags.get_bool('update') or { false }
// ---------- PATH LOGIC ----------
// Resolve the source directory that contains a cfg subdirectory.
mut path := cmd.flags.get_string('path') or { '' }
mut source_path := ''
if path != '' {
// user supplied a path
if !os.exists(path) || !os.is_dir(path) {
return error('Provided path "${path}" does not exist or is not a directory.')
}
cfg_subdir := os.join_path(path, 'cfg')
source_path = if os.exists(cfg_subdir) && os.is_dir(cfg_subdir) {
path
} else if path.ends_with('cfg') {
os.dir(path)
} else {
return error('Provided path "${path}" does not contain a cfg subdirectory.')
}
} else {
// default to current working directory
cwd := os.getwd()
cfg_dir := os.join_path(cwd, 'cfg')
if !os.exists(cfg_dir) || !os.is_dir(cfg_dir) {
return error('No path supplied and "./cfg" not found in the current directory.')
}
source_path = cwd
mut url := cmd.flags.get_string('url') or { '' }
if path=="" && url==""{
path = os.getwd()
}
console.print_header('Running Docusaurus for: ${source_path}')
// ---------- BUILD PLAYBOOK ----------
// Build a PlayBook from the source directory (it contains the HeroScript actions)
mut plbook := playbook.new(path: source_path)!
docusaurus_path :=gittools.path(
git_url:url
path: path
reset: reset
pull: update
)!
// If the user asked for a CLIlevel reset we inject a temporary define action
// so that the underlying factory_set receives `reset:true`.
if reset {
// prepend a temporary docusaurus.define action (this is safe because the playbook
// already contains the real definitions, the extra one will just be ignored later)
mut reset_action := playbook.Action{
actor: 'docusaurus'
name: 'define'
params: {
'reset': 'true'
}
done: false
}
// Insert at the front of the action list
plbook.actions.prepend(reset_action)
if ! os.exists(os.join_path(docusaurus_path, 'cfg')) {
error('Docusaurus configuration directory not found at: ${os.join_path(docusaurus_path, 'cfg')}')
}
// ---------- RUN DOCUSUROUS ----------
// This will:
// * read the generic `site.*` definitions,
// * create a Docusaurus factory (or reuse an existing one),
// * add the site to the factory via `dsite_add`.
docusaurus.play(mut plbook)!
console.print_header('Running Docusaurus for: ${docusaurus_path}')
// After `play` we should have exactly one site in the global map.
// Retrieve it if more than one exists we pick the one whose source path matches.
mut dsite_opt := docusaurus.dsite_get(plbook.ensure_once(filter: 'site.define')!.params.get('name')!) or {
// fallback: take the first entry
if docusaurus_sites.len == 0 {
return error('No Docusaurus site was created by the playbook.')
}
docusaurus_sites.values()[0]!
}
playcmds.run(
heroscript_path:docusaurus_path
reset: false
)!
// ---------- ACTIONS ----------
if buildpublish {
dsite_opt.build_publish()!
} else if builddevpublish {
dsite_opt.build()!
// } else if builddevpublish {
// dsite_opt.build()!
} else if dev {
dsite_opt.dev(
open: open