js-dev-tool 1.0.3 → 1.0.7
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/README.md +5 -10
- package/common/index.d.ts +3 -2
- package/common/index.js +8 -8
- package/extras/tiny-progress.js +4 -4
- package/package.json +9 -5
- package/progress/index.d.ts +4 -0
- package/progress/index.js +10 -7
- package/progress/progress-extras.js +9 -8
- package/scripts/normalize-commit-msg.mjs +22 -0
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +31 -21
- package/tool-lib/ps.js +37 -28
- package/tool-lib/rws.js +1 -1
- package/tool-lib/tools.d.ts +6 -5
- package/tools.d.ts +1 -7
- package/tools.js +9 -28
- package/tsconfig.json +9 -4
- package/utils.d.ts +3 -3
- package/utils.js +10 -10
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# js-tool
|
|
1
|
+
# js-dev-tool
|
|
2
2
|
|
|
3
3
|
A collection of command-line tools to assist in JavaScript project development.
|
|
4
4
|
|
|
@@ -56,13 +56,12 @@ cmtTrick help: Do comment trick toggle
|
|
|
56
56
|
bases - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
57
57
|
test - terget extension, default is /\\.js$/
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
stripSome help: jstool -cmd stripSome [-after <replacement>] -regex "/^\s+<!--[\s\S]+?-->(?:\r?\n)?/gm" [-targets "<path>,<path>,..." | <args: file, file file...>]
|
|
59
|
+
replace help: jstool -cmd replace [-after <replacement>] -regex "/^\s+<!--[\s\S]+?-->(?:\r?\n)?/gm" [-targets "<path>,<path>,..." | <args: file, file file...>]
|
|
61
60
|
note:
|
|
62
61
|
targets - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
63
62
|
note: targets - can use args parameter instead
|
|
64
63
|
It is better to use the <args: file, file file...>
|
|
65
|
-
e.g - jstool -cmd
|
|
64
|
+
e.g - jstool -cmd replace -after ".." -regex "re/(?<=reference path=")(\.)(?=\/index.d.ts")/" build/**/*.js
|
|
66
65
|
^^^^^^^^^^^^^
|
|
67
66
|
|
|
68
67
|
version help: jstool -cmd version [-major | -minor] [-pkgJsons "./package.json,../package.json"] [-extras "test/web/index.html"]
|
|
@@ -110,9 +109,9 @@ Toggles "comment tricks" in the code, useful for conditional code execution duri
|
|
|
110
109
|
|
|
111
110
|
---
|
|
112
111
|
|
|
113
|
-
### `
|
|
112
|
+
### `replace`
|
|
114
113
|
Performs generic string replacement on a set of target files using a regular expression.
|
|
115
|
-
* **Usage:** `jstool -cmd
|
|
114
|
+
* **Usage:** `jstool -cmd replace [-after <replacement>] -regex "<regex>" [-targets "<path1>,<path2>" | <file1> <file2> ...]`
|
|
116
115
|
* **Note:** It's often better to pass target files as direct arguments instead of using the `-targets` option.
|
|
117
116
|
|
|
118
117
|
---
|
|
@@ -138,10 +137,6 @@ Removes C-style comments from files.
|
|
|
138
137
|
|
|
139
138
|
---
|
|
140
139
|
|
|
141
|
-
### `stripWebpack` (deprecated)
|
|
142
|
-
Strips webpack-specific boilerplate from bundled files.
|
|
143
|
-
* **Usage:** `jstool -cmd stripWebpack -regex "%npm_package_defs_regex%"`
|
|
144
|
-
|
|
145
140
|
|
|
146
141
|
## 📜 License
|
|
147
142
|
|
package/common/index.d.ts
CHANGED
|
@@ -32,9 +32,10 @@ export function createLogStreamAndResolvePath(logPath: string): any;
|
|
|
32
32
|
/**
|
|
33
33
|
* use process.stderr stream
|
|
34
34
|
*
|
|
35
|
-
* @param {string}
|
|
35
|
+
* @param {string=} msg if empty string or undefined then only clear line and move cursor to head.
|
|
36
|
+
* @param {number=} row
|
|
36
37
|
*/
|
|
37
|
-
export function renderLine(msg?: string): void;
|
|
38
|
+
export function renderLine(msg?: string, row?: number): void;
|
|
38
39
|
/**
|
|
39
40
|
*
|
|
40
41
|
* @param {boolean} enabled
|
package/common/index.js
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// @ts-check
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const path = require("path");
|
|
14
|
-
const rl = require("readline");
|
|
15
14
|
/**
|
|
16
15
|
* @param {string} dest
|
|
17
16
|
*/
|
|
@@ -31,15 +30,16 @@ function createLogStreamAndResolvePath(logPath) {
|
|
|
31
30
|
/**
|
|
32
31
|
* use process.stderr stream
|
|
33
32
|
*
|
|
34
|
-
* @param {string}
|
|
33
|
+
* @param {string=} msg if empty string or undefined then only clear line and move cursor to head.
|
|
34
|
+
* @param {number=} row
|
|
35
35
|
*/
|
|
36
|
-
function renderLine(msg
|
|
36
|
+
function renderLine(msg, row) {
|
|
37
37
|
const output = process.stderr || process.stdout;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
output.cursorTo(0, row);
|
|
39
|
+
msg && (
|
|
40
|
+
output.write(msg),
|
|
41
|
+
output.clearLine(1)
|
|
42
|
+
);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
*
|
package/extras/tiny-progress.js
CHANGED
|
@@ -43,18 +43,18 @@ const pcb = () => {
|
|
|
43
43
|
let progress;
|
|
44
44
|
/**
|
|
45
45
|
* @param {number} [fps]
|
|
46
|
-
* @param {() => string} [
|
|
46
|
+
* @param {() => string} [messageEmitter]
|
|
47
47
|
*/
|
|
48
|
-
const create = (fps = 30,
|
|
48
|
+
const create = (fps = 30, messageEmitter) => {
|
|
49
49
|
const spinner = rndSpinners.getRandomFrame();
|
|
50
|
-
!
|
|
50
|
+
!messageEmitter && (messageEmitter = pcb);
|
|
51
51
|
progress = p.createProgressObject(
|
|
52
52
|
spinner.frames,
|
|
53
53
|
{
|
|
54
54
|
fmt: "{tick} - {frameName} - {msg}",
|
|
55
55
|
payload: { frameName: spinner.name },
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
messageEmitter,
|
|
58
58
|
);
|
|
59
59
|
progress.setFPS(fps);
|
|
60
60
|
return progress;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-dev-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"bin": {
|
|
5
|
-
"jstool": "
|
|
5
|
+
"jstool": "tools.js"
|
|
6
6
|
},
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"main": "./index.js",
|
|
9
|
-
"repository":
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+ssh://git@github.com/jeffy-g/js-dev-scripts.git"
|
|
12
|
+
},
|
|
10
13
|
"author": "jeffy-g <hirotom1107@gmail.com>",
|
|
11
14
|
"license": "MIT",
|
|
12
15
|
"keywords": [
|
|
@@ -37,7 +40,8 @@
|
|
|
37
40
|
"*.d.ts"
|
|
38
41
|
],
|
|
39
42
|
"peerDependencies": {
|
|
40
|
-
"archiver": "^4.0.1"
|
|
43
|
+
"archiver": "^4.0.1",
|
|
44
|
+
"webpack": "*"
|
|
41
45
|
},
|
|
42
46
|
"dependencies": {
|
|
43
47
|
"colors.ts": "^1.0.20",
|
|
@@ -46,6 +50,6 @@
|
|
|
46
50
|
"replace": "^1.2.2",
|
|
47
51
|
"rm-cstyle-cmts": "^3.3.22",
|
|
48
52
|
"terser": "^5.44.1",
|
|
49
|
-
"tin-args": "^0.
|
|
53
|
+
"tin-args": "^0.1.1"
|
|
50
54
|
}
|
|
51
55
|
}
|
package/progress/index.d.ts
CHANGED
|
@@ -71,6 +71,10 @@ export function createProgressObject(frames: string[], formatOpt: TProgressForma
|
|
|
71
71
|
* stop timer
|
|
72
72
|
*/
|
|
73
73
|
stop(): void;
|
|
74
|
+
/**
|
|
75
|
+
* running or not?
|
|
76
|
+
*/
|
|
77
|
+
isRunning(): boolean;
|
|
74
78
|
};
|
|
75
79
|
declare global {
|
|
76
80
|
type TWebpackProgressHandler = (percentage: number, message: string, ...args: string[]) => void;
|
package/progress/index.js
CHANGED
|
@@ -69,12 +69,12 @@ const createProgressSync = (frames, formatOpt) => {
|
|
|
69
69
|
* ```
|
|
70
70
|
* " {frameName} [{tick}]: {msg}" // etc
|
|
71
71
|
* ```
|
|
72
|
-
* @param {() => string}
|
|
72
|
+
* @param {() => string} messageEmitter
|
|
73
73
|
*/
|
|
74
|
-
const createProgressObject = (frames, formatOpt,
|
|
74
|
+
const createProgressObject = (frames, formatOpt, messageEmitter) => {
|
|
75
75
|
let done = false;
|
|
76
76
|
const render = () => {
|
|
77
|
-
|
|
77
|
+
progress(messageEmitter(), done);
|
|
78
78
|
};
|
|
79
79
|
let progress = createProgressSync(frames, formatOpt);
|
|
80
80
|
/** @type {ReturnType<typeof setInterval> | undefined} */
|
|
@@ -125,7 +125,7 @@ const createProgressObject = (frames, formatOpt, callback) => {
|
|
|
125
125
|
* this method useful when `run` method did not smooth.
|
|
126
126
|
*/
|
|
127
127
|
renderSync() {
|
|
128
|
-
|
|
128
|
+
progress(messageEmitter(), done);
|
|
129
129
|
},
|
|
130
130
|
/**
|
|
131
131
|
* run timer (30fps)
|
|
@@ -147,6 +147,9 @@ const createProgressObject = (frames, formatOpt, callback) => {
|
|
|
147
147
|
timer = void 0;
|
|
148
148
|
lib.cursor(true);
|
|
149
149
|
},
|
|
150
|
+
isRunning() {
|
|
151
|
+
return !!timer;
|
|
152
|
+
}
|
|
150
153
|
};
|
|
151
154
|
};
|
|
152
155
|
/**
|
|
@@ -198,7 +201,7 @@ function createWebpackProgressPluginHandler(
|
|
|
198
201
|
/** @type {TWebpackProgressHandler} */
|
|
199
202
|
let wppHandler;
|
|
200
203
|
{
|
|
201
|
-
const
|
|
204
|
+
const shortenProgress = (/** @type {number} */ pct) => {
|
|
202
205
|
renderer(formatPercentage(pct));
|
|
203
206
|
pct === 1 && (console.log(), (dotted = 0));
|
|
204
207
|
};
|
|
@@ -207,7 +210,7 @@ function createWebpackProgressPluginHandler(
|
|
|
207
210
|
/** @type {((p: number) => void) | undefined} */
|
|
208
211
|
let writeCallback;
|
|
209
212
|
if (!disableRenderLine) {
|
|
210
|
-
writeCallback =
|
|
213
|
+
writeCallback = shortenProgress;
|
|
211
214
|
}
|
|
212
215
|
wppHandler = (percentage, message, ...args) => {
|
|
213
216
|
wppLogger.write(
|
|
@@ -227,7 +230,7 @@ function createWebpackProgressPluginHandler(
|
|
|
227
230
|
wppHandler = renderDot;
|
|
228
231
|
} else {
|
|
229
232
|
if (processType === "gitpod") {
|
|
230
|
-
wppHandler =
|
|
233
|
+
wppHandler = shortenProgress;
|
|
231
234
|
} else {
|
|
232
235
|
wppHandler = isWebpackV5later() ? wppHandlerV5 : wppHandlerV4;
|
|
233
236
|
}
|
|
@@ -17,11 +17,12 @@ const checkENV = () => {
|
|
|
17
17
|
};
|
|
18
18
|
/** @type {TWebpackProgressHandler} */
|
|
19
19
|
const wppHandlerV4 = ((renderer, cwd) => {
|
|
20
|
+
const cwdLen = cwd.length;
|
|
20
21
|
return (percentage, message, ...args) => {
|
|
21
22
|
let [modules, actives, path = ""] = args;
|
|
22
23
|
if (message) {
|
|
23
24
|
const x = path.lastIndexOf(cwd) + 1;
|
|
24
|
-
x > 0 && (path = path.
|
|
25
|
+
x > 0 && (path = path.slice(x + cwdLen));
|
|
25
26
|
} else {
|
|
26
27
|
message = "- done -";
|
|
27
28
|
}
|
|
@@ -35,20 +36,20 @@ const wppHandlerV4 = ((renderer, cwd) => {
|
|
|
35
36
|
})(lib.renderLine, process.cwd());
|
|
36
37
|
/** @type {TWebpackProgressHandler} */
|
|
37
38
|
const wppHandlerV5 = ((renderer, cwd) => {
|
|
39
|
+
const cwdLen = cwd.length;
|
|
38
40
|
return (percentage, message, ...args) => {
|
|
39
41
|
if (!message) {
|
|
40
42
|
message = "- done -";
|
|
41
43
|
}
|
|
42
|
-
let
|
|
43
|
-
if (
|
|
44
|
-
const x =
|
|
44
|
+
let pathOrPluginName = args.shift() || "";
|
|
45
|
+
if (pathOrPluginName) {
|
|
46
|
+
const x = pathOrPluginName.lastIndexOf(cwd) + 1;
|
|
45
47
|
if (x > 0) {
|
|
46
|
-
|
|
48
|
+
pathOrPluginName = pathOrPluginName.slice(x + cwdLen);
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
str = args.shift() || "";
|
|
50
51
|
renderer(
|
|
51
|
-
`pct: ${(percentage * 100).toFixed(4)}%, process: [${message}]${
|
|
52
|
+
`pct: ${(percentage * 100).toFixed(4)}%, process: [${message}]${pathOrPluginName ? `, info: [${pathOrPluginName}]` : ""}${args.length ? " - " : ""}${args.join(", ")}`,
|
|
52
53
|
);
|
|
53
54
|
percentage === 1 && console.log();
|
|
54
55
|
};
|
|
@@ -61,7 +62,7 @@ let checkedCache;
|
|
|
61
62
|
const isWebpackV5later = () => {
|
|
62
63
|
if (checkedCache === void 0) {
|
|
63
64
|
try {
|
|
64
|
-
// @ts-ignore
|
|
65
|
+
// @ts-ignore TODO: 2025/11/14 20:54:23
|
|
65
66
|
const webpack = require("webpack");
|
|
66
67
|
checkedCache = +webpack.version[0] > 4;
|
|
67
68
|
} catch (e) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
const commitMsgPath = path.resolve(__dirname, "..", ".codex", "commit_msg.txt");
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(commitMsgPath)) {
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let msg = fs.readFileSync(commitMsgPath, "utf8");
|
|
14
|
+
|
|
15
|
+
msg = msg.replace(/\r\n/g, "\n");
|
|
16
|
+
msg = msg
|
|
17
|
+
.split("\n")
|
|
18
|
+
.map(line => line.replace(/\s+$/u, ""))
|
|
19
|
+
.join("\n");
|
|
20
|
+
msg = msg.replace(/\n+$/u, "\n");
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync(commitMsgPath, msg, "utf8");
|
package/tool-lib/cjbm.js
CHANGED
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @file (C)onvert (J)S to (B)rowser (M)odule
|
|
13
13
|
*/
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const path = require("path");
|
|
14
16
|
/**
|
|
15
17
|
* @import * as Regex from "../regex.d.ts";
|
|
16
18
|
*/
|
|
17
19
|
const RE_TEXT = String.raw`
|
|
18
|
-
# NOTE: PCRE
|
|
19
|
-
(
|
|
20
|
+
# NOTE: When validating with PCRE, use line comment assertion as (?<!\/\/|\/\/\s) (regex101.com)
|
|
21
|
+
(?<!\/\/\s*.+?)(?:(?<!@)import|export)
|
|
20
22
|
\s*
|
|
21
23
|
(?:
|
|
22
24
|
"(?!https?:)(?=[.\/]+)(?:
|
|
@@ -66,6 +68,31 @@ function getReplacer(ext) {
|
|
|
66
68
|
};
|
|
67
69
|
return replacer;
|
|
68
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} ext
|
|
73
|
+
*/
|
|
74
|
+
const emitProcessCallback = (ext) => {
|
|
75
|
+
/**
|
|
76
|
+
* @param {string[]} sourceFiles
|
|
77
|
+
*/
|
|
78
|
+
return (sourceFiles) => {
|
|
79
|
+
if (sourceFiles && sourceFiles.length) {
|
|
80
|
+
for (let i = 0, sourceFilesLen = sourceFiles.length; i < sourceFilesLen;) {
|
|
81
|
+
const sourceFile = sourceFiles[i++];
|
|
82
|
+
const parsed = path.parse(sourceFile);
|
|
83
|
+
if (parsed.ext !== `.${ext}`) {
|
|
84
|
+
const afterPath = `${parsed.dir}/${parsed.name}.${ext}`;
|
|
85
|
+
fs.rename(sourceFile, afterPath, err => {
|
|
86
|
+
if (err) console.error(err);
|
|
87
|
+
else {
|
|
88
|
+
console.log(`renamed: ${sourceFile} => ${afterPath}`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
69
96
|
/**
|
|
70
97
|
* @returns {TJSToolEntry}
|
|
71
98
|
*/
|
|
@@ -78,31 +105,14 @@ module.exports = () => {
|
|
|
78
105
|
fn() {
|
|
79
106
|
const bases = getBasePaths();
|
|
80
107
|
const ext = params.ext || "js";
|
|
81
|
-
|
|
82
|
-
* ```perl
|
|
83
|
-
* (?:import|export) # comments
|
|
84
|
-
* \s*
|
|
85
|
-
* (?:
|
|
86
|
-
* "(?=[.\/]+)| # character ["] \x22 e.g - import "../global/index"
|
|
87
|
-
* (?:
|
|
88
|
-
* [\w_]+\s+| # default import, e.g - import fs from "./file";
|
|
89
|
-
* (?:[\w_]+\s*,\s*)?\{[^}]+\}\s*| # e.g - import View, { TitiledSphereMesh } from "./view";
|
|
90
|
-
* \*\s*as\s+[\w_]+\s+| # e.g - export * as OO from "./rateLimiter";
|
|
91
|
-
* \*\s* # e.g - export * from "./rateLimiter";
|
|
92
|
-
* )from\s*"(?:[.\/]+) # Positive Lookahead (./|../|../../) ...
|
|
93
|
-
* )
|
|
94
|
-
* (?:[^"]*)
|
|
95
|
-
* (?<!\.js) # Negative Lookbehind not(/\.(?:c|m)?js/)
|
|
96
|
-
* (?="\s*;?)
|
|
97
|
-
* ```
|
|
98
|
-
* @see regex details see {@link https://regex101.com/r/EpuQLT/32 regex101.com}
|
|
99
|
-
*/
|
|
108
|
+
/* const sourceFiles = await */
|
|
100
109
|
processSources(
|
|
101
110
|
/** @type {string} */ (this.taskName), (data) => {
|
|
102
111
|
reImportExportDetection.lastIndex = 0;
|
|
103
112
|
return data.replace(reImportExportDetection, getReplacer(ext));
|
|
104
113
|
}, {
|
|
105
114
|
bases,
|
|
115
|
+
cb: emitProcessCallback(ext)
|
|
106
116
|
},
|
|
107
117
|
);
|
|
108
118
|
},
|
package/tool-lib/ps.js
CHANGED
|
@@ -50,7 +50,7 @@ module.exports = {
|
|
|
50
50
|
* @param {(source: string) => Promise<string> | string} process
|
|
51
51
|
* @param {TProcessSourcesOpt} [opt]
|
|
52
52
|
*/
|
|
53
|
-
function processSources(taskName, process, opt = {}) {
|
|
53
|
+
async function processSources(taskName, process, opt = {}) {
|
|
54
54
|
const {
|
|
55
55
|
root = params.root,
|
|
56
56
|
base = "./build",
|
|
@@ -58,6 +58,7 @@ module.exports = {
|
|
|
58
58
|
test = /\.js$/,
|
|
59
59
|
suffix = "",
|
|
60
60
|
targets,
|
|
61
|
+
cb
|
|
61
62
|
} = opt;
|
|
62
63
|
/**
|
|
63
64
|
* 主に javascript 系 file を push する.
|
|
@@ -89,41 +90,49 @@ module.exports = {
|
|
|
89
90
|
DEBUG && console.log("processSources::processSources:", sourceFiles);
|
|
90
91
|
let count = sourceFiles.length;
|
|
91
92
|
let written = 0;
|
|
93
|
+
/** @type {() => void} */
|
|
94
|
+
let psResolve;
|
|
92
95
|
/** @type {(fileName?: string) => void} */
|
|
93
96
|
const done = (fileName) => {
|
|
94
97
|
--count === 0 && (
|
|
95
|
-
console.timeEnd(taskName), utils.log(`[${taskName}] file written: ${written}`)
|
|
98
|
+
console.timeEnd(taskName), utils.log(`[${taskName}] file written: ${written}`),
|
|
99
|
+
psResolve()
|
|
96
100
|
);
|
|
97
101
|
if (verbose && fileName) {
|
|
98
102
|
utils.log(`[${taskName}] done: ${fileName}`);
|
|
99
103
|
}
|
|
100
104
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
105
|
+
await /** @type {Promise<void>} */(new Promise(resolve => {
|
|
106
|
+
psResolve = resolve;
|
|
107
|
+
count && console.time(taskName);
|
|
108
|
+
for (const sourceFile of sourceFiles) {
|
|
109
|
+
fs.stat(sourceFile, (statErr, stat) => {
|
|
110
|
+
if (statErr) {
|
|
111
|
+
return handleError(statErr, () => done(sourceFile));
|
|
112
|
+
}
|
|
113
|
+
if (stat.isFile()) {
|
|
114
|
+
fs.readFile(sourceFile, "utf8", async (readErr, code) => {
|
|
115
|
+
if (readErr) {
|
|
116
|
+
return handleError(readErr, () => done(sourceFile));
|
|
117
|
+
}
|
|
118
|
+
const result = await runProcess(code, process);
|
|
119
|
+
const outputPath = sourceFile.replace(/(?=\.js$)/, suffix);
|
|
120
|
+
if (result !== code) {
|
|
121
|
+
fs.writeFile(outputPath, result, () => {
|
|
122
|
+
written++, done(outputPath);
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
done(outputPath);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
done(sourceFile);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
cb && cb(sourceFiles);
|
|
135
|
+
return sourceFiles;
|
|
127
136
|
}
|
|
128
137
|
globalThis.processSources = processSources;
|
|
129
138
|
},
|
package/tool-lib/rws.js
CHANGED
package/tool-lib/tools.d.ts
CHANGED
|
@@ -25,13 +25,13 @@ declare global {
|
|
|
25
25
|
taskName: string,
|
|
26
26
|
process: (source: string) => Promise<string> | string,
|
|
27
27
|
options?: TProcessSourcesOpt
|
|
28
|
-
):
|
|
28
|
+
): Promise<string[]>;
|
|
29
29
|
/** regex replace sig */
|
|
30
30
|
declare type TStringReplacer = (matchs: string, ...args: any[]) => string;
|
|
31
31
|
/** use `(R)ecord(W)ebpack(S)ize` */
|
|
32
32
|
declare type TRwsTags = "webpack" | "umd" | "bin";
|
|
33
33
|
declare var params: ReturnType<typeof import("tin-args")<TToolArgs>>;
|
|
34
|
-
declare
|
|
34
|
+
declare var isArray: typeof Array.isArray;
|
|
35
35
|
/**
|
|
36
36
|
* @date 2025/2/18 0:46:03
|
|
37
37
|
*/
|
|
@@ -68,7 +68,7 @@ declare global {
|
|
|
68
68
|
* cjbm, minify, rmc
|
|
69
69
|
*/
|
|
70
70
|
basePath: string | string[];
|
|
71
|
-
/** processSources, cmtTrick,
|
|
71
|
+
/** processSources, cmtTrick, replace, rmc */
|
|
72
72
|
targets: string[];
|
|
73
73
|
/** minify, rmc */
|
|
74
74
|
suffix: string;
|
|
@@ -84,7 +84,7 @@ declare global {
|
|
|
84
84
|
ext: string;
|
|
85
85
|
/** shared, minify, rmc */
|
|
86
86
|
test: RegExp;
|
|
87
|
-
/**
|
|
87
|
+
/** replace */
|
|
88
88
|
regex: RegExp;
|
|
89
89
|
/** rmc */
|
|
90
90
|
rmc4ts: boolean;
|
|
@@ -117,7 +117,7 @@ declare global {
|
|
|
117
117
|
/** want help? form - "-help <cmd name>" */
|
|
118
118
|
help: string;
|
|
119
119
|
/**
|
|
120
|
-
* for
|
|
120
|
+
* for replace
|
|
121
121
|
* @date 2024-01-05
|
|
122
122
|
*/
|
|
123
123
|
after: string;
|
|
@@ -138,6 +138,7 @@ declare global {
|
|
|
138
138
|
test?: RegExp;
|
|
139
139
|
targets?: string[];
|
|
140
140
|
suffix?: string;
|
|
141
|
+
cb?: (sourceFiles: string[]) => void
|
|
141
142
|
}
|
|
142
143
|
declare type TJSToolEntry = {
|
|
143
144
|
fn: (mode?: string) => void;
|
package/tools.d.ts
CHANGED
package/tools.js
CHANGED
|
@@ -12,11 +12,11 @@ const fs = require("fs");
|
|
|
12
12
|
const path = require("path");
|
|
13
13
|
/* utilities module by own. */
|
|
14
14
|
const utils = require("./utils");
|
|
15
|
-
// @ts-expect-error
|
|
15
|
+
// @ts-expect- error
|
|
16
16
|
global.params = require("tin-args")();
|
|
17
|
-
// @ts-expect-error
|
|
17
|
+
// @ts-expect- error
|
|
18
18
|
global.verbose = params.verb;
|
|
19
|
-
// @ts-expect-error
|
|
19
|
+
// @ts-expect- error
|
|
20
20
|
global.isArray = Array.isArray;
|
|
21
21
|
require("./tool-lib/ps").globalize(fs, utils);
|
|
22
22
|
utils.log(params);
|
|
@@ -58,25 +58,6 @@ const ToolFunctions = {
|
|
|
58
58
|
rws: require("./tool-lib/rws")(fs, utils),
|
|
59
59
|
cjbm: require("./tool-lib/cjbm")(),
|
|
60
60
|
cmtTrick: require("./tool-lib/cmt-trick")(),
|
|
61
|
-
stripWebpack: {
|
|
62
|
-
taskName: "stripWebpack",
|
|
63
|
-
fn() {
|
|
64
|
-
const re =
|
|
65
|
-
params.regex ||
|
|
66
|
-
/!function\s*\((.+?)\)(?:(.+?=.\(\)\})|([^]+)(?=\(.\.restrictor\s*\|\|))/g;
|
|
67
|
-
if (re) {
|
|
68
|
-
processSources(this.taskName, (data) => data.replace(re, ""), {
|
|
69
|
-
base: "",
|
|
70
|
-
targets: [
|
|
71
|
-
"./dist/umd/index.js",
|
|
72
|
-
"./dist/webpack/index.js",
|
|
73
|
-
"./dist/webpack-esm/index.mjs",
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
help: 'jstool -cmd stripWebpack -regex "%npm_package_defs_regex%"',
|
|
79
|
-
},
|
|
80
61
|
/**
|
|
81
62
|
* Performs string substitutions on various file contents
|
|
82
63
|
*
|
|
@@ -84,8 +65,8 @@ const ToolFunctions = {
|
|
|
84
65
|
*
|
|
85
66
|
* @date 2020/6/11
|
|
86
67
|
*/
|
|
87
|
-
|
|
88
|
-
taskName: "
|
|
68
|
+
replace: {
|
|
69
|
+
taskName: "replace",
|
|
89
70
|
fn() {
|
|
90
71
|
const re = params.regex;
|
|
91
72
|
const after = params.after || "";
|
|
@@ -96,12 +77,12 @@ const ToolFunctions = {
|
|
|
96
77
|
});
|
|
97
78
|
}
|
|
98
79
|
},
|
|
99
|
-
help: `jstool -cmd
|
|
80
|
+
help: `jstool -cmd replace [-after <replacement>] -regex \"/^\\s+<!--[\\s\\S]+?-->(?:\\r?\\n)?/gm\" [-targets "<path>,<path>,..." | <args: file, file file...>]
|
|
100
81
|
note:
|
|
101
82
|
targets - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
102
83
|
note: targets - can use args parameter instead
|
|
103
84
|
It is better to use the <args: file, file file...>
|
|
104
|
-
e.g - jstool -cmd
|
|
85
|
+
e.g - jstool -cmd replace -after ".." -regex "re/(?<=reference path=\")(\\.)(?=\\/index.d.ts\")/" build/**/*.js
|
|
105
86
|
^^^^^^^^^^^^^
|
|
106
87
|
`,
|
|
107
88
|
},
|
|
@@ -146,8 +127,8 @@ const ToolFunctions = {
|
|
|
146
127
|
? [params.extras]
|
|
147
128
|
: [];
|
|
148
129
|
if (paths.length) {
|
|
149
|
-
utils.fireReplace(/(v)?(\d+\.\d+\.\d+)(
|
|
150
|
-
if ($
|
|
130
|
+
utils.fireReplace(/(v)?(\d+\.\d+\.\d+)(?:-\w+)?/g, /** @type {TStringReplacer} */($0, $prefix, $versionStr) => {
|
|
131
|
+
if ($versionStr === currentVersion && $prefix) {
|
|
151
132
|
return "v" + nextVersion;
|
|
152
133
|
}
|
|
153
134
|
return $0;
|
package/tsconfig.json
CHANGED
|
@@ -7,14 +7,19 @@
|
|
|
7
7
|
"removeComments": false,
|
|
8
8
|
"moduleResolution": "nodenext",
|
|
9
9
|
"resolveJsonModule": true,
|
|
10
|
-
"baseUrl": "./",
|
|
11
10
|
"declaration": true,
|
|
12
11
|
"emitDeclarationOnly": true,
|
|
13
12
|
"allowJs": true,
|
|
14
13
|
"checkJs": true,
|
|
15
14
|
"target": "es2019",
|
|
16
|
-
"module": "
|
|
17
|
-
"outDir": "./build"
|
|
15
|
+
"module": "nodenext",
|
|
16
|
+
"outDir": "./build",
|
|
17
|
+
// "baseUrl": ".",
|
|
18
|
+
"paths": {
|
|
19
|
+
"*": [
|
|
20
|
+
"./*"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
18
23
|
},
|
|
19
24
|
"include": [
|
|
20
25
|
"index.js",
|
|
@@ -25,6 +30,6 @@
|
|
|
25
30
|
"./**/*.d.ts"
|
|
26
31
|
],
|
|
27
32
|
"exclude": [
|
|
28
|
-
|
|
33
|
+
"./**/npm-outdated*.js",
|
|
29
34
|
]
|
|
30
35
|
}
|
package/utils.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import type {
|
|
11
11
|
Dirent
|
|
12
12
|
} from "fs";
|
|
13
|
-
export const
|
|
13
|
+
export const tinArgs: typeof import("tin-args");
|
|
14
14
|
export type TFsCallback = (err: any, data: string) => void;
|
|
15
15
|
export type TypedRecord<T> = {
|
|
16
16
|
[x: string]: T;
|
|
@@ -71,12 +71,12 @@ export function removeJsonComments(source: string): string;
|
|
|
71
71
|
* @param {string} dest content output path
|
|
72
72
|
* @param {() => void} [callback] the callback function
|
|
73
73
|
*/
|
|
74
|
-
export function
|
|
74
|
+
export function writeText(content: string | NodeJS.ReadableStream | Buffer, dest: string, callback?: () => void): void;
|
|
75
75
|
/**
|
|
76
76
|
* @param {string} from file path.
|
|
77
77
|
* @param [callback]
|
|
78
78
|
*/
|
|
79
|
-
export function
|
|
79
|
+
export function readText<C extends TBD<TFsCallback>, R extends undefined extends C ? string : void>(from: string, callback?: C): R;
|
|
80
80
|
/**
|
|
81
81
|
* NOTE: when callback specified, returns undefined
|
|
82
82
|
*
|
package/utils.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
const fs = require("fs");
|
|
23
23
|
const path = require("path");
|
|
24
24
|
const lib = require("./common");
|
|
25
|
-
const
|
|
25
|
+
const tinArgs = require("tin-args");
|
|
26
26
|
const CI = !!process.env.CI;
|
|
27
27
|
/**
|
|
28
28
|
* Nothing is logged in a CI environment.
|
|
@@ -96,7 +96,7 @@ function walkDirSync(path, handler) {
|
|
|
96
96
|
* @param {string} dest content output path
|
|
97
97
|
* @param {() => void} [callback] the callback function
|
|
98
98
|
*/
|
|
99
|
-
function
|
|
99
|
+
function writeText(content, dest, callback) {
|
|
100
100
|
lib.checkParentDirectory(dest);
|
|
101
101
|
const ws = fs.createWriteStream(dest);
|
|
102
102
|
ws.on("error", function (err) {
|
|
@@ -114,7 +114,7 @@ function writeTextUTF8(content, dest, callback) {
|
|
|
114
114
|
ws.end();
|
|
115
115
|
});
|
|
116
116
|
} else {
|
|
117
|
-
|
|
117
|
+
ws.end();
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
else if ("readable" in content) {
|
|
@@ -131,7 +131,7 @@ function writeTextUTF8(content, dest, callback) {
|
|
|
131
131
|
* @param {C} [callback]
|
|
132
132
|
* @returns {R} description
|
|
133
133
|
*/
|
|
134
|
-
function
|
|
134
|
+
function readText(from, callback) {
|
|
135
135
|
if (typeof callback === "function") {
|
|
136
136
|
fs.readFile(from, "utf8", callback);
|
|
137
137
|
} else {
|
|
@@ -159,11 +159,11 @@ function readTextUTF8(from, callback) {
|
|
|
159
159
|
*/
|
|
160
160
|
function readJson(path, callback) {
|
|
161
161
|
if (typeof callback === "function") {
|
|
162
|
-
|
|
162
|
+
readText(path, (err, data) => {
|
|
163
163
|
callback(err, JSON.parse(data));
|
|
164
164
|
});
|
|
165
165
|
} else {
|
|
166
|
-
const data =
|
|
166
|
+
const data = readText(path);
|
|
167
167
|
return JSON.parse(data);
|
|
168
168
|
}
|
|
169
169
|
return /** @type {R} */ (undefined);
|
|
@@ -360,7 +360,7 @@ function copyText(content, message = "text copied!", chcp65001 = true) {
|
|
|
360
360
|
*/
|
|
361
361
|
function convertRelativeDir(vinyl, dest = ".") {
|
|
362
362
|
let x = vinyl.cwd.length + 1;
|
|
363
|
-
let relative_dir = vinyl.base.
|
|
363
|
+
let relative_dir = vinyl.base.slice(x);
|
|
364
364
|
return `${dest}/${relative_dir}`;
|
|
365
365
|
}
|
|
366
366
|
/**
|
|
@@ -388,10 +388,10 @@ module.exports = {
|
|
|
388
388
|
prependStringTo,
|
|
389
389
|
extractVersion,
|
|
390
390
|
dateStringForFile,
|
|
391
|
-
|
|
391
|
+
tinArgs,
|
|
392
392
|
removeJsonComments,
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
writeText,
|
|
394
|
+
readText,
|
|
395
395
|
readJson,
|
|
396
396
|
walkDirSync,
|
|
397
397
|
compressScript,
|