This commit is contained in:
2025-08-07 08:15:04 +02:00
parent 2667856633
commit 93953ed570
5 changed files with 65 additions and 43 deletions

View File

@@ -3,21 +3,24 @@
import freeflowuniverse.herolib.core.playcmds import freeflowuniverse.herolib.core.playcmds
playcmds.run( playcmds.run(
heroscript: ' heroscript: '
!!docusaurus.define !!docusaurus.define
path_build: "/tmp/docusaurus_build" path_build: "/tmp/docusaurus_build"
path_publish: "/tmp/docusaurus_publish" path_publish: "/tmp/docusaurus_publish"
reset: 1 // reset: 1
install: 1 // install: 1
template_update: 1 // template_update: 1
!!docusaurus.add name:"tfgrid_docs" !!docusaurus.add name:"tfgrid_docs"
git_url:"https://git.threefold.info/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech" sitename:"tfgrid_docs"
git_root:"/tmp/code" git_url:"https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech"
git_reset:1 // git_root:"/tmp/code"
git_pull:1 // git_reset:1
// git_pull:1
!!docusaurus.build // !!docusaurus.build
// !!docusaurus.dev site:"tfgrid_docs" open:true watch_changes:true
' '
)! )!

View File

@@ -97,6 +97,27 @@ pub fn (mut plbook PlayBook) exists_once(args FindArgs) bool {
return res.len == 1 return res.len == 1
} }
//checks it exists once, if more than one it returns error
pub fn (mut plbook PlayBook) max_once(args FindArgs) !bool {
mut res := plbook.find(args) or { [] }
if res.len > 1 {
return error("found more than one action: '${args.filter}'")
}
return res.len == 1
}
//will give error on what is not done yet
pub fn (mut plbook PlayBook) ensure_processed(args FindArgs) ! {
mut res := plbook.find(args) or { [] }
for item in res {
if !item.done {
return error("action not done: '${item.actor}.${item.name}'")
}
}
}
pub fn (mut plbook PlayBook) exists(args FindArgs) bool { pub fn (mut plbook PlayBook) exists(args FindArgs) bool {
mut res := plbook.find(args) or { [] } mut res := plbook.find(args) or { [] }
return res.len > 0 return res.len > 0

View File

@@ -63,14 +63,6 @@ pub fn dsite_add(args_ AddArgs) !&DocSite {
osal.rm('${args.path}/sync.sh')! osal.rm('${args.path}/sync.sh')!
osal.rm('${args.path}/.DS_Store')! osal.rm('${args.path}/.DS_Store')!
mut website := site.get(name: args.sitename)!
mut myconfig := new_configuration(website.siteconfig)! // go from site.SiteConfig to docusaurus.Configuration
if myconfig.main.name.len == 0 {
return error('main.name is not set in the site configuration')
}
mut f := factory_get()! mut f := factory_get()!
if args.path_publish == '' { if args.path_publish == '' {
@@ -80,20 +72,15 @@ pub fn dsite_add(args_ AddArgs) !&DocSite {
path_build_ := '${f.path_build.path}/${args.sitename}' path_build_ := '${f.path_build.path}/${args.sitename}'
// get our website // get our website
console.print_debug('Docusaurus site ${args.sitename} at ${args.path}.')
mut mysite := site.new(name: args.sitename)! mut mysite := site.new(name: args.sitename)!
if site.exists(name: args.sitename) { mut plbook := playbook.new(path: '${args.path}/cfg')!
console.print_debug('Docusaurus site ${args.sitename} already exists, using existing site.') if plbook.actions.len == 0 {
mysite = site.get(name: args.sitename)! return error('No actions found in playbook at ${args.path}/cfg')
} else { }
if !args.play { site.play(mut plbook)!
return error('Docusaurus site ${args.sitename} does not exist, please set play to true to create it.') mysite = site.get(name: args.sitename) or {
} return error('Failed to get site after playing playbook: ${args.sitename}')
console.print_debug('Creating new Docusaurus site ${args.sitename}.')
mut plbook := playbook.new(path: '${args.path}/cfg')!
site.play(mut plbook)!
mysite = site.get(name: args.sitename) or {
return error('Failed to get site after playing playbook: ${args.sitename}')
}
} }
// Create the DocSite instance // Create the DocSite instance
@@ -102,7 +89,7 @@ pub fn dsite_add(args_ AddArgs) !&DocSite {
path_src: pathlib.get_dir(path: args.path, create: false)! path_src: pathlib.get_dir(path: args.path, create: false)!
path_publish: pathlib.get_dir(path: args.path_publish, create: true)! path_publish: pathlib.get_dir(path: args.path_publish, create: true)!
path_build: pathlib.get_dir(path: path_build_, create: true)! path_build: pathlib.get_dir(path: path_build_, create: true)!
config: new_configuration(website.siteconfig)! config: new_configuration(mysite.siteconfig)!
website: mysite website: mysite
} }

View File

@@ -15,7 +15,7 @@ pub fn play(mut plbook PlayBook) ! {
// check if docusaurus.define exists, if not, we create a default factory // check if docusaurus.define exists, if not, we create a default factory
mut f := DocSiteFactory{} mut f := DocSiteFactory{}
if plbook.exists_once(filter: 'docusaurus.define') { if plbook.max_once(filter: 'docusaurus.define')! {
mut a := plbook.get(filter: 'docusaurus.define') or { mut a := plbook.get(filter: 'docusaurus.define') or {
panic('docusaurus.define action not found, this should not happen.') panic('docusaurus.define action not found, this should not happen.')
} }
@@ -41,10 +41,10 @@ pub fn play(mut plbook PlayBook) ! {
dsite_add( dsite_add(
sitename: site_name sitename: site_name
path: p.get('path')! path: p.get_default('path', '')!
git_url: p.get('git_url')! git_url: p.get_default('git_url','')!
git_reset: p.get_default_false('git_reset') git_reset: p.get_default_false('git_reset')
git_root: p.get('git_root')! git_root: p.get_default('git_root','')!
git_pull: p.get_default_false('git_pull') git_pull: p.get_default_false('git_pull')
path_publish: p.get_default('path_publish', f.path_publish.path)! path_publish: p.get_default('path_publish', f.path_publish.path)!
play: false // need to make sure we don't play again play: false // need to make sure we don't play again
@@ -80,4 +80,6 @@ pub fn play(mut plbook PlayBook) ! {
dsite.build()! dsite.build()!
action.done = true action.done = true
} }
plbook.ensure_processed(filter: 'docusaurus.')!
} }

View File

@@ -5,16 +5,28 @@ import freeflowuniverse.herolib.core.texttools
import time import time
pub fn play(mut plbook PlayBook) ! { pub fn play(mut plbook PlayBook) ! {
if !plbook.exists(filter: 'site.') {
return
}
// Handle multiple site configurations // Handle multiple site configurations
mut config_actions := plbook.find(filter: 'site.config')! mut config_actions := plbook.find(filter: 'site.config')!
println('Playing site configuration...')
// println(config_actions)
// if true{panic('site.play not implemented yet, this is a stub')}
if config_actions.len == 0 { if config_actions.len == 0 {
return error('No site.config actions found') return error('No site.config actions found')
} }
// Process each site configuration separately // Process each site configuration separately
for mut config_action in config_actions { for mut config_action in config_actions {
mut website := play_config_single(mut config_action)! mut website := play_config_single( *config_action)!
config_action.done = true // Mark the action as done
mut config := &website.siteconfig mut config := &website.siteconfig
@@ -28,7 +40,7 @@ pub fn play(mut plbook PlayBook) ! {
} }
} }
fn play_config_single(mut action Action) !&Site { fn play_config_single(action Action) !&Site {
mut p := action.params mut p := action.params
name := p.get('name') or { return error('need to specify name in site.config.\n${action}') } name := p.get('name') or { return error('need to specify name in site.config.\n${action}') }
@@ -45,9 +57,6 @@ fn play_config_single(mut action Action) !&Site {
config.base_url = p.get_default('base_url', config.base_url)! config.base_url = p.get_default('base_url', config.base_url)!
config.url_home = p.get_default('url_home', config.url_home)! config.url_home = p.get_default('url_home', config.url_home)!
config.name = name config.name = name
action.done = true // Mark the action as done
return website return website
} }