2022-08-13 14:44:21 +02:00
|
|
|
module main
|
|
|
|
|
2023-08-07 01:03:23 +02:00
|
|
|
import os
|
|
|
|
import cli
|
2023-08-08 16:11:00 +02:00
|
|
|
import log
|
2022-08-13 14:44:21 +02:00
|
|
|
import commands
|
2023-08-08 16:11:00 +02:00
|
|
|
import internal.config
|
2022-08-13 14:44:21 +02:00
|
|
|
|
2023-08-07 01:03:23 +02:00
|
|
|
const version = '0.3.0'
|
|
|
|
|
2023-08-08 16:11:00 +02:00
|
|
|
const default_config = 'config.toml'
|
|
|
|
|
|
|
|
// load_config loads a toml config file
|
|
|
|
fn load_config(toml_file string) !config.Config {
|
|
|
|
toml_text := os.read_file(toml_file)!
|
|
|
|
return config.load(toml_text)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn init_logger() log.Log {
|
|
|
|
return log.Log{
|
|
|
|
level: log.Level.info
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn init_commands() cli.Command {
|
|
|
|
return cli.Command{
|
2023-08-07 01:03:23 +02:00
|
|
|
name: 'vss'
|
|
|
|
version: version
|
|
|
|
description: 'static site generator'
|
|
|
|
execute: fn (cmd cli.Command) ! {
|
|
|
|
println(cmd.help_message())
|
|
|
|
}
|
2023-08-08 16:11:00 +02:00
|
|
|
commands: [
|
|
|
|
cli.Command{
|
|
|
|
name: 'build'
|
|
|
|
description: 'build your site'
|
|
|
|
usage: 'vss build'
|
|
|
|
execute: fn (cmd cli.Command) ! {
|
|
|
|
mut logger := init_logger()
|
|
|
|
conf := load_config(default_config)!
|
|
|
|
mut c := commands.new_build_cmd(conf, logger)
|
|
|
|
c.run() or {
|
|
|
|
logger.error(err.msg())
|
|
|
|
println('build failed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cli.Command{
|
|
|
|
name: 'serve'
|
|
|
|
description: 'serve dist'
|
|
|
|
usage: 'vss serve'
|
|
|
|
execute: fn (cmd cli.Command) ! {
|
|
|
|
mut logger := init_logger()
|
|
|
|
conf := load_config(default_config)!
|
|
|
|
mut c := commands.new_serve_cmd(conf, logger)
|
|
|
|
c.run() or {
|
|
|
|
logger.error(err.msg())
|
|
|
|
println('serve failed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
2023-08-07 01:03:23 +02:00
|
|
|
}
|
2023-08-08 16:11:00 +02:00
|
|
|
}
|
2023-08-07 01:03:23 +02:00
|
|
|
|
2023-08-08 16:11:00 +02:00
|
|
|
fn main() {
|
|
|
|
mut app := init_commands()
|
2023-08-07 01:03:23 +02:00
|
|
|
app.setup()
|
|
|
|
app.parse(os.args)
|
2022-08-13 14:44:21 +02:00
|
|
|
}
|