🎨 Maintain repository structure

main
zztkm 2 years ago
parent 040e19b5f0
commit a932333830

@ -30,7 +30,7 @@ tasks:
test: test:
desc: Run test desc: Run test
cmds: cmds:
- v test . - v test commands/
vet: vet:
desc: Report suspicious code constructs desc: Report suspicious code constructs
@ -41,6 +41,8 @@ tasks:
desc: Format .v files desc: Format .v files
cmds: cmds:
- v fmt -w *.v - v fmt -w *.v
- v fmt -w commands/*.v
- v fmt -w template/*.v
clean: clean:
desc: Clean test files desc: Clean test files

@ -1,4 +1,4 @@
module main module commands
import os import os
import cli import cli
@ -20,37 +20,24 @@ const default_index = 'index.md'
const default_dist = 'dist' const default_dist = 'dist'
fn main() { fn new_build_cmd() cli.Command {
mut app := cli.Command{ return cli.Command{
name: 'vss'
version: '0.0.7'
description: 'static site generator'
execute: fn (cmd cli.Command) ? {
println(cmd.help_message())
}
commands: [
cli.Command{
name: 'build' name: 'build'
description: 'build your site' description: 'build your site'
usage: 'vss build' usage: 'vss build'
execute: fn (cmd cli.Command) ? { execute: fn (cmd cli.Command) ? {
build()? build()?
} }
},
]
} }
app.setup()
app.parse(os.args)
} }
fn get_config_map() ?map[string]string { fn get_config_map() ?map[string]string {
mut config_map := map[string]string{} mut config_map := map[string]string{}
// https://modules.vlang.io/toml.html // https://modules.vlang.io/toml.html
config := toml.parse_file(default_config)? config := toml.parse_file(commands.default_config)?
for param in config_params { for param in commands.config_params {
v := config.value_opt(param) or { continue } v := config.value_opt(param) or { continue }
config_map[param] = v.string() config_map[param] = v.string()
} }
@ -81,7 +68,7 @@ fn pre_proc_md_to_html(contents string) ?string {
} }
fn build() ? { fn build() ? {
dist := default_dist dist := commands.default_dist
if os.exists(dist) { if os.exists(dist) {
os.rmdir_all(dist)? os.rmdir_all(dist)?
os.mkdir_all(dist)? os.mkdir_all(dist)?
@ -90,11 +77,11 @@ fn build() ? {
} }
// copy static files // copy static files
if os.exists(defautl_static) { if os.exists(commands.defautl_static) {
os.cp_all(defautl_static, dist, false)? os.cp_all(commands.defautl_static, dist, false)?
} }
template_content := os.read_file(default_template)? template_content := os.read_file(commands.default_template)?
mut config_map := get_config_map()? mut config_map := get_config_map()?
md_paths := os.walk_ext('.', '.md') md_paths := os.walk_ext('.', '.md')

@ -0,0 +1,20 @@
module commands
import os
import cli
pub fn execute() {
mut app := cli.Command{
name: 'vss'
version: '0.0.7'
description: 'static site generator'
execute: fn (cmd cli.Command) ? {
println(cmd.help_message())
}
}
app.add_command(new_build_cmd())
app.setup()
app.parse(os.args)
}

@ -0,0 +1,7 @@
module main
import commands
fn main() {
commands.execute()
}
Loading…
Cancel
Save