@nanoforge-dev/cli 1.5.3 → 1.5.4-beta.5329236
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/dist/command.loader.js +91 -52
- package/dist/command.loader.js.map +1 -1
- package/dist/nf.js +92 -53
- package/package.json +2 -2
package/dist/command.loader.js
CHANGED
|
@@ -126,12 +126,76 @@ const Prefixes = {
|
|
|
126
126
|
//#region src/lib/ui/spinner.ts
|
|
127
127
|
const getSpinner = (message) => ora({ text: message });
|
|
128
128
|
//#endregion
|
|
129
|
+
//#region src/lib/utils/errors.ts
|
|
130
|
+
var CLIError = class extends Error {
|
|
131
|
+
constructor(message) {
|
|
132
|
+
super(message);
|
|
133
|
+
this.name = this.constructor.name;
|
|
134
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var ConfigNotFoundError = class extends CLIError {
|
|
138
|
+
constructor(configPath) {
|
|
139
|
+
super(`Configuration file not found at path: ${configPath}. Please run 'nf new' or provide a valid --config path.`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var InvalidCommandArgumentError = class extends CLIError {
|
|
143
|
+
constructor(argName, expected) {
|
|
144
|
+
super(`Invalid argument '${argName}'. Expected: ${expected}.`);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var RegistryAuthenticationError = class extends CLIError {
|
|
148
|
+
constructor() {
|
|
149
|
+
super("You must be logged in to perform this action. Run 'nf login'.");
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var ManifestError = class extends CLIError {
|
|
153
|
+
constructor(detail) {
|
|
154
|
+
super(`Manifest Error: ${detail}`);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var FileSystemError = class extends CLIError {
|
|
158
|
+
constructor(action, targetPath) {
|
|
159
|
+
super(`File System Error [${action}]: ${targetPath}`);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var ApiRequestError = class extends CLIError {
|
|
163
|
+
constructor(status, cause) {
|
|
164
|
+
const causeStr = cause && typeof cause === "object" ? JSON.stringify(cause, null, 2) : cause;
|
|
165
|
+
super(`API Request failed (Status ${status})${causeStr ? `\nDetails: ${causeStr}` : ""}`);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const getErrorString = (error) => {
|
|
169
|
+
const stack = error.stack ? error.stack : error.message;
|
|
170
|
+
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
171
|
+
return `${stack}${cause ? `\n${cause}` : ""}`;
|
|
172
|
+
};
|
|
173
|
+
const getErrorMessage = (error) => {
|
|
174
|
+
if (error instanceof Error) return getErrorString(error);
|
|
175
|
+
if (typeof error === "string") return error;
|
|
176
|
+
};
|
|
177
|
+
const handleActionError = (context, error) => {
|
|
178
|
+
console.error();
|
|
179
|
+
console.error(red(context));
|
|
180
|
+
if (error instanceof CLIError) {
|
|
181
|
+
console.error(error.message);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
const msg = getErrorMessage(error);
|
|
185
|
+
if (msg) console.error(msg);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
};
|
|
188
|
+
const promptError = (err) => {
|
|
189
|
+
if (err.name === "ExitPromptError") process.exit(1);
|
|
190
|
+
throw err;
|
|
191
|
+
};
|
|
192
|
+
//#endregion
|
|
129
193
|
//#region src/lib/input/base-inputs.ts
|
|
130
194
|
const getStringInput = (input, field) => {
|
|
131
195
|
const value = input.get(field)?.value;
|
|
132
196
|
if (value === void 0) return void 0;
|
|
133
197
|
if (typeof value === "string") return value;
|
|
134
|
-
throw new
|
|
198
|
+
throw new InvalidCommandArgumentError(field, "string");
|
|
135
199
|
};
|
|
136
200
|
const getStringInputWithDefault = (input, field, defaultValue) => {
|
|
137
201
|
return getStringInput(input, field) ?? defaultValue;
|
|
@@ -140,7 +204,7 @@ const getBooleanInput = (input, field) => {
|
|
|
140
204
|
const value = input.get(field)?.value;
|
|
141
205
|
if (value === void 0) return void 0;
|
|
142
206
|
if (typeof value === "boolean") return value;
|
|
143
|
-
throw new
|
|
207
|
+
throw new InvalidCommandArgumentError(field, "boolean");
|
|
144
208
|
};
|
|
145
209
|
const getBooleanInputWithDefault = (input, field, defaultValue) => {
|
|
146
210
|
return getBooleanInput(input, field) ?? defaultValue;
|
|
@@ -149,7 +213,7 @@ const getArrayInput = (input, field) => {
|
|
|
149
213
|
const value = input.get(field)?.value;
|
|
150
214
|
if (value === void 0) return void 0;
|
|
151
215
|
if (typeof value === "object" && Array.isArray(value)) return value;
|
|
152
|
-
throw new
|
|
216
|
+
throw new InvalidCommandArgumentError(field, "array");
|
|
153
217
|
};
|
|
154
218
|
//#endregion
|
|
155
219
|
//#region src/lib/input/ask-inputs.ts
|
|
@@ -158,7 +222,7 @@ const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
|
158
222
|
const res = await askCb();
|
|
159
223
|
if (res !== void 0) return res;
|
|
160
224
|
if (defaultValue !== void 0) return defaultValue;
|
|
161
|
-
throw new
|
|
225
|
+
throw new CLIError("No input provided. Please provide a valid value.");
|
|
162
226
|
};
|
|
163
227
|
//#endregion
|
|
164
228
|
//#region src/lib/input/inputs/directory.input.ts
|
|
@@ -177,28 +241,6 @@ const getEditorInput = (inputs) => {
|
|
|
177
241
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
178
242
|
};
|
|
179
243
|
//#endregion
|
|
180
|
-
//#region src/lib/utils/errors.ts
|
|
181
|
-
const getErrorMessage = (error) => {
|
|
182
|
-
if (error instanceof Error) return getErrorString(error);
|
|
183
|
-
if (typeof error === "string") return error;
|
|
184
|
-
};
|
|
185
|
-
const getErrorString = (error) => {
|
|
186
|
-
const stack = error.stack ? error.stack : error.message;
|
|
187
|
-
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
188
|
-
return `${stack}${cause ? `\n${cause}` : ""}`;
|
|
189
|
-
};
|
|
190
|
-
const handleActionError = (context, error) => {
|
|
191
|
-
console.error();
|
|
192
|
-
console.error(red(context));
|
|
193
|
-
const msg = getErrorMessage(error);
|
|
194
|
-
if (msg) console.error(msg);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
};
|
|
197
|
-
const promptError = (err) => {
|
|
198
|
-
if (err.name === "ExitPromptError") process.exit(1);
|
|
199
|
-
throw err;
|
|
200
|
-
};
|
|
201
|
-
//#endregion
|
|
202
244
|
//#region src/lib/question/questions/confirm.question.ts
|
|
203
245
|
const askConfirm = async (question, baseOptions) => {
|
|
204
246
|
return await confirm({
|
|
@@ -290,7 +332,7 @@ const getWatchInput = (inputs) => {
|
|
|
290
332
|
const getCreateTypeInput = (inputs) => {
|
|
291
333
|
const res = getStringInput(inputs, "type");
|
|
292
334
|
if (res && ["component", "system"].includes(res)) return res;
|
|
293
|
-
throw new
|
|
335
|
+
throw new InvalidCommandArgumentError("type", "'component' or 'system'");
|
|
294
336
|
};
|
|
295
337
|
//#endregion
|
|
296
338
|
//#region src/lib/input/inputs/dev/generate.input.ts
|
|
@@ -426,7 +468,7 @@ const resolveCLINodeBinaryPath = (name) => {
|
|
|
426
468
|
base = join$1(base, "..");
|
|
427
469
|
}
|
|
428
470
|
}
|
|
429
|
-
throw new
|
|
471
|
+
throw new FileSystemError("resolve binary", name);
|
|
430
472
|
};
|
|
431
473
|
//#endregion
|
|
432
474
|
//#region src/lib/utils/spinner.ts
|
|
@@ -545,7 +587,7 @@ var PackageManager = class {
|
|
|
545
587
|
return (await withSpinner(() => this.exec(args, directory), Messages.PACKAGE_MANAGER_INSTALLATION_IN_PROGRESS, Messages.PACKAGE_MANAGER_INSTALLATION_SUCCEED(), Messages.PACKAGE_MANAGER_INSTALLATION_FAILED(this.formatFailCommand(args)))).success;
|
|
546
588
|
}
|
|
547
589
|
assertSupports(feature) {
|
|
548
|
-
if (!this.commands[feature]) throw new
|
|
590
|
+
if (!this.commands[feature]) throw new CLIError(`Package manager "${this.name}" does not support "${feature}"`);
|
|
549
591
|
}
|
|
550
592
|
buildRunArgs(script, params, flags, silent) {
|
|
551
593
|
const args = [...flags, this.commands.run];
|
|
@@ -556,7 +598,7 @@ var PackageManager = class {
|
|
|
556
598
|
return args.concat(params);
|
|
557
599
|
}
|
|
558
600
|
buildRunFileArgs(script, params, flags, silent) {
|
|
559
|
-
if (!this.commands.runFile) throw new
|
|
601
|
+
if (!this.commands.runFile) throw new CLIError("Package manager does not support runFile");
|
|
560
602
|
const args = [...flags, this.commands.runFile];
|
|
561
603
|
if (silent) args.push(this.commands.silentFlag);
|
|
562
604
|
args.push(script);
|
|
@@ -670,7 +712,7 @@ var RunnerFactory = class {
|
|
|
670
712
|
try {
|
|
671
713
|
return getModulePath("@angular-devkit/schematics-cli/bin/schematics.js");
|
|
672
714
|
} catch {
|
|
673
|
-
throw new
|
|
715
|
+
throw new CLIError("'schematics' binary path could not be found!");
|
|
674
716
|
}
|
|
675
717
|
}
|
|
676
718
|
};
|
|
@@ -762,7 +804,7 @@ const LOCK_FILE_MAP = {
|
|
|
762
804
|
var PackageManagerFactory = class {
|
|
763
805
|
static create(name) {
|
|
764
806
|
const config = PM_CONFIGS[name];
|
|
765
|
-
if (!config) throw new
|
|
807
|
+
if (!config) throw new CLIError(`Package manager '${name}' is not managed/supported.`);
|
|
766
808
|
const runner = this.createRunner(name, config.binary);
|
|
767
809
|
return new PackageManager(name, config.commands, runner);
|
|
768
810
|
}
|
|
@@ -786,7 +828,7 @@ var PackageManagerFactory = class {
|
|
|
786
828
|
//#region src/lib/utils/files.ts
|
|
787
829
|
const copyFiles = (from, to) => {
|
|
788
830
|
if (!fs.existsSync(from)) return;
|
|
789
|
-
if (!fs.existsSync(to)) throw new
|
|
831
|
+
if (!fs.existsSync(to)) throw new FileSystemError("directory not found", to);
|
|
790
832
|
fs.readdirSync(from, { recursive: true }).forEach((file) => {
|
|
791
833
|
fs.copyFileSync(join$1(from, file.toString()), join$1(to, file.toString()));
|
|
792
834
|
});
|
|
@@ -1013,7 +1055,7 @@ const getConfigPath = (directory, name) => {
|
|
|
1013
1055
|
const path = join(directory, n);
|
|
1014
1056
|
if (existsSync(path)) return path;
|
|
1015
1057
|
}
|
|
1016
|
-
throw new
|
|
1058
|
+
throw new ConfigNotFoundError(join(directory, CONFIG_FILE_NAME));
|
|
1017
1059
|
}
|
|
1018
1060
|
};
|
|
1019
1061
|
const loadConfig = async (directory, name, noThrow = false) => {
|
|
@@ -1025,10 +1067,10 @@ const loadConfig = async (directory, name, noThrow = false) => {
|
|
|
1025
1067
|
} catch {
|
|
1026
1068
|
rawData = noThrow ? CONFIG_DEFAULTS : null;
|
|
1027
1069
|
}
|
|
1028
|
-
if (!rawData) throw new
|
|
1070
|
+
if (!rawData) throw new FileSystemError("read config file", path);
|
|
1029
1071
|
const data = plainToInstance(Config, rawData, { excludeExtraneousValues: true });
|
|
1030
1072
|
const errors = await validate(data);
|
|
1031
|
-
if (errors.length > 0) throw new
|
|
1073
|
+
if (errors.length > 0) throw new CLIError(`Invalid config:\n${errors.toString().replace(/,/g, "\n")}`);
|
|
1032
1074
|
config = data;
|
|
1033
1075
|
return config;
|
|
1034
1076
|
};
|
|
@@ -1218,7 +1260,7 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1218
1260
|
}
|
|
1219
1261
|
validate(name) {
|
|
1220
1262
|
const schematic = NanoforgeCollection.schematics.find((s) => s.name === name || s.alias === name);
|
|
1221
|
-
if (schematic === void 0 || schematic === null) throw new
|
|
1263
|
+
if (schematic === void 0 || schematic === null) throw new CLIError(`Invalid schematic "${name}". Please, ensure that "${name}" exists in this collection.`);
|
|
1222
1264
|
return schematic.name;
|
|
1223
1265
|
}
|
|
1224
1266
|
};
|
|
@@ -1228,7 +1270,7 @@ var CollectionFactory = class {
|
|
|
1228
1270
|
static create(collection, directory) {
|
|
1229
1271
|
const schematicRunner = RunnerFactory.createSchematic();
|
|
1230
1272
|
if (collection === "@nanoforge-dev/schematics") return new NanoforgeCollection(schematicRunner, directory);
|
|
1231
|
-
throw new
|
|
1273
|
+
throw new CLIError(`Unknown collection: ${collection}`);
|
|
1232
1274
|
}
|
|
1233
1275
|
};
|
|
1234
1276
|
//#endregion
|
|
@@ -1563,27 +1605,24 @@ var Repository = class {
|
|
|
1563
1605
|
async runRequest(request, path, options) {
|
|
1564
1606
|
const res = await this._client[request](path, options);
|
|
1565
1607
|
const data = await res.json();
|
|
1566
|
-
if (!res.ok) throw new
|
|
1608
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1567
1609
|
return data;
|
|
1568
1610
|
}
|
|
1569
1611
|
async runFileRequest(request, path, options) {
|
|
1570
1612
|
const res = await this._client[request](path, options);
|
|
1571
|
-
if (!res.ok) throw new
|
|
1613
|
+
if (!res.ok) throw new ApiRequestError(res.status, (await res.json())["error"]);
|
|
1572
1614
|
return await res.blob();
|
|
1573
1615
|
}
|
|
1574
1616
|
async runRequestBody(request, path, body, options) {
|
|
1575
1617
|
const res = await this._client[request](path, body === void 0 ? void 0 : body instanceof FormData ? body : JSON.stringify(body), options);
|
|
1576
1618
|
const data = await res.json();
|
|
1577
|
-
if (!res.ok) throw new
|
|
1619
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1578
1620
|
return data;
|
|
1579
1621
|
}
|
|
1580
1622
|
};
|
|
1581
1623
|
new Repository(new HttpClient("https://api.nanoforge.eu"));
|
|
1582
1624
|
const withAuth = (apiKey, force = false, headers = { "Content-Type": "application/json" }) => {
|
|
1583
|
-
if (!apiKey && force)
|
|
1584
|
-
console.error("No registry key found. Please use `nf login` to login");
|
|
1585
|
-
throw new Error("No apikey found. Please use `nf login` to login");
|
|
1586
|
-
}
|
|
1625
|
+
if (!apiKey && force) throw new RegistryAuthenticationError();
|
|
1587
1626
|
return new Repository(new HttpClient("https://api.nanoforge.eu", { headers: {
|
|
1588
1627
|
Authorization: apiKey,
|
|
1589
1628
|
...headers
|
|
@@ -1659,12 +1698,12 @@ var Registry = class {
|
|
|
1659
1698
|
}
|
|
1660
1699
|
static _getPackageFile(filename, dir) {
|
|
1661
1700
|
const path = join$1(getCwd(dir ?? "."), filename);
|
|
1662
|
-
if (!fs.existsSync(path)) throw new
|
|
1701
|
+
if (!fs.existsSync(path)) throw new CLIError("Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!");
|
|
1663
1702
|
try {
|
|
1664
1703
|
fs.accessSync(path, fs.constants.R_OK);
|
|
1665
1704
|
return fs.openAsBlob(path);
|
|
1666
1705
|
} catch {
|
|
1667
|
-
throw new
|
|
1706
|
+
throw new CLIError("Cannot read package file, please verify your file permissions!");
|
|
1668
1707
|
}
|
|
1669
1708
|
}
|
|
1670
1709
|
};
|
|
@@ -1971,7 +2010,7 @@ const getManifestPath = (directory) => {
|
|
|
1971
2010
|
const path = join(directory, n);
|
|
1972
2011
|
if (existsSync(path)) return path;
|
|
1973
2012
|
}
|
|
1974
|
-
throw new
|
|
2013
|
+
throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1975
2014
|
};
|
|
1976
2015
|
const loadManifest = async (directory) => {
|
|
1977
2016
|
let rawData;
|
|
@@ -1981,10 +2020,10 @@ const loadManifest = async (directory) => {
|
|
|
1981
2020
|
} catch {
|
|
1982
2021
|
rawData = null;
|
|
1983
2022
|
}
|
|
1984
|
-
if (!rawData) throw new
|
|
2023
|
+
if (!rawData) throw new ManifestError(`Unable to read or parse file at ${path}`);
|
|
1985
2024
|
const data = plainToInstance(Manifest, rawData, { excludeExtraneousValues: true });
|
|
1986
2025
|
const errors = await validate(data);
|
|
1987
|
-
if (errors.length > 0) throw new
|
|
2026
|
+
if (errors.length > 0) throw new ManifestError(`Validation failed\n${errors.toString()}`);
|
|
1988
2027
|
return data;
|
|
1989
2028
|
};
|
|
1990
2029
|
//#endregion
|
|
@@ -2027,8 +2066,8 @@ var StartAction = class extends AbstractAction {
|
|
|
2027
2066
|
const cert = getStringInput(options, "cert");
|
|
2028
2067
|
const key = getStringInput(options, "key");
|
|
2029
2068
|
if (!cert && !key) return void 0;
|
|
2030
|
-
if (!cert) throw new
|
|
2031
|
-
if (!key) throw new
|
|
2069
|
+
if (!cert) throw new CLIError("No cert entered for SSL. Please enter a cert with --cert.");
|
|
2070
|
+
if (!key) throw new CLIError("No key entered for SSL. Please enter a key with --key.");
|
|
2032
2071
|
return {
|
|
2033
2072
|
cert,
|
|
2034
2073
|
key
|