This commit is contained in:
2025-08-13 08:49:44 +02:00
parent aab018925d
commit 1f9bc11a2e
16 changed files with 100 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -n -cg -w -parallel-cc -enable-globals run
#!/usr/bin/env -S v -n -g -cg -w -parallel-cc -showcc -enable-globals run
// #!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import os
@@ -43,9 +43,9 @@ if os.user_os() == 'macos' {
// Set compilation command based on OS and mode
compile_cmd := if os.user_os() == 'macos' {
if prod_mode {
'v -enable-globals -w -n -prod hero.v'
'v -enable-globals -g -w -n -prod hero.v'
} else {
'v -w -cg -gc none -cc tcc -d use_openssl -enable-globals hero.v'
'v -n -g -w -cg -gc none -cc tcc -d use_openssl -enable-globals hero.v'
}
} else {
if prod_mode {
@@ -56,6 +56,7 @@ compile_cmd := if os.user_os() == 'macos' {
}
println('Building in ${if prod_mode { 'production' } else { 'debug' }} mode...')
// eprintln(compile_cmd)
if os.system(compile_cmd) != 0 {
panic('Failed to compile hero.v with command: ${compile_cmd}')

View File

@@ -3,8 +3,6 @@ module main
import os
import cli { Command }
import freeflowuniverse.herolib.core.herocmds
// import freeflowuniverse.herolib.hero.cmds
// import freeflowuniverse.herolib.hero.publishing
import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.ui
@@ -83,9 +81,14 @@ fn do() ! {
base.redis_install()!
// herocmds.cmd_bootstrap(mut cmd)
herocmds.cmd_run(mut cmd)
herocmds.cmd_git(mut cmd)
herocmds.cmd_generator(mut cmd)
herocmds.cmd_docusaurus(mut cmd)
// herocmds.cmd_bootstrap(mut cmd)
// herocmds.cmd_init(mut cmd)
// herocmds.cmd_imagedownsize(mut cmd)
// herocmds.cmd_biztools(mut cmd)
@@ -103,8 +106,6 @@ fn do() ! {
// herocmds.cmd_caddy(mut cmd)
// herocmds.cmd_zola(mut cmd)
// herocmds.cmd_juggler(mut cmd)
herocmds.cmd_generator(mut cmd)
herocmds.cmd_docusaurus(mut cmd)
// herocmds.cmd_starlight(mut cmd)
// herocmds.cmd_docsorter(mut cmd)
// cmd.add_command(publishing.cmd_publisher(pre_func))
@@ -113,9 +114,15 @@ fn do() ! {
}
fn main() {
do() or { panic(err) }
do() or {
$dbg;
eprintln('Error: ${err}')
print_backtrace()
exit(1)
}
}
fn pre_func(cmd Command) ! {
herocmds.plbook_run(cmd)!
}
// fn pre_func(cmd Command) ! {
// herocmds.plbook_run(cmd)!
// }

View File

@@ -1,13 +1,11 @@
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
pub fn cmd_docusaurus(mut cmdroot Command) Command {
mut cmd_run := Command{

View File

@@ -118,6 +118,9 @@ pub fn (mut plbook PlayBook) exists_once(args FindArgs) bool {
pub fn (mut plbook PlayBook) max_once(args FindArgs) !bool {
mut res := plbook.find(args) or { [] }
if res.len > 1 {
$if debug {
print_backtrace()
}
return error("found more than one action: '${args.filter}'")
}
return res.len == 1
@@ -143,6 +146,9 @@ pub fn (mut plbook PlayBook) get(args FindArgs) !&Action {
if res.len == 0 {
return error("can't find action: '${args.filter}'")
} else if res.len > 1 {
$if debug {
print_backtrace()
}
return error("found more than one action: '${args.filter}'")
}
return res[0] or { panic('bug') }

View File

@@ -17,7 +17,10 @@ fn play_core(mut plbook PlayBook) ! {
// Track included paths to prevent infinite recursion
mut included_paths := map[string]bool{}
for mut action_ in plbook.find(filter: 'play.*')! {
if action_.name == 'include' {
mut action := *action_
mut toreplace := action.params.get_default('replace', '')!
@@ -25,7 +28,7 @@ fn play_core(mut plbook PlayBook) ! {
if playrunpath.len == 0 {
action.name = 'pull'
playrunpath = gittools.get_repo_path(
path: action.params.get_default('path', '')!
path: playrunpath
git_url: action.params.get_default('git_url', '')!
git_reset: action.params.get_default_false('git_reset')
git_pull: action.params.get_default_false('git_pull')
@@ -60,6 +63,7 @@ fn play_core(mut plbook PlayBook) ! {
}
}
// ----------------------------------------------------------------
// 2. Session environment handling
// ----------------------------------------------------------------
@@ -68,6 +72,7 @@ fn play_core(mut plbook PlayBook) ! {
// !!session.env_set / env_set_once
for mut action in plbook.find(filter: 'session.')! {
mut p := action.params
match action.name {
'env_set' {
@@ -86,6 +91,7 @@ fn play_core(mut plbook PlayBook) ! {
action.done = true
}
// ----------------------------------------------------------------
// 3. Template replacement in action parameters
// ----------------------------------------------------------------
@@ -136,4 +142,5 @@ fn play_core(mut plbook PlayBook) ! {
session.save()!
action.done = true
}
}

View File

@@ -12,7 +12,9 @@ pub fn (params &Params) get(key_ string) !string {
return p.value.trim(' ')
}
}
// print_backtrace()
$if debug {
print_backtrace()
}
return error('Did not find key:${key} in ${params}')
}
@@ -156,7 +158,10 @@ pub fn (params &Params) get_int_default(key string, defval int) !int {
}
pub fn (params &Params) get_default_true(key string) bool {
mut r := params.get(key) or { '' }
mut r := ""
if params.exists(key) {
r = params.get(key) or { panic("bug") }
}
r = texttools.name_fix_no_underscore(r)
if r == '' || r == '1' || r == 'true' || r == 'y' || r == 'yes' {
return true
@@ -165,8 +170,10 @@ pub fn (params &Params) get_default_true(key string) bool {
}
pub fn (params &Params) get_default_false(key string) bool {
mut r := params.get(key) or { '' }
r = texttools.name_fix_no_underscore(r)
mut r := ""
if params.exists(key) {
r = params.get(key) or { panic("bug") }
} r = texttools.name_fix_no_underscore(r)
if r == '' || r == '0' || r == 'false' || r == 'n' || r == 'no' {
return false
}

View File

@@ -20,9 +20,16 @@ pub mut:
// get_repo_path implements the GitUrlResolver interface
pub fn get_repo_path(args GetRepoArgs) !string {
if args.path!=""{
if os.exists(args.path) {
return args.path
}else{
if args.git_url == "" {
return error("can't resolve git repo path without url or existing path, ${args.path} does not exist.")
}
}
}
mut gs := get(coderoot:args.git_root)!
mut repo := gs.get_repo(
url: args.git_url

View File

@@ -116,8 +116,11 @@ pub fn (mut gitstructure GitStructure) get_repo(args_ ReposGetArgs) !&GitRepo {
}
if repositories.len > 1 {
repos := repositories.map('- ${it.account}.${it.name}').join_lines()
return error('Found more than one repository for \n${args}\n${repos}')
// repos := repositories.map('- ${it.account}.${it.name}').join_lines()
$if debug {
print_backtrace()
}
return error('Found more than one repository for \n${args}')
}
// the pull & reset was not used, now re-inserted

View File

@@ -55,7 +55,7 @@ pub fn config() !DocusaurusConfig {
template_update: args.template_update
}
if c.install {
install()!
install(c)!
c.install=false
}
return c

View File

@@ -16,6 +16,7 @@ pub mut:
errors []SiteError
config Configuration
website sitemodule.Site
generated bool
}
pub fn (mut s DocSite) build() ! {

View File

@@ -8,6 +8,9 @@ import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.ui.console
pub fn (mut docsite DocSite) generate() ! {
if docsite.generated {
return
}
mut c := config()!
console.print_header(' docsite generate: ${docsite.name} on ${c.path_build.path}')

View File

@@ -24,6 +24,10 @@ pub fn (mut docsite DocSite) import() ! {
c:=config()!
if importparams.path == "" && importparams.url != "" {
return error("in import for docusaurus need to specify url or path")
}
// Use gittools to get path of what we want to import
import_path := gittools.get_repo_path(
git_pull: c.reset

View File

@@ -13,7 +13,6 @@ pub mut:
pub fn dsite_define(sitename string) ! {
console.print_header('Add Docusaurus Site: ${sitename}')
mut c := config()!
path_publish := '${c.path_publish.path}/${sitename}'

View File

@@ -6,16 +6,15 @@ import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.installers.web.bun
fn install() ! {
fn install(c DocusaurusConfig) ! {
mut gs := gittools.new()!
mut c:=config()!
if c.reset {
osal.rm(c.path_build.path)!
osal.dir_ensure(c.path_build.path)!
}
template_path := gs.get_path(
pull: c.template_update
reset: c.reset
@@ -26,7 +25,6 @@ fn install() ! {
template_path0.copy(dest: c.path_build.path, delete: false)! //the dir has already been deleted so no point to delete again
if c.install { //config.install is set in factory if there is missing bun
// install bun
mut installer := bun.get()!
installer.install()!
@@ -39,5 +37,5 @@ fn install() ! {
bun install
'
)!
}
}

View File

@@ -22,13 +22,17 @@ pub fn play(mut plbook PlayBook) ! {
)!
site_name := param_define.get('name') or {
return error('In docusaurus.add, param "name" is required.')
return error('In docusaurus.define, param "name" is required.')
}
dsite_define(site_name)!
action_define.done = true
mut dsite := dsite_get(site_name)!
dsite.generate()!
mut actions_dev := plbook.find(filter: 'docusaurus.dev')!
if actions_dev.len > 1 {
return error('Multiple "docusaurus.dev" actions found. Only one is allowed.')

View File

@@ -1,5 +1,5 @@
module site
import os
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.core.texttools
import time
@@ -70,10 +70,18 @@ fn play_import(mut plbook PlayBook, mut config SiteConfig) ! {
}
}
}
mut importpath := p.get_default('path', '')!
if importpath != '' {
if ! importpath.starts_with('/') {
importpath = os.abs_path('${plbook.path}/${importpath}')
}
}
mut import_ := ImportItem{
name: p.get_default('name', '')!
url: p.get('url')!
path: p.get_default('path', '')!
url: p.get_default('url', '')!
path: importpath
dest: p.get_default('dest', '')!
replace: replace_map
visible: p.get_default_false('visible')