depflow 1.1.2 → 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/cli/DepFLowCLI.d.ts +15 -0
- package/build/cli/DepFLowCLI.js +193 -0
- package/build/cli/DepFLowCLI.js.map +1 -0
- package/build/cli/bin.d.ts +2 -0
- package/build/cli/bin.js +37 -0
- 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 +6 -4
- package/build/Dependency.d.ts +0 -99
- package/build/Dependency.js +0 -258
- package/build/Dependency.js.map +0 -1
- package/build/File.d.ts +0 -45
- package/build/File.js +0 -113
- 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 -159
- package/build/PathFixer.js.map +0 -1
- package/build/Validator.d.ts +0 -54
- package/build/Validator.js +0 -150
- package/build/Validator.js.map +0 -1
- package/build/bin.d.ts +0 -7
- package/build/bin.js +0 -241
- package/build/bin.js.map +0 -1
- /package/build/{Git.d.ts → support/Git.d.ts} +0 -0
- /package/build/{Git.js → support/Git.js} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DebugUI } from "@netfeez/vterm";
|
|
2
|
+
export declare class DepFlowCLI extends DebugUI {
|
|
3
|
+
readonly configPath: string;
|
|
4
|
+
protected readonly projectRoot: string;
|
|
5
|
+
constructor(configPath?: string);
|
|
6
|
+
commandAdd(command: string, args: string[]): Promise<void>;
|
|
7
|
+
commandRemove(command: string, args: string[]): Promise<void>;
|
|
8
|
+
commandInstall(command: string, args: string[]): Promise<void>;
|
|
9
|
+
uninstall(command: string, args: string[]): Promise<void>;
|
|
10
|
+
list(command: string, args: string[]): Promise<void>;
|
|
11
|
+
rewritePaths(command: string, args: string[]): Promise<void>;
|
|
12
|
+
commandSync(command: string, args: string[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace DepFlowCLI { }
|
|
15
|
+
export default DepFlowCLI;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { DebugUI } from "@netfeez/vterm";
|
|
2
|
+
import Validator from "../support/Validator.js";
|
|
3
|
+
import Utils from "../support/Utils.js";
|
|
4
|
+
import Config from "../config/Config.js";
|
|
5
|
+
import schemas from "../config/schemas.js";
|
|
6
|
+
import Dependency from "../support/Dependency.js";
|
|
7
|
+
import Tsconfig from "../config/Tsconfig.js";
|
|
8
|
+
import pathResolver from "../support/PathResolver/PathResolver.js";
|
|
9
|
+
import ImportMap from "../config/ImportMap.js";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
export class DepFlowCLI extends DebugUI {
|
|
12
|
+
configPath;
|
|
13
|
+
projectRoot;
|
|
14
|
+
constructor(configPath = 'depFlow.json') {
|
|
15
|
+
super();
|
|
16
|
+
this.configPath = configPath;
|
|
17
|
+
const absoluteConfigPath = path.resolve(process.cwd(), this.configPath);
|
|
18
|
+
this.projectRoot = path.dirname(absoluteConfigPath);
|
|
19
|
+
this.addCommand('add', this.commandAdd, { usage: 'dep add <repo_url> [name]', description: 'Add a dependency to the configuration file.' });
|
|
20
|
+
this.addCommand('remove', this.commandRemove, { usage: 'dep remove <name> | <repo_url>', description: 'Remove a dependency from the configuration file by name or repo URL.' });
|
|
21
|
+
this.addCommand('install', this.commandInstall, { usage: 'dep install [name1 name2 ...]', description: 'Install dependencies. If names are provided, only those dependencies will be installed.' });
|
|
22
|
+
this.addCommand('uninstall', this.uninstall, { usage: 'dep uninstall [name1 name2 ...]', description: 'Uninstall dependencies. If names are provided, only those dependencies will be uninstalled.' });
|
|
23
|
+
this.addCommand('list', this.list, { usage: 'dep list', description: 'List all dependencies in the configuration file.' });
|
|
24
|
+
this.addCommand('rewrite-paths', this.rewritePaths, { usage: 'dep rewrite-paths [--watch] [--cdn]', description: 'Resolve and rewrite paths in built files based on depFlow configuration.' });
|
|
25
|
+
this.addCommand('sync', this.commandSync, { usage: 'dep sync', description: 'Syncs depFlow.json with tsconfig.json and generates the importmap.' });
|
|
26
|
+
}
|
|
27
|
+
async commandAdd(command, args) {
|
|
28
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
29
|
+
this.out.info(`&C(255,180,220)│ Adding dependency...`);
|
|
30
|
+
let [repo, name] = args;
|
|
31
|
+
try {
|
|
32
|
+
Validator.validateRepo(repo);
|
|
33
|
+
if (!name)
|
|
34
|
+
name = Utils.getRepoName(repo);
|
|
35
|
+
const config = await Config.load(this.configPath);
|
|
36
|
+
const dep = schemas.dependency.processData({ name, repo });
|
|
37
|
+
config.dependencies.push(dep);
|
|
38
|
+
await Config.save(this.configPath, config);
|
|
39
|
+
this.out.info(`&C(255,180,220)│ Added dependency "${dep.name}".`);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.out.error(`&C(255,180,220)│ &C1${error}`);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async commandRemove(command, args) {
|
|
49
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
50
|
+
const [identifier] = args;
|
|
51
|
+
try {
|
|
52
|
+
if (!identifier)
|
|
53
|
+
throw new Error('Usage: dep remove <name> | <repo_url>');
|
|
54
|
+
const config = await Config.load(this.configPath);
|
|
55
|
+
config.dependencies = config.dependencies.filter(dep => dep.name !== identifier && dep.repo !== identifier);
|
|
56
|
+
await Config.save(this.configPath, config);
|
|
57
|
+
this.out.info(`&C(255,180,220)│ Removed dependency "${identifier}".`);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.out.error(`&C(255,180,220)│ &C1${error}`);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async commandInstall(command, args) {
|
|
67
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
68
|
+
try {
|
|
69
|
+
const config = await Config.load(this.configPath);
|
|
70
|
+
const toInstall = args.length > 0
|
|
71
|
+
? config.dependencies.filter(dep => args.includes(dep.name) || args.includes(dep.repo))
|
|
72
|
+
: config.dependencies;
|
|
73
|
+
if (toInstall.length === 0)
|
|
74
|
+
throw new Error(args.length > 0 ? 'Specified dependencies not found.' : 'No dependencies to install.');
|
|
75
|
+
for (const dep of toInstall) {
|
|
76
|
+
this.out.info(`&C(255,180,220)│ Installing "${dep.name}" from "${dep.repo}"...`);
|
|
77
|
+
const dependency = new Dependency(config, dep);
|
|
78
|
+
const result = await dependency.install();
|
|
79
|
+
this.out.info(`&C(255,180,220)│ ${result.join('\n').replace(/\n/g, '\n&C(255,180,220)│ ')}`);
|
|
80
|
+
this.out.info(`&C(255,180,220)│ &C3Installed dependency: &C3${dep.name}`);
|
|
81
|
+
this.out.info(`&C(255,180,220)│ Installed "${dep.name}".`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
this.out.error(`&C(255,180,220)│ &C1${error}`);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
89
|
+
}
|
|
90
|
+
this.commandSync('sync', []);
|
|
91
|
+
}
|
|
92
|
+
async uninstall(command, args) {
|
|
93
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
94
|
+
try {
|
|
95
|
+
const config = await Config.load(this.configPath);
|
|
96
|
+
const toUninstall = args.length > 0
|
|
97
|
+
? config.dependencies.filter(dep => args.includes(dep.name) || args.includes(dep.repo))
|
|
98
|
+
: config.dependencies;
|
|
99
|
+
if (toUninstall.length === 0)
|
|
100
|
+
throw new Error(args.length > 0 ? 'Specified dependencies not found.' : 'No dependencies to uninstall.');
|
|
101
|
+
for (const dep of toUninstall) {
|
|
102
|
+
this.out.info(`&C(255,180,220)│ Uninstalling "${dep.name}" from "${dep.repo}"...`);
|
|
103
|
+
const dependency = new Dependency(config, dep);
|
|
104
|
+
const result = await dependency.uninstall();
|
|
105
|
+
this.out.info(`&C(255,180,220)│ ${result.join('\n').replace(/\n/g, '\n&C(255,180,220)│ ')}`);
|
|
106
|
+
this.out.info(`&C(255,180,220)│ &C3Uninstalled dependency: &C3${dep.name}`);
|
|
107
|
+
this.out.info(`&C(255,180,220)│ Uninstalled "${dep.name}".`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.out.error(`&C(255,180,220)│ &C1${error}`);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async list(command, args) {
|
|
118
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
119
|
+
try {
|
|
120
|
+
const config = await Config.load(this.configPath);
|
|
121
|
+
if (config.dependencies.length === 0) {
|
|
122
|
+
this.out.info(`&C(255,180,220)│ No dependencies found.`);
|
|
123
|
+
}
|
|
124
|
+
for (const dep of config.dependencies) {
|
|
125
|
+
this.out.info(`&C(255,180,220)│ &C3${dep.name} &C(255,180,220)from &C3${dep.repo}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.out.error(`&C(255,180,220)│ &C1${error}`);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async rewritePaths(command, args) {
|
|
136
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
137
|
+
try {
|
|
138
|
+
const config = await Config.load(this.configPath);
|
|
139
|
+
const watch = args.includes('--watch') || args.includes('-w');
|
|
140
|
+
const useCDN = args.includes('--cdn');
|
|
141
|
+
const mode = useCDN ? 'cdn' : 'local';
|
|
142
|
+
this.out.info(`&C(255,180,220)│ Mode: &C3${useCDN ? 'CDN' : 'Local'}`);
|
|
143
|
+
if (watch)
|
|
144
|
+
this.out.info(`&C(255,180,220)│ Watcher: &C2Enabled`);
|
|
145
|
+
const resolver = new pathResolver(config, { logger: this.out });
|
|
146
|
+
if (watch)
|
|
147
|
+
await resolver.watch(mode);
|
|
148
|
+
else
|
|
149
|
+
await resolver.rewritePaths(mode);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
this.out.error(`&C(255,180,220)│ &C1${error.message || error}`);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async commandSync(command, args) {
|
|
159
|
+
this.out.info(`&C(255,180,220)╭──────────────────────────────────────────────────`);
|
|
160
|
+
this.out.info(`&C(255,180,220)│ Synchronizing configurations...`);
|
|
161
|
+
try {
|
|
162
|
+
const useCDN = args.includes('--cdn');
|
|
163
|
+
const mode = useCDN ? 'cdn' : 'local';
|
|
164
|
+
const config = await Config.load(this.configPath);
|
|
165
|
+
const resolver = new pathResolver(config, { logger: this.out });
|
|
166
|
+
const tsconfigFile = config.tsconfig;
|
|
167
|
+
const importMapFile = config.importmap;
|
|
168
|
+
if (tsconfigFile) {
|
|
169
|
+
const tsconfig = await Tsconfig.load(this.projectRoot, tsconfigFile, { logger: this.out });
|
|
170
|
+
tsconfig.updatePaths(resolver.aliases);
|
|
171
|
+
await tsconfig.save();
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
this.out.warn(`&C(255,180,220)│ No tsconfig file specified in configuration. Skipping tsconfig synchronization.`);
|
|
175
|
+
if (importMapFile) {
|
|
176
|
+
const importmap = await ImportMap.load(this.projectRoot, importMapFile, { logger: this.out });
|
|
177
|
+
importmap.updateImports(resolver.aliases, mode);
|
|
178
|
+
await importmap.save();
|
|
179
|
+
}
|
|
180
|
+
else
|
|
181
|
+
this.out.warn(`&C(255,180,220)│ No import map file specified in configuration. Skipping import map synchronization.`);
|
|
182
|
+
this.out.info(`&C(255,180,220)│ &C2Successfully synced all configurations.`);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
this.out.error(`&C(255,180,220)│ &C1Error during sync: ${error.message}`);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
this.out.info(`&C(255,180,220)╰──────────────────────────────────────────────────`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export default DepFlowCLI;
|
|
193
|
+
//# sourceMappingURL=DepFLowCLI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DepFLowCLI.js","sourceRoot":"","sources":["../../src/cli/DepFLowCLI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,YAA8B,MAAM,yCAAyC,CAAC;AACrF,OAAO,SAAS,MAAM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C,GAAG,CAAC,KAAK,CAAC,0CAA0C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAAC,CAAC;gBAC3F,CAAC;YAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;QAAC,CAAC;IACpG,CAAC;CACJ;AAED,eAAe,UAAU,CAAC"}
|
package/build/cli/bin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import DepFlowCLI from "./DepFLowCLI.js";
|
|
3
|
+
import { Utils } from "../support/Utils.js";
|
|
4
|
+
import schemas from "../config/schemas.js";
|
|
5
|
+
function startupSchemaValidation(flowPath) {
|
|
6
|
+
const jsonSchema = schemas.config.jsonSchema;
|
|
7
|
+
Utils.addVscodeValidation(flowPath, jsonSchema);
|
|
8
|
+
}
|
|
9
|
+
const skip = 2;
|
|
10
|
+
const [commandName, ...args] = process.argv.slice(skip);
|
|
11
|
+
const flowTag = (Utils.getFlagValue(args, '--flow') ||
|
|
12
|
+
Utils.getFlagValue(args, '-f'));
|
|
13
|
+
const flowPath = flowTag[0] || 'depflow.json';
|
|
14
|
+
const cli = new DepFlowCLI(flowPath);
|
|
15
|
+
startupSchemaValidation(flowPath);
|
|
16
|
+
console.log(flowPath);
|
|
17
|
+
try {
|
|
18
|
+
if (commandName !== null) {
|
|
19
|
+
const command = cli.getCommand(commandName);
|
|
20
|
+
if (command) {
|
|
21
|
+
await command.exec.call(cli, commandName, args);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cli.out.error(`Unknown command: ${commandName}`);
|
|
25
|
+
cli.getCommand('help')?.exec.call(cli, 'help', []);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
cli.start();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
cli.out.error(`&C(255,180,220)╭─────────────────────────────────────────────`);
|
|
33
|
+
cli.out.error(`&C(255,180,220)│ &C1${error?.stack || error}`);
|
|
34
|
+
cli.out.error(`&C(255,180,220)╰─────────────────────────────────────────────`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AAEA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAE3C,SAAS,uBAAuB,CAAC,QAAgB;IAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;IAC7C,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAExD,MAAM,OAAO,GAAG,CACZ,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC;IAClC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CACjC,CAAC;AAEF,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC;AAC9C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AAErC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;AAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACtB,IAAI,CAAC;IACD,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,WAAW,EAAE,CAAC,CAAC;YACjD,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACvD,CAAC;IACL,CAAC;;QAAM,GAAG,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC;AAAC,OAAO,KAAU,EAAE,CAAC;IAClB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC/E,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import schemas from './schemas.js';
|
|
2
|
+
export declare class Config {
|
|
3
|
+
/**
|
|
4
|
+
* Loads the configuration from a file at the specified path.
|
|
5
|
+
* If the file does not exist, it creates a new configuration file with default values and returns those defaults.
|
|
6
|
+
* If the file exists, it reads the content, parses it as JSON, and processes it using the defined schema to ensure it conforms to the expected structure.
|
|
7
|
+
* This method is essential for managing application settings or other relevant information in a structured format that can be easily read and modified as needed.
|
|
8
|
+
* @param path The file system path of the configuration file to load.
|
|
9
|
+
* @returns A promise that resolves to the loaded configuration object, which conforms to the expected structure defined in the Config.Config type.
|
|
10
|
+
* @throws Will throw an error if there is an issue during the file reading or writing process, such as insufficient permissions or invalid path.
|
|
11
|
+
*/
|
|
12
|
+
static load(path: string): Promise<Config.Config>;
|
|
13
|
+
/**
|
|
14
|
+
* Saves the provided configuration object to a file at the specified path.
|
|
15
|
+
* It converts the configuration object into a JSON string with proper formatting and writes it to the file using the File.write method.
|
|
16
|
+
* This function is essential for persisting configuration data, allowing applications to store settings or other relevant information in a structured format that can be easily read and modified as needed.
|
|
17
|
+
* @param path The file system path where the configuration should be saved.
|
|
18
|
+
* @param config The configuration object to be saved, which should conform to the expected structure defined in the Config.ConfigToProcess type.
|
|
19
|
+
* @returns A promise that resolves when the save operation is complete.
|
|
20
|
+
* @throws Will throw an error if there is an issue during the file writing process, such as insufficient permissions or invalid path.
|
|
21
|
+
*/
|
|
22
|
+
static save(path: string, config: Config.ConfigToProcess): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace Config {
|
|
25
|
+
type Config = typeof schemas.config.infer;
|
|
26
|
+
type ConfigToProcess = typeof schemas.config.inferToProcess;
|
|
27
|
+
}
|
|
28
|
+
export default Config;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Utility to help with File operations.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { File } from '@netfeez/common-node';
|
|
7
|
+
import schemas from './schemas.js';
|
|
8
|
+
export class Config {
|
|
9
|
+
/**
|
|
10
|
+
* Loads the configuration from a file at the specified path.
|
|
11
|
+
* If the file does not exist, it creates a new configuration file with default values and returns those defaults.
|
|
12
|
+
* If the file exists, it reads the content, parses it as JSON, and processes it using the defined schema to ensure it conforms to the expected structure.
|
|
13
|
+
* This method is essential for managing application settings or other relevant information in a structured format that can be easily read and modified as needed.
|
|
14
|
+
* @param path The file system path of the configuration file to load.
|
|
15
|
+
* @returns A promise that resolves to the loaded configuration object, which conforms to the expected structure defined in the Config.Config type.
|
|
16
|
+
* @throws Will throw an error if there is an issue during the file reading or writing process, such as insufficient permissions or invalid path.
|
|
17
|
+
*/
|
|
18
|
+
static async load(path) {
|
|
19
|
+
if (!await File.exists(path)) {
|
|
20
|
+
const defaults = schemas.config.processData({});
|
|
21
|
+
await Config.save(path, defaults);
|
|
22
|
+
return defaults;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const content = await File.read(path, 'utf-8');
|
|
26
|
+
const json = JSON.parse(content);
|
|
27
|
+
const config = schemas.config.processData(json);
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Saves the provided configuration object to a file at the specified path.
|
|
33
|
+
* It converts the configuration object into a JSON string with proper formatting and writes it to the file using the File.write method.
|
|
34
|
+
* This function is essential for persisting configuration data, allowing applications to store settings or other relevant information in a structured format that can be easily read and modified as needed.
|
|
35
|
+
* @param path The file system path where the configuration should be saved.
|
|
36
|
+
* @param config The configuration object to be saved, which should conform to the expected structure defined in the Config.ConfigToProcess type.
|
|
37
|
+
* @returns A promise that resolves when the save operation is complete.
|
|
38
|
+
* @throws Will throw an error if there is an issue during the file writing process, such as insufficient permissions or invalid path.
|
|
39
|
+
*/
|
|
40
|
+
static async save(path, config) {
|
|
41
|
+
const content = JSON.stringify(config, null, 2);
|
|
42
|
+
await File.write(path, content, 'utf-8');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default Config;
|
|
46
|
+
//# sourceMappingURL=Config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../../src/config/Config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,OAAO,MAAM;IACf;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC1B,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAChD,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAClC,OAAO,QAAQ,CAAC;QACpB,CAAC;aAAM,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC;QAClB,CAAC;IACL,CAAC;IACD;;;;;;;;OAQG;IACH,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,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;CACJ;AAMD,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Logger } from '@netfeez/vterm';
|
|
2
|
+
import AliasCompiler from '../support/PathResolver/AliasCompiler.js';
|
|
3
|
+
export declare class ImportMap {
|
|
4
|
+
protected data: ImportMap.Data;
|
|
5
|
+
protected projectRoot: string;
|
|
6
|
+
protected filename: string;
|
|
7
|
+
protected logger: Logger;
|
|
8
|
+
constructor(data: ImportMap.Data, projectRoot: string, filename: string, options?: ImportMap.Options);
|
|
9
|
+
/**
|
|
10
|
+
* Updates the import map data based on the provided compiled aliases.
|
|
11
|
+
* It constructs an "imports" section where each alias is mapped to its target path.
|
|
12
|
+
* @param aliases An array of compiled aliases.
|
|
13
|
+
* @param mode The resolution mode ('local' or 'cdn').
|
|
14
|
+
*/
|
|
15
|
+
updateImports(aliases: AliasCompiler.CompiledAlias[], mode: 'local' | 'cdn'): void;
|
|
16
|
+
save(filename?: string): Promise<void>;
|
|
17
|
+
static save(projectRoot: string, filename: string, data: ImportMap.Data, options?: ImportMap.Options): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Factory method: Loads, validates (or creates default), and returns an instance of the ImportMap class.
|
|
20
|
+
* It checks if the specified import map file exists, and if it does, it attempts to read and parse its content as JSON.
|
|
21
|
+
* If the file does not exist or contains invalid JSON, it initializes the data with a default structure containing an empty "imports" object.
|
|
22
|
+
* Finally, it returns a new instance of ImportMap with the loaded or default data, allowing for further manipulation and saving of the import map configuration.
|
|
23
|
+
* @param projectRoot The root directory of the project where the import map file is located.
|
|
24
|
+
* @param filename The name of the import map file to load (e.g., 'import-map.json').
|
|
25
|
+
* @param options Additional options for loading, such as a logger for logging messages during the load process.
|
|
26
|
+
* @returns A promise that resolves to an instance of ImportMap initialized with the loaded or default data.
|
|
27
|
+
*/
|
|
28
|
+
static load(projectRoot: string, filename: string, options?: ImportMap.Options): Promise<ImportMap>;
|
|
29
|
+
}
|
|
30
|
+
export declare namespace ImportMap {
|
|
31
|
+
interface Data {
|
|
32
|
+
imports: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
interface Options {
|
|
35
|
+
logger?: Logger;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export default ImportMap;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import PATH from 'node:path';
|
|
2
|
+
import { Logger } from '@netfeez/vterm';
|
|
3
|
+
import { File, Path } from '@netfeez/common-node';
|
|
4
|
+
export class ImportMap {
|
|
5
|
+
data;
|
|
6
|
+
projectRoot;
|
|
7
|
+
filename;
|
|
8
|
+
logger;
|
|
9
|
+
constructor(data, projectRoot, filename, options = {}) {
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.projectRoot = projectRoot;
|
|
12
|
+
this.filename = filename;
|
|
13
|
+
this.logger = options.logger || new Logger({ name: 'IMP-MAP' });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Updates the import map data based on the provided compiled aliases.
|
|
17
|
+
* It constructs an "imports" section where each alias is mapped to its target path.
|
|
18
|
+
* @param aliases An array of compiled aliases.
|
|
19
|
+
* @param mode The resolution mode ('local' or 'cdn').
|
|
20
|
+
*/
|
|
21
|
+
updateImports(aliases, mode) {
|
|
22
|
+
if (!this.data.imports)
|
|
23
|
+
this.data.imports = {};
|
|
24
|
+
for (const aliasObj of aliases) {
|
|
25
|
+
const key = aliasObj.isWildcard ? `${aliasObj.alias}/` : aliasObj.alias;
|
|
26
|
+
let target = mode === 'cdn' && aliasObj.targets.cdn
|
|
27
|
+
? aliasObj.targets.cdn
|
|
28
|
+
: aliasObj.targets.local;
|
|
29
|
+
if (target === aliasObj.targets.local) {
|
|
30
|
+
target = PATH.relative(this.projectRoot, target);
|
|
31
|
+
if (!target.startsWith('./'))
|
|
32
|
+
target = `./${target}`;
|
|
33
|
+
target = Path.normalize(target);
|
|
34
|
+
}
|
|
35
|
+
if (aliasObj.isWildcard) {
|
|
36
|
+
if (!target.endsWith('/'))
|
|
37
|
+
target += '/';
|
|
38
|
+
}
|
|
39
|
+
this.data.imports[key] = target;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async save(filename = this.filename) {
|
|
43
|
+
await ImportMap.save(this.projectRoot, filename, this.data, { logger: this.logger });
|
|
44
|
+
}
|
|
45
|
+
static async save(projectRoot, filename, data, options = {}) {
|
|
46
|
+
const logger = options.logger || new Logger({ name: 'IMP-MAP' });
|
|
47
|
+
const importMapPath = PATH.resolve(projectRoot, filename);
|
|
48
|
+
const folder = PATH.dirname(importMapPath);
|
|
49
|
+
if (!await File.exists(folder))
|
|
50
|
+
await File.mkdir(folder, { recursive: true });
|
|
51
|
+
const json = JSON.stringify(data, null, 4);
|
|
52
|
+
await File.write(importMapPath, json);
|
|
53
|
+
logger.log(`&C2Generated &C4${filename}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Factory method: Loads, validates (or creates default), and returns an instance of the ImportMap class.
|
|
57
|
+
* It checks if the specified import map file exists, and if it does, it attempts to read and parse its content as JSON.
|
|
58
|
+
* If the file does not exist or contains invalid JSON, it initializes the data with a default structure containing an empty "imports" object.
|
|
59
|
+
* Finally, it returns a new instance of ImportMap with the loaded or default data, allowing for further manipulation and saving of the import map configuration.
|
|
60
|
+
* @param projectRoot The root directory of the project where the import map file is located.
|
|
61
|
+
* @param filename The name of the import map file to load (e.g., 'import-map.json').
|
|
62
|
+
* @param options Additional options for loading, such as a logger for logging messages during the load process.
|
|
63
|
+
* @returns A promise that resolves to an instance of ImportMap initialized with the loaded or default data.
|
|
64
|
+
*/
|
|
65
|
+
static async load(projectRoot, filename, options = {}) {
|
|
66
|
+
const logger = options.logger || new Logger({ name: 'IMP-MAP' });
|
|
67
|
+
const importMapPath = PATH.resolve(projectRoot, filename);
|
|
68
|
+
let data = { imports: {} };
|
|
69
|
+
if (!await File.exists(importMapPath)) {
|
|
70
|
+
logger.warn(`&C3${filename} not found. Creating defaults...`);
|
|
71
|
+
const data = { imports: {} };
|
|
72
|
+
await ImportMap.save(projectRoot, filename, data, { logger });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const content = await File.read(importMapPath, 'utf-8');
|
|
76
|
+
const json = JSON.parse(content);
|
|
77
|
+
data = json;
|
|
78
|
+
}
|
|
79
|
+
return new ImportMap(data, projectRoot, filename, { logger });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export default ImportMap;
|
|
83
|
+
//# sourceMappingURL=ImportMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportMap.js","sourceRoot":"","sources":["../../src/config/ImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,OAAO,SAAS;IAIJ;IAC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,EAAE;QAC3F,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACjE,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,IAAI,GAAmB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,MAAM,QAAQ,kCAAkC,CAAC,CAAC;YAC9D,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;YAC7B,MAAM,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,GAAG,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;CACJ;AASD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Logger } from '@netfeez/vterm';
|
|
2
|
+
import schemas from "./schemas.js";
|
|
3
|
+
import AliasCompiler from '../support/PathResolver/AliasCompiler.js';
|
|
4
|
+
export declare class Tsconfig {
|
|
5
|
+
protected data: Tsconfig.Data;
|
|
6
|
+
protected projectRoot: string;
|
|
7
|
+
protected filename: string;
|
|
8
|
+
protected logger: Logger;
|
|
9
|
+
constructor(data: Tsconfig.Data, projectRoot: string, filename: string, options?: Tsconfig.Options);
|
|
10
|
+
/**
|
|
11
|
+
* Updates the paths in the tsconfig data based on the provided compiled aliases.
|
|
12
|
+
* It ensures that the compilerOptions and paths properties exist in the tsconfig data, and then iterates through the compiled aliases to construct the appropriate path mappings.
|
|
13
|
+
* For each alias, it calculates the relative path from the project root to the local target and normalizes it. If the alias is a wildcard, it appends '/*' to the target path.
|
|
14
|
+
* Finally, it updates the paths in the tsconfig data with the new mappings, allowing TypeScript to resolve module paths according to the defined aliases.
|
|
15
|
+
* @param aliases An array of compiled aliases containing alias names, target paths, and wildcard information.
|
|
16
|
+
*/
|
|
17
|
+
updatePaths(aliases: AliasCompiler.CompiledAlias[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Saves the current tsconfig data to a file.
|
|
20
|
+
* It constructs the path to the tsconfig file using the project root and filename, converts the data to a JSON string with proper formatting, and writes it to the file system using the File.write method.
|
|
21
|
+
* The method also includes error handling to log any issues that occur during the save process, ensuring that users are informed of any problems when attempting to save the tsconfig configuration.
|
|
22
|
+
* @param filename The name of the tsconfig file to save (default is the instance's filename property).
|
|
23
|
+
* @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
|
|
24
|
+
*/
|
|
25
|
+
save(filename?: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Static method to save tsconfig data to a specified file. It takes the project root, filename, tsconfig data, and options (including a logger) as parameters.
|
|
28
|
+
* The method constructs the full path to the tsconfig file, converts the data to a formatted JSON string, and writes it to the file system.
|
|
29
|
+
* It also includes error handling to log any issues that arise during the save process, providing feedback on whether the operation was successful or if it encountered problems.
|
|
30
|
+
* @param projectRoot The root directory of the project where the tsconfig file should be saved.
|
|
31
|
+
* @param filename The name of the tsconfig file (default is 'tsconfig.json').
|
|
32
|
+
* @param data The tsconfig data to be saved, structured according to the defined schema.
|
|
33
|
+
* @param options Additional options for saving, such as a logger for logging messages during the save process.
|
|
34
|
+
* @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
|
|
35
|
+
* @throws Will throw an error if there is an issue during the save process, which can be caught by the caller to handle it appropriately.
|
|
36
|
+
*/
|
|
37
|
+
static save(projectRoot: string, filename: string | undefined, data: Tsconfig.Data, options?: Tsconfig.Options): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Static method to load tsconfig data from a specified file.
|
|
40
|
+
* It takes the project root, filename, and options (including a logger) as parameters.
|
|
41
|
+
* The method checks if the tsconfig file exists, and if it does, it reads the content, parses it as JSON, and processes it using the defined schema to ensure it conforms to the expected structure.
|
|
42
|
+
* If the file does not exist, it creates a default tsconfig data object using the schema. Finally, it returns an instance of the Tsconfig class initialized with the loaded or default data.
|
|
43
|
+
* @param projectRoot The root directory of the project where the tsconfig file is located.
|
|
44
|
+
* @param filename The name of the tsconfig file to load (default is 'tsconfig.json').
|
|
45
|
+
* @param options Additional options for loading, such as a logger for logging messages during the load process.
|
|
46
|
+
* @returns A promise that resolves to an instance of the Tsconfig class containing the loaded data, or rejects if there is an error during the load process.
|
|
47
|
+
* @throws Will throw an error if there is an issue during the load process, which
|
|
48
|
+
*/
|
|
49
|
+
static load(projectRoot: string, filename: string, options: Tsconfig.Options): Promise<Tsconfig>;
|
|
50
|
+
}
|
|
51
|
+
export declare namespace Tsconfig {
|
|
52
|
+
type Data = schemas.basicTsconfig['infer'];
|
|
53
|
+
interface Options {
|
|
54
|
+
logger?: Logger;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default Tsconfig;
|