diff --git a/cli/compile.vsh b/cli/compile.vsh index c6f25b6f..8f58459a 100755 --- a/cli/compile.vsh +++ b/cli/compile.vsh @@ -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}') diff --git a/cli/hero.v b/cli/hero.v index c9b6ccfb..a231125c 100644 --- a/cli/hero.v +++ b/cli/hero.v @@ -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)! +// } diff --git a/lib/core/herocmds/docusaurus.v b/lib/core/herocmds/docusaurus.v index db663702..d5f6a17f 100644 --- a/lib/core/herocmds/docusaurus.v +++ b/lib/core/herocmds/docusaurus.v @@ -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{ diff --git a/lib/core/playbook/find.v b/lib/core/playbook/find.v index 79fb5add..7d97c372 100644 --- a/lib/core/playbook/find.v +++ b/lib/core/playbook/find.v @@ -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') } diff --git a/lib/core/playcmds/play_core.v b/lib/core/playcmds/play_core.v index fa5b2e26..89d0ed1d 100644 --- a/lib/core/playcmds/play_core.v +++ b/lib/core/playcmds/play_core.v @@ -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' { @@ -85,6 +90,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 } + } diff --git a/lib/data/paramsparser/params_get_kwargs.v b/lib/data/paramsparser/params_get_kwargs.v index 71513e15..59f79af1 100644 --- a/lib/data/paramsparser/params_get_kwargs.v +++ b/lib/data/paramsparser/params_get_kwargs.v @@ -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 } diff --git a/lib/develop/gittools/factory.v b/lib/develop/gittools/factory.v index e8fc7d56..a551b707 100644 --- a/lib/develop/gittools/factory.v +++ b/lib/develop/gittools/factory.v @@ -20,9 +20,16 @@ pub mut: // get_repo_path implements the GitUrlResolver interface pub fn get_repo_path(args GetRepoArgs) !string { - if os.exists(args.path) { - return args.path + 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 diff --git a/lib/develop/gittools/repos_get.v b/lib/develop/gittools/repos_get.v index 2d2f5860..e76b2979 100644 --- a/lib/develop/gittools/repos_get.v +++ b/lib/develop/gittools/repos_get.v @@ -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 diff --git a/lib/web/docusaurus/config.v b/lib/web/docusaurus/config.v index 10c749ff..aaf89e60 100644 --- a/lib/web/docusaurus/config.v +++ b/lib/web/docusaurus/config.v @@ -55,7 +55,7 @@ pub fn config() !DocusaurusConfig { template_update: args.template_update } if c.install { - install()! + install(c)! c.install=false } return c diff --git a/lib/web/docusaurus/dsite.v b/lib/web/docusaurus/dsite.v index f8a4a300..f195e181 100644 --- a/lib/web/docusaurus/dsite.v +++ b/lib/web/docusaurus/dsite.v @@ -16,6 +16,7 @@ pub mut: errors []SiteError config Configuration website sitemodule.Site + generated bool } pub fn (mut s DocSite) build() ! { diff --git a/lib/web/docusaurus/dsite_generate.v b/lib/web/docusaurus/dsite_generate.v index d039e632..e55b7da9 100644 --- a/lib/web/docusaurus/dsite_generate.v +++ b/lib/web/docusaurus/dsite_generate.v @@ -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}') diff --git a/lib/web/docusaurus/dsite_import.v b/lib/web/docusaurus/dsite_import.v index 2bc174d3..08ab4065 100644 --- a/lib/web/docusaurus/dsite_import.v +++ b/lib/web/docusaurus/dsite_import.v @@ -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 diff --git a/lib/web/docusaurus/factory.v b/lib/web/docusaurus/factory.v index ef95adae..bce5f576 100644 --- a/lib/web/docusaurus/factory.v +++ b/lib/web/docusaurus/factory.v @@ -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}' diff --git a/lib/web/docusaurus/install.v b/lib/web/docusaurus/install.v index dca2a76f..baca98dd 100644 --- a/lib/web/docusaurus/install.v +++ b/lib/web/docusaurus/install.v @@ -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,18 +25,17 @@ 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()! - osal.exec( - // always stay in the context of the build directory - cmd: ' - ${osal.profile_path_source_and()!} - export PATH=${c.path_build.path}/node_modules/.bin::${os.home_dir()}/.bun/bin/:\$PATH - cd ${c.path_build.path} - bun 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=${c.path_build.path}/node_modules/.bin::${os.home_dir()}/.bun/bin/:\$PATH + cd ${c.path_build.path} + bun install + ' + )! + } diff --git a/lib/web/docusaurus/play.v b/lib/web/docusaurus/play.v index d6ed70c0..8c721e45 100644 --- a/lib/web/docusaurus/play.v +++ b/lib/web/docusaurus/play.v @@ -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.') diff --git a/lib/web/site/play.v b/lib/web/site/play.v index dc7564fb..6c626dfa 100644 --- a/lib/web/site/play.v +++ b/lib/web/site/play.v @@ -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')