@frsource/frs-replace 3.0.3 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -0
- package/bin/cli.js +12 -4
- package/package.json +11 -11
- package/src/utils.js +11 -11
- package/yarn.lock +1734 -1479
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.1.0](https://github.com/FRSource/frs-replace/compare/v4.0.0...v4.1.0) (2023-02-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add stdin flag ([7574b49](https://github.com/FRSource/frs-replace/commit/7574b49274a525432f0353b0ce24c54e1514e580))
|
|
11
|
+
|
|
12
|
+
## [4.0.0](https://github.com/FRSource/frs-replace/compare/v3.0.3...v4.0.0) (2022-12-07)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### ⚠ BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* from now on replatement file path should be relative to projects' root
|
|
18
|
+
|
|
19
|
+
Signed-off-by: Jakub Freisler <jakub@frsource.org>
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* require replacement method in scope of projects' root ([69fc050](https://github.com/FRSource/frs-replace/commit/69fc05009bf11230fbab73d649b4ce636ebbc8e2))
|
|
24
|
+
|
|
5
25
|
### [3.0.3](https://github.com/FRSource/frs-replace/compare/v3.0.2...v3.0.3) (2021-04-18)
|
|
6
26
|
|
|
7
27
|
### [3.0.2](https://github.com/FRSource/frs-replace/compare/v3.0.1...v3.0.2) (2021-04-18)
|
package/README.md
CHANGED
|
@@ -100,6 +100,7 @@ frs-replace <regex> <replacement> [options]
|
|
|
100
100
|
|‑i, ‑‑input | string or string[] | *-* | Path to files or [fast-glob](https://github.com/mrmlnc/fast-glob) pattern pointing to files to be read & replaced from. If multiple files specified results will be joined using `outputJoinString` option's value) |
|
|
101
101
|
| ‑‑i-read-opts | string or object | utf8 | Options which are passed directly to the [readFileSync method](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options) when reading input file |
|
|
102
102
|
| ‑‑i-glob-opts | object | *undefined* | Options which are passed directly to the [fast-glob package](https://github.com/mrmlnc/fast-glob#options-1) when resolving glob patterns |
|
|
103
|
+
| ‑‑stdin | boolean | *true* | Wait for stdin input (should be set to *false* when used in non-interactive terminals) |
|
|
103
104
|
| ‑o, ‑‑output | string | *-* | Output file name/path (replaces the file if it already exists and creates any intermediate directories if they don't already exist) |
|
|
104
105
|
| ‑‑o-write-opts | string or object | utf8 | Passed as options argument of [write's .sync](https://www.npmjs.com/package/write#sync) |
|
|
105
106
|
| ‑‑o-join-str | string | \n | Used when joining multiple files, passed directly to [javascript join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join#Syntax) |
|
package/bin/cli.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const replaceSync = require('../sync')
|
|
2
|
+
const replaceSync = require('../sync');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
(
|
|
5
|
+
~process.argv.indexOf('--no-stdin')
|
|
6
|
+
? Promise.resolve()
|
|
7
|
+
: require('get-stdin')()
|
|
8
|
+
).then((stdin) => {
|
|
5
9
|
const isPiped = !!stdin
|
|
6
10
|
|
|
7
11
|
if (isPiped) {
|
|
@@ -48,7 +52,6 @@ require('get-stdin')().then((stdin) => {
|
|
|
48
52
|
.choices('f', ['', 'g', 'm', 'i', 'gm', 'gi', 'mi', 'mg', 'ig', 'im', 'gmi', 'gim', 'mig', 'mgi', 'igm', 'img'])
|
|
49
53
|
.default('f', 'g')
|
|
50
54
|
.coerce('f', arg => arg.trim())
|
|
51
|
-
|
|
52
55
|
.option('i', { demandOption: !isContentPresent && !isHelpPresent })
|
|
53
56
|
.alias('i', 'input')
|
|
54
57
|
.describe('i', 'Path to files or fast-glob pattern pointing to files to read & replace from')
|
|
@@ -63,6 +66,11 @@ require('get-stdin')().then((stdin) => {
|
|
|
63
66
|
.describe('i-glob-opts', 'Passed to fast-glob.sync when resolving glob patterns')
|
|
64
67
|
.implies('i-glob-opts', 'i')
|
|
65
68
|
|
|
69
|
+
.option('stdin')
|
|
70
|
+
.describe('stdin', 'Wait for stdin input (should be set to false when used in non-interactive terminals)')
|
|
71
|
+
.boolean('stdin')
|
|
72
|
+
.default('stdin', true)
|
|
73
|
+
|
|
66
74
|
.option('c', { demandOption: isContentPresent })
|
|
67
75
|
.alias('c', 'content')
|
|
68
76
|
.describe('c', 'Content to be replaced (takes precedence over stream & file input)')
|
|
@@ -125,7 +133,7 @@ require('get-stdin')().then((stdin) => {
|
|
|
125
133
|
outputWriteOptions: argv['o-write-opts'],
|
|
126
134
|
outputJoinString: argv['o-join-str'],
|
|
127
135
|
needle: new RegExp(argv.needle, argv.f),
|
|
128
|
-
replacement: argv.r ? require(argv.replacement) : argv.replacement
|
|
136
|
+
replacement: argv.r ? require(require('path').resolve(argv.replacement)) : argv.replacement
|
|
129
137
|
})
|
|
130
138
|
|
|
131
139
|
if (argv.stdout) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frsource/frs-replace",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Simple wrapper around javascript replace with CLI usage support!",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frs-replace": "./bin/cli.js"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"javascript"
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
|
-
"prerelease": "yarn standard:fix && yarn test
|
|
44
|
+
"prerelease": "yarn standard:fix && yarn test",
|
|
45
45
|
"release": "standard-version",
|
|
46
46
|
"postrelease": "git push --follow-tags origin master && yarn publish",
|
|
47
47
|
"pretest": "standard",
|
|
@@ -56,19 +56,19 @@
|
|
|
56
56
|
"standard:fix": "standard --fix"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"perfy": "
|
|
60
|
-
"replace": "
|
|
61
|
-
"replace-in-file": "
|
|
62
|
-
"replace-string": "
|
|
63
|
-
"standard": "
|
|
64
|
-
"standard-version": "
|
|
65
|
-
"tap": "
|
|
66
|
-
"tmp-promise": "
|
|
59
|
+
"perfy": "1.1.5",
|
|
60
|
+
"replace": "1.2.2",
|
|
61
|
+
"replace-in-file": "6.3.5",
|
|
62
|
+
"replace-string": "3.1.0",
|
|
63
|
+
"standard": "17.0.0",
|
|
64
|
+
"standard-version": "9.5.0",
|
|
65
|
+
"tap": "16.3.4",
|
|
66
|
+
"tmp-promise": "3.0.3"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"fast-glob": "^3.1.0",
|
|
70
70
|
"get-stdin": "^8.0.0",
|
|
71
71
|
"write": "^2.0.0",
|
|
72
|
-
"yargs": "^
|
|
72
|
+
"yargs": "^17.0.0"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/utils.js
CHANGED
|
@@ -3,20 +3,20 @@ const writeError = msg => { throw new Error(`@frsource/frs-replace :: ${msg}`) }
|
|
|
3
3
|
const getReplaceFn = (needle, replacement) =>
|
|
4
4
|
typeof needle === 'string'
|
|
5
5
|
? content => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const needleLen = needle.length
|
|
7
|
+
let result = ''
|
|
8
|
+
let i
|
|
9
|
+
let endIndex = 0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
while ((i = content.indexOf(needle, endIndex)) !== -1) {
|
|
12
|
+
result += content.slice(endIndex, i) + replacement
|
|
13
|
+
endIndex = i + needleLen
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
result += content.slice(endIndex, content.length)
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
20
|
: content => content.replace(needle, replacement)
|
|
21
21
|
|
|
22
22
|
module.exports = { writeError, getReplaceFn }
|