Skip to content

Commit

Permalink
fix: --force-Flag not working (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
about-code committed Oct 18, 2020
1 parent 14641cd commit 5084d36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
20 changes: 13 additions & 7 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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: ""
}
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions lib/cli/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 5084d36

Please sign in to comment.