From 3bbf655514f437b19ccb74d130c2275ab9db27b5 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 22 Nov 2018 23:25:50 +1100 Subject: [PATCH] Make --initial-indent be level number not number of spaces, make --wrap async --- cli.js | 17 +++++++++-------- jstize.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cli.js b/cli.js index a3ade7c..f9a1110 100755 --- a/cli.js +++ b/cli.js @@ -7,24 +7,25 @@ let jstize = require('./jstize') commander .version('0.1.0', '-v, --version') .option('-i, --indent ', 'indent [2]', '2') - .option('-j, --initial-indent ', 'initial indent [0]', '0') + .option('-j, --initial-indent ', 'initial indent level [0]', '0') .option('-n, --name ', 'message for --wrap [page.jst]', 'page.jst') - .option('-w, --wrap', 'wrap as jst_server template function', false) + .option('-w, --wrap', 'wrap as jst_server template function') .parse(process.argv) let indent = parseInt(commander.indent) let initial_indent = parseInt(commander.initialIndent) +let wrap = commander.wrap || false let text = jstize( fs.readFileSync(0, {encoding: 'utf-8'}), { indent: indent, - initial_indent: initial_indent + commander.wrap ? indent : 0 + initial_indent: initial_indent + wrap } ) -if (commander.wrap) - text = `${' '.repeat(initial_indent)}return env => { -${' '.repeat(initial_indent)} let _out = [] -${text}${' '.repeat(initial_indent)} _site.serve(env, 200, Buffer.from(_out.join('')), '${commander.name}') -${' '.repeat(initial_indent)}} +if (wrap) + text = `${' '.repeat(indent * initial_indent)}return async env => { +${' '.repeat(indent * (initial_indent + 1))}let _out = [] +${text}${' '.repeat(indent * (initial_indent + 1))}_site.serve(env, 200, Buffer.from(_out.join('')), '${commander.name}') +${' '.repeat(indent * initial_indent)}} ` fs.writeSync(1, text, {encoding: 'utf-8'}) diff --git a/jstize.js b/jstize.js index c73127b..c35351c 100644 --- a/jstize.js +++ b/jstize.js @@ -14,7 +14,7 @@ let jstize = (text, options) => { options || {} ) let tags = [] - let indent = options.initial_indent + let indent = options.indent * options.initial_indent let buffer = [] let parse = text => { new html_minifier.HTMLParser( -- 2.34.1