From 93953ed5709547eadebe1a0893d0bc522a00db18 Mon Sep 17 00:00:00 2001 From: despiegk Date: Thu, 7 Aug 2025 08:15:04 +0200 Subject: [PATCH] ... --- examples/web/docusaurus_example.vsh | 27 ++++++++++++++----------- lib/core/playbook/find.v | 21 +++++++++++++++++++ lib/web/docusaurus/dsite_add.v | 31 +++++++++-------------------- lib/web/docusaurus/play.v | 10 ++++++---- lib/web/site/play.v | 19 +++++++++++++----- 5 files changed, 65 insertions(+), 43 deletions(-) diff --git a/examples/web/docusaurus_example.vsh b/examples/web/docusaurus_example.vsh index db1e72e2..8f0f6d0b 100755 --- a/examples/web/docusaurus_example.vsh +++ b/examples/web/docusaurus_example.vsh @@ -3,21 +3,24 @@ import freeflowuniverse.herolib.core.playcmds playcmds.run( - heroscript: ' + heroscript: ' - !!docusaurus.define + !!docusaurus.define path_build: "/tmp/docusaurus_build" path_publish: "/tmp/docusaurus_publish" - reset: 1 - install: 1 - template_update: 1 + // reset: 1 + // install: 1 + // template_update: 1 - !!docusaurus.add name:"tfgrid_docs" - git_url:"https://git.threefold.info/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech" - git_root:"/tmp/code" - git_reset:1 - git_pull:1 + !!docusaurus.add name:"tfgrid_docs" + sitename:"tfgrid_docs" + git_url:"https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech" + // git_root:"/tmp/code" + // git_reset:1 + // git_pull:1 - !!docusaurus.build +// !!docusaurus.build + +// !!docusaurus.dev site:"tfgrid_docs" open:true watch_changes:true ' -)! +)! \ No newline at end of file diff --git a/lib/core/playbook/find.v b/lib/core/playbook/find.v index 893c6e27..2435bbc3 100644 --- a/lib/core/playbook/find.v +++ b/lib/core/playbook/find.v @@ -97,6 +97,27 @@ pub fn (mut plbook PlayBook) exists_once(args FindArgs) bool { 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 { mut res := plbook.find(args) or { [] } return res.len > 0 diff --git a/lib/web/docusaurus/dsite_add.v b/lib/web/docusaurus/dsite_add.v index 957dc9a2..30e9b6c3 100644 --- a/lib/web/docusaurus/dsite_add.v +++ b/lib/web/docusaurus/dsite_add.v @@ -63,14 +63,6 @@ pub fn dsite_add(args_ AddArgs) !&DocSite { osal.rm('${args.path}/sync.sh')! 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()! if args.path_publish == '' { @@ -80,20 +72,15 @@ pub fn dsite_add(args_ AddArgs) !&DocSite { path_build_ := '${f.path_build.path}/${args.sitename}' // get our website + console.print_debug('Docusaurus site ${args.sitename} at ${args.path}.') mut mysite := site.new(name: args.sitename)! - if site.exists(name: args.sitename) { - console.print_debug('Docusaurus site ${args.sitename} already exists, using existing site.') - mysite = site.get(name: args.sitename)! - } else { - if !args.play { - return error('Docusaurus site ${args.sitename} does not exist, please set play to true to create it.') - } - 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}') - } + mut plbook := playbook.new(path: '${args.path}/cfg')! + if plbook.actions.len == 0 { + return error('No actions found in playbook at ${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 @@ -102,7 +89,7 @@ pub fn dsite_add(args_ AddArgs) !&DocSite { path_src: pathlib.get_dir(path: args.path, create: false)! path_publish: pathlib.get_dir(path: args.path_publish, create: true)! path_build: pathlib.get_dir(path: path_build_, create: true)! - config: new_configuration(website.siteconfig)! + config: new_configuration(mysite.siteconfig)! website: mysite } diff --git a/lib/web/docusaurus/play.v b/lib/web/docusaurus/play.v index 63bdccee..0b938959 100644 --- a/lib/web/docusaurus/play.v +++ b/lib/web/docusaurus/play.v @@ -15,7 +15,7 @@ pub fn play(mut plbook PlayBook) ! { // check if docusaurus.define exists, if not, we create a default factory 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 { panic('docusaurus.define action not found, this should not happen.') } @@ -41,10 +41,10 @@ pub fn play(mut plbook PlayBook) ! { dsite_add( sitename: site_name - path: p.get('path')! - git_url: p.get('git_url')! + path: p.get_default('path', '')! + git_url: p.get_default('git_url','')! 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') path_publish: p.get_default('path_publish', f.path_publish.path)! play: false // need to make sure we don't play again @@ -80,4 +80,6 @@ pub fn play(mut plbook PlayBook) ! { dsite.build()! action.done = true } + + plbook.ensure_processed(filter: 'docusaurus.')! } diff --git a/lib/web/site/play.v b/lib/web/site/play.v index 7bf6f321..498c34b9 100644 --- a/lib/web/site/play.v +++ b/lib/web/site/play.v @@ -5,16 +5,28 @@ import freeflowuniverse.herolib.core.texttools import time pub fn play(mut plbook PlayBook) ! { + + if !plbook.exists(filter: 'site.') { + return + } + + // Handle multiple site configurations 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 { return error('No site.config actions found') } // Process each site configuration separately 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 @@ -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 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.url_home = p.get_default('url_home', config.url_home)! config.name = name - - action.done = true // Mark the action as done - return website }