diff --git a/README.md b/README.md index ed9a3e6..9a9934b 100644 --- a/README.md +++ b/README.md @@ -133,10 +133,15 @@ const changedFiles = replace.sync({ ### CLI usage ```sh -replace-in-file from to some/file.js,some/**/glob.js --ignore=ignore/files.js,ignore/**/glob.js [--isRegex] +replace-in-file from to some/file.js,some/**/glob.js + [--ignore=ignore/files.js,ignore/**/glob.js] + [--encoding=utf-8] + [--allowEmptyPaths] + [--isRegex] + [--verbose] ``` -The flags `allowEmptyPaths` and `encoding` are supported in the CLI. +The flags `allowEmptyPaths`, `ignore` and `encoding` are supported in the CLI. In addition, the CLI supports the `verbose` flag to list the changed files. Multiple files or globs can be replaced by providing a comma separated list. diff --git a/lib/replace-in-file.js b/lib/replace-in-file.js index 2e88af1..fc3bf9d 100644 --- a/lib/replace-in-file.js +++ b/lib/replace-in-file.js @@ -13,7 +13,7 @@ const chalk = require('chalk'); const defaults = { allowEmptyPaths: false, encoding: 'utf-8', - ignore: [] + ignore: [], }; /** @@ -201,11 +201,11 @@ function replaceInFile(config, cb) { const allowEmptyPaths = config.allowEmptyPaths; const ignore = config.ignore; const globs = Array.isArray(files) ? files : [files]; - const ignoreGlobs = Array.isArray(ignore) ? ignore : [ignore]; + const ignored = Array.isArray(ignore) ? ignore : [ignore]; //Find files return Promise - .all(globs.map(pattern => globPromise(pattern, ignoreGlobs, allowEmptyPaths))) + .all(globs.map(pattern => globPromise(pattern, ignored, allowEmptyPaths))) //Flatten array .then(files => [].concat.apply([], files)) @@ -257,13 +257,13 @@ replaceInFile.sync = function(config) { const encoding = config.encoding; const ignore = config.ignore; const globs = Array.isArray(files) ? files : [files]; - const ignoreGlobs = Array.isArray(ignore) ? ignore : [ignore]; + const ignored = Array.isArray(ignore) ? ignore : [ignore]; const changedFiles = []; //Process synchronously globs.forEach(pattern => { glob - .sync(pattern, {ignore: ignoreGlobs, nodir: true}) + .sync(pattern, {ignore: ignored, nodir: true}) .forEach(file => { if (replaceSync(file, from, to, encoding)) { changedFiles.push(file);