From fea93cb1bfc1205d917d3acc7d9beeaac10f39f4 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 22 Dec 2022 05:23:59 +0700 Subject: [PATCH] Add some simple stats at the end to help with progress, but give a --quiet option if you don't want that. --- commands/codedoc.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/commands/codedoc.js b/commands/codedoc.js index 83f5166..2754026 100644 --- a/commands/codedoc.js +++ b/commands/codedoc.js @@ -2,11 +2,10 @@ import fs from "fs"; import assert from "assert"; import logging from '../lib/logging.js'; -import { mkdir, mkdir_to, glob } from "../lib/builderator.js"; +import { mkdir_to, glob } from "../lib/builderator.js"; import { create_renderer } from "../lib/docgen.js"; import path from "path"; import slugify from "slugify"; -import template from "lodash/template.js"; import * as acorn from "acorn"; import * as acorn_walk from "acorn-walk"; @@ -16,6 +15,7 @@ export const description = "Describe your command here." // your command uses the npm package commander's options format export const options = [ + ["--quiet", "Don't output the stats at the end."] ] // example of a positional argument, it's the 1st argument to main @@ -28,6 +28,7 @@ export const required = [ const RENDERER = create_renderer(); const CAPS_WORDS = ["BUG", "TODO", "WARNING", "FOOTGUN", "DEPRECATED"]; +const STATS = {total: 0, docs: 0, undoc: 0}; const slug = (instring) => slugify(instring, { lower: true, strict: true, trim: true}); @@ -98,6 +99,7 @@ class ParseWalker { new_method.code = this.slice_code(new_method.range); + this.update_stats(new_method); // methods can't go through add_export new_class.methods.push(new_method); } }); @@ -142,6 +144,16 @@ class ParseWalker { } } + update_stats(exp) { + STATS.total += 1; + + if(exp.comment) { + STATS.docs += 1; + } else { + STATS.undoc += 1; + } + } + add_export(id, exp) { exp.name = id.name; exp.slug = exp.slug ? exp.slug : slug(id.name); @@ -150,6 +162,8 @@ class ParseWalker { this.has_CAPS(exp); exp.code = this.slice_code(exp.range); this.exported.push(exp); + + this.update_stats(exp); } slice_code(range) { @@ -314,5 +328,13 @@ export const main = async (source_globs, opts) => { // now write the grand index const index_name = path.join(opts.output, "index.json"); fs.writeFileSync(index_name, dump(index)); + + + const percent = Math.floor(100 * STATS.docs / STATS.total); + + if(!opts.quiet) { + console.log(`Total ${STATS.total}, ${percent}% documented (${STATS.docs} docs vs. ${STATS.undoc} no docs).`); + } + process.exit(0); }