js-dev-tool 1.2.7 → 1.2.8
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/basic-types.d.ts +14 -10
- package/package.json +1 -1
- package/tools.js +17 -21
package/basic-types.d.ts
CHANGED
|
@@ -24,12 +24,12 @@ type TBD<T> = T | undefined;
|
|
|
24
24
|
type TBC<T> = T | null;
|
|
25
25
|
type Maybe<T> = T | null | undefined;
|
|
26
26
|
/**
|
|
27
|
-
* T is falsy then return A,
|
|
28
|
-
*
|
|
27
|
+
* T is falsy then return A, truthy then B
|
|
28
|
+
*
|
|
29
29
|
* ```ts
|
|
30
30
|
* type ConditionalX<T, A, B> = T extends (void | false | undefined) ? A : B // <- maybe not works
|
|
31
31
|
* type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
|
|
32
|
-
*
|
|
32
|
+
*
|
|
33
33
|
* function x<T extends true | void, R extends ConditionalX<T, string, string[]>>(need?: T): R {
|
|
34
34
|
* return (need? "": [""]) as R;
|
|
35
35
|
* }
|
|
@@ -80,15 +80,18 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
|
80
80
|
type Constructor<T> = new (...args: any[]) => T;
|
|
81
81
|
/**
|
|
82
82
|
* mark a specific property as `required`
|
|
83
|
-
*
|
|
84
|
-
* + About `
|
|
83
|
+
*
|
|
84
|
+
* + About `Flatten` parameter - Accepts values of `1` or `0`.
|
|
85
85
|
* - If it is **1**, the types are displayed concatenated.
|
|
86
86
|
* - If it is **0**, the types are displayed separated by "&".
|
|
87
|
+
*
|
|
88
|
+
* @date Renamed due to reasons. (`RequireThese` to `RequireKeys`)
|
|
87
89
|
*/
|
|
88
|
-
type
|
|
89
|
-
T, K extends keyof T
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
type RequireKeys<
|
|
91
|
+
T, K extends keyof T = keyof T,
|
|
92
|
+
Flatten extends 1 | 0 = 0,
|
|
93
|
+
Intersected = T & { [P in K]-?: T[P] }
|
|
94
|
+
> = Flatten extends 1 ? Prettify<Intersected> : Intersected;
|
|
92
95
|
/**
|
|
93
96
|
* pick any `property` as excludes
|
|
94
97
|
*/
|
|
@@ -118,8 +121,9 @@ type TypedCtor<T> = {
|
|
|
118
121
|
interface ITypedCtor<T> extends TypedCtor<T> {}
|
|
119
122
|
/**
|
|
120
123
|
* Array.sort etc...
|
|
124
|
+
* @date 2026/03/03 - Improved to allow comparison of different types
|
|
121
125
|
*/
|
|
122
|
-
declare type TComparator<T> = (a: T, b:
|
|
126
|
+
declare type TComparator<T, T2 = T> = (a: T, b: T2) => number;
|
|
123
127
|
/**
|
|
124
128
|
* Generates all combinations of the string S. The order of characters does not matter.
|
|
125
129
|
* @template S - The target string type
|
package/package.json
CHANGED
package/tools.js
CHANGED
|
@@ -9,16 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
// @ts-check
|
|
11
11
|
"use strict";
|
|
12
|
+
require("colors.ts");
|
|
12
13
|
const fs = require("fs");
|
|
13
14
|
const path = require("path");
|
|
14
15
|
const rmc = require("rm-cstyle-cmts");
|
|
15
16
|
/* utilities module by own. */
|
|
16
17
|
const utils = require("./utils");
|
|
17
|
-
// @ts-expect- error
|
|
18
18
|
global.params = require("tin-args")();
|
|
19
|
-
// @ts-expect- error
|
|
20
19
|
global.verbose = params.verb;
|
|
21
|
-
// @ts-expect- error
|
|
22
20
|
global.isArray = Array.isArray;
|
|
23
21
|
require("./tool-lib/ps").globalize(fs, utils);
|
|
24
22
|
utils.log(params);
|
|
@@ -83,21 +81,28 @@ const ToolFunctions = {
|
|
|
83
81
|
fn() {
|
|
84
82
|
const re = params.regex;
|
|
85
83
|
const after = params.after || "";
|
|
84
|
+
let targets = params.args || params.targets
|
|
85
|
+
if (typeof targets === "string") targets = [targets];
|
|
86
|
+
params.targets = targets;
|
|
86
87
|
if (re) {
|
|
87
88
|
processSources(this.taskName, (data) => data.replace(re, after), {
|
|
88
89
|
base: "",
|
|
89
|
-
targets: params.args || params.targets,
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
help
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
get help() {
|
|
94
|
+
return `jstool -cmd replace [-after <replacement>] -regex \"/^\\s+<!--[\\s\\S]+?-->(?:\\r?\\n)?/gm\" [-targets "<path>,<path>,..." | <args: file, file file...>]
|
|
95
|
+
|
|
96
|
+
${"Options:".red}
|
|
97
|
+
${"after".cyan} ${`: If omitted, "" (empty string) is used, meaning that the matched string is deleted.`.gray(16)}
|
|
98
|
+
${"targets".cyan}${`: Single path string or Array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."`.gray(16)}
|
|
99
|
+
|
|
100
|
+
${"remarks".magenta}${": targets - can use args parameter instead".gray(16)}${`
|
|
101
|
+
It is better to use the <args: file, file file...>
|
|
102
|
+
e.g - ${"jstool".yellow} ${"-cmd".green} ${"replace".cyan} ${"-after".green} ${`".."`.red} ${"-regex".green} ${String.raw`'re/(?<=reference path=")(\.)(?=\/index.d.ts")/'`.magenta} ${"build/**/*.js".gray(16)}
|
|
103
|
+
^^^^^^^^^^^^^
|
|
104
|
+
`.gray(16)}`;
|
|
105
|
+
},
|
|
101
106
|
},
|
|
102
107
|
version: {
|
|
103
108
|
taskName: "version",
|
|
@@ -287,19 +292,11 @@ function isJSToolEntry(entry) {
|
|
|
287
292
|
if (typeof entry !== "object") return false;
|
|
288
293
|
return typeof entry.fn === "function" && typeof entry.help === "string";
|
|
289
294
|
}
|
|
290
|
-
let colorEnable = false;
|
|
291
|
-
function enableColors() {
|
|
292
|
-
if (!colorEnable) {
|
|
293
|
-
require("colors.ts");
|
|
294
|
-
colorEnable = true;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
295
|
/**
|
|
298
296
|
* @param {string} cmd
|
|
299
297
|
* @returns {void}
|
|
300
298
|
*/
|
|
301
299
|
function printHelp(cmd) {
|
|
302
|
-
enableColors();
|
|
303
300
|
const entry = ToolFunctions[cmd];
|
|
304
301
|
console.log(`${cmd.yellow + " help:".green} ${entry.help.gray(8)}`);
|
|
305
302
|
}
|
|
@@ -318,7 +315,6 @@ if (params.cmd) {
|
|
|
318
315
|
process.cwd(),
|
|
319
316
|
);
|
|
320
317
|
} else if (params.v) {
|
|
321
|
-
enableColors();
|
|
322
318
|
const thisVersion = require("./package.json").version;
|
|
323
319
|
console.log(
|
|
324
320
|
`${"jstool".magenta} in "js-dev-scripts", version: ${thisVersion.green}
|