@nanoforge-dev/cli 1.5.3-beta.8113568 → 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/nf.js
CHANGED
|
@@ -232,12 +232,76 @@ const Prefixes = {
|
|
|
232
232
|
//#region src/lib/ui/spinner.ts
|
|
233
233
|
const getSpinner = (message) => ora({ text: message });
|
|
234
234
|
//#endregion
|
|
235
|
+
//#region src/lib/utils/errors.ts
|
|
236
|
+
var CLIError = class extends Error {
|
|
237
|
+
constructor(message) {
|
|
238
|
+
super(message);
|
|
239
|
+
this.name = this.constructor.name;
|
|
240
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var ConfigNotFoundError = class extends CLIError {
|
|
244
|
+
constructor(configPath) {
|
|
245
|
+
super(`Configuration file not found at path: ${configPath}. Please run 'nf new' or provide a valid --config path.`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var InvalidCommandArgumentError = class extends CLIError {
|
|
249
|
+
constructor(argName, expected) {
|
|
250
|
+
super(`Invalid argument '${argName}'. Expected: ${expected}.`);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var RegistryAuthenticationError = class extends CLIError {
|
|
254
|
+
constructor() {
|
|
255
|
+
super("You must be logged in to perform this action. Run 'nf login'.");
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var ManifestError = class extends CLIError {
|
|
259
|
+
constructor(detail) {
|
|
260
|
+
super(`Manifest Error: ${detail}`);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var FileSystemError = class extends CLIError {
|
|
264
|
+
constructor(action, targetPath) {
|
|
265
|
+
super(`File System Error [${action}]: ${targetPath}`);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var ApiRequestError = class extends CLIError {
|
|
269
|
+
constructor(status, cause) {
|
|
270
|
+
const causeStr = cause && typeof cause === "object" ? JSON.stringify(cause, null, 2) : cause;
|
|
271
|
+
super(`API Request failed (Status ${status})${causeStr ? `\nDetails: ${causeStr}` : ""}`);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const getErrorString = (error) => {
|
|
275
|
+
const stack = error.stack ? error.stack : error.message;
|
|
276
|
+
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
277
|
+
return `${stack}${cause ? `\n${cause}` : ""}`;
|
|
278
|
+
};
|
|
279
|
+
const getErrorMessage = (error) => {
|
|
280
|
+
if (error instanceof Error) return getErrorString(error);
|
|
281
|
+
if (typeof error === "string") return error;
|
|
282
|
+
};
|
|
283
|
+
const handleActionError = (context, error) => {
|
|
284
|
+
console.error();
|
|
285
|
+
console.error(red(context));
|
|
286
|
+
if (error instanceof CLIError) {
|
|
287
|
+
console.error(error.message);
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
290
|
+
const msg = getErrorMessage(error);
|
|
291
|
+
if (msg) console.error(msg);
|
|
292
|
+
process.exit(1);
|
|
293
|
+
};
|
|
294
|
+
const promptError = (err) => {
|
|
295
|
+
if (err.name === "ExitPromptError") process.exit(1);
|
|
296
|
+
throw err;
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
235
299
|
//#region src/lib/input/base-inputs.ts
|
|
236
300
|
const getStringInput = (input, field) => {
|
|
237
301
|
const value = input.get(field)?.value;
|
|
238
302
|
if (value === void 0) return void 0;
|
|
239
303
|
if (typeof value === "string") return value;
|
|
240
|
-
throw new
|
|
304
|
+
throw new InvalidCommandArgumentError(field, "string");
|
|
241
305
|
};
|
|
242
306
|
const getStringInputWithDefault = (input, field, defaultValue) => {
|
|
243
307
|
return getStringInput(input, field) ?? defaultValue;
|
|
@@ -246,7 +310,7 @@ const getBooleanInput = (input, field) => {
|
|
|
246
310
|
const value = input.get(field)?.value;
|
|
247
311
|
if (value === void 0) return void 0;
|
|
248
312
|
if (typeof value === "boolean") return value;
|
|
249
|
-
throw new
|
|
313
|
+
throw new InvalidCommandArgumentError(field, "boolean");
|
|
250
314
|
};
|
|
251
315
|
const getBooleanInputWithDefault = (input, field, defaultValue) => {
|
|
252
316
|
return getBooleanInput(input, field) ?? defaultValue;
|
|
@@ -255,7 +319,7 @@ const getArrayInput = (input, field) => {
|
|
|
255
319
|
const value = input.get(field)?.value;
|
|
256
320
|
if (value === void 0) return void 0;
|
|
257
321
|
if (typeof value === "object" && Array.isArray(value)) return value;
|
|
258
|
-
throw new
|
|
322
|
+
throw new InvalidCommandArgumentError(field, "array");
|
|
259
323
|
};
|
|
260
324
|
//#endregion
|
|
261
325
|
//#region src/lib/input/ask-inputs.ts
|
|
@@ -264,7 +328,7 @@ const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
|
264
328
|
const res = await askCb();
|
|
265
329
|
if (res !== void 0) return res;
|
|
266
330
|
if (defaultValue !== void 0) return defaultValue;
|
|
267
|
-
throw new
|
|
331
|
+
throw new CLIError("No input provided. Please provide a valid value.");
|
|
268
332
|
};
|
|
269
333
|
//#endregion
|
|
270
334
|
//#region src/lib/input/inputs/directory.input.ts
|
|
@@ -283,28 +347,6 @@ const getEditorInput = (inputs) => {
|
|
|
283
347
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
284
348
|
};
|
|
285
349
|
//#endregion
|
|
286
|
-
//#region src/lib/utils/errors.ts
|
|
287
|
-
const getErrorMessage = (error) => {
|
|
288
|
-
if (error instanceof Error) return getErrorString(error);
|
|
289
|
-
if (typeof error === "string") return error;
|
|
290
|
-
};
|
|
291
|
-
const getErrorString = (error) => {
|
|
292
|
-
const stack = error.stack ? error.stack : error.message;
|
|
293
|
-
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
294
|
-
return `${stack}${cause ? `\n${cause}` : ""}`;
|
|
295
|
-
};
|
|
296
|
-
const handleActionError = (context, error) => {
|
|
297
|
-
console.error();
|
|
298
|
-
console.error(red(context));
|
|
299
|
-
const msg = getErrorMessage(error);
|
|
300
|
-
if (msg) console.error(msg);
|
|
301
|
-
process.exit(1);
|
|
302
|
-
};
|
|
303
|
-
const promptError = (err) => {
|
|
304
|
-
if (err.name === "ExitPromptError") process.exit(1);
|
|
305
|
-
throw err;
|
|
306
|
-
};
|
|
307
|
-
//#endregion
|
|
308
350
|
//#region src/lib/question/questions/confirm.question.ts
|
|
309
351
|
const askConfirm = async (question, baseOptions) => {
|
|
310
352
|
return await confirm({
|
|
@@ -396,7 +438,7 @@ const getWatchInput = (inputs) => {
|
|
|
396
438
|
const getCreateTypeInput = (inputs) => {
|
|
397
439
|
const res = getStringInput(inputs, "type");
|
|
398
440
|
if (res && ["component", "system"].includes(res)) return res;
|
|
399
|
-
throw new
|
|
441
|
+
throw new InvalidCommandArgumentError("type", "'component' or 'system'");
|
|
400
442
|
};
|
|
401
443
|
//#endregion
|
|
402
444
|
//#region src/lib/input/inputs/dev/generate.input.ts
|
|
@@ -532,7 +574,7 @@ const resolveCLINodeBinaryPath = (name) => {
|
|
|
532
574
|
base = join(base, "..");
|
|
533
575
|
}
|
|
534
576
|
}
|
|
535
|
-
throw new
|
|
577
|
+
throw new FileSystemError("resolve binary", name);
|
|
536
578
|
};
|
|
537
579
|
//#endregion
|
|
538
580
|
//#region src/lib/utils/spinner.ts
|
|
@@ -651,7 +693,7 @@ var PackageManager = class {
|
|
|
651
693
|
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;
|
|
652
694
|
}
|
|
653
695
|
assertSupports(feature) {
|
|
654
|
-
if (!this.commands[feature]) throw new
|
|
696
|
+
if (!this.commands[feature]) throw new CLIError(`Package manager "${this.name}" does not support "${feature}"`);
|
|
655
697
|
}
|
|
656
698
|
buildRunArgs(script, params, flags, silent) {
|
|
657
699
|
const args = [...flags, this.commands.run];
|
|
@@ -662,7 +704,7 @@ var PackageManager = class {
|
|
|
662
704
|
return args.concat(params);
|
|
663
705
|
}
|
|
664
706
|
buildRunFileArgs(script, params, flags, silent) {
|
|
665
|
-
if (!this.commands.runFile) throw new
|
|
707
|
+
if (!this.commands.runFile) throw new CLIError("Package manager does not support runFile");
|
|
666
708
|
const args = [...flags, this.commands.runFile];
|
|
667
709
|
if (silent) args.push(this.commands.silentFlag);
|
|
668
710
|
args.push(script);
|
|
@@ -776,7 +818,7 @@ var RunnerFactory = class {
|
|
|
776
818
|
try {
|
|
777
819
|
return getModulePath("@angular-devkit/schematics-cli/bin/schematics.js");
|
|
778
820
|
} catch {
|
|
779
|
-
throw new
|
|
821
|
+
throw new CLIError("'schematics' binary path could not be found!");
|
|
780
822
|
}
|
|
781
823
|
}
|
|
782
824
|
};
|
|
@@ -868,7 +910,7 @@ const LOCK_FILE_MAP = {
|
|
|
868
910
|
var PackageManagerFactory = class {
|
|
869
911
|
static create(name) {
|
|
870
912
|
const config = PM_CONFIGS[name];
|
|
871
|
-
if (!config) throw new
|
|
913
|
+
if (!config) throw new CLIError(`Package manager '${name}' is not managed/supported.`);
|
|
872
914
|
const runner = this.createRunner(name, config.binary);
|
|
873
915
|
return new PackageManager(name, config.commands, runner);
|
|
874
916
|
}
|
|
@@ -892,7 +934,7 @@ var PackageManagerFactory = class {
|
|
|
892
934
|
//#region src/lib/utils/files.ts
|
|
893
935
|
const copyFiles = (from, to) => {
|
|
894
936
|
if (!fs.existsSync(from)) return;
|
|
895
|
-
if (!fs.existsSync(to)) throw new
|
|
937
|
+
if (!fs.existsSync(to)) throw new FileSystemError("directory not found", to);
|
|
896
938
|
fs.readdirSync(from, { recursive: true }).forEach((file) => {
|
|
897
939
|
fs.copyFileSync(join(from, file.toString()), join(to, file.toString()));
|
|
898
940
|
});
|
|
@@ -1119,7 +1161,7 @@ const getConfigPath = (directory, name) => {
|
|
|
1119
1161
|
const path = join$1(directory, n);
|
|
1120
1162
|
if (existsSync$1(path)) return path;
|
|
1121
1163
|
}
|
|
1122
|
-
throw new
|
|
1164
|
+
throw new ConfigNotFoundError(join$1(directory, CONFIG_FILE_NAME));
|
|
1123
1165
|
}
|
|
1124
1166
|
};
|
|
1125
1167
|
const loadConfig = async (directory, name, noThrow = false) => {
|
|
@@ -1131,10 +1173,10 @@ const loadConfig = async (directory, name, noThrow = false) => {
|
|
|
1131
1173
|
} catch {
|
|
1132
1174
|
rawData = noThrow ? CONFIG_DEFAULTS : null;
|
|
1133
1175
|
}
|
|
1134
|
-
if (!rawData) throw new
|
|
1176
|
+
if (!rawData) throw new FileSystemError("read config file", path);
|
|
1135
1177
|
const data = plainToInstance(Config, rawData, { excludeExtraneousValues: true });
|
|
1136
1178
|
const errors = await validate(data);
|
|
1137
|
-
if (errors.length > 0) throw new
|
|
1179
|
+
if (errors.length > 0) throw new CLIError(`Invalid config:\n${errors.toString().replace(/,/g, "\n")}`);
|
|
1138
1180
|
config = data;
|
|
1139
1181
|
return config;
|
|
1140
1182
|
};
|
|
@@ -1324,7 +1366,7 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1324
1366
|
}
|
|
1325
1367
|
validate(name) {
|
|
1326
1368
|
const schematic = NanoforgeCollection.schematics.find((s) => s.name === name || s.alias === name);
|
|
1327
|
-
if (schematic === void 0 || schematic === null) throw new
|
|
1369
|
+
if (schematic === void 0 || schematic === null) throw new CLIError(`Invalid schematic "${name}". Please, ensure that "${name}" exists in this collection.`);
|
|
1328
1370
|
return schematic.name;
|
|
1329
1371
|
}
|
|
1330
1372
|
};
|
|
@@ -1334,7 +1376,7 @@ var CollectionFactory = class {
|
|
|
1334
1376
|
static create(collection, directory) {
|
|
1335
1377
|
const schematicRunner = RunnerFactory.createSchematic();
|
|
1336
1378
|
if (collection === "@nanoforge-dev/schematics") return new NanoforgeCollection(schematicRunner, directory);
|
|
1337
|
-
throw new
|
|
1379
|
+
throw new CLIError(`Unknown collection: ${collection}`);
|
|
1338
1380
|
}
|
|
1339
1381
|
};
|
|
1340
1382
|
//#endregion
|
|
@@ -1669,27 +1711,24 @@ var Repository = class {
|
|
|
1669
1711
|
async runRequest(request, path, options) {
|
|
1670
1712
|
const res = await this._client[request](path, options);
|
|
1671
1713
|
const data = await res.json();
|
|
1672
|
-
if (!res.ok) throw new
|
|
1714
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1673
1715
|
return data;
|
|
1674
1716
|
}
|
|
1675
1717
|
async runFileRequest(request, path, options) {
|
|
1676
1718
|
const res = await this._client[request](path, options);
|
|
1677
|
-
if (!res.ok) throw new
|
|
1719
|
+
if (!res.ok) throw new ApiRequestError(res.status, (await res.json())["error"]);
|
|
1678
1720
|
return await res.blob();
|
|
1679
1721
|
}
|
|
1680
1722
|
async runRequestBody(request, path, body, options) {
|
|
1681
1723
|
const res = await this._client[request](path, body === void 0 ? void 0 : body instanceof FormData ? body : JSON.stringify(body), options);
|
|
1682
1724
|
const data = await res.json();
|
|
1683
|
-
if (!res.ok) throw new
|
|
1725
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1684
1726
|
return data;
|
|
1685
1727
|
}
|
|
1686
1728
|
};
|
|
1687
1729
|
new Repository(new HttpClient("https://api.nanoforge.eu"));
|
|
1688
1730
|
const withAuth = (apiKey, force = false, headers = { "Content-Type": "application/json" }) => {
|
|
1689
|
-
if (!apiKey && force)
|
|
1690
|
-
console.error("No registry key found. Please use `nf login` to login");
|
|
1691
|
-
throw new Error("No apikey found. Please use `nf login` to login");
|
|
1692
|
-
}
|
|
1731
|
+
if (!apiKey && force) throw new RegistryAuthenticationError();
|
|
1693
1732
|
return new Repository(new HttpClient("https://api.nanoforge.eu", { headers: {
|
|
1694
1733
|
Authorization: apiKey,
|
|
1695
1734
|
...headers
|
|
@@ -1765,12 +1804,12 @@ var Registry = class {
|
|
|
1765
1804
|
}
|
|
1766
1805
|
static _getPackageFile(filename, dir) {
|
|
1767
1806
|
const path = join(getCwd(dir ?? "."), filename);
|
|
1768
|
-
if (!fs.existsSync(path)) throw new
|
|
1807
|
+
if (!fs.existsSync(path)) throw new CLIError("Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!");
|
|
1769
1808
|
try {
|
|
1770
1809
|
fs.accessSync(path, fs.constants.R_OK);
|
|
1771
1810
|
return fs.openAsBlob(path);
|
|
1772
1811
|
} catch {
|
|
1773
|
-
throw new
|
|
1812
|
+
throw new CLIError("Cannot read package file, please verify your file permissions!");
|
|
1774
1813
|
}
|
|
1775
1814
|
}
|
|
1776
1815
|
};
|
|
@@ -2077,7 +2116,7 @@ const getManifestPath = (directory) => {
|
|
|
2077
2116
|
const path = join$1(directory, n);
|
|
2078
2117
|
if (existsSync$1(path)) return path;
|
|
2079
2118
|
}
|
|
2080
|
-
throw new
|
|
2119
|
+
throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
2081
2120
|
};
|
|
2082
2121
|
const loadManifest = async (directory) => {
|
|
2083
2122
|
let rawData;
|
|
@@ -2087,10 +2126,10 @@ const loadManifest = async (directory) => {
|
|
|
2087
2126
|
} catch {
|
|
2088
2127
|
rawData = null;
|
|
2089
2128
|
}
|
|
2090
|
-
if (!rawData) throw new
|
|
2129
|
+
if (!rawData) throw new ManifestError(`Unable to read or parse file at ${path}`);
|
|
2091
2130
|
const data = plainToInstance(Manifest, rawData, { excludeExtraneousValues: true });
|
|
2092
2131
|
const errors = await validate(data);
|
|
2093
|
-
if (errors.length > 0) throw new
|
|
2132
|
+
if (errors.length > 0) throw new ManifestError(`Validation failed\n${errors.toString()}`);
|
|
2094
2133
|
return data;
|
|
2095
2134
|
};
|
|
2096
2135
|
//#endregion
|
|
@@ -2133,8 +2172,8 @@ var StartAction = class extends AbstractAction {
|
|
|
2133
2172
|
const cert = getStringInput(options, "cert");
|
|
2134
2173
|
const key = getStringInput(options, "key");
|
|
2135
2174
|
if (!cert && !key) return void 0;
|
|
2136
|
-
if (!cert) throw new
|
|
2137
|
-
if (!key) throw new
|
|
2175
|
+
if (!cert) throw new CLIError("No cert entered for SSL. Please enter a cert with --cert.");
|
|
2176
|
+
if (!key) throw new CLIError("No key entered for SSL. Please enter a key with --key.");
|
|
2138
2177
|
return {
|
|
2139
2178
|
cert,
|
|
2140
2179
|
key
|
|
@@ -2453,7 +2492,7 @@ var CommandLoader = class {
|
|
|
2453
2492
|
};
|
|
2454
2493
|
//#endregion
|
|
2455
2494
|
//#region package.json
|
|
2456
|
-
var version = "1.5.
|
|
2495
|
+
var version = "1.5.4-beta.5329236";
|
|
2457
2496
|
//#endregion
|
|
2458
2497
|
//#region src/bin/nf.ts
|
|
2459
2498
|
const bootstrap = async () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@nanoforge-dev/cli",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.4-beta.5329236",
|
|
5
5
|
"description": "NanoForge CLI",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"nanoforge",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@commitlint/cli": "^21.0.2",
|
|
57
57
|
"@commitlint/config-conventional": "^21.0.2",
|
|
58
58
|
"@favware/cliff-jumper": "^6.1.0",
|
|
59
|
-
"@nanoforge-dev/actions": "^2.1.
|
|
59
|
+
"@nanoforge-dev/actions": "^2.1.2",
|
|
60
60
|
"@nanoforge-dev/utils-eslint-config": "^1.0.2",
|
|
61
61
|
"@nanoforge-dev/utils-prettier-config": "^1.0.2",
|
|
62
62
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|