...
This commit is contained in:
@@ -3,6 +3,8 @@ module herocmds
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import freeflowuniverse.herolib.web.docusaurus
|
import freeflowuniverse.herolib.web.docusaurus
|
||||||
|
import freeflowuniverse.herolib.core.playcmds
|
||||||
|
import freeflowuniverse.herolib.develop.gittools
|
||||||
import os
|
import os
|
||||||
import cli { Command, Flag }
|
import cli { Command, Flag }
|
||||||
import freeflowuniverse.herolib.core.playbook
|
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.'
|
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)
|
cmdroot.add_command(cmd_run)
|
||||||
return cmdroot
|
return cmdroot
|
||||||
@@ -125,80 +120,41 @@ fn cmd_docusaurus_execute(cmd Command) ! {
|
|||||||
mut builddevpublish := cmd.flags.get_bool('builddevpublish') or { false }
|
mut builddevpublish := cmd.flags.get_bool('builddevpublish') or { false }
|
||||||
mut dev := cmd.flags.get_bool('dev') or { false }
|
mut dev := cmd.flags.get_bool('dev') or { false }
|
||||||
mut reset := cmd.flags.get_bool('reset') 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 ----------
|
// ---------- PATH LOGIC ----------
|
||||||
// Resolve the source directory that contains a “cfg” sub‑directory.
|
// Resolve the source directory that contains a “cfg” sub‑directory.
|
||||||
mut path := cmd.flags.get_string('path') or { '' }
|
mut path := cmd.flags.get_string('path') or { '' }
|
||||||
mut source_path := ''
|
mut url := cmd.flags.get_string('url') or { '' }
|
||||||
if path != '' {
|
|
||||||
// user supplied a path
|
if path=="" && url==""{
|
||||||
if !os.exists(path) || !os.is_dir(path) {
|
path = os.getwd()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('Running Docusaurus for: ${source_path}')
|
|
||||||
|
|
||||||
// ---------- BUILD PLAYBOOK ----------
|
docusaurus_path :=gittools.path(
|
||||||
// Build a PlayBook from the source directory (it contains the HeroScript actions)
|
git_url:url
|
||||||
mut plbook := playbook.new(path: source_path)!
|
path: path
|
||||||
|
reset: reset
|
||||||
|
pull: update
|
||||||
|
)!
|
||||||
|
|
||||||
// If the user asked for a CLI‑level reset we inject a temporary define action
|
if ! os.exists(os.join_path(docusaurus_path, 'cfg')) {
|
||||||
// so that the underlying factory_set receives `reset:true`.
|
error('Docusaurus configuration directory not found at: ${os.join_path(docusaurus_path, 'cfg')}')
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- RUN DOCUSUROUS ----------
|
console.print_header('Running Docusaurus for: ${docusaurus_path}')
|
||||||
// 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)!
|
|
||||||
|
|
||||||
// After `play` we should have exactly one site in the global map.
|
playcmds.run(
|
||||||
// Retrieve it – if more than one exists we pick the one whose source path matches.
|
heroscript_path:docusaurus_path
|
||||||
mut dsite_opt := docusaurus.dsite_get(plbook.ensure_once(filter: 'site.define')!.params.get('name')!) or {
|
reset: false
|
||||||
// fallback: take the first entry
|
)!
|
||||||
if docusaurus_sites.len == 0 {
|
|
||||||
return error('No Docusaurus site was created by the playbook.')
|
|
||||||
}
|
|
||||||
docusaurus_sites.values()[0]!
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- ACTIONS ----------
|
// ---------- ACTIONS ----------
|
||||||
if buildpublish {
|
if buildpublish {
|
||||||
dsite_opt.build_publish()!
|
dsite_opt.build_publish()!
|
||||||
} else if builddevpublish {
|
// } else if builddevpublish {
|
||||||
dsite_opt.build()!
|
// dsite_opt.build()!
|
||||||
} else if dev {
|
} else if dev {
|
||||||
dsite_opt.dev(
|
dsite_opt.dev(
|
||||||
open: open
|
open: open
|
||||||
|
|||||||
Reference in New Issue
Block a user