From ae83cc146a82cf1c9d5e927a5d2baaf0a989ddea Mon Sep 17 00:00:00 2001 From: indaam Date: Tue, 28 Jul 2020 20:22:21 +0700 Subject: [PATCH 1/4] Add options main, to skip rendered when have dependencies --- README.md | 1 + index.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 677f9c3..60b6d88 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ input is taken from standard input and output to standard output. -w, --watch watch files for changes and automatically re-render -E, --extension specify the output file extension -s, --silent do not output logs +-m, --main Main File, Only render single main file when have dependencies --name-after-file name the template after the last section of the file path (requires --client and overriden by --name) --doctype specify the doctype on the command line (useful if it diff --git a/index.js b/index.js index 84cbe42..04988bc 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ program .option('-w, --watch', 'watch files for changes and automatically re-render') .option('-E, --extension ', 'specify the output file extension') .option('-s, --silent', 'do not output logs') + .option('-m, --main ', 'Main File, Only render when have dependencies') .option('--name-after-file', 'name the template after the last section of the file path (requires --client and overriden by --name)') .option('--doctype ', 'specify the doctype on the command line (useful if it is not specified by the template)') @@ -110,6 +111,7 @@ function parseObj (input) { ['pretty', 'pretty'], // --pretty ['basedir', 'basedir'], // --basedir ['doctype', 'doctype'], // --doctype + ['main', 'main'], // --main ].forEach(function (o) { options[o[1]] = program[o[0]] !== undefined ? program[o[0]] : options[o[1]]; }); @@ -185,9 +187,17 @@ function watchFile(path, base, rootPath) { if (curr.mtime.getTime() === 0) return; // istanbul ignore if if (curr.mtime.getTime() === prev.mtime.getTime()) return; - watchList[path].forEach(function(file) { - tryRender(file, rootPath); - }); + + if(options.main && watchList[path].length > 1){ + var mainFile = watchList[path].find( function(file){ + return file === options.main; + }) || watchList[path][0]; + tryRender(mainFile, rootPath); + }else{ + watchList[path].forEach(function(file) { + tryRender(file, rootPath); + }); + } }); } From 7b5ab94b86e4929bd9d8eb3c3bc795b482fbe8c4 Mon Sep 17 00:00:00 2001 From: indaam Date: Tue, 28 Jul 2020 20:37:58 +0700 Subject: [PATCH 2/4] Add options ignoreinitial, to skip render on first watch --- README.md | 1 + index.js | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 60b6d88..99e9e73 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ input is taken from standard input and output to standard output. -E, --extension specify the output file extension -s, --silent do not output logs -m, --main Main File, Only render single main file when have dependencies +-I, --ignoreinitial Skip first rendered on watch --name-after-file name the template after the last section of the file path (requires --client and overriden by --name) --doctype specify the doctype on the command line (useful if it diff --git a/index.js b/index.js index 04988bc..c9d6af0 100644 --- a/index.js +++ b/index.js @@ -40,6 +40,7 @@ program .option('-E, --extension ', 'specify the output file extension') .option('-s, --silent', 'do not output logs') .option('-m, --main ', 'Main File, Only render when have dependencies') + .option('-I, --ignoreinitial', 'Ignore render on first watch') .option('--name-after-file', 'name the template after the last section of the file path (requires --client and overriden by --name)') .option('--doctype ', 'specify the doctype on the command line (useful if it is not specified by the template)') @@ -77,6 +78,7 @@ program.on('--help', function(){ program.parse(process.argv); // options given, parse them +var count = 0; if (program.obj) { options = parseObj(program.obj); @@ -105,13 +107,14 @@ function parseObj (input) { } [ - ['path', 'filename'], // --path - ['debug', 'compileDebug'], // --no-debug - ['client', 'client'], // --client - ['pretty', 'pretty'], // --pretty - ['basedir', 'basedir'], // --basedir - ['doctype', 'doctype'], // --doctype - ['main', 'main'], // --main + ['path', 'filename'], // --path + ['debug', 'compileDebug'], // --no-debug + ['client', 'client'], // --client + ['pretty', 'pretty'], // --pretty + ['basedir', 'basedir'], // --basedir + ['doctype', 'doctype'], // --doctype + ['main', 'main'], // --main + ['ignoreinitial', 'ignoreinitial'], // --ignoreinitial ].forEach(function (o) { options[o[1]] = program[o[0]] !== undefined ? program[o[0]] : options[o[1]]; }); @@ -252,6 +255,7 @@ function stdin() { */ function renderFile(path, rootPath) { + program.ignoreinitial && count++; var isPug = /\.(?:pug|jade)$/; var isIgnored = /([\/\\]_)|(^_)/; @@ -273,6 +277,10 @@ function renderFile(path, rootPath) { }); } + if( program.ignoreinitial && program.watch && (count <= program.args.length)){ + return; + } + // --extension var extname; if (program.extension) extname = '.' + program.extension; From 3c78cde477c0bd3a894c6c877cbb3ce922b735f8 Mon Sep 17 00:00:00 2001 From: indaam Date: Thu, 30 Jul 2020 10:59:28 +0700 Subject: [PATCH 3/4] Add options ignoredependencies to skip render first watch --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c9d6af0..56b7fd8 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,7 @@ program .option('-s, --silent', 'do not output logs') .option('-m, --main ', 'Main File, Only render when have dependencies') .option('-I, --ignoreinitial', 'Ignore render on first watch') + .option('--ignoredependencies', 'Ignore dependencies on watch') .option('--name-after-file', 'name the template after the last section of the file path (requires --client and overriden by --name)') .option('--doctype ', 'specify the doctype on the command line (useful if it is not specified by the template)') @@ -115,6 +116,7 @@ function parseObj (input) { ['doctype', 'doctype'], // --doctype ['main', 'main'], // --main ['ignoreinitial', 'ignoreinitial'], // --ignoreinitial + ['ignoredependencies', 'ignoredependencies'], // --ignoreinitial ].forEach(function (o) { options[o[1]] = program[o[0]] !== undefined ? program[o[0]] : options[o[1]]; }); @@ -270,15 +272,21 @@ function renderFile(path, rootPath) { var fn = options.client ? pug.compileFileClient(path, options) : pug.compileFile(path, options); - if (program.watch && fn.dependencies) { + + // Add ignoredependencies for fast watching + if (program.watch && fn.dependencies && !program.ignoredependencies) { // watch dependencies, and recompile the base fn.dependencies.forEach(function (dep) { watchFile(dep, path, rootPath); }); } + // Only render main file when ignoreinitial if( program.ignoreinitial && program.watch && (count <= program.args.length)){ - return; + watchFile(program.main || program.args[0], null, rootPath); + if(count > 1){ + return; + } } // --extension From 821ef346be29c2e8db99decd366338e3926f5bac Mon Sep 17 00:00:00 2001 From: indaam Date: Mon, 3 Aug 2020 13:04:47 +0700 Subject: [PATCH 4/4] Add options only, to render only one file --- index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 56b7fd8..25388b7 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,7 @@ program .option('-m, --main ', 'Main File, Only render when have dependencies') .option('-I, --ignoreinitial', 'Ignore render on first watch') .option('--ignoredependencies', 'Ignore dependencies on watch') + .option('--only ', 'Only render one file') .option('--name-after-file', 'name the template after the last section of the file path (requires --client and overriden by --name)') .option('--doctype ', 'specify the doctype on the command line (useful if it is not specified by the template)') @@ -117,6 +118,7 @@ function parseObj (input) { ['main', 'main'], // --main ['ignoreinitial', 'ignoreinitial'], // --ignoreinitial ['ignoredependencies', 'ignoredependencies'], // --ignoreinitial + ['only', 'only'], // --only ].forEach(function (o) { options[o[1]] = program[o[0]] !== undefined ? program[o[0]] : options[o[1]]; }); @@ -152,9 +154,19 @@ if (files.length) { process.exit(1); }); } - files.forEach(function (file) { - render(file); - }); + + if(!!program.watch && options.only){ + render(options.only); + }else{ + files.forEach(function (file) { + if(!!program.watch && options.only){ + return render(options.only) + }else{ + render(file); + } + }); + } + // stdio } else { stdin();