depflow 1.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.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Utility to help with File operations.
4
+ * @license Apache-2.0
5
+ */
6
+ import Dependency from './Dependency.js';
7
+ export declare class File {
8
+ /**
9
+ * Validates and transforms raw data into a DependencyDef object.
10
+ * @param data - The raw data to extract from.
11
+ * @returns A valid DependencyDef object.
12
+ */
13
+ private static extractDependency;
14
+ /**
15
+ * Reads and parses a dependency file.
16
+ * @param path - Path to the dependency file.
17
+ * @returns The parsed JSON content.
18
+ */
19
+ private static read;
20
+ /**
21
+ * Loads, validates, and compiles dependencies from a file.
22
+ * @param path - Path to the dependency file.
23
+ * @returns An array of valid DependencyDef objects.
24
+ */
25
+ static load(path: string): Promise<Dependency.Dependency[]>;
26
+ /**
27
+ * Saves an array of dependency definitions to a file.
28
+ * @param path - Path to the dependency file.
29
+ * @param dependencies - The dependencies to save.
30
+ */
31
+ static save(path: string, dependencies: any[]): Promise<void>;
32
+ /**
33
+ * Check if a file exists
34
+ * @param path Path to check
35
+ * @returns Promise<boolean>
36
+ */
37
+ static isFile(path: string): Promise<boolean>;
38
+ /**
39
+ * Check if a file or folder exists
40
+ * @param path Path to check
41
+ * @returns Promise<boolean>
42
+ */
43
+ static exists(path: string): Promise<boolean>;
44
+ }
45
+ export default File;
package/build/File.js ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Utility to help with File operations.
4
+ * @license Apache-2.0
5
+ */
6
+ import { promises as FS } from 'fs';
7
+ import Validator from './Validator.js';
8
+ export class File {
9
+ /**
10
+ * Validates and transforms raw data into a DependencyDef object.
11
+ * @param data - The raw data to extract from.
12
+ * @returns A valid DependencyDef object.
13
+ */
14
+ static extractDependency(data) {
15
+ Validator.validateDependency(data);
16
+ return data;
17
+ }
18
+ /**
19
+ * Reads and parses a dependency file.
20
+ * @param path - Path to the dependency file.
21
+ * @returns The parsed JSON content.
22
+ */
23
+ static async read(path) {
24
+ try {
25
+ if (!await this.exists(path))
26
+ await FS.writeFile(path, '[]');
27
+ if (!await this.isFile(path))
28
+ throw new Error(`Dependency file at &C2${path}&R does not exist.`);
29
+ const content = await FS.readFile(path, 'utf-8');
30
+ return JSON.parse(content);
31
+ }
32
+ catch (error) {
33
+ throw new Error(`Failed to read or parse dependency file at &C2${path}&R.`, { cause: error });
34
+ }
35
+ }
36
+ /**
37
+ * Loads, validates, and compiles dependencies from a file.
38
+ * @param path - Path to the dependency file.
39
+ * @returns An array of valid DependencyDef objects.
40
+ */
41
+ static async load(path) {
42
+ try {
43
+ const data = await this.read(path);
44
+ if (!Array.isArray(data))
45
+ throw new Error('Dependency file content must be an array.');
46
+ const dependencies = [];
47
+ for (const item of data)
48
+ dependencies.push(this.extractDependency(item));
49
+ return dependencies;
50
+ }
51
+ catch (error) {
52
+ throw error;
53
+ }
54
+ }
55
+ /**
56
+ * Saves an array of dependency definitions to a file.
57
+ * @param path - Path to the dependency file.
58
+ * @param dependencies - The dependencies to save.
59
+ */
60
+ static async save(path, dependencies) {
61
+ try {
62
+ const validatedDeps = [];
63
+ const seenNames = new Set();
64
+ for (const item of dependencies) {
65
+ const dependency = this.extractDependency(item);
66
+ if (seenNames.has(dependency.name))
67
+ throw new Error(`Duplicate dependency name found: "${dependency.name}".`);
68
+ seenNames.add(dependency.name);
69
+ validatedDeps.push(dependency);
70
+ }
71
+ try {
72
+ const content = JSON.stringify(validatedDeps, null, 4);
73
+ await FS.writeFile(path, content);
74
+ }
75
+ catch (error) {
76
+ throw new Error(`Failed to write dependency file at &C2${path}&R.`, { cause: error });
77
+ }
78
+ }
79
+ catch (error) {
80
+ throw error;
81
+ }
82
+ }
83
+ /**
84
+ * Check if a file exists
85
+ * @param path Path to check
86
+ * @returns Promise<boolean>
87
+ */
88
+ static async isFile(path) {
89
+ try {
90
+ const stats = await FS.stat(path);
91
+ return stats.isFile();
92
+ }
93
+ catch {
94
+ return false;
95
+ }
96
+ }
97
+ /**
98
+ * Check if a file or folder exists
99
+ * @param path Path to check
100
+ * @returns Promise<boolean>
101
+ */
102
+ static async exists(path) {
103
+ try {
104
+ await FS.access(path);
105
+ return true;
106
+ }
107
+ catch {
108
+ return false;
109
+ }
110
+ }
111
+ }
112
+ export default File;
113
+ //# sourceMappingURL=File.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"File.js","sourceRoot":"","sources":["../src/File.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,MAAM,OAAO,IAAI;IACb;;;;OAIG;IACK,MAAM,CAAC,iBAAiB,CAAC,IAAS;QACtC,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD;;;;OAIG;IACK,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAClC,IAAI,CAAC;YACD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,oBAAoB,CAAC,CAAC;YACjG,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,KAAK,EAAE,EAAE,KAAK,EAAE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,CAAC;gBACvD,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACtC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAAC,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAAC,CAAC;QAC9G,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAAC,MAAM,KAAK,CAAC;QAAC,CAAC;IACpC,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY;QACnC,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;IAC7B,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY;QACnC,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAAC,OAAO,IAAI,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;IACvE,CAAC;CACJ;AAED,eAAe,IAAI,CAAC"}
package/build/Git.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Executes git commands.
4
+ * @license Apache-2.0
5
+ */
6
+ declare class Git {
7
+ /**
8
+ * Executes a command and returns its output.
9
+ * @param command The command to execute.
10
+ * @returns A promise that resolves with the command's output.
11
+ */
12
+ private static exec;
13
+ /**
14
+ * Clones a repository.
15
+ * @param repo The repository URL.
16
+ * @param path The path to clone the repository to.
17
+ * @returns A promise that resolves when the command is finished.
18
+ * @throws Error if the command fails.
19
+ */
20
+ static clone(repo: string, path: string, branch?: string): Promise<string>;
21
+ /**
22
+ * Checks out a branch/tag.
23
+ * @param path The path to the repository.
24
+ * @param branch The branch/tag to checkout.
25
+ * @returns A promise that resolves when the command is finished.
26
+ */
27
+ static switch(path: string, branch: string): Promise<string>;
28
+ /**
29
+ * Pulls changes from a remote repository.
30
+ * @param path The path to the repository.
31
+ * @param branch The branch to pull from.
32
+ * @returns A promise that resolves when the command is finished.
33
+ */
34
+ static pull(path: string, branch?: string): Promise<string>;
35
+ }
36
+ export default Git;
package/build/Git.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Executes git commands.
4
+ * @license Apache-2.0
5
+ */
6
+ import ChildProcess from 'child_process';
7
+ class Git {
8
+ /**
9
+ * Executes a command and returns its output.
10
+ * @param command The command to execute.
11
+ * @returns A promise that resolves with the command's output.
12
+ */
13
+ static exec(command) {
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
+ });
33
+ }
34
+ /**
35
+ * Clones a repository.
36
+ * @param repo The repository URL.
37
+ * @param path The path to clone the repository to.
38
+ * @returns A promise that resolves when the command is finished.
39
+ * @throws Error if the command fails.
40
+ */
41
+ static async clone(repo, path, branch) {
42
+ return this.exec(`git clone ${repo} ${path}${branch ? ` --branch ${branch}` : ''}`);
43
+ }
44
+ /**
45
+ * Checks out a branch/tag.
46
+ * @param path The path to the repository.
47
+ * @param branch The branch/tag to checkout.
48
+ * @returns A promise that resolves when the command is finished.
49
+ */
50
+ static async switch(path, branch) {
51
+ return this.exec(`git -C ${path} switch ${branch}`);
52
+ }
53
+ /**
54
+ * Pulls changes from a remote repository.
55
+ * @param path The path to the repository.
56
+ * @param branch The branch to pull from.
57
+ * @returns A promise that resolves when the command is finished.
58
+ */
59
+ static async pull(path, branch) {
60
+ const command = `git -C ${path} pull`;
61
+ if (branch)
62
+ return this.exec(`${command} --branch ${branch}`);
63
+ else
64
+ return this.exec(command);
65
+ }
66
+ }
67
+ export default Git;
68
+ //# sourceMappingURL=Git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Git.js","sourceRoot":"","sources":["../src/Git.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,MAAM,GAAG;IACL;;;;OAIG;IACK,MAAM,CAAC,IAAI,CAAC,OAAe;QAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1C,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAG,CAAC,CAAC;YAEhE,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,WAAW,GAAG,EAAE,CAAC;YAErB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC/D,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACpE,OAAO,CAAC,EAAE,CAAC,OAAO,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C,OAAO,CAAC,CAAC;IACnC,CAAC;CACJ;AAED,eAAe,GAAG,CAAC"}
@@ -0,0 +1,35 @@
1
+ export declare class PathFixer {
2
+ readonly info: PathFixer.ProjectInfo;
3
+ readonly projectRoot: string;
4
+ static readonly IMPORT_REGEX: RegExp;
5
+ static readonly DEFAULT_PROJECT_INFO: PathFixer.ProjectInfo;
6
+ static readonly PROJECT_ROOT: string;
7
+ static readonly EXTENSIONS: string[];
8
+ absoluteRoot: string;
9
+ _alias: PathFixer.Alias[] | null;
10
+ constructor(info?: PathFixer.ProjectInfo, projectRoot?: string);
11
+ get alias(): PathFixer.Alias[];
12
+ run(): Promise<void>;
13
+ watch(): Promise<void>;
14
+ private process;
15
+ private processReplacer;
16
+ watchHandler(queue: Map<string, NodeJS.Timeout>, eventType: string, filename: string): Promise<void>;
17
+ watchTimeout(file: string, name: string): Promise<void>;
18
+ static getAllFiles(dir: string, extensions: string[]): Promise<string[]>;
19
+ static getProjectInfo(tsconfig?: string): Promise<PathFixer.ProjectInfo>;
20
+ }
21
+ declare namespace PathFixer {
22
+ interface Paths {
23
+ [alias: string]: string[];
24
+ }
25
+ interface Alias {
26
+ alias: string;
27
+ target: string;
28
+ }
29
+ interface ProjectInfo {
30
+ root: string;
31
+ out: string;
32
+ path: Paths;
33
+ }
34
+ }
35
+ export default PathFixer;
@@ -0,0 +1,158 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Utility for path fixing.
4
+ * @license Apache-2.0
5
+ */
6
+ import path from 'path';
7
+ import syncFs, { promises as fs } from 'fs';
8
+ import { Logger, Utilities } from 'vortez';
9
+ const logger = new Logger({ prefix: 'PathFixer' });
10
+ export class PathFixer {
11
+ info;
12
+ projectRoot;
13
+ static IMPORT_REGEX = /(from\s+['"])([^'"]+)(['"])/g;
14
+ static DEFAULT_PROJECT_INFO = { root: 'src', out: 'build', path: {} };
15
+ static PROJECT_ROOT = process.cwd();
16
+ static EXTENSIONS = ['js', '.d.ts'];
17
+ absoluteRoot;
18
+ _alias = null;
19
+ constructor(info = PathFixer.DEFAULT_PROJECT_INFO, projectRoot = PathFixer.PROJECT_ROOT) {
20
+ this.info = info;
21
+ this.projectRoot = projectRoot;
22
+ const fullPath = path.join(projectRoot, info.out);
23
+ this.absoluteRoot = path.resolve(fullPath);
24
+ }
25
+ get alias() {
26
+ if (this._alias)
27
+ return this._alias;
28
+ const result = [];
29
+ for (const [key, value] of Object.entries(this.info.path)) {
30
+ let alias = key.replace(/\/\*$/, '');
31
+ alias = alias.replace(new RegExp(`^${this.info.root}`), '');
32
+ alias = alias.replace(/^\//, '');
33
+ let target = value[0].replace(/\/\*$/, '');
34
+ target = target.replace(new RegExp(`^${this.info.root}`), '');
35
+ target = target.replace(/^\/|\/$/, '');
36
+ target = path.join(this.absoluteRoot, target);
37
+ result.push({ alias, target });
38
+ }
39
+ this._alias = result;
40
+ return result;
41
+ }
42
+ async run() {
43
+ logger.log('&C2Starting path fixer, please wait...');
44
+ if (!await Utilities.fileExists(this.absoluteRoot))
45
+ return void logger.warn(`The root directory &C4${this.absoluteRoot}&R does not exist.`);
46
+ const files = await PathFixer.getAllFiles(this.absoluteRoot, PathFixer.EXTENSIONS);
47
+ logger.log(`&C2Found &C3${files.length} &C2files to process in &C4${this.absoluteRoot}.`);
48
+ let rewrittenCount = 0;
49
+ for (const file of files) {
50
+ const changed = await this.process(file);
51
+ if (changed)
52
+ rewrittenCount++;
53
+ }
54
+ logger.log(`&C2Path aliases rewritten in &C3${rewrittenCount} &C2files.`);
55
+ }
56
+ async watch() {
57
+ await this.run();
58
+ logger.log(`&C2Starting watcher in &C4${this.absoluteRoot}.`);
59
+ if (!await Utilities.fileExists(this.absoluteRoot))
60
+ await fs.mkdir(this.absoluteRoot, { recursive: true });
61
+ const watcher = syncFs.watch(this.absoluteRoot, { recursive: true });
62
+ const queue = new Map();
63
+ watcher.on('change', this.watchHandler.bind(this, queue));
64
+ }
65
+ async process(file) {
66
+ const content = await fs.readFile(file, 'utf8');
67
+ const newContent = content.replace(PathFixer.IMPORT_REGEX, this.processReplacer.bind(this, file));
68
+ if (content === newContent)
69
+ return false;
70
+ await fs.writeFile(file, newContent, 'utf8');
71
+ return true;
72
+ }
73
+ processReplacer(file, match, prefix, modulePath, suffix) {
74
+ const config = this.alias.find(config => modulePath.startsWith(`${config.alias}/`) || modulePath === config.alias);
75
+ if (!config)
76
+ return match;
77
+ const dir = path.dirname(file);
78
+ const restOfModulePath = modulePath.substring(config.alias.length);
79
+ const absoluteTarget = path.join(config.target, restOfModulePath);
80
+ let target = path.relative(dir, absoluteTarget);
81
+ if (!target.startsWith('.'))
82
+ target = `./${target}`;
83
+ target = target.replace(/\\/g, '/');
84
+ return `${prefix}${target}${suffix}`;
85
+ }
86
+ async watchHandler(queue, eventType, filename) {
87
+ if (!filename || !PathFixer.EXTENSIONS.some(ext => filename.endsWith(ext)))
88
+ return;
89
+ const fullPath = path.join(this.absoluteRoot, filename);
90
+ if (queue.has(fullPath))
91
+ clearTimeout(queue.get(fullPath));
92
+ queue.set(fullPath, setTimeout(this.watchTimeout.bind(this, fullPath, filename), 300));
93
+ }
94
+ async watchTimeout(file, name) {
95
+ try {
96
+ const stat = await fs.stat(file);
97
+ if (!stat.isFile())
98
+ return;
99
+ logger.log(`&C2Change detected in &C4${name}&C2. Processing`);
100
+ const changed = await this.process(file);
101
+ if (changed)
102
+ logger.log(`&C2File &C4${name}&C2 rewritten.`);
103
+ }
104
+ catch (error) {
105
+ if (error.code && error.code === 'ENOENT') {
106
+ logger.warn(`File &C4${name}&R not found, it may have been deleted.`);
107
+ }
108
+ else {
109
+ logger.error(`Error processing file &C4${name}&R:`, error);
110
+ }
111
+ }
112
+ }
113
+ static async getAllFiles(dir, extensions) {
114
+ const result = [];
115
+ if (!await Utilities.fileExists(dir))
116
+ return result;
117
+ const files = await fs.readdir(dir);
118
+ for (const file of files) {
119
+ const fullPath = path.join(dir, file);
120
+ try {
121
+ const stat = await fs.stat(fullPath);
122
+ if (stat.isDirectory()) {
123
+ const subFiles = await this.getAllFiles(fullPath, extensions);
124
+ result.push(...subFiles);
125
+ }
126
+ else if (stat.isFile() && extensions.some(ext => fullPath.endsWith(ext))) {
127
+ result.push(fullPath);
128
+ }
129
+ }
130
+ catch (error) {
131
+ if (error && error.code === 'ENOENT') {
132
+ logger.warn(`File or directory &C4${fullPath}&R not found during scan, skipping.`);
133
+ }
134
+ else {
135
+ logger.error(`Error scanning file &C4${fullPath}&R:`, error);
136
+ }
137
+ }
138
+ }
139
+ return result;
140
+ }
141
+ static async getProjectInfo(tsconfig = 'tsconfig.json') {
142
+ const info = PathFixer.DEFAULT_PROJECT_INFO;
143
+ const content = await fs.readFile(tsconfig, 'utf8');
144
+ const json = JSON.parse(content);
145
+ if (!json.compilerOptions)
146
+ return info;
147
+ const options = json.compilerOptions;
148
+ if (options.rootDir)
149
+ info.root = options.rootDir;
150
+ if (options.outDir)
151
+ info.out = options.outDir;
152
+ if (options.paths)
153
+ info.path = options.paths;
154
+ return info;
155
+ }
156
+ }
157
+ export default PathFixer;
158
+ //# sourceMappingURL=PathFixer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathFixer.js","sourceRoot":"","sources":["../src/PathFixer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,EAAE,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE3C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAEnD,MAAM,OAAO,SAAS;IAQE;IACA;IARb,MAAM,CAAU,YAAY,GAAG,8BAA8B,CAAC;IAC9D,MAAM,CAAU,oBAAoB,GAA0B,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,EAA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,CAAC,KAAK;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AAgBL,eAAe,SAAS,CAAC"}
@@ -0,0 +1,54 @@
1
+ import Dependency from './Dependency.js';
2
+ export declare class Validator {
3
+ /**
4
+ * Validates the 'name' property.
5
+ * @param name The 'name' property to validate.
6
+ * @returns `true` if valid, otherwise throws an error.
7
+ */
8
+ static validateName(name: any): asserts name is string;
9
+ /**
10
+ * Validates the repository URL.
11
+ * @param repo The repository URL to validate.
12
+ * @returns `true` if valid, otherwise throws an error.
13
+ * @throws Error if the repository URL is invalid.
14
+ */
15
+ static validateRepo(repo: any): asserts repo is Dependency.repo;
16
+ /**
17
+ * Validates the 'branch' property.
18
+ * @param branch The 'branch' property to validate.
19
+ * @returns `true` if valid, otherwise throws an error.
20
+ */
21
+ static validateBranch(branch: any): asserts branch is string | null | undefined;
22
+ static validateBuilder(builder: any): asserts builder is Dependency.Builder | null | undefined;
23
+ /**
24
+ * Validates the 'builder.run' property.
25
+ * @param run The 'builder.run' property to validate.
26
+ * @returns `true` if valid, otherwise throws an error.
27
+ */
28
+ static validateRun(run: any): asserts run is string | string[] | null | undefined;
29
+ /**
30
+ * Validates the 'builder.move' property.
31
+ * @param move The 'builder.move' property to validate.
32
+ * @returns `true` if valid, otherwise throws an error.
33
+ */
34
+ static validateMove(move: any): asserts move is Dependency.Builder.MoveType | null | undefined;
35
+ /**
36
+ * Validates a full dependency definition object.
37
+ * @param data The dependency data to validate.
38
+ * @returns `true` if valid, otherwise throws an error.
39
+ */
40
+ static validateDependency(data: any): asserts data is Dependency.Dependency;
41
+ /**
42
+ * Check if a file exists
43
+ * @param path Path to check
44
+ * @returns Promise<boolean>
45
+ */
46
+ protected isFile(path: string): Promise<boolean>;
47
+ /**
48
+ * Check if a file or folder exists
49
+ * @param path Path to check
50
+ * @returns Promise<boolean>
51
+ */
52
+ protected exists(path: string): Promise<boolean>;
53
+ }
54
+ export default Validator;