@e-mc/module 0.8.11 → 0.8.13
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 +6 -6
- package/README.md +241 -241
- package/index.d.ts +4 -4
- package/index.js +81 -56
- package/lib-v4.d.ts +4 -4
- package/package.json +33 -33
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
# @e-mc/module
|
|
2
|
-
|
|
3
|
-
* NodeJS 14
|
|
4
|
-
* ES2019
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { LogStatus } from "./squared";
|
|
16
|
-
|
|
17
|
-
import type { IHost } from "./index";
|
|
18
|
-
import type { IAbortComponent, IPermission } from "./core";
|
|
19
|
-
import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, StatusType } from "./logger";
|
|
20
|
-
import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
|
|
21
|
-
import type { Settings } from "./node";
|
|
22
|
-
|
|
23
|
-
import type { SpawnOptions } from "child_process";
|
|
24
|
-
import type { BinaryLike } from "crypto";
|
|
25
|
-
import type { FileTypeResult } from "file-type";
|
|
26
|
-
import type { NoParamCallback } from "fs";
|
|
27
|
-
|
|
28
|
-
import type * as EventEmitter from "events";
|
|
29
|
-
|
|
30
|
-
type BufferView = Buffer | string | NodeJS.ArrayBufferView;
|
|
31
|
-
type CpuUsage = NodeJS.CpuUsage;
|
|
32
|
-
|
|
33
|
-
interface IModule extends EventEmitter, IAbortComponent {
|
|
34
|
-
readonly status: LogStatus<StatusType>[];
|
|
35
|
-
readonly errors: unknown[];
|
|
36
|
-
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
37
|
-
supports(name: string, value?: boolean): boolean;
|
|
38
|
-
getTempDir(options: GetTempDirOptions): string;
|
|
39
|
-
getTempDir(uuidDir: boolean, createDir?: boolean): string;
|
|
40
|
-
getTempDir(pathname: string, createDir?: boolean): string;
|
|
41
|
-
getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
|
|
42
|
-
getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
|
|
43
|
-
canRead(uri: string, options?: PermissionOptions): boolean;
|
|
44
|
-
canWrite(uri: string, options?: PermissionOptions): boolean;
|
|
45
|
-
readFile(src: string): Buffer | undefined;
|
|
46
|
-
readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
|
|
47
|
-
readFile(src: string, promises: true): Promise<Buffer | undefined>;
|
|
48
|
-
readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
|
|
49
|
-
readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
|
|
50
|
-
readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
|
|
51
|
-
writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
|
|
52
|
-
writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
|
|
53
|
-
writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
|
|
54
|
-
writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
|
|
55
|
-
writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
56
|
-
deleteFile(src: string, options?: DeleteFileOptions): boolean;
|
|
57
|
-
deleteFile(src: string, promises: true): Promise<boolean>;
|
|
58
|
-
deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
|
|
59
|
-
deleteFile(src: string, callback: NoParamCallback): void;
|
|
60
|
-
deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
|
|
61
|
-
copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
|
|
62
|
-
copyFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
63
|
-
copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
|
|
64
|
-
copyFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
65
|
-
copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
|
|
66
|
-
moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
|
|
67
|
-
moveFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
68
|
-
moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
|
|
69
|
-
moveFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
70
|
-
moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
|
|
71
|
-
createDir(src: string, options?: CreateDirOptions): boolean;
|
|
72
|
-
createDir(src: string, promises: true): Promise<boolean>;
|
|
73
|
-
createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
|
|
74
|
-
createDir(src: string, callback: NoParamCallback): void;
|
|
75
|
-
createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
|
|
76
|
-
removeDir(src: string, options?: RemoveDirOptions): boolean;
|
|
77
|
-
removeDir(src: string, promises: true): Promise<boolean>;
|
|
78
|
-
removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
|
|
79
|
-
removeDir(src: string, callback: NoParamCallback): void;
|
|
80
|
-
removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
|
|
81
|
-
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
|
|
82
|
-
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
83
|
-
formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
|
|
84
|
-
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
85
|
-
writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
|
|
86
|
-
writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
|
|
87
|
-
checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
|
|
88
|
-
checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
|
|
89
|
-
checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
|
|
90
|
-
writeLog(component: LogComponent, queue?: boolean): void;
|
|
91
|
-
writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
92
|
-
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
|
|
93
|
-
addLog(component: LogComponent, queue?: boolean): void;
|
|
94
|
-
addLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
95
|
-
addLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
96
|
-
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
|
|
97
|
-
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
|
|
98
|
-
getLog(...type: StatusType[]): LogStatus<StatusType>[];
|
|
99
|
-
flushLog(): void;
|
|
100
|
-
willAbort(value: unknown): boolean;
|
|
101
|
-
hasOwnPermission(): boolean;
|
|
102
|
-
isFatal(err?: unknown): boolean;
|
|
103
|
-
detach(): void;
|
|
104
|
-
reset(): void;
|
|
105
|
-
get moduleName(): string;
|
|
106
|
-
set host(value);
|
|
107
|
-
get host(): IHost | null;
|
|
108
|
-
set permission(value);
|
|
109
|
-
get permission(): IPermission | null;
|
|
110
|
-
get aborted(): boolean;
|
|
111
|
-
set abortable(value);
|
|
112
|
-
get abortable(): boolean;
|
|
113
|
-
get threadable(): boolean;
|
|
114
|
-
set sessionId(value);
|
|
115
|
-
get sessionId(): string;
|
|
116
|
-
set broadcastId(value);
|
|
117
|
-
get broadcastId(): string | string[];
|
|
118
|
-
get logType(): LOG_TYPE;
|
|
119
|
-
set logLevel(value: number | string);
|
|
120
|
-
get logLevel(): number;
|
|
121
|
-
get statusType(): STATUS_TYPE;
|
|
122
|
-
set tempDir(value);
|
|
123
|
-
get tempDir(): string;
|
|
124
|
-
|
|
125
|
-
/* EventEmitter */
|
|
126
|
-
on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
127
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
128
|
-
on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
129
|
-
on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
130
|
-
on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
131
|
-
on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
132
|
-
on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
133
|
-
on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
134
|
-
on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
135
|
-
once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
136
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
137
|
-
once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
138
|
-
once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
139
|
-
once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
140
|
-
once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
141
|
-
once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
142
|
-
once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
143
|
-
once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
144
|
-
emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
|
|
145
|
-
emit(event: "error", err: Error): boolean;
|
|
146
|
-
emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
|
|
147
|
-
emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
|
|
148
|
-
emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
|
|
149
|
-
emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
|
|
150
|
-
emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
|
|
151
|
-
emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
|
|
152
|
-
emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
interface ModuleConstructor {
|
|
156
|
-
PROCESS_TIMEOUT: number;
|
|
157
|
-
LOG_STYLE_FAIL: LogMessageOptions;
|
|
158
|
-
LOG_STYLE_SUCCESS: LogMessageOptions;
|
|
159
|
-
LOG_STYLE_INFO: LogMessageOptions;
|
|
160
|
-
LOG_STYLE_WARN: LogMessageOptions;
|
|
161
|
-
LOG_STYLE_NOTICE: LogMessageOptions;
|
|
162
|
-
LOG_STYLE_REVERSE: LogMessageOptions;
|
|
163
|
-
readonly VERSION: string;
|
|
164
|
-
readonly LOG_TYPE: LOG_TYPE;
|
|
165
|
-
readonly STATUS_TYPE: STATUS_TYPE;
|
|
166
|
-
readonly MAX_TIMEOUT: number;
|
|
167
|
-
readonly TEMP_DIR: string;
|
|
168
|
-
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
169
|
-
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
170
|
-
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
171
|
-
enabled(key: string, username?: string): boolean;
|
|
172
|
-
parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
173
|
-
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
174
|
-
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
175
|
-
asHash(data: BinaryLike, options: AsHashOptions): string;
|
|
176
|
-
asHash(data: BinaryLike, minLength: number): string;
|
|
177
|
-
asHash(data: BinaryLike, algorithm?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
|
|
178
|
-
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
179
|
-
toPosix(value: unknown, normalize: boolean): string;
|
|
180
|
-
toPosix(value: unknown, filename?: string, normalize?: boolean): string;
|
|
181
|
-
hasLogType(value: LogType): boolean;
|
|
182
|
-
isURL(value: string, ...exclude: string[]): boolean;
|
|
183
|
-
isFile(value: string | URL, type?: ProtocolType): boolean;
|
|
184
|
-
isDir(value: string | URL): boolean;
|
|
185
|
-
isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
|
|
186
|
-
isPath(value: string | URL, isFile?: boolean): boolean;
|
|
187
|
-
isErrorCode(err: unknown, ...code: string[]): boolean;
|
|
188
|
-
fromLocalPath(value: string): string;
|
|
189
|
-
resolveFile(value: string): string;
|
|
190
|
-
resolvePath(value: string, base: string | URL): string;
|
|
191
|
-
joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
|
|
192
|
-
joinPath(...values: unknown[]): string;
|
|
193
|
-
normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
|
|
194
|
-
createDir(value: string | URL, overwrite?: boolean): boolean;
|
|
195
|
-
removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
|
|
196
|
-
removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
|
|
197
|
-
copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
|
|
198
|
-
copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
|
|
199
|
-
renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
|
|
200
|
-
streamFile(src: string, cache: boolean): Promise<Buffer | string>;
|
|
201
|
-
streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
|
|
202
|
-
streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
|
|
203
|
-
readText(value: string | URL, cache: boolean): string;
|
|
204
|
-
readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
|
|
205
|
-
readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
|
|
206
|
-
readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
|
|
207
|
-
readBuffer(value: string | URL, cache?: boolean): Buffer | null;
|
|
208
|
-
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
209
|
-
lookupMime(value: string, extension?: boolean): string;
|
|
210
|
-
initCpuUsage(instance?: IModule): CpuUsage;
|
|
211
|
-
getCpuUsage(start: CpuUsage, format: true): string;
|
|
212
|
-
getCpuUsage(start: CpuUsage, format?: boolean): number;
|
|
213
|
-
getMemUsage(format: true): string;
|
|
214
|
-
getMemUsage(format?: boolean): number;
|
|
215
|
-
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
216
|
-
getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
|
|
217
|
-
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
|
|
218
|
-
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
219
|
-
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
|
|
220
|
-
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
221
|
-
sanitizeCmd(value: string): string;
|
|
222
|
-
sanitizeArgs(value: string, doubleQuote?: boolean): string;
|
|
223
|
-
sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
|
|
224
|
-
purgeMemory(percent: number, parent: boolean | number): Promise<number>;
|
|
225
|
-
purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
|
|
226
|
-
canWrite(name: "temp" | "home"): boolean;
|
|
227
|
-
loadSettings(settings: Settings, password?: string): boolean;
|
|
228
|
-
readonly prototype: IModule<IHost>;
|
|
229
|
-
new(): IModule<IHost>;
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## References
|
|
234
|
-
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
239
|
-
|
|
240
|
-
## LICENSE
|
|
241
|
-
|
|
1
|
+
# @e-mc/module
|
|
2
|
+
|
|
3
|
+
* NodeJS 14
|
|
4
|
+
* ES2019
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/index.d.ts
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { LogStatus } from "./squared";
|
|
16
|
+
|
|
17
|
+
import type { IHost } from "./index";
|
|
18
|
+
import type { IAbortComponent, IPermission } from "./core";
|
|
19
|
+
import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, StatusType } from "./logger";
|
|
20
|
+
import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
|
|
21
|
+
import type { Settings } from "./node";
|
|
22
|
+
|
|
23
|
+
import type { SpawnOptions } from "child_process";
|
|
24
|
+
import type { BinaryLike } from "crypto";
|
|
25
|
+
import type { FileTypeResult } from "file-type";
|
|
26
|
+
import type { NoParamCallback } from "fs";
|
|
27
|
+
|
|
28
|
+
import type * as EventEmitter from "events";
|
|
29
|
+
|
|
30
|
+
type BufferView = Buffer | string | NodeJS.ArrayBufferView;
|
|
31
|
+
type CpuUsage = NodeJS.CpuUsage;
|
|
32
|
+
|
|
33
|
+
interface IModule extends EventEmitter, IAbortComponent {
|
|
34
|
+
readonly status: LogStatus<StatusType>[];
|
|
35
|
+
readonly errors: unknown[];
|
|
36
|
+
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
37
|
+
supports(name: string, value?: boolean): boolean;
|
|
38
|
+
getTempDir(options: GetTempDirOptions): string;
|
|
39
|
+
getTempDir(uuidDir: boolean, createDir?: boolean): string;
|
|
40
|
+
getTempDir(pathname: string, createDir?: boolean): string;
|
|
41
|
+
getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
|
|
42
|
+
getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
|
|
43
|
+
canRead(uri: string, options?: PermissionOptions): boolean;
|
|
44
|
+
canWrite(uri: string, options?: PermissionOptions): boolean;
|
|
45
|
+
readFile(src: string): Buffer | undefined;
|
|
46
|
+
readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
|
|
47
|
+
readFile(src: string, promises: true): Promise<Buffer | undefined>;
|
|
48
|
+
readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
|
|
49
|
+
readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
|
|
50
|
+
readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
|
|
51
|
+
writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
|
|
52
|
+
writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
|
|
53
|
+
writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
|
|
54
|
+
writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
|
|
55
|
+
writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
56
|
+
deleteFile(src: string, options?: DeleteFileOptions): boolean;
|
|
57
|
+
deleteFile(src: string, promises: true): Promise<boolean>;
|
|
58
|
+
deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
|
|
59
|
+
deleteFile(src: string, callback: NoParamCallback): void;
|
|
60
|
+
deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
|
|
61
|
+
copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
|
|
62
|
+
copyFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
63
|
+
copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
|
|
64
|
+
copyFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
65
|
+
copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
|
|
66
|
+
moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
|
|
67
|
+
moveFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
68
|
+
moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
|
|
69
|
+
moveFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
70
|
+
moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
|
|
71
|
+
createDir(src: string, options?: CreateDirOptions): boolean;
|
|
72
|
+
createDir(src: string, promises: true): Promise<boolean>;
|
|
73
|
+
createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
|
|
74
|
+
createDir(src: string, callback: NoParamCallback): void;
|
|
75
|
+
createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
|
|
76
|
+
removeDir(src: string, options?: RemoveDirOptions): boolean;
|
|
77
|
+
removeDir(src: string, promises: true): Promise<boolean>;
|
|
78
|
+
removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
|
|
79
|
+
removeDir(src: string, callback: NoParamCallback): void;
|
|
80
|
+
removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
|
|
81
|
+
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
|
|
82
|
+
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
83
|
+
formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
|
|
84
|
+
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
85
|
+
writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
|
|
86
|
+
writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
|
|
87
|
+
checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
|
|
88
|
+
checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
|
|
89
|
+
checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
|
|
90
|
+
writeLog(component: LogComponent, queue?: boolean): void;
|
|
91
|
+
writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
92
|
+
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
|
|
93
|
+
addLog(component: LogComponent, queue?: boolean): void;
|
|
94
|
+
addLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
95
|
+
addLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
96
|
+
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
|
|
97
|
+
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
|
|
98
|
+
getLog(...type: StatusType[]): LogStatus<StatusType>[];
|
|
99
|
+
flushLog(): void;
|
|
100
|
+
willAbort(value: unknown): boolean;
|
|
101
|
+
hasOwnPermission(): boolean;
|
|
102
|
+
isFatal(err?: unknown): boolean;
|
|
103
|
+
detach(): void;
|
|
104
|
+
reset(): void;
|
|
105
|
+
get moduleName(): string;
|
|
106
|
+
set host(value);
|
|
107
|
+
get host(): IHost | null;
|
|
108
|
+
set permission(value);
|
|
109
|
+
get permission(): IPermission | null;
|
|
110
|
+
get aborted(): boolean;
|
|
111
|
+
set abortable(value);
|
|
112
|
+
get abortable(): boolean;
|
|
113
|
+
get threadable(): boolean;
|
|
114
|
+
set sessionId(value);
|
|
115
|
+
get sessionId(): string;
|
|
116
|
+
set broadcastId(value);
|
|
117
|
+
get broadcastId(): string | string[];
|
|
118
|
+
get logType(): LOG_TYPE;
|
|
119
|
+
set logLevel(value: number | string);
|
|
120
|
+
get logLevel(): number;
|
|
121
|
+
get statusType(): STATUS_TYPE;
|
|
122
|
+
set tempDir(value);
|
|
123
|
+
get tempDir(): string;
|
|
124
|
+
|
|
125
|
+
/* EventEmitter */
|
|
126
|
+
on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
127
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
128
|
+
on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
129
|
+
on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
130
|
+
on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
131
|
+
on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
132
|
+
on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
133
|
+
on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
134
|
+
on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
135
|
+
once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
136
|
+
once(event: "error", listener: (err: Error) => void): this;
|
|
137
|
+
once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
138
|
+
once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
139
|
+
once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
140
|
+
once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
141
|
+
once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
142
|
+
once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
143
|
+
once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
144
|
+
emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
|
|
145
|
+
emit(event: "error", err: Error): boolean;
|
|
146
|
+
emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
|
|
147
|
+
emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
|
|
148
|
+
emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
|
|
149
|
+
emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
|
|
150
|
+
emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
|
|
151
|
+
emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
|
|
152
|
+
emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface ModuleConstructor {
|
|
156
|
+
PROCESS_TIMEOUT: number;
|
|
157
|
+
LOG_STYLE_FAIL: LogMessageOptions;
|
|
158
|
+
LOG_STYLE_SUCCESS: LogMessageOptions;
|
|
159
|
+
LOG_STYLE_INFO: LogMessageOptions;
|
|
160
|
+
LOG_STYLE_WARN: LogMessageOptions;
|
|
161
|
+
LOG_STYLE_NOTICE: LogMessageOptions;
|
|
162
|
+
LOG_STYLE_REVERSE: LogMessageOptions;
|
|
163
|
+
readonly VERSION: string;
|
|
164
|
+
readonly LOG_TYPE: LOG_TYPE;
|
|
165
|
+
readonly STATUS_TYPE: STATUS_TYPE;
|
|
166
|
+
readonly MAX_TIMEOUT: number;
|
|
167
|
+
readonly TEMP_DIR: string;
|
|
168
|
+
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
169
|
+
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
170
|
+
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
171
|
+
enabled(key: string, username?: string): boolean;
|
|
172
|
+
parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
173
|
+
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
174
|
+
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
175
|
+
asHash(data: BinaryLike, options: AsHashOptions): string;
|
|
176
|
+
asHash(data: BinaryLike, minLength: number): string;
|
|
177
|
+
asHash(data: BinaryLike, algorithm?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
|
|
178
|
+
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
179
|
+
toPosix(value: unknown, normalize: boolean): string;
|
|
180
|
+
toPosix(value: unknown, filename?: string, normalize?: boolean): string;
|
|
181
|
+
hasLogType(value: LogType): boolean;
|
|
182
|
+
isURL(value: string, ...exclude: string[]): boolean;
|
|
183
|
+
isFile(value: string | URL, type?: ProtocolType): boolean;
|
|
184
|
+
isDir(value: string | URL): boolean;
|
|
185
|
+
isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
|
|
186
|
+
isPath(value: string | URL, isFile?: boolean): boolean;
|
|
187
|
+
isErrorCode(err: unknown, ...code: string[]): boolean;
|
|
188
|
+
fromLocalPath(value: string): string;
|
|
189
|
+
resolveFile(value: string): string;
|
|
190
|
+
resolvePath(value: string, base: string | URL): string;
|
|
191
|
+
joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
|
|
192
|
+
joinPath(...values: unknown[]): string;
|
|
193
|
+
normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
|
|
194
|
+
createDir(value: string | URL, overwrite?: boolean): boolean;
|
|
195
|
+
removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
|
|
196
|
+
removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
|
|
197
|
+
copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
|
|
198
|
+
copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
|
|
199
|
+
renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
|
|
200
|
+
streamFile(src: string, cache: boolean): Promise<Buffer | string>;
|
|
201
|
+
streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
|
|
202
|
+
streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
|
|
203
|
+
readText(value: string | URL, cache: boolean): string;
|
|
204
|
+
readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
|
|
205
|
+
readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
|
|
206
|
+
readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
|
|
207
|
+
readBuffer(value: string | URL, cache?: boolean): Buffer | null;
|
|
208
|
+
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
209
|
+
lookupMime(value: string, extension?: boolean): string;
|
|
210
|
+
initCpuUsage(instance?: IModule): CpuUsage;
|
|
211
|
+
getCpuUsage(start: CpuUsage, format: true): string;
|
|
212
|
+
getCpuUsage(start: CpuUsage, format?: boolean): number;
|
|
213
|
+
getMemUsage(format: true): string;
|
|
214
|
+
getMemUsage(format?: boolean): number;
|
|
215
|
+
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
216
|
+
getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
|
|
217
|
+
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
|
|
218
|
+
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
219
|
+
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
|
|
220
|
+
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
221
|
+
sanitizeCmd(value: string): string;
|
|
222
|
+
sanitizeArgs(value: string, doubleQuote?: boolean): string;
|
|
223
|
+
sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
|
|
224
|
+
purgeMemory(percent: number, parent: boolean | number): Promise<number>;
|
|
225
|
+
purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
|
|
226
|
+
canWrite(name: "temp" | "home"): boolean;
|
|
227
|
+
loadSettings(settings: Settings, password?: string): boolean;
|
|
228
|
+
readonly prototype: IModule<IHost>;
|
|
229
|
+
new(): IModule<IHost>;
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## References
|
|
234
|
+
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/core.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/logger.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/module.d.ts
|
|
238
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/node.d.ts
|
|
239
|
+
|
|
240
|
+
## LICENSE
|
|
241
|
+
|
|
242
242
|
MIT
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Module: ModuleConstructor;
|
|
4
|
-
|
|
1
|
+
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Module: ModuleConstructor;
|
|
4
|
+
|
|
5
5
|
export = Module;
|
package/index.js
CHANGED
|
@@ -129,6 +129,25 @@ const MEMORY_CACHE_DISK = {
|
|
|
129
129
|
exclude: null
|
|
130
130
|
};
|
|
131
131
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
132
|
+
const RESERVED_SHELL = [
|
|
133
|
+
'if',
|
|
134
|
+
'then',
|
|
135
|
+
'elif',
|
|
136
|
+
'else',
|
|
137
|
+
'fi',
|
|
138
|
+
'time',
|
|
139
|
+
'for',
|
|
140
|
+
'in',
|
|
141
|
+
'until',
|
|
142
|
+
'while',
|
|
143
|
+
'do',
|
|
144
|
+
'done',
|
|
145
|
+
'case',
|
|
146
|
+
'esac',
|
|
147
|
+
'coproc',
|
|
148
|
+
'select',
|
|
149
|
+
'function'
|
|
150
|
+
];
|
|
132
151
|
let LOG_NEWLINE = true;
|
|
133
152
|
let LOG_EMPTYLINE = false;
|
|
134
153
|
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
@@ -220,7 +239,7 @@ function applyStyle(options, style) {
|
|
|
220
239
|
}
|
|
221
240
|
function checkColorOptions(type, settings, options) {
|
|
222
241
|
var _h, _j, _k, _l;
|
|
223
|
-
if (
|
|
242
|
+
if (!(0, types_1.isObject)(settings)) {
|
|
224
243
|
return false;
|
|
225
244
|
}
|
|
226
245
|
let result = false;
|
|
@@ -642,14 +661,15 @@ function withinDir(value, base) {
|
|
|
642
661
|
value = path.normalize(value);
|
|
643
662
|
return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
|
|
644
663
|
}
|
|
645
|
-
function formatPercent(value, precision
|
|
664
|
+
function formatPercent(value, precision) {
|
|
646
665
|
if (value <= 0) {
|
|
647
666
|
return '0%';
|
|
648
667
|
}
|
|
649
|
-
if (value ===
|
|
668
|
+
if (value === (value | 0)) {
|
|
650
669
|
return value + '00%';
|
|
651
670
|
}
|
|
652
|
-
|
|
671
|
+
value *= 100;
|
|
672
|
+
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
653
673
|
}
|
|
654
674
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
655
675
|
const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
@@ -687,7 +707,7 @@ class Module extends EventEmitter {
|
|
|
687
707
|
this[_f] = new AbortController();
|
|
688
708
|
this[_g] = null;
|
|
689
709
|
}
|
|
690
|
-
static get VERSION() { return "0.8.
|
|
710
|
+
static get VERSION() { return "0.8.13"; }
|
|
691
711
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
692
712
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
693
713
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -981,10 +1001,14 @@ class Module extends EventEmitter {
|
|
|
981
1001
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
982
1002
|
hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
|
|
983
1003
|
}
|
|
984
|
-
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
985
|
-
}
|
|
986
|
-
else if (title) {
|
|
987
1004
|
value = getValue();
|
|
1005
|
+
hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
|
|
1006
|
+
}
|
|
1007
|
+
else {
|
|
1008
|
+
if (title) {
|
|
1009
|
+
value = getValue();
|
|
1010
|
+
}
|
|
1011
|
+
hint = '';
|
|
988
1012
|
}
|
|
989
1013
|
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
990
1014
|
const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
@@ -1029,19 +1053,19 @@ class Module extends EventEmitter {
|
|
|
1029
1053
|
}
|
|
1030
1054
|
}
|
|
1031
1055
|
else {
|
|
1032
|
-
if (!i) {
|
|
1056
|
+
if (!i && !hint) {
|
|
1033
1057
|
v = v.trim();
|
|
1034
1058
|
}
|
|
1035
1059
|
m = '';
|
|
1036
1060
|
}
|
|
1037
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
|
|
1061
|
+
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i ? i : ' ') + m;
|
|
1038
1062
|
}
|
|
1039
1063
|
catch {
|
|
1040
1064
|
}
|
|
1041
1065
|
}
|
|
1042
1066
|
if (!output) {
|
|
1043
|
-
const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
1044
|
-
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1067
|
+
const m = truncateStart(stripansi(this.asString(message)), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
1068
|
+
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1045
1069
|
}
|
|
1046
1070
|
if (broadcastId) {
|
|
1047
1071
|
if (BROADCAST_OUT) {
|
|
@@ -1796,7 +1820,7 @@ class Module extends EventEmitter {
|
|
|
1796
1820
|
const usage = user + system;
|
|
1797
1821
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1798
1822
|
}
|
|
1799
|
-
return format ? formatPercent(result) : result;
|
|
1823
|
+
return format ? formatPercent(result, 3) : result;
|
|
1800
1824
|
}
|
|
1801
1825
|
}
|
|
1802
1826
|
return format ? '' : 0;
|
|
@@ -1826,7 +1850,7 @@ class Module extends EventEmitter {
|
|
|
1826
1850
|
return (0, types_1.formatSize)(result, { unit });
|
|
1827
1851
|
}
|
|
1828
1852
|
}
|
|
1829
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1853
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1830
1854
|
}
|
|
1831
1855
|
static formatCpuMem(start, all) {
|
|
1832
1856
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1857,7 +1881,7 @@ class Module extends EventEmitter {
|
|
|
1857
1881
|
}
|
|
1858
1882
|
const unit = Math.max(bar, 10);
|
|
1859
1883
|
const length = Math.floor(usage * unit);
|
|
1860
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1884
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1861
1885
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1862
1886
|
}
|
|
1863
1887
|
else if (usage) {
|
|
@@ -1867,7 +1891,7 @@ class Module extends EventEmitter {
|
|
|
1867
1891
|
if (mem || all) {
|
|
1868
1892
|
const usage = this.getMemUsage(mem_format || true);
|
|
1869
1893
|
if (usage) {
|
|
1870
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1894
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1871
1895
|
}
|
|
1872
1896
|
}
|
|
1873
1897
|
return result;
|
|
@@ -2111,6 +2135,9 @@ class Module extends EventEmitter {
|
|
|
2111
2135
|
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
2112
2136
|
}
|
|
2113
2137
|
}
|
|
2138
|
+
else if (RESERVED_SHELL.includes(value)) {
|
|
2139
|
+
value = "'" + value + "'";
|
|
2140
|
+
}
|
|
2114
2141
|
}
|
|
2115
2142
|
}
|
|
2116
2143
|
else if (opt) {
|
|
@@ -2457,52 +2484,50 @@ class Module extends EventEmitter {
|
|
|
2457
2484
|
});
|
|
2458
2485
|
}
|
|
2459
2486
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
if ((
|
|
2467
|
-
|
|
2468
|
-
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2469
|
-
}
|
|
2470
|
-
else {
|
|
2471
|
-
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2472
|
-
dir = undefined;
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
if (!(0, types_1.isString)(dir)) {
|
|
2476
|
-
dir = VALUES["temp.dir"];
|
|
2487
|
+
let dir = settings.temp_dir, write, modified;
|
|
2488
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2489
|
+
dir || (dir = temp.dir);
|
|
2490
|
+
write = temp.write;
|
|
2491
|
+
}
|
|
2492
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2493
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2494
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2477
2495
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2496
|
+
else {
|
|
2497
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2498
|
+
dir = undefined;
|
|
2481
2499
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2500
|
+
}
|
|
2501
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2502
|
+
dir = VALUES["temp.dir"];
|
|
2503
|
+
}
|
|
2504
|
+
if (typeof write === 'boolean') {
|
|
2505
|
+
modified = VALUES["temp.write"] !== write;
|
|
2506
|
+
VALUES["temp.write"] = write;
|
|
2507
|
+
}
|
|
2508
|
+
do {
|
|
2509
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2510
|
+
if ((0, types_1.isString)(output)) {
|
|
2511
|
+
if (index > 0) {
|
|
2512
|
+
dir = trimDir(dir) + '_' + index;
|
|
2494
2513
|
}
|
|
2495
|
-
if (
|
|
2496
|
-
|
|
2514
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2515
|
+
VALUES["temp.dir"] = dir;
|
|
2516
|
+
modified = true;
|
|
2497
2517
|
}
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2518
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2519
|
+
break;
|
|
2501
2520
|
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
temp.dir = dir;
|
|
2521
|
+
if (output instanceof Error) {
|
|
2522
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2505
2523
|
}
|
|
2524
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2525
|
+
if (modified) {
|
|
2526
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2527
|
+
}
|
|
2528
|
+
settings.temp_dir = dir;
|
|
2529
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2530
|
+
temp.dir = dir;
|
|
2506
2531
|
}
|
|
2507
2532
|
return true;
|
|
2508
2533
|
}
|
package/lib-v4.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
-
|
|
3
|
-
declare const LibV4: IModuleLibV4;
|
|
4
|
-
|
|
1
|
+
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
+
|
|
3
|
+
declare const LibV4: IModuleLibV4;
|
|
4
|
+
|
|
5
5
|
export = LibV4;
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Module base class for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
-
"directory": "src/module"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
24
|
-
"abort-controller": "^3.0.0",
|
|
25
|
-
"chalk": "4.1.2",
|
|
26
|
-
"event-target-shim": "^5.0.1",
|
|
27
|
-
"file-type": "16.5.4",
|
|
28
|
-
"js-yaml": "^4.1.0",
|
|
29
|
-
"mime-types": "^2.1.35",
|
|
30
|
-
"picomatch": "^3.0.1",
|
|
31
|
-
"strip-ansi": "6.0.1"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/module",
|
|
3
|
+
"version": "0.8.13",
|
|
4
|
+
"description": "Module base class for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
+
"directory": "src/module"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/types": "0.8.13",
|
|
24
|
+
"abort-controller": "^3.0.0",
|
|
25
|
+
"chalk": "4.1.2",
|
|
26
|
+
"event-target-shim": "^5.0.1",
|
|
27
|
+
"file-type": "16.5.4",
|
|
28
|
+
"js-yaml": "^4.1.0",
|
|
29
|
+
"mime-types": "^2.1.35",
|
|
30
|
+
"picomatch": "^3.0.1",
|
|
31
|
+
"strip-ansi": "6.0.1"
|
|
32
|
+
}
|
|
33
|
+
}
|