Make --initial-indent be level number not number of spaces, make --wrap async
authorNick Downing <nick@ndcode.org>
Thu, 22 Nov 2018 12:25:50 +0000 (23:25 +1100)
committerNick Downing <nick@ndcode.org>
Thu, 22 Nov 2018 13:31:58 +0000 (00:31 +1100)
cli.js
jstize.js

diff --git a/cli.js b/cli.js
index a3ade7c..f9a1110 100755 (executable)
--- a/cli.js
+++ b/cli.js
@@ -7,24 +7,25 @@ let jstize = require('./jstize')
 commander
   .version('0.1.0', '-v, --version')
   .option('-i, --indent <n>', 'indent [2]', '2')
-  .option('-j, --initial-indent <n>', 'initial indent [0]', '0')
+  .option('-j, --initial-indent <n>', 'initial indent level [0]', '0')
   .option('-n, --name <str>', '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'})
index c73127b..c35351c 100644 (file)
--- 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(