mirror of
https://github.com/zhigang1992/replace-in-file.git
synced 2026-01-12 22:51:48 +08:00
Update readme, fix line length
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user