From a1cdebaabc175572871d08f06df045bfc431398c Mon Sep 17 00:00:00 2001 From: ge Date: Thu, 15 May 2025 09:46:08 +0300 Subject: [PATCH] init --- .editorconfig | 8 ++++++++ .gitattributes | 8 ++++++++ .gitignore | 24 ++++++++++++++++++++++++ v.mod | 7 +++++++ vdocserve.v | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 v.mod create mode 100644 vdocserve.v diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..01072ca --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.v] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9a98968 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +* text=auto eol=lf +*.bat eol=crlf + +*.v linguist-language=V +*.vv linguist-language=V +*.vsh linguist-language=V +v.mod linguist-language=V +.vdocignore linguist-language=ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d9e735 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Binaries for programs and plugins +main +vdocserve +*.exe +*.exe~ +*.so +*.dylib +*.dll + +# Ignore binary output folders +bin/ + +# Ignore common editor/system specific metadata +.DS_Store +.idea/ +.vscode/ +*.iml + +# ENV +.env + +# vweb and database +*.db +*.js diff --git a/v.mod b/v.mod new file mode 100644 index 0000000..0bc8749 --- /dev/null +++ b/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'vdocserve' + description: 'Generate and serve module documentation' + version: '0.1.0' + license: 'MIT' + dependencies: [] +} diff --git a/vdocserve.v b/vdocserve.v new file mode 100644 index 0000000..a4e0578 --- /dev/null +++ b/vdocserve.v @@ -0,0 +1,42 @@ +module main + +import flag +import log +import net.http.file +import os +import rand +import v.vmod + +fn main() { + mut fp := flag.new_flag_parser(os.args) + fp.application('vdocserve') + fp.description('generate and serve V module HTML documentation') + fp.version('0.1.0') + fp.skip_executable() + fp.limit_free_args(0, 2)! + listen := fp.string('listen', u8(`l`), '127.0.0.1:4000', 'HTTP server listen address:port') + fp.finalize() or { + eprintln(err) + println(fp.usage()) + exit(1) + } + mut cache := vmod.get_cache() + modfile := cache.get_by_folder(os.getwd()) + modname := vmod.from_file(modfile.vmod_file)!.name + docs_dir := os.join_path(os.temp_dir(), os.geteuid().str(), modname + '_docs_' + + rand.u16().hex()) + log.info('generating HTML docs in temporary dir ${docs_dir}') + os.mkdir_all(docs_dir, mode: 0o755)! + os.execute_or_exit('v doc -f html -o ${docs_dir} -m . ') + sigint_callback := fn [docs_dir] (_ os.Signal) { + os.rmdir_all(docs_dir) or { + log.error('unable to delete temporary dir ${docs_dir}') + exit(1) + } + eprintln('cleanup temporary data') + exit(0) + } + os.signal_opt(.int, sigint_callback)! + log.info('starting docs server, use ^C to quit') + file.serve(folder: docs_dir, index_file: modname + '.html', on: listen) +}