atlas is working
This commit is contained in:
10
examples/data/atlas/heroscript_example.hero
Executable file
10
examples/data/atlas/heroscript_example.hero
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env hero
|
||||||
|
|
||||||
|
!!atlas.scan
|
||||||
|
path: '~/code/git.ourworld.tf/geomind/extranet_geomind'
|
||||||
|
meta_path: '/tmp/atlas_export_meta'
|
||||||
|
|
||||||
|
!!atlas.export
|
||||||
|
destination: '/tmp/atlas_export_test'
|
||||||
|
include: true
|
||||||
|
redis: true
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
|
||||||
|
|
||||||
import incubaid.herolib.core.playbook
|
|
||||||
import incubaid.herolib.data.atlas
|
|
||||||
|
|
||||||
heroscript := "
|
|
||||||
!!atlas.scan
|
|
||||||
path: '~/code/github/incubaid/herolib/lib/data/atlas/testdata'
|
|
||||||
|
|
||||||
!!atlas.validate
|
|
||||||
|
|
||||||
!!atlas.export
|
|
||||||
destination: '/tmp/atlas_export_test'
|
|
||||||
include: true
|
|
||||||
redis: false
|
|
||||||
"
|
|
||||||
|
|
||||||
mut plbook := playbook.new(text: heroscript)!
|
|
||||||
atlas.play(mut plbook)!
|
|
||||||
|
|
||||||
println('✅ Atlas HeroScript processing complete!')
|
|
||||||
@@ -39,6 +39,15 @@ pub fn cmd_atlas(mut cmdroot Command) Command {
|
|||||||
description: 'Path where atlas collections are located.'
|
description: 'Path where atlas collections are located.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cmd_run.add_flag(Flag{
|
||||||
|
flag: .string
|
||||||
|
required: false
|
||||||
|
name: 'path_meta'
|
||||||
|
abbrev: 'pm'
|
||||||
|
description: 'Path where collection.json... will be saved too.'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
cmd_run.add_flag(Flag{
|
cmd_run.add_flag(Flag{
|
||||||
flag: .string
|
flag: .string
|
||||||
required: false
|
required: false
|
||||||
@@ -111,6 +120,7 @@ fn cmd_atlas_execute(cmd Command) ! {
|
|||||||
|
|
||||||
// ---------- PATH LOGIC ----------
|
// ---------- PATH LOGIC ----------
|
||||||
mut path := cmd.flags.get_string('path') or { '' }
|
mut path := cmd.flags.get_string('path') or { '' }
|
||||||
|
mut path_meta := cmd.flags.get_string('path_meta') or { '' }
|
||||||
mut url := cmd.flags.get_string('url') or { '' }
|
mut url := cmd.flags.get_string('url') or { '' }
|
||||||
mut name := cmd.flags.get_string('name') or { 'default' }
|
mut name := cmd.flags.get_string('name') or { 'default' }
|
||||||
mut destination := cmd.flags.get_string('destination') or { '' }
|
mut destination := cmd.flags.get_string('destination') or { '' }
|
||||||
@@ -150,7 +160,7 @@ fn cmd_atlas_execute(cmd Command) ! {
|
|||||||
// Execute operations
|
// Execute operations
|
||||||
if scan {
|
if scan {
|
||||||
console.print_header('Scanning collections...')
|
console.print_header('Scanning collections...')
|
||||||
a.scan(path: atlas_path.path, save: true)!
|
a.scan(path: atlas_path.path, meta_path: path_meta)!
|
||||||
console.print_green('✓ Scan complete: ${a.collections.len} collection(s) found')
|
console.print_green('✓ Scan complete: ${a.collections.len} collection(s) found')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module playcmds
|
|||||||
|
|
||||||
import incubaid.herolib.core.playbook { PlayBook }
|
import incubaid.herolib.core.playbook { PlayBook }
|
||||||
import incubaid.herolib.data.doctree
|
import incubaid.herolib.data.doctree
|
||||||
|
import incubaid.herolib.data.atlas
|
||||||
import incubaid.herolib.biz.bizmodel
|
import incubaid.herolib.biz.bizmodel
|
||||||
import incubaid.herolib.threefold.incatokens
|
import incubaid.herolib.threefold.incatokens
|
||||||
import incubaid.herolib.web.site
|
import incubaid.herolib.web.site
|
||||||
@@ -59,7 +60,7 @@ pub fn run(args_ PlayArgs) ! {
|
|||||||
doctree.play(mut plbook)!
|
doctree.play(mut plbook)!
|
||||||
|
|
||||||
incatokens.play(mut plbook)!
|
incatokens.play(mut plbook)!
|
||||||
|
atlas.play(mut plbook)!
|
||||||
docusaurus.play(mut plbook)!
|
docusaurus.play(mut plbook)!
|
||||||
hetznermanager.play(mut plbook)!
|
hetznermanager.play(mut plbook)!
|
||||||
hetznermanager.play2(mut plbook)!
|
hetznermanager.play2(mut plbook)!
|
||||||
|
|||||||
@@ -85,13 +85,21 @@ pub fn (mut a Atlas) add_collection(args AddCollectionArgs) ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scan a path for collections
|
// Scan a path for collections
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct ScanArgs {
|
||||||
|
pub mut:
|
||||||
|
path string @[required]
|
||||||
|
meta_path string // where collection json files will be stored
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (mut a Atlas) scan(args ScanArgs) ! {
|
pub fn (mut a Atlas) scan(args ScanArgs) ! {
|
||||||
mut path := pathlib.get_dir(path: args.path)!
|
mut path := pathlib.get_dir(path: args.path)!
|
||||||
a.scan_directory(mut path)!
|
a.scan_directory(mut path)!
|
||||||
a.validate_links()!
|
a.validate_links()!
|
||||||
a.fix_links()!
|
a.fix_links()!
|
||||||
if args.save {
|
if args.meta_path.len > 0 {
|
||||||
a.save()!
|
a.save(args.meta_path)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := p.get('path')!
|
path := p.get('path')!
|
||||||
atlas_instance.scan(path: path, save: true)!
|
meta_path := p.get_default('meta_path', '')!
|
||||||
|
atlas_instance.scan(path: path, meta_path: meta_path)!
|
||||||
action.done = true
|
action.done = true
|
||||||
atlas_set(atlas_instance)
|
atlas_set(atlas_instance)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,50 +4,48 @@ import json
|
|||||||
import incubaid.herolib.core.pathlib
|
import incubaid.herolib.core.pathlib
|
||||||
|
|
||||||
// Save collection to .collection.json in the collection directory
|
// Save collection to .collection.json in the collection directory
|
||||||
pub fn (c Collection) save() ! {
|
pub fn (c Collection) save(path string) ! {
|
||||||
// json.encode automatically skips fields marked with [skip]
|
// json.encode automatically skips fields marked with [skip]
|
||||||
json_str := json.encode(c)
|
json_str := json.encode_pretty(c)
|
||||||
|
|
||||||
mut json_file := pathlib.get_file(
|
mut json_file := pathlib.get_file(
|
||||||
path: '${c.path.path}/.collection.json'
|
path: '${path}/${c.name}.json'
|
||||||
create: true
|
create: true
|
||||||
)!
|
)!
|
||||||
|
|
||||||
json_file.write(json_str)!
|
json_file.write(json_str)!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save all collections in atlas to their respective directories
|
// Save all collections in atlas to their respective directories
|
||||||
pub fn (a Atlas) save() ! {
|
pub fn (a Atlas) save(path string) ! {
|
||||||
for _, col in a.collections {
|
for _, col in a.collections {
|
||||||
col.save()!
|
col.save(path)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load collection from .collection.json file
|
// // Load collection from .collection.json file
|
||||||
pub fn (mut a Atlas) load_collection(path string) !&Collection {
|
// pub fn (mut a Atlas) load_meta(path string) !&Collection {
|
||||||
mut json_file := pathlib.get_file(path: '${path}/.collection.json')!
|
// mut json_file := pathlib.get_file(path: '${path}/.collection.json')!
|
||||||
json_str := json_file.read()!
|
// json_str := json_file.read()!
|
||||||
|
|
||||||
mut col := json.decode(Collection, json_str)!
|
// mut col := json.decode(Collection, json_str)!
|
||||||
|
|
||||||
// Fix circular references that were skipped during encode
|
// // Fix circular references that were skipped during encode
|
||||||
col.atlas = &a
|
// col.atlas = &a
|
||||||
|
|
||||||
// Rebuild error cache from errors
|
// // Rebuild error cache from errors
|
||||||
col.error_cache = map[string]bool{}
|
// col.error_cache = map[string]bool{}
|
||||||
for err in col.errors {
|
// for err in col.errors {
|
||||||
col.error_cache[err.hash()] = true
|
// col.error_cache[err.hash()] = true
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Fix page references to collection
|
// // Fix page references to collection
|
||||||
for name, mut page in col.pages {
|
// for name, mut page in col.pages {
|
||||||
page.collection = &col
|
// page.collection = &col
|
||||||
col.pages[name] = page
|
// col.pages[name] = page
|
||||||
}
|
// }
|
||||||
|
|
||||||
a.collections[col.name] = &col
|
// a.collections[col.name] = &col
|
||||||
return &col
|
// return &col
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Load all collections from a directory tree
|
// Load all collections from a directory tree
|
||||||
pub fn (mut a Atlas) load_from_directory(path string) ! {
|
pub fn (mut a Atlas) load_from_directory(path string) ! {
|
||||||
@@ -58,10 +56,10 @@ pub fn (mut a Atlas) load_from_directory(path string) ! {
|
|||||||
// Scan directory for .collection.json files and load them
|
// Scan directory for .collection.json files and load them
|
||||||
fn (mut a Atlas) scan_and_load(mut dir pathlib.Path) ! {
|
fn (mut a Atlas) scan_and_load(mut dir pathlib.Path) ! {
|
||||||
// Check if this directory has .collection.json
|
// Check if this directory has .collection.json
|
||||||
if dir.file_exists('.collection.json') {
|
// if dir.file_exists('.collection.json') {
|
||||||
a.load_collection(dir.path)!
|
// a.load_collection(dir.path)!
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Scan subdirectories
|
// Scan subdirectories
|
||||||
mut entries := dir.list(recursive: false)!
|
mut entries := dir.list(recursive: false)!
|
||||||
|
|||||||
@@ -5,13 +5,6 @@ import incubaid.herolib.data.paramsparser
|
|||||||
import incubaid.herolib.core.texttools
|
import incubaid.herolib.core.texttools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct ScanArgs {
|
|
||||||
pub mut:
|
|
||||||
path string @[required]
|
|
||||||
save bool = true // save atlas after scan
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan a directory for collections
|
// Scan a directory for collections
|
||||||
fn (mut a Atlas) scan_directory(mut dir pathlib.Path) ! {
|
fn (mut a Atlas) scan_directory(mut dir pathlib.Path) ! {
|
||||||
if !dir.is_dir() {
|
if !dir.is_dir() {
|
||||||
|
|||||||
Reference in New Issue
Block a user