From 5084d36b263b0a8f168aaf35be357bc2d05af79a Mon Sep 17 00:00:00 2001 From: about-code <6525873+about-code@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:40:57 +0200 Subject: [PATCH] fix: --force-Flag not working (#103) --- bin/index.js | 20 +++++++++++++------- lib/cli/messages.js | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/index.js b/bin/index.js index fac06530..0dcf7e89 100755 --- a/bin/index.js +++ b/bin/index.js @@ -6,7 +6,7 @@ const path = require("path"); const proc = require("process"); const program = require("../lib/main"); const confSchema = require("../conf.schema.json").properties; -const {NO_BASEDIR, NO_OUTDIR, OUTDIR_IS_BASEDIR, OUTDIR_NOT_DELETED} = require("../lib/cli/messages"); +const {NO_BASEDIR, NO_OUTDIR, OUTDIR_IS_BASEDIR, OUTDIR_NOT_DELETED, OUTDIR_IS_BASEDIR_WITH_DROP} = require("../lib/cli/messages"); const {version} = require("../package.json"); const CWD = proc.cwd(); @@ -27,13 +27,13 @@ const cli = { } ,"shallow": { alias: "" - ,description: "Shallow-merge the given configuration string with the configuration file or default configuration. Shallow merging with replace nested property values. Use --deep to deep-merge." + ,description: "Shallow-merge the given JSON configuration string with the configuration file or default configuration. Shallow merging with replace nested property values. Use --deep to deep-merge." ,type: "string" ,default: "" } ,"deep": { alias: "" - ,description: "Deeply merge the given configuration string with the configuration file or default configuration. This will with extend nested arrays and replace only those keys exactly matching with the given structure." + ,description: "Deeply merge the given JSON configuration string with the configuration file or default configuration. This will with extend nested arrays and replace only those keys exactly matching with the given structure." ,type: "string" ,default: "" } @@ -133,10 +133,16 @@ function validateOpts(conf) { console.log(`☛ Reading from: ${conf.baseDir}`); console.log(`☛ Writing to: ${conf.outDir}\n`); - if (conf.outDir === conf.baseDir && !conf.force) { - console.log(OUTDIR_IS_BASEDIR); - console.log("ABORTED.\n"); - proc.exit(0); + if (conf.outDir === conf.baseDir) { + if (conf.outDirDropOld) { + console.log(OUTDIR_IS_BASEDIR_WITH_DROP); + console.log("ABORTED.\n"); + proc.exit(0); + } else if (!argv.force) { + console.log(OUTDIR_IS_BASEDIR); + console.log("ABORTED.\n"); + proc.exit(0); + } } } diff --git a/lib/cli/messages.js b/lib/cli/messages.js index 04b3efe8..0427da46 100644 --- a/lib/cli/messages.js +++ b/lib/cli/messages.js @@ -11,20 +11,28 @@ See --help for details. `; const OUTDIR_IS_BASEDIR = -`⚠ Warning: --baseDir and --outDir resolve to the same directory. -Such a config is going to overwrite input files in --baseDir. -Choose a different --outDir or change config provided via --config. +`⚠ Warning: "baseDir" and "outDir" resolve to the same directory. +This is going to overwrite input files in "baseDir". Choose a different +"outDir" or change config provided via --config. + Use --force if you want to proceed with current settings. See --help for details. `; +const OUTDIR_IS_BASEDIR_WITH_DROP = +`⚠ Error: "baseDir" and "outDir" resolve to the same directory. Cannot apply +"outDirDropOld: true". It would delete the input files in "baseDir". Choose +a different "outDir" or configure "outDirDropOld: false". +`; + const OUTDIR_NOT_DELETED = -`⚠ Could not delete --outDir. Will proceed by copying files... +`⚠ Could not delete "outDir". Will proceed by copying files... `; module.exports = { NO_BASEDIR ,NO_OUTDIR ,OUTDIR_IS_BASEDIR + ,OUTDIR_IS_BASEDIR_WITH_DROP ,OUTDIR_NOT_DELETED };