depflow 1.1.1 → 2.0.0-dev.1
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/Config.d.ts +15 -0
- package/build/Config.js +21 -0
- package/build/Config.js.map +1 -0
- package/build/Dependency.d.ts +8 -21
- package/build/Dependency.js +7 -1
- package/build/Dependency.js.map +1 -1
- package/build/File.d.ts +5 -41
- package/build/File.js +19 -91
- package/build/File.js.map +1 -1
- package/build/Git.d.ts +1 -1
- package/build/Git.js +1 -1
- package/build/PathFixer.d.ts +9 -9
- package/build/PathFixer.js +56 -72
- package/build/PathFixer.js.map +1 -1
- package/build/Tsconfig.d.ts +13 -0
- package/build/Tsconfig.js +16 -0
- package/build/Tsconfig.js.map +1 -0
- package/build/Utils.d.ts +16 -0
- package/build/Utils.js +40 -0
- package/build/Utils.js.map +1 -0
- package/build/Validator.d.ts +6 -51
- package/build/Validator.js +8 -143
- package/build/Validator.js.map +1 -1
- package/build/bin/DepFLowCLI.d.ts +13 -0
- package/build/bin/DepFLowCLI.js +169 -0
- package/build/bin/DepFLowCLI.js.map +1 -0
- package/build/bin/bin.d.ts +2 -0
- package/build/bin/bin.js +26 -0
- package/build/bin/bin.js.map +1 -0
- package/build/bin.d.ts +0 -5
- package/build/bin.js +4 -219
- package/build/bin.js.map +1 -1
- package/build/schemas.d.ts +296 -0
- package/build/schemas.js +29 -0
- package/build/schemas.js.map +1 -0
- package/package.json +11 -10
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
2
|
+
import schemas from "./schemas.js";
|
|
2
3
|
export declare class Dependency implements Dependency.Dependency {
|
|
3
4
|
static include: string[];
|
|
4
5
|
readonly name: string;
|
|
5
6
|
readonly repo: Dependency.repo;
|
|
6
7
|
readonly branch?: string;
|
|
7
|
-
readonly builder
|
|
8
|
+
readonly builder: Dependency.Builder[];
|
|
8
9
|
/**
|
|
9
10
|
* Create a new dependency
|
|
10
11
|
* @param dependency Dependency to create
|
|
@@ -37,7 +38,7 @@ export declare class Dependency implements Dependency.Dependency {
|
|
|
37
38
|
*/
|
|
38
39
|
uninstall(): Promise<string[]>;
|
|
39
40
|
protected build(): Promise<string[]>;
|
|
40
|
-
protected move(move: Dependency.Builder
|
|
41
|
+
protected move(move: Dependency.Builder['move']): Promise<string[]>;
|
|
41
42
|
/**
|
|
42
43
|
* Execute multiple commands in a shell
|
|
43
44
|
* @param commands Commands to execute
|
|
@@ -70,28 +71,14 @@ export declare class Dependency implements Dependency.Dependency {
|
|
|
70
71
|
* @param builder Builder to get folders from
|
|
71
72
|
* @returns Folders
|
|
72
73
|
*/
|
|
73
|
-
static getAllOutFolders(builder: Dependency.Builder
|
|
74
|
+
static getAllOutFolders(builder: Dependency.Builder['move']): string[];
|
|
74
75
|
}
|
|
75
76
|
export declare namespace Dependency {
|
|
76
77
|
type logCallback = (messages: string[]) => void;
|
|
77
|
-
type repo = `https://github.com/${string}/${string}.git`;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
type MoveType = string | string[] | Move;
|
|
83
|
-
interface Step {
|
|
84
|
-
run?: string | string[] | undefined;
|
|
85
|
-
move?: MoveType;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
type Builder = Builder.Step[];
|
|
89
|
-
interface Dependency {
|
|
90
|
-
name: string;
|
|
91
|
-
repo: repo;
|
|
92
|
-
branch?: string;
|
|
93
|
-
builder?: Builder;
|
|
94
|
-
}
|
|
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'];
|
|
95
82
|
interface manageOptions {
|
|
96
83
|
force?: boolean;
|
|
97
84
|
}
|
package/build/Dependency.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author NetFeez <
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
3
|
* @description Dependency utility.
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
@@ -7,6 +7,7 @@ import { promises as FS } from "fs";
|
|
|
7
7
|
import { spawn } from "child_process";
|
|
8
8
|
import Git from "./Git.js";
|
|
9
9
|
import File from "./File.js";
|
|
10
|
+
import Validator from "./Validator.js";
|
|
10
11
|
export class Dependency {
|
|
11
12
|
static include = ['*'];
|
|
12
13
|
name;
|
|
@@ -20,6 +21,7 @@ export class Dependency {
|
|
|
20
21
|
* @returns New dependency
|
|
21
22
|
*/
|
|
22
23
|
constructor(dependency) {
|
|
24
|
+
Validator.validateRepo(dependency.repo);
|
|
23
25
|
this.name = dependency.name;
|
|
24
26
|
this.repo = dependency.repo;
|
|
25
27
|
this.branch = dependency.branch;
|
|
@@ -123,6 +125,8 @@ export class Dependency {
|
|
|
123
125
|
return output;
|
|
124
126
|
}
|
|
125
127
|
async move(move) {
|
|
128
|
+
if (!move)
|
|
129
|
+
return [];
|
|
126
130
|
const output = [];
|
|
127
131
|
if (typeof move === 'string' || Array.isArray(move)) {
|
|
128
132
|
const moves = Array.isArray(move) ? move : [move];
|
|
@@ -241,6 +245,8 @@ export class Dependency {
|
|
|
241
245
|
* @returns Folders
|
|
242
246
|
*/
|
|
243
247
|
static getAllOutFolders(builder) {
|
|
248
|
+
if (!builder)
|
|
249
|
+
return [];
|
|
244
250
|
const folders = [];
|
|
245
251
|
if (typeof builder === 'string')
|
|
246
252
|
folders.push(builder);
|
package/build/Dependency.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dependency.js","sourceRoot":"","sources":["../src/Dependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAgD,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpF,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,OAAO,UAAU;IACZ,MAAM,CAAC,OAAO,GAAa,CAAE,GAAG,CAAE,CAAC;IAC1B,IAAI,CAAS;IACb,IAAI,CAAkB;IACtB,MAAM,CAAU;IAChB,OAAO,
|
|
1
|
+
{"version":3,"file":"Dependency.js","sourceRoot":"","sources":["../src/Dependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAgD,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpF,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,UAAU;IACZ,MAAM,CAAC,OAAO,GAAa,CAAE,GA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I,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IACD;;;;OAIG;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;;AAYL,eAAe,UAAU,CAAC"}
|
package/build/File.d.ts
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
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
1
|
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
2
|
static exists(path: string): Promise<boolean>;
|
|
3
|
+
static isFile(path: string): Promise<boolean>;
|
|
4
|
+
static isDirectory(path: string): Promise<boolean>;
|
|
5
|
+
static read(path: string): Promise<string>;
|
|
6
|
+
static write(path: string, content: string): Promise<void>;
|
|
44
7
|
}
|
|
8
|
+
export declare namespace File { }
|
|
45
9
|
export default File;
|
package/build/File.js
CHANGED
|
@@ -1,113 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author NetFeez <codefeez.dev@gmail.com>
|
|
3
|
-
* @description Utility to help with File operations.
|
|
4
|
-
* @license Apache-2.0
|
|
5
|
-
*/
|
|
6
1
|
import { promises as FS } from 'fs';
|
|
7
|
-
import Validator from './Validator.js';
|
|
8
2
|
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) {
|
|
3
|
+
static async exists(path) {
|
|
61
4
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
5
|
+
await FS.access(path);
|
|
6
|
+
return true;
|
|
78
7
|
}
|
|
79
|
-
catch
|
|
80
|
-
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
81
10
|
}
|
|
82
11
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if a file exists
|
|
85
|
-
* @param path Path to check
|
|
86
|
-
* @returns Promise<boolean>
|
|
87
|
-
*/
|
|
88
12
|
static async isFile(path) {
|
|
89
13
|
try {
|
|
90
|
-
const
|
|
91
|
-
return
|
|
14
|
+
const stat = await FS.stat(path);
|
|
15
|
+
return stat.isFile();
|
|
92
16
|
}
|
|
93
17
|
catch {
|
|
94
18
|
return false;
|
|
95
19
|
}
|
|
96
20
|
}
|
|
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) {
|
|
21
|
+
static async isDirectory(path) {
|
|
103
22
|
try {
|
|
104
|
-
await FS.
|
|
105
|
-
return
|
|
23
|
+
const stat = await FS.stat(path);
|
|
24
|
+
return stat.isDirectory();
|
|
106
25
|
}
|
|
107
26
|
catch {
|
|
108
27
|
return false;
|
|
109
28
|
}
|
|
110
29
|
}
|
|
30
|
+
static async read(path) {
|
|
31
|
+
if (!await this.isFile(path)) {
|
|
32
|
+
throw new Error(`Path ${path} is not a file.`);
|
|
33
|
+
}
|
|
34
|
+
return await FS.readFile(path, 'utf-8');
|
|
35
|
+
}
|
|
36
|
+
static async write(path, content) {
|
|
37
|
+
await FS.writeFile(path, content, 'utf-8');
|
|
38
|
+
}
|
|
111
39
|
}
|
|
112
40
|
export default File;
|
|
113
41
|
//# sourceMappingURL=File.js.map
|
package/build/File.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.js","sourceRoot":"","sources":["../src/File.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"File.js","sourceRoot":"","sources":["../src/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,OAAO,IAAI;IACb,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY;QAC5B,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;IACD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY;QAC5B,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;IAC7B,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAY;QACjC,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;IAC7B,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC1B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,iBAAiB,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAAe;QAC5C,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;CACJ;AAID,eAAe,IAAI,CAAC"}
|
package/build/Git.d.ts
CHANGED
package/build/Git.js
CHANGED
package/build/PathFixer.d.ts
CHANGED
|
@@ -2,34 +2,34 @@ export declare class PathFixer {
|
|
|
2
2
|
readonly info: PathFixer.ProjectInfo;
|
|
3
3
|
readonly projectRoot: string;
|
|
4
4
|
static readonly IMPORT_REGEX: RegExp;
|
|
5
|
-
static readonly DEFAULT_PROJECT_INFO: PathFixer.ProjectInfo;
|
|
6
5
|
static readonly PROJECT_ROOT: string;
|
|
7
6
|
static readonly EXTENSIONS: string[];
|
|
8
7
|
absoluteRoot: string;
|
|
9
|
-
_alias
|
|
10
|
-
constructor(info
|
|
8
|
+
private _alias;
|
|
9
|
+
constructor(info: PathFixer.ProjectInfo, projectRoot?: string);
|
|
11
10
|
get alias(): PathFixer.Alias[];
|
|
12
11
|
run(): Promise<void>;
|
|
13
12
|
watch(): Promise<void>;
|
|
14
13
|
private process;
|
|
15
14
|
private processReplacer;
|
|
16
15
|
watchHandler(queue: Map<string, NodeJS.Timeout>, eventType: string, filename: string): Promise<void>;
|
|
17
|
-
watchTimeout
|
|
16
|
+
private watchTimeout;
|
|
18
17
|
static getAllFiles(dir: string, extensions: string[]): Promise<string[]>;
|
|
19
|
-
static getProjectInfo(tsconfig?: string): Promise<PathFixer.ProjectInfo>;
|
|
20
18
|
}
|
|
21
|
-
declare namespace PathFixer {
|
|
19
|
+
export declare namespace PathFixer {
|
|
22
20
|
interface Paths {
|
|
23
21
|
[alias: string]: string[];
|
|
24
22
|
}
|
|
25
23
|
interface Alias {
|
|
26
24
|
alias: string;
|
|
27
25
|
target: string;
|
|
26
|
+
isWildcard: boolean;
|
|
28
27
|
}
|
|
29
28
|
interface ProjectInfo {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
rootDir?: string;
|
|
31
|
+
outDir: string;
|
|
32
|
+
paths: Paths;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export default PathFixer;
|
package/build/PathFixer.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author NetFeez <
|
|
3
|
-
* @description Utility for path fixing.
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Utility for path fixing with dual support for baseUrl and rootDir.
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import syncFs, { promises as fs } from 'fs';
|
|
8
8
|
import { Logger, Utilities } from 'vortez';
|
|
9
|
+
import File from './File.js';
|
|
9
10
|
const logger = new Logger({ prefix: 'PathFixer' });
|
|
10
11
|
export class PathFixer {
|
|
11
12
|
info;
|
|
12
13
|
projectRoot;
|
|
13
14
|
static IMPORT_REGEX = /(from\s+['"])([^'"]+)(['"])/g;
|
|
14
|
-
static DEFAULT_PROJECT_INFO = { root: 'src', out: 'build', path: {} };
|
|
15
15
|
static PROJECT_ROOT = process.cwd();
|
|
16
16
|
static EXTENSIONS = ['js', '.d.ts'];
|
|
17
17
|
absoluteRoot;
|
|
18
18
|
_alias = null;
|
|
19
|
-
constructor(info
|
|
19
|
+
constructor(info, projectRoot = PathFixer.PROJECT_ROOT) {
|
|
20
20
|
this.info = info;
|
|
21
21
|
this.projectRoot = projectRoot;
|
|
22
|
-
const fullPath = path.
|
|
22
|
+
const fullPath = path.isAbsolute(info.outDir)
|
|
23
|
+
? info.outDir
|
|
24
|
+
: path.join(projectRoot, info.outDir);
|
|
23
25
|
this.absoluteRoot = path.resolve(fullPath);
|
|
24
26
|
}
|
|
25
27
|
get alias() {
|
|
26
28
|
if (this._alias)
|
|
27
29
|
return this._alias;
|
|
28
30
|
const result = [];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
result.push({ alias, target });
|
|
31
|
+
const tsConfigBase = path.resolve(this.projectRoot, this.info.baseUrl || '.');
|
|
32
|
+
const sourceRoot = path.resolve(this.projectRoot, this.info.rootDir || this.info.baseUrl || '.');
|
|
33
|
+
for (const [key, value] of Object.entries(this.info.paths || {})) {
|
|
34
|
+
const isWildcard = key.endsWith('/*');
|
|
35
|
+
const aliasBase = key.replace(/\/\*$/, '');
|
|
36
|
+
const targetRaw = value[0].replace(/\/\*$/, '');
|
|
37
|
+
const absoluteSourceTarget = path.resolve(tsConfigBase, targetRaw);
|
|
38
|
+
const relativeToSourceRoot = path.relative(sourceRoot, absoluteSourceTarget);
|
|
39
|
+
const absoluteBuildTarget = path.resolve(this.absoluteRoot, relativeToSourceRoot);
|
|
40
|
+
result.push({ alias: aliasBase, target: absoluteBuildTarget, isWildcard });
|
|
39
41
|
}
|
|
40
42
|
this._alias = result;
|
|
41
43
|
return result;
|
|
42
44
|
}
|
|
43
45
|
async run() {
|
|
44
|
-
logger.log('&C2Starting path fixer
|
|
45
|
-
if (!await
|
|
46
|
+
logger.log('&C2Starting path fixer...');
|
|
47
|
+
if (!await File.exists(this.absoluteRoot)) {
|
|
46
48
|
return void logger.warn(`The root directory &C4${this.absoluteRoot}&R does not exist.`);
|
|
49
|
+
}
|
|
47
50
|
const files = await PathFixer.getAllFiles(this.absoluteRoot, PathFixer.EXTENSIONS);
|
|
48
|
-
logger.log(`&C2Found &C3${files.length} &C2files
|
|
51
|
+
logger.log(`&C2Found &C3${files.length} &C2files in &C4${this.absoluteRoot}.`);
|
|
52
|
+
console.log(JSON.stringify(this, null, 2));
|
|
49
53
|
let rewrittenCount = 0;
|
|
50
54
|
for (const file of files) {
|
|
51
55
|
const changed = await this.process(file);
|
|
@@ -57,32 +61,44 @@ export class PathFixer {
|
|
|
57
61
|
async watch() {
|
|
58
62
|
await this.run();
|
|
59
63
|
logger.log(`&C2Starting watcher in &C4${this.absoluteRoot}.`);
|
|
60
|
-
if (!await Utilities.fileExists(this.absoluteRoot))
|
|
64
|
+
if (!await Utilities.fileExists(this.absoluteRoot)) {
|
|
61
65
|
await fs.mkdir(this.absoluteRoot, { recursive: true });
|
|
62
|
-
|
|
66
|
+
}
|
|
63
67
|
const queue = new Map();
|
|
64
|
-
|
|
68
|
+
syncFs.watch(this.absoluteRoot, { recursive: true }, (eventType, filename) => {
|
|
69
|
+
this.watchHandler(queue, eventType, filename);
|
|
70
|
+
});
|
|
65
71
|
}
|
|
66
72
|
async process(file) {
|
|
67
73
|
const content = await fs.readFile(file, 'utf8');
|
|
68
|
-
const newContent = content.replace(PathFixer.IMPORT_REGEX,
|
|
74
|
+
const newContent = content.replace(PathFixer.IMPORT_REGEX, (match, prefix, modulePath, suffix) => {
|
|
75
|
+
return this.processReplacer(file, match, prefix, modulePath, suffix);
|
|
76
|
+
});
|
|
69
77
|
if (content === newContent)
|
|
70
78
|
return false;
|
|
71
79
|
await fs.writeFile(file, newContent, 'utf8');
|
|
72
80
|
return true;
|
|
73
81
|
}
|
|
74
82
|
processReplacer(file, match, prefix, modulePath, suffix) {
|
|
75
|
-
const config = this.alias.find(
|
|
83
|
+
const config = this.alias.find(c => c.isWildcard ? modulePath.startsWith(`${c.alias}/`) : modulePath === c.alias);
|
|
76
84
|
if (!config)
|
|
77
85
|
return match;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
const currentFileDir = path.dirname(file);
|
|
87
|
+
let absoluteTarget;
|
|
88
|
+
if (config.isWildcard) {
|
|
89
|
+
const subPath = modulePath.length > config.alias.length
|
|
90
|
+
? modulePath.substring(config.alias.length + 1)
|
|
91
|
+
: '';
|
|
92
|
+
absoluteTarget = path.join(config.target, subPath);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
absoluteTarget = config.target;
|
|
96
|
+
}
|
|
97
|
+
let relativeTarget = path.relative(currentFileDir, absoluteTarget);
|
|
98
|
+
if (!relativeTarget.startsWith('.'))
|
|
99
|
+
relativeTarget = `./${relativeTarget}`;
|
|
100
|
+
const finalTarget = Utilities.Path.normalize(relativeTarget);
|
|
101
|
+
return `${prefix}${finalTarget}${suffix}`;
|
|
86
102
|
}
|
|
87
103
|
async watchHandler(queue, eventType, filename) {
|
|
88
104
|
if (!filename || !PathFixer.EXTENSIONS.some(ext => filename.endsWith(ext)))
|
|
@@ -90,70 +106,38 @@ export class PathFixer {
|
|
|
90
106
|
const fullPath = path.join(this.absoluteRoot, filename);
|
|
91
107
|
if (queue.has(fullPath))
|
|
92
108
|
clearTimeout(queue.get(fullPath));
|
|
93
|
-
queue.set(fullPath, setTimeout(this.watchTimeout
|
|
109
|
+
queue.set(fullPath, setTimeout(() => this.watchTimeout(fullPath, filename), 300));
|
|
94
110
|
}
|
|
95
111
|
async watchTimeout(file, name) {
|
|
96
112
|
try {
|
|
97
113
|
const stat = await fs.stat(file);
|
|
98
114
|
if (!stat.isFile())
|
|
99
115
|
return;
|
|
100
|
-
logger.log(`&C2Change detected in &C4${name}&C2. Processing`);
|
|
101
116
|
const changed = await this.process(file);
|
|
102
117
|
if (changed)
|
|
103
118
|
logger.log(`&C2File &C4${name}&C2 rewritten.`);
|
|
104
119
|
}
|
|
105
120
|
catch (error) {
|
|
106
|
-
if (error.code
|
|
107
|
-
logger.
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
logger.error(`Error processing file &C4${name}&R:`, error);
|
|
111
|
-
}
|
|
121
|
+
if (error.code !== 'ENOENT')
|
|
122
|
+
logger.error(`Error processing &C4${name}&R:`, error);
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
125
|
static async getAllFiles(dir, extensions) {
|
|
115
126
|
const result = [];
|
|
116
|
-
if (!await Utilities.fileExists(dir))
|
|
117
|
-
return result;
|
|
118
127
|
const files = await fs.readdir(dir);
|
|
119
128
|
for (const file of files) {
|
|
120
129
|
const fullPath = path.join(dir, file);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
result.push(...subFiles);
|
|
126
|
-
}
|
|
127
|
-
else if (stat.isFile() && extensions.some(ext => fullPath.endsWith(ext))) {
|
|
128
|
-
result.push(fullPath);
|
|
129
|
-
}
|
|
130
|
+
const stat = await fs.stat(fullPath);
|
|
131
|
+
if (stat.isDirectory()) {
|
|
132
|
+
const allFiles = await PathFixer.getAllFiles(fullPath, extensions);
|
|
133
|
+
result.push(...allFiles);
|
|
130
134
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
logger.warn(`File or directory &C4${fullPath}&R not found during scan, skipping.`);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
logger.error(`Error scanning file &C4${fullPath}&R:`, error);
|
|
137
|
-
}
|
|
135
|
+
else if (extensions.some(ext => fullPath.endsWith(ext))) {
|
|
136
|
+
result.push(fullPath);
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
139
|
return result;
|
|
141
140
|
}
|
|
142
|
-
static async getProjectInfo(tsconfig = 'tsconfig.json') {
|
|
143
|
-
const info = PathFixer.DEFAULT_PROJECT_INFO;
|
|
144
|
-
const content = await fs.readFile(tsconfig, 'utf8');
|
|
145
|
-
const json = JSON.parse(content);
|
|
146
|
-
if (!json.compilerOptions)
|
|
147
|
-
return info;
|
|
148
|
-
const options = json.compilerOptions;
|
|
149
|
-
if (options.rootDir)
|
|
150
|
-
info.root = options.rootDir;
|
|
151
|
-
if (options.outDir)
|
|
152
|
-
info.out = options.outDir;
|
|
153
|
-
if (options.paths)
|
|
154
|
-
info.path = options.paths;
|
|
155
|
-
return info;
|
|
156
|
-
}
|
|
157
141
|
}
|
|
158
142
|
export default PathFixer;
|
|
159
143
|
//# sourceMappingURL=PathFixer.js.map
|