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.
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/basic-types.d.ts +279 -0
- package/common/index.d.ts +43 -0
- package/common/index.js +101 -0
- package/extras/tiny-progress.d.ts +14 -0
- package/extras/tiny-progress.js +74 -0
- package/index.d.ts +27 -0
- package/index.js +15 -0
- package/lib/unzip.min.js +812 -0
- package/lib/zip.min.js +1036 -0
- package/lib/zlibjs.d.ts +34 -0
- package/package.json +51 -0
- package/progress/index.d.ts +92 -0
- package/progress/index.js +305 -0
- package/progress/progress-extras.js +90 -0
- package/progress/rnd-spinner.js +55 -0
- package/progress/spinners.d.ts +74 -0
- package/progress/spinners.json +805 -0
- package/progress/test.js +94 -0
- package/regex.d.ts +154 -0
- package/scripts/publish-version.json +3 -0
- package/scripts/unzip.js +30 -0
- package/scripts/zip.js +138 -0
- package/tool-lib/cjbm.js +239 -0
- package/tool-lib/cjmb-regex-latest.svg +366 -0
- package/tool-lib/cjmb-regex.svg +90 -0
- package/tool-lib/cmt-trick.js +125 -0
- package/tool-lib/ps.js +158 -0
- package/tool-lib/rws.js +181 -0
- package/tool-lib/tools.d.ts +245 -0
- package/tool-lib/zip-task.js +34 -0
- package/tools.d.ts +7 -0
- package/tools.js +450 -0
- package/tsconfig.json +25 -0
- package/utils.d.ts +194 -0
- package/utils.js +643 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 jeffy-g
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# js-tool
|
|
2
|
+
|
|
3
|
+
A collection of command-line tools to assist in JavaScript project development.
|
|
4
|
+
|
|
5
|
+
This utility, `jstool`, provides various functions for file manipulation, versioning, and building.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
The primary way to use these tools is through the `jstool` command, which is an alias for `node tools.js`.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# General syntax
|
|
13
|
+
node tools.js -cmd <command_name> [options]
|
|
14
|
+
|
|
15
|
+
# Or if installed globally or via package.json scripts
|
|
16
|
+
jstool -cmd <command_name> [options]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
To see the help for a specific command:
|
|
20
|
+
```bash
|
|
21
|
+
node tools.js -help <command_name>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
Here is a list of available commands registered in `ToolFunctions`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
zip help: jstool -cmd zip [-comment "the comment"] lib/webpack.js lib/type-ids.js
|
|
30
|
+
rws help: (R)ecord(W)ebpack(S)ize
|
|
31
|
+
ex - jstool -cmd rws [-webpack lib/webpack.js -umd umd/webpack.js -dest "./dev-extras/webpack-size.json"] [-rws-tags "web/login:./dist/es/web/login.mjs,webpack-esm:./dist/webpack-esm/index.mjs"]
|
|
32
|
+
note:
|
|
33
|
+
webpack - if not specified then apply "./dist/webpack/index.js"
|
|
34
|
+
umd - if not specified then apply "./dist/umd/index.js"
|
|
35
|
+
bin - if not specified then apply "./dist/bin/index.js"
|
|
36
|
+
rws-tags - It is treated as parameter array separated by ":", e.g - "web/login:./dist/es/web/login.mjs,webpack-esm:./dist/webpack-esm/index.mjs"
|
|
37
|
+
dest - if not specified then apply "./logs/webpack-size.json"
|
|
38
|
+
|
|
39
|
+
cjbm help: (C)onvert (J)S to (B)rowser (M)odule
|
|
40
|
+
ex - jstool -cmd cjbm [-root ./build | -basePath "./dist/esm,extra-tests/mini-semaphore"] [-ext js] [-targets "['core.js', 'object.js']"]
|
|
41
|
+
note:
|
|
42
|
+
root - Recursively searches for files.
|
|
43
|
+
This option is useful, but if there are directories that need to be avoided, use the 'basePath' option
|
|
44
|
+
basePath - can be "<path>,<path>,..." (array type arg)
|
|
45
|
+
ext - specifies the module extension for import clauses. default is "js"
|
|
46
|
+
targets - specify this if you want to apply it only to a specific file.
|
|
47
|
+
the file specified here should be directly under `basePath`!
|
|
48
|
+
value must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
49
|
+
|
|
50
|
+
cmtTrick help: Do comment trick toggle
|
|
51
|
+
It recognizes three markers: `ctt | comment-toggle-trick | https://coderwall`
|
|
52
|
+
jstool -cmd cmtTrick[:clean] (-base <source dir> | -bases "<source dir>,<source dir>,...") [-test re/\\.js$/]
|
|
53
|
+
note:
|
|
54
|
+
:clean - remove comment token etc leaving the currently enabled code
|
|
55
|
+
base (or root) - scan single source folder
|
|
56
|
+
bases - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
57
|
+
test - terget extension, default is /\\.js$/
|
|
58
|
+
|
|
59
|
+
stripWebpack help: jstool -cmd stripWebpack -regex "%npm_package_defs_regex%"
|
|
60
|
+
stripSome help: jstool -cmd stripSome [-after <replacement>] -regex "/^\s+<!--[\s\S]+?-->(?:\r?\n)?/gm" [-targets "<path>,<path>,..." | <args: file, file file...>]
|
|
61
|
+
note:
|
|
62
|
+
targets - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
|
|
63
|
+
note: targets - can use args parameter instead
|
|
64
|
+
It is better to use the <args: file, file file...>
|
|
65
|
+
e.g - jstool -cmd stripSome -after ".." -regex "re/(?<=reference path=")(\.)(?=\/index.d.ts")/" build/**/*.js
|
|
66
|
+
^^^^^^^^^^^^^
|
|
67
|
+
|
|
68
|
+
version help: jstool -cmd version [-major | -minor] [-pkgJsons "./package.json,../package.json"] [-extras "test/web/index.html"]
|
|
69
|
+
bump top level package.json version(can specify "package.json" paths by `pkgJsons` option if need), specify patch version is unnecessary.
|
|
70
|
+
note:
|
|
71
|
+
extras - can be "<path>,<path>,..." (array type arg)
|
|
72
|
+
|
|
73
|
+
minify help: jstool -cmd minify -basePath extra-tests/web/mini-semaphore [-test "re/\.js$/"] [-suffix ".mini"]
|
|
74
|
+
note:
|
|
75
|
+
basePath - can be "<path>,<path>,..." (array type arg)
|
|
76
|
+
test - can be omit, default is `/\.js$/`
|
|
77
|
+
suffix - can be omit, default is ".mini"
|
|
78
|
+
|
|
79
|
+
rmc help: $ jstool -cmd rmc -basePath "./dist/cjs,./dist/cjs/gulp" -test "/\.(js|d\.ts)$/"
|
|
80
|
+
note: basePath - can be "<path>,<path>,..." (array type arg)
|
|
81
|
+
test - can be omit, defulat `/.js$/`
|
|
82
|
+
rmc4ts - for typescript source.
|
|
83
|
+
keep comment that start with "/*" when "*/" end mark appears in same line.
|
|
84
|
+
if start with "/*-" remove it
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### `zip`
|
|
90
|
+
Creates a zip archive of specified files.
|
|
91
|
+
* **Usage:** `jstool -cmd zip [-comment "the comment"] file1.js file2.js ...`
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### `rws`
|
|
96
|
+
Records the size of webpack bundles or other files. The name stands for (r)ecord(W)ebpack(S)ize.
|
|
97
|
+
* **Usage:** `jstool -cmd rws -webpack lib/webpack.js -dest "./dev-extras/webpack-size.json"`
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### `cjbm`
|
|
102
|
+
Converts JavaScript files to browser-compatible modules. The name stands for (C)onvert (J)S to (B)rowser (M)odule.
|
|
103
|
+
* **Usage:** `jstool -cmd cjbm -basePath <source_dir> -targets "['file1.js', 'file2.js']"`
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### `cmtTrick`
|
|
108
|
+
Toggles "comment tricks" in the code, useful for conditional code execution during development.
|
|
109
|
+
* **Usage:** `jstool -cmd cmtTrick -basePath <source_dir> -targets "['file1.js', 'file2.js']"`
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
### `stripSome`
|
|
114
|
+
Performs generic string replacement on a set of target files using a regular expression.
|
|
115
|
+
* **Usage:** `jstool -cmd stripSome [-after <replacement>] -regex "<regex>" [-targets "<path1>,<path2>" | <file1> <file2> ...]`
|
|
116
|
+
* **Note:** It's often better to pass target files as direct arguments instead of using the `-targets` option.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### `version`
|
|
121
|
+
Bumps the version number in `package.json` and optionally in other files.
|
|
122
|
+
* **Usage:** `jstool -cmd version [-major | -minor] [-pkgJsons "./package.json,../other/package.json"] [-extras "file.html"]`
|
|
123
|
+
* **Note:** Bumps the patch version by default. Use `-major` or `-minor` to bump those instead.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### `minify`
|
|
128
|
+
Minifies JavaScript files using Terser.
|
|
129
|
+
* **Usage:** `jstool -cmd minify -basePath <source_dir> [-test "<regex>"] [-suffix ".min"]`
|
|
130
|
+
* **Note:** `basePath` can be a comma-separated list. The default suffix is `.mini`.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### `rmc`
|
|
135
|
+
Removes C-style comments from files.
|
|
136
|
+
* **Usage:** `jstool -cmd rmc -basePath "./dist/cjs,./dist/other" -test "/\\.(js|d\\.ts)$/"`
|
|
137
|
+
* **Note:** Use the `-rmc4ts` flag for special handling of TypeScript comments (e.g., `/// <reference>`).
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### `stripWebpack` (deprecated)
|
|
142
|
+
Strips webpack-specific boilerplate from bundled files.
|
|
143
|
+
* **Usage:** `jstool -cmd stripWebpack -regex "%npm_package_defs_regex%"`
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## 📜 License
|
|
147
|
+
|
|
148
|
+
Released under the MIT License.
|
|
149
|
+
See [LICENSE](./LICENSE) for details.
|
|
150
|
+
|
package/basic-types.d.ts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2018 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @file basic-types/index.d.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// --------------------- define primative types.
|
|
13
|
+
/**
|
|
14
|
+
* #### To Be Defined
|
|
15
|
+
*
|
|
16
|
+
* + can be `undefined`.
|
|
17
|
+
* + 7 character shorten
|
|
18
|
+
*/
|
|
19
|
+
type TBD<T> = T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* #### To Be Completed
|
|
22
|
+
*
|
|
23
|
+
* + can be `null`.
|
|
24
|
+
* + 2 character shorten
|
|
25
|
+
*/
|
|
26
|
+
type TBC<T> = T | null;
|
|
27
|
+
|
|
28
|
+
// needed?
|
|
29
|
+
type DecideType<T> = T extends infer P? P : T;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* T is falsy then return A, trusy then B
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* type ConditionalX<T, A, B> = T extends (void | false | undefined) ? A : B // <- maybe not works
|
|
36
|
+
* type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
|
|
37
|
+
*
|
|
38
|
+
* function x<T extends true | void, R extends ConditionalX<T, string, string[]>>(need?: T): R {
|
|
39
|
+
* return (need? "": [""]) as R;
|
|
40
|
+
* }
|
|
41
|
+
* // string | string[]
|
|
42
|
+
* const xret = x();
|
|
43
|
+
* // string[]
|
|
44
|
+
* const xret2 = x(true);
|
|
45
|
+
*
|
|
46
|
+
* function ok<T extends true | void, R extends Conditional<T, string, string[]>>(need?: T): R {
|
|
47
|
+
* return (need? "": [""]) as R;
|
|
48
|
+
* }
|
|
49
|
+
* // string
|
|
50
|
+
* const okret = ok();
|
|
51
|
+
* // string[]
|
|
52
|
+
* const okret2 = ok(true);
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @date 20/03/31
|
|
56
|
+
*/
|
|
57
|
+
type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
|
|
58
|
+
// or
|
|
59
|
+
// /**
|
|
60
|
+
// * @deprecated often not working properly (maybe)
|
|
61
|
+
// */
|
|
62
|
+
// type Conditional<T, A, B> = undefined extends T ? B : false extends T ? B : A;
|
|
63
|
+
|
|
64
|
+
type BasicIterator<T> = Iterator<T, T, T>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove readonly
|
|
68
|
+
*/
|
|
69
|
+
type Writable<T> = {
|
|
70
|
+
-readonly [P in keyof T]: T[P];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// 2020/3/12 20:36:52
|
|
74
|
+
type JsonValueTypes = string | number | boolean | object | Array<number | string | boolean | object>;
|
|
75
|
+
|
|
76
|
+
// /**
|
|
77
|
+
// * get property type.
|
|
78
|
+
// */
|
|
79
|
+
// type TypeOf<T, K extends keyof T> = T[K];
|
|
80
|
+
// // -> same as like SkillPlanDataType["plans"]
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* pickup public fields and methods from `typescript` class.
|
|
84
|
+
*
|
|
85
|
+
* shorthand of:
|
|
86
|
+
* ```ts
|
|
87
|
+
* const someValue: Pick<T, keyof T>;
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* NOTE: cannot listed `protected` and `private` modifier
|
|
91
|
+
*
|
|
92
|
+
* @see Partial
|
|
93
|
+
* @see Required
|
|
94
|
+
* @see ReadOnly
|
|
95
|
+
*/
|
|
96
|
+
type InterfaceType<T> = {
|
|
97
|
+
[P in keyof T]: T[P];
|
|
98
|
+
};
|
|
99
|
+
// or
|
|
100
|
+
// type InterfaceType<T> = Pick<T, keyof T>;
|
|
101
|
+
|
|
102
|
+
type TStdFunction<R = any> = (...args: any[]) => R;
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* mark a specific property as `required`
|
|
107
|
+
*/
|
|
108
|
+
type RequireThese<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
109
|
+
/**
|
|
110
|
+
* pick any `property` as excludes
|
|
111
|
+
*/
|
|
112
|
+
type ExcludePick<T, K extends keyof T> = Exclude<Pick<T, K>, T>;
|
|
113
|
+
/**
|
|
114
|
+
* pick any `property` as required
|
|
115
|
+
*/
|
|
116
|
+
type RequiredPick<T, K extends keyof T> = Required<Pick<T, K>>;
|
|
117
|
+
/**
|
|
118
|
+
* pick any `property` as partial
|
|
119
|
+
*/
|
|
120
|
+
type PartialPick<T, K extends keyof T> = Partial<Pick<T, K>>;
|
|
121
|
+
|
|
122
|
+
// // The opposite of Pick. Return type without specified property
|
|
123
|
+
/**
|
|
124
|
+
* NOTE: can use ts builtin `Omit` instead
|
|
125
|
+
*/
|
|
126
|
+
type Flip<T, K extends keyof T> = {
|
|
127
|
+
[P in Exclude<keyof T, K>]: T[P];
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @date 2019/8/19
|
|
133
|
+
* @see Parameters
|
|
134
|
+
*/
|
|
135
|
+
type RequiredParameters<TFunction extends (...args: any) => any> = Required<
|
|
136
|
+
Parameters<TFunction>
|
|
137
|
+
>;
|
|
138
|
+
// /**
|
|
139
|
+
// * Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
|
|
140
|
+
// */
|
|
141
|
+
// type ThisParameterType<T> = T extends (this: unknown, ...args: any[]) => any ? unknown : T extends (this: infer U, ...args: any[]) => any ? U : unknown;
|
|
142
|
+
// /**
|
|
143
|
+
// * Removes the 'this' parameter from a function type.
|
|
144
|
+
// */
|
|
145
|
+
// type OmitThisParameter<T> = unknown extends ThisParameterType<T> ? T : T extends (...args: infer A) => infer R ? (...args: A) => R : T;
|
|
146
|
+
|
|
147
|
+
type PickProperties<P, T> = { [K in keyof T]-?: T[K] extends P ? K : never }[keyof T];
|
|
148
|
+
type PickNumberProperties<T> = PickProperties<number, T>;
|
|
149
|
+
type PickStringProperties<T> = PickProperties<string, T>;
|
|
150
|
+
|
|
151
|
+
type NonFunctionPropertyNames<T> = { [K in keyof T]-?: T[K] extends Function ? never : K }[keyof T];
|
|
152
|
+
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* extract () => number | string functoin names from T
|
|
156
|
+
*/
|
|
157
|
+
type NorSFunctions<T> = { [K in keyof T]: T[K] extends (() => number | string) ? K : never }[keyof T];
|
|
158
|
+
// type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
|
159
|
+
// type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
|
160
|
+
// type OKKK<T> = Exclude<FunctionProperties<T>, never>;
|
|
161
|
+
type Unpacked<T> =
|
|
162
|
+
T extends Array<infer U> ? U :
|
|
163
|
+
T extends (...args: any[]) => infer U ? U :
|
|
164
|
+
T extends Promise<infer U> ? U :
|
|
165
|
+
T;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* cannot apply to parameter required function. (?)
|
|
169
|
+
*/
|
|
170
|
+
type SimpleUnpack<T> = T extends (...args: any[]) => infer U ? U :
|
|
171
|
+
T extends Promise<infer U> ? U :
|
|
172
|
+
// T extends null ? null:
|
|
173
|
+
T;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* usage:
|
|
177
|
+
* ```
|
|
178
|
+
* async function some(): Promise<string> {
|
|
179
|
+
* return "OK";
|
|
180
|
+
* };
|
|
181
|
+
* type RT = UnpackReturnType<typeof some>;
|
|
182
|
+
*
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
type UnpackReturnType<T extends (...args: any[]) => any> = Unpacked<ReturnType<T>>;
|
|
186
|
+
// type XUnpackReturnType<T> = T extends (...args: any[]) => any? Unpacked<ReturnType<T>>: T;
|
|
187
|
+
|
|
188
|
+
// // ERROR: TS2345
|
|
189
|
+
// type AvoidTS2345<T, K extends keyof T> = T[K];
|
|
190
|
+
// // OK, but... . . . .
|
|
191
|
+
// type AvoidTS2345<T, K extends keyof T> = K extends infer X? T[K]: any;
|
|
192
|
+
|
|
193
|
+
// 1/30/2019, 4:14:25 PM
|
|
194
|
+
/**
|
|
195
|
+
* http query parameter types. (maybe not enough.
|
|
196
|
+
*/
|
|
197
|
+
type QueryValueTypes = string | number | boolean | Date;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* means can convert to Date object.
|
|
201
|
+
*/
|
|
202
|
+
type DateString = string;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* document.querySelector etc
|
|
206
|
+
*/
|
|
207
|
+
type TQuerySelector = string;
|
|
208
|
+
|
|
209
|
+
// --------------------- define unique types.
|
|
210
|
+
type NumberMap<T> = {
|
|
211
|
+
[index: number]: T;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
type UndefableStringMap<T> = TBD<Record<string, T>>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* for lazy assign class.
|
|
218
|
+
*/
|
|
219
|
+
type TypedCtor<T> = {
|
|
220
|
+
new (...args: any[]): T;
|
|
221
|
+
prototype: T;
|
|
222
|
+
};
|
|
223
|
+
// DEVNOTE: 2022/02/15 its a same declare, so marged
|
|
224
|
+
interface ITypedCtor<T> extends TypedCtor<T> {}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Array.sort etc...
|
|
228
|
+
*/
|
|
229
|
+
declare type TComparator<T> = (a: T, b: T) => number;
|
|
230
|
+
|
|
231
|
+
declare const enum ETypeOf {
|
|
232
|
+
VBigInt = "bigint",
|
|
233
|
+
VBool = "boolean",
|
|
234
|
+
VFn = "function",
|
|
235
|
+
VNum = "number",
|
|
236
|
+
VO = "object",
|
|
237
|
+
VS = "string",
|
|
238
|
+
VSym = "symbol",
|
|
239
|
+
VUndef = "undefined"
|
|
240
|
+
}
|
|
241
|
+
declare namespace ETypeOf {
|
|
242
|
+
export type Values = "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined";
|
|
243
|
+
export type Bi = bigint;
|
|
244
|
+
export type B = boolean;
|
|
245
|
+
export type F = Function;
|
|
246
|
+
export type N = number;
|
|
247
|
+
export type O = object;
|
|
248
|
+
export type S = string;
|
|
249
|
+
export type Sym = symbol;
|
|
250
|
+
export type U = undefined;
|
|
251
|
+
}
|
|
252
|
+
// /**
|
|
253
|
+
// * @param {ETypeOf.S} v
|
|
254
|
+
// */
|
|
255
|
+
// function isOK(v: ETypeOf.S): v is ETypeOf.S
|
|
256
|
+
// let x: bigint;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Generates all combinations of the string S. The order of characters does not matter.
|
|
260
|
+
* @template S - The target string type
|
|
261
|
+
* @template Pre - The prefix string (used internally)
|
|
262
|
+
*/
|
|
263
|
+
type Combination<
|
|
264
|
+
S extends string, Pre extends string = "",
|
|
265
|
+
> = S extends `${infer First}${infer Post}` ?
|
|
266
|
+
`${First}${Combination<`${Pre}${Post}`>}` | Combination<Post, `${Pre}${First}`> : "";
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Generates all fixed combinations of the string S. The order of characters is preserved.
|
|
270
|
+
* @template S - The target string type
|
|
271
|
+
* @template Pre - The prefix string (used internally)
|
|
272
|
+
*/
|
|
273
|
+
// DEVNOTE: 2025/01/27 - これは文字の順序が限定される
|
|
274
|
+
type FixedCombination<
|
|
275
|
+
S extends string,
|
|
276
|
+
Pre extends string = ""
|
|
277
|
+
> = S extends `${infer First}${infer Post}` ?
|
|
278
|
+
`${Pre}${First}${FixedCombination<Post, "">}` | FixedCombination<Post, `${Pre}${First}`> : "";
|
|
279
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2022 jeffy-g hirotom1107@gmail.com
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} dest
|
|
26
|
+
*/
|
|
27
|
+
export function checkParentDirectory(dest: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} logPath
|
|
30
|
+
*/
|
|
31
|
+
export function createLogStreamAndResolvePath(logPath: string): any;
|
|
32
|
+
/**
|
|
33
|
+
* use process.stderr stream
|
|
34
|
+
*
|
|
35
|
+
* @param {string} [msg] if empty string or undefined then only clear line and move cursor to head.
|
|
36
|
+
*/
|
|
37
|
+
export function renderLine(msg?: string): void;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {boolean} enabled
|
|
41
|
+
* @param {NodeJS.WriteStream} [output]
|
|
42
|
+
*/
|
|
43
|
+
export function cursor(enabled: boolean, output?: NodeJS.WriteStream): void;
|
package/common/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2022 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @file js-dev-scripts/common/index.js
|
|
10
|
+
*/
|
|
11
|
+
// @ts-check
|
|
12
|
+
|
|
13
|
+
// NOTE: fs-extra are bit slower.
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
// const util = require('util');
|
|
16
|
+
const path = require("path");
|
|
17
|
+
// for clearLine...
|
|
18
|
+
const rl = require("readline");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} dest
|
|
22
|
+
*/
|
|
23
|
+
function checkParentDirectory(dest) {
|
|
24
|
+
const parent = path.dirname(dest);
|
|
25
|
+
if (!fs.existsSync(parent)) {
|
|
26
|
+
// DEVNOTE: fix Error: ENOENT: no such file or directory, mkdir ./path/to/dir
|
|
27
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} logPath
|
|
32
|
+
*/
|
|
33
|
+
function createLogStreamAndResolvePath(logPath) {
|
|
34
|
+
checkParentDirectory(logPath);
|
|
35
|
+
return fs.createWriteStream(logPath);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* use process.stderr stream
|
|
40
|
+
*
|
|
41
|
+
* @param {string} [msg] if empty string or undefined then only clear line and move cursor to head.
|
|
42
|
+
*/
|
|
43
|
+
// CHANGES: 2020/2/18 18:28:17 - fix ちらつき
|
|
44
|
+
// dir <number>
|
|
45
|
+
// -1: to the left from cursor
|
|
46
|
+
// 1: to the right from cursor
|
|
47
|
+
// 0: the entire line
|
|
48
|
+
//
|
|
49
|
+
// function renderLine(msg) {
|
|
50
|
+
// const output = process.stderr;
|
|
51
|
+
// // move cursor to line head
|
|
52
|
+
// // @ts-ignore
|
|
53
|
+
// rl.cursorTo(output, 0);
|
|
54
|
+
// // write the message.
|
|
55
|
+
// msg && output.write(msg);
|
|
56
|
+
// // clear line to the right from cursor
|
|
57
|
+
// // @ts-ignore
|
|
58
|
+
// rl.clearLine(output, 0);
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// FIX: 2025/5/13 output.clearLine is not a function
|
|
62
|
+
function renderLine(msg /*, del = "\x1B[?25l"*/) {
|
|
63
|
+
const output = process.stderr || process.stdout;
|
|
64
|
+
// output.write(del); // clear cursol
|
|
65
|
+
// clear line to the right from cursor
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
rl.clearLine(output, 0);
|
|
68
|
+
// output.clearLine(0);
|
|
69
|
+
|
|
70
|
+
// move cursor to line head
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
rl.cursorTo(output, 0);
|
|
73
|
+
// output.cursorTo(0);
|
|
74
|
+
|
|
75
|
+
msg && output.write(msg);
|
|
76
|
+
// // write the message.
|
|
77
|
+
// // msg && output.write(msg);
|
|
78
|
+
// output.write(`${spin_char[spin_count]} ${msg}`);
|
|
79
|
+
// spin_count++;
|
|
80
|
+
// spin_count >= spin_char.length && (spin_count = 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {boolean} enabled
|
|
86
|
+
* @param {NodeJS.WriteStream} [output]
|
|
87
|
+
*/
|
|
88
|
+
const cursor = (enabled, output = process.stderr) => {
|
|
89
|
+
if (enabled) {
|
|
90
|
+
output.write("\x1B[?25h");
|
|
91
|
+
} else {
|
|
92
|
+
output.write("\x1B[?25l");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
checkParentDirectory,
|
|
98
|
+
createLogStreamAndResolvePath,
|
|
99
|
+
renderLine,
|
|
100
|
+
cursor,
|
|
101
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import * as progress from "../progress/";
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} [fps]
|
|
11
|
+
* @param {() => string} [messageEmiter]
|
|
12
|
+
*/
|
|
13
|
+
export function create(fps?: number, messageEmiter?: () => string): ReturnType<typeof progress.createProgressObject>;
|
|
14
|
+
export type Progress = ReturnType<typeof progress.createProgressObject>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
Copyright (C) 2022 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
Released under the MIT license
|
|
5
|
+
https://opensource.org/licenses/mit-license.php
|
|
6
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/** [usage]
|
|
9
|
+
> node -i
|
|
10
|
+
let t = require("./extras/progress-sample");
|
|
11
|
+
let p = t.create();
|
|
12
|
+
p.run();
|
|
13
|
+
p.stop();
|
|
14
|
+
p = t.create();
|
|
15
|
+
p.run();
|
|
16
|
+
p.stop();
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const p = require("../progress/");
|
|
20
|
+
const rndSpinners = require("../progress/rnd-spinner");
|
|
21
|
+
|
|
22
|
+
let fired = 0;
|
|
23
|
+
let pending = 0;
|
|
24
|
+
|
|
25
|
+
/** @type {() => { fired: number; pending: number; errors?: number; }} */
|
|
26
|
+
const cb = () => {
|
|
27
|
+
return {
|
|
28
|
+
fired: ++fired,
|
|
29
|
+
pending: ++pending,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let tag = "progress test";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* progress callback
|
|
37
|
+
* @type {() => string}
|
|
38
|
+
*/
|
|
39
|
+
const pcb = () => {
|
|
40
|
+
if (cb) {
|
|
41
|
+
const { fired, pending, errors } = cb();
|
|
42
|
+
return `${tag} | error: ${(errors + "").padEnd(3)} | send: ${(fired + "").padStart(3)}, pending: ${(pending + "").padEnd(5)}`;
|
|
43
|
+
} else {
|
|
44
|
+
// error
|
|
45
|
+
return "- - error - -";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** @type {ReturnType<typeof p.createProgressObject>} */
|
|
50
|
+
let progress;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {number} [fps]
|
|
54
|
+
* @param {() => string} [messageEmiter]
|
|
55
|
+
*/
|
|
56
|
+
const create = (fps = 30, messageEmiter) => {
|
|
57
|
+
const spinner = rndSpinners.getRandomFrame();
|
|
58
|
+
// const pong = rndSpinners.pong;
|
|
59
|
+
!messageEmiter && (messageEmiter = pcb);
|
|
60
|
+
progress = p.createProgressObject(
|
|
61
|
+
spinner.frames,
|
|
62
|
+
{
|
|
63
|
+
fmt: "{tick} - {frameName} - {msg}",
|
|
64
|
+
payload: { frameName: spinner.name },
|
|
65
|
+
},
|
|
66
|
+
messageEmiter,
|
|
67
|
+
);
|
|
68
|
+
progress.setFPS(fps);
|
|
69
|
+
return progress;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
create,
|
|
74
|
+
};
|