I'm using replace-in-files-cli
(specifically, the programmatic API) to prepend a banner to a bunch of files.
There are myriad packages to do this sort of thing, but they either a) expect the data to be in package.json
, b) are plugins for a task runner like grunt
, c) unmaintained, or d) hopelessly broken and overengineered. If you have written a standalone tool to do this, please let me know!
This is what "prepend to file" looks like:
const replace = require('replace-in-files-cli/api');
// let's pretend top-level await works
await replace('/path/to/file', {
find: [/^/], // <--------------------------
replacement: '/* my awesome banner */'
});
Whereas "append to file" looks like this:
const replace = require('replace-in-files-cli/api');
// let's pretend top-level await works
await replace('/path/to/file', {
find: [/$/g], // <------------------------
replacement: '/* my awesome banner */'
});
This isn't quite obvious. I had to play around with regexes to arrive at "append", which works opposite of how I'd expect--I'd expect a banner after every line (which can be accomplished with /$/gm
). Anyway.
append
and prepend
flags would be more user-friendly.append()
or prepend()
might be OK, except that a user may want to append/prepend and find/replace in a single operation--find
accepts an array, after all.Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too