depflow 3.0.0-dev.10 → 3.0.0-dev.12
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/README.md +513 -117
- package/dist/builder/Builder.d.ts +279 -0
- package/dist/builder/Builder.js +391 -0
- package/dist/builder/Builder.js.map +1 -0
- package/dist/cli/Actions.d.ts +187 -0
- package/dist/cli/Actions.js +793 -0
- package/dist/cli/Actions.js.map +1 -0
- package/dist/cli/CLI.d.ts +170 -0
- package/dist/cli/CLI.js +231 -0
- package/dist/cli/CLI.js.map +1 -0
- package/dist/cli/DepflowCLI.d.ts +62 -0
- package/dist/cli/DepflowCLI.js +229 -0
- package/dist/cli/DepflowCLI.js.map +1 -0
- package/dist/cli/Flags.d.ts +106 -0
- package/dist/cli/Flags.js +125 -0
- package/dist/cli/Flags.js.map +1 -0
- package/dist/cli/bin.js +63 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/config/Config.d.ts +690 -0
- package/dist/config/Config.js +45 -0
- package/dist/config/Config.js.map +1 -0
- package/dist/config/ImportMap.d.ts +60 -0
- package/dist/config/ImportMap.js +66 -0
- package/dist/config/ImportMap.js.map +1 -0
- package/dist/config/JsonSchema.d.ts +12 -0
- package/dist/config/JsonSchema.js +26 -0
- package/dist/config/JsonSchema.js.map +1 -0
- package/dist/config/Settings.d.ts +201 -0
- package/dist/config/Settings.js +191 -0
- package/dist/config/Settings.js.map +1 -0
- package/dist/config/TSConfig.d.ts +73 -0
- package/dist/config/TSConfig.js +73 -0
- package/dist/config/TSConfig.js.map +1 -0
- package/dist/config/codecs/JsonCodec.d.ts +30 -0
- package/dist/config/codecs/JsonCodec.js +31 -0
- package/dist/config/codecs/JsonCodec.js.map +1 -0
- package/dist/config/codecs/YamlCodec.d.ts +62 -0
- package/dist/config/codecs/YamlCodec.js +89 -0
- package/dist/config/codecs/YamlCodec.js.map +1 -0
- package/dist/dependency/DepUtils.d.ts +78 -0
- package/dist/dependency/DepUtils.js +122 -0
- package/dist/dependency/DepUtils.js.map +1 -0
- package/dist/dependency/Dependency.d.ts +81 -0
- package/dist/dependency/Dependency.js +71 -0
- package/dist/dependency/Dependency.js.map +1 -0
- package/dist/dependency/Git.d.ts +75 -0
- package/dist/dependency/Git.js +97 -0
- package/dist/dependency/Git.js.map +1 -0
- package/dist/dependency/GitDependency.d.ts +30 -0
- package/dist/dependency/GitDependency.js +79 -0
- package/dist/dependency/GitDependency.js.map +1 -0
- package/dist/dependency/NpmDependency.d.ts +27 -0
- package/dist/dependency/NpmDependency.js +91 -0
- package/dist/dependency/NpmDependency.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.d.ts +18 -5
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.js +31 -9
- package/dist/resolve/AliasCompiler.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/PathResolver.d.ts +25 -8
- package/dist/resolve/PathResolver.js +133 -0
- package/dist/resolve/PathResolver.js.map +1 -0
- package/dist/resolve/PathRewriter.d.ts +24 -0
- package/{build/support/PathResolver → dist/resolve}/PathRewriter.js +21 -11
- package/dist/resolve/PathRewriter.js.map +1 -0
- package/{build → dist}/schema/Config/Builder.d.ts +114 -49
- package/dist/schema/Config/Builder.js +78 -0
- package/dist/schema/Config/Builder.js.map +1 -0
- package/{build → dist}/schema/Config/Config.d.ts +169 -78
- package/dist/schema/Config/Config.js +62 -0
- package/dist/schema/Config/Config.js.map +1 -0
- package/{build → dist}/schema/Config/Dependency.d.ts +219 -89
- package/dist/schema/Config/Dependency.js +80 -0
- package/dist/schema/Config/Dependency.js.map +1 -0
- package/{build → dist}/schema/Config/Extractor.d.ts +41 -17
- package/dist/schema/Config/Extractor.js +43 -0
- package/dist/schema/Config/Extractor.js.map +1 -0
- package/{build → dist}/schema/Config/Resolver.d.ts +25 -8
- package/dist/schema/Config/Resolver.js +43 -0
- package/dist/schema/Config/Resolver.js.map +1 -0
- package/{build → dist}/schema/Config/Transform.d.ts +22 -5
- package/dist/schema/Config/Transform.js +51 -0
- package/dist/schema/Config/Transform.js.map +1 -0
- package/dist/schema/Defaults.d.ts +20 -0
- package/dist/schema/Defaults.js +24 -0
- package/dist/schema/Defaults.js.map +1 -0
- package/dist/schema/ImportMap.d.ts +30 -0
- package/dist/schema/ImportMap.js +28 -0
- package/dist/schema/ImportMap.js.map +1 -0
- package/{build → dist}/schema/TSConfig.d.ts +23 -9
- package/dist/schema/TSConfig.js +39 -0
- package/dist/schema/TSConfig.js.map +1 -0
- package/{build → dist}/schema/schema.d.ts +11 -2
- package/{build → dist}/schema/schema.js +11 -2
- package/dist/schema/schema.js.map +1 -0
- package/dist/task/Command.d.ts +287 -0
- package/dist/task/Command.js +404 -0
- package/dist/task/Command.js.map +1 -0
- package/dist/task/Group.d.ts +15 -0
- package/dist/task/Group.js +29 -0
- package/dist/task/Group.js.map +1 -0
- package/dist/task/OutputPolicy.d.ts +262 -0
- package/dist/task/OutputPolicy.js +364 -0
- package/dist/task/OutputPolicy.js.map +1 -0
- package/dist/task/Task.d.ts +210 -0
- package/dist/task/Task.js +312 -0
- package/dist/task/Task.js.map +1 -0
- package/package.json +14 -10
- package/.gitignore +0 -7
- package/build/cli/DepFLowCLI.d.ts +0 -16
- package/build/cli/DepFLowCLI.js +0 -254
- package/build/cli/DepFLowCLI.js.map +0 -1
- package/build/cli/bin.js +0 -38
- package/build/cli/bin.js.map +0 -1
- package/build/config/Config.d.ts +0 -28
- package/build/config/Config.js +0 -46
- package/build/config/Config.js.map +0 -1
- package/build/config/ImportMap.d.ts +0 -51
- package/build/config/ImportMap.js +0 -97
- package/build/config/ImportMap.js.map +0 -1
- package/build/config/TSConfig.d.ts +0 -54
- package/build/config/TSConfig.js +0 -104
- package/build/config/TSConfig.js.map +0 -1
- package/build/schema/Config/Builder.js +0 -48
- package/build/schema/Config/Builder.js.map +0 -1
- package/build/schema/Config/Config.js +0 -20
- package/build/schema/Config/Config.js.map +0 -1
- package/build/schema/Config/Dependency.js +0 -25
- package/build/schema/Config/Dependency.js.map +0 -1
- package/build/schema/Config/Extractor.js +0 -25
- package/build/schema/Config/Extractor.js.map +0 -1
- package/build/schema/Config/Resolver.js +0 -25
- package/build/schema/Config/Resolver.js.map +0 -1
- package/build/schema/Config/Transform.js +0 -27
- package/build/schema/Config/Transform.js.map +0 -1
- package/build/schema/ImportMap.d.ts +0 -22
- package/build/schema/ImportMap.js +0 -12
- package/build/schema/ImportMap.js.map +0 -1
- package/build/schema/TSConfig.js +0 -19
- package/build/schema/TSConfig.js.map +0 -1
- package/build/schema/schema.js.map +0 -1
- package/build/support/Builder/Builder.d.ts +0 -46
- package/build/support/Builder/Builder.js +0 -116
- package/build/support/Builder/Builder.js.map +0 -1
- package/build/support/Dependency/Dependency.d.ts +0 -38
- package/build/support/Dependency/Dependency.js +0 -14
- package/build/support/Dependency/Dependency.js.map +0 -1
- package/build/support/Dependency/GitDependency.d.ts +0 -20
- package/build/support/Dependency/GitDependency.js +0 -67
- package/build/support/Dependency/GitDependency.js.map +0 -1
- package/build/support/Dependency/NpmDependency.d.ts +0 -18
- package/build/support/Dependency/NpmDependency.js +0 -65
- package/build/support/Dependency/NpmDependency.js.map +0 -1
- package/build/support/Git.d.ts +0 -53
- package/build/support/Git.js +0 -86
- package/build/support/Git.js.map +0 -1
- package/build/support/PathResolver/AliasCompiler.js.map +0 -1
- package/build/support/PathResolver/PathResolver.js +0 -105
- package/build/support/PathResolver/PathResolver.js.map +0 -1
- package/build/support/PathResolver/PathRewriter.d.ts +0 -18
- package/build/support/PathResolver/PathRewriter.js.map +0 -1
- package/build/support/PathResolver/Utils.d.ts +0 -36
- package/build/support/PathResolver/Utils.js +0 -45
- package/build/support/PathResolver/Utils.js.map +0 -1
- package/build/support/Task/Command.d.ts +0 -49
- package/build/support/Task/Command.js +0 -100
- package/build/support/Task/Command.js.map +0 -1
- package/build/support/Task/Task.d.ts +0 -84
- package/build/support/Task/Task.js +0 -145
- package/build/support/Task/Task.js.map +0 -1
- package/build/support/Utils.d.ts +0 -40
- package/build/support/Utils.js +0 -138
- package/build/support/Utils.js.map +0 -1
- package/build/support/Validator.d.ts +0 -22
- package/build/support/Validator.js +0 -28
- package/build/support/Validator.js.map +0 -1
- /package/{build → dist}/cli/bin.d.ts +0 -0
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { Events } from "@netfeez/common";
|
|
3
|
-
export class Command extends Events {
|
|
4
|
-
shell;
|
|
5
|
-
command;
|
|
6
|
-
activeListeners = null;
|
|
7
|
-
constructor(shell, command) {
|
|
8
|
-
super();
|
|
9
|
-
this.shell = shell;
|
|
10
|
-
this.command = command;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Executes a command using the provided shell instance, returning a promise that resolves with the command's output, execution time, and success status.
|
|
14
|
-
* This method sets up listeners for the shell's stdout and stderr streams to capture the command's output and errors in real-time.
|
|
15
|
-
* It also handles the command's completion by listening for a specific marker in the output, allowing it to determine when the command has finished executing and to capture its exit status.
|
|
16
|
-
* The method ensures that all listeners are properly cleaned up after execution to prevent memory leaks and unintended side effects on subsequent commands executed with the same shell instance.
|
|
17
|
-
*/
|
|
18
|
-
exec() {
|
|
19
|
-
const marker = `__DEF_FLOW_END_${Date.now()}__`;
|
|
20
|
-
const statusKey = `__EXIT_STATUS_${Date.now()}__`;
|
|
21
|
-
let accumulator = '';
|
|
22
|
-
const isWin = process.platform === 'win32';
|
|
23
|
-
const getStatusCmd = isWin
|
|
24
|
-
? `echo ${statusKey}=%errorlevel%`
|
|
25
|
-
: `echo ${statusKey}=$?`;
|
|
26
|
-
const stdoutListener = (data) => {
|
|
27
|
-
const chunk = data.toString();
|
|
28
|
-
accumulator += chunk;
|
|
29
|
-
if (!chunk.includes(marker) && !chunk.includes(statusKey)) {
|
|
30
|
-
this.emit('log', chunk.trim());
|
|
31
|
-
}
|
|
32
|
-
if (accumulator.includes(marker)) {
|
|
33
|
-
const statusMatch = accumulator.match(new RegExp(`${statusKey}=(\\d+)`));
|
|
34
|
-
const statusCode = statusMatch ? parseInt(statusMatch[1]) : 0;
|
|
35
|
-
this.cleanup();
|
|
36
|
-
const msg = accumulator.replace(getStatusCmd, '').replace(marker, '').trim();
|
|
37
|
-
this.emit('end', statusCode, msg);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const stderrListener = (data) => {
|
|
41
|
-
const msg = data.toString().trim();
|
|
42
|
-
if (msg)
|
|
43
|
-
this.emit('err', msg);
|
|
44
|
-
};
|
|
45
|
-
this.activeListeners = { stdout: stdoutListener, stderr: stderrListener };
|
|
46
|
-
this.shell.stdout.on('data', stdoutListener);
|
|
47
|
-
this.shell.stderr.on('data', stderrListener);
|
|
48
|
-
this.shell.once('error', (error) => {
|
|
49
|
-
this.cleanup();
|
|
50
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
51
|
-
this.emit('err', `Fatal Shell Error: ${errorMsg}`);
|
|
52
|
-
this.emit('end', -1, errorMsg);
|
|
53
|
-
});
|
|
54
|
-
this.shell.stdin.write(`${this.command}\n`);
|
|
55
|
-
this.shell.stdin.write(`${getStatusCmd}\n`);
|
|
56
|
-
this.shell.stdin.write(`echo ${marker}\n`);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Cleans up the listeners attached to the shell's stdout and stderr streams after command execution, ensuring that no residual listeners remain that could interfere with subsequent commands or cause memory leaks.
|
|
60
|
-
* This method is called after a command finishes executing, regardless of whether it succeeded or failed, to ensure that the TaskManager can safely execute new commands without unintended side effects from previous listeners.
|
|
61
|
-
* It checks if there are active listeners and, if so, removes them from the shell's stdout and stderr streams before resetting the activeListeners reference to null.
|
|
62
|
-
* By centralizing the cleanup logic in this method, it promotes better resource management and helps maintain the stability and reliability of the command execution process within the TaskManager.
|
|
63
|
-
*/
|
|
64
|
-
cleanup() {
|
|
65
|
-
if (!this.activeListeners)
|
|
66
|
-
return;
|
|
67
|
-
this.shell.stdout.off('data', this.activeListeners.stdout);
|
|
68
|
-
this.shell.stderr.off('data', this.activeListeners.stderr);
|
|
69
|
-
this.activeListeners = null;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new shell instance using the appropriate shell executable based on the operating system, returning a promise that resolves with the created shell process.
|
|
73
|
-
* This method abstracts the logic for determining which shell to use (e.g., cmd.exe for Windows and bash for Unix-like systems) and handles the creation of the shell process with the necessary stdio configuration.
|
|
74
|
-
* By returning a promise, it allows callers to easily integrate shell creation into asynchronous workflows, ensuring that they can await the availability of the shell before attempting to execute commands.
|
|
75
|
-
* If the shell process fails to start, the promise will be rejected with an appropriate error message, allowing callers to handle such scenarios gracefully.
|
|
76
|
-
*/
|
|
77
|
-
static async createShell() {
|
|
78
|
-
const ac = new AbortController();
|
|
79
|
-
const shellExecutable = process.platform === 'win32' ? 'cmd.exe' : 'bash';
|
|
80
|
-
const shell = spawn(shellExecutable, { shell: false, detached: true, stdio: ['pipe', 'pipe', 'pipe'], signal: ac.signal });
|
|
81
|
-
shell.unref();
|
|
82
|
-
ac.signal.addEventListener('abort', () => {
|
|
83
|
-
if (shell.stderr)
|
|
84
|
-
shell.stderr.destroy();
|
|
85
|
-
if (shell.stdout)
|
|
86
|
-
shell.stdout.destroy();
|
|
87
|
-
if (shell.stdin)
|
|
88
|
-
shell.stdin.destroy();
|
|
89
|
-
if (process.platform !== 'win32' && shell.pid) {
|
|
90
|
-
try {
|
|
91
|
-
process.kill(-shell.pid, 'SIGKILL');
|
|
92
|
-
}
|
|
93
|
-
catch (e) { }
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return { shell, abort: (reason) => ac.abort(reason) };
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export default Command;
|
|
100
|
-
//# sourceMappingURL=Command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/support/Task/Command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,EAAE,MAAM,oB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M;gBAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,MAAM;gBAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,KAAK;gBAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACvC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;gBAC5C,IAAI,CAAC;oBAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;gBAAC,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;YAC7D,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,MAAY,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;IAChE,CAAC;CACJ;AAmBD,eAAe,OAAO,CAAC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Events } from "@netfeez/common";
|
|
2
|
-
import Command from "./Command.js";
|
|
3
|
-
export declare class Task extends Events<Task.EventMap> implements Task.FinishData {
|
|
4
|
-
protected readonly cwd: string;
|
|
5
|
-
protected readonly commands: string[];
|
|
6
|
-
protected vResults: Task.commandResult[];
|
|
7
|
-
protected vFails: number;
|
|
8
|
-
protected vSuccesses: number;
|
|
9
|
-
protected vCurrentStep: number;
|
|
10
|
-
protected vTotalTime: number;
|
|
11
|
-
protected vIsFinished: boolean;
|
|
12
|
-
protected vIsRunning: boolean;
|
|
13
|
-
protected shellComponents: Command.ShellComponents | null;
|
|
14
|
-
constructor(cwd: string, commands: string[]);
|
|
15
|
-
get currentStep(): number;
|
|
16
|
-
get isFinished(): boolean;
|
|
17
|
-
get completes(): number;
|
|
18
|
-
get totalTime(): number;
|
|
19
|
-
get successes(): number;
|
|
20
|
-
get results(): Task.commandResult[];
|
|
21
|
-
get errors(): string[];
|
|
22
|
-
get fails(): number;
|
|
23
|
-
/**
|
|
24
|
-
* Stops the execution of the task immediately, aborting any active command and marking the task as finished.
|
|
25
|
-
* It emits a 'finish' event with the current summary data, allowing consumers of the Task class to access the results and errors collected up to the point of stopping.
|
|
26
|
-
* This method is essential for providing a way to gracefully terminate a task that may be taking too long or encountering issues, ensuring that resources are properly released and that the task's state is accurately reflected as finished.
|
|
27
|
-
* It also allows for external control over the task execution, enabling users to stop the task based on certain conditions or user input without having to wait for all commands to complete.
|
|
28
|
-
* @returns void
|
|
29
|
-
*/
|
|
30
|
-
stop(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Starts the execution of the task by running each command in sequence using the provided shell instance.
|
|
33
|
-
* It captures the output and errors of each command, emitting events for each line of output, each step completion, and any errors encountered.
|
|
34
|
-
* The method also tracks the execution time for each command and compiles a summary of the task's performance once all commands have been executed.
|
|
35
|
-
* If any command fails, it continues executing the remaining commands but records the failure in the summary data.
|
|
36
|
-
* Once all commands have been processed, it emits a 'finish' event with the compiled summary data, allowing consumers of the Task class to access detailed information about the execution outcomes.
|
|
37
|
-
* @returns A promise that resolves when all commands have been executed and the 'finish' event has been emitted, providing a comprehensive summary of the task execution.
|
|
38
|
-
* @throws Will throw an error if the task has already finished or if there is no shell available to execute the commands.
|
|
39
|
-
*/
|
|
40
|
-
start(): Promise<void>;
|
|
41
|
-
protected cleanup(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Generates a summary of the task execution, including the number of completed steps, failed steps, total execution time, results, and errors.
|
|
44
|
-
* This method is called when the task finishes to compile the final data that will be emitted with the 'finish' event.
|
|
45
|
-
* It provides a comprehensive overview of the task's performance and outcomes, allowing consumers of the Task class to easily access and utilize this information for reporting, logging, or further processing.
|
|
46
|
-
* @returns An object containing the summary data of the task execution, structured according to the Task.FinishData interface.
|
|
47
|
-
*/
|
|
48
|
-
private getSummary;
|
|
49
|
-
/**
|
|
50
|
-
* Executes a single shell command in the provided child process, capturing its output and handling errors.
|
|
51
|
-
* It writes the command to the child process's stdin and listens for output on stdout and stderr.
|
|
52
|
-
* The method uses a unique marker to determine when the command has finished executing, allowing it to capture the complete output before resolving.
|
|
53
|
-
* If an error occurs during execution, it captures the error message and rejects the promise with a descriptive error.
|
|
54
|
-
* This function is essential for running individual build commands as part of the dependency installation process, providing detailed feedback on the execution of each command and ensuring that any issues are properly handled and reported.
|
|
55
|
-
* @param shell The child process in which to execute the command.
|
|
56
|
-
* @param cmd The shell command to execute.
|
|
57
|
-
* @returns A promise that resolves to an array of string messages indicating the result of the command execution, including any output captured during the process.
|
|
58
|
-
* @throws Will throw an error if the command fails to execute properly, providing details about the failed command and the associated error message.
|
|
59
|
-
*/
|
|
60
|
-
protected runCommand(shell: Command.Shell, cmd: string): Promise<Task.commandResult>;
|
|
61
|
-
}
|
|
62
|
-
export declare namespace Task {
|
|
63
|
-
type Emitter = Events.Emitter<EventMap>;
|
|
64
|
-
type InternalEmitter = Events.Emitter<EventMap>;
|
|
65
|
-
type EventMap = {
|
|
66
|
-
line: [line: string];
|
|
67
|
-
step: [result: string, step: number, time: number];
|
|
68
|
-
error: [error: string, step: number, time: number];
|
|
69
|
-
finish: [data: FinishData];
|
|
70
|
-
};
|
|
71
|
-
interface commandResult {
|
|
72
|
-
success: boolean;
|
|
73
|
-
result: string;
|
|
74
|
-
time: number;
|
|
75
|
-
}
|
|
76
|
-
interface FinishData {
|
|
77
|
-
completes: number;
|
|
78
|
-
fails: number;
|
|
79
|
-
totalTime: number;
|
|
80
|
-
results: commandResult[];
|
|
81
|
-
errors: string[];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export default Task;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { Async } from "@netfeez/common-node";
|
|
2
|
-
import { Events } from "@netfeez/common";
|
|
3
|
-
import Command from "./Command.js";
|
|
4
|
-
export class Task extends Events {
|
|
5
|
-
cwd;
|
|
6
|
-
commands;
|
|
7
|
-
vResults = [];
|
|
8
|
-
vFails = 0;
|
|
9
|
-
vSuccesses = 0;
|
|
10
|
-
vCurrentStep = 0;
|
|
11
|
-
vTotalTime = 0;
|
|
12
|
-
vIsFinished = false;
|
|
13
|
-
vIsRunning = false;
|
|
14
|
-
shellComponents = null;
|
|
15
|
-
constructor(cwd, commands) {
|
|
16
|
-
super();
|
|
17
|
-
this.cwd = cwd;
|
|
18
|
-
this.commands = commands;
|
|
19
|
-
}
|
|
20
|
-
get currentStep() { return this.vCurrentStep; }
|
|
21
|
-
get isFinished() { return this.vIsFinished; }
|
|
22
|
-
get completes() { return this.vResults.length; }
|
|
23
|
-
get totalTime() { return this.vTotalTime; }
|
|
24
|
-
get successes() { return this.vResults.filter(r => r.success).length; }
|
|
25
|
-
get results() { return this.vResults; }
|
|
26
|
-
get errors() { return this.vResults.filter(r => !r.success).map(r => r.result); }
|
|
27
|
-
get fails() { return this.vResults.filter(r => !r.success).length; }
|
|
28
|
-
/**
|
|
29
|
-
* Stops the execution of the task immediately, aborting any active command and marking the task as finished.
|
|
30
|
-
* It emits a 'finish' event with the current summary data, allowing consumers of the Task class to access the results and errors collected up to the point of stopping.
|
|
31
|
-
* This method is essential for providing a way to gracefully terminate a task that may be taking too long or encountering issues, ensuring that resources are properly released and that the task's state is accurately reflected as finished.
|
|
32
|
-
* It also allows for external control over the task execution, enabling users to stop the task based on certain conditions or user input without having to wait for all commands to complete.
|
|
33
|
-
* @returns void
|
|
34
|
-
*/
|
|
35
|
-
stop() {
|
|
36
|
-
if (this.vIsFinished)
|
|
37
|
-
return;
|
|
38
|
-
if (!this.shellComponents)
|
|
39
|
-
return;
|
|
40
|
-
this.cleanup();
|
|
41
|
-
this.vIsFinished = true;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Starts the execution of the task by running each command in sequence using the provided shell instance.
|
|
45
|
-
* It captures the output and errors of each command, emitting events for each line of output, each step completion, and any errors encountered.
|
|
46
|
-
* The method also tracks the execution time for each command and compiles a summary of the task's performance once all commands have been executed.
|
|
47
|
-
* If any command fails, it continues executing the remaining commands but records the failure in the summary data.
|
|
48
|
-
* Once all commands have been processed, it emits a 'finish' event with the compiled summary data, allowing consumers of the Task class to access detailed information about the execution outcomes.
|
|
49
|
-
* @returns A promise that resolves when all commands have been executed and the 'finish' event has been emitted, providing a comprehensive summary of the task execution.
|
|
50
|
-
* @throws Will throw an error if the task has already finished or if there is no shell available to execute the commands.
|
|
51
|
-
*/
|
|
52
|
-
async start() {
|
|
53
|
-
if (this.vIsFinished)
|
|
54
|
-
throw new Error("Task has already finished.");
|
|
55
|
-
if (this.vIsRunning)
|
|
56
|
-
throw new Error("Task is already running.");
|
|
57
|
-
this.vIsRunning = true;
|
|
58
|
-
this.shellComponents = await Command.createShell();
|
|
59
|
-
const { shell, abort } = this.shellComponents;
|
|
60
|
-
try {
|
|
61
|
-
const cdRS = await this.runCommand(shell, `cd ${this.cwd}`);
|
|
62
|
-
if (!cdRS.success)
|
|
63
|
-
throw new Error(`Failed to change directory to ${this.cwd}: ${cdRS.result}`);
|
|
64
|
-
for (const command of this.commands) {
|
|
65
|
-
if (this.vIsFinished)
|
|
66
|
-
break;
|
|
67
|
-
this.vCurrentStep += 1;
|
|
68
|
-
const result = await this.runCommand(shell, command);
|
|
69
|
-
this.vResults.push(result);
|
|
70
|
-
this.vTotalTime += result.time;
|
|
71
|
-
if (result.success)
|
|
72
|
-
this.emit('step', result.result, this.vCurrentStep, result.time);
|
|
73
|
-
else
|
|
74
|
-
this.emit('error', result.result, this.vCurrentStep, result.time);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
this.vIsFinished = true;
|
|
79
|
-
this.vIsRunning = false;
|
|
80
|
-
this.cleanup();
|
|
81
|
-
this.emit('finish', this.getSummary());
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
cleanup() {
|
|
85
|
-
if (this.shellComponents && this.vIsRunning) {
|
|
86
|
-
this.shellComponents.abort();
|
|
87
|
-
this.shellComponents = null;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.shellComponents?.shell.kill();
|
|
91
|
-
this.shellComponents = null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Generates a summary of the task execution, including the number of completed steps, failed steps, total execution time, results, and errors.
|
|
96
|
-
* This method is called when the task finishes to compile the final data that will be emitted with the 'finish' event.
|
|
97
|
-
* It provides a comprehensive overview of the task's performance and outcomes, allowing consumers of the Task class to easily access and utilize this information for reporting, logging, or further processing.
|
|
98
|
-
* @returns An object containing the summary data of the task execution, structured according to the Task.FinishData interface.
|
|
99
|
-
*/
|
|
100
|
-
getSummary() {
|
|
101
|
-
return {
|
|
102
|
-
completes: this.completes,
|
|
103
|
-
fails: this.fails,
|
|
104
|
-
totalTime: this.totalTime,
|
|
105
|
-
results: this.results,
|
|
106
|
-
errors: this.errors
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Executes a single shell command in the provided child process, capturing its output and handling errors.
|
|
111
|
-
* It writes the command to the child process's stdin and listens for output on stdout and stderr.
|
|
112
|
-
* The method uses a unique marker to determine when the command has finished executing, allowing it to capture the complete output before resolving.
|
|
113
|
-
* If an error occurs during execution, it captures the error message and rejects the promise with a descriptive error.
|
|
114
|
-
* This function is essential for running individual build commands as part of the dependency installation process, providing detailed feedback on the execution of each command and ensuring that any issues are properly handled and reported.
|
|
115
|
-
* @param shell The child process in which to execute the command.
|
|
116
|
-
* @param cmd The shell command to execute.
|
|
117
|
-
* @returns A promise that resolves to an array of string messages indicating the result of the command execution, including any output captured during the process.
|
|
118
|
-
* @throws Will throw an error if the command fails to execute properly, providing details about the failed command and the associated error message.
|
|
119
|
-
*/
|
|
120
|
-
async runCommand(shell, cmd) {
|
|
121
|
-
const startTime = Date.now();
|
|
122
|
-
try {
|
|
123
|
-
const result = await Async.awaitEvent((done, fail) => {
|
|
124
|
-
const command = new Command(shell, cmd);
|
|
125
|
-
command.on('log', (msg) => this.emit('line', msg));
|
|
126
|
-
command.on('err', (msg) => this.emit('line', msg));
|
|
127
|
-
command.once('end', (status, msg) => {
|
|
128
|
-
if (status === 0)
|
|
129
|
-
done(msg);
|
|
130
|
-
else
|
|
131
|
-
fail(new Error(`Command failed with status ${status}`));
|
|
132
|
-
});
|
|
133
|
-
command.exec();
|
|
134
|
-
return () => { this.stop(); };
|
|
135
|
-
});
|
|
136
|
-
return { success: true, result, time: Date.now() - startTime };
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
140
|
-
return { success: false, result: errorMsg, time: Date.now() - startTime };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export default Task;
|
|
145
|
-
//# sourceMappingURL=Task.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Task.js","sourceRoot":"","sources":["../../../src/support/Task/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,OAAO,IAAK,SAAQ,MAAqB;IAcpB;IACA;IAdb,QAAQ,GAAyB,EAAE,CAAC;IAEpC,MAAM,GAAW,CAAC,CAAC;IACnB,UAAU,GAAW,CAAC,CAAC;IACvB,YAAY,GAAW,CAAC,CAAC;IACzB,UAAU,GAAW,CAAC,CAAC;IAEvB,WAAW,GAAY,KAAK,CAAC;IAC7B,UAAU,GAAY,KAAK,CAAC;IAE5B,eAAe,GAAmC,IAAI,CAAC;IAEjE,YACuB,GAAW,EACX,QAAkB;QACrC,KAAK,EAAE,CAAC;QAFW,QAAG,GAAH,GAAG,CAAQ;QACX,aAAQ,GAAR,QAAQ,CAAU;IAC5B,CAAC;IAEd,IAAW,WAAW,KAAa,OAAO,IAAI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C;gBAEnD,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;oBAChC,IAAI,MAAM,KAAK,CAAC;wBAAE,IAAI,CAAC,GAAG,CAAC,CAAC;;wBACvB,IAAI,CAAC,IAAI,KAAK,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC,CAAC;gBACjE,CAAC,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,EAAE,CAAC;gBACf,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;YAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACxE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;QAC9E,CAAC;IACL,CAAC;CACJ;AAwBD,eAAe,IAAI,CAAC"}
|
package/build/support/Utils.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type Grouper from '@netfeez/vterm/logger/Grouper';
|
|
2
|
-
export declare class Utils {
|
|
3
|
-
protected static REPO_REGEX: RegExp;
|
|
4
|
-
static newGroup(color: `#${string}` | number): Grouper.Group;
|
|
5
|
-
/**
|
|
6
|
-
* Extracts a repository name from its URL.
|
|
7
|
-
* @param repo - The repository URL.
|
|
8
|
-
* @returns The repository name.
|
|
9
|
-
*/
|
|
10
|
-
static getRepoName: (repo: string) => string;
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the value(s) of a specified flag from an array of command-line arguments.
|
|
13
|
-
* @param args - The array of command-line arguments.
|
|
14
|
-
* @param flag - The flag to search for (e.g., '-p' or '--project').
|
|
15
|
-
* @param multiple - Whether to allow multiple values for the same flag.
|
|
16
|
-
* @returns An array of values associated with the specified flag.
|
|
17
|
-
*/
|
|
18
|
-
static getFlagValue(args: string[], flag: string, multiple?: boolean): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Adds JSON schema validation for a specified file in Visual Studio Code by creating or updating the settings.json file in the .vscode directory.
|
|
21
|
-
* It ensures that the provided schema object is saved locally and referenced correctly in the VSCode settings, allowing for enhanced editing support such as autocompletion and validation based on the defined schema when working with the specified file.
|
|
22
|
-
* @param flowPath The file path to which the JSON schema validation should be applied (e.g., 'depflow.json').
|
|
23
|
-
* @param schemaObject The JSON schema object that defines the structure and validation rules for the specified file.
|
|
24
|
-
* @returns A promise that resolves to true if the operation was successful, or false if an error occurred during the process.
|
|
25
|
-
*/
|
|
26
|
-
static addVscodeValidation(flowPath: string, schemaObject: object): Promise<boolean>;
|
|
27
|
-
static debounce<Args extends any[]>(fn: Utils.DebouncedFunction<Args>, delay: number): Utils.DebouncedFunction<Args>;
|
|
28
|
-
static extractFlags(args: string[]): Utils.FlagResult;
|
|
29
|
-
}
|
|
30
|
-
export declare namespace Utils {
|
|
31
|
-
interface FlagMap {
|
|
32
|
-
[flag: string]: string[];
|
|
33
|
-
}
|
|
34
|
-
interface FlagResult {
|
|
35
|
-
args: string[];
|
|
36
|
-
flags: FlagMap;
|
|
37
|
-
}
|
|
38
|
-
type DebouncedFunction<Args extends any[]> = (...args: Args) => void;
|
|
39
|
-
}
|
|
40
|
-
export default Utils;
|
package/build/support/Utils.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { File, Path } from '@netfeez/common-node';
|
|
2
|
-
export class Utils {
|
|
3
|
-
static REPO_REGEX = /^(?:https:\/\/github\.com\/([^/]+)\/([^/.]+)(?:\.git)?|git@github\.com:([^/]+)\/([^/.]+)(?:\.git)?)$/;
|
|
4
|
-
static newGroup(color) {
|
|
5
|
-
let code = '';
|
|
6
|
-
if (typeof color === 'number') {
|
|
7
|
-
code = color >= 1 && color <= 7 ? `C${color}` : 'R';
|
|
8
|
-
}
|
|
9
|
-
else if (typeof color === 'string' && /^#([0-9A-Fa-f]{6})$/.test(color)) {
|
|
10
|
-
code = `C(${color})`;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
code = 'R';
|
|
14
|
-
}
|
|
15
|
-
return { open: `&N&${code}╭─`, item: `&N&${code}│ `, line: `&N&${code}├─`, stop: `&N&${code}╰─` };
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Extracts a repository name from its URL.
|
|
19
|
-
* @param repo - The repository URL.
|
|
20
|
-
* @returns The repository name.
|
|
21
|
-
*/
|
|
22
|
-
static getRepoName = (repo) => {
|
|
23
|
-
const match = repo.match(Utils.REPO_REGEX);
|
|
24
|
-
if (match) {
|
|
25
|
-
const user = match[1] || match[3];
|
|
26
|
-
const repoName = match[2] || match[4];
|
|
27
|
-
return `${user}.${repoName}`;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(`Invalid repository URL: "${repo}"`);
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Extracts the value(s) of a specified flag from an array of command-line arguments.
|
|
33
|
-
* @param args - The array of command-line arguments.
|
|
34
|
-
* @param flag - The flag to search for (e.g., '-p' or '--project').
|
|
35
|
-
* @param multiple - Whether to allow multiple values for the same flag.
|
|
36
|
-
* @returns An array of values associated with the specified flag.
|
|
37
|
-
*/
|
|
38
|
-
static getFlagValue(args, flag, multiple = false) {
|
|
39
|
-
const values = [];
|
|
40
|
-
for (const index in args) {
|
|
41
|
-
const value = args[index];
|
|
42
|
-
if (value === flag) {
|
|
43
|
-
const nextValue = args[Number(index) + 1];
|
|
44
|
-
if (nextValue && !nextValue.startsWith('-')) {
|
|
45
|
-
values.push(nextValue);
|
|
46
|
-
if (!multiple)
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return values;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Adds JSON schema validation for a specified file in Visual Studio Code by creating or updating the settings.json file in the .vscode directory.
|
|
55
|
-
* It ensures that the provided schema object is saved locally and referenced correctly in the VSCode settings, allowing for enhanced editing support such as autocompletion and validation based on the defined schema when working with the specified file.
|
|
56
|
-
* @param flowPath The file path to which the JSON schema validation should be applied (e.g., 'depflow.json').
|
|
57
|
-
* @param schemaObject The JSON schema object that defines the structure and validation rules for the specified file.
|
|
58
|
-
* @returns A promise that resolves to true if the operation was successful, or false if an error occurred during the process.
|
|
59
|
-
*/
|
|
60
|
-
static async addVscodeValidation(flowPath, schemaObject) {
|
|
61
|
-
const root = process.cwd();
|
|
62
|
-
const internalDir = Path.join(root, '.depflow');
|
|
63
|
-
const schemaLocalPath = Path.join(internalDir, 'schema.json');
|
|
64
|
-
const vscodeDir = Path.join(root, '.vscode');
|
|
65
|
-
const settingsPath = Path.join(vscodeDir, 'settings.json');
|
|
66
|
-
try {
|
|
67
|
-
if (!await File.exists(internalDir))
|
|
68
|
-
await File.mkdir(internalDir, { recursive: true });
|
|
69
|
-
await File.write(schemaLocalPath, JSON.stringify(schemaObject, null, 4));
|
|
70
|
-
if (!await File.exists(vscodeDir))
|
|
71
|
-
await File.mkdir(vscodeDir, { recursive: true });
|
|
72
|
-
let settings = {};
|
|
73
|
-
if (await File.exists(settingsPath)) {
|
|
74
|
-
try {
|
|
75
|
-
settings = JSON.parse(await File.read(settingsPath));
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
settings = {};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (!settings['json.schemas'])
|
|
82
|
-
settings['json.schemas'] = [];
|
|
83
|
-
const relativeSchema = './.depflow/schema.json';
|
|
84
|
-
const hasSchema = settings['json.schemas'].some((s) => s.fileMatch && s.fileMatch.includes(flowPath));
|
|
85
|
-
if (hasSchema)
|
|
86
|
-
return true;
|
|
87
|
-
settings['json.schemas'].push({ fileMatch: [flowPath], url: relativeSchema });
|
|
88
|
-
await File.write(settingsPath, JSON.stringify(settings, null, 4));
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
static debounce(fn, delay) {
|
|
96
|
-
let timeoutId = null;
|
|
97
|
-
return function (...args) {
|
|
98
|
-
if (timeoutId)
|
|
99
|
-
clearTimeout(timeoutId);
|
|
100
|
-
timeoutId = setTimeout(() => {
|
|
101
|
-
fn.apply(this, args);
|
|
102
|
-
timeoutId = null;
|
|
103
|
-
}, delay);
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
static extractFlags(args) {
|
|
107
|
-
const purifiedArgs = [];
|
|
108
|
-
const flags = {};
|
|
109
|
-
for (let i = 0; i < args.length; i++) {
|
|
110
|
-
const arg = args[i];
|
|
111
|
-
if (!arg.startsWith('-')) {
|
|
112
|
-
purifiedArgs.push(arg);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
let [key, value] = arg.split('=');
|
|
116
|
-
if (value !== undefined) {
|
|
117
|
-
if (!flags[key])
|
|
118
|
-
flags[key] = [];
|
|
119
|
-
flags[key].push(value);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
const nextArg = args[i + 1];
|
|
123
|
-
if (nextArg && !nextArg.startsWith('-')) {
|
|
124
|
-
if (!flags[key])
|
|
125
|
-
flags[key] = [];
|
|
126
|
-
flags[key].push(nextArg);
|
|
127
|
-
i++;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
if (!flags[key])
|
|
131
|
-
flags[key] = [];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { args: purifiedArgs, flags };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export default Utils;
|
|
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AAG,EAAE,CAAC;gBACjC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,SAAS;YACb,CAAC;YAED,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;oBAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;gBACjC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACzB,CAAC,EAAE,CAAC;YACR,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;oBAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YACrC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;;AAYL,eAAe,KAAK,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare class Validator {
|
|
2
|
-
/**
|
|
3
|
-
* Validates that the provided repository URL is a non-empty string and matches common Git repository URL patterns. It checks for both HTTPS and SSH formats, ensuring that the URL is well-formed and points to a valid Git repository.
|
|
4
|
-
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided repository URL.
|
|
5
|
-
* @param repo The repository URL to validate.
|
|
6
|
-
* @throws Will throw an error if the repository URL is invalid.
|
|
7
|
-
*/
|
|
8
|
-
static validateRepo(repo: unknown): asserts repo is Validator.Repo;
|
|
9
|
-
/**
|
|
10
|
-
* Validates that the provided name is a non-empty string.
|
|
11
|
-
* It checks if the name is of type string and contains non-whitespace characters.
|
|
12
|
-
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided name.
|
|
13
|
-
* @param name The name to validate.
|
|
14
|
-
* @throws Will throw an error if the name is invalid.
|
|
15
|
-
*/
|
|
16
|
-
static validateName(name: unknown): asserts name is Validator.name;
|
|
17
|
-
}
|
|
18
|
-
export declare namespace Validator {
|
|
19
|
-
type Repo = `https://github.com/${string}/${string}.git` | `git@github.com:${string}/${string}.git`;
|
|
20
|
-
type name = string;
|
|
21
|
-
}
|
|
22
|
-
export default Validator;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class Validator {
|
|
2
|
-
/**
|
|
3
|
-
* Validates that the provided repository URL is a non-empty string and matches common Git repository URL patterns. It checks for both HTTPS and SSH formats, ensuring that the URL is well-formed and points to a valid Git repository.
|
|
4
|
-
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided repository URL.
|
|
5
|
-
* @param repo The repository URL to validate.
|
|
6
|
-
* @throws Will throw an error if the repository URL is invalid.
|
|
7
|
-
*/
|
|
8
|
-
static validateRepo(repo) {
|
|
9
|
-
if (typeof repo !== 'string' || !repo.trim())
|
|
10
|
-
throw new Error(`Invalid repository URL: "${repo}"`);
|
|
11
|
-
const gitRegex = /^(?:(?:https?|git|ssh|rsync|file|git@[-\w.]+):(\/\/)?)([\w.@:/\-~]+)(\.git)(\/)?$/;
|
|
12
|
-
if (!gitRegex.test(repo))
|
|
13
|
-
throw new Error(`Invalid repository URL: ${repo}`);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Validates that the provided name is a non-empty string.
|
|
17
|
-
* It checks if the name is of type string and contains non-whitespace characters.
|
|
18
|
-
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided name.
|
|
19
|
-
* @param name The name to validate.
|
|
20
|
-
* @throws Will throw an error if the name is invalid.
|
|
21
|
-
*/
|
|
22
|
-
static validateName(name) {
|
|
23
|
-
if (typeof name !== 'string' || !name.trim())
|
|
24
|
-
throw new Error(`Invalid dependency name: "${name}"`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export default Validator;
|
|
28
|
-
//# sourceMappingURL=Validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../src/support/Validator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAClB;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,IAAa;QAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC;QACnG,MAAM,QAAQ,GAAG,mFAAmF,CAAC;QACrG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IACD;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,IAAa;QAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,GAAG,CAAC,CAAC;IACxG,CAAC;CACJ;AAKD,eAAe,SAAS,CAAC"}
|
|
File without changes
|