Replaces strings in files. Useful creating a npm only build pipeline. Inspired by https://github.com/harthur/replace .
Strings can be replaced by other strings, environment variables and the current git version hash (SHA).
Does not follow symlinks.
npm install -g replacestuff
To see all options
replacestuff --help
In-place replace:
replacestuff s1 s2 dist/**/*.html
Different output folder
replacestuff s1 s2 **/* --basedir=build --output=dist/
If there are several strings to replace, it's better to use a replacestuff.json
file.
[
{ search: 'search0', replace: 'replace0' },
{ searchRegExp: 'search1', replace: 'replace1' },
{ search: 'search2', replaceVar: 'gitsha' },
{ search: 'search3', replaceEnv: 'replace3' }
]
In this example
- the string 'search' will be replaced by 'replace0'.
- strings matching the regular expression 'search1' will be replaced by 'replace1'.
- the string 'search2' will be replaced by the current git version hash.
- the string 'search3' will be replaced by the value of the environment variable 'replace3'.
Keep in mind that each replacement happens in the same order as in the replacestuff.json
.
npm test
npm run dev:watch
npm version major|minor|patch
npm publish
git push
rules
Copyright (c) 2016 Wouter Mooij.
Licensed under the MIT License.