@homedev/framework 0.0.12 → 0.0.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/dist/index.d.ts +348 -28
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a file is readable.
|
|
3
|
+
*
|
|
4
|
+
* @param fileName - File path to check.
|
|
5
|
+
* @returns True when the file can be accessed for reading.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const exists: (fileName: string) => Promise<boolean>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare interface FilePatternOptions {
|
|
14
|
+
cwd: string;
|
|
15
|
+
filter?: (fileName: string, index: number, array: string[]) => boolean;
|
|
16
|
+
map: (fileName: string, index: number, array: string[]) => Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the working directory used by file utilities.
|
|
21
|
+
*
|
|
22
|
+
* @param cwd - Optional absolute or relative directory override.
|
|
23
|
+
* @returns Absolute working directory path.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const getCwd: (cwd?: string) => string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Maps files matching a glob pattern (or a single path) with async projection.
|
|
30
|
+
*
|
|
31
|
+
* @param pattern - Glob pattern(s) or direct file path.
|
|
32
|
+
* @param options - Mapping options including cwd, optional filter, and map function.
|
|
33
|
+
* @returns Mapped result for a direct path, or mapped array for glob patterns.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare interface ImportOptions {
|
|
52
|
+
cwd?: string;
|
|
53
|
+
resolveDefault?: boolean | 'only';
|
|
54
|
+
filter?: (name: string) => boolean | undefined;
|
|
55
|
+
fail?: (name: string, error: any) => boolean | undefined;
|
|
56
|
+
map?: (module: any, name: string) => any;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
* @param fileName - Name or path of the file to load.
|
|
62
|
+
* @param options - Loading options including parser selection and lookup directories.
|
|
63
|
+
* @returns Parsed file content and path metadata.
|
|
64
|
+
* @throws - When no parser is resolved or locating/reading/parsing fails.
|
|
65
|
+
*/
|
|
66
|
+
export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare interface LoadFormatParser {
|
|
72
|
+
matching?: string[];
|
|
73
|
+
fn: (data: string) => any;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare interface LoadOptions {
|
|
80
|
+
dirs?: string[];
|
|
81
|
+
parsers?: Record<string, LoadFormatParser>;
|
|
82
|
+
format?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Result of loading and parsing a file.
|
|
87
|
+
*
|
|
88
|
+
* @typeParam T - Parsed content type.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare interface LoadResult<T> {
|
|
92
|
+
fullPath: string;
|
|
93
|
+
folderPath: string;
|
|
94
|
+
content: T;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolves a file path by searching the provided directories.
|
|
99
|
+
*
|
|
100
|
+
* @param fileName - File name or path to locate.
|
|
101
|
+
* @param dirs - Optional directories to search when fileName is relative.
|
|
102
|
+
* @returns Absolute path to the first matching file.
|
|
103
|
+
* @throws - When no matching file is found.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
1
111
|
export declare type LogFunction = (className: string, ...args: any[]) => void;
|
|
2
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
3
116
|
export declare class Logger {
|
|
4
117
|
options: LoggerOptions;
|
|
118
|
+
/**
|
|
119
|
+
* Creates a logger with optional configuration overrides.
|
|
120
|
+
*
|
|
121
|
+
* @param options - Partial logger options to merge with defaults.
|
|
122
|
+
*/
|
|
5
123
|
constructor(options?: Partial<LoggerOptions>);
|
|
124
|
+
/**
|
|
125
|
+
* Writes a log entry when the message level passes the configured filter.
|
|
126
|
+
*
|
|
127
|
+
* @param className - Log level name.
|
|
128
|
+
* @param args - Log payload values.
|
|
129
|
+
*/
|
|
6
130
|
write(className: string, ...args: any[]): void;
|
|
131
|
+
/**
|
|
132
|
+
* Writes an INFO level log entry.
|
|
133
|
+
*
|
|
134
|
+
* @param args - Log payload values.
|
|
135
|
+
*/
|
|
7
136
|
info(...args: any[]): void;
|
|
137
|
+
/**
|
|
138
|
+
* Writes an ERROR level log entry.
|
|
139
|
+
*
|
|
140
|
+
* @param args - Log payload values.
|
|
141
|
+
*/
|
|
8
142
|
error(...args: any[]): void;
|
|
143
|
+
/**
|
|
144
|
+
* Writes a WARN level log entry.
|
|
145
|
+
*
|
|
146
|
+
* @param args - Log payload values.
|
|
147
|
+
*/
|
|
9
148
|
warn(...args: any[]): void;
|
|
149
|
+
/**
|
|
150
|
+
* Writes a DEBUG level log entry.
|
|
151
|
+
*
|
|
152
|
+
* @param args - Log payload values.
|
|
153
|
+
*/
|
|
10
154
|
debug(...args: any[]): void;
|
|
155
|
+
/**
|
|
156
|
+
* Writes a VERBOSE level log entry.
|
|
157
|
+
*
|
|
158
|
+
* @param args - Log payload values.
|
|
159
|
+
*/
|
|
11
160
|
verbose(...args: any[]): void;
|
|
12
161
|
}
|
|
13
162
|
|
|
163
|
+
/**
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
14
166
|
export declare interface LoggerOptions {
|
|
15
167
|
level: string;
|
|
16
168
|
showClass: boolean;
|
|
@@ -21,32 +173,74 @@ export declare interface LoggerOptions {
|
|
|
21
173
|
logFunction: LogFunction;
|
|
22
174
|
}
|
|
23
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Fluent markdown content builder.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
24
181
|
export declare class Markdown extends StringBuilder {
|
|
25
182
|
#private;
|
|
183
|
+
/**
|
|
184
|
+
* Writes a markdown heading and trailing blank line.
|
|
185
|
+
*
|
|
186
|
+
* @param text - Heading text.
|
|
187
|
+
* @param level - Heading level from 1 to 6.
|
|
188
|
+
*/
|
|
26
189
|
header(text: string, level?: number): this;
|
|
190
|
+
/**
|
|
191
|
+
* Starts a fenced code block and optionally writes code and closes it.
|
|
192
|
+
*
|
|
193
|
+
* @param code - Optional code content.
|
|
194
|
+
* @param language - Optional code language id.
|
|
195
|
+
*/
|
|
27
196
|
codeBlock(code?: string, language?: string): this;
|
|
197
|
+
/** Closes the current fenced code block. */
|
|
28
198
|
endCodeBlock(): this;
|
|
29
|
-
|
|
199
|
+
/** Writes an inline markdown link. */
|
|
200
|
+
link(text: string, url: string, title?: string): this;
|
|
201
|
+
/** Writes a markdown table from headers and rows. */
|
|
30
202
|
table(headers: string[], rows: string[][]): this;
|
|
203
|
+
/** Writes one or more quoted lines. */
|
|
31
204
|
blockquote(text: string): this;
|
|
205
|
+
/** Writes bold text. */
|
|
32
206
|
bold(text: string): this;
|
|
207
|
+
/** Writes italic text. */
|
|
33
208
|
italic(text: string): this;
|
|
209
|
+
/** Writes a bullet item line. */
|
|
34
210
|
item(text: string): this;
|
|
211
|
+
/** Writes bullet items from an array or key-value map. */
|
|
35
212
|
items(items: string[] | Record<string, any>): this;
|
|
213
|
+
/** Writes an ordered list starting from the provided number. */
|
|
36
214
|
orderedList(items: string[], start?: number): this;
|
|
215
|
+
/** Writes inline code text. */
|
|
37
216
|
code(text: string): this;
|
|
217
|
+
/** Writes a horizontal rule. */
|
|
38
218
|
horizontalRule(): this;
|
|
219
|
+
/** Writes an image markdown line. */
|
|
39
220
|
image(alt: string, url: string): this;
|
|
221
|
+
/** Writes strikethrough text. */
|
|
40
222
|
strikethrough(text: string): this;
|
|
223
|
+
/** Writes highlighted text using == syntax. */
|
|
41
224
|
highlight(text: string): this;
|
|
225
|
+
/** Writes subscript text using ~ syntax. */
|
|
42
226
|
subscript(text: string): this;
|
|
227
|
+
/** Writes superscript text using ^ syntax. */
|
|
43
228
|
superscript(text: string): this;
|
|
229
|
+
/** Writes a markdown task list. */
|
|
44
230
|
taskList(items: {
|
|
45
231
|
text: string;
|
|
46
232
|
checked: boolean;
|
|
47
233
|
}[]): this;
|
|
234
|
+
/**
|
|
235
|
+
* Starts a section heading and increments internal nesting level.
|
|
236
|
+
*
|
|
237
|
+
* @param text - Section title.
|
|
238
|
+
* @param level - Optional explicit heading level baseline.
|
|
239
|
+
*/
|
|
48
240
|
section(text: string, level?: number): this;
|
|
241
|
+
/** Decrements section nesting level by one. */
|
|
49
242
|
endSection(): this;
|
|
243
|
+
/** Sets the internal section nesting level directly. */
|
|
50
244
|
setSectionLevel(level: number): this;
|
|
51
245
|
}
|
|
52
246
|
|
|
@@ -118,6 +312,16 @@ export declare class NavigateResult {
|
|
|
118
312
|
static DeleteItem(skipSiblings?: boolean): NavigateResult;
|
|
119
313
|
}
|
|
120
314
|
|
|
315
|
+
/**
|
|
316
|
+
* @public
|
|
317
|
+
*/
|
|
318
|
+
export declare interface Output {
|
|
319
|
+
name: string;
|
|
320
|
+
type?: 'json' | 'yaml' | 'text';
|
|
321
|
+
value: any;
|
|
322
|
+
class?: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
121
325
|
/**
|
|
122
326
|
* Options for configuring the select function behavior
|
|
123
327
|
* @public
|
|
@@ -135,24 +339,74 @@ export declare interface SelectOptions {
|
|
|
135
339
|
optional?: boolean;
|
|
136
340
|
}
|
|
137
341
|
|
|
342
|
+
/**
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
138
345
|
export declare class StringBuilder {
|
|
139
346
|
#private;
|
|
140
347
|
options: StringBuilderOptions;
|
|
348
|
+
/**
|
|
349
|
+
* Creates a new StringBuilder instance.
|
|
350
|
+
*
|
|
351
|
+
* @param initial - Optional initial content.
|
|
352
|
+
* @param options - Builder formatting options.
|
|
353
|
+
*/
|
|
141
354
|
constructor(initial?: string | string[] | StringBuilder, options?: StringBuilderOptions);
|
|
355
|
+
/**
|
|
356
|
+
* Replaces current formatting options.
|
|
357
|
+
*
|
|
358
|
+
* @param options - New builder options.
|
|
359
|
+
* @returns Current builder instance.
|
|
360
|
+
*/
|
|
142
361
|
setOptions(options: StringBuilderOptions): this;
|
|
362
|
+
/** Clears all buffered blocks. */
|
|
143
363
|
clear(): this;
|
|
364
|
+
/** Returns true when no content is buffered. */
|
|
144
365
|
isEmpty(): boolean;
|
|
366
|
+
/** Returns concatenated content. */
|
|
145
367
|
toString(): string;
|
|
368
|
+
/** Increases indentation level by one. */
|
|
146
369
|
indent(): this;
|
|
370
|
+
/** Decreases indentation level by one when possible. */
|
|
147
371
|
dedent(): this;
|
|
372
|
+
/** Returns current indentation level. */
|
|
148
373
|
getCurrentIndent(): number;
|
|
374
|
+
/** Returns current content split by newline. */
|
|
149
375
|
getLines(): string[];
|
|
376
|
+
/**
|
|
377
|
+
* Formats a line according to indentation and line options.
|
|
378
|
+
*
|
|
379
|
+
* @param line - Input line to format.
|
|
380
|
+
* @returns Formatted line including line separator.
|
|
381
|
+
*/
|
|
150
382
|
formatLine(line?: string): string;
|
|
383
|
+
/**
|
|
384
|
+
* Appends one or more values to the buffer.
|
|
385
|
+
*
|
|
386
|
+
* @param args - Values to append.
|
|
387
|
+
* @returns Current builder instance.
|
|
388
|
+
*/
|
|
151
389
|
write(...args: any[]): this;
|
|
390
|
+
/**
|
|
391
|
+
* Writes one or more formatted lines.
|
|
392
|
+
*
|
|
393
|
+
* @param args - Values to write as lines.
|
|
394
|
+
* @returns Current builder instance.
|
|
395
|
+
*/
|
|
152
396
|
writeLine(...args: any[]): this;
|
|
397
|
+
/**
|
|
398
|
+
* Maps input items to writes using a callback.
|
|
399
|
+
*
|
|
400
|
+
* @param items - Source items.
|
|
401
|
+
* @param fn - Mapping callback.
|
|
402
|
+
* @returns Current builder instance.
|
|
403
|
+
*/
|
|
153
404
|
writeMap<T>(items: T[], fn: (item: T, index: number, builder: this) => string | this): this;
|
|
154
405
|
}
|
|
155
406
|
|
|
407
|
+
/**
|
|
408
|
+
* @public
|
|
409
|
+
*/
|
|
156
410
|
export declare interface StringBuilderOptions {
|
|
157
411
|
indentChar?: string;
|
|
158
412
|
indentSize?: number;
|
|
@@ -162,6 +416,72 @@ export declare interface StringBuilderOptions {
|
|
|
162
416
|
lineSuffix?: string;
|
|
163
417
|
}
|
|
164
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Encodes and writes content to a file path using the selected format encoder.
|
|
421
|
+
*
|
|
422
|
+
* @param filePath - Destination file path.
|
|
423
|
+
* @param content - Data to encode and write.
|
|
424
|
+
* @param options - Encoder selection options.
|
|
425
|
+
* @returns Promise resolved when writing completes.
|
|
426
|
+
* @throws - When no encoder can be resolved.
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
export declare const writeFormat: (filePath: string, content: any, options?: WriteFormatOptions) => Promise<void>;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @public
|
|
433
|
+
*/
|
|
434
|
+
export declare interface WriteFormatEncoder {
|
|
435
|
+
matching?: string[];
|
|
436
|
+
fn: (data: any) => Promise<string> | string;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* @public
|
|
441
|
+
*/
|
|
442
|
+
export declare interface WriteFormatOptions {
|
|
443
|
+
format: string;
|
|
444
|
+
encoders?: Record<string, WriteFormatEncoder>;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Writes a single output entry to disk.
|
|
449
|
+
*
|
|
450
|
+
* @param o - Output entry to write.
|
|
451
|
+
* @param options - Writing behavior configuration.
|
|
452
|
+
* @returns Promise resolved when output is processed.
|
|
453
|
+
* @throws - When class requirements fail or file operations fail.
|
|
454
|
+
* @public
|
|
455
|
+
*/
|
|
456
|
+
export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* @public
|
|
460
|
+
*/
|
|
461
|
+
export declare interface WriteOutputOption {
|
|
462
|
+
targetDirectory?: string;
|
|
463
|
+
writing?: (output: Output) => boolean | undefined | void;
|
|
464
|
+
classes?: string[];
|
|
465
|
+
classRequired?: boolean;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Writes multiple outputs to disk.
|
|
470
|
+
*
|
|
471
|
+
* @param outputs - Output definitions to write.
|
|
472
|
+
* @param options - Writing behavior configuration.
|
|
473
|
+
* @returns Promise resolved when all outputs are processed.
|
|
474
|
+
* @public
|
|
475
|
+
*/
|
|
476
|
+
export declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* @public
|
|
480
|
+
*/
|
|
481
|
+
export declare interface WriteOutputsOption extends WriteOutputOption {
|
|
482
|
+
removeFirst?: boolean;
|
|
483
|
+
}
|
|
484
|
+
|
|
165
485
|
export { }
|
|
166
486
|
|
|
167
487
|
/* Global declarations */
|
|
@@ -174,6 +494,33 @@ declare global {
|
|
|
174
494
|
var defined: <T>(value: T | undefined | null, msg?: string) => T;
|
|
175
495
|
}
|
|
176
496
|
|
|
497
|
+
declare global {
|
|
498
|
+
interface String {
|
|
499
|
+
capitalize(): string;
|
|
500
|
+
toPascal(): string;
|
|
501
|
+
toCamel(): string;
|
|
502
|
+
toSnake(): string;
|
|
503
|
+
toKebab(): string;
|
|
504
|
+
changeCase(to: 'upper' | 'lower' | 'pascal' | 'camel' | 'snake' | 'kebab'): string;
|
|
505
|
+
splitWithQuotes(separator?: string): {
|
|
506
|
+
value: string;
|
|
507
|
+
quoted: boolean;
|
|
508
|
+
}[];
|
|
509
|
+
splitNested(separator: string, open: string, close: string): string[];
|
|
510
|
+
padBlock(indent: number, separator?: string, padder?: string): string;
|
|
511
|
+
tokenize(from: Record<string, unknown>, tokenizer?: RegExp): string;
|
|
512
|
+
stripIndent(): string;
|
|
513
|
+
toHtmlLink(path?: string): string;
|
|
514
|
+
toStringBuilder(): StringBuilder;
|
|
515
|
+
toRgb(): string;
|
|
516
|
+
toArgb(): string;
|
|
517
|
+
single(char: string): string;
|
|
518
|
+
remove(char: string): string;
|
|
519
|
+
toAlphanum(): string;
|
|
520
|
+
toAlpha(): string;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
177
524
|
declare global {
|
|
178
525
|
interface ObjectConstructor {
|
|
179
526
|
mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
|
|
@@ -208,30 +555,3 @@ declare global {
|
|
|
208
555
|
}
|
|
209
556
|
}
|
|
210
557
|
|
|
211
|
-
declare global {
|
|
212
|
-
interface String {
|
|
213
|
-
capitalize(): string;
|
|
214
|
-
toPascal(): string;
|
|
215
|
-
toCamel(): string;
|
|
216
|
-
toSnake(): string;
|
|
217
|
-
toKebab(): string;
|
|
218
|
-
changeCase(to: 'upper' | 'lower' | 'pascal' | 'camel' | 'snake' | 'kebab'): string;
|
|
219
|
-
splitWithQuotes(separator?: string): {
|
|
220
|
-
value: string;
|
|
221
|
-
quoted: boolean;
|
|
222
|
-
}[];
|
|
223
|
-
splitNested(separator: string, open: string, close: string): string[];
|
|
224
|
-
padBlock(indent: number, separator?: string, padder?: string): string;
|
|
225
|
-
tokenize(from: Record<string, unknown>, tokenizer?: RegExp): string;
|
|
226
|
-
stripIndent(): string;
|
|
227
|
-
toHtmlLink(path?: string): string;
|
|
228
|
-
toStringBuilder(): StringBuilder;
|
|
229
|
-
toRgb(): string;
|
|
230
|
-
toArgb(): string;
|
|
231
|
-
single(char: string): string;
|
|
232
|
-
remove(char: string): string;
|
|
233
|
-
toAlphanum(): string;
|
|
234
|
-
toAlpha(): string;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Array.prototype.findOrFail=function(
|
|
2
|
-
`))};String.prototype.padBlock=function(
|
|
3
|
-
`,
|
|
4
|
-
`)};String.prototype.toHtmlLink=function(
|
|
5
|
-
`)}formatLine(
|
|
6
|
-
`;let
|
|
7
|
-
`)}write(...
|
|
8
|
-
`)}writeMap(
|
|
9
|
-
`).forEach((
|
|
1
|
+
Array.prototype.findOrFail=function(T,x,f){let m=this.find(T,f);if(m===void 0)throw Error(x??"Element not found");return m};Array.flat=function(T){if(Array.isArray(T))return T.flat(2);else return[T]};Array.prototype.forEachAsync=async function(T){for(let x=0;x<this.length;x++)await T(this[x],x,this)};Array.prototype.groupBy=function(T){return this.reduce((x,f)=>{let m=T(f);if(!x[m])x[m]=[];return x[m].push(f),x},{})};Array.prototype.createInstances=function(T,...x){return this.map((f,m)=>new T(...x,f,m))};Array.prototype.mapAsync=async function(T){return Promise.all(this.map(T))};Array.prototype.nonNullMap=function(T){let x=[];for(let f=0;f<this.length;f++){let m=T(this[f],f,this);if(m!=null)x.push(m)}return x};Array.prototype.nonNullMapAsync=async function(T){let x=[];for(let f=0;f<this.length;f++){let m=await T(this[f],f,this);if(m!=null)x.push(m)}return x};Array.prototype.mergeAll=function(T){let x={};for(let f of this.slice().reverse())Object.merge(f,x,T);return x};Array.prototype.toObject=function(T,x){return Object.fromEntries(this.map((f)=>{let m=T(f),U=x?x(f):f;return[m,U]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((x)=>[String(x[T]),x]))};Array.prototype.selectFor=function(T,x,f,m){let U=this.find(T,m);if(U===void 0)throw Error(f??"Element not found");return x(U)};Array.prototype.sortBy=function(T,x=!0){return this.slice().sort((f,m)=>{let U=T(f),b=T(m);if(U<b)return x?-1:1;if(U>b)return x?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(T){let x=new Set;return this.filter((f)=>{let m=T(f);if(x.has(m))return!1;else return x.add(m),!0})};var w;((O)=>{O[O.Explore=0]="Explore";O[O.SkipSiblings=1]="SkipSiblings";O[O.NoExplore=2]="NoExplore";O[O.ReplaceParent=3]="ReplaceParent";O[O.DeleteParent=4]="DeleteParent";O[O.MergeParent=5]="MergeParent";O[O.ReplaceItem=6]="ReplaceItem";O[O.DeleteItem=7]="DeleteItem"})(w||={});class F{action;by;skipSiblings;reexplore;constructor(T,x,f,m){this.action=T;this.by=x;this.skipSiblings=f;this.reexplore=m}static _explore=new F(0);static _noExplore=new F(2);static _skipSiblings=new F(1);static _deleteParent=new F(4);static ReplaceParent(T,x){return new F(3,T,void 0,x)}static SkipSiblings(){return F._skipSiblings}static Explore(){return F._explore}static NoExplore(){return F._noExplore}static DeleteParent(){return F._deleteParent}static MergeParent(T){return new F(5,T)}static ReplaceItem(T,x){return new F(6,T,x)}static DeleteItem(T){return new F(7,void 0,T)}}Object.navigate=async(T,x)=>{let f=new WeakSet,m=[],U=[],b=async(E,O,$)=>{let j=E===null,B=j?F.Explore():await x({key:E,value:O,path:m,parent:$,parents:U});if(O&&typeof O==="object"&&B.action===0){if(f.has(O))return B;if(f.add(O),!j)m.push(E),U.push($);let X=O;while(await A(X,E,$))X=$[E];if(!j)U.pop(),m.pop()}return B},A=async(E,O,$)=>{let j=Object.keys(E),K=j.length;for(let B=0;B<K;B++){let Y=j[B],G=E[Y],X=await b(Y,G,E),Z=X.action;if(Z===0||Z===2)continue;if(Z===6){if(E[Y]=X.by,X.skipSiblings)return;continue}if(Z===7){if(delete E[Y],X.skipSiblings)return;continue}if(Z===1)return;if(Z===3){if(O===null)throw Error("Cannot replace root object");if($[O]=X.by,X.reexplore)return!0;return}if(Z===4){if(O===null)throw Error("Cannot delete root object");delete $[O];return}if(Z===5)delete E[Y],Object.assign(E,X.by)}};await b(null,T,null)};Object.find=async function(T,x){let f=[];return await Object.navigate(T,(m)=>{if(x([...m.path,m.key].join("."),m.value))f.push(m.value);return F.Explore()}),f};Object.merge=(T,x,f)=>{for(let m of Object.keys(x)){if(T[m]===void 0)continue;let U=x[m],b=T[m];if(typeof b!==typeof U||Array.isArray(b)!==Array.isArray(U)){let E=f?.mismatch?.(m,b,U,T,x);if(E!==void 0){x[m]=E;continue}throw Error(`Type mismatch: ${m}`)}let A=f?.mode?.(m,b,U,T,x)??x[".merge"]??"merge";switch(A){case"source":x[m]=b;continue;case"target":continue;case"skip":delete x[m],delete T[m];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${A}`)}if(typeof b==="object")if(Array.isArray(b))U.push(...b);else{if(f?.navigate?.(m,b,U,T,x)===!1)continue;Object.merge(b,U,f)}else{if(b===U)continue;let E=f?.conflict?.(m,b,U,T,x);x[m]=E===void 0?U:E}}for(let m of Object.keys(T))if(x[m]===void 0)x[m]=T[m]};var L=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,V=/^([^[\]]*)\[([^\]]*)]$/,J=(T,x,f,m)=>{if(T.startsWith("{")&&T.endsWith("}")){let U=T.substring(1,T.length-1);return Object.select(x,U,f)?.toString()}return m?T:void 0},P=(T,x,f,m)=>{let U=J(x,f,m);if(U)return Object.select(T,U,m);let b=L.exec(x);if(b){let[,E,O,$]=b,j=J(E.trim(),f,m,!0),K=J($.trim(),f,m,!0);if(Array.isArray(T)&&(O==="="||O==="==")&&j)return T.find((B)=>B?.[j]==K)}let A=V.exec(x);if(A){let[,E,O]=A;return T?.[E]?.[O]}return T?.[x]};Object.select=(T,x,f)=>{let m=void 0,U=void 0,b=x??"",A=(K)=>{if(!K)return[K,!1];return K.endsWith("?")?[K.substring(0,K.length-1),!0]:[K,!1]},E=(K,B)=>{let[Y,G]=A(B.pop());if(!Y){if(f?.set!==void 0&&U!==void 0&&m!==void 0)m[U]=f.set;return K}let X=P(K,Y,T,f);if(X===void 0){if(G||f?.optional||f?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${Y}" in "${b}"`)}return m=K,U=Y,E(X,B)},O=b.splitNested(f?.separator??".","{","}"),$=void 0;if(O.length>0&&O[O.length-1].startsWith("?="))$=O.pop()?.substring(2);O.reverse();let j=E(T,O);if(j===void 0)return $??f?.defaultValue;return j};Object.deepClone=function(T){if(typeof structuredClone<"u")try{return structuredClone(T)}catch{}return JSON.parse(JSON.stringify(T))};Object.toList=function(T,x){return Object.entries(T).map(([f,m])=>({[x]:f,...m}))};Object.mapEntries=function(T,x){let m=Object.entries(T).map(([U,b])=>x(U,b));return Object.fromEntries(m)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(T,x="Value is undefined")=>{if(T===void 0||T===null)throw Error(x);return T};String.prototype.tokenize=function(T,x=/\${([^}]+)}/g){return this.replace(x,(f,m)=>{let U=T[m];if(U===null||U===void 0)return"";if(typeof U==="string")return U;if(typeof U==="number"||typeof U==="boolean")return String(U);return String(U)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(T,x)=>x.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(T,x)=>x.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(T,x)=>x.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(T){switch(T){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${T}`)}};String.prototype.splitWithQuotes=function(T=","){let x=[],f=this.length,m=T.length,U=0,b=(A)=>{if(A+m>f)return!1;for(let E=0;E<m;E++)if(this[A+E]!==T[E])return!1;return!0};while(U<f){while(U<f&&this[U]===" ")U++;if(U>=f)break;let A="",E=this[U]==='"'||this[U]==="'";if(E){let O=this[U++];while(U<f&&this[U]!==O)A+=this[U++];if(U<f)U++}else{while(U<f&&!b(U)){let O=this[U];if(O==='"'||O==="'"){A+=O,U++;while(U<f&&this[U]!==O)A+=this[U++];if(U<f)A+=this[U++]}else A+=this[U++]}A=A.trim()}if(A)x.push({value:A,quoted:E});if(b(U))U+=m}return x};String.prototype.splitNested=function(T,x,f){let m=0,U="",b=[];for(let A of this){if(U+=A,A===x)m++;if(A===f)m--;if(m===0&&A===T)b.push(U.slice(0,-1)),U=""}if(U)b.push(U);return b};String.prototype.toStringBuilder=function(){return new C(this.split(`
|
|
2
|
+
`))};String.prototype.padBlock=function(T,x=`
|
|
3
|
+
`,f=" "){let m=f.repeat(T);return this.split(x).map((U)=>m+U).join(x)};String.prototype.stripIndent=function(){let T=this.split(/\r?\n/),x=T.filter((m)=>m.trim().length>0).map((m)=>/^[ \t]*/.exec(m)?.[0].length??0),f=x.length>0?Math.min(...x):0;if(f===0)return this;return T.map((m)=>m.slice(f)).join(`
|
|
4
|
+
`)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};String.prototype.toRgb=function(){let T=this.toString().replace("#","");if(T.length!==6)throw Error("Invalid hex color");let x=parseInt(T.substring(0,2),16),f=parseInt(T.substring(2,4),16),m=parseInt(T.substring(4,6),16);return`rgb(${x.toString()}, ${f.toString()}, ${m.toString()})`};String.prototype.toArgb=function(){let T=this.toString().replace("#","");if(T.length!==8)throw Error("Invalid hex color");let x=parseInt(T.substring(0,2),16),f=parseInt(T.substring(2,4),16),m=parseInt(T.substring(4,6),16),U=parseInt(T.substring(6,8),16);return`argb(${x.toString()}, ${f.toString()}, ${m.toString()}, ${U.toString()})`};String.prototype.single=function(T){return this.replaceAll(new RegExp(`(${T})+`,"g"),"$1")};String.prototype.remove=function(T){return this.replaceAll(new RegExp(T,"g"),"")};String.prototype.toAlphanum=function(){return this.replace(/[^a-z0-9]/gi,"")};String.prototype.toAlpha=function(){return this.replace(/[^a-z]/gi,"")};class R{options;constructor(T){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(x,...f)=>{switch(x){case"ERROR":console.error(...f);break;case"WARN":console.warn(...f);break;case"DEBUG":console.debug(...f);break;case"VERBOSE":console.log(...f);break;default:console.log(...f)}},...T}}write(T,...x){if(this.options.level){let U=this.options.levels.indexOf(this.options.level),b=this.options.levels.indexOf(T);if(U===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(b===-1)throw Error(`Unknown log level: ${T}`);if(b<U)return}let f=[],m=[];if(this.options.timeStamp)m.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)m.push(T);if(m.length>0)f.push(`[${m.join(" ")}]`);f.push(...x),this.options.logFunction(T,...f)}info(...T){this.write("INFO",...T)}error(...T){this.write("ERROR",...T)}warn(...T){this.write("WARN",...T)}debug(...T){this.write("DEBUG",...T)}verbose(...T){this.write("VERBOSE",...T)}}class C{#T=[];#x=0;options;constructor(T,x){if(T instanceof C)this.options={...T.options,...x},this.#T.push(...T.#T);else if(this.options=x??{},T)if(Array.isArray(T))this.#T.push(...T);else this.#T.push(T)}setOptions(T){return this.options=T,this}clear(){return this.#T.length=0,this}isEmpty(){return this.#T.length===0}toString(){return this.#T.join("")}indent(){return this.#x+=1,this}dedent(){if(this.#x>0)this.#x-=1;return this}getCurrentIndent(){return this.#x}getLines(){return this.toString().split(`
|
|
5
|
+
`)}formatLine(T){T??=`
|
|
6
|
+
`;let x=(this.options.indentChar??" ").repeat(this.#x*(this.options.indentSize??2));if(this.options.trim)T=T.trim();return x+(this.options.linePrefix??"")+T+(this.options.lineSuffix??"")+(this.options.lineSeparator??`
|
|
7
|
+
`)}write(...T){return this.#T.push(...T.flatMap((x)=>{if(x!==void 0){if(typeof x==="string")return x;if(Array.isArray(x))return x.flat();if(x instanceof C)return x.toString();if(typeof x==="function")return x(this);return String(x)}}).filter((x)=>x!==void 0)),this}writeLine(...T){return this.write(T.length>0?T.map((x)=>this.formatLine(x)):`
|
|
8
|
+
`)}writeMap(T,x){return T.forEach((f,m)=>x(f,m,this)),this}}class S extends C{#T=0;#x="```";#f(T){return Math.min(6,Math.max(1,Math.floor(T)))}#m(T){if(T===void 0)return"```";let x=0;for(let f of T.matchAll(/`+/g))x=Math.max(x,f[0].length);return"`".repeat(Math.max(3,x+1))}header(T,x=1){let f=this.#f(x);return this.writeLine(`${"#".repeat(f)} ${T}`,"")}codeBlock(T,x){let f=this.#m(T);if(this.#x=f,x??="",this.writeLine(f+x),T!==void 0)this.writeLine(T).endCodeBlock();return this}endCodeBlock(){let T=this.#x;return this.#x="```",this.writeLine(T)}link(T,x,f){if(f)return this.write(`[${T}](${x} "${f}")`);return this.write(`[${T}](${x})`)}table(T,x){if(T.length===0)throw Error("Table requires at least one header");let f=T.map((b,A)=>{let E=b.length;return x.forEach((O)=>{if(O[A])E=Math.max(E,O[A].length)}),E}),m=T.map((b,A)=>b.padEnd(f[A]));this.writeLine("| "+m.join(" | ")+" |");let U=f.map((b)=>"-".repeat(b));return this.writeLine("| "+U.join(" | ")+" |"),x.forEach((b)=>{let A=T.map((E,O)=>(b[O]??"").padEnd(f[O]));this.writeLine("| "+A.join(" | ")+" |")}),this}blockquote(T){return T.split(`
|
|
9
|
+
`).forEach((f)=>this.writeLine("> "+f)),this}bold(T){return this.write(`**${T}**`)}italic(T){return this.write(`*${T}*`)}item(T){return this.writeLine(`- ${T}`)}items(T){if(Array.isArray(T))T.forEach((x)=>this.item(x));else Object.entries(T).forEach(([x,f])=>f!==void 0&&this.item(`${x}: ${f!==void 0?String(f):""}`));return this}orderedList(T,x=1){return T.forEach((f,m)=>this.writeLine(`${(m+x).toString()}. ${f}`)),this}code(T){return this.write(`\`${T}\``)}horizontalRule(){return this.writeLine("---")}image(T,x){return this.writeLine(``)}strikethrough(T){return this.write(`~~${T}~~`)}highlight(T){return this.write(`==${T}==`)}subscript(T){return this.write(`~${T}~`)}superscript(T){return this.write(`^${T}^`)}taskList(T){return T.forEach((x)=>this.writeLine(`- [${x.checked?"x":" "}] ${x.text}`)),this}section(T,x){if(x!==void 0)this.#T=this.#f(x);else this.#T=Math.min(6,this.#T+1);return this.header(T,this.#T)}endSection(){if(this.#T>0)this.#T--;return this}setSectionLevel(T){return this.#T=Math.min(6,Math.max(0,Math.floor(T))),this}}import H from"fs/promises";var z=async(T)=>{try{return await H.access(T,H.constants.R_OK),!0}catch{return!1}};import Q from"path";var M=async(T,x)=>{let f=!Q.isAbsolute(T)&&x?["",...x]:[""];for(let m of f){let U=Q.join(m,T);if(await z(U))return Q.resolve(U)}throw Error(`File not found: "${T}"`)};import k from"fs/promises";import d from"path";var N=(T,x)=>x?.some((f)=>new RegExp(f).test(T))===!0,hT=async(T,x)=>{let f=await M(T,x?.dirs),m=await k.readFile(f,"utf-8"),U=d.dirname(f),b={text:{fn:(O)=>O,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...x?.parsers},A=x?.format?b[x.format]:Object.values(b).find((O)=>N(T,O.matching));if(!A)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await A.fn(m),fullPath:f,folderPath:U}};import h from"fs/promises";var g=(T,x)=>x?.some((f)=>new RegExp(f).test(T))===!0,D=async(T,x,f)=>{let m={text:{fn:(b)=>b,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...f?.encoders},U=f?.format?m[f.format]:Object.values(m).find((b)=>g(T,b.matching));if(!U)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await h.writeFile(T,await U.fn(x))};import r from"fs/promises";var uT=async(T,x)=>{if(typeof T==="string"&&!T.includes("*"))return await x.map(T,0,[]);let f=await Array.fromAsync(r.glob(T,{cwd:x.cwd})),m=x.filter?f.filter(x.filter):f;return await Promise.all(m.map(x.map))};import y from"fs/promises";import I from"path";var lT=async(T,x)=>{if(x?.targetDirectory&&x?.removeFirst)try{await y.rm(x?.targetDirectory,{recursive:!0,force:!0})}catch(f){throw Error(`Failed to clean the output directory: ${f.message}`,{cause:f})}for(let f of T)await v(f,x)},v=async(T,x)=>{let f=I.join(x?.targetDirectory??".",T.name),m=I.dirname(f);if(x?.classes){if(T.class!==void 0&&!x.classes.includes(T.class))return;if(x.classRequired&&T.class===void 0)throw Error(`Output "${T.name}" is missing class field`)}if(x?.writing?.(T)===!1)return;try{await y.mkdir(m,{recursive:!0})}catch(U){throw Error(`Failed to create target directory "${m}" for output "${f}": ${U.message}`,{cause:U})}try{await D(f,T.value,{format:T.type??"text"})}catch(U){throw Error(`Failed to write output "${f}": ${U.message}`,{cause:U})}};import p from"fs/promises";import _ from"path";import W from"path";var q=(T)=>T?W.isAbsolute(T)?T:W.join(process.cwd(),T):process.cwd();var u=async(T,x)=>{let f=[];for(let m of T)try{let U=!_.isAbsolute(m)?_.join(q(x?.cwd),m):m;if(x?.filter?.(U)===!1)continue;let b=await import(U);if(x?.resolveDefault==="only"&&!b.default)throw Error(`Module ${m} does not have a default export`);let A=x?.resolveDefault?b.default??b:b,E=x?.map?await x.map(A,m):A;if(E!==void 0)f.push(E)}catch(U){if(x?.fail?.(m,U)===!1)continue;throw Error(`Failed to import module ${m}: ${U.message??U}`,{cause:U})}return f},fx=async(T,x)=>{let f=[],m=q(x?.cwd);for(let U of T){let b=(await Array.fromAsync(p.glob(U,{cwd:m}))).map((A)=>_.join(m,A));f.push(...await u(b,x))}return f};export{lT as writeOutputs,v as writeOutput,D as writeFormat,M as locate,hT as loadFormat,u as importList,fx as importGlob,uT as globMap,q as getCwd,z as exists,C as StringBuilder,F as NavigateResult,w as NavigateAction,S as Markdown,R as Logger};
|