fixes docusaurus
This commit is contained in:
@@ -84,7 +84,7 @@ pub fn load_config(cfg_dir string) !Config {
|
||||
main_config_path := os.join_path(cfg_dir, 'main.json')
|
||||
main_content := os.read_file(main_config_path)!
|
||||
main := json.decode(Main, main_content) or {
|
||||
eprintln('${main_config_path} is not in the right format please fix.\nError: ${err}')
|
||||
eprintln('main.json in ${cfg_dir} is not in the right format please fix.\nError: ${err}')
|
||||
println('
|
||||
|
||||
## EXAMPLE OF A GOOD ONE:
|
||||
|
||||
@@ -18,29 +18,14 @@ pub mut:
|
||||
path_src pathlib.Path
|
||||
path_build pathlib.Path
|
||||
// path_publish pathlib.Path
|
||||
args DSiteNewArgs
|
||||
args DSiteGetArgs
|
||||
errors []SiteError
|
||||
config Config
|
||||
factory &DocusaurusFactory @[skip; str: skip] // Reference to the parent
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct DSiteNewArgs {
|
||||
pub mut:
|
||||
name string
|
||||
nameshort string
|
||||
path string
|
||||
url string
|
||||
publish_path string
|
||||
build_path string
|
||||
production bool
|
||||
watch_changes bool = true
|
||||
update bool
|
||||
deploykey string
|
||||
config ?Config
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) build(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s := f.add(args_)!
|
||||
pub fn (mut s DocSite) build() ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
@@ -49,11 +34,9 @@ pub fn (mut f DocusaurusFactory) build(args_ DSiteNewArgs) !&DocSite {
|
||||
'
|
||||
retry: 0
|
||||
)!
|
||||
return s
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) build_dev_publish(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s := f.add(args_)!
|
||||
pub fn (mut s DocSite) build_dev_publish() ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
@@ -62,13 +45,10 @@ pub fn (mut f DocusaurusFactory) build_dev_publish(args_ DSiteNewArgs) !&DocSite
|
||||
'
|
||||
retry: 0
|
||||
)!
|
||||
return s
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) build_publish(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s := f.add(args_)!
|
||||
pub fn (mut s DocSite) build_publish()! {
|
||||
s.generate()!
|
||||
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
@@ -76,12 +56,9 @@ pub fn (mut f DocusaurusFactory) build_publish(args_ DSiteNewArgs) !&DocSite {
|
||||
'
|
||||
retry: 0
|
||||
)!
|
||||
return s
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
|
||||
mut s := f.add(args_)!
|
||||
|
||||
pub fn (mut s DocSite) dev()! {
|
||||
s.clean()!
|
||||
s.generate()!
|
||||
|
||||
@@ -121,90 +98,11 @@ pub fn (mut f DocusaurusFactory) dev(args_ DSiteNewArgs) !&DocSite {
|
||||
// tf.wait()!
|
||||
println('\n')
|
||||
|
||||
if args_.watch_changes {
|
||||
if s.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_
|
||||
|
||||
if args.build_path.len == 0 {
|
||||
args.build_path = '${f.path_build.path}'
|
||||
}
|
||||
// if args.publish_path.len == 0 {
|
||||
// args.publish_path = '${f.path_publish.path}/${args.name}'
|
||||
|
||||
// coderoot:"${os.home_dir()}/hero/var/publishcode"
|
||||
mut gs := gittools.new(ssh_key_path: args.deploykey)!
|
||||
|
||||
if args.url.len > 0 {
|
||||
args.path = gs.get_path(url: args.url)!
|
||||
}
|
||||
|
||||
if args.path.len == 0 {
|
||||
return error("Can't get path from docusaurus site, its not specified.")
|
||||
}
|
||||
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
pull: args.update
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
|
||||
// First, check if the new site args provides a configuration that can be written instead of template cfg dir
|
||||
if cfg := args.config {
|
||||
cfg.write('${args.path}/cfg')!
|
||||
} else {
|
||||
// Then ensure cfg directory exists in src,
|
||||
if !os.exists('${args.path}/cfg') {
|
||||
// else copy config from template
|
||||
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')!
|
||||
}
|
||||
|
||||
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 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)!
|
||||
path_build: f.path_build
|
||||
// path_publish: pathlib.get_dir(path: args.publish_path, create: true)!
|
||||
args: args
|
||||
config: myconfig
|
||||
}
|
||||
|
||||
f.sites << &ds
|
||||
|
||||
return &ds
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -226,9 +124,27 @@ pub fn (mut site DocSite) error(args ErrorArgs) {
|
||||
console.print_stderr(args.msg)
|
||||
}
|
||||
|
||||
fn check_item(item string)!{
|
||||
item2:=item.trim_space().trim("/").trim_space().all_after_last("/")
|
||||
if ["internal","infodev","info","dev","friends","dd","web"].contains(item2){
|
||||
return error("destination path is wrong, cannot be: ${item}")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn (mut site DocSite) check() ! {
|
||||
for item in site.config.main.build_dest{
|
||||
check_item(item)!
|
||||
}
|
||||
for item in site.config.main.build_dest_dev{
|
||||
check_item(item)!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut site DocSite) generate() ! {
|
||||
console.print_header(' site generate: ${site.name} on ${site.path_build.path}')
|
||||
console.print_header(' site source on ${site.path_src.path}')
|
||||
site.check()!
|
||||
site.template_install()!
|
||||
// osal.exec(
|
||||
// cmd: '
|
||||
@@ -256,34 +172,22 @@ pub fn (mut site DocSite) generate() ! {
|
||||
fn (mut site DocSite) template_install() ! {
|
||||
mut gs := gittools.new()!
|
||||
|
||||
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)!
|
||||
}
|
||||
|
||||
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}')
|
||||
}
|
||||
}
|
||||
|
||||
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}')
|
||||
}
|
||||
}
|
||||
site.factory.template_install(template_update:false, install:false, delete:false)!
|
||||
|
||||
cfg := site.config
|
||||
|
||||
profile_include := osal.profile_path_source()!
|
||||
mut myhome:="\$\{HOME\}" //for usage in bash
|
||||
|
||||
profile_include := osal.profile_path_source()!.replace(os.home_dir(),myhome)
|
||||
|
||||
mydir:=site.path_build.path.replace(os.home_dir(),myhome)
|
||||
|
||||
for item in ['src', 'static'] {
|
||||
mut aa := site.path_src.dir_get(item) or {continue}
|
||||
aa.copy(dest: '${site.factory.path_build.path}/${item}', delete:false)!
|
||||
|
||||
}
|
||||
|
||||
|
||||
develop := $tmpl('templates/develop.sh')
|
||||
build := $tmpl('templates/build.sh')
|
||||
@@ -313,4 +217,5 @@ fn (mut site DocSite) template_install() ! {
|
||||
mut build2_ := site.path_src.file_get_new('build.sh')!
|
||||
build2_.template_write(build, true)!
|
||||
build2_.chmod(0o700)!
|
||||
|
||||
}
|
||||
|
||||
110
lib/web/docusaurus/dsite_get.v
Normal file
110
lib/web/docusaurus/dsite_get.v
Normal file
@@ -0,0 +1,110 @@
|
||||
module docusaurus
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@[params]
|
||||
pub struct DSiteGetArgs {
|
||||
pub mut:
|
||||
name string
|
||||
nameshort string
|
||||
path string
|
||||
url string
|
||||
publish_path string
|
||||
build_path string
|
||||
production bool
|
||||
watch_changes bool = true
|
||||
update bool
|
||||
init bool //means create new one if needed
|
||||
deploykey string
|
||||
config ?Config
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
|
||||
console.print_header(' Docusaurus: ${args_.name}')
|
||||
mut args := args_
|
||||
|
||||
if args.build_path.len == 0 {
|
||||
args.build_path = '${f.path_build.path}'
|
||||
}
|
||||
// if args.publish_path.len == 0 {
|
||||
// args.publish_path = '${f.path_publish.path}/${args.name}'
|
||||
|
||||
// coderoot:"${os.home_dir()}/hero/var/publishcode"
|
||||
mut gs := gittools.new(ssh_key_path: args.deploykey)!
|
||||
|
||||
if args.url.len > 0 {
|
||||
args.path = gs.get_path(url: args.url)!
|
||||
}
|
||||
|
||||
if args.path.trim_space() == "" {
|
||||
args.path = os.getwd()
|
||||
}
|
||||
args.path = args.path.replace('~', os.home_dir())
|
||||
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
// First, check if the new site args provides a configuration that can be written instead of template cfg dir
|
||||
if cfg := args.config {
|
||||
panic("not implemented")
|
||||
// cfg.write('${args.path}/cfg')!
|
||||
} else {
|
||||
// Then ensure cfg directory exists in src,
|
||||
if !os.exists('${args.path}/cfg') {
|
||||
if args.init{
|
||||
// else copy config from template
|
||||
mut template_cfg := template_path.dir_get('cfg')!
|
||||
template_cfg.copy(dest: '${args.path}/cfg')!
|
||||
}else{
|
||||
return error("Can't find cfg dir in chosen docusaurus location: ${args.path}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !os.exists('${args.path}/docs') {
|
||||
if args.init{
|
||||
mut template_cfg := template_path.dir_get('docs')!
|
||||
template_cfg.copy(dest: '${args.path}/docs')!
|
||||
}else{
|
||||
return error("Can't find docs dir in chosen docusaurus location: ${args.path}")
|
||||
}
|
||||
}
|
||||
|
||||
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 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)!
|
||||
path_build: f.path_build
|
||||
// path_publish: pathlib.get_dir(path: args.publish_path, create: true)!
|
||||
args: args
|
||||
config: myconfig
|
||||
factory: &f
|
||||
}
|
||||
|
||||
ds.check()!
|
||||
|
||||
f.sites << &ds
|
||||
|
||||
return &ds
|
||||
}
|
||||
@@ -39,7 +39,7 @@ pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
|
||||
// path_publish: pathlib.get_dir(path: args_.publish_path, create: true)!
|
||||
}
|
||||
|
||||
ds.template_install(args.update)!
|
||||
ds.template_install(install:true,template_update:args.update,delete:true)!
|
||||
|
||||
return ds
|
||||
}
|
||||
@@ -5,30 +5,54 @@ import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.installers.web.bun
|
||||
import os
|
||||
|
||||
fn (mut site DocusaurusFactory) template_install(update bool) ! {
|
||||
@[params]
|
||||
struct TemplateInstallArgs{
|
||||
template_update bool = true
|
||||
install bool
|
||||
delete bool = true
|
||||
}
|
||||
|
||||
fn (mut self DocusaurusFactory) template_install(args TemplateInstallArgs) ! {
|
||||
mut gs := gittools.new()!
|
||||
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
pull: update
|
||||
pull: args.template_update
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
|
||||
for item in ['package.json', 'sidebars.ts', 'tsconfig.json'] {
|
||||
mut aa := template_path.file_get(item)!
|
||||
aa.copy(dest: '${site.path_build.path}/${item}')!
|
||||
aa.copy(dest: '${self.path_build.path}/${item}')!
|
||||
}
|
||||
|
||||
// install bun
|
||||
mut installer := bun.get()!
|
||||
installer.install()!
|
||||
// always start from template first
|
||||
for item in ['src', 'static'] {
|
||||
mut aa := template_path.dir_get(item)!
|
||||
aa.copy(dest: '${self.path_build.path}/${item}', delete: args.delete)!
|
||||
}
|
||||
|
||||
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(self.path_build.path, item)
|
||||
os.cp(src_path, dest_path) or {
|
||||
return error('Failed to copy ${item} to build path: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
if args.install{
|
||||
// install bun
|
||||
mut installer := bun.get()!
|
||||
installer.install()!
|
||||
|
||||
osal.exec(
|
||||
cmd: '
|
||||
${osal.profile_path_source_and()!}
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:${os.home_dir()}/.bun/bin/:??PATH
|
||||
cd ${self.path_build.path}
|
||||
bun install
|
||||
'
|
||||
)!
|
||||
}
|
||||
|
||||
osal.exec(
|
||||
cmd: '
|
||||
${osal.profile_path_source_and()!}
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:${os.home_dir()}/.bun/bin/:??PATH
|
||||
cd ${site.path_build.path}
|
||||
bun install
|
||||
'
|
||||
)!
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ cd "??{script_dir}"
|
||||
|
||||
echo "Docs directory: ??script_dir"
|
||||
|
||||
cd ${site.path_build.path}
|
||||
cd "${mydir}"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ cd "??{script_dir}"
|
||||
|
||||
echo "Docs directory: ??script_dir"
|
||||
|
||||
cd ${site.path_build.path}
|
||||
cd "${mydir}"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ cd "??{script_dir}"
|
||||
|
||||
echo "Docs directory: ??script_dir"
|
||||
|
||||
cd ${site.path_build.path}
|
||||
cd "${mydir}"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ cd "??{script_dir}"
|
||||
|
||||
echo "Docs directory: ??script_dir"
|
||||
|
||||
cd ${site.path_build.path}
|
||||
cd "${mydir}"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
|
||||
|
||||
|
||||
Reference in New Issue
Block a user