depflow 2.0.0-dev.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli/DepFLowCLI.js +10 -16
- package/build/cli/DepFLowCLI.js.map +1 -1
- package/build/cli/bin.js +0 -0
- package/build/config/schemas.d.ts +105 -56
- package/build/config/schemas.js +20 -20
- package/build/config/schemas.js.map +1 -1
- package/build/support/Async.d.ts +22 -0
- package/build/support/Async.js +62 -0
- package/build/support/Async.js.map +1 -0
- package/build/support/Dependency.d.ts +23 -41
- package/build/support/Dependency.js +65 -115
- package/build/support/Dependency.js.map +1 -1
- package/build/support/Git.d.ts +45 -28
- package/build/support/Git.js +81 -55
- package/build/support/Git.js.map +1 -1
- package/build/support/Task/Command.d.ts +49 -0
- package/build/support/Task/Command.js +100 -0
- package/build/support/Task/Command.js.map +1 -0
- package/build/support/Task/Task.d.ts +84 -0
- package/build/support/Task/Task.js +145 -0
- package/build/support/Task/Task.js.map +1 -0
- package/package.json +3 -3
- package/build/support/File.d.ts +0 -80
- package/build/support/File.js +0 -123
- package/build/support/File.js.map +0 -1
- package/build/support/PathFixer.d.ts +0 -36
- package/build/support/PathFixer.js +0 -161
- package/build/support/PathFixer.js.map +0 -1
- package/build/support/PathResolver.d.ts +0 -100
- package/build/support/PathResolver.js +0 -280
- package/build/support/PathResolver.js.map +0 -1
- package/build/support/Resolver/AliasCompiler.d.ts +0 -18
- package/build/support/Resolver/AliasCompiler.js +0 -32
- package/build/support/Resolver/AliasCompiler.js.map +0 -1
- package/build/support/Resolver/PathResolver.d.ts +0 -25
- package/build/support/Resolver/PathResolver.js +0 -79
- package/build/support/Resolver/PathResolver.js.map +0 -1
- package/build/support/Resolver/PathRewriter.d.ts +0 -10
- package/build/support/Resolver/PathRewriter.js +0 -39
- package/build/support/Resolver/PathRewriter.js.map +0 -1
- package/build/support/Resolver/Utils.d.ts +0 -36
- package/build/support/Resolver/Utils.js +0 -45
- package/build/support/Resolver/Utils.js.map +0 -1
package/build/support/Git.js
CHANGED
|
@@ -1,67 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const [cmd, ...args] = command.split(' ');
|
|
16
|
-
const process = ChildProcess.spawn(cmd, args, { shell: true });
|
|
17
|
-
let output = '';
|
|
18
|
-
let errorOutput = '';
|
|
19
|
-
process.stdout.on('data', (data) => output += data.toString());
|
|
20
|
-
process.stderr.on('data', (data) => errorOutput += data.toString());
|
|
21
|
-
process.on('error', (err) => reject(err));
|
|
22
|
-
process.on('close', (code) => {
|
|
23
|
-
if (code === 0) {
|
|
24
|
-
const result = (output + errorOutput).trim();
|
|
25
|
-
resolve(result);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const errorMessage = `Command failed with code ${code}: ${command}\n${errorOutput || output}`.trim();
|
|
29
|
-
reject(new Error(errorMessage));
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
});
|
|
1
|
+
import Task from "./Task/Task.js";
|
|
2
|
+
import Async from "./Async.js";
|
|
3
|
+
export class Git {
|
|
4
|
+
path;
|
|
5
|
+
repo;
|
|
6
|
+
logger;
|
|
7
|
+
cwd;
|
|
8
|
+
constructor(path, repo, options) {
|
|
9
|
+
this.path = path;
|
|
10
|
+
this.repo = repo;
|
|
11
|
+
const { logger, cwd } = options;
|
|
12
|
+
this.logger = logger || null;
|
|
13
|
+
this.cwd = cwd || process.cwd();
|
|
33
14
|
}
|
|
34
15
|
/**
|
|
35
|
-
* Clones a repository.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
16
|
+
* Clones a Git repository from the specified URL to the target path, optionally checking out a specific tag after cloning.
|
|
17
|
+
* The method constructs the necessary commands to perform the clone operation and optionally check out a specified tag, then initiates a Task to execute these commands sequentially.
|
|
18
|
+
* It listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
|
|
19
|
+
* Once all commands have been executed,
|
|
20
|
+
* it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
|
|
21
|
+
* @param repo The URL of the Git repository to clone.
|
|
22
|
+
* @param path The file system path where the repository should be cloned to.
|
|
23
|
+
* @param options An object containing optional parameters for the clone operation, including:
|
|
24
|
+
* - tag: An optional Git tag to check out after cloning the repository.
|
|
25
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
26
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
40
27
|
*/
|
|
41
|
-
static async clone(repo, path,
|
|
42
|
-
|
|
28
|
+
static async clone(repo, path, options) {
|
|
29
|
+
const { tag, logger, cwd = process.cwd() } = options;
|
|
30
|
+
const commands = [
|
|
31
|
+
`git clone ${repo} ${path}`,
|
|
32
|
+
`cd ${path}`,
|
|
33
|
+
];
|
|
34
|
+
if (tag)
|
|
35
|
+
commands.push(`git checkout ${tag}`);
|
|
36
|
+
await this.runTask(commands, { cwd, logger });
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
39
|
+
* Performs a 'git pull' operation on the specified repository path, optionally checking out a specific tag after pulling the latest changes.
|
|
40
|
+
* The method constructs the necessary commands to navigate to the repository path, execute the pull operation, and optionally check out a specified tag.
|
|
41
|
+
* It then initiates a Task to execute these commands sequentially, providing real-time logging and error handling through the provided Logger instance.
|
|
42
|
+
* The method listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
|
|
43
|
+
* Once all commands have been executed, it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
|
|
44
|
+
* @param path The file system path to the local Git repository where the pull operation should be performed.
|
|
45
|
+
* @param options An object containing optional parameters for the pull operation, including:
|
|
46
|
+
* - tag: An optional Git tag to check out after pulling the latest changes.
|
|
47
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
48
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
49
49
|
*/
|
|
50
|
-
static async
|
|
51
|
-
|
|
50
|
+
static async pull(path, options) {
|
|
51
|
+
const { tag, logger, cwd = process.cwd() } = options;
|
|
52
|
+
const commands = [
|
|
53
|
+
`cd ${path}`,
|
|
54
|
+
`git pull`
|
|
55
|
+
];
|
|
56
|
+
if (tag)
|
|
57
|
+
commands.push(`git checkout ${tag}`);
|
|
58
|
+
await this.runTask(commands, { cwd, logger });
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
61
|
+
* Executes a series of Git commands as a Task, providing real-time logging and error handling through the provided Logger instance.
|
|
62
|
+
* The method constructs the necessary commands based on the provided repository URL, target path, and optional tag, then initiates a Task to execute these commands sequentially.
|
|
63
|
+
* It listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
|
|
64
|
+
* Once all commands have been executed, it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
|
|
58
65
|
*/
|
|
59
|
-
static async
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
static async runTask(commands, options) {
|
|
67
|
+
const { cwd = process.cwd(), logger } = options;
|
|
68
|
+
return Async.awaitEvent((done, fail) => {
|
|
69
|
+
const task = new Task(cwd, commands);
|
|
70
|
+
if (logger) {
|
|
71
|
+
task.on('line', logger.info.bind(logger));
|
|
72
|
+
task.on('error', (msg, step) => {
|
|
73
|
+
logger.error(`&C6[Step ${step}]&C7: &C1${msg}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
task.once('finish', (summary) => {
|
|
77
|
+
if (summary.fails > 0) {
|
|
78
|
+
if (logger)
|
|
79
|
+
logger.error(`&C1Git clone completed with ${summary.fails} failed steps in ${summary.totalTime}ms.`);
|
|
80
|
+
fail(new Error(`Git clone failed with ${summary.fails} failed steps.\nErrors:\n${summary.errors.join('\n')}`));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (logger)
|
|
84
|
+
logger.info(`&C2Git clone completed successfully in ${summary.totalTime}ms with ${summary.completes} steps.`);
|
|
85
|
+
done(summary);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
task.start().catch(fail);
|
|
89
|
+
return () => { task.stop(); };
|
|
90
|
+
});
|
|
65
91
|
}
|
|
66
92
|
}
|
|
67
93
|
export default Git;
|
package/build/support/Git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Git.js","sourceRoot":"","sources":["../../src/support/Git.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Git.js","sourceRoot":"","sources":["../../src/support/Git.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAClC,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,MAAM,OAAO,GAAG;IAIE;IACA;IAJJ,MAAM,CAAgB;IACtB,GAAG,CAAS;IACtB,YACc,IAAY,EACZ,IAAY,EACtB,OAAwB;QAFd,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QAGtB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;IACD;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,K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IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1C,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;oBAC3B,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,YAAY,GAAG,EAAE,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACP,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC5B,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;oBACpB,IAAI,MAAM;wBAAE,MAAM,CAAC,KAAK,CAAC,+BAA+B,OAAO,CAAC,KAAK,oBAAoB,OAAO,CAAC,SAAS,KAAK,CAAC,CAAC;oBACjH,IAAI,CAAC,IAAI,KAAK,CAAC,yBAAyB,OAAO,CAAC,KAAK,4BAA4B,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;gBACnH,CAAC;qBAAM,CAAC;oBACJ,IAAI,MAAM;wBAAE,MAAM,CAAC,IAAI,CAAC,0CAA0C,OAAO,CAAC,SAAS,WAAW,OAAO,CAAC,SAAS,SAAS,CAAC,CAAC;oBAC1H,IAAI,CAAC,OAAO,CAAC,CAAC;gBAClB,CAAC;YACL,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzB,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAUD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
import { Events } from "@netfeez/common";
|
|
3
|
+
export declare class Command extends Events<Command.EventMap> {
|
|
4
|
+
protected shell: ChildProcessWithoutNullStreams;
|
|
5
|
+
protected command: string;
|
|
6
|
+
protected activeListeners: {
|
|
7
|
+
stdout: Command.StdOut;
|
|
8
|
+
stderr: Command.StdErr;
|
|
9
|
+
} | null;
|
|
10
|
+
constructor(shell: ChildProcessWithoutNullStreams, command: string);
|
|
11
|
+
/**
|
|
12
|
+
* Executes a command using the provided shell instance, returning a promise that resolves with the command's output, execution time, and success status.
|
|
13
|
+
* This method sets up listeners for the shell's stdout and stderr streams to capture the command's output and errors in real-time.
|
|
14
|
+
* 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.
|
|
15
|
+
* 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.
|
|
16
|
+
*/
|
|
17
|
+
exec(): void;
|
|
18
|
+
/**
|
|
19
|
+
* 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.
|
|
20
|
+
* 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.
|
|
21
|
+
* 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.
|
|
22
|
+
* 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.
|
|
23
|
+
*/
|
|
24
|
+
protected cleanup(): void;
|
|
25
|
+
/**
|
|
26
|
+
* 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.
|
|
27
|
+
* 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.
|
|
28
|
+
* 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.
|
|
29
|
+
* If the shell process fails to start, the promise will be rejected with an appropriate error message, allowing callers to handle such scenarios gracefully.
|
|
30
|
+
*/
|
|
31
|
+
static createShell(): Promise<Command.ShellComponents>;
|
|
32
|
+
}
|
|
33
|
+
export declare namespace Command {
|
|
34
|
+
type Emitter = Events.Emitter<EventMap>;
|
|
35
|
+
type StdOut = (output: Buffer) => void;
|
|
36
|
+
type StdErr = (error: Buffer) => void;
|
|
37
|
+
type Abort = (reason?: any) => void;
|
|
38
|
+
type Shell = ChildProcessWithoutNullStreams;
|
|
39
|
+
type EventMap = {
|
|
40
|
+
log: [message: string];
|
|
41
|
+
err: [message: string];
|
|
42
|
+
end: [code: number, message: string];
|
|
43
|
+
};
|
|
44
|
+
interface ShellComponents {
|
|
45
|
+
shell: Shell;
|
|
46
|
+
abort: Abort;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default Command;
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/support/Task/Command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,OAAO,OAAQ,SAAQ,MAAwB;IACvC,KAAK,CAAiC;IACtC,OAAO,CAAS;IAChB,eAAe,GAA8D,IAAI,CAAC;IAE5F,YAAmB,KAAqC,EAAE,OAAe;QAAI,KAAK,EAAE,CAAC;QACjF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IACD;;;;;MAKE;IACK,IAAI;QACP,MAAM,MAAM,GAAG,kBAAkB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;QAChD,MAAM,SAAS,GAAG,iBAAiB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;QAClD,IAAI,WAAW,GAAG,EAAE,CAAC;QAErB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;QAC3C,MAAM,YAAY,GAAG,KAAK;YACtB,CAAC,CAAC,QAAQ,SAAS,eAAe;YAClC,CAAC,CAAC,QAAQ,SAAS,KAAK,CAAC;QAE7B,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9B,WAAW,IAAI,KAAK,CAAC;YAErB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAA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C1E,MAAM,KAAK,GAAG,KAAK,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3H,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YACrC,IAAI,KAAK,CAAC,MAAM;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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Events } from "@netfeez/common";
|
|
2
|
+
import Command from "./Command.js";
|
|
3
|
+
import Async from "../Async.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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.js","sourceRoot":"","sources":["../../../src/support/Task/Task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,MAAM,OAAO,IAAK,SAAQ,MAAqB;IAcpB;IACA;IAdb,QAAQ,GAAyB,EAAE,CAAC;IAEpC,MAAM,GAAW,CAAC,CAAC;IACnB,UAAU,GAAW,CAAC,CAAC;I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
{
|
|
2
2
|
"name": "depflow",
|
|
3
3
|
"description": "is a simple dependency manager based on github repositories",
|
|
4
|
-
"version": "2.0.0
|
|
5
|
-
"main": "build/
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"main": "build/cli/DepFlowCLI.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"dep": "build/cli/bin.js"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@netfeez/common": "^
|
|
36
|
+
"@netfeez/common": "^3.0.0",
|
|
37
37
|
"@netfeez/common-node": "^1.0.1",
|
|
38
38
|
"@netfeez/vterm": "^1.0.0"
|
|
39
39
|
},
|