replace-in-files-cli
Advanced tools
Comparing version 1.0.0 to 2.0.0
26
api.js
@@ -1,12 +0,10 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const normalizePath = process.platform === 'win32' ? require('normalize-path') : x => x; | ||
const writeFileAtomic = require('write-file-atomic'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const arrify = require('arrify'); | ||
const globby = require('globby'); | ||
import process from 'node:process'; | ||
import path from 'node:path'; | ||
import {promises as fsPromises} from 'node:fs'; | ||
import normalizePath_ from 'normalize-path'; | ||
import writeFileAtomic from 'write-file-atomic'; | ||
import escapeStringRegexp from 'escape-string-regexp'; | ||
import {globby} from 'globby'; | ||
const readFile = promisify(fs.readFile); | ||
const normalizePath = process.platform === 'win32' ? normalizePath_ : x => x; | ||
@@ -16,4 +14,4 @@ // TODO(sindresorhus): I will extract this to a separate module at some point when it's more mature. | ||
// The `ignoreCase` option overrides the `i` flag for regexes in `find` | ||
module.exports = async (filePaths, {find, replacement, ignoreCase, glob} = {}) => { | ||
filePaths = arrify(filePaths); | ||
export default async function replaceInFiler(filePaths, {find, replacement, ignoreCase, glob} = {}) { | ||
filePaths = [filePaths].flat(); | ||
@@ -52,3 +50,3 @@ if (filePaths.length === 0) { | ||
await Promise.all(filePaths.map(async filePath => { | ||
const string = await readFile(filePath, 'utf8'); | ||
const string = await fsPromises.readFile(filePath, 'utf8'); | ||
@@ -66,2 +64,2 @@ let newString = string; | ||
})); | ||
}; | ||
} |
28
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
const meow = require('meow'); | ||
const replaceInFiles = require('./api'); | ||
import process from 'node:process'; | ||
import meow from 'meow'; | ||
import replaceInFiles from './api.js'; | ||
@@ -24,24 +24,25 @@ const cli = meow(` | ||
`, { | ||
importMeta: import.meta, | ||
flags: { | ||
regex: { | ||
type: 'string', | ||
isMultiple: true | ||
isMultiple: true, | ||
}, | ||
string: { | ||
type: 'string', | ||
isMultiple: true | ||
isMultiple: true, | ||
}, | ||
replacement: { | ||
type: 'string', | ||
isRequired: true | ||
isRequired: true, | ||
}, | ||
ignoreCase: { | ||
type: 'boolean', | ||
default: false | ||
default: false, | ||
}, | ||
glob: { | ||
type: 'boolean', | ||
default: true | ||
} | ||
} | ||
default: true, | ||
}, | ||
}, | ||
}); | ||
@@ -62,10 +63,9 @@ | ||
find: [ | ||
// TODO: Remove the `|| []` when `meow` 7.1.2 is out. | ||
...(cli.flags.string || []), | ||
...(cli.flags.regex || []).map(regexString => new RegExp(regexString, 'g')) | ||
...cli.flags.string, | ||
...cli.flags.regex.map(regexString => new RegExp(regexString, 'g')), | ||
], | ||
replacement: cli.flags.replacement, | ||
ignoreCase: cli.flags.ignoreCase, | ||
glob: cli.flags.glob | ||
glob: cli.flags.glob, | ||
}); | ||
})(); |
{ | ||
"name": "replace-in-files-cli", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Replace matching strings and regexes in files", | ||
@@ -13,7 +13,8 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"bin": { | ||
"replace-in-files": "cli.js" | ||
"replace-in-files": "./cli.js" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -46,15 +47,14 @@ "scripts": { | ||
"dependencies": { | ||
"arrify": "^2.0.1", | ||
"escape-string-regexp": "^4.0.0", | ||
"globby": "^11.0.1", | ||
"meow": "^7.1.1", | ||
"escape-string-regexp": "^5.0.0", | ||
"globby": "^12.0.2", | ||
"meow": "^10.1.1", | ||
"normalize-path": "^3.0.0", | ||
"write-file-atomic": "^3.0.0" | ||
"write-file-atomic": "^3.0.3" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.1.0", | ||
"execa": "^1.0.0", | ||
"temp-write": "^4.0.0", | ||
"xo": "^0.33.1" | ||
"ava": "^3.15.0", | ||
"execa": "^5.1.1", | ||
"temp-write": "^5.0.0", | ||
"xo": "^0.46.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# replace-in-files-cli [![Build Status](https://travis-ci.com/sindresorhus/replace-in-files-cli.svg?branch=master)](https://travis-ci.com/github/sindresorhus/replace-in-files-cli) | ||
# replace-in-files-cli | ||
@@ -7,5 +7,5 @@ > Replace matching strings and regexes in files | ||
```sh | ||
npm install --global replace-in-files-cli | ||
``` | ||
$ npm install --global replace-in-files-cli | ||
``` | ||
@@ -12,0 +12,0 @@ ## Usage |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5
1
Yes
6965
110
+ Addedarray-union@3.0.1(transitive)
+ Addedcamelcase@6.3.0(transitive)
+ Addedcamelcase-keys@7.0.2(transitive)
+ Addeddecamelize@5.0.1(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedglobby@12.2.0(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmeow@10.1.5(transitive)
+ Addednormalize-package-data@3.0.3(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedread-pkg@6.0.0(transitive)
+ Addedread-pkg-up@8.0.0(transitive)
+ Addedredent@4.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedslash@4.0.0(transitive)
+ Addedstrip-indent@4.0.0(transitive)
+ Addedtrim-newlines@4.1.1(transitive)
+ Addedtype-fest@1.4.0(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removedarrify@^2.0.1
- Removedarray-union@2.1.0(transitive)
- Removedarrify@2.0.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcamelcase-keys@6.2.2(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedmeow@7.1.1(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedquick-lru@4.0.1(transitive)
- Removedread-pkg@5.2.0(transitive)
- Removedread-pkg-up@7.0.1(transitive)
- Removedredent@3.0.0(transitive)
- Removedresolve@1.22.9(transitive)
- Removedsemver@5.7.2(transitive)
- Removedslash@3.0.0(transitive)
- Removedstrip-indent@3.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@3.0.1(transitive)
- Removedtype-fest@0.13.10.6.00.8.1(transitive)
- Removedyargs-parser@18.1.3(transitive)
Updatedescape-string-regexp@^5.0.0
Updatedglobby@^12.0.2
Updatedmeow@^10.1.1
Updatedwrite-file-atomic@^3.0.3