Update readme, fix line length

This commit is contained in:
Adam Reis
2017-08-25 07:34:56 +12:00
parent 508ad44b09
commit dae627324e
2 changed files with 12 additions and 7 deletions

View File

@@ -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.

View File

@@ -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);