depflow 2.0.0-dev.1 → 2.0.0-dev.2
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/{bin → cli}/DepFLowCLI.d.ts +4 -2
- package/build/{bin → cli}/DepFLowCLI.js +60 -36
- package/build/cli/DepFLowCLI.js.map +1 -0
- package/build/{bin → cli}/bin.js +15 -4
- package/build/cli/bin.js.map +1 -0
- package/build/config/Config.d.ts +28 -0
- package/build/config/Config.js +46 -0
- package/build/config/Config.js.map +1 -0
- package/build/config/ImportMap.d.ts +38 -0
- package/build/config/ImportMap.js +83 -0
- package/build/config/ImportMap.js.map +1 -0
- package/build/config/Tsconfig.d.ts +57 -0
- package/build/config/Tsconfig.js +99 -0
- package/build/config/Tsconfig.js.map +1 -0
- package/build/config/schemas.d.ts +592 -0
- package/build/config/schemas.js +51 -0
- package/build/config/schemas.js.map +1 -0
- package/build/support/Dependency.d.ts +127 -0
- package/build/support/Dependency.js +307 -0
- package/build/support/Dependency.js.map +1 -0
- package/build/support/File.d.ts +80 -0
- package/build/support/File.js +123 -0
- package/build/support/File.js.map +1 -0
- package/build/support/Git.js.map +1 -0
- package/build/support/PathFixer.d.ts +36 -0
- package/build/support/PathFixer.js +161 -0
- package/build/support/PathFixer.js.map +1 -0
- package/build/support/PathResolver/AliasCompiler.d.ts +25 -0
- package/build/support/PathResolver/AliasCompiler.js +39 -0
- package/build/support/PathResolver/AliasCompiler.js.map +1 -0
- package/build/support/PathResolver/PathResolver.d.ts +45 -0
- package/build/support/PathResolver/PathResolver.js +99 -0
- package/build/support/PathResolver/PathResolver.js.map +1 -0
- package/build/support/PathResolver/PathRewriter.d.ts +18 -0
- package/build/support/PathResolver/PathRewriter.js +47 -0
- package/build/support/PathResolver/PathRewriter.js.map +1 -0
- package/build/support/PathResolver/Utils.d.ts +36 -0
- package/build/support/PathResolver/Utils.js +45 -0
- package/build/support/PathResolver/Utils.js.map +1 -0
- package/build/support/PathResolver.d.ts +100 -0
- package/build/support/PathResolver.js +280 -0
- package/build/support/PathResolver.js.map +1 -0
- package/build/support/Resolver/AliasCompiler.d.ts +18 -0
- package/build/support/Resolver/AliasCompiler.js +32 -0
- package/build/support/Resolver/AliasCompiler.js.map +1 -0
- package/build/support/Resolver/PathResolver.d.ts +25 -0
- package/build/support/Resolver/PathResolver.js +79 -0
- package/build/support/Resolver/PathResolver.js.map +1 -0
- package/build/support/Resolver/PathRewriter.d.ts +10 -0
- package/build/support/Resolver/PathRewriter.js +39 -0
- package/build/support/Resolver/PathRewriter.js.map +1 -0
- package/build/support/Resolver/Utils.d.ts +36 -0
- package/build/support/Resolver/Utils.js +45 -0
- package/build/support/Resolver/Utils.js.map +1 -0
- package/build/support/Utils.d.ts +30 -0
- package/build/support/Utils.js +95 -0
- package/build/support/Utils.js.map +1 -0
- package/build/support/Validator.d.ts +22 -0
- package/build/support/Validator.js +28 -0
- package/build/support/Validator.js.map +1 -0
- package/package.json +3 -2
- package/build/Config.d.ts +0 -15
- package/build/Config.js +0 -21
- package/build/Config.js.map +0 -1
- package/build/Dependency.d.ts +0 -86
- package/build/Dependency.js +0 -264
- package/build/Dependency.js.map +0 -1
- package/build/File.d.ts +0 -9
- package/build/File.js +0 -41
- package/build/File.js.map +0 -1
- package/build/Git.js.map +0 -1
- package/build/PathFixer.d.ts +0 -35
- package/build/PathFixer.js +0 -143
- package/build/PathFixer.js.map +0 -1
- package/build/Tsconfig.d.ts +0 -13
- package/build/Tsconfig.js +0 -16
- package/build/Tsconfig.js.map +0 -1
- package/build/Utils.d.ts +0 -16
- package/build/Utils.js +0 -40
- package/build/Utils.js.map +0 -1
- package/build/Validator.d.ts +0 -9
- package/build/Validator.js +0 -15
- package/build/Validator.js.map +0 -1
- package/build/bin/DepFLowCLI.js.map +0 -1
- package/build/bin/bin.d.ts +0 -2
- package/build/bin/bin.js.map +0 -1
- package/build/bin.js +0 -26
- package/build/bin.js.map +0 -1
- package/build/schemas.d.ts +0 -296
- package/build/schemas.js +0 -29
- package/build/schemas.js.map +0 -1
- /package/build/{bin.d.ts → cli/bin.d.ts} +0 -0
- /package/build/{Git.d.ts → support/Git.d.ts} +0 -0
- /package/build/{Git.js → support/Git.js} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
+
import schemas from "../config/schemas.js";
|
|
3
|
+
import Config from "../config/Config.js";
|
|
4
|
+
export declare class Dependency implements Dependency.Dependency {
|
|
5
|
+
protected readonly config: Config.Config;
|
|
6
|
+
static include: string[];
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly repo: Dependency.repo;
|
|
9
|
+
readonly branch?: string;
|
|
10
|
+
readonly builder: Dependency.Builder[];
|
|
11
|
+
readonly resolver: Dependency.Resolver[];
|
|
12
|
+
constructor(config: Config.Config, dependency: Dependency.Dependency);
|
|
13
|
+
/** Get the folder of the dependency */
|
|
14
|
+
get folder(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Clones the dependency's repository to the local file system. If the target folder already exists, it checks the 'force' option: if 'force' is false, it performs a pull to update the existing repository; if 'force' is true, it uninstalls (deletes) the existing folder before cloning.
|
|
17
|
+
* This method ensures that the local copy of the dependency is up-to-date with the remote repository, allowing for both fresh installations and updates based on user preference.
|
|
18
|
+
* @param options An object containing options for managing the dependency, such as 'force' to determine whether to overwrite existing files.
|
|
19
|
+
* @returns A promise that resolves to a string message indicating the result of the clone or pull operation.
|
|
20
|
+
* @throws Will throw an error if the cloning or pulling process fails.
|
|
21
|
+
*/
|
|
22
|
+
clone(options?: Dependency.manageOptions): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Pulls the latest changes from the dependency's repository to the local file system. It uses the Git utility to perform a pull operation on the existing local repository, ensuring that it is updated with any new commits or changes from the remote repository. This method is essential for keeping the local copy of the dependency in sync with its source, allowing for seamless updates without needing to reinstall the entire dependency.
|
|
25
|
+
* @returns A promise that resolves to a string message indicating the result of the pull operation.
|
|
26
|
+
* @throws Will throw an error if the pull process fails, such as if the local repository is not properly set up or if there are conflicts that cannot be automatically resolved.
|
|
27
|
+
*/
|
|
28
|
+
pull(): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Installs the dependency by first cloning its repository (or pulling updates if it already exists) and then executing any build steps defined in the builder property. It manages the entire installation process, including handling the cloning/pulling of the repository and running any necessary commands to set up the dependency according to its configuration. This method ensures that the dependency is properly installed and ready for use, providing feedback on each step of the process through returned messages.
|
|
31
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the cloning/pulling and building processes.
|
|
32
|
+
* @throws Will throw an error if any step of the installation process fails, such as issues with cloning, pulling, or executing build commands.
|
|
33
|
+
*/
|
|
34
|
+
install(): Promise<string[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Uninstalls the dependency by removing its local folder and any additional folders specified in the builder's move steps.
|
|
37
|
+
* It checks for the existence of each folder before attempting to remove it, ensuring that it only tries to delete valid paths.
|
|
38
|
+
* This method is crucial for cleanly removing a dependency from the local file system, allowing for a complete uninstallation that includes all related files and directories as defined by the dependency's configuration.
|
|
39
|
+
* @return A promise that resolves to an array of string messages indicating the results of the uninstallation process, such as which folders were removed.
|
|
40
|
+
* @throws Will throw an error if any issues occur during the uninstallation process, such as problems with file system access or if the specified folders cannot be removed.
|
|
41
|
+
*/
|
|
42
|
+
uninstall(): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the dependency by executing the commands specified in the builder property.
|
|
45
|
+
* It iterates through each build step, running any defined commands and handling file movements as necessary.
|
|
46
|
+
* The method uses a child process to execute shell commands, capturing the output and errors for each step.
|
|
47
|
+
* This allows for a flexible build process that can accommodate various setup requirements defined by the dependency's configuration, ensuring that the dependency is properly built and ready for use after installation.
|
|
48
|
+
* @return A promise that resolves to an array of string messages indicating the results of the build process, including any command outputs and file movements.
|
|
49
|
+
* @throws Will throw an error if any issues occur during the build process, such as command execution failures or problems with file movements.
|
|
50
|
+
*/
|
|
51
|
+
protected build(): Promise<string[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Handles the file movements defined in the builder's move steps.
|
|
54
|
+
* It supports various formats for specifying destinations, including strings, arrays, and objects with keys representing source paths.
|
|
55
|
+
* The method checks for the existence of source files or directories before attempting to move them to the specified destinations, ensuring that it only operates on valid paths.
|
|
56
|
+
* This function is essential for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
57
|
+
* @param move The move configuration from the builder, which can be a string, an array of strings, or an object mapping source paths to destination paths.
|
|
58
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the file movements, including any errors encountered during the process.
|
|
59
|
+
* @throws Will throw an error if any issues occur during the file movement process, such as missing source paths or problems with file system access.
|
|
60
|
+
*/
|
|
61
|
+
protected move(move: Dependency.Builder['move']): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Executes a series of shell commands in a child process, capturing the output and errors for each command.
|
|
64
|
+
* It writes each command to the child process's stdin and listens for output on stdout and stderr.
|
|
65
|
+
* The method uses a marker to determine when a command has finished executing, allowing it to capture the complete output for each command before proceeding to the next one.
|
|
66
|
+
* This function is crucial for running build commands defined in the dependency's configuration, providing feedback on the execution of each command and handling any errors that may arise during the process.
|
|
67
|
+
* @param commands An array of shell commands to execute.
|
|
68
|
+
* @param shell The child process in which to execute the commands.
|
|
69
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the command executions, including any output or errors captured during the process.
|
|
70
|
+
* @throws Will throw an error if any command fails to execute properly, providing details about the failed command and the associated error message.
|
|
71
|
+
*/
|
|
72
|
+
protected executeCommands(commands: string[], shell: ChildProcessWithoutNullStreams): Promise<string[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Executes a single shell command in the provided child process, capturing its output and handling errors.
|
|
75
|
+
* It writes the command to the child process's stdin and listens for output on stdout and stderr.
|
|
76
|
+
* The method uses a unique marker to determine when the command has finished executing, allowing it to capture the complete output before resolving.
|
|
77
|
+
* If an error occurs during execution, it captures the error message and rejects the promise with a descriptive error.
|
|
78
|
+
* 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.
|
|
79
|
+
* @param shell The child process in which to execute the command.
|
|
80
|
+
* @param command The shell command to execute.
|
|
81
|
+
* @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.
|
|
82
|
+
* @throws Will throw an error if the command fails to execute properly, providing details about the failed command and the associated error message.
|
|
83
|
+
*/
|
|
84
|
+
protected executeCommand(shell: ChildProcessWithoutNullStreams, command: string): Promise<string[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Handles the file movements for a specific source and destination.
|
|
87
|
+
* It checks for the existence of the source path and creates the destination folder if it does not exist.
|
|
88
|
+
* The method uses fs.cp to copy files or directories from the source to the destination, supporting recursive copying for directories.
|
|
89
|
+
* It captures any errors that occur during the process and provides descriptive error messages to help identify issues with file movements.
|
|
90
|
+
* This function is crucial for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
91
|
+
* @param destination The target path(s) where the source should be moved to.
|
|
92
|
+
* @param source An optional specific source path within the dependency folder to move, defaulting to the entire folder if not provided.
|
|
93
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the file movements, including any errors encountered during the process.
|
|
94
|
+
* @throws Will throw an error if any issues occur during the file movement process, such as missing source paths or problems with file system access.
|
|
95
|
+
*/
|
|
96
|
+
protected moveFiles(destination: string | string[], source?: string): Promise<string[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Constructs the source path for file movements based on the dependency's folder and an optional specific source path.
|
|
99
|
+
* If a specific source is provided, it concatenates it with the dependency's folder; otherwise, it returns the dependency's folder as the source path.
|
|
100
|
+
* The method also ensures that any trailing slashes are removed from the folder and that any leading slashes are removed from the source to create a valid path for file operations.
|
|
101
|
+
* This function is essential for determining the correct source path when moving files as part of the build process, allowing for flexible configurations that can specify either the entire dependency folder or specific subpaths within it.
|
|
102
|
+
* @param folder The base folder of the dependency.
|
|
103
|
+
* @param source An optional specific source path within the dependency folder to use for file movements.
|
|
104
|
+
* @returns A string representing the constructed source path for file operations.
|
|
105
|
+
*/
|
|
106
|
+
static getSourcePath(folder: string, source?: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Recursively extracts all destination folders from the builder's move configuration, supporting various formats such as strings, arrays, and nested objects.
|
|
109
|
+
* It traverses the move configuration, collecting all destination paths into a single array, which can then be used for file operations during the build process.
|
|
110
|
+
* This method is crucial for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
111
|
+
* @param builder The move configuration from the builder, which can be a string, an array of strings, or an object mapping source paths to destination paths.
|
|
112
|
+
* @returns An array of strings representing all destination folders extracted from the move configuration.
|
|
113
|
+
*/
|
|
114
|
+
static getAllOutFolders(builder: Dependency.Builder['move']): string[];
|
|
115
|
+
}
|
|
116
|
+
export declare namespace Dependency {
|
|
117
|
+
type logCallback = (messages: string[]) => void;
|
|
118
|
+
type repo = `https://github.com/${string}/${string}.git` | `git@github.com:${string}/${string}.git`;
|
|
119
|
+
type Builder = schemas.builder['infer'];
|
|
120
|
+
type Resolver = schemas.pathResolverEntry['infer'];
|
|
121
|
+
type Dependency = schemas.dependency['infer'];
|
|
122
|
+
type newDependency = schemas.dependency['inferToProcess'];
|
|
123
|
+
interface manageOptions {
|
|
124
|
+
force?: boolean;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export default Dependency;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Dependency utility.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { promises as FS } from "fs";
|
|
7
|
+
import { spawn } from "child_process";
|
|
8
|
+
import { File, Path } from '@netfeez/common-node';
|
|
9
|
+
import Git from "./Git.js";
|
|
10
|
+
import Validator from "./Validator.js";
|
|
11
|
+
export class Dependency {
|
|
12
|
+
config;
|
|
13
|
+
static include = ['*'];
|
|
14
|
+
name;
|
|
15
|
+
repo;
|
|
16
|
+
branch;
|
|
17
|
+
builder;
|
|
18
|
+
resolver;
|
|
19
|
+
constructor(config, dependency) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
Validator.validateRepo(dependency.repo);
|
|
22
|
+
this.name = dependency.name;
|
|
23
|
+
this.repo = dependency.repo;
|
|
24
|
+
this.branch = dependency.branch;
|
|
25
|
+
this.builder = dependency.builder;
|
|
26
|
+
this.resolver = dependency.resolver;
|
|
27
|
+
}
|
|
28
|
+
/** Get the folder of the dependency */
|
|
29
|
+
get folder() {
|
|
30
|
+
let path = Path.join(this.config.flowFolder, this.name);
|
|
31
|
+
path = Path.normalize(path);
|
|
32
|
+
return path;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Clones the dependency's repository to the local file system. If the target folder already exists, it checks the 'force' option: if 'force' is false, it performs a pull to update the existing repository; if 'force' is true, it uninstalls (deletes) the existing folder before cloning.
|
|
36
|
+
* This method ensures that the local copy of the dependency is up-to-date with the remote repository, allowing for both fresh installations and updates based on user preference.
|
|
37
|
+
* @param options An object containing options for managing the dependency, such as 'force' to determine whether to overwrite existing files.
|
|
38
|
+
* @returns A promise that resolves to a string message indicating the result of the clone or pull operation.
|
|
39
|
+
* @throws Will throw an error if the cloning or pulling process fails.
|
|
40
|
+
*/
|
|
41
|
+
async clone(options = {}) {
|
|
42
|
+
if (await File.exists(this.folder)) {
|
|
43
|
+
if (!options.force)
|
|
44
|
+
return await this.pull();
|
|
45
|
+
else
|
|
46
|
+
await this.uninstall();
|
|
47
|
+
}
|
|
48
|
+
return await Git.clone(this.repo, this.folder, this.branch);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Pulls the latest changes from the dependency's repository to the local file system. It uses the Git utility to perform a pull operation on the existing local repository, ensuring that it is updated with any new commits or changes from the remote repository. This method is essential for keeping the local copy of the dependency in sync with its source, allowing for seamless updates without needing to reinstall the entire dependency.
|
|
52
|
+
* @returns A promise that resolves to a string message indicating the result of the pull operation.
|
|
53
|
+
* @throws Will throw an error if the pull process fails, such as if the local repository is not properly set up or if there are conflicts that cannot be automatically resolved.
|
|
54
|
+
*/
|
|
55
|
+
async pull() {
|
|
56
|
+
return await Git.pull(this.folder, this.branch);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Installs the dependency by first cloning its repository (or pulling updates if it already exists) and then executing any build steps defined in the builder property. It manages the entire installation process, including handling the cloning/pulling of the repository and running any necessary commands to set up the dependency according to its configuration. This method ensures that the dependency is properly installed and ready for use, providing feedback on each step of the process through returned messages.
|
|
60
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the cloning/pulling and building processes.
|
|
61
|
+
* @throws Will throw an error if any step of the installation process fails, such as issues with cloning, pulling, or executing build commands.
|
|
62
|
+
*/
|
|
63
|
+
async install() {
|
|
64
|
+
const output = [];
|
|
65
|
+
try {
|
|
66
|
+
const cloneResult = await this.clone();
|
|
67
|
+
output.push(cloneResult);
|
|
68
|
+
const buildResult = await this.build();
|
|
69
|
+
output.push(...buildResult);
|
|
70
|
+
return output;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Uninstalls the dependency by removing its local folder and any additional folders specified in the builder's move steps.
|
|
78
|
+
* It checks for the existence of each folder before attempting to remove it, ensuring that it only tries to delete valid paths.
|
|
79
|
+
* This method is crucial for cleanly removing a dependency from the local file system, allowing for a complete uninstallation that includes all related files and directories as defined by the dependency's configuration.
|
|
80
|
+
* @return A promise that resolves to an array of string messages indicating the results of the uninstallation process, such as which folders were removed.
|
|
81
|
+
* @throws Will throw an error if any issues occur during the uninstallation process, such as problems with file system access or if the specified folders cannot be removed.
|
|
82
|
+
*/
|
|
83
|
+
async uninstall() {
|
|
84
|
+
try {
|
|
85
|
+
const output = [];
|
|
86
|
+
const moves = this.builder
|
|
87
|
+
? this.builder
|
|
88
|
+
.map(step => step.move ? Dependency.getAllOutFolders(step.move) : [])
|
|
89
|
+
.reduce((acc, val) => acc.concat(val), [])
|
|
90
|
+
: [];
|
|
91
|
+
const folders = [this.folder, ...moves];
|
|
92
|
+
for (const folder of folders) {
|
|
93
|
+
if (!await File.exists(folder))
|
|
94
|
+
continue;
|
|
95
|
+
output.push(`Removing &C4${folder}`);
|
|
96
|
+
await FS.rm(folder, { recursive: true });
|
|
97
|
+
}
|
|
98
|
+
return output;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Builds the dependency by executing the commands specified in the builder property.
|
|
106
|
+
* It iterates through each build step, running any defined commands and handling file movements as necessary.
|
|
107
|
+
* The method uses a child process to execute shell commands, capturing the output and errors for each step.
|
|
108
|
+
* This allows for a flexible build process that can accommodate various setup requirements defined by the dependency's configuration, ensuring that the dependency is properly built and ready for use after installation.
|
|
109
|
+
* @return A promise that resolves to an array of string messages indicating the results of the build process, including any command outputs and file movements.
|
|
110
|
+
* @throws Will throw an error if any issues occur during the build process, such as command execution failures or problems with file movements.
|
|
111
|
+
*/
|
|
112
|
+
async build() {
|
|
113
|
+
const output = [];
|
|
114
|
+
if (!this.builder || this.builder.length === 0)
|
|
115
|
+
return output;
|
|
116
|
+
const shell = spawn('/bin/bash', [], {
|
|
117
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
for (const step of this.builder) {
|
|
121
|
+
if (step.run) {
|
|
122
|
+
const run = typeof step.run === 'string' ? [step.run] : step.run;
|
|
123
|
+
const commands = [`cd ${this.folder}`, ...run];
|
|
124
|
+
const results = await this.executeCommands(commands, shell);
|
|
125
|
+
output.push(...results);
|
|
126
|
+
}
|
|
127
|
+
if (step.move) {
|
|
128
|
+
const moveResults = await this.move(step.move);
|
|
129
|
+
output.push(...moveResults);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
shell.kill();
|
|
138
|
+
}
|
|
139
|
+
return output;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Handles the file movements defined in the builder's move steps.
|
|
143
|
+
* It supports various formats for specifying destinations, including strings, arrays, and objects with keys representing source paths.
|
|
144
|
+
* The method checks for the existence of source files or directories before attempting to move them to the specified destinations, ensuring that it only operates on valid paths.
|
|
145
|
+
* This function is essential for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
146
|
+
* @param move The move configuration from the builder, which can be a string, an array of strings, or an object mapping source paths to destination paths.
|
|
147
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the file movements, including any errors encountered during the process.
|
|
148
|
+
* @throws Will throw an error if any issues occur during the file movement process, such as missing source paths or problems with file system access.
|
|
149
|
+
*/
|
|
150
|
+
async move(move) {
|
|
151
|
+
if (!move)
|
|
152
|
+
return [];
|
|
153
|
+
const output = [];
|
|
154
|
+
if (typeof move === 'string' || Array.isArray(move)) {
|
|
155
|
+
const moves = Array.isArray(move) ? move : [move];
|
|
156
|
+
for (const destination of moves) {
|
|
157
|
+
const moveResult = await this.moveFiles(destination);
|
|
158
|
+
output.push(...moveResult);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
for (const key in move) {
|
|
163
|
+
const value = move[key];
|
|
164
|
+
const destinations = typeof value === 'string' ? [value] : value;
|
|
165
|
+
for (const destination of destinations) {
|
|
166
|
+
const moveResult = await this.moveFiles(destination, key);
|
|
167
|
+
output.push(...moveResult);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return output;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Executes a series of shell commands in a child process, capturing the output and errors for each command.
|
|
175
|
+
* It writes each command to the child process's stdin and listens for output on stdout and stderr.
|
|
176
|
+
* The method uses a marker to determine when a command has finished executing, allowing it to capture the complete output for each command before proceeding to the next one.
|
|
177
|
+
* This function is crucial for running build commands defined in the dependency's configuration, providing feedback on the execution of each command and handling any errors that may arise during the process.
|
|
178
|
+
* @param commands An array of shell commands to execute.
|
|
179
|
+
* @param shell The child process in which to execute the commands.
|
|
180
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the command executions, including any output or errors captured during the process.
|
|
181
|
+
* @throws Will throw an error if any command fails to execute properly, providing details about the failed command and the associated error message.
|
|
182
|
+
*/
|
|
183
|
+
async executeCommands(commands, shell) {
|
|
184
|
+
const output = [];
|
|
185
|
+
shell.stderr.on('data', data => output.push(data.toString()));
|
|
186
|
+
for (const command of commands) {
|
|
187
|
+
const result = await this.executeCommand(shell, command);
|
|
188
|
+
output.push(...result);
|
|
189
|
+
}
|
|
190
|
+
shell.kill();
|
|
191
|
+
return output;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Executes a single shell command in the provided child process, capturing its output and handling errors.
|
|
195
|
+
* It writes the command to the child process's stdin and listens for output on stdout and stderr.
|
|
196
|
+
* The method uses a unique marker to determine when the command has finished executing, allowing it to capture the complete output before resolving.
|
|
197
|
+
* If an error occurs during execution, it captures the error message and rejects the promise with a descriptive error.
|
|
198
|
+
* 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.
|
|
199
|
+
* @param shell The child process in which to execute the command.
|
|
200
|
+
* @param command The shell command to execute.
|
|
201
|
+
* @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.
|
|
202
|
+
* @throws Will throw an error if the command fails to execute properly, providing details about the failed command and the associated error message.
|
|
203
|
+
*/
|
|
204
|
+
async executeCommand(shell, command) {
|
|
205
|
+
const output = [];
|
|
206
|
+
output.push(`&RRunning command &C4${command}`);
|
|
207
|
+
await new Promise((resolve, reject) => {
|
|
208
|
+
shell.stdin.write(command + '\n');
|
|
209
|
+
const marker = `__END_${Date.now()}__`;
|
|
210
|
+
shell.stdin.write(`echo ${marker}\n`);
|
|
211
|
+
let out = '';
|
|
212
|
+
const listener = (data) => {
|
|
213
|
+
if (data.toString().includes(marker)) {
|
|
214
|
+
shell.stdout.off('data', listener);
|
|
215
|
+
output.push(out.trim());
|
|
216
|
+
resolve();
|
|
217
|
+
}
|
|
218
|
+
else
|
|
219
|
+
out += data.toString().trim();
|
|
220
|
+
};
|
|
221
|
+
shell.stdout.on('data', listener);
|
|
222
|
+
shell.stderr.once('data', data => {
|
|
223
|
+
shell.stdout.off('data', listener);
|
|
224
|
+
output.push(data.toString().trim());
|
|
225
|
+
reject(new Error(`Command "${command}" failed with error: ${data.toString().trim()}`));
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return output;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Handles the file movements for a specific source and destination.
|
|
232
|
+
* It checks for the existence of the source path and creates the destination folder if it does not exist.
|
|
233
|
+
* The method uses fs.cp to copy files or directories from the source to the destination, supporting recursive copying for directories.
|
|
234
|
+
* It captures any errors that occur during the process and provides descriptive error messages to help identify issues with file movements.
|
|
235
|
+
* This function is crucial for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
236
|
+
* @param destination The target path(s) where the source should be moved to.
|
|
237
|
+
* @param source An optional specific source path within the dependency folder to move, defaulting to the entire folder if not provided.
|
|
238
|
+
* @returns A promise that resolves to an array of string messages indicating the results of the file movements, including any errors encountered during the process.
|
|
239
|
+
* @throws Will throw an error if any issues occur during the file movement process, such as missing source paths or problems with file system access.
|
|
240
|
+
*/
|
|
241
|
+
async moveFiles(destination, source) {
|
|
242
|
+
const output = [];
|
|
243
|
+
destination = Array.isArray(destination) ? destination : [destination];
|
|
244
|
+
source = Dependency.getSourcePath(this.folder, source);
|
|
245
|
+
for (const folder of destination) {
|
|
246
|
+
try {
|
|
247
|
+
if (!await File.exists(source))
|
|
248
|
+
throw new Error(`Source path ${source} does not exist.`);
|
|
249
|
+
if (!await File.exists(folder)) {
|
|
250
|
+
if (!await File.isFile(source))
|
|
251
|
+
await FS.mkdir(folder, { recursive: true });
|
|
252
|
+
else {
|
|
253
|
+
const toCreate = folder.slice(0, folder.lastIndexOf('/'));
|
|
254
|
+
if (!await File.exists(toCreate))
|
|
255
|
+
await FS.mkdir(toCreate, { recursive: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
output.push(`&RMoving source &C4${source} &Rto &C4${folder}`);
|
|
259
|
+
await FS.cp(source, folder, { recursive: true, force: true });
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
throw new Error(`Failed to move files from ${this.name} to ${folder}, \n${error}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return output;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Constructs the source path for file movements based on the dependency's folder and an optional specific source path.
|
|
269
|
+
* If a specific source is provided, it concatenates it with the dependency's folder; otherwise, it returns the dependency's folder as the source path.
|
|
270
|
+
* The method also ensures that any trailing slashes are removed from the folder and that any leading slashes are removed from the source to create a valid path for file operations.
|
|
271
|
+
* This function is essential for determining the correct source path when moving files as part of the build process, allowing for flexible configurations that can specify either the entire dependency folder or specific subpaths within it.
|
|
272
|
+
* @param folder The base folder of the dependency.
|
|
273
|
+
* @param source An optional specific source path within the dependency folder to use for file movements.
|
|
274
|
+
* @returns A string representing the constructed source path for file operations.
|
|
275
|
+
*/
|
|
276
|
+
static getSourcePath(folder, source) {
|
|
277
|
+
folder = folder.endsWith('/') ? folder.slice(0, -1) : folder;
|
|
278
|
+
if (!source)
|
|
279
|
+
return folder;
|
|
280
|
+
source = source.startsWith('/') ? source.slice(1) : source;
|
|
281
|
+
return `${folder}/${source}`.replace(/ /g, '\\ ');
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Recursively extracts all destination folders from the builder's move configuration, supporting various formats such as strings, arrays, and nested objects.
|
|
285
|
+
* It traverses the move configuration, collecting all destination paths into a single array, which can then be used for file operations during the build process.
|
|
286
|
+
* This method is crucial for managing the organization of files after building a dependency, allowing for flexible configurations that can accommodate different project structures and requirements.
|
|
287
|
+
* @param builder The move configuration from the builder, which can be a string, an array of strings, or an object mapping source paths to destination paths.
|
|
288
|
+
* @returns An array of strings representing all destination folders extracted from the move configuration.
|
|
289
|
+
*/
|
|
290
|
+
static getAllOutFolders(builder) {
|
|
291
|
+
if (!builder)
|
|
292
|
+
return [];
|
|
293
|
+
const folders = [];
|
|
294
|
+
if (typeof builder === 'string')
|
|
295
|
+
folders.push(builder);
|
|
296
|
+
else if (Array.isArray(builder))
|
|
297
|
+
folders.push(...builder);
|
|
298
|
+
else
|
|
299
|
+
for (const key in builder) {
|
|
300
|
+
const out = this.getAllOutFolders(builder[key]);
|
|
301
|
+
folders.push(...out);
|
|
302
|
+
}
|
|
303
|
+
return folders;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
export default Dependency;
|
|
307
|
+
//# sourceMappingURL=Dependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dependency.js","sourceRoot":"","sources":["../../src/support/Dependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAkC,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,MAAM,OAAO,UAAU;IASI;IARhB,MAAM,CAAC,OAAO,GAAa,CAAE,GAAG,CAAE,CAAC;IAC1B,IAAI,CAAS;IACb,IAAI,CAAkB;IACtB,MAAM,CAAU;IAChB,OAAO,CAAuB;IAC9B,QAAQ,CAAwB;IAEhD,YACuB,MAAqB,EACxC,UAAiC;QADd,WAAM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C3D,OAAO,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAAC,OAAmC;QAC9D,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QACxB,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAClD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;;YACrD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;gBAChD,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;YACzB,CAAC;QAAC,OAAO,OAAO,CAAC;IACrB,CAAC;;AAaL,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export declare class File {
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a given path exists in the file system.
|
|
4
|
+
* It uses fs.access to determine if the path is accessible, returning true if it exists and false if it does not.
|
|
5
|
+
* This method is useful for verifying the presence of files or directories before attempting to read, write, or perform other operations on them, helping to prevent errors related to non-existent paths.
|
|
6
|
+
* @param path The file system path to check for existence.
|
|
7
|
+
* @returns A promise that resolves to true if the path exists, or false if it does not.
|
|
8
|
+
*/
|
|
9
|
+
static exists(path: string): Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the given path is a file.
|
|
12
|
+
* It uses fs.stat to retrieve the file system statistics for the path and checks if it is a file using the isFile method.
|
|
13
|
+
* If the path does not exist or is not a file, it returns false.
|
|
14
|
+
* This method is useful for validating that a specific path points to a file before performing operations that require a file, such as reading or writing content.
|
|
15
|
+
* It helps to ensure that the expected file structure is in place and can prevent errors related to invalid paths or types.
|
|
16
|
+
* @param path The file system path to check.
|
|
17
|
+
* @returns A promise that resolves to true if the path is a file, or false if it is not.
|
|
18
|
+
* @throws Will throw an error if the path does not exist or is not a file.
|
|
19
|
+
*/
|
|
20
|
+
static isFile(path: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if the given path is a directory.
|
|
23
|
+
* It uses fs.stat to retrieve the file system statistics for the path and checks if it is a directory using the isDirectory method.
|
|
24
|
+
* If the path does not exist or is not a directory, it returns false.
|
|
25
|
+
* This method is useful for validating that a specific path points to a directory before performing operations that require a directory, such as creating files within it or listing its contents.
|
|
26
|
+
* It helps to ensure that the expected directory structure is in place and can prevent errors related to invalid paths or types.
|
|
27
|
+
* @param path The file system path to check.
|
|
28
|
+
* @returns A promise that resolves to true if the path is a directory, or false if it is not.
|
|
29
|
+
* @throws Will throw an error if the path does not exist or is not a directory.
|
|
30
|
+
*/
|
|
31
|
+
static isDirectory(path: string): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the content of a file at the specified path using the given encoding (defaulting to 'utf-8').
|
|
34
|
+
* It first checks if the path is a file using the isFile method, and if it is not, it throws an error indicating that the path is not a file.
|
|
35
|
+
* If the path is valid, it uses fs.readFile to read the content of the file and returns it as a string.
|
|
36
|
+
* This method is essential for safely reading files while ensuring that the provided path points to a valid file, preventing errors related to invalid paths or types.
|
|
37
|
+
* @param path The file system path of the file to read.
|
|
38
|
+
* @param encoding The character encoding to use when reading the file (default is 'utf-8').
|
|
39
|
+
* @returns A promise that resolves to the content of the file as a string.
|
|
40
|
+
* @throws Will throw an error if the path does not point to a valid file.
|
|
41
|
+
*/
|
|
42
|
+
static read(path: string, encoding?: BufferEncoding): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Writes the specified content to a file at the given path using the provided encoding (defaulting to 'utf-8').
|
|
45
|
+
* It uses fs.writeFile to write the content to the file, creating the file if it does not exist or overwriting it if it does.
|
|
46
|
+
* This method is crucial for saving data to files while ensuring that the content is properly encoded and that any necessary directories are in place before writing.
|
|
47
|
+
* It can be used for a variety of purposes, such as saving configuration files, logs, or any other data that needs to be persisted in the file system.
|
|
48
|
+
* @param path The file system path where the content should be written.
|
|
49
|
+
* @param content The string content to write to the file.
|
|
50
|
+
* @param encoding The character encoding to use when writing the file (default is 'utf-8').
|
|
51
|
+
* @returns A promise that resolves when the write operation is complete.
|
|
52
|
+
*/
|
|
53
|
+
static write(path: string, content: string, encoding?: BufferEncoding): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a directory at the specified path with the given options (such as recursive creation). It first checks if the path already exists using the exists method, and if it does, it throws an error to prevent overwriting existing files or directories. If the path does not exist, it uses fs.mkdir to create the directory according to the provided options. This method is essential for safely creating directories while ensuring that existing paths are not unintentionally overwritten, and it can be used to set up necessary directory structures for applications or projects.
|
|
56
|
+
* @param path The file system path where the directory should be created.
|
|
57
|
+
* @param options Optional settings for directory creation, such as { recursive: true } to create parent directories if they do not exist.
|
|
58
|
+
* @returns A promise that resolves when the directory has been successfully created.
|
|
59
|
+
* @throws Will throw an error if the path already exists or if there is an issue during directory creation.
|
|
60
|
+
*/
|
|
61
|
+
static mkdir(path: string, options?: {
|
|
62
|
+
recursive?: boolean;
|
|
63
|
+
}): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Recursively retrieves all files with specified extensions from a given directory.
|
|
66
|
+
* It uses fs.readdir with the "withFileTypes" option to efficiently determine if an entry is a file or a directory.
|
|
67
|
+
* For directories, it calls itself recursively to gather files from subdirectories. For files, it checks if their extensions match the provided list and includes them in the result.
|
|
68
|
+
* This method returns a flat array of file paths that can be processed by the path resolver.
|
|
69
|
+
* @param dir The directory to scan for files.
|
|
70
|
+
* @param extensions An array of file extensions to filter the results (e.g., ['.js', '.ts']).
|
|
71
|
+
* @returns A promise that resolves to an array of file paths matching the specified extensions.
|
|
72
|
+
*/
|
|
73
|
+
static getAllFiles(dir: string, extensions: string[]): Promise<string[]>;
|
|
74
|
+
}
|
|
75
|
+
export declare namespace File {
|
|
76
|
+
interface ReadDirOptions {
|
|
77
|
+
withFileTypes?: boolean;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export default File;
|