@james-pre/config 0.0.1
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.md +157 -0
- package/README.md +3 -0
- package/dist/core.d.ts +43 -0
- package/dist/core.js +79 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/jobs.d.ts +48 -0
- package/dist/jobs.js +135 -0
- package/dist/manager.d.ts +123 -0
- package/dist/manager.js +343 -0
- package/dist/node/config.d.ts +119 -0
- package/dist/node/config.js +351 -0
- package/dist/node/core.d.ts +7 -0
- package/dist/node/core.js +198 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +17 -0
- package/dist/node/jobs.d.ts +11 -0
- package/dist/node/jobs.js +76 -0
- package/dist/node/process.d.ts +25 -0
- package/dist/node/process.js +78 -0
- package/dist/node/rl.d.ts +13 -0
- package/dist/node/rl.js +97 -0
- package/dist/table.d.ts +26 -0
- package/dist/table.js +65 -0
- package/dist/tracking.d.ts +20 -0
- package/dist/tracking.js +48 -0
- package/package.json +66 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
6
|
+
<https://fsf.org/>
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
9
|
+
license document, but changing it is not allowed.
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
|
13
|
+
supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
## 0. Additional Definitions.
|
|
16
|
+
|
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
|
19
|
+
GNU General Public License.
|
|
20
|
+
|
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
|
22
|
+
than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
|
32
|
+
Version".
|
|
33
|
+
|
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
## 2. Conveying Modified Versions.
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
|
58
|
+
to ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from a
|
|
67
|
+
header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
|
74
|
+
the Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
|
77
|
+
license document.
|
|
78
|
+
|
|
79
|
+
## 4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
|
82
|
+
together, effectively do not restrict modification of the portions of
|
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
|
84
|
+
debugging such modifications, if you also do each of the following:
|
|
85
|
+
|
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
|
87
|
+
the Library is used in it and that the Library and its use are
|
|
88
|
+
covered by this License.
|
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
|
90
|
+
license document.
|
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
|
92
|
+
execution, include the copyright notice for the Library among
|
|
93
|
+
these notices, as well as a reference directing the user to the
|
|
94
|
+
copies of the GNU GPL and this license document.
|
|
95
|
+
- d) Do one of the following:
|
|
96
|
+
- 0. Convey the Minimal Corresponding Source under the terms of
|
|
97
|
+
this License, and the Corresponding Application Code in a form
|
|
98
|
+
suitable for, and under terms that permit, the user to
|
|
99
|
+
recombine or relink the Application with a modified version of
|
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
102
|
+
Corresponding Source.
|
|
103
|
+
- 1. Use a suitable shared library mechanism for linking with
|
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
|
105
|
+
time a copy of the Library already present on the user's
|
|
106
|
+
computer system, and (b) will operate properly with a modified
|
|
107
|
+
version of the Library that is interface-compatible with the
|
|
108
|
+
Linked Version.
|
|
109
|
+
- e) Provide Installation Information, but only if you would
|
|
110
|
+
otherwise be required to provide such information under section 6
|
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
|
112
|
+
necessary to install and execute a modified version of the
|
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
|
119
|
+
Corresponding Source.)
|
|
120
|
+
|
|
121
|
+
## 5. Combined Libraries.
|
|
122
|
+
|
|
123
|
+
You may place library facilities that are a work based on the Library
|
|
124
|
+
side by side in a single library together with other library
|
|
125
|
+
facilities that are not Applications and are not covered by this
|
|
126
|
+
License, and convey such a combined library under terms of your
|
|
127
|
+
choice, if you do both of the following:
|
|
128
|
+
|
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
|
130
|
+
based on the Library, uncombined with any other library
|
|
131
|
+
facilities, conveyed under the terms of this License.
|
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
|
133
|
+
is a work based on the Library, and explaining where to find the
|
|
134
|
+
accompanying uncombined form of the same work.
|
|
135
|
+
|
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
|
137
|
+
|
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
140
|
+
versions will be similar in spirit to the present version, but may
|
|
141
|
+
differ in detail to address new problems or concerns.
|
|
142
|
+
|
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
|
144
|
+
as you received it specifies that a certain numbered version of the
|
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
|
146
|
+
it, you have the option of following the terms and conditions either
|
|
147
|
+
of that published version or of any later version published by the
|
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
|
151
|
+
published by the Free Software Foundation.
|
|
152
|
+
|
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
156
|
+
permanent authorization for you to choose that version for the
|
|
157
|
+
Library.
|
package/README.md
ADDED
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a human-readable string for a date that also fits into CLIs well (fixed-width)
|
|
3
|
+
*/
|
|
4
|
+
export declare function prettyDate(date: Date): string;
|
|
5
|
+
export declare let _debugOutput: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Enable or disable debug output.
|
|
8
|
+
*/
|
|
9
|
+
export declare function _setDebugOutput(enabled: boolean): void;
|
|
10
|
+
export declare function start(message: string): Disposable;
|
|
11
|
+
export declare let progress: (value: number, max: number, message?: any, valueText?: string) => void;
|
|
12
|
+
export declare let done: (noPrint?: boolean) => void;
|
|
13
|
+
export interface ProgressIO {
|
|
14
|
+
start(message: string): void;
|
|
15
|
+
progress(value: number, max: number, message?: any, valueText?: string): void;
|
|
16
|
+
done(noPrint?: boolean): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function useProgress(io: ProgressIO): void;
|
|
19
|
+
export declare let debug: (...args: any[]) => void;
|
|
20
|
+
export declare let log: (...args: any[]) => void;
|
|
21
|
+
export declare let info: (...args: any[]) => void;
|
|
22
|
+
export declare let warn: (...args: any[]) => void;
|
|
23
|
+
export declare let error: (...args: any[]) => void;
|
|
24
|
+
export interface ConsoleLike {
|
|
25
|
+
debug(...args: any[]): void;
|
|
26
|
+
log(...args: any[]): void;
|
|
27
|
+
info(...args: any[]): void;
|
|
28
|
+
warn(...args: any[]): void;
|
|
29
|
+
error(...args: any[]): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function useOutput(output: ConsoleLike): void;
|
|
32
|
+
export declare function warnOnce(...args: any[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* This is a factory for handling errors when performing operations.
|
|
35
|
+
* The handler will allow the parent scope to continue if certain errors occur,
|
|
36
|
+
* rather than fatally exiting.
|
|
37
|
+
*/
|
|
38
|
+
export declare function someWarnings(...allowList: [RegExp, string?][]): (error: string | Error) => void;
|
|
39
|
+
export declare function errorText(error: unknown): string;
|
|
40
|
+
/** @hidden @internal for other APIs that take a `Console` but check `.constructor.name` */
|
|
41
|
+
export declare const constructor: {
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
/* eslint-disable @typescript-eslint/only-throw-error */
|
|
3
|
+
const _month = new Intl.DateTimeFormat(undefined, { month: 'short' });
|
|
4
|
+
// Shortcut to convert to 2-digit. Mostly used to make the line shorter.
|
|
5
|
+
const _2 = (v) => v.toString().padStart(2, '0');
|
|
6
|
+
/**
|
|
7
|
+
* Get a human-readable string for a date that also fits into CLIs well (fixed-width)
|
|
8
|
+
*/
|
|
9
|
+
export function prettyDate(date) {
|
|
10
|
+
return `${date.getFullYear()} ${_month.format(date)} ${_2(date.getDate())} ${_2(date.getHours())}:${_2(date.getMinutes())}:${_2(date.getSeconds())}.${date.getMilliseconds().toString().padStart(3, '0')}`;
|
|
11
|
+
}
|
|
12
|
+
export let _debugOutput = false;
|
|
13
|
+
/**
|
|
14
|
+
* Enable or disable debug output.
|
|
15
|
+
*/
|
|
16
|
+
export function _setDebugOutput(enabled) {
|
|
17
|
+
_debugOutput = enabled;
|
|
18
|
+
}
|
|
19
|
+
// I/O for "progressive" actions
|
|
20
|
+
let _start;
|
|
21
|
+
export function start(message) {
|
|
22
|
+
_start(message);
|
|
23
|
+
return { [Symbol.dispose]: () => done(true) };
|
|
24
|
+
}
|
|
25
|
+
export let progress;
|
|
26
|
+
export let done;
|
|
27
|
+
export function useProgress(io) {
|
|
28
|
+
_start = io.start.bind(io);
|
|
29
|
+
progress = io.progress.bind(io);
|
|
30
|
+
done = io.done.bind(io);
|
|
31
|
+
}
|
|
32
|
+
// User-facing messaging
|
|
33
|
+
export let debug = console.debug;
|
|
34
|
+
export let log = console.log;
|
|
35
|
+
export let info = console.info;
|
|
36
|
+
export let warn = console.warn;
|
|
37
|
+
export let error = console.error;
|
|
38
|
+
export function useOutput(output) {
|
|
39
|
+
debug = output.debug.bind(output);
|
|
40
|
+
log = output.log.bind(output);
|
|
41
|
+
info = output.info.bind(output);
|
|
42
|
+
warn = output.warn.bind(output);
|
|
43
|
+
error = output.error.bind(output);
|
|
44
|
+
}
|
|
45
|
+
const _warned = new Set();
|
|
46
|
+
export function warnOnce(...args) {
|
|
47
|
+
const key = args.map(String).join(' ');
|
|
48
|
+
if (_warned.has(key))
|
|
49
|
+
return;
|
|
50
|
+
_warned.add(key);
|
|
51
|
+
warn(...args);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* This is a factory for handling errors when performing operations.
|
|
55
|
+
* The handler will allow the parent scope to continue if certain errors occur,
|
|
56
|
+
* rather than fatally exiting.
|
|
57
|
+
*/
|
|
58
|
+
export function someWarnings(...allowList) {
|
|
59
|
+
return (error) => {
|
|
60
|
+
error = typeof error == 'object' && 'message' in error ? error.message : error;
|
|
61
|
+
for (const [pattern, message = error] of allowList) {
|
|
62
|
+
if (!pattern.test(error))
|
|
63
|
+
continue;
|
|
64
|
+
warn(message);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const zod = await import('zod/v4/core').catch(() => null);
|
|
71
|
+
export function errorText(error) {
|
|
72
|
+
if (zod && error instanceof zod.$ZodError)
|
|
73
|
+
return zod.prettifyError(error);
|
|
74
|
+
if (error instanceof Error)
|
|
75
|
+
return error.message;
|
|
76
|
+
return String(error);
|
|
77
|
+
}
|
|
78
|
+
/** @hidden @internal for other APIs that take a `Console` but check `.constructor.name` */
|
|
79
|
+
export const constructor = { name: 'Console' };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './manager.js';
|
package/dist/index.js
ADDED
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface JobResult {
|
|
2
|
+
status: 'succeeded' | 'failed';
|
|
3
|
+
text: {
|
|
4
|
+
toString(): string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export declare function useClear(clear: (lastDrawLineCount: number) => void): void;
|
|
8
|
+
export declare function useDraw(draw: (lines: string[]) => void): void;
|
|
9
|
+
export declare function useResultFormat(format: (result: JobResult) => string): void;
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function _disableInPlaceUpdates(): void;
|
|
12
|
+
export interface Options {
|
|
13
|
+
concurrency: number;
|
|
14
|
+
jobStartText?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Results {
|
|
17
|
+
failed: number;
|
|
18
|
+
noJobs?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface Context {
|
|
21
|
+
nextIndex: number;
|
|
22
|
+
remaining: number;
|
|
23
|
+
failed: number;
|
|
24
|
+
finished: number;
|
|
25
|
+
prefix(i: number, number?: number): string;
|
|
26
|
+
}
|
|
27
|
+
export interface JobContext {
|
|
28
|
+
progress(this: void, ...args: any[]): void;
|
|
29
|
+
}
|
|
30
|
+
type JobFn = (context: JobContext) => JobResult | Promise<JobResult>;
|
|
31
|
+
export type Job = JobFn | {
|
|
32
|
+
run: JobFn;
|
|
33
|
+
name?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A position in a job list that enforces job ordering.
|
|
37
|
+
* Every job before it finishes before any job after it starts.
|
|
38
|
+
* It is not work of its own, so it is not counted or numbered.
|
|
39
|
+
*/
|
|
40
|
+
export declare const barrier: unique symbol;
|
|
41
|
+
export declare function run(options: Options, entries: (Job | typeof barrier)[]): Promise<Results>;
|
|
42
|
+
export interface OptionsWithData<T> extends Options {
|
|
43
|
+
run(data: T, progress: (...args: any[]) => void): JobResult | Promise<JobResult>;
|
|
44
|
+
name?(data: T): string | undefined;
|
|
45
|
+
group?(data: T): unknown;
|
|
46
|
+
}
|
|
47
|
+
export declare function runWithData<T>(options: OptionsWithData<T>, data: T[]): Promise<Results>;
|
|
48
|
+
export {};
|
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import * as io from './core.js';
|
|
3
|
+
let clearActiveLines, drawActiveLines, formatJobResult = (result) => result.text ? result.text.toString() : result.status == 'failed' ? 'failed' : 'done', _noInPlaceUpdate = false;
|
|
4
|
+
export function useClear(clear) {
|
|
5
|
+
clearActiveLines = clear;
|
|
6
|
+
}
|
|
7
|
+
export function useDraw(draw) {
|
|
8
|
+
drawActiveLines = draw;
|
|
9
|
+
}
|
|
10
|
+
export function useResultFormat(format) {
|
|
11
|
+
formatJobResult = format;
|
|
12
|
+
}
|
|
13
|
+
/** @internal */
|
|
14
|
+
export function _disableInPlaceUpdates() {
|
|
15
|
+
_noInPlaceUpdate = true;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A position in a job list that enforces job ordering.
|
|
19
|
+
* Every job before it finishes before any job after it starts.
|
|
20
|
+
* It is not work of its own, so it is not counted or numbered.
|
|
21
|
+
*/
|
|
22
|
+
export const barrier = Symbol('ioium.jobs.barrier');
|
|
23
|
+
export async function run(options, entries) {
|
|
24
|
+
const jobs = [];
|
|
25
|
+
const segments = [];
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (entry !== barrier) {
|
|
28
|
+
jobs.push(entry);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (jobs.length && segments.at(-1) !== jobs.length)
|
|
32
|
+
segments.push(jobs.length);
|
|
33
|
+
}
|
|
34
|
+
if (!jobs.length) {
|
|
35
|
+
return { failed: 0, noJobs: true };
|
|
36
|
+
}
|
|
37
|
+
if (segments.at(-1) !== jobs.length)
|
|
38
|
+
segments.push(jobs.length);
|
|
39
|
+
const totalWidth = jobs.length.toString().length;
|
|
40
|
+
const $ = {
|
|
41
|
+
nextIndex: 0,
|
|
42
|
+
remaining: jobs.length,
|
|
43
|
+
failed: 0,
|
|
44
|
+
finished: 0,
|
|
45
|
+
prefix(i, number = i + 1) {
|
|
46
|
+
let prefix = `[${number.toString().padStart(totalWidth)}/${jobs.length}]`;
|
|
47
|
+
if (typeof jobs[i] === 'object' && jobs[i].name)
|
|
48
|
+
prefix += ' ' + jobs[i].name;
|
|
49
|
+
return prefix;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const activeJobs = [];
|
|
53
|
+
let lastDrawLineCount = 0;
|
|
54
|
+
function _draw() {
|
|
55
|
+
if (_noInPlaceUpdate)
|
|
56
|
+
return;
|
|
57
|
+
drawActiveLines?.(activeJobs.map((j, i) => `${$.prefix(j.index, $.finished + 1 + i)} ${j.message}`));
|
|
58
|
+
lastDrawLineCount = activeJobs.length;
|
|
59
|
+
}
|
|
60
|
+
function _clear() {
|
|
61
|
+
if (!lastDrawLineCount || _noInPlaceUpdate)
|
|
62
|
+
return;
|
|
63
|
+
clearActiveLines?.(lastDrawLineCount);
|
|
64
|
+
lastDrawLineCount = 0;
|
|
65
|
+
}
|
|
66
|
+
async function nextJob(limit, noInitialDraw = false) {
|
|
67
|
+
if ($.nextIndex >= limit)
|
|
68
|
+
return;
|
|
69
|
+
const index = $.nextIndex++;
|
|
70
|
+
const job = { message: options.jobStartText || 'starting...', index };
|
|
71
|
+
if (!_noInPlaceUpdate && !noInitialDraw)
|
|
72
|
+
_clear();
|
|
73
|
+
activeJobs.push(job);
|
|
74
|
+
if (_noInPlaceUpdate)
|
|
75
|
+
io.log($.prefix(index, $.finished + activeJobs.length), job.message);
|
|
76
|
+
else if (!noInitialDraw)
|
|
77
|
+
_draw();
|
|
78
|
+
function progress(...args) {
|
|
79
|
+
const line = args.join(' ').trim();
|
|
80
|
+
if (!line)
|
|
81
|
+
return;
|
|
82
|
+
job.message = line;
|
|
83
|
+
_clear();
|
|
84
|
+
_draw();
|
|
85
|
+
}
|
|
86
|
+
const runJob = typeof jobs[index] === 'function' ? jobs[index] : jobs[index].run;
|
|
87
|
+
let result;
|
|
88
|
+
try {
|
|
89
|
+
result = await runJob({ progress });
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
result = { status: 'failed', text: io.errorText(e) };
|
|
93
|
+
}
|
|
94
|
+
if (result.status == 'failed')
|
|
95
|
+
$.failed++;
|
|
96
|
+
_clear();
|
|
97
|
+
io.log($.prefix(index, ++$.finished), formatJobResult(result));
|
|
98
|
+
const jobIdx = activeJobs.indexOf(job);
|
|
99
|
+
if (jobIdx === -1)
|
|
100
|
+
throw new Error('BUG: Could not remove a job from the active jobs list');
|
|
101
|
+
activeJobs.splice(jobIdx, 1);
|
|
102
|
+
_draw();
|
|
103
|
+
$.remaining--;
|
|
104
|
+
return await nextJob(limit);
|
|
105
|
+
}
|
|
106
|
+
for (const end of segments) {
|
|
107
|
+
const allDone = [];
|
|
108
|
+
for (let i = 0; i < options.concurrency; i++) {
|
|
109
|
+
if ($.nextIndex >= end)
|
|
110
|
+
break;
|
|
111
|
+
allDone.push(nextJob(end, true));
|
|
112
|
+
}
|
|
113
|
+
_clear();
|
|
114
|
+
_draw();
|
|
115
|
+
await Promise.all(allDone);
|
|
116
|
+
}
|
|
117
|
+
return { failed: $.failed };
|
|
118
|
+
}
|
|
119
|
+
export async function runWithData(options, data) {
|
|
120
|
+
const entries = [];
|
|
121
|
+
let previous;
|
|
122
|
+
for (const [i, d] of data.entries()) {
|
|
123
|
+
if (options.group) {
|
|
124
|
+
const group = options.group(d);
|
|
125
|
+
if (i && !Object.is(group, previous))
|
|
126
|
+
entries.push(barrier);
|
|
127
|
+
previous = group;
|
|
128
|
+
}
|
|
129
|
+
entries.push({
|
|
130
|
+
run: (context) => options.run(d, context.progress),
|
|
131
|
+
name: options.name?.(d),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return await run(options, entries);
|
|
135
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import type { FlattenKeys, GetByString, PartialRecursive } from 'utilium';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
export type FileType = 'system' | 'user' | 'local';
|
|
5
|
+
/** Information about a loaded config file */
|
|
6
|
+
interface File<Value> {
|
|
7
|
+
path: string;
|
|
8
|
+
wasIncluded: boolean;
|
|
9
|
+
data: Value;
|
|
10
|
+
type: FileType;
|
|
11
|
+
auto: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* How a file is being loaded
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
interface FileLoadInit {
|
|
18
|
+
wasIncluded?: boolean;
|
|
19
|
+
type?: FileType;
|
|
20
|
+
auto?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface LoadOptions {
|
|
23
|
+
/**
|
|
24
|
+
* If enabled, the config file will still be loaded if it does not match the schema.
|
|
25
|
+
*/
|
|
26
|
+
loose?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* If enabled, the config file will be skipped if it does not exist.
|
|
29
|
+
*/
|
|
30
|
+
optional?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* If enabled, an empty config file will be created when it does not exist.
|
|
33
|
+
* Included files are never created.
|
|
34
|
+
*/
|
|
35
|
+
create?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Used to mark files that are included, auto-loaded, etc.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
[kInit]?: FileLoadInit;
|
|
41
|
+
}
|
|
42
|
+
declare const kInit: unique symbol;
|
|
43
|
+
export interface ManagerOptions {
|
|
44
|
+
/** If true, allow specifying `include: [...]` to load additional files */
|
|
45
|
+
enableIncludes?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If set, try to load files in the XDG config directory (or the OS-equivalent).
|
|
48
|
+
* This corresponds to the relative path, though you can omit `.json`
|
|
49
|
+
*/
|
|
50
|
+
xdg?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Try to load system-wide configuration from `/etc` (or the OS-equivalent).
|
|
53
|
+
* Trailing `.json` can be omitted.
|
|
54
|
+
*/
|
|
55
|
+
system?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Manager for configuration files
|
|
59
|
+
*/
|
|
60
|
+
export declare class Manager<Shape extends Readonly<Record<string, z.ZodType>>, LoadOpts extends LoadOptions = LoadOptions, out In extends z.input<z.ZodObject<Shape>> = z.input<z.ZodObject<Shape>>, out FileData = z.output<ReturnType<typeof z.deepPartial<z.ZodObject<Shape>>>>> extends EventEmitter<{
|
|
61
|
+
load: [path: string, config: FileData];
|
|
62
|
+
post_load: [path: string, config: FileData];
|
|
63
|
+
load_error: [path: string, stage: 'read' | 'create' | 'parse', error: Error];
|
|
64
|
+
create: [path: string];
|
|
65
|
+
change: [];
|
|
66
|
+
write: [path: string, data: FileData];
|
|
67
|
+
reload: [];
|
|
68
|
+
}> {
|
|
69
|
+
protected options: ManagerOptions;
|
|
70
|
+
readonly schema: z.ZodObject<Shape>;
|
|
71
|
+
readonly fileSchema: ReturnType<typeof z.deepPartial<z.ZodObject<Shape>>>;
|
|
72
|
+
protected files: Map<string, File<FileData>>;
|
|
73
|
+
readonly data: z.output<z.ZodObject<Shape>>;
|
|
74
|
+
constructor(shape: Shape, options?: ManagerOptions);
|
|
75
|
+
/**
|
|
76
|
+
* A fresh config with only the schema's defaults applied.
|
|
77
|
+
*/
|
|
78
|
+
get defaults(): z.output<z.ZodObject<Shape>> & In;
|
|
79
|
+
get<const K extends string | number = FlattenKeys<z.output<z.ZodObject<Shape>>>>(key: K): GetByString<z.output<z.ZodObject<Shape>>, K>;
|
|
80
|
+
set<const K extends string | number = FlattenKeys<z.output<z.ZodObject<Shape>>>, V = GetByString<z.output<z.ZodObject<Shape>>, K>>(key: K, value: V): void;
|
|
81
|
+
/**
|
|
82
|
+
* Deeply merge `config` into the current config. Arrays are replaced rather than combined.
|
|
83
|
+
*/
|
|
84
|
+
merge(config: PartialRecursive<In>): void;
|
|
85
|
+
/** Replace the current config with `config`, applying defaults for anything missing. */
|
|
86
|
+
replace(config: In): void;
|
|
87
|
+
loadFile(path: string, options: LoadOpts): void;
|
|
88
|
+
/** Get the entry for `path`, adding one for a file that has not been loaded */
|
|
89
|
+
protected fileAt(path: string): File<FileData>;
|
|
90
|
+
protected writeFile(file: File<FileData>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Replace the contents of the config file at `path` and write it,
|
|
93
|
+
* then rebuild the current config from the defaults and all loaded files.
|
|
94
|
+
*/
|
|
95
|
+
replaceFile(path: string, config: In): void;
|
|
96
|
+
/**
|
|
97
|
+
* Merge `config` into the current config and into the config file at `path`, then write it.
|
|
98
|
+
*/
|
|
99
|
+
updateFile(path: string, config: PartialRecursive<In>): void;
|
|
100
|
+
/**
|
|
101
|
+
* The files `loadDefaults` will try to load, ordered from most global to most local.
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
get defaultPaths(): ReadonlyArray<{
|
|
105
|
+
path: string;
|
|
106
|
+
type: FileType;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Load the files from `defaultPaths`. Missing files are skipped unless `options` says otherwise.
|
|
110
|
+
*/
|
|
111
|
+
loadDefaults(options: LoadOpts): void;
|
|
112
|
+
/**
|
|
113
|
+
* The file a change of the given type is written to:
|
|
114
|
+
* the most recently loaded file of that type, or the path `loadDefaults` would use for it.
|
|
115
|
+
*/
|
|
116
|
+
findPath(type?: FileType): string;
|
|
117
|
+
/**
|
|
118
|
+
* Merge `config` into the current config and save it.
|
|
119
|
+
*/
|
|
120
|
+
update(config: PartialRecursive<In>, type?: FileType): void;
|
|
121
|
+
reloadFiles(options: LoadOpts): void;
|
|
122
|
+
}
|
|
123
|
+
export {};
|