🎨 Maintain repository structure
This commit is contained in:
parent
040e19b5f0
commit
a932333830
5 changed files with 43 additions and 27 deletions
|
@ -30,7 +30,7 @@ tasks:
|
|||
test:
|
||||
desc: Run test
|
||||
cmds:
|
||||
- v test .
|
||||
- v test commands/
|
||||
|
||||
vet:
|
||||
desc: Report suspicious code constructs
|
||||
|
@ -41,6 +41,8 @@ tasks:
|
|||
desc: Format .v files
|
||||
cmds:
|
||||
- v fmt -w *.v
|
||||
- v fmt -w commands/*.v
|
||||
- v fmt -w template/*.v
|
||||
|
||||
clean:
|
||||
desc: Clean test files
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module main
|
||||
module commands
|
||||
|
||||
import os
|
||||
import cli
|
||||
|
@ -20,37 +20,24 @@ const default_index = 'index.md'
|
|||
|
||||
const default_dist = 'dist'
|
||||
|
||||
fn main() {
|
||||
mut app := cli.Command{
|
||||
name: 'vss'
|
||||
version: '0.0.7'
|
||||
description: 'static site generator'
|
||||
fn new_build_cmd() cli.Command {
|
||||
return cli.Command{
|
||||
name: 'build'
|
||||
description: 'build your site'
|
||||
usage: 'vss build'
|
||||
execute: fn (cmd cli.Command) ? {
|
||||
println(cmd.help_message())
|
||||
build()?
|
||||
}
|
||||
commands: [
|
||||
cli.Command{
|
||||
name: 'build'
|
||||
description: 'build your site'
|
||||
usage: 'vss build'
|
||||
execute: fn (cmd cli.Command) ? {
|
||||
build()?
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
app.setup()
|
||||
app.parse(os.args)
|
||||
}
|
||||
|
||||
fn get_config_map() ?map[string]string {
|
||||
mut config_map := map[string]string{}
|
||||
|
||||
// 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 }
|
||||
config_map[param] = v.string()
|
||||
}
|
||||
|
@ -81,7 +68,7 @@ fn pre_proc_md_to_html(contents string) ?string {
|
|||
}
|
||||
|
||||
fn build() ? {
|
||||
dist := default_dist
|
||||
dist := commands.default_dist
|
||||
if os.exists(dist) {
|
||||
os.rmdir_all(dist)?
|
||||
os.mkdir_all(dist)?
|
||||
|
@ -90,11 +77,11 @@ fn build() ? {
|
|||
}
|
||||
|
||||
// copy static files
|
||||
if os.exists(defautl_static) {
|
||||
os.cp_all(defautl_static, dist, false)?
|
||||
if os.exists(commands.defautl_static) {
|
||||
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()?
|
||||
|
||||
md_paths := os.walk_ext('.', '.md')
|
20
commands/vss.v
Normal file
20
commands/vss.v
Normal file
|
@ -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)
|
||||
}
|
7
main.v
Normal file
7
main.v
Normal file
|
@ -0,0 +1,7 @@
|
|||
module main
|
||||
|
||||
import commands
|
||||
|
||||
fn main() {
|
||||
commands.execute()
|
||||
}
|
Loading…
Reference in a new issue