js-dev-tool 1.0.6 → 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/package.json +1 -1
- package/scripts/normalize-commit-msg.mjs +22 -0
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +29 -19
- package/tool-lib/ps.js +37 -28
- package/tool-lib/tools.d.ts +2 -1
package/package.json
CHANGED
|
@@ -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,6 +11,8 @@
|
|
|
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
|
*/
|
|
@@ -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/tools.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ 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` */
|
|
@@ -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;
|