js-dev-tool 1.0.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.
@@ -0,0 +1,245 @@
1
+ /*!
2
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
+ Copyright (C) 2023 jeffy-g <hirotom1107@gmail.com>
4
+ Released under the MIT license
5
+ https://opensource.org/licenses/mit-license.php
6
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
+ */
8
+ /// <reference path="../regex.d.ts"/>
9
+
10
+ declare const ImportExportDetectRegex = `(?<!\\/\\/+\\s*)(?:import|export)\\s*(?:"(?!https?:)(?=[.\\/]+)\
11
+ (?:(?<globalName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)"|\
12
+ \\(\\s*"(?!https?:)(?=[.\\/]+)(?<dynamicName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?"\\s*\\)|\
13
+ (?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*"(?!https?:)(?=[.\\/]+)(?:(?<moduleName>(?:[.\\/]+)?[^"]+?)\
14
+ (?:\\.(?<moduleExt>(?:c|m)?jsx?))?)")(?=\\s*;)?`;
15
+ declare const reOk: ReturnType<typeof XRegex.createRegExp<typeof ImportExportDetectRegex>>;
16
+ type TRegexDetectRet = XRegex.ReGroups<typeof reOk>;
17
+ /* ctt
18
+ // DONE: 2025/3/18 17:49:31 ok, result is 1, works
19
+ type OKK = TRegexDetectRet extends TImportExportRegexGroup ? 1: 0;
20
+ /*/
21
+ //*/
22
+
23
+ /**
24
+ * @date 2023-10-25
25
+ */
26
+ declare global {
27
+
28
+ // DEVNOTE: 2025/3/18 17:51:42 - Retained for a while as a product of the past
29
+ // type TRegexImportExportDetectorGroupNames =
30
+ // | "clause"
31
+ // | "dynamicExt"
32
+ // | "dynamicName"
33
+ // | "globalExt"
34
+ // | "globalName"
35
+ // | "moduleExt"
36
+ // | "moduleName";
37
+ // type TImportExportRegexGroup = {
38
+ // [K in TRegexImportExportDetectorGroupNames]?: string;
39
+ // };
40
+ type TRegexImportExportDetectorReplacer = function(
41
+ string, string, string, string, string, string, string, string, number, string,
42
+ TRegexDetectRet
43
+ ): string;
44
+
45
+ declare function processSources(
46
+ taskName: string,
47
+ process: (source: string) => Promise<string> | string,
48
+ options?: TProcessSourcesOpt
49
+ ): void;
50
+
51
+ /** regex replace sig */
52
+ declare type TStringReplacer = (matchs: string, ...args: any[]) => string;
53
+
54
+ /** use `(R)ecord(W)ebpack(S)ize` */
55
+ declare type TRwsTags = "webpack" | "umd" | "bin";
56
+
57
+
58
+ declare var params: ReturnType<typeof import("tin-args")<TToolArgs>>;
59
+
60
+ /**
61
+ * @date 2025/2/18 0:46:03
62
+ */
63
+ declare function getBasePaths(): string[] | undefined;
64
+
65
+ /**
66
+ * + tool option `verb`
67
+ */
68
+ declare var verbose: TBD<true>;
69
+ /**
70
+ * tools command arg types
71
+ */
72
+ declare type TToolArgs = {
73
+
74
+ /**
75
+ * parameter is used to specify the root directory of the source code scan.
76
+ *
77
+ * This is used in the `processSources` function to determine the base path for scanning.
78
+ *
79
+ * @since 1.4.35
80
+ */
81
+ root?: string;
82
+ /**
83
+ * @since 1.4.28
84
+ */
85
+ shell?: string;
86
+
87
+ /**
88
+ * print jstool version
89
+ * @date 2025/1/23 11:37:58
90
+ */
91
+ v?: true;
92
+
93
+ /** task command shortten name */
94
+ cmd: string;
95
+
96
+ /**
97
+ * processSources
98
+ * cjbm, minify, rmc
99
+ */
100
+ basePath: string | string[];
101
+ /** processSources, cmtTrick, stripSome, rmc */
102
+ targets: string[];
103
+ /** minify, rmc */
104
+ suffix: string;
105
+
106
+ // version
107
+ major?: true;
108
+ minor?: true;
109
+ patch?: true;
110
+ extras: string[];
111
+
112
+ /** rws, backup */
113
+ dest: string;
114
+ /** backup */
115
+ projectName: string;
116
+
117
+ /** for `cjbm` replace extension. default is `js` */
118
+ ext: string;
119
+
120
+ /** shared, minify, rmc */
121
+ test: RegExp;
122
+
123
+ /** stripWebpack, stripSome */
124
+ regex: RegExp;
125
+
126
+ /** rmc */
127
+ rmc4ts: boolean;
128
+
129
+ // rws
130
+ /**
131
+ * webpacked source path.
132
+ * @default `./dist/webpack/index.js`
133
+ */
134
+ webpack: string;
135
+ /**
136
+ * webpacked source path.
137
+ * @default `./dist/umd/index.js`
138
+ */
139
+ umd: string;
140
+ /**
141
+ * webpacked source path.
142
+ * @default `./dist/bin/index.js`
143
+ */
144
+ bin: string;
145
+ /**
146
+ * if need other name then use this option.
147
+ * ```js
148
+ * `./dist/${tag}/index.js`
149
+ * ```
150
+ */
151
+ "rws-tags": `${string}:${string}` | `${string}:${string}`[];
152
+
153
+ /** zip comment */
154
+ comment: string;
155
+ /** specify target package.json(s) [version] */
156
+ pkgJsons: string[];
157
+
158
+ /** want help? form - "-help <cmd name>" */
159
+ help: string;
160
+
161
+ /**
162
+ * for stripSome
163
+ * @date 2024-01-05
164
+ */
165
+ after: string;
166
+ /** want print written file name? */
167
+ verb: true;
168
+
169
+ /**
170
+ * @date 2025/4/6 17:09:40
171
+ */
172
+ debug?: true;
173
+ }
174
+
175
+ // /**
176
+ // * @typedef {
177
+ // (path: string, handler: (dirent: import("fs").Dirent) => void) => void
178
+ // } TWalkDirSyncFunction
179
+ // */
180
+ declare type TWalkDirSyncFunction = (path: string, handler: (dirent: import("fs").Dirent) => void) => void;
181
+
182
+ // /**
183
+ // * @typedef TProcessSourcesOpt
184
+ // * @prop {string} [base]
185
+ // * @prop {string[]} [bases] Array of search directory paths, overriding "base"
186
+ // * @prop {RegExp} [test] default: `/\.js$/`
187
+ // * @prop {string[]} [targets]
188
+ // * @prop {string} [suffix]
189
+ // */
190
+ declare type TProcessSourcesOpt = {
191
+ root?: string;
192
+ base?: string;
193
+ /** Array of search directory paths, overriding "base" */
194
+ bases?: string[];
195
+ /** @default `/\.js$/` */
196
+ test?: RegExp;
197
+ targets?: string[];
198
+ suffix?: string;
199
+ }
200
+
201
+ // /**
202
+ // * @typedef {{
203
+ // * fn: () => void;
204
+ // * help: string;
205
+ // * taskName: string;
206
+ // * }} TJSToolEntry
207
+ // */
208
+ declare type TJSToolEntry = {
209
+ fn: (mode?: string) => void;
210
+ help: string;
211
+ taskName: string;
212
+ }
213
+
214
+ /**
215
+ * version command type
216
+ */
217
+ declare type TVersionString = `${number}.${number}.${number}`;
218
+ // unused
219
+ // type TNVersion = [number, number, number];
220
+ declare type TVersionRecords = Record<TVersionString, Partial<Record<TRwsTags, number>>>;
221
+ declare type TSizeRecordEntry = TVersionRecords["0.0.0"];
222
+
223
+ // /**
224
+ // * @typedef TRecordWebpackSizeArgs
225
+ // * @prop {string} dest - record path
226
+ // * @prop {string} webpack - webpacked source path. default `./dist/webpack/index.js`
227
+ // * @prop {string} umd - webpacked umd source path. default `./dist/umd/index.js`
228
+ // * @prop {string} bin - webpacked bin source path. default `./dist/bin/index.js`
229
+ // *
230
+ // * @typedef TCJBMArgs currentlly support `js` only
231
+ // * @prop {string | string[]} basePath - source scan path
232
+ // */
233
+ // type TRecordWebpackSizeArgs = {
234
+ // /** record path */
235
+ // dest: string;
236
+ // /** {@link TToolArgs.webpack webpack} */
237
+ // webpack: string;
238
+ // /** {@link TToolArgs.umd umd} */
239
+ // umd: string;
240
+ // /** {@link TToolArgs.bin bin} */
241
+ // bin: string;
242
+ // }
243
+ }
244
+
245
+ export = {};
@@ -0,0 +1,34 @@
1
+ /*!
2
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
+ Copyright (C) 2023 jeffy-g <hirotom1107@gmail.com>
4
+ Released under the MIT license
5
+ https://opensource.org/licenses/mit-license.php
6
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
+ */
8
+ /// <reference path="./tools.d.ts"/>
9
+ // @ts-check
10
+
11
+ /**
12
+ * @file zip compression task
13
+ */
14
+ module.exports =
15
+ /**
16
+ * @param {import("../utils")} utils
17
+ * @returns {TJSToolEntry}
18
+ */
19
+ (utils) => {
20
+ return {
21
+ taskName: "zip",
22
+ fn() {
23
+ const comment = params.comment;
24
+ const paths = params.args;
25
+ if (Array.isArray(paths)) {
26
+ for (let i = 0, end = paths.length; i < end; ) {
27
+ const path = paths[i++];
28
+ utils.compressScript(path, comment);
29
+ }
30
+ }
31
+ },
32
+ help: `jstool -cmd zip [-comment "the comment"] lib/webpack.js lib/type-ids.js`,
33
+ };
34
+ };
package/tools.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export type {
2
+ TToolArgs,
3
+ TJSToolEntry,
4
+ TZipArgs,
5
+ TRecordWebpackSizeArgs,
6
+ TCJBMArgs
7
+ } from "./tools.js";