depflow 2.0.0-dev.1 → 2.0.0-dev.3
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 +4 -3
- 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,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Utility for path resolution with Local/CDN support and dual path fixing.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import syncFs, { promises as fs } from 'node:fs';
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { Logger } from "vortez";
|
|
9
|
+
import Utils from '../Utils.js';
|
|
10
|
+
import File from '../File.js';
|
|
11
|
+
import PathRewriter from './PathRewriter.js';
|
|
12
|
+
import AliasCompiler from './AliasCompiler.js';
|
|
13
|
+
export class PathResolver {
|
|
14
|
+
config;
|
|
15
|
+
options;
|
|
16
|
+
static PROJECT_ROOT = process.cwd();
|
|
17
|
+
static EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
|
|
18
|
+
logger;
|
|
19
|
+
rewriter;
|
|
20
|
+
absoluteOutDir;
|
|
21
|
+
aliases;
|
|
22
|
+
constructor(config, options = {}) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.logger = options.logger || new Logger({ prefix: 'PathResolver' });
|
|
26
|
+
const outDir = config.outDir || '.';
|
|
27
|
+
this.absoluteOutDir = !path.isAbsolute(outDir)
|
|
28
|
+
? path.resolve(PathResolver.PROJECT_ROOT, outDir)
|
|
29
|
+
: outDir;
|
|
30
|
+
this.aliases = new AliasCompiler(PathResolver.PROJECT_ROOT).compile(config);
|
|
31
|
+
this.rewriter = new PathRewriter(this.aliases, PathResolver.PROJECT_ROOT);
|
|
32
|
+
}
|
|
33
|
+
async rewritePaths(mode) {
|
|
34
|
+
this.logger.log(`&C2Starting path resolver in &C3${mode} &C2mode...`);
|
|
35
|
+
if (!await File.exists(this.absoluteOutDir))
|
|
36
|
+
return void this.logger.warn(`Directory &C4${this.absoluteOutDir}&R not found.`);
|
|
37
|
+
const files = await File.getAllFiles(this.absoluteOutDir, PathResolver.EXTENSIONS);
|
|
38
|
+
let rewrittenCount = 0;
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
if (await this.processFile(file, mode))
|
|
41
|
+
rewrittenCount++;
|
|
42
|
+
}
|
|
43
|
+
this.logger.log(`&C2Path aliases resolved in &C3${rewrittenCount} &C2files.`);
|
|
44
|
+
}
|
|
45
|
+
async processFile(file, mode) {
|
|
46
|
+
try {
|
|
47
|
+
const content = await fs.readFile(file, 'utf8');
|
|
48
|
+
const newContent = this.rewriter.rewrite(content, file, mode);
|
|
49
|
+
if (content === newContent)
|
|
50
|
+
return false;
|
|
51
|
+
await fs.writeFile(file, newContent, 'utf8');
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.logger.error(`Failed to process file &C4${file}:`, error.message);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async watch(mode) {
|
|
60
|
+
await this.rewritePaths(mode);
|
|
61
|
+
this.logger.log(`&C2Watching for changes in &C4${this.absoluteOutDir}...`);
|
|
62
|
+
const debouncedProcessor = Utils.debounce(async (fullPath, filename) => {
|
|
63
|
+
if (await this.processFile(fullPath, mode)) {
|
|
64
|
+
this.logger.log(`&C2File &C4${filename}&C2 updated.`);
|
|
65
|
+
}
|
|
66
|
+
}, 300);
|
|
67
|
+
syncFs.watch(this.absoluteOutDir, { recursive: true }, (eventType, filename) => {
|
|
68
|
+
if (!filename)
|
|
69
|
+
return;
|
|
70
|
+
const isTargetExtension = PathResolver.EXTENSIONS.some(ext => filename.endsWith(ext));
|
|
71
|
+
if (!isTargetExtension)
|
|
72
|
+
return;
|
|
73
|
+
const fullPath = path.join(this.absoluteOutDir, filename);
|
|
74
|
+
debouncedProcessor(fullPath, filename);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export default PathResolver;
|
|
79
|
+
//# sourceMappingURL=PathResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathResolver.js","sourceRoot":"","sources":["../../../src/support/Resolver/PathResolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,MAAM,EAAE,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,IAAI,MAAM,YAAY,CAAC;AAG9B,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAE/C,MAAM,OAAO,YAAY;IAUD;IACA;IAVb,MAAM,CAAU,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7C,MAAM,CAAU,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhD,MAAM,CAAS;IACf,QAAQ,CAAe;IACvB,cAAc,CAAS;IAC1B,OAAO,CAAgC;IAEvD,YACoB,MAA+B,EAC/B,UAAgC,EAAE;QADlC,WAAM,GAAN,MAAM,CAAyB;QAC/B,YAAO,GAAP,OAAO,CAA2B;QAElD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;QAEvE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC1C,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC;YACjD,CAA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EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC;;AAUL,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import AliasCompiler from "./AliasCompiler.js";
|
|
2
|
+
export declare class PathRewriter {
|
|
3
|
+
private readonly aliases;
|
|
4
|
+
private readonly projectRoot;
|
|
5
|
+
static readonly IMPORT_REGEX: RegExp;
|
|
6
|
+
constructor(aliases: AliasCompiler.CompiledAlias[], projectRoot: string);
|
|
7
|
+
rewrite(content: string, filePath: string, mode: 'local' | 'cdn'): string;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace PathRewriter { }
|
|
10
|
+
export default PathRewriter;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Utilities } from "vortez";
|
|
3
|
+
export class PathRewriter {
|
|
4
|
+
aliases;
|
|
5
|
+
projectRoot;
|
|
6
|
+
static IMPORT_REGEX = /(from\s+['"])([^'"]+)(['"])/g;
|
|
7
|
+
constructor(aliases, projectRoot) {
|
|
8
|
+
this.aliases = aliases;
|
|
9
|
+
this.projectRoot = projectRoot;
|
|
10
|
+
}
|
|
11
|
+
rewrite(content, filePath, mode) {
|
|
12
|
+
return content.replace(PathRewriter.IMPORT_REGEX, (match, prefix, modulePath, suffix) => {
|
|
13
|
+
const aliasCfg = this.aliases.find(c => c.isWildcard ? modulePath.startsWith(`${c.alias}/`) : modulePath === c.alias);
|
|
14
|
+
if (!aliasCfg)
|
|
15
|
+
return match;
|
|
16
|
+
const isCDN = mode === 'cdn' && aliasCfg.targets.cdn;
|
|
17
|
+
const baseTarget = isCDN ? aliasCfg.targets.cdn : aliasCfg.targets.local;
|
|
18
|
+
let resolvedPath;
|
|
19
|
+
if (aliasCfg.isWildcard) {
|
|
20
|
+
const subPath = modulePath.substring(aliasCfg.alias.length + 1);
|
|
21
|
+
resolvedPath = isCDN
|
|
22
|
+
? `${baseTarget.replace(/\/$/, '')}/${subPath}`
|
|
23
|
+
: path.join(baseTarget, subPath);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
resolvedPath = baseTarget;
|
|
27
|
+
}
|
|
28
|
+
if (isCDN)
|
|
29
|
+
return `${prefix}${resolvedPath}${suffix}`;
|
|
30
|
+
const currentFileDir = path.dirname(filePath);
|
|
31
|
+
let relativeTarget = path.relative(currentFileDir, resolvedPath);
|
|
32
|
+
if (!relativeTarget.startsWith('.'))
|
|
33
|
+
relativeTarget = `./${relativeTarget}`;
|
|
34
|
+
return `${prefix}${Utilities.Path.normalize(relativeTarget)}${suffix}`;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export default PathRewriter;
|
|
39
|
+
//# sourceMappingURL=PathRewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathRewriter.js","sourceRoot":"","sources":["../../../src/support/Resolver/PathRewriter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,MAAM,OAAO,YAAY;IAGA;IACA;IAHd,MAAM,CAAU,YAAY,GAAG,8BAA8B,CAAC;IACrE,YACqB,OAAsC,EACtC,WAAmB;QADnB,YAAO,GAAP,OAAO,CAA+B;QACtC,gBAAW,GAAX,WAAW,CAAQ;IACrC,CAAC;IAEG,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAqB;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;YACpF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,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;;AAGL,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class Utils {
|
|
2
|
+
static readonly WILDCARD_SUFFIX_REGEX: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given alias string ends with a wildcard suffix (either "/*" or "/"), indicating that it is a wildcard alias.
|
|
5
|
+
* This method is used to determine whether an alias should be treated as a wildcard mapping, which allows for matching multiple paths under the same base alias.
|
|
6
|
+
* @param alias The alias string to check (e.g., "components/*" or "utils/").
|
|
7
|
+
* @returns True if the alias ends with a wildcard suffix, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
static isWildcard(alias: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard.
|
|
12
|
+
* This is useful for normalizing aliases when processing them, allowing the resolver to work with a consistent format regardless of whether the original alias was defined as a wildcard or not.
|
|
13
|
+
* @param pathStr The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
|
|
14
|
+
* @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
|
|
15
|
+
*/
|
|
16
|
+
static removeWildcardSuffix(pathStr: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that a given alias string has a wildcard suffix (i.e., ends with "/*"). If the input string already ends with "/*" or "/", it will be normalized to end with "/*".
|
|
19
|
+
* If it does not end with either, "/*" will be appended to the end of the string.
|
|
20
|
+
* This method is useful for standardizing alias definitions when they are intended to be wildcard mappings.
|
|
21
|
+
* @param pathStr The alias string to ensure has a wildcard suffix (e.g., "components", "utils/", or "services/*").
|
|
22
|
+
* @returns The alias string guaranteed to end with "/*" (e.g., "components/*", "utils/*", or "services/*").
|
|
23
|
+
*/
|
|
24
|
+
static ensureTsWildcard(pathStr: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Ensures that a given alias string has a trailing slash (i.e., ends with "/"). If the input string already ends with "/*" or "/", it will be normalized to end with "/".
|
|
27
|
+
* If it does not end with either, "/" will be appended to the end of the string.
|
|
28
|
+
* This method is useful for standardizing alias definitions when they are intended to be directory mappings without the wildcard.
|
|
29
|
+
* @param pathStr The alias string to ensure has a trailing slash (e.g., "components", "utils/", or "services/*").
|
|
30
|
+
* @returns The alias string guaranteed to end with "/" (e.g., "components/", "utils/", or "services/").
|
|
31
|
+
*/
|
|
32
|
+
static ensureTrailingSlash(pathStr: string): string;
|
|
33
|
+
}
|
|
34
|
+
export declare namespace Utils {
|
|
35
|
+
}
|
|
36
|
+
export default Utils;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class Utils {
|
|
2
|
+
static WILDCARD_SUFFIX_REGEX = /\/\*?$/;
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given alias string ends with a wildcard suffix (either "/*" or "/"), indicating that it is a wildcard alias.
|
|
5
|
+
* This method is used to determine whether an alias should be treated as a wildcard mapping, which allows for matching multiple paths under the same base alias.
|
|
6
|
+
* @param alias The alias string to check (e.g., "components/*" or "utils/").
|
|
7
|
+
* @returns True if the alias ends with a wildcard suffix, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
static isWildcard(alias) {
|
|
10
|
+
return this.WILDCARD_SUFFIX_REGEX.test(alias);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard.
|
|
14
|
+
* This is useful for normalizing aliases when processing them, allowing the resolver to work with a consistent format regardless of whether the original alias was defined as a wildcard or not.
|
|
15
|
+
* @param pathStr The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
|
|
16
|
+
* @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
|
|
17
|
+
*/
|
|
18
|
+
static removeWildcardSuffix(pathStr) {
|
|
19
|
+
return pathStr.replace(this.WILDCARD_SUFFIX_REGEX, '');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Ensures that a given alias string has a wildcard suffix (i.e., ends with "/*"). If the input string already ends with "/*" or "/", it will be normalized to end with "/*".
|
|
23
|
+
* If it does not end with either, "/*" will be appended to the end of the string.
|
|
24
|
+
* This method is useful for standardizing alias definitions when they are intended to be wildcard mappings.
|
|
25
|
+
* @param pathStr The alias string to ensure has a wildcard suffix (e.g., "components", "utils/", or "services/*").
|
|
26
|
+
* @returns The alias string guaranteed to end with "/*" (e.g., "components/*", "utils/*", or "services/*").
|
|
27
|
+
*/
|
|
28
|
+
static ensureTsWildcard(pathStr) {
|
|
29
|
+
const clean = this.removeWildcardSuffix(pathStr);
|
|
30
|
+
return `${clean}/*`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Ensures that a given alias string has a trailing slash (i.e., ends with "/"). If the input string already ends with "/*" or "/", it will be normalized to end with "/".
|
|
34
|
+
* If it does not end with either, "/" will be appended to the end of the string.
|
|
35
|
+
* This method is useful for standardizing alias definitions when they are intended to be directory mappings without the wildcard.
|
|
36
|
+
* @param pathStr The alias string to ensure has a trailing slash (e.g., "components", "utils/", or "services/*").
|
|
37
|
+
* @returns The alias string guaranteed to end with "/" (e.g., "components/", "utils/", or "services/").
|
|
38
|
+
*/
|
|
39
|
+
static ensureTrailingSlash(pathStr) {
|
|
40
|
+
const clean = this.removeWildcardSuffix(pathStr);
|
|
41
|
+
return `${clean}/`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export default Utils;
|
|
45
|
+
//# sourceMappingURL=Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/support/Resolver/Utils.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACP,MAAM,CAAU,qBAAqB,GAAG,QAAQ,CAAC;IACxD;;;;;OAKG;IACI,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,oBAAoB,CAAC,OAAe;QAC9C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAAC,OAAe;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,GAAG,KAAK,IAAI,CAAC;IACxB,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,mBAAmB,CAAC,OAAe;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,GAAG,KAAK,GAAG,CAAC;IACvB,CAAC;;AAKL,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class Utils {
|
|
2
|
+
protected static REPO_REGEX: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Extracts a repository name from its URL.
|
|
5
|
+
* @param repo - The repository URL.
|
|
6
|
+
* @returns The repository name.
|
|
7
|
+
*/
|
|
8
|
+
static getRepoName: (repo: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Extracts the value(s) of a specified flag from an array of command-line arguments.
|
|
11
|
+
* @param args - The array of command-line arguments.
|
|
12
|
+
* @param flag - The flag to search for (e.g., '-p' or '--project').
|
|
13
|
+
* @param multiple - Whether to allow multiple values for the same flag.
|
|
14
|
+
* @returns An array of values associated with the specified flag.
|
|
15
|
+
*/
|
|
16
|
+
static getFlagValue(args: string[], flag: string, multiple?: boolean): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Adds JSON schema validation for a specified file in Visual Studio Code by creating or updating the settings.json file in the .vscode directory.
|
|
19
|
+
* It ensures that the provided schema object is saved locally and referenced correctly in the VSCode settings, allowing for enhanced editing support such as autocompletion and validation based on the defined schema when working with the specified file.
|
|
20
|
+
* @param flowPath The file path to which the JSON schema validation should be applied (e.g., 'depflow.json').
|
|
21
|
+
* @param schemaObject The JSON schema object that defines the structure and validation rules for the specified file.
|
|
22
|
+
* @returns A promise that resolves to true if the operation was successful, or false if an error occurred during the process.
|
|
23
|
+
*/
|
|
24
|
+
static addVscodeValidation(flowPath: string, schemaObject: object): Promise<boolean>;
|
|
25
|
+
static debounce<Args extends any[]>(fn: Utils.DebouncedFunction<Args>, delay: number): Utils.DebouncedFunction<Args>;
|
|
26
|
+
}
|
|
27
|
+
export declare namespace Utils {
|
|
28
|
+
type DebouncedFunction<Args extends any[]> = (...args: Args) => void;
|
|
29
|
+
}
|
|
30
|
+
export default Utils;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { File, Path } from '@netfeez/common-node';
|
|
2
|
+
export class Utils {
|
|
3
|
+
static REPO_REGEX = /^(?:https:\/\/github\.com\/([^/]+)\/([^/.]+)(?:\.git)?|git@github\.com:([^/]+)\/([^/.]+)(?:\.git)?)$/;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts a repository name from its URL.
|
|
6
|
+
* @param repo - The repository URL.
|
|
7
|
+
* @returns The repository name.
|
|
8
|
+
*/
|
|
9
|
+
static getRepoName = (repo) => {
|
|
10
|
+
const match = repo.match(Utils.REPO_REGEX);
|
|
11
|
+
if (match) {
|
|
12
|
+
const user = match[1] || match[3];
|
|
13
|
+
const repoName = match[2] || match[4];
|
|
14
|
+
return `${user}.${repoName}`;
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Invalid repository URL: "${repo}"`);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the value(s) of a specified flag from an array of command-line arguments.
|
|
20
|
+
* @param args - The array of command-line arguments.
|
|
21
|
+
* @param flag - The flag to search for (e.g., '-p' or '--project').
|
|
22
|
+
* @param multiple - Whether to allow multiple values for the same flag.
|
|
23
|
+
* @returns An array of values associated with the specified flag.
|
|
24
|
+
*/
|
|
25
|
+
static getFlagValue(args, flag, multiple = false) {
|
|
26
|
+
const values = [];
|
|
27
|
+
for (const index in args) {
|
|
28
|
+
const value = args[index];
|
|
29
|
+
if (value === flag) {
|
|
30
|
+
const nextValue = args[Number(index) + 1];
|
|
31
|
+
if (nextValue && !nextValue.startsWith('-')) {
|
|
32
|
+
values.push(nextValue);
|
|
33
|
+
if (!multiple)
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return values;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds JSON schema validation for a specified file in Visual Studio Code by creating or updating the settings.json file in the .vscode directory.
|
|
42
|
+
* It ensures that the provided schema object is saved locally and referenced correctly in the VSCode settings, allowing for enhanced editing support such as autocompletion and validation based on the defined schema when working with the specified file.
|
|
43
|
+
* @param flowPath The file path to which the JSON schema validation should be applied (e.g., 'depflow.json').
|
|
44
|
+
* @param schemaObject The JSON schema object that defines the structure and validation rules for the specified file.
|
|
45
|
+
* @returns A promise that resolves to true if the operation was successful, or false if an error occurred during the process.
|
|
46
|
+
*/
|
|
47
|
+
static async addVscodeValidation(flowPath, schemaObject) {
|
|
48
|
+
const root = process.cwd();
|
|
49
|
+
const internalDir = Path.join(root, '.depflow');
|
|
50
|
+
const schemaLocalPath = Path.join(internalDir, 'schema.json');
|
|
51
|
+
const vscodeDir = Path.join(root, '.vscode');
|
|
52
|
+
const settingsPath = Path.join(vscodeDir, 'settings.json');
|
|
53
|
+
try {
|
|
54
|
+
if (!await File.exists(internalDir))
|
|
55
|
+
await File.mkdir(internalDir, { recursive: true });
|
|
56
|
+
await File.write(schemaLocalPath, JSON.stringify(schemaObject, null, 4));
|
|
57
|
+
if (!await File.exists(vscodeDir))
|
|
58
|
+
await File.mkdir(vscodeDir, { recursive: true });
|
|
59
|
+
let settings = {};
|
|
60
|
+
if (await File.exists(settingsPath)) {
|
|
61
|
+
try {
|
|
62
|
+
settings = JSON.parse(await File.read(settingsPath));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
settings = {};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!settings['json.schemas'])
|
|
69
|
+
settings['json.schemas'] = [];
|
|
70
|
+
const relativeSchema = './.depflow/schema.json';
|
|
71
|
+
const hasSchema = settings['json.schemas'].some((s) => s.fileMatch && s.fileMatch.includes(flowPath));
|
|
72
|
+
if (hasSchema)
|
|
73
|
+
return true;
|
|
74
|
+
settings['json.schemas'].push({ fileMatch: [flowPath], url: relativeSchema });
|
|
75
|
+
await File.write(settingsPath, JSON.stringify(settings, null, 4));
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
static debounce(fn, delay) {
|
|
83
|
+
let timeoutId = null;
|
|
84
|
+
return function (...args) {
|
|
85
|
+
if (timeoutId)
|
|
86
|
+
clearTimeout(timeoutId);
|
|
87
|
+
timeoutId = setTimeout(() => {
|
|
88
|
+
fn.apply(this, args);
|
|
89
|
+
timeoutId = null;
|
|
90
|
+
}, delay);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export default Utils;
|
|
95
|
+
//# sourceMappingURL=Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../src/support/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,OAAO,KAAK;IACJ,MAAM,CAAC,UAAU,GAAG,sGAAsG,CAAC;IACrI;;;;OAIG;IACI,MAAM,CAAC,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC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E,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC;YAE9E,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;IACrC,CAAC;IACM,MAAM,CAAC,QAAQ,CAClB,EAAiC,EACjC,KAAa;QAEb,IAAI,SAAS,GAA0B,IAAI,CAAC;QAE5C,OAAO,UAAoB,GAAG,IAAU;YACpC,IAAI,SAAS;gBAAE,YAAY,CAAC,SAAS,CAAC,CAAC;YAEvC,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;gBACxB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACrB,SAAS,GAAG,IAAI,CAAC;YACrB,CAAC,EAAE,KAAK,CAAC,CAAC;QACd,CAAC,CAAC;IACN,CAAC;;AAKL,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class Validator {
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the provided repository URL is a non-empty string and matches common Git repository URL patterns. It checks for both HTTPS and SSH formats, ensuring that the URL is well-formed and points to a valid Git repository.
|
|
4
|
+
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided repository URL.
|
|
5
|
+
* @param repo The repository URL to validate.
|
|
6
|
+
* @throws Will throw an error if the repository URL is invalid.
|
|
7
|
+
*/
|
|
8
|
+
static validateRepo(repo: unknown): asserts repo is Validator.Repo;
|
|
9
|
+
/**
|
|
10
|
+
* Validates that the provided name is a non-empty string.
|
|
11
|
+
* It checks if the name is of type string and contains non-whitespace characters.
|
|
12
|
+
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided name.
|
|
13
|
+
* @param name The name to validate.
|
|
14
|
+
* @throws Will throw an error if the name is invalid.
|
|
15
|
+
*/
|
|
16
|
+
static validateName(name: unknown): asserts name is Validator.name;
|
|
17
|
+
}
|
|
18
|
+
export declare namespace Validator {
|
|
19
|
+
type Repo = `https://github.com/${string}/${string}.git` | `git@github.com:${string}/${string}.git`;
|
|
20
|
+
type name = string;
|
|
21
|
+
}
|
|
22
|
+
export default Validator;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class Validator {
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the provided repository URL is a non-empty string and matches common Git repository URL patterns. It checks for both HTTPS and SSH formats, ensuring that the URL is well-formed and points to a valid Git repository.
|
|
4
|
+
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided repository URL.
|
|
5
|
+
* @param repo The repository URL to validate.
|
|
6
|
+
* @throws Will throw an error if the repository URL is invalid.
|
|
7
|
+
*/
|
|
8
|
+
static validateRepo(repo) {
|
|
9
|
+
if (typeof repo !== 'string' || !repo.trim())
|
|
10
|
+
throw new Error(`Invalid repository URL: "${repo}"`);
|
|
11
|
+
const gitRegex = /^(?:(?:https?|git|ssh|rsync|file|git@[-\w.]+):(\/\/)?)([\w.@:/\-~]+)(\.git)(\/)?$/;
|
|
12
|
+
if (!gitRegex.test(repo))
|
|
13
|
+
throw new Error(`Invalid repository URL: ${repo}`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates that the provided name is a non-empty string.
|
|
17
|
+
* It checks if the name is of type string and contains non-whitespace characters.
|
|
18
|
+
* If the validation fails, it throws an error with a descriptive message indicating the issue with the provided name.
|
|
19
|
+
* @param name The name to validate.
|
|
20
|
+
* @throws Will throw an error if the name is invalid.
|
|
21
|
+
*/
|
|
22
|
+
static validateName(name) {
|
|
23
|
+
if (typeof name !== 'string' || !name.trim())
|
|
24
|
+
throw new Error(`Invalid dependency name: "${name}"`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default Validator;
|
|
28
|
+
//# sourceMappingURL=Validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../src/support/Validator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAClB;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,IAAa;QAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC;QACnG,MAAM,QAAQ,GAAG,mFAAmF,CAAC;QACrG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IACD;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,IAAa;QAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,GAAG,CAAC,CAAC;IACxG,CAAC;CACJ;AAKD,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "depflow",
|
|
3
3
|
"description": "is a simple dependency manager based on github repositories",
|
|
4
|
-
"version": "2.0.0-dev.
|
|
4
|
+
"version": "2.0.0-dev.3",
|
|
5
5
|
"main": "build/bin/bin.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"dep": "build/
|
|
8
|
+
"dep": "build/cli/bin.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "npx tsc --watch",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@netfeez/common": "^2.1.0",
|
|
37
|
-
"
|
|
37
|
+
"@netfeez/common-node": "^1.0.1",
|
|
38
|
+
"@netfeez/vterm": "^1.0.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/node": "^25.6.0",
|
package/build/Config.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
-
* @description Utility to help with File operations.
|
|
4
|
-
* @license Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import schemas from './schemas.js';
|
|
7
|
-
export declare class Config {
|
|
8
|
-
static load(path: string): Promise<Config.Config>;
|
|
9
|
-
static save(path: string, config: Config.ConfigToProcess): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare namespace Config {
|
|
12
|
-
type Config = typeof schemas.config.infer;
|
|
13
|
-
type ConfigToProcess = typeof schemas.config.inferToProcess;
|
|
14
|
-
}
|
|
15
|
-
export default Config;
|
package/build/Config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author NetFeez <netfeez.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 schemas from './schemas.js';
|
|
8
|
-
export class Config {
|
|
9
|
-
static async load(path) {
|
|
10
|
-
const content = await FS.readFile(path, 'utf-8');
|
|
11
|
-
const json = JSON.parse(content);
|
|
12
|
-
const config = schemas.config.processData(json);
|
|
13
|
-
return config;
|
|
14
|
-
}
|
|
15
|
-
static async save(path, config) {
|
|
16
|
-
const content = JSON.stringify(config, null, 2);
|
|
17
|
-
await FS.writeFile(path, content, 'utf-8');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export default Config;
|
|
21
|
-
//# sourceMappingURL=Config.js.map
|
package/build/Config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../src/Config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,OAAO,MAAM;IACf,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC1B,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,MAA8B;QAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAChD,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;CACJ;AAMD,eAAe,MAAM,CAAC"}
|
package/build/Dependency.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
-
import schemas from "./schemas.js";
|
|
3
|
-
export declare class Dependency implements Dependency.Dependency {
|
|
4
|
-
static include: string[];
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly repo: Dependency.repo;
|
|
7
|
-
readonly branch?: string;
|
|
8
|
-
readonly builder: Dependency.Builder[];
|
|
9
|
-
/**
|
|
10
|
-
* Create a new dependency
|
|
11
|
-
* @param dependency Dependency to create
|
|
12
|
-
* @param logger Logger to use
|
|
13
|
-
* @returns New dependency
|
|
14
|
-
*/
|
|
15
|
-
constructor(dependency: Dependency.Dependency);
|
|
16
|
-
/** Get the folder of the dependency */
|
|
17
|
-
get folder(): string;
|
|
18
|
-
/**
|
|
19
|
-
* Clone a dependency
|
|
20
|
-
* @param options Options to use
|
|
21
|
-
* @returns Promise<void>
|
|
22
|
-
*/
|
|
23
|
-
clone(options?: Dependency.manageOptions): Promise<string>;
|
|
24
|
-
/**
|
|
25
|
-
* Pull a dependency
|
|
26
|
-
* @returns Promise<void>
|
|
27
|
-
*/
|
|
28
|
-
pull(): Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* Install a dependency
|
|
31
|
-
* @param options Options to use
|
|
32
|
-
* @returns Promise<void>
|
|
33
|
-
*/
|
|
34
|
-
install(): Promise<string[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Uninstall a dependency
|
|
37
|
-
* @returns Promise<void>
|
|
38
|
-
*/
|
|
39
|
-
uninstall(): Promise<string[]>;
|
|
40
|
-
protected build(): Promise<string[]>;
|
|
41
|
-
protected move(move: Dependency.Builder['move']): Promise<string[]>;
|
|
42
|
-
/**
|
|
43
|
-
* Execute multiple commands in a shell
|
|
44
|
-
* @param commands Commands to execute
|
|
45
|
-
* @param customShell Custom shell to use (optional)
|
|
46
|
-
* @returns Output of the commands
|
|
47
|
-
*/
|
|
48
|
-
protected executeCommands(commands: string[], shell: ChildProcessWithoutNullStreams): Promise<string[]>;
|
|
49
|
-
/**
|
|
50
|
-
* Execute a command in a shell
|
|
51
|
-
* @param shell Shell to execute the command in
|
|
52
|
-
* @param command Command to execute
|
|
53
|
-
* @returns Output of the command
|
|
54
|
-
*/
|
|
55
|
-
protected executeCommand(shell: ChildProcessWithoutNullStreams, command: string): Promise<string[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Move files from a dependency
|
|
58
|
-
* @param destination Destination folder
|
|
59
|
-
* @param source Source folder
|
|
60
|
-
* @returns The output of the operation
|
|
61
|
-
*/
|
|
62
|
-
protected moveFiles(destination: string | string[], source?: string): Promise<string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Get the source path of a dependency
|
|
65
|
-
* @param source Source path
|
|
66
|
-
* @returns Source path
|
|
67
|
-
*/
|
|
68
|
-
static getSourcePath(folder: string, source?: string): string;
|
|
69
|
-
/**
|
|
70
|
-
* Get all folders of a dependency
|
|
71
|
-
* @param builder Builder to get folders from
|
|
72
|
-
* @returns Folders
|
|
73
|
-
*/
|
|
74
|
-
static getAllOutFolders(builder: Dependency.Builder['move']): string[];
|
|
75
|
-
}
|
|
76
|
-
export declare namespace Dependency {
|
|
77
|
-
type logCallback = (messages: string[]) => void;
|
|
78
|
-
type repo = `https://github.com/${string}/${string}.git` | `git@github.com:${string}/${string}.git`;
|
|
79
|
-
type Builder = schemas.builder['inferToProcess'];
|
|
80
|
-
type Dependency = schemas.dependency['infer'];
|
|
81
|
-
type newDependency = schemas.dependency['inferToProcess'];
|
|
82
|
-
interface manageOptions {
|
|
83
|
-
force?: boolean;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export default Dependency;
|