Skip to content

Commit f0da9ce

Browse files
committed
chore: new scripts + t2k
1 parent eb7aa30 commit f0da9ce

20 files changed

+98
-58
lines changed

.editorconfig

100755100644
File mode changed.

.gitignore

100755100644
+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ package-lock.json
77
.DS_Store
88
.idea
99
.vscode
10+
11+
# vscode localhistory
12+
.history

.npmignore

100755100644
+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test
66
__tests__
77
src
88
build
9+
docs
910
gulpfile.js
1011

1112
.editorconfig
@@ -16,3 +17,7 @@ LICENSE.txt
1617
Rakefile
1718
express.js
1819
.vscode
20+
21+
22+
# vscode localhistory
23+
.history

.npmrc

100755100644
File mode changed.

.prettierrc

100755100644
File mode changed.

Gemfile

100755100644
File mode changed.

LICENSE.txt

100755100644
File mode changed.

README.md

100755100644
+39-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# next-replace-in-file
22
> File content replace for next.
33
4+
[![version][version-image]][version-url]
5+
[![license][license-image]][license-url]
6+
[![size][size-image]][size-url]
7+
[![download][download-image]][download-url]
8+
49
## installation
510
```bash
611
npm install -S @feizheng/next-replace-in-file
@@ -41,28 +46,43 @@ npm install -S @feizheng/next-replace-in-file
4146
## options
4247
> Not fully, because `fast-glob` does not implement all options of `node-glob`. See table below.
4348
44-
| node-glob(😂) | fast-glob(😎) |
45-
| :-----------: | :---------------------------------------------------------: |
46-
| `cwd` | [`cwd`](#cwd) |
47-
| `root` ||
48-
| `dot` | [`dot`](#dot) |
49-
| `nomount` ||
50-
| `mark` | [`markDirectories`](#markdirectories) |
51-
| `nosort` ||
52-
| `nounique` | [`unique`](#unique) |
53-
| `nobrace` | [`nobrace`](#nobrace) or [`brace`](#brace) |
54-
| `noglobstar` | [`noglobstar`](#noglobstar) or [`globstar`](#globstar) |
55-
| `noext` | [`noext`](#noext) or [`extension`](#extension) |
56-
| `nocase` | [`nocase`](#nocase) or [`case`](#case) |
57-
| `matchBase` | [`matchbase`](#matchbase) |
58-
| `nodir` | [`onlyFiles`](#onlyfiles) |
59-
| `ignore` | [`ignore`](#ignore) |
60-
| `follow` | [`followSymlinkedDirectories`](#followsymlinkeddirectories) |
61-
| `realpath` ||
62-
| `absolute` | [`absolute`](#absolute) |
49+
| node-glob(😂) | fast-glob(😎) |
50+
| :----------: | :---------------------------------------------------------: |
51+
| `cwd` | [`cwd`](#cwd) |
52+
| `root` ||
53+
| `dot` | [`dot`](#dot) |
54+
| `nomount` ||
55+
| `mark` | [`markDirectories`](#markdirectories) |
56+
| `nosort` ||
57+
| `nounique` | [`unique`](#unique) |
58+
| `nobrace` | [`nobrace`](#nobrace) or [`brace`](#brace) |
59+
| `noglobstar` | [`noglobstar`](#noglobstar) or [`globstar`](#globstar) |
60+
| `noext` | [`noext`](#noext) or [`extension`](#extension) |
61+
| `nocase` | [`nocase`](#nocase) or [`case`](#case) |
62+
| `matchBase` | [`matchbase`](#matchbase) |
63+
| `nodir` | [`onlyFiles`](#onlyfiles) |
64+
| `ignore` | [`ignore`](#ignore) |
65+
| `follow` | [`followSymlinkedDirectories`](#followsymlinkeddirectories) |
66+
| `realpath` ||
67+
| `absolute` | [`absolute`](#absolute) |
6368

6469

6570
## resources
6671
- https://github.com/afeiship/next-array-replace
6772
- https://github.com/sindresorhus/globby
6873
- https://github.com/mrmlnc/fast-glob#options-1
74+
75+
## license
76+
Code released under [the MIT license](https://github.com/afeiship/next-replace-in-file/blob/master/LICENSE.txt).
77+
78+
[version-image]: https://img.shields.io/npm/v/@feizheng/next-replace-in-file
79+
[version-url]: https://npmjs.org/package/@feizheng/next-replace-in-file
80+
81+
[license-image]: https://img.shields.io/npm/l/@feizheng/next-replace-in-file
82+
[license-url]: https://github.com/afeiship/next-replace-in-file/blob/master/LICENSE.txt
83+
84+
[size-image]: https://img.shields.io/bundlephobia/minzip/@feizheng/next-replace-in-file
85+
[size-url]: https://github.com/afeiship/next-replace-in-file/blob/master/dist/next-replace-in-file.min.js
86+
87+
[download-image]: https://img.shields.io/npm/dm/@feizheng/next-replace-in-file
88+
[download-url]: https://www.npmjs.com/package/@feizheng/next-replace-in-file

Rakefile

100755100644
File mode changed.

__tests__/api.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('api.basic test', () => {
66
nx.replaceInFile(
77
'__tests__/**',
88
[
9-
[/_VERSION_/gi, '__VERSION__'],
9+
[/____VERSION____/gi, '_____VERSION_____'],
1010
[/FILE/g, 'FILE'],
1111
[/DESC/g, 'DESC']
1212
],

build/clean.js

100755100644
File mode changed.

build/scripts.js

100755100644
-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
gulp.task('scripts', function() {
1111
return gulp
1212
.src('src/*.js')
13-
.pipe($.sourcemaps.init())
1413
.pipe($.feizheng.pkgHeader())
15-
.pipe($.sourcemaps.write('.'))
1614
.pipe(gulp.dest('dist'))
1715
.pipe($.size({ title: '[ default size ]:' }))
18-
.pipe($.ignore('*.js.map'))
1916
.pipe($.uglify({ output: { comments: saveLicense } }))
2017
.pipe($.rename({ extname: '.min.js' }))
2118
.pipe(gulp.dest('dist'))

dist/next-replace-in-file.js

100755100644
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
/*!
22
* name: @feizheng/next-replace-in-file
33
* description: File content replace for next.
4-
* url: https://github.com/afeiship/next-replace-in-file
5-
* version: 1.0.0
6-
* date: 2020-01-28 23:12:08
4+
* homepage: https://github.com/afeiship/next-replace-in-file
5+
* version: 1.0.2
6+
* date: 2020-11-05T12:04:46.035Z
77
* license: MIT
88
*/
99

10-
(function() {
10+
(function () {
1111
var global = global || this || window || Function('return this')();
1212
var nx = global.nx || require('@feizheng/next-js-core2');
1313
var fs = require('fs');
1414
var globby = require('globby');
1515
var CHARSET = 'utf-8';
16-
var DEFAULT_OPTIONS = { dot: true, ignore: ['.git'] };
16+
var DEFAULT_OPTIONS = { dot: true, debug: false, ignore: ['.git'] };
1717

1818
// next packages:
1919
require('@feizheng/next-array-replace');
2020

21-
nx.replaceInFile = function(inFiles, inArray, inOptions) {
21+
nx.replaceInFile = function (inFiles, inArray, inOptions) {
2222
var options = nx.mix(DEFAULT_OPTIONS, inOptions);
2323
var files = globby.sync(inFiles, options);
24-
var replaceInFile = function(filename) {
24+
var replaceInFile = function (filename) {
2525
var content = fs.readFileSync(filename, CHARSET);
2626
var result = nx.arrayReplace(content, inArray);
2727
fs.writeFileSync(filename, result);
2828
};
2929

30+
// add debug params:
31+
options.debug && console.log('[debug]:', files);
32+
3033
// replace files:
31-
files.forEach(function(filename) {
34+
files.forEach(function (filename) {
3235
var fsState = fs.statSync(filename);
3336
if (fsState.isFile(filename)) {
3437
replaceInFile(filename);
@@ -40,5 +43,3 @@
4043
module.exports = nx.replaceInFile;
4144
}
4245
})();
43-
44-
//# sourceMappingURL=next-replace-in-file.js.map

dist/next-replace-in-file.js.map

-1
This file was deleted.

dist/next-replace-in-file.min.js

100755100644
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*!
22
* name: @feizheng/next-replace-in-file
33
* description: File content replace for next.
4-
* url: https://github.com/afeiship/next-replace-in-file
5-
* version: 1.0.0
6-
* date: 2020-01-28 23:12:08
4+
* homepage: https://github.com/afeiship/next-replace-in-file
5+
* version: 1.0.2
6+
* date: 2020-11-05T12:04:46.035Z
77
* license: MIT
88
*/
9-
!function(){var e=e||this||window||Function("return this")(),o=e.nx||require("@feizheng/next-js-core2"),a=require("fs"),c=require("globby"),u={dot:!0,ignore:[".git"]};require("@feizheng/next-array-replace"),o.replaceInFile=function(e,t,r){var i=o.mix(u,r),n=c.sync(e,i);n.forEach(function(e){var r,i,n;a.statSync(e).isFile(e)&&(r=e,i=a.readFileSync(r,"utf-8"),n=o.arrayReplace(i,t),a.writeFileSync(r,n))})},"undefined"!=typeof module&&module.exports&&(module.exports=o.replaceInFile)}();
9+
!function(){var i=(this||window||Function("return this")()).nx||require("@feizheng/next-js-core2"),o=require("fs"),t=require("globby"),u={dot:!0,debug:!1,ignore:[".git"]};require("@feizheng/next-array-replace"),i.replaceInFile=function(e,n,r){r=i.mix(u,r),e=t.sync(e,r);r.debug&&console.log("[debug]:",e),e.forEach(function(e){var r;o.statSync(e).isFile(e)&&(r=e,e=o.readFileSync(r,"utf-8"),e=i.arrayReplace(e,n),o.writeFileSync(r,e))})},"undefined"!=typeof module&&module.exports&&(module.exports=i.replaceInFile)}();

express.js

100755100644
File mode changed.

gulpfile.js

100755100644
File mode changed.

jest.config.js

100755100644
File mode changed.

package.json

100755100644
+27-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@feizheng/next-replace-in-file",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "File content replace for next.",
55
"homepage": "https://github.com/afeiship/next-replace-in-file",
66
"author": {
@@ -9,35 +9,47 @@
99
},
1010
"scripts": {
1111
"build": "gulp",
12-
"test": "jest",
12+
"test": "jest --forceExit --detectOpenHandles --maxWorkers=10",
1313
"start": "node ./express.js"
1414
},
1515
"main": "dist/next-replace-in-file.js",
1616
"license": "MIT",
1717
"devDependencies": {
18-
"@feizheng/gulp-pkg-header": "^1.0.2",
18+
"@feizheng/gulp-pkg-header": "^1.0.4",
19+
"@feizheng/next-js-core2": "^2.6.0",
1920
"@feizheng/rake-git": "^1.2.1",
20-
"del": "^5.1.0",
21+
"del": "^6.0.0",
2122
"express": "^4.17.1",
2223
"gulp": "^4.0.2",
2324
"gulp-debug": "^4.0.0",
2425
"gulp-header": "^2.0.9",
2526
"gulp-ignore": "^3.0.0",
26-
"gulp-load-plugins": "^2.0.2",
27+
"gulp-load-plugins": "^2.0.5",
2728
"gulp-rename": "^2.0.0",
2829
"gulp-size": "^3.0.0",
29-
"gulp-sourcemaps": "^2.6.5",
3030
"gulp-uglify": "^3.0.2",
31-
"jest": "^25.1.0",
32-
"prettier": "^1.19.1",
31+
"jest": "^26.6.3",
32+
"prettier": "^2.1.2",
33+
"uglify-js": "3.11.5",
3334
"uglify-save-license": "^0.4.1",
34-
"yargs": "^15.1.0"
35+
"yargs": "^16.1.0"
36+
},
37+
"publishConfig": {
38+
"registry": "https://registry.npmjs.org"
3539
},
3640
"dependencies": {
37-
"@feizheng/next-array-replace": "^1.0.1",
38-
"@feizheng/next-js-core2": "^2.4.1"
41+
"@feizheng/next-array-replace": "^1.0.2"
3942
},
40-
"publishConfig": {
41-
"registry": "https://registry.npmjs.org/"
42-
}
43-
}
43+
"keywords": [
44+
"next",
45+
"file",
46+
"replace",
47+
"in",
48+
"content",
49+
"string",
50+
"regexp",
51+
"glob",
52+
"pattern",
53+
"globby"
54+
]
55+
}

src/next-replace-in-file.js

100755100644
+8-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
(function() {
1+
(function () {
22
var global = global || this || window || Function('return this')();
33
var nx = global.nx || require('@feizheng/next-js-core2');
44
var fs = require('fs');
55
var globby = require('globby');
66
var CHARSET = 'utf-8';
7-
var DEFAULT_OPTIONS = { dot: true, ignore: ['.git'] };
7+
var DEFAULT_OPTIONS = { dot: true, debug: false, ignore: ['.git'] };
88

99
// next packages:
1010
require('@feizheng/next-array-replace');
1111

12-
nx.replaceInFile = function(inFiles, inArray, inOptions) {
12+
nx.replaceInFile = function (inFiles, inArray, inOptions) {
1313
var options = nx.mix(DEFAULT_OPTIONS, inOptions);
1414
var files = globby.sync(inFiles, options);
15-
var replaceInFile = function(filename) {
15+
var replaceInFile = function (filename) {
1616
var content = fs.readFileSync(filename, CHARSET);
1717
var result = nx.arrayReplace(content, inArray);
1818
fs.writeFileSync(filename, result);
1919
};
2020

21+
// add debug params:
22+
options.debug && console.log('[debug]:', files);
23+
2124
// replace files:
22-
files.forEach(function(filename) {
25+
files.forEach(function (filename) {
2326
var fsState = fs.statSync(filename);
2427
if (fsState.isFile(filename)) {
2528
replaceInFile(filename);

0 commit comments

Comments
 (0)