🔊 add logs

main
zztkm 2 years ago
parent 309125fd03
commit fd1d8ef26d

@ -28,17 +28,27 @@ fn new_build_cmd() cli.Command {
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()? mut logger := log.Log{}
logger.set_level(log.Level.info)
build(mut logger) or {
logger.error(err.msg())
println("Build failed")
}
} }
} }
} }
fn read_file(filename string) ?string {
contents := os.read_file(filename.trim_space())?
return contents
}
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(commands.default_config)? toml_str := read_file(commands.default_config)?
config := toml.parse_text(toml_str)?
for param in commands.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()
@ -69,22 +79,23 @@ fn pre_proc_md_to_html(contents string) ?string {
return parsed_lines.join('\n') return parsed_lines.join('\n')
} }
fn build() ? { fn build(mut logger log.Log) ? {
mut logger := log.Log{} println("Start building")
logger.set_level(log.Level.info)
logger.info()
mut sw := time.new_stopwatch() mut sw := time.new_stopwatch()
dist := commands.default_dist dist := commands.default_dist
if os.exists(dist) { if os.exists(dist) {
logger.info("re-create dist dir")
os.rmdir_all(dist)? os.rmdir_all(dist)?
os.mkdir_all(dist)? os.mkdir_all(dist)?
} else { } else {
logger.info("create dist dir")
os.mkdir_all(dist)? os.mkdir_all(dist)?
} }
// copy static files // copy static files
if os.exists(commands.defautl_static) { if os.exists(commands.defautl_static) {
logger.info("copy static files")
os.cp_all(commands.defautl_static, dist, false)? os.cp_all(commands.defautl_static, dist, false)?
} }
@ -92,6 +103,7 @@ fn build() ? {
mut config_map := get_config_map()? mut config_map := get_config_map()?
md_paths := os.walk_ext('.', '.md') md_paths := os.walk_ext('.', '.md')
logger.info("start md to html")
for path in md_paths { for path in md_paths {
mut md := os.read_file(path)? mut md := os.read_file(path)?
md = pre_proc_md_to_html(md)? md = pre_proc_md_to_html(md)?
@ -102,8 +114,9 @@ fn build() ? {
html_path := os.join_path(dist, filename) html_path := os.join_path(dist, filename)
os.write_file(html_path, html)? os.write_file(html_path, html)?
} }
logger.info("end md to html")
sw.stop() sw.stop()
println(sw.elapsed().seconds()) println("Total in " + sw.elapsed().milliseconds().str() + " ms")
return return
} }

@ -1,7 +1,7 @@
Module { Module {
name: 'vss' name: 'vss'
description: 'static site generator' description: 'static site generator'
version: '0.0.7' version: '0.0.8'
license: 'MIT' license: 'MIT'
dependencies: [] dependencies: []
} }

Loading…
Cancel
Save