...
This commit is contained in:
@@ -13,58 +13,58 @@ import freeflowuniverse.herolib.ui.console
|
||||
@[heap]
|
||||
pub struct DocSite {
|
||||
pub mut:
|
||||
name string
|
||||
url string
|
||||
path_src pathlib.Path
|
||||
path_build pathlib.Path
|
||||
name string
|
||||
url string
|
||||
path_src pathlib.Path
|
||||
path_build pathlib.Path
|
||||
// path_publish pathlib.Path
|
||||
args DSiteNewArgs
|
||||
errors []SiteError
|
||||
args DSiteNewArgs
|
||||
errors []SiteError
|
||||
config Config
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct DSiteNewArgs {
|
||||
pub mut:
|
||||
name string
|
||||
nameshort string
|
||||
path string
|
||||
url string
|
||||
name string
|
||||
nameshort string
|
||||
path string
|
||||
url string
|
||||
// publish_path string
|
||||
build_path string
|
||||
production bool
|
||||
build_path string
|
||||
production bool
|
||||
watch_changes bool = true
|
||||
update bool
|
||||
update bool
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) build_dev(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s:=f.add(args_)!
|
||||
mut s := f.add(args_)!
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
bash build_dev.sh
|
||||
'
|
||||
retry: 0
|
||||
)!
|
||||
)!
|
||||
return s
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) build(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s:=f.add(args_)!
|
||||
mut s := f.add(args_)!
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
bash build.sh
|
||||
'
|
||||
retry: 0
|
||||
)!
|
||||
)!
|
||||
return s
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s:=f.add(args_)!
|
||||
mut s := f.add(args_)!
|
||||
|
||||
s.clean()!
|
||||
s.generate()!
|
||||
@@ -72,14 +72,14 @@ pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
|
||||
// Create screen session for docusaurus development server
|
||||
mut screen_name := 'docusaurus'
|
||||
mut sf := screen.new()!
|
||||
|
||||
|
||||
// Add and start a new screen session
|
||||
mut scr := sf.add(
|
||||
name: screen_name
|
||||
cmd: '/bin/bash'
|
||||
start: true
|
||||
name: screen_name
|
||||
cmd: '/bin/bash'
|
||||
start: true
|
||||
attach: false
|
||||
reset: true
|
||||
reset: true
|
||||
)!
|
||||
|
||||
// Send commands to the screen session
|
||||
@@ -93,33 +93,29 @@ pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
|
||||
console.print_item(' 1. Attach to screen: screen -r ${screen_name}')
|
||||
console.print_item(' 2. To detach from screen: Press Ctrl+A then D')
|
||||
console.print_item(' 3. To list all screens: screen -ls')
|
||||
console.print_item('The site content is on::')
|
||||
console.print_item('The site content is on::')
|
||||
console.print_item(' 1. location of documents: ${s.path_src.path}/docs')
|
||||
if osal.cmd_exists("code"){
|
||||
if osal.cmd_exists('code') {
|
||||
console.print_item(' 2. We opened above dir in vscode.')
|
||||
osal.exec(cmd:'code ${s.path_src.path}/docs')!
|
||||
osal.exec(cmd: 'code ${s.path_src.path}/docs')!
|
||||
}
|
||||
|
||||
|
||||
// Start the watcher in a separate thread
|
||||
//mut tf:=spawn watch_docs(docs_path, s.path_src.path, s.path_build.path)
|
||||
//tf.wait()!
|
||||
println("\n")
|
||||
// mut tf:=spawn watch_docs(docs_path, s.path_src.path, s.path_build.path)
|
||||
// tf.wait()!
|
||||
println('\n')
|
||||
|
||||
if args_.watch_changes {
|
||||
docs_path := '${s.path_src.path}/docs'
|
||||
watch_docs(docs_path, s.path_src.path, s.path_build.path)!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
pub fn (mut f DocusaurusFactory) add(args_ DSiteNewArgs) !&DocSite {
|
||||
console.print_header(' Docusaurus: ${args_.name}')
|
||||
mut args := args_
|
||||
@@ -129,62 +125,57 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteNewArgs) !&DocSite {
|
||||
}
|
||||
// if args.publish_path.len == 0 {
|
||||
// args.publish_path = '${f.path_publish.path}/${args.name}'
|
||||
|
||||
|
||||
if args.url.len>0{
|
||||
|
||||
if args.url.len > 0 {
|
||||
mut gs := gittools.new()!
|
||||
args.path = gs.get_path(url: args.url)!
|
||||
|
||||
}
|
||||
|
||||
if args.path.len==0{
|
||||
if args.path.len == 0 {
|
||||
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)!
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
pull: args.update
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
// First ensure cfg directory exists in src, if not copy from template
|
||||
if !os.exists("${args.path}/cfg") {
|
||||
mut template_cfg := template_path.dir_get("cfg")!
|
||||
template_cfg.copy(dest:"${args.path}/cfg")!
|
||||
if !os.exists('${args.path}/cfg') {
|
||||
mut template_cfg := template_path.dir_get('cfg')!
|
||||
template_cfg.copy(dest: '${args.path}/cfg')!
|
||||
}
|
||||
|
||||
if !os.exists("${args.path}/docs") {
|
||||
mut template_cfg := template_path.dir_get("docs")!
|
||||
template_cfg.copy(dest:"${args.path}/docs")!
|
||||
if !os.exists('${args.path}/docs') {
|
||||
mut template_cfg := template_path.dir_get('docs')!
|
||||
template_cfg.copy(dest: '${args.path}/docs')!
|
||||
}
|
||||
|
||||
mut myconfig := load_config('${args.path}/cfg')!
|
||||
|
||||
mut myconfig:=load_config("${args.path}/cfg")!
|
||||
|
||||
if myconfig.main.name.len==0{
|
||||
myconfig.main.name = myconfig.main.base_url.trim_space().trim("/").trim_space()
|
||||
if myconfig.main.name.len == 0 {
|
||||
myconfig.main.name = myconfig.main.base_url.trim_space().trim('/').trim_space()
|
||||
}
|
||||
|
||||
|
||||
if args.name == '' {
|
||||
args.name = myconfig.main.name
|
||||
}
|
||||
}
|
||||
|
||||
if args.nameshort.len == 0 {
|
||||
args.nameshort = args.name
|
||||
}
|
||||
}
|
||||
args.nameshort = texttools.name_fix(args.nameshort)
|
||||
|
||||
|
||||
|
||||
mut ds := DocSite{
|
||||
name: args.name
|
||||
url: args.url
|
||||
path_src: pathlib.get_dir(path: args.path, create: false)!
|
||||
name: args.name
|
||||
url: args.url
|
||||
path_src: pathlib.get_dir(path: args.path, create: false)!
|
||||
path_build: f.path_build
|
||||
// path_publish: pathlib.get_dir(path: args.publish_path, create: true)!
|
||||
args: args
|
||||
config:myconfig
|
||||
args: args
|
||||
config: myconfig
|
||||
}
|
||||
|
||||
f.sites << &ds
|
||||
@@ -201,9 +192,9 @@ pub mut:
|
||||
}
|
||||
|
||||
pub fn (mut site DocSite) error(args ErrorArgs) {
|
||||
// path2 := pathlib.get(args.path)
|
||||
e := SiteError{
|
||||
path: args.path
|
||||
// path2 := pathlib.get(args.path)
|
||||
e := SiteError{
|
||||
path: args.path
|
||||
msg: args.msg
|
||||
cat: args.cat
|
||||
}
|
||||
@@ -222,21 +213,19 @@ pub fn (mut site DocSite) generate() ! {
|
||||
// retry: 0
|
||||
// )!
|
||||
|
||||
|
||||
// Now copy all directories that exist in src to build
|
||||
for item in ["src","static","cfg"]{
|
||||
if os.exists("${site.path_src.path}/${item}"){
|
||||
mut aa:= site.path_src.dir_get(item)!
|
||||
aa.copy(dest:"${site.path_build.path}/${item}")!
|
||||
for item in ['src', 'static', 'cfg'] {
|
||||
if os.exists('${site.path_src.path}/${item}') {
|
||||
mut aa := site.path_src.dir_get(item)!
|
||||
aa.copy(dest: '${site.path_build.path}/${item}')!
|
||||
}
|
||||
}
|
||||
for item in ["docs"]{
|
||||
if os.exists("${site.path_src.path}/${item}"){
|
||||
mut aa:= site.path_src.dir_get(item)!
|
||||
aa.copy(dest:"${site.path_build.path}/${item}",delete:true)!
|
||||
for item in ['docs'] {
|
||||
if os.exists('${site.path_src.path}/${item}') {
|
||||
mut aa := site.path_src.dir_get(item)!
|
||||
aa.copy(dest: '${site.path_build.path}/${item}', delete: true)!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn (mut site DocSite) template_install() ! {
|
||||
@@ -245,22 +234,26 @@ fn (mut site DocSite) template_install() ! {
|
||||
mut r := gs.get_repo(url: 'https://github.com/freeflowuniverse/docusaurus_template.git')!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
//always start from template first
|
||||
for item in ["src","static","cfg"]{
|
||||
mut aa:= template_path.dir_get(item)!
|
||||
aa.copy(dest:"${site.path_build.path}/${item}",delete:true)!
|
||||
// always start from template first
|
||||
for item in ['src', 'static', 'cfg'] {
|
||||
mut aa := template_path.dir_get(item)!
|
||||
aa.copy(dest: '${site.path_build.path}/${item}', delete: true)!
|
||||
}
|
||||
|
||||
for item in ['package.json', 'sidebars.ts', 'tsconfig.json','docusaurus.config.ts'] {
|
||||
for item in ['package.json', 'sidebars.ts', 'tsconfig.json', 'docusaurus.config.ts'] {
|
||||
src_path := os.join_path(template_path.path, item)
|
||||
dest_path := os.join_path(site.path_build.path, item)
|
||||
os.cp(src_path, dest_path) or { return error('Failed to copy ${item} to build path: ${err}') }
|
||||
os.cp(src_path, dest_path) or {
|
||||
return error('Failed to copy ${item} to build path: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
for item in ['.gitignore'] {
|
||||
src_path := os.join_path(template_path.path, item)
|
||||
dest_path := os.join_path(site.path_src.path, item)
|
||||
os.cp(src_path, dest_path) or { return error('Failed to copy ${item} to source path: ${err}') }
|
||||
os.cp(src_path, dest_path) or {
|
||||
return error('Failed to copy ${item} to source path: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
cfg := site.config
|
||||
@@ -269,30 +262,27 @@ fn (mut site DocSite) template_install() ! {
|
||||
build := $tmpl('templates/build.sh')
|
||||
build_dev := $tmpl('templates/build_dev.sh')
|
||||
|
||||
mut develop_ := site.path_build.file_get_new("develop.sh")!
|
||||
develop_.template_write(develop,true)!
|
||||
mut develop_ := site.path_build.file_get_new('develop.sh')!
|
||||
develop_.template_write(develop, true)!
|
||||
develop_.chmod(0o700)!
|
||||
|
||||
mut build_ := site.path_build.file_get_new("build.sh")!
|
||||
build_.template_write(build,true)!
|
||||
mut build_ := site.path_build.file_get_new('build.sh')!
|
||||
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)!
|
||||
mut build_dev_ := site.path_build.file_get_new('build_dev.sh')!
|
||||
build_dev_.template_write(build_dev, true)!
|
||||
build_dev_.chmod(0o700)!
|
||||
|
||||
mut develop2_ := site.path_src.file_get_new("develop.sh")!
|
||||
develop2_.template_write(develop,true)!
|
||||
mut develop2_ := site.path_src.file_get_new('develop.sh')!
|
||||
develop2_.template_write(develop, true)!
|
||||
develop2_.chmod(0o700)!
|
||||
|
||||
mut build2_ := site.path_src.file_get_new("build.sh")!
|
||||
build2_.template_write(build,true)!
|
||||
mut build2_ := site.path_src.file_get_new('build.sh')!
|
||||
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)!
|
||||
|
||||
|
||||
|
||||
mut build_dev2_ := site.path_src.file_get_new('build_dev.sh')!
|
||||
build_dev2_.template_write(build_dev, true)!
|
||||
build_dev2_.chmod(0o700)!
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub mut:
|
||||
// publish_path string
|
||||
build_path string
|
||||
production bool
|
||||
update bool
|
||||
update bool
|
||||
}
|
||||
|
||||
pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
|
||||
|
||||
@@ -7,7 +7,10 @@ import freeflowuniverse.herolib.installers.web.bun
|
||||
fn (mut site DocusaurusFactory) template_install(update bool) ! {
|
||||
mut gs := gittools.new()!
|
||||
|
||||
mut r := gs.get_repo(url: 'https://github.com/freeflowuniverse/docusaurus_template.git',pull:update)!
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
pull: update
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
for item in ['package.json', 'sidebars.ts', 'tsconfig.json'] {
|
||||
|
||||
Reference in New Issue
Block a user