Skip to content

Commit

Permalink
[doc] #94 Add more info on using globs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreisnz committed Apr 25, 2020
1 parent 2545bc4 commit f94e466
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ A simple utility to quickly replace text in one or more files or globs. Works sy
- [Specify character encoding](#specify-character-encoding)
- [Dry run](#dry-run)
- [CLI usage](#cli-usage)
- [A note on using globs with the CLI](#a-note-on-using-globs-with-the-cli)
- [Version information](#version-information)
- [License](#license)

Expand Down Expand Up @@ -424,6 +425,44 @@ information in a configuration file. You can provide a path to a configuration f
(either Javascript or JSON) with the `--configFile` flag. This path will be resolved using
Node’s built in `path.resolve()`, so you can pass in an absolute or relative path.

## A note on using globs with the CLI
When using the CLI, the glob pattern is handled by the operating system. But if you specify the glob pattern in the configuration file, the package will use the glob module from the Node modules, and this can lead to different behaviour despite using the same pattern.

For example, the following will only look at top level files:

```js
//config.js
module.exports = {
from: /cat/g,
to: 'dog',
};
```

```sh
replace-in-file ** --configFile=config.js
```

However, this example is recursive:

```js
//config.js
module.exports = {
files: '**',
from: /cat/g,
to: 'dog',
};
```

```sh
replace-in-file --configFile=config.js
```

If you want to do a recursive file search as an argument you must use:

```sh
replace-in-file $(ls l {,**/}*) --configFile=config.js
```

## Version information
From version 3.0.0 onwards, replace in file requires Node 6 or higher. If you need support for Node 4 or 5, please use version 2.x.x.

Expand Down

0 comments on commit f94e466

Please sign in to comment.