...
This commit is contained in:
@@ -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
|
// #!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||||
import os
|
import os
|
||||||
@@ -43,9 +43,9 @@ if os.user_os() == 'macos' {
|
|||||||
// Set compilation command based on OS and mode
|
// Set compilation command based on OS and mode
|
||||||
compile_cmd := if os.user_os() == 'macos' {
|
compile_cmd := if os.user_os() == 'macos' {
|
||||||
if prod_mode {
|
if prod_mode {
|
||||||
'v -enable-globals -w -n -prod hero.v'
|
'v -enable-globals -g -w -n -prod hero.v'
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
if prod_mode {
|
if prod_mode {
|
||||||
@@ -56,6 +56,7 @@ compile_cmd := if os.user_os() == 'macos' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println('Building in ${if prod_mode { 'production' } else { 'debug' }} mode...')
|
println('Building in ${if prod_mode { 'production' } else { 'debug' }} mode...')
|
||||||
|
// eprintln(compile_cmd)
|
||||||
|
|
||||||
if os.system(compile_cmd) != 0 {
|
if os.system(compile_cmd) != 0 {
|
||||||
panic('Failed to compile hero.v with command: ${compile_cmd}')
|
panic('Failed to compile hero.v with command: ${compile_cmd}')
|
||||||
|
|||||||
25
cli/hero.v
25
cli/hero.v
@@ -3,8 +3,6 @@ module main
|
|||||||
import os
|
import os
|
||||||
import cli { Command }
|
import cli { Command }
|
||||||
import freeflowuniverse.herolib.core.herocmds
|
import freeflowuniverse.herolib.core.herocmds
|
||||||
// import freeflowuniverse.herolib.hero.cmds
|
|
||||||
// import freeflowuniverse.herolib.hero.publishing
|
|
||||||
import freeflowuniverse.herolib.installers.base
|
import freeflowuniverse.herolib.installers.base
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.ui
|
import freeflowuniverse.herolib.ui
|
||||||
@@ -83,9 +81,14 @@ fn do() ! {
|
|||||||
|
|
||||||
base.redis_install()!
|
base.redis_install()!
|
||||||
|
|
||||||
// herocmds.cmd_bootstrap(mut cmd)
|
|
||||||
|
|
||||||
herocmds.cmd_run(mut cmd)
|
herocmds.cmd_run(mut cmd)
|
||||||
herocmds.cmd_git(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_init(mut cmd)
|
||||||
// herocmds.cmd_imagedownsize(mut cmd)
|
// herocmds.cmd_imagedownsize(mut cmd)
|
||||||
// herocmds.cmd_biztools(mut cmd)
|
// herocmds.cmd_biztools(mut cmd)
|
||||||
@@ -103,8 +106,6 @@ fn do() ! {
|
|||||||
// herocmds.cmd_caddy(mut cmd)
|
// herocmds.cmd_caddy(mut cmd)
|
||||||
// herocmds.cmd_zola(mut cmd)
|
// herocmds.cmd_zola(mut cmd)
|
||||||
// herocmds.cmd_juggler(mut cmd)
|
// herocmds.cmd_juggler(mut cmd)
|
||||||
herocmds.cmd_generator(mut cmd)
|
|
||||||
herocmds.cmd_docusaurus(mut cmd)
|
|
||||||
// herocmds.cmd_starlight(mut cmd)
|
// herocmds.cmd_starlight(mut cmd)
|
||||||
// herocmds.cmd_docsorter(mut cmd)
|
// herocmds.cmd_docsorter(mut cmd)
|
||||||
// cmd.add_command(publishing.cmd_publisher(pre_func))
|
// cmd.add_command(publishing.cmd_publisher(pre_func))
|
||||||
@@ -113,9 +114,15 @@ fn do() ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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)!
|
||||||
|
// }
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
module herocmds
|
module herocmds
|
||||||
|
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.core.texttools
|
|
||||||
import freeflowuniverse.herolib.web.docusaurus
|
import freeflowuniverse.herolib.web.docusaurus
|
||||||
import freeflowuniverse.herolib.core.playcmds
|
import freeflowuniverse.herolib.core.playcmds
|
||||||
import freeflowuniverse.herolib.develop.gittools
|
import freeflowuniverse.herolib.develop.gittools
|
||||||
import os
|
import os
|
||||||
import cli { Command, Flag }
|
import cli { Command, Flag }
|
||||||
import freeflowuniverse.herolib.core.playbook
|
|
||||||
|
|
||||||
pub fn cmd_docusaurus(mut cmdroot Command) Command {
|
pub fn cmd_docusaurus(mut cmdroot Command) Command {
|
||||||
mut cmd_run := Command{
|
mut cmd_run := Command{
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ pub fn (mut plbook PlayBook) exists_once(args FindArgs) bool {
|
|||||||
pub fn (mut plbook PlayBook) max_once(args FindArgs) !bool {
|
pub fn (mut plbook PlayBook) max_once(args FindArgs) !bool {
|
||||||
mut res := plbook.find(args) or { [] }
|
mut res := plbook.find(args) or { [] }
|
||||||
if res.len > 1 {
|
if res.len > 1 {
|
||||||
|
$if debug {
|
||||||
|
print_backtrace()
|
||||||
|
}
|
||||||
return error("found more than one action: '${args.filter}'")
|
return error("found more than one action: '${args.filter}'")
|
||||||
}
|
}
|
||||||
return res.len == 1
|
return res.len == 1
|
||||||
@@ -143,6 +146,9 @@ pub fn (mut plbook PlayBook) get(args FindArgs) !&Action {
|
|||||||
if res.len == 0 {
|
if res.len == 0 {
|
||||||
return error("can't find action: '${args.filter}'")
|
return error("can't find action: '${args.filter}'")
|
||||||
} else if res.len > 1 {
|
} else if res.len > 1 {
|
||||||
|
$if debug {
|
||||||
|
print_backtrace()
|
||||||
|
}
|
||||||
return error("found more than one action: '${args.filter}'")
|
return error("found more than one action: '${args.filter}'")
|
||||||
}
|
}
|
||||||
return res[0] or { panic('bug') }
|
return res[0] or { panic('bug') }
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
// Track included paths to prevent infinite recursion
|
// Track included paths to prevent infinite recursion
|
||||||
mut included_paths := map[string]bool{}
|
mut included_paths := map[string]bool{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for mut action_ in plbook.find(filter: 'play.*')! {
|
for mut action_ in plbook.find(filter: 'play.*')! {
|
||||||
|
|
||||||
if action_.name == 'include' {
|
if action_.name == 'include' {
|
||||||
mut action := *action_
|
mut action := *action_
|
||||||
mut toreplace := action.params.get_default('replace', '')!
|
mut toreplace := action.params.get_default('replace', '')!
|
||||||
@@ -25,7 +28,7 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
if playrunpath.len == 0 {
|
if playrunpath.len == 0 {
|
||||||
action.name = 'pull'
|
action.name = 'pull'
|
||||||
playrunpath = gittools.get_repo_path(
|
playrunpath = gittools.get_repo_path(
|
||||||
path: action.params.get_default('path', '')!
|
path: playrunpath
|
||||||
git_url: action.params.get_default('git_url', '')!
|
git_url: action.params.get_default('git_url', '')!
|
||||||
git_reset: action.params.get_default_false('git_reset')
|
git_reset: action.params.get_default_false('git_reset')
|
||||||
git_pull: action.params.get_default_false('git_pull')
|
git_pull: action.params.get_default_false('git_pull')
|
||||||
@@ -60,6 +63,7 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// 2. Session environment handling
|
// 2. Session environment handling
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
@@ -68,6 +72,7 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
|
|
||||||
// !!session.env_set / env_set_once
|
// !!session.env_set / env_set_once
|
||||||
for mut action in plbook.find(filter: 'session.')! {
|
for mut action in plbook.find(filter: 'session.')! {
|
||||||
|
|
||||||
mut p := action.params
|
mut p := action.params
|
||||||
match action.name {
|
match action.name {
|
||||||
'env_set' {
|
'env_set' {
|
||||||
@@ -85,6 +90,7 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
action.done = true
|
action.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// 3. Template replacement in action parameters
|
// 3. Template replacement in action parameters
|
||||||
@@ -136,4 +142,5 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
session.save()!
|
session.save()!
|
||||||
action.done = true
|
action.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ pub fn (params &Params) get(key_ string) !string {
|
|||||||
return p.value.trim(' ')
|
return p.value.trim(' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// print_backtrace()
|
$if debug {
|
||||||
|
print_backtrace()
|
||||||
|
}
|
||||||
return error('Did not find key:${key} in ${params}')
|
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 {
|
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)
|
r = texttools.name_fix_no_underscore(r)
|
||||||
if r == '' || r == '1' || r == 'true' || r == 'y' || r == 'yes' {
|
if r == '' || r == '1' || r == 'true' || r == 'y' || r == 'yes' {
|
||||||
return true
|
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 {
|
pub fn (params &Params) get_default_false(key string) bool {
|
||||||
mut r := params.get(key) or { '' }
|
mut r := ""
|
||||||
r = texttools.name_fix_no_underscore(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' {
|
if r == '' || r == '0' || r == 'false' || r == 'n' || r == 'no' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,16 @@ pub mut:
|
|||||||
|
|
||||||
// get_repo_path implements the GitUrlResolver interface
|
// get_repo_path implements the GitUrlResolver interface
|
||||||
pub fn get_repo_path(args GetRepoArgs) !string {
|
pub fn get_repo_path(args GetRepoArgs) !string {
|
||||||
if os.exists(args.path) {
|
if args.path!=""{
|
||||||
return 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 gs := get(coderoot:args.git_root)!
|
||||||
mut repo := gs.get_repo(
|
mut repo := gs.get_repo(
|
||||||
url: args.git_url
|
url: args.git_url
|
||||||
|
|||||||
@@ -116,8 +116,11 @@ pub fn (mut gitstructure GitStructure) get_repo(args_ ReposGetArgs) !&GitRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if repositories.len > 1 {
|
if repositories.len > 1 {
|
||||||
repos := repositories.map('- ${it.account}.${it.name}').join_lines()
|
// repos := repositories.map('- ${it.account}.${it.name}').join_lines()
|
||||||
return error('Found more than one repository for \n${args}\n${repos}')
|
$if debug {
|
||||||
|
print_backtrace()
|
||||||
|
}
|
||||||
|
return error('Found more than one repository for \n${args}')
|
||||||
}
|
}
|
||||||
|
|
||||||
// the pull & reset was not used, now re-inserted
|
// the pull & reset was not used, now re-inserted
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ pub fn config() !DocusaurusConfig {
|
|||||||
template_update: args.template_update
|
template_update: args.template_update
|
||||||
}
|
}
|
||||||
if c.install {
|
if c.install {
|
||||||
install()!
|
install(c)!
|
||||||
c.install=false
|
c.install=false
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub mut:
|
|||||||
errors []SiteError
|
errors []SiteError
|
||||||
config Configuration
|
config Configuration
|
||||||
website sitemodule.Site
|
website sitemodule.Site
|
||||||
|
generated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut s DocSite) build() ! {
|
pub fn (mut s DocSite) build() ! {
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import freeflowuniverse.herolib.osal.core as osal
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
pub fn (mut docsite DocSite) generate() ! {
|
pub fn (mut docsite DocSite) generate() ! {
|
||||||
|
if docsite.generated {
|
||||||
|
return
|
||||||
|
}
|
||||||
mut c := config()!
|
mut c := config()!
|
||||||
|
|
||||||
console.print_header(' docsite generate: ${docsite.name} on ${c.path_build.path}')
|
console.print_header(' docsite generate: ${docsite.name} on ${c.path_build.path}')
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ pub fn (mut docsite DocSite) import() ! {
|
|||||||
|
|
||||||
c:=config()!
|
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
|
// Use gittools to get path of what we want to import
|
||||||
import_path := gittools.get_repo_path(
|
import_path := gittools.get_repo_path(
|
||||||
git_pull: c.reset
|
git_pull: c.reset
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ pub mut:
|
|||||||
|
|
||||||
pub fn dsite_define(sitename string) ! {
|
pub fn dsite_define(sitename string) ! {
|
||||||
console.print_header('Add Docusaurus Site: ${sitename}')
|
console.print_header('Add Docusaurus Site: ${sitename}')
|
||||||
|
|
||||||
mut c := config()!
|
mut c := config()!
|
||||||
|
|
||||||
path_publish := '${c.path_publish.path}/${sitename}'
|
path_publish := '${c.path_publish.path}/${sitename}'
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ import freeflowuniverse.herolib.develop.gittools
|
|||||||
import freeflowuniverse.herolib.osal.core as osal
|
import freeflowuniverse.herolib.osal.core as osal
|
||||||
import freeflowuniverse.herolib.installers.web.bun
|
import freeflowuniverse.herolib.installers.web.bun
|
||||||
|
|
||||||
fn install() ! {
|
fn install(c DocusaurusConfig) ! {
|
||||||
mut gs := gittools.new()!
|
mut gs := gittools.new()!
|
||||||
|
|
||||||
mut c:=config()!
|
|
||||||
|
|
||||||
if c.reset {
|
if c.reset {
|
||||||
osal.rm(c.path_build.path)!
|
osal.rm(c.path_build.path)!
|
||||||
osal.dir_ensure(c.path_build.path)!
|
osal.dir_ensure(c.path_build.path)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template_path := gs.get_path(
|
template_path := gs.get_path(
|
||||||
pull: c.template_update
|
pull: c.template_update
|
||||||
reset: c.reset
|
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
|
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
|
||||||
// install bun
|
mut installer := bun.get()!
|
||||||
mut installer := bun.get()!
|
installer.install()!
|
||||||
installer.install()!
|
osal.exec(
|
||||||
osal.exec(
|
// always stay in the context of the build directory
|
||||||
// always stay in the context of the build directory
|
cmd: '
|
||||||
cmd: '
|
${osal.profile_path_source_and()!}
|
||||||
${osal.profile_path_source_and()!}
|
export PATH=${c.path_build.path}/node_modules/.bin::${os.home_dir()}/.bun/bin/:\$PATH
|
||||||
export PATH=${c.path_build.path}/node_modules/.bin::${os.home_dir()}/.bun/bin/:\$PATH
|
cd ${c.path_build.path}
|
||||||
cd ${c.path_build.path}
|
bun install
|
||||||
bun install
|
'
|
||||||
'
|
)!
|
||||||
)!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,17 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
)!
|
)!
|
||||||
|
|
||||||
site_name := param_define.get('name') or {
|
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)!
|
dsite_define(site_name)!
|
||||||
|
|
||||||
|
|
||||||
action_define.done = true
|
action_define.done = true
|
||||||
mut dsite := dsite_get(site_name)!
|
mut dsite := dsite_get(site_name)!
|
||||||
|
|
||||||
|
dsite.generate()!
|
||||||
|
|
||||||
mut actions_dev := plbook.find(filter: 'docusaurus.dev')!
|
mut actions_dev := plbook.find(filter: 'docusaurus.dev')!
|
||||||
if actions_dev.len > 1 {
|
if actions_dev.len > 1 {
|
||||||
return error('Multiple "docusaurus.dev" actions found. Only one is allowed.')
|
return error('Multiple "docusaurus.dev" actions found. Only one is allowed.')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module site
|
module site
|
||||||
|
import os
|
||||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import time
|
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{
|
mut import_ := ImportItem{
|
||||||
name: p.get_default('name', '')!
|
name: p.get_default('name', '')!
|
||||||
url: p.get('url')!
|
url: p.get_default('url', '')!
|
||||||
path: p.get_default('path', '')!
|
path: importpath
|
||||||
dest: p.get_default('dest', '')!
|
dest: p.get_default('dest', '')!
|
||||||
replace: replace_map
|
replace: replace_map
|
||||||
visible: p.get_default_false('visible')
|
visible: p.get_default_false('visible')
|
||||||
|
|||||||
Reference in New Issue
Block a user