🔊 add logs

This commit is contained in:
zztkm 2022-08-14 20:01:01 +09:00
parent 309125fd03
commit fd1d8ef26d
2 changed files with 22 additions and 9 deletions

View file

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

2
v.mod
View file

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