From 0f3eb48132aada92f195850f901a521e6f2a4506 Mon Sep 17 00:00:00 2001 From: mde Date: Thu, 23 Apr 2020 21:21:31 -0700 Subject: [PATCH] Camelize all CLI opts internally --- bin/cli.js | 19 ++++++++++++------- package.json | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index da302e76..e2fc852a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -107,16 +107,21 @@ function run() { program.availableOpts = CLI_OPTS; program.parseArgs(args); - let pOpts = program.opts; - let pVals = program.envVars; let templatePath = program.taskNames[0]; + let pVals = program.envVars; + let pOpts = {}; + + for (let p in program.opts) { + let name = p.replace(/-[a-z]/g, (match) => { return match[1].toUpperCase(); }); + pOpts[name] = program.opts[p]; + } let opts = {}; let vals = {}; // Same-named 'passthrough' opts CLI_OPTS.forEach((opt) => { - let optName = opt.full.replace(/-[a-z]/g, (match) => { return match[1].toUpperCase(); }); + let optName = opt.full; if (opt.passThrough && typeof pOpts[optName] != 'undefined') { opts[optName] = pOpts[optName]; } @@ -142,8 +147,8 @@ function run() { } // Read the data from any data file - if (pOpts['data-file']) { - vals = JSON.parse(fs.readFileSync(pOpts['data-file']).toString()); + if (pOpts.dataFile) { + vals = JSON.parse(fs.readFileSync(pOpts.dataFile).toString()); } // Override / set any values passed from the command line for (let p in pVals) { @@ -152,8 +157,8 @@ function run() { let template = fs.readFileSync(templatePath).toString(); let output = ejs.render(template, vals, opts); - if (pOpts['output-file']) { - fs.writeFileSync(pOpts['output-file'], output); + if (pOpts.outputFile) { + fs.writeFileSync(pOpts.outputFile, output); } else { process.stdout.write(output); diff --git a/package.json b/package.json index 5fdce2d6..bf357314 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "bugs": "https://github.com/mde/ejs/issues", "homepage": "https://github.com/mde/ejs", "dependencies": { - "jake": "^10.5.2" + "jake": "^10.6.1" }, "devDependencies": { "browserify": "^16.5.1",