From fd1d8ef26d05cd2d0f601c05ccbbacd71705366d Mon Sep 17 00:00:00 2001 From: zztkm Date: Sun, 14 Aug 2022 20:01:01 +0900 Subject: [PATCH] :loud_sound: add logs --- commands/build.v | 29 +++++++++++++++++++++-------- v.mod | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/commands/build.v b/commands/build.v index 0e05ab9..4e20ef8 100644 --- a/commands/build.v +++ b/commands/build.v @@ -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 } diff --git a/v.mod b/v.mod index 2529d2b..2113a58 100644 --- a/v.mod +++ b/v.mod @@ -1,7 +1,7 @@ Module { name: 'vss' description: 'static site generator' - version: '0.0.7' + version: '0.0.8' license: 'MIT' dependencies: [] }