@nanoforge-dev/cli 1.5.4-beta.acc5439 ā 1.5.4-beta.c7cb939
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 +95 -53
- package/dist/command.loader.js.map +1 -1
- package/dist/nf.js +96 -54
- package/package.json +1 -1
package/dist/command.loader.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bgRgb, bold, green, red, yellow } from "ansis";
|
|
1
|
+
import { bgRgb, bold, cyan, green, red, yellow } from "ansis";
|
|
2
2
|
import { get } from "node-emoji";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { watch } from "chokidar";
|
|
@@ -126,12 +126,79 @@ 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
|
+
suggestion;
|
|
132
|
+
constructor(message, suggestion) {
|
|
133
|
+
super(message);
|
|
134
|
+
this.name = this.constructor.name;
|
|
135
|
+
this.suggestion = suggestion;
|
|
136
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var ConfigNotFoundError = class extends CLIError {
|
|
140
|
+
constructor(configPath) {
|
|
141
|
+
super(`Configuration file not found at path: ${configPath}.`, "Please run 'nf new' or provide a valid --config path.");
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var InvalidCommandArgumentError = class extends CLIError {
|
|
145
|
+
constructor(argName, expected) {
|
|
146
|
+
super(`Invalid argument '${argName}'. Expected: ${expected}.`, "Verify the command syntax using the --help flag.");
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var RegistryAuthenticationError = class extends CLIError {
|
|
150
|
+
constructor() {
|
|
151
|
+
super("You must be logged in to perform this action.", "Run 'nf login' to authenticate.");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var ManifestError = class extends CLIError {
|
|
155
|
+
constructor(detail) {
|
|
156
|
+
super(`Manifest Error: ${detail}`, "Check your nanoforge.manifest.json file for syntax or formatting errors.");
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var FileSystemError = class extends CLIError {
|
|
160
|
+
constructor(action, targetPath) {
|
|
161
|
+
super(`File System Error [${action}]: ${targetPath}`, "Verify your file permissions and ensure the path exists.");
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var ApiRequestError = class extends CLIError {
|
|
165
|
+
constructor(status, cause) {
|
|
166
|
+
const causeStr = cause && typeof cause === "object" ? JSON.stringify(cause, null, 2) : cause;
|
|
167
|
+
super(`API Request failed (Status ${status})${causeStr ? `\nDetails: ${causeStr}` : ""}`, "Check your network connection, API key, or the registry status.");
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const getErrorString = (error) => {
|
|
171
|
+
const stack = error.stack ? error.stack : error.message;
|
|
172
|
+
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
173
|
+
return `${stack}${cause ? `\n${cause}` : ""}`;
|
|
174
|
+
};
|
|
175
|
+
const getErrorMessage = (error) => {
|
|
176
|
+
if (error instanceof Error) return getErrorString(error);
|
|
177
|
+
if (typeof error === "string") return error;
|
|
178
|
+
};
|
|
179
|
+
const handleActionError = (context, error) => {
|
|
180
|
+
console.error();
|
|
181
|
+
console.error(red(context));
|
|
182
|
+
if (error instanceof CLIError) {
|
|
183
|
+
console.error(error.message);
|
|
184
|
+
if (error.suggestion) console.info(cyan(`\nš” Suggestion: ${error.suggestion}`));
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
const msg = getErrorMessage(error);
|
|
188
|
+
if (msg) console.error(msg);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
};
|
|
191
|
+
const promptError = (err) => {
|
|
192
|
+
if (err.name === "ExitPromptError") process.exit(1);
|
|
193
|
+
throw err;
|
|
194
|
+
};
|
|
195
|
+
//#endregion
|
|
129
196
|
//#region src/lib/input/base-inputs.ts
|
|
130
197
|
const getStringInput = (input, field) => {
|
|
131
198
|
const value = input.get(field)?.value;
|
|
132
199
|
if (value === void 0) return void 0;
|
|
133
200
|
if (typeof value === "string") return value;
|
|
134
|
-
throw new
|
|
201
|
+
throw new InvalidCommandArgumentError(field, "string");
|
|
135
202
|
};
|
|
136
203
|
const getStringInputWithDefault = (input, field, defaultValue) => {
|
|
137
204
|
return getStringInput(input, field) ?? defaultValue;
|
|
@@ -140,7 +207,7 @@ const getBooleanInput = (input, field) => {
|
|
|
140
207
|
const value = input.get(field)?.value;
|
|
141
208
|
if (value === void 0) return void 0;
|
|
142
209
|
if (typeof value === "boolean") return value;
|
|
143
|
-
throw new
|
|
210
|
+
throw new InvalidCommandArgumentError(field, "boolean");
|
|
144
211
|
};
|
|
145
212
|
const getBooleanInputWithDefault = (input, field, defaultValue) => {
|
|
146
213
|
return getBooleanInput(input, field) ?? defaultValue;
|
|
@@ -149,7 +216,7 @@ const getArrayInput = (input, field) => {
|
|
|
149
216
|
const value = input.get(field)?.value;
|
|
150
217
|
if (value === void 0) return void 0;
|
|
151
218
|
if (typeof value === "object" && Array.isArray(value)) return value;
|
|
152
|
-
throw new
|
|
219
|
+
throw new InvalidCommandArgumentError(field, "array");
|
|
153
220
|
};
|
|
154
221
|
//#endregion
|
|
155
222
|
//#region src/lib/input/ask-inputs.ts
|
|
@@ -158,7 +225,7 @@ const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
|
158
225
|
const res = await askCb();
|
|
159
226
|
if (res !== void 0) return res;
|
|
160
227
|
if (defaultValue !== void 0) return defaultValue;
|
|
161
|
-
throw new
|
|
228
|
+
throw new CLIError("No input provided. Please provide a valid value.");
|
|
162
229
|
};
|
|
163
230
|
//#endregion
|
|
164
231
|
//#region src/lib/input/inputs/directory.input.ts
|
|
@@ -177,28 +244,6 @@ const getEditorInput = (inputs) => {
|
|
|
177
244
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
178
245
|
};
|
|
179
246
|
//#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
247
|
//#region src/lib/question/questions/confirm.question.ts
|
|
203
248
|
const askConfirm = async (question, baseOptions) => {
|
|
204
249
|
return await confirm({
|
|
@@ -290,7 +335,7 @@ const getWatchInput = (inputs) => {
|
|
|
290
335
|
const getCreateTypeInput = (inputs) => {
|
|
291
336
|
const res = getStringInput(inputs, "type");
|
|
292
337
|
if (res && ["component", "system"].includes(res)) return res;
|
|
293
|
-
throw new
|
|
338
|
+
throw new InvalidCommandArgumentError("type", "'component' or 'system'");
|
|
294
339
|
};
|
|
295
340
|
//#endregion
|
|
296
341
|
//#region src/lib/input/inputs/dev/generate.input.ts
|
|
@@ -426,7 +471,7 @@ const resolveCLINodeBinaryPath = (name) => {
|
|
|
426
471
|
base = join$1(base, "..");
|
|
427
472
|
}
|
|
428
473
|
}
|
|
429
|
-
throw new
|
|
474
|
+
throw new FileSystemError("resolve binary", name);
|
|
430
475
|
};
|
|
431
476
|
//#endregion
|
|
432
477
|
//#region src/lib/utils/spinner.ts
|
|
@@ -545,7 +590,7 @@ var PackageManager = class {
|
|
|
545
590
|
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
591
|
}
|
|
547
592
|
assertSupports(feature) {
|
|
548
|
-
if (!this.commands[feature]) throw new
|
|
593
|
+
if (!this.commands[feature]) throw new CLIError(`Package manager "${this.name}" does not support "${feature}"`);
|
|
549
594
|
}
|
|
550
595
|
buildRunArgs(script, params, flags, silent) {
|
|
551
596
|
const args = [...flags, this.commands.run];
|
|
@@ -556,7 +601,7 @@ var PackageManager = class {
|
|
|
556
601
|
return args.concat(params);
|
|
557
602
|
}
|
|
558
603
|
buildRunFileArgs(script, params, flags, silent) {
|
|
559
|
-
if (!this.commands.runFile) throw new
|
|
604
|
+
if (!this.commands.runFile) throw new CLIError("Package manager does not support runFile");
|
|
560
605
|
const args = [...flags, this.commands.runFile];
|
|
561
606
|
if (silent) args.push(this.commands.silentFlag);
|
|
562
607
|
args.push(script);
|
|
@@ -670,7 +715,7 @@ var RunnerFactory = class {
|
|
|
670
715
|
try {
|
|
671
716
|
return getModulePath("@angular-devkit/schematics-cli/bin/schematics.js");
|
|
672
717
|
} catch {
|
|
673
|
-
throw new
|
|
718
|
+
throw new CLIError("'schematics' binary path could not be found!");
|
|
674
719
|
}
|
|
675
720
|
}
|
|
676
721
|
};
|
|
@@ -762,7 +807,7 @@ const LOCK_FILE_MAP = {
|
|
|
762
807
|
var PackageManagerFactory = class {
|
|
763
808
|
static create(name) {
|
|
764
809
|
const config = PM_CONFIGS[name];
|
|
765
|
-
if (!config) throw new
|
|
810
|
+
if (!config) throw new CLIError(`Package manager '${name}' is not managed/supported.`);
|
|
766
811
|
const runner = this.createRunner(name, config.binary);
|
|
767
812
|
return new PackageManager(name, config.commands, runner);
|
|
768
813
|
}
|
|
@@ -786,7 +831,7 @@ var PackageManagerFactory = class {
|
|
|
786
831
|
//#region src/lib/utils/files.ts
|
|
787
832
|
const copyFiles = (from, to) => {
|
|
788
833
|
if (!fs.existsSync(from)) return;
|
|
789
|
-
if (!fs.existsSync(to)) throw new
|
|
834
|
+
if (!fs.existsSync(to)) throw new FileSystemError("directory not found", to);
|
|
790
835
|
fs.readdirSync(from, { recursive: true }).forEach((file) => {
|
|
791
836
|
fs.copyFileSync(join$1(from, file.toString()), join$1(to, file.toString()));
|
|
792
837
|
});
|
|
@@ -1013,7 +1058,7 @@ const getConfigPath = (directory, name) => {
|
|
|
1013
1058
|
const path = join(directory, n);
|
|
1014
1059
|
if (existsSync(path)) return path;
|
|
1015
1060
|
}
|
|
1016
|
-
throw new
|
|
1061
|
+
throw new ConfigNotFoundError(join(directory, CONFIG_FILE_NAME));
|
|
1017
1062
|
}
|
|
1018
1063
|
};
|
|
1019
1064
|
const loadConfig = async (directory, name, noThrow = false) => {
|
|
@@ -1025,10 +1070,10 @@ const loadConfig = async (directory, name, noThrow = false) => {
|
|
|
1025
1070
|
} catch {
|
|
1026
1071
|
rawData = noThrow ? CONFIG_DEFAULTS : null;
|
|
1027
1072
|
}
|
|
1028
|
-
if (!rawData) throw new
|
|
1073
|
+
if (!rawData) throw new FileSystemError("read config file", path);
|
|
1029
1074
|
const data = plainToInstance(Config, rawData, { excludeExtraneousValues: true });
|
|
1030
1075
|
const errors = await validate(data);
|
|
1031
|
-
if (errors.length > 0) throw new
|
|
1076
|
+
if (errors.length > 0) throw new CLIError(`Invalid config:\n${errors.toString().replace(/,/g, "\n")}`);
|
|
1032
1077
|
config = data;
|
|
1033
1078
|
return config;
|
|
1034
1079
|
};
|
|
@@ -1218,7 +1263,7 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1218
1263
|
}
|
|
1219
1264
|
validate(name) {
|
|
1220
1265
|
const schematic = NanoforgeCollection.schematics.find((s) => s.name === name || s.alias === name);
|
|
1221
|
-
if (schematic === void 0 || schematic === null) throw new
|
|
1266
|
+
if (schematic === void 0 || schematic === null) throw new CLIError(`Invalid schematic "${name}". Please, ensure that "${name}" exists in this collection.`);
|
|
1222
1267
|
return schematic.name;
|
|
1223
1268
|
}
|
|
1224
1269
|
};
|
|
@@ -1228,7 +1273,7 @@ var CollectionFactory = class {
|
|
|
1228
1273
|
static create(collection, directory) {
|
|
1229
1274
|
const schematicRunner = RunnerFactory.createSchematic();
|
|
1230
1275
|
if (collection === "@nanoforge-dev/schematics") return new NanoforgeCollection(schematicRunner, directory);
|
|
1231
|
-
throw new
|
|
1276
|
+
throw new CLIError(`Unknown collection: ${collection}`);
|
|
1232
1277
|
}
|
|
1233
1278
|
};
|
|
1234
1279
|
//#endregion
|
|
@@ -1563,27 +1608,24 @@ var Repository = class {
|
|
|
1563
1608
|
async runRequest(request, path, options) {
|
|
1564
1609
|
const res = await this._client[request](path, options);
|
|
1565
1610
|
const data = await res.json();
|
|
1566
|
-
if (!res.ok) throw new
|
|
1611
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1567
1612
|
return data;
|
|
1568
1613
|
}
|
|
1569
1614
|
async runFileRequest(request, path, options) {
|
|
1570
1615
|
const res = await this._client[request](path, options);
|
|
1571
|
-
if (!res.ok) throw new
|
|
1616
|
+
if (!res.ok) throw new ApiRequestError(res.status, (await res.json())["error"]);
|
|
1572
1617
|
return await res.blob();
|
|
1573
1618
|
}
|
|
1574
1619
|
async runRequestBody(request, path, body, options) {
|
|
1575
1620
|
const res = await this._client[request](path, body === void 0 ? void 0 : body instanceof FormData ? body : JSON.stringify(body), options);
|
|
1576
1621
|
const data = await res.json();
|
|
1577
|
-
if (!res.ok) throw new
|
|
1622
|
+
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1578
1623
|
return data;
|
|
1579
1624
|
}
|
|
1580
1625
|
};
|
|
1581
1626
|
new Repository(new HttpClient("https://api.nanoforge.eu"));
|
|
1582
1627
|
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
|
-
}
|
|
1628
|
+
if (!apiKey && force) throw new RegistryAuthenticationError();
|
|
1587
1629
|
return new Repository(new HttpClient("https://api.nanoforge.eu", { headers: {
|
|
1588
1630
|
Authorization: apiKey,
|
|
1589
1631
|
...headers
|
|
@@ -1659,12 +1701,12 @@ var Registry = class {
|
|
|
1659
1701
|
}
|
|
1660
1702
|
static _getPackageFile(filename, dir) {
|
|
1661
1703
|
const path = join$1(getCwd(dir ?? "."), filename);
|
|
1662
|
-
if (!fs.existsSync(path)) throw new
|
|
1704
|
+
if (!fs.existsSync(path)) throw new CLIError("Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!");
|
|
1663
1705
|
try {
|
|
1664
1706
|
fs.accessSync(path, fs.constants.R_OK);
|
|
1665
1707
|
return fs.openAsBlob(path);
|
|
1666
1708
|
} catch {
|
|
1667
|
-
throw new
|
|
1709
|
+
throw new CLIError("Cannot read package file, please verify your file permissions!");
|
|
1668
1710
|
}
|
|
1669
1711
|
}
|
|
1670
1712
|
};
|
|
@@ -1971,7 +2013,7 @@ const getManifestPath = (directory) => {
|
|
|
1971
2013
|
const path = join(directory, n);
|
|
1972
2014
|
if (existsSync(path)) return path;
|
|
1973
2015
|
}
|
|
1974
|
-
throw new
|
|
2016
|
+
throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1975
2017
|
};
|
|
1976
2018
|
const loadManifest = async (directory) => {
|
|
1977
2019
|
let rawData;
|
|
@@ -1981,10 +2023,10 @@ const loadManifest = async (directory) => {
|
|
|
1981
2023
|
} catch {
|
|
1982
2024
|
rawData = null;
|
|
1983
2025
|
}
|
|
1984
|
-
if (!rawData) throw new
|
|
2026
|
+
if (!rawData) throw new ManifestError(`Unable to read or parse file at ${path}`);
|
|
1985
2027
|
const data = plainToInstance(Manifest, rawData, { excludeExtraneousValues: true });
|
|
1986
2028
|
const errors = await validate(data);
|
|
1987
|
-
if (errors.length > 0) throw new
|
|
2029
|
+
if (errors.length > 0) throw new ManifestError(`Validation failed\n${errors.toString()}`);
|
|
1988
2030
|
return data;
|
|
1989
2031
|
};
|
|
1990
2032
|
//#endregion
|
|
@@ -2027,8 +2069,8 @@ var StartAction = class extends AbstractAction {
|
|
|
2027
2069
|
const cert = getStringInput(options, "cert");
|
|
2028
2070
|
const key = getStringInput(options, "key");
|
|
2029
2071
|
if (!cert && !key) return void 0;
|
|
2030
|
-
if (!cert) throw new
|
|
2031
|
-
if (!key) throw new
|
|
2072
|
+
if (!cert) throw new CLIError("No cert entered for SSL. Please enter a cert with --cert.");
|
|
2073
|
+
if (!key) throw new CLIError("No key entered for SSL. Please enter a key with --key.");
|
|
2032
2074
|
return {
|
|
2033
2075
|
cert,
|
|
2034
2076
|
key
|