This commit is contained in:
timurgordon
2025-02-09 20:13:18 +00:00
parent f1a4547961
commit 34dea39c52
8 changed files with 137 additions and 39 deletions

View File

@@ -29,19 +29,37 @@ pub fn cmd_docusaurus(mut cmdroot Command) {
description: 'Url where docusaurus source is.'
})
cmd_run.add_flag(Flag{
flag: .string
required: false
name: 'deploykey'
abbrev: 'dk'
// default: ''
description: 'Path of SSH Key used to deploy.'
})
cmd_run.add_flag(Flag{
flag: .string
required: false
name: 'publish'
// default: ''
description: 'Path where to publish.'
})
cmd_run.add_flag(Flag{
flag: .bool
required: false
name: 'build'
abbrev: 'b'
name: 'buildpublish'
abbrev: 'bp'
description: 'build and publish.'
})
cmd_run.add_flag(Flag{
flag: .bool
required: false
name: 'builddev'
abbrev: 'bd'
name: 'builddevpublish'
abbrev: 'bpd'
description: 'build dev version and publish.'
})
@@ -49,7 +67,6 @@ pub fn cmd_docusaurus(mut cmdroot Command) {
flag: .bool
required: false
name: 'update'
abbrev: 'p'
description: 'update your environment the template and the repo you are working on (git pull).'
})
@@ -67,6 +84,8 @@ pub fn cmd_docusaurus(mut cmdroot Command) {
fn cmd_docusaurus_execute(cmd Command) ! {
mut update := cmd.flags.get_bool('update') or { false }
mut url := cmd.flags.get_string('url') or { '' }
mut publish_path := cmd.flags.get_string('publish') or { '' }
mut deploykey := cmd.flags.get_string('deploykey') or { '' }
// mut path := cmd.flags.get_string('path') or { '' }
// if path == '' {
@@ -74,30 +93,42 @@ fn cmd_docusaurus_execute(cmd Command) ! {
// }
// path = path.replace('~', os.home_dir())
mut build := cmd.flags.get_bool('build') or { false }
mut builddev := cmd.flags.get_bool('builddev') or { false }
mut buildpublish := cmd.flags.get_bool('buildpublish') or { false }
mut builddevpublish := cmd.flags.get_bool('builddevpublish') or { false }
mut dev := cmd.flags.get_bool('dev') or { false }
// if build== false && build== false && build== false {
// eprintln("specify build, builddev or dev")
// exit(1)
// }
mut docs := docusaurus.new(update: update)!
if build {
// Create a new docusaurus site
if publish_path.len>0 {
_ := docs.build(
url: url
update: update
publish_path: publish_path
deploykey:deploykey
)!
}
if builddev {
if buildpublish {
// Create a new docusaurus site
_ := docs.build_dev(
_ := docs.build_publish(
url: url
update: update
deploykey:deploykey
)!
}
if builddevpublish {
// Create a new docusaurus site
_ := docs.build_dev_publish(
url: url
update: update
deploykey:deploykey
)!
}
@@ -106,6 +137,7 @@ fn cmd_docusaurus_execute(cmd Command) ! {
_ := docs.dev(
url: url
update: update
deploykey:deploykey
)!
}
}

View File

@@ -20,6 +20,7 @@ pub mut:
log bool = true // If true, logs git commands/statements
debug bool = true
ssh_key_name string // name of ssh key to be used when loading the gitstructure
ssh_key_path string
reload bool
}
@@ -35,6 +36,8 @@ pub fn new(args_ GitStructureArgsNew) !&GitStructure {
log: args.log
debug: args.debug
ssh_key_name: args.ssh_key_name
ssh_key_path: args.ssh_key_path
}
return get(coderoot: args.coderoot, reload: args.reload, cfg: cfg)
@@ -77,7 +80,19 @@ pub fn get(args_ GitStructureArgGet) !&GitStructure {
coderoot: pathlib.get_dir(path: args.coderoot, create: true)!
}
mut cfg := args.cfg or {
mut cfg_:=GitStructureConfig{coderoot:"SKIP"}
cfg_
}
if cfg.coderoot != "SKIP"{
gs.config_ = cfg
gs.config_save()!
println(gs.config()!)
}
gs.config()! // will load the config, don't remove
gs.load(false)!
if gs.repos.keys().len == 0 || args.reload {

View File

@@ -14,8 +14,10 @@ pub mut:
log bool = true // If true, logs git commands/statements
debug bool = true
ssh_key_name string
ssh_key_path string
}
// GitStructure holds information about repositories within a specific code root.
// This structure keeps track of loaded repositories, their configurations, and their status.
@[heap]
@@ -233,6 +235,6 @@ pub fn (mut self GitStructure) config_reset() ! {
pub fn (mut self GitStructure) config_save() ! {
// Retrieve the configuration from Redis.
mut redis := redis_get()
datajson := json.encode(self.config)
datajson := json.encode(self.config()!)
redis.set('${self.cache_key()}:config', datajson)!
}

View File

@@ -34,7 +34,17 @@ pub fn (mut gitstructure GitStructure) clone(args GitCloneArgs) !&GitRepo {
extra = '--depth 1 --no-single-branch '
}
cmd := 'cd ${parent_dir} && git clone ${extra} ${repo.get_http_url()!} ${repo.name}'
cfg:=gitstructure.config()!
mut cmd := 'cd ${parent_dir} && git clone ${extra} ${repo.get_http_url()!} ${repo.name}'
mut sshkey_include := ""
if cfg.ssh_key_path.len>0{
sshkey_include="GIT_SSH_COMMAND=\"ssh -i ${cfg.ssh_key_path}\" "
cmd = 'cd ${parent_dir} && ${sshkey_include}git clone ${extra} ${repo.get_ssh_url()!} ${repo.name}'
}
console.print_debug(cmd)
result := os.execute(cmd)
if result.exit_code != 0 {
return error('Cannot clone the repository due to: \n${result.output}')

View File

@@ -30,24 +30,12 @@ pub mut:
nameshort string
path string
url string
// publish_path string
publish_path string
build_path string
production bool
watch_changes bool = true
update bool
}
pub fn (mut f DocusaurusFactory) build_dev(args_ DSiteNewArgs) !&DocSite {
mut s := f.add(args_)!
s.generate()!
osal.exec(
cmd: '
cd ${s.path_build.path}
bash build_dev.sh
'
retry: 0
)!
return s
deploykey string
}
pub fn (mut f DocusaurusFactory) build(args_ DSiteNewArgs) !&DocSite {
@@ -63,6 +51,33 @@ pub fn (mut f DocusaurusFactory) build(args_ DSiteNewArgs) !&DocSite {
return s
}
pub fn (mut f DocusaurusFactory) build_dev_publish(args_ DSiteNewArgs) !&DocSite {
mut s := f.add(args_)!
s.generate()!
osal.exec(
cmd: '
cd ${s.path_build.path}
bash build_dev_publish.sh
'
retry: 0
)!
return s
}
pub fn (mut f DocusaurusFactory) build_publish(args_ DSiteNewArgs) !&DocSite {
mut s := f.add(args_)!
s.generate()!
osal.exec(
cmd: '
cd ${s.path_build.path}
bash build_publish.sh
'
retry: 0
)!
return s
}
pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
mut s := f.add(args_)!
@@ -126,8 +141,9 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteNewArgs) !&DocSite {
// if args.publish_path.len == 0 {
// args.publish_path = '${f.path_publish.path}/${args.name}'
mut gs := gittools.new(ssh_key_path:args.deploykey, coderoot:"/var/publishcode")!
if args.url.len > 0 {
mut gs := gittools.new()!
args.path = gs.get_path(url: args.url)!
}
@@ -135,7 +151,6 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteNewArgs) !&DocSite {
return error("Can't get path from docusaurus site, its not specified.")
}
mut gs := gittools.new()!
mut r := gs.get_repo(
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
pull: args.update
@@ -262,7 +277,8 @@ fn (mut site DocSite) template_install() ! {
develop := $tmpl('templates/develop.sh')
build := $tmpl('templates/build.sh')
build_dev := $tmpl('templates/build_dev.sh')
build_dev_publish := $tmpl('templates/build_dev_publish.sh')
build_publish := $tmpl('templates/build_publish.sh')
mut develop_ := site.path_build.file_get_new('develop.sh')!
develop_.template_write(develop, true)!
@@ -272,9 +288,13 @@ fn (mut site DocSite) template_install() ! {
build_.template_write(build, true)!
build_.chmod(0o700)!
mut build_dev_ := site.path_build.file_get_new('build_dev.sh')!
build_dev_.template_write(build_dev, true)!
build_dev_.chmod(0o700)!
mut build_publish_ := site.path_build.file_get_new('build_publish.sh')!
build_publish_.template_write(build_publish, true)!
build_publish_.chmod(0o700)!
mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
build_dev_publish_.template_write(build_dev_publish, true)!
build_dev_publish_.chmod(0o700)!
mut develop2_ := site.path_src.file_get_new('develop.sh')!
develop2_.template_write(develop, true)!
@@ -284,7 +304,4 @@ fn (mut site DocSite) template_install() ! {
build2_.template_write(build, true)!
build2_.chmod(0o700)!
mut build_dev2_ := site.path_src.file_get_new('build_dev.sh')!
build_dev2_.template_write(build_dev, true)!
build_dev2_.chmod(0o700)!
}

View File

@@ -17,4 +17,6 @@ ${profile_include}
bun docusaurus build
rsync -rv --delete ${site.path_build.path}/build/ ${cfg.main.build_dest.trim_right("/")}/${cfg.main.name.trim_right("/")}/
mkdir -p ${site.args.publish_path.trim_right("/")}
echo SYNC TO ${site.args.publish_path.trim_right("/")}
rsync -rv --delete ${site.path_build.path}/build/ ${site.args.publish_path.trim_right("/")}/

View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -e
script_dir="??(cd "??(dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd ${site.path_build.path}
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
rm -rf ${site.path_build.path}/build/
${profile_include}
bun docusaurus build
rsync -rv --delete ${site.path_build.path}/build/ ${cfg.main.build_dest.trim_right("/")}/${cfg.main.name.trim_right("/")}/

View File

@@ -5,7 +5,6 @@ set -e
script_dir="??(cd "??(dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd ${site.path_build.path}