@nanoforge-dev/cli 2.3.1 → 3.0.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/CHANGELOG.md +47 -0
- package/README.md +17 -7
- package/dist/command.loader.d.ts +0 -2
- package/dist/command.loader.d.ts.map +1 -1
- package/dist/command.loader.js +430 -572
- package/dist/command.loader.js.map +1 -1
- package/dist/nf.js +439 -583
- package/package.json +25 -28
package/dist/nf.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from "commander";
|
|
3
|
-
import "reflect-metadata";
|
|
4
3
|
import { execSync, spawn } from "node:child_process";
|
|
5
4
|
import fs, { existsSync } from "fs";
|
|
6
|
-
import { join, posix, resolve } from "path";
|
|
5
|
+
import { dirname, join, posix, resolve, sep, win32 } from "path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { bgRgb, bold, cyan, green, red, yellow } from "ansis";
|
|
8
8
|
import { get } from "node-emoji";
|
|
9
9
|
import ora from "ora";
|
|
10
10
|
import { defaultClientConfig, defaultServerConfig, parseConfig } from "@nanoforge-dev/config";
|
|
11
11
|
import { watch } from "chokidar";
|
|
12
|
-
import { dirname, join as join$1, relative } from "node:path";
|
|
13
|
-
import { existsSync as existsSync$1, readFileSync, statSync } from "node:fs";
|
|
14
|
-
import {
|
|
12
|
+
import { basename, dirname as dirname$1, isAbsolute, join as join$1, normalize, relative, resolve as resolve$1 } from "node:path";
|
|
13
|
+
import { chmodSync, closeSync, existsSync as existsSync$1, openSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
14
|
+
import { ItemManifest, MANIFEST_FILE, ProjectPackages, RegistryClient, RegistryError, isInsidePath, readArchive, readPackageContents, zipFolder } from "@nanoforge-dev/registry";
|
|
15
|
+
import { glob, readFile } from "node:fs/promises";
|
|
15
16
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
16
17
|
import { spawn as spawn$1 } from "child_process";
|
|
17
18
|
import * as process$1 from "node:process";
|
|
18
19
|
import open from "open";
|
|
19
20
|
import { read, readUserConfig, write, writeUserConfig } from "rc9";
|
|
20
|
-
import { Expose, Type, plainToInstance } from "class-transformer";
|
|
21
|
-
import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, Matches, ValidateNested, validate } from "class-validator";
|
|
22
21
|
import dotenv from "dotenv";
|
|
23
|
-
|
|
22
|
+
// src/lib/tree-kill/tree-kill.ts
|
|
24
23
|
const treeKill = (pid, signal) => {
|
|
25
24
|
function extracted(resolve) {
|
|
26
25
|
const tree = {};
|
|
@@ -104,23 +103,24 @@ function buildProcessTree(parentPid, tree, pidsToProcess, spawnChildProcessesLis
|
|
|
104
103
|
};
|
|
105
104
|
ps.on("close", onClose);
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
//#region src/lib/utils/local-binaries.ts
|
|
106
|
+
// src/lib/utils/local-binaries.ts
|
|
109
107
|
const localBinPathSegments = [
|
|
110
|
-
process.cwd(),
|
|
111
108
|
"node_modules",
|
|
112
109
|
"@nanoforge-dev",
|
|
113
110
|
"cli",
|
|
114
111
|
"dist"
|
|
115
112
|
];
|
|
116
113
|
const localBinExists = () => {
|
|
117
|
-
return existsSync(join(...localBinPathSegments));
|
|
114
|
+
return existsSync(join(process.cwd(), ...localBinPathSegments));
|
|
115
|
+
};
|
|
116
|
+
const getLocalBinCommandLoaderUrl = (cwd = process.cwd(), windows = process.platform === "win32") => {
|
|
117
|
+
const path = (windows ? win32 : posix).join(cwd, ...localBinPathSegments, "command.loader.js");
|
|
118
|
+
return pathToFileURL(path, { windows }).href;
|
|
118
119
|
};
|
|
119
120
|
const loadLocalBinCommandLoader = async () => {
|
|
120
|
-
return (await import(
|
|
121
|
+
return (await import(getLocalBinCommandLoaderUrl())).CommandLoader;
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
-
//#region src/lib/ui/emojis.ts
|
|
123
|
+
// src/lib/ui/emojis.ts
|
|
124
124
|
const Emojis = {
|
|
125
125
|
HEART: get("heart"),
|
|
126
126
|
COFFEE: get("coffee"),
|
|
@@ -140,8 +140,7 @@ const Emojis = {
|
|
|
140
140
|
PRAY: get("pray"),
|
|
141
141
|
WINE: get("wine_glass")
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
//#region src/lib/ui/messages.ts
|
|
143
|
+
// src/lib/ui/messages.ts
|
|
145
144
|
const success = (text) => `${Emojis.ROCKET} ${text}`;
|
|
146
145
|
const failure = (text) => `${Emojis.SCREAM} ${text}`;
|
|
147
146
|
const Messages = {
|
|
@@ -182,6 +181,9 @@ const Messages = {
|
|
|
182
181
|
CREATE_SUCCESS: success("Element successfully created!"),
|
|
183
182
|
CREATE_FAILED: failure("Creation failed!"),
|
|
184
183
|
CREATE_NAME_QUESTION: "What is the name of your component/system?",
|
|
184
|
+
CREATE_PLUGIN_NAME_QUESTION: "What is the name of your plugin (@scope/name)?",
|
|
185
|
+
CREATE_PLUGIN_NEXT: (directory) => `\nPlugin created in ${directory}\n cd ${directory}\n pnpm install\n pnpm dev\nthen start the editor with DEV_PLUGINS=${directory} nf editor <project>.\n`,
|
|
186
|
+
CREATE_THEME_NEXT: (directory) => `\nTheme created in ${directory}\n cd ${directory}\n node build.mjs --watch\nthen start the editor with DEV_PLUGINS=${directory} nf editor <project>, and choose it in Settings › Editor › Appearance.\n`,
|
|
185
187
|
DEV_START: "NanoForge Dev Mode",
|
|
186
188
|
DEV_SUCCESS: "Dev mode ended",
|
|
187
189
|
DEV_FAILED: failure("Dev mode failed!"),
|
|
@@ -198,6 +200,8 @@ const Messages = {
|
|
|
198
200
|
PUBLISH_SUCCESS: success("Publish completed!"),
|
|
199
201
|
PUBLISH_FAILED: failure("Publish failed!"),
|
|
200
202
|
PUBLISH_IN_PROGRESS: (name) => `Publishing ${name}...`,
|
|
203
|
+
PUBLISH_FILES: (name, count, size) => `${name}: ${count} file${count === 1 ? "" : "s"}, ${size} unpacked`,
|
|
204
|
+
PUBLISH_DRY_RUN_SUCCESS: success("Dry run completed: nothing was published."),
|
|
201
205
|
UNPUBLISH_START: "NanoForge Unpublish",
|
|
202
206
|
UNPUBLISH_SUCCESS: success("Unpublish completed!"),
|
|
203
207
|
UNPUBLISH_FAILED: failure("Unpublish failed!"),
|
|
@@ -218,17 +222,14 @@ const Messages = {
|
|
|
218
222
|
GIT_REMOTE_FAILED: (command) => failure(`Git remote addition failed!\nTry running manually: ${bold(command)}`),
|
|
219
223
|
RUNNER_EXECUTION_ERROR: (command) => `\nFailed to execute command: ${bold(command)}`
|
|
220
224
|
};
|
|
221
|
-
|
|
222
|
-
//#region src/lib/ui/prefixes.ts
|
|
225
|
+
// src/lib/ui/prefixes.ts
|
|
223
226
|
const Prefixes = {
|
|
224
227
|
INFO: bgRgb(60, 190, 100).bold.rgb(0, 0, 0)(" Info "),
|
|
225
228
|
ERROR: bgRgb(210, 0, 75).bold.rgb(0, 0, 0)(" Error ")
|
|
226
229
|
};
|
|
227
|
-
|
|
228
|
-
//#region src/lib/ui/spinner.ts
|
|
230
|
+
// src/lib/ui/spinner.ts
|
|
229
231
|
const getSpinner = (message) => ora({ text: message });
|
|
230
|
-
|
|
231
|
-
//#region src/lib/utils/errors.ts
|
|
232
|
+
// src/lib/utils/errors.ts
|
|
232
233
|
var CLIError = class extends Error {
|
|
233
234
|
suggestion;
|
|
234
235
|
constructor(message, suggestion) {
|
|
@@ -263,12 +264,6 @@ var FileSystemError = class extends CLIError {
|
|
|
263
264
|
super(`File System Error [${action}]: ${targetPath}`, "Verify your file permissions and ensure the path exists.");
|
|
264
265
|
}
|
|
265
266
|
};
|
|
266
|
-
var ApiRequestError = class extends CLIError {
|
|
267
|
-
constructor(status, cause) {
|
|
268
|
-
const causeStr = cause && typeof cause === "object" ? JSON.stringify(cause, null, 2) : cause;
|
|
269
|
-
super(`API Request failed (Status ${status})${causeStr ? `\nDetails: ${causeStr}` : ""}`, "Check your network connection, API key, or the registry status.");
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
267
|
const getErrorString = (error) => {
|
|
273
268
|
const stack = error.stack ? error.stack : error.message;
|
|
274
269
|
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
@@ -278,12 +273,22 @@ const getErrorMessage = (error) => {
|
|
|
278
273
|
if (error instanceof Error) return getErrorString(error);
|
|
279
274
|
if (typeof error === "string") return error;
|
|
280
275
|
};
|
|
276
|
+
const REGISTRY_SUGGESTIONS = {
|
|
277
|
+
NOT_FOUND: "Check the package name and version.",
|
|
278
|
+
UNAVAILABLE: "Check your connection and REGISTRY_URL, then try again.",
|
|
279
|
+
CONFLICT: "Raise the version in nanoforge.manifest.json before publishing again."
|
|
280
|
+
};
|
|
281
|
+
/** C0 controls but tab and newline, DEL and C1 controls, bidi overrides and isolates. */
|
|
282
|
+
const isControl = (code) => code < 32 && code !== 9 && code !== 10 || code >= 127 && code <= 159 || code >= 8234 && code <= 8238 || code >= 8294 && code <= 8297;
|
|
283
|
+
/** Registry text comes from the network: no terminal control characters. */
|
|
284
|
+
const printable = (text) => [...text].filter((char) => !isControl(char.codePointAt(0) ?? 0)).join("");
|
|
281
285
|
const handleActionError = (context, error) => {
|
|
282
286
|
console.error();
|
|
283
287
|
console.error(red(context));
|
|
284
|
-
if (error instanceof CLIError) {
|
|
285
|
-
console.error(error.message);
|
|
286
|
-
|
|
288
|
+
if (error instanceof CLIError || error instanceof RegistryError) {
|
|
289
|
+
console.error(printable(error.message));
|
|
290
|
+
const suggestion = error instanceof CLIError ? error.suggestion : REGISTRY_SUGGESTIONS[error.code];
|
|
291
|
+
if (suggestion) console.info(cyan(`\n💡 Suggestion: ${suggestion}`));
|
|
287
292
|
process.exit(1);
|
|
288
293
|
}
|
|
289
294
|
const msg = getErrorMessage(error);
|
|
@@ -294,8 +299,7 @@ const promptError = (err) => {
|
|
|
294
299
|
if (err.name === "ExitPromptError") process.exit(1);
|
|
295
300
|
throw err;
|
|
296
301
|
};
|
|
297
|
-
|
|
298
|
-
//#region src/lib/config/config-loader.ts
|
|
302
|
+
// src/lib/config/config-loader.ts
|
|
299
303
|
const CONFIG_BASE_NAME = "nanoforge.config";
|
|
300
304
|
const CONFIG_EXTENSIONS = ["ts", "js"];
|
|
301
305
|
const getConfigPath = (directory) => {
|
|
@@ -314,8 +318,7 @@ const loadConfig = async (directory) => {
|
|
|
314
318
|
const path = getConfigPath(directory);
|
|
315
319
|
return parseConfig(path);
|
|
316
320
|
};
|
|
317
|
-
|
|
318
|
-
//#region src/lib/config/workspace-config-parser.ts
|
|
321
|
+
// src/lib/config/workspace-config-parser.ts
|
|
319
322
|
const resolvePackageConfig = async (packageDir) => {
|
|
320
323
|
let config;
|
|
321
324
|
try {
|
|
@@ -363,8 +366,8 @@ const parseWorkspaceConfig = async (directory) => {
|
|
|
363
366
|
config
|
|
364
367
|
};
|
|
365
368
|
};
|
|
366
|
-
|
|
367
|
-
|
|
369
|
+
// src/lib/config/workspace-loader.ts
|
|
370
|
+
const isPeerToPeer = (workspace) => workspace.type === "workspace" && workspace.config.network === "p2p";
|
|
368
371
|
const resolveProjects = (workspace, baseDirectory) => {
|
|
369
372
|
if (workspace.type === "project") return [{
|
|
370
373
|
directory: baseDirectory,
|
|
@@ -375,8 +378,7 @@ const resolveProjects = (workspace, baseDirectory) => {
|
|
|
375
378
|
config: project.config
|
|
376
379
|
}));
|
|
377
380
|
};
|
|
378
|
-
|
|
379
|
-
//#region src/lib/input/base-inputs.ts
|
|
381
|
+
// src/lib/input/base-inputs.ts
|
|
380
382
|
const getStringInput = (input, field) => {
|
|
381
383
|
const value = input.get(field)?.value;
|
|
382
384
|
if (value === void 0) return void 0;
|
|
@@ -401,8 +403,7 @@ const getArrayInput = (input, field) => {
|
|
|
401
403
|
if (typeof value === "object" && Array.isArray(value)) return value;
|
|
402
404
|
throw new InvalidCommandArgumentError(field, "array");
|
|
403
405
|
};
|
|
404
|
-
|
|
405
|
-
//#region src/lib/input/ask-inputs.ts
|
|
406
|
+
// src/lib/input/ask-inputs.ts
|
|
406
407
|
const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
407
408
|
if (baseInput !== void 0) return baseInput;
|
|
408
409
|
const res = await askCb();
|
|
@@ -410,19 +411,16 @@ const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
|
410
411
|
if (defaultValue !== void 0) return defaultValue;
|
|
411
412
|
throw new CLIError("No input provided. Please provide a valid value.");
|
|
412
413
|
};
|
|
413
|
-
|
|
414
|
-
//#region src/lib/input/inputs/directory.input.ts
|
|
414
|
+
// src/lib/input/inputs/directory.input.ts
|
|
415
415
|
function getDirectoryInput(inputs, withDefault = true) {
|
|
416
416
|
if (withDefault) return getStringInputWithDefault(inputs, "directory", ".");
|
|
417
417
|
return getStringInput(inputs, "directory");
|
|
418
418
|
}
|
|
419
|
-
|
|
420
|
-
//#region src/lib/input/inputs/editor.input.ts
|
|
419
|
+
// src/lib/input/inputs/editor.input.ts
|
|
421
420
|
const getEditorInput = (inputs) => {
|
|
422
421
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
423
422
|
};
|
|
424
|
-
|
|
425
|
-
//#region src/lib/question/questions/confirm.question.ts
|
|
423
|
+
// src/lib/question/questions/confirm.question.ts
|
|
426
424
|
const askConfirm = async (question, baseOptions) => {
|
|
427
425
|
const options = {
|
|
428
426
|
default: false,
|
|
@@ -433,8 +431,7 @@ const askConfirm = async (question, baseOptions) => {
|
|
|
433
431
|
default: options.default
|
|
434
432
|
}).catch(promptError);
|
|
435
433
|
};
|
|
436
|
-
|
|
437
|
-
//#region src/lib/question/questions/input.question.ts
|
|
434
|
+
// src/lib/question/questions/input.question.ts
|
|
438
435
|
const askInput = async (question, baseOptions) => {
|
|
439
436
|
const options = {
|
|
440
437
|
required: false,
|
|
@@ -460,8 +457,7 @@ const askInputArray = async (question, baseOptions) => {
|
|
|
460
457
|
}).catch(promptError)).split(options.split);
|
|
461
458
|
return options.filter ? res.filter((r) => r.length) : res;
|
|
462
459
|
};
|
|
463
|
-
|
|
464
|
-
//#region src/lib/question/questions/select.question.ts
|
|
460
|
+
// src/lib/question/questions/select.question.ts
|
|
465
461
|
const askSelect = async (question, choices, baseOptions) => {
|
|
466
462
|
const options = {
|
|
467
463
|
loop: true,
|
|
@@ -474,8 +470,7 @@ const askSelect = async (question, choices, baseOptions) => {
|
|
|
474
470
|
default: options.default
|
|
475
471
|
}).catch(promptError);
|
|
476
472
|
};
|
|
477
|
-
|
|
478
|
-
//#region src/lib/input/inputs/name.input.ts
|
|
473
|
+
// src/lib/input/inputs/name.input.ts
|
|
479
474
|
const getNameInput = (inputs) => {
|
|
480
475
|
return getStringInput(inputs, "name");
|
|
481
476
|
};
|
|
@@ -485,91 +480,98 @@ const getNewNameInputOrAsk = (inputs) => {
|
|
|
485
480
|
default: "nanoforge-app"
|
|
486
481
|
}));
|
|
487
482
|
};
|
|
483
|
+
const getPluginNameInputOrAsk = (inputs) => {
|
|
484
|
+
return getInputOrAsk(getNameInput(inputs), () => askInput(Messages.CREATE_PLUGIN_NAME_QUESTION, {
|
|
485
|
+
required: true,
|
|
486
|
+
default: "@nanoforge/ecs"
|
|
487
|
+
}));
|
|
488
|
+
};
|
|
488
489
|
const getCreateNameInputOrAsk = (inputs) => {
|
|
489
490
|
return getInputOrAsk(getNameInput(inputs), () => askInput(Messages.CREATE_NAME_QUESTION, {
|
|
490
491
|
required: true,
|
|
491
492
|
default: "example"
|
|
492
493
|
}));
|
|
493
494
|
};
|
|
494
|
-
|
|
495
|
-
//#region src/lib/input/inputs/path.input.ts
|
|
495
|
+
// src/lib/input/inputs/path.input.ts
|
|
496
496
|
const getPathInput = (inputs) => {
|
|
497
497
|
return getStringInput(inputs, "path");
|
|
498
498
|
};
|
|
499
499
|
const getPathInputWithDefault = (inputs, defaultValue) => {
|
|
500
500
|
return getStringInputWithDefault(inputs, "path", defaultValue);
|
|
501
501
|
};
|
|
502
|
-
|
|
503
|
-
//#region src/lib/input/inputs/server.input.ts
|
|
504
|
-
function getServerInput(inputs) {
|
|
505
|
-
return getBooleanInputWithDefault(inputs, "server", false);
|
|
506
|
-
}
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/lib/input/inputs/watch.input.ts
|
|
502
|
+
// src/lib/input/inputs/watch.input.ts
|
|
509
503
|
const getWatchInput = (inputs) => {
|
|
510
504
|
return getBooleanInputWithDefault(inputs, "watch", false);
|
|
511
505
|
};
|
|
512
|
-
|
|
513
|
-
//#region src/lib/input/inputs/create/type.input.ts
|
|
506
|
+
// src/lib/input/inputs/create/type.input.ts
|
|
514
507
|
const getCreateTypeInput = (inputs) => {
|
|
515
508
|
const res = getStringInput(inputs, "type");
|
|
516
|
-
if (res && [
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
509
|
+
if (res && [
|
|
510
|
+
"component",
|
|
511
|
+
"system",
|
|
512
|
+
"plugin"
|
|
513
|
+
].includes(res)) return res;
|
|
514
|
+
throw new InvalidCommandArgumentError("type", "'component', 'system' or 'plugin'");
|
|
515
|
+
};
|
|
516
|
+
// src/lib/input/inputs/editor/open.input.ts
|
|
521
517
|
const getEditorOpenInput = (inputs, defaultValue) => {
|
|
522
518
|
return getBooleanInputWithDefault(inputs, "open", defaultValue);
|
|
523
519
|
};
|
|
524
|
-
|
|
525
|
-
|
|
520
|
+
// src/lib/input/inputs/editor/port.input.ts
|
|
521
|
+
/** Default port of `nf editor` (the loaders use 3000). */
|
|
522
|
+
const DEFAULT_EDITOR_PORT = 5173;
|
|
523
|
+
const getEditorPortInput = (inputs) => {
|
|
524
|
+
const raw = getStringInput(inputs, "port");
|
|
525
|
+
if (raw === void 0) return DEFAULT_EDITOR_PORT;
|
|
526
|
+
const port = Number(raw);
|
|
527
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid editor port: ${raw}`);
|
|
528
|
+
return port;
|
|
529
|
+
};
|
|
530
|
+
// src/lib/input/inputs/install/lib.input.ts
|
|
526
531
|
function getInstallLibInput(inputs) {
|
|
527
532
|
return getBooleanInputWithDefault(inputs, "lib", false);
|
|
528
533
|
}
|
|
529
|
-
|
|
530
|
-
//#region src/lib/input/inputs/install/names.input.ts
|
|
534
|
+
// src/lib/input/inputs/install/names.input.ts
|
|
531
535
|
const getNamesInput = (inputs) => {
|
|
532
536
|
return getArrayInput(inputs, "names");
|
|
533
537
|
};
|
|
534
538
|
const getInstallNamesInputOrAsk = (inputs) => {
|
|
535
539
|
return getInputOrAsk(getNamesInput(inputs), () => askInputArray(Messages.INSTALL_NAMES_QUESTION, { required: true }));
|
|
536
540
|
};
|
|
537
|
-
|
|
538
|
-
//#region src/lib/input/inputs/login-out/api-key.input.ts
|
|
541
|
+
// src/lib/input/inputs/login-out/api-key.input.ts
|
|
539
542
|
const getApiKeyInput = (inputs) => {
|
|
540
543
|
return getStringInput(inputs, "apiKey");
|
|
541
544
|
};
|
|
542
545
|
const getLoginApiKeyInputOrAsk = (inputs) => {
|
|
543
546
|
return getInputOrAsk(getApiKeyInput(inputs), () => askInput(Messages.LOGIN_API_KEY_QUESTION, { required: true }));
|
|
544
547
|
};
|
|
545
|
-
|
|
546
|
-
//#region src/lib/input/inputs/login-out/local.input.ts
|
|
548
|
+
// src/lib/input/inputs/login-out/local.input.ts
|
|
547
549
|
function getLocalInput(inputs) {
|
|
548
550
|
return getBooleanInputWithDefault(inputs, "local", false);
|
|
549
551
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
+
// src/lib/input/inputs/new/agents.input.ts
|
|
553
|
+
const getNewAgentsInput = (inputs) => {
|
|
554
|
+
return getBooleanInputWithDefault(inputs, "agents", true);
|
|
555
|
+
};
|
|
556
|
+
// src/lib/input/inputs/new/docker.input.ts
|
|
552
557
|
const getNewDockerInput = (inputs) => {
|
|
553
558
|
return getBooleanInput(inputs, "docker");
|
|
554
559
|
};
|
|
555
560
|
const getNewDockerOrAsk = (inputs) => {
|
|
556
561
|
return getInputOrAsk(getNewDockerInput(inputs), () => askConfirm(Messages.NEW_DOCKER_QUESTION, { default: true }));
|
|
557
562
|
};
|
|
558
|
-
|
|
559
|
-
//#region src/lib/input/inputs/new/language.input.ts
|
|
563
|
+
// src/lib/input/inputs/new/language.input.ts
|
|
560
564
|
const getLanguageInput = (inputs) => {
|
|
561
565
|
return getStringInput(inputs, "language");
|
|
562
566
|
};
|
|
563
567
|
const getNewLanguageInputOrAsk = (inputs) => {
|
|
564
568
|
return getInputOrAsk(getLanguageInput(inputs), () => askSelect(Messages.NEW_LANGUAGE_QUESTION, [{ value: "ts" }, { value: "js" }], { default: "ts" }));
|
|
565
569
|
};
|
|
566
|
-
|
|
567
|
-
//#region src/lib/input/inputs/new/lint.input.ts
|
|
570
|
+
// src/lib/input/inputs/new/lint.input.ts
|
|
568
571
|
const getNewLintInput = (inputs) => {
|
|
569
572
|
return getBooleanInputWithDefault(inputs, "lint", true);
|
|
570
573
|
};
|
|
571
|
-
|
|
572
|
-
//#region src/lib/input/inputs/new/package-manager.input.ts
|
|
574
|
+
// src/lib/input/inputs/new/package-manager.input.ts
|
|
573
575
|
const getPackageManagerInput = (inputs) => {
|
|
574
576
|
return getStringInput(inputs, "packageManager");
|
|
575
577
|
};
|
|
@@ -581,32 +583,32 @@ const getNewPackageManagerInputOrAsk = (inputs) => {
|
|
|
581
583
|
{ value: "bun" }
|
|
582
584
|
], { default: "npm" }));
|
|
583
585
|
};
|
|
584
|
-
|
|
585
|
-
//#region src/lib/input/inputs/new/server.input.ts
|
|
586
|
+
// src/lib/input/inputs/new/server.input.ts
|
|
586
587
|
const getNewServerInput = (inputs) => {
|
|
587
588
|
return getBooleanInput(inputs, "server");
|
|
588
589
|
};
|
|
589
590
|
const getNewServerOrAsk = (inputs) => {
|
|
590
591
|
return getInputOrAsk(getNewServerInput(inputs), () => askConfirm(Messages.NEW_SERVER_QUESTION, { default: false }));
|
|
591
592
|
};
|
|
592
|
-
|
|
593
|
-
//#region src/lib/input/inputs/new/skip-install.input.ts
|
|
593
|
+
// src/lib/input/inputs/new/skip-install.input.ts
|
|
594
594
|
const getNewSkipInstallInput = (inputs) => {
|
|
595
595
|
return getBooleanInput(inputs, "skipInstall");
|
|
596
596
|
};
|
|
597
597
|
const getNewSkipInstallOrAsk = (inputs) => {
|
|
598
598
|
return getInputOrAsk(getNewSkipInstallInput(inputs), () => askConfirm(Messages.NEW_SKIP_INSTALL_QUESTION, { default: false }));
|
|
599
599
|
};
|
|
600
|
-
|
|
601
|
-
//#region src/lib/input/inputs/new/strict.input.ts
|
|
600
|
+
// src/lib/input/inputs/new/strict.input.ts
|
|
602
601
|
const getNewStrictInput = (inputs) => {
|
|
603
602
|
return getBooleanInput(inputs, "strict");
|
|
604
603
|
};
|
|
605
604
|
const getNewStrictOrAsk = (inputs) => {
|
|
606
605
|
return getInputOrAsk(getNewStrictInput(inputs), () => askConfirm(Messages.NEW_STRICT_QUESTION, { default: true }));
|
|
607
606
|
};
|
|
608
|
-
|
|
609
|
-
|
|
607
|
+
// src/lib/input/inputs/publish/dry-run.input.ts
|
|
608
|
+
const getDryRunInput = (inputs) => {
|
|
609
|
+
return getBooleanInputWithDefault(inputs, "dryRun", false);
|
|
610
|
+
};
|
|
611
|
+
// src/lib/runner/process-logger.ts
|
|
610
612
|
const formatLines = (chunk) => {
|
|
611
613
|
return chunk.toString().replace(/\r\n|\n/g, "\n").replace(/^\n+|\n+$/g, "").split("\n");
|
|
612
614
|
};
|
|
@@ -619,14 +621,13 @@ const createStderrLogger = (name) => (chunk) => {
|
|
|
619
621
|
const prefix = red(`(${name}) ERROR -`);
|
|
620
622
|
for (const line of formatLines(chunk)) console.error(`${timestamp()} ${prefix} ${line}`);
|
|
621
623
|
};
|
|
622
|
-
|
|
623
|
-
//#region src/lib/utils/path.ts
|
|
624
|
+
// src/lib/utils/path.ts
|
|
624
625
|
const getCwd = (directory) => {
|
|
625
626
|
return resolve(directory);
|
|
626
627
|
};
|
|
627
628
|
const getModulePath = (name, removeLast = false) => {
|
|
628
|
-
const path = import.meta.resolve(name)
|
|
629
|
-
if (removeLast) return path.
|
|
629
|
+
const path = fileURLToPath(import.meta.resolve(name));
|
|
630
|
+
if (removeLast) return path.endsWith(sep) ? path.slice(0, -1) : dirname(path);
|
|
630
631
|
return path;
|
|
631
632
|
};
|
|
632
633
|
const resolveCLINodeBinaryPath = (name) => {
|
|
@@ -642,8 +643,7 @@ const resolveCLINodeBinaryPath = (name) => {
|
|
|
642
643
|
}
|
|
643
644
|
throw new FileSystemError("resolve binary", name);
|
|
644
645
|
};
|
|
645
|
-
|
|
646
|
-
//#region src/lib/utils/spinner.ts
|
|
646
|
+
// src/lib/utils/spinner.ts
|
|
647
647
|
const withSpinner = async (task, loadingMessage, successMessage, failureMessage, onError) => {
|
|
648
648
|
const spinner = getSpinner(loadingMessage);
|
|
649
649
|
spinner.start();
|
|
@@ -663,8 +663,7 @@ const withSpinner = async (task, loadingMessage, successMessage, failureMessage,
|
|
|
663
663
|
};
|
|
664
664
|
}
|
|
665
665
|
};
|
|
666
|
-
|
|
667
|
-
//#region src/lib/package-manager/package-manager.ts
|
|
666
|
+
// src/lib/package-manager/package-manager.ts
|
|
668
667
|
var PackageManager = class {
|
|
669
668
|
name;
|
|
670
669
|
commands;
|
|
@@ -796,8 +795,23 @@ var PackageManager = class {
|
|
|
796
795
|
console.info();
|
|
797
796
|
}
|
|
798
797
|
};
|
|
799
|
-
|
|
800
|
-
|
|
798
|
+
// src/lib/runner/runner.ts
|
|
799
|
+
const IS_WINDOWS = process$1.platform === "win32";
|
|
800
|
+
/**
|
|
801
|
+
* Quotes one argument for cmd.exe: npm, pnpm and yarn are `.cmd` shims there, which Node only starts
|
|
802
|
+
* through a shell. Elsewhere, arguments go to the binary as an array, with no shell. cmd.exe has no
|
|
803
|
+
* escape for `"` and expands `%VAR%` (and `!VAR!` with delayed expansion) inside quotes, so arguments holding them are refused.
|
|
804
|
+
* shortcut: refuses `"`, `%`, `!` and line breaks on Windows, use cross-spawn if real arguments need them.
|
|
805
|
+
*/
|
|
806
|
+
const quoteForCmd = (arg) => {
|
|
807
|
+
if (/["%!\r\n]/.test(arg)) throw new Error(`error: argument not supported on Windows (holds ", %, ! or a line break): ${arg}`);
|
|
808
|
+
return `"${arg.replace(/(\\+)$/, "$1$1")}"`;
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* The cmd.exe command line for a binary and its arguments. A bare name (`npm`) stays unquoted:
|
|
812
|
+
* started as `"npm"`, a `.cmd` shim resolves `%~dp0` to the working directory and can't find itself.
|
|
813
|
+
*/
|
|
814
|
+
const cmdLine = (binary, args) => [/^[\w.-]+$/.test(binary) ? binary : quoteForCmd(binary), ...args.map(quoteForCmd)].join(" ");
|
|
801
815
|
var Runner = class {
|
|
802
816
|
binary;
|
|
803
817
|
baseArgs;
|
|
@@ -808,10 +822,11 @@ var Runner = class {
|
|
|
808
822
|
async run(args, options = {}) {
|
|
809
823
|
const { collect = false, cwd = process$1.cwd(), env, listeners, onFail } = options;
|
|
810
824
|
const spawnOpts = this.buildSpawnOptions(collect, cwd, env);
|
|
811
|
-
const fullArgs = [...this.baseArgs, ...args];
|
|
825
|
+
const fullArgs = [...this.baseArgs, ...args].filter((arg) => arg !== "");
|
|
812
826
|
return new Promise((resolve, reject) => {
|
|
813
|
-
const child = spawn$1(
|
|
827
|
+
const child = IS_WINDOWS ? spawn$1(cmdLine(this.binary, fullArgs), spawnOpts) : spawn$1(this.binary, fullArgs, spawnOpts);
|
|
814
828
|
const output = this.attachOutputHandlers(child, listeners);
|
|
829
|
+
child.on("error", reject);
|
|
815
830
|
child.on("close", (code) => {
|
|
816
831
|
if (code === 0) resolve(this.formatOutput(output, collect));
|
|
817
832
|
else {
|
|
@@ -832,7 +847,7 @@ var Runner = class {
|
|
|
832
847
|
return {
|
|
833
848
|
cwd,
|
|
834
849
|
stdio: collect ? "pipe" : "inherit",
|
|
835
|
-
shell:
|
|
850
|
+
shell: IS_WINDOWS,
|
|
836
851
|
env: {
|
|
837
852
|
...process$1.env,
|
|
838
853
|
...env
|
|
@@ -868,8 +883,7 @@ var Runner = class {
|
|
|
868
883
|
return /* @__PURE__ */ new Error(`Command "${this.binary} ${args.join(" ")}" exited with code ${code}`);
|
|
869
884
|
}
|
|
870
885
|
};
|
|
871
|
-
|
|
872
|
-
//#region src/lib/runner/runner.factory.ts
|
|
886
|
+
// src/lib/runner/runner.factory.ts
|
|
873
887
|
var RunnerFactory = class {
|
|
874
888
|
static create(binary, args) {
|
|
875
889
|
return new Runner(binary, args);
|
|
@@ -878,7 +892,7 @@ var RunnerFactory = class {
|
|
|
878
892
|
return new Runner(resolveCLINodeBinaryPath(binary), args);
|
|
879
893
|
}
|
|
880
894
|
static createSchematic() {
|
|
881
|
-
return new Runner("node", [
|
|
895
|
+
return new Runner("node", [this.resolveSchematicBinary()]);
|
|
882
896
|
}
|
|
883
897
|
static resolveSchematicBinary() {
|
|
884
898
|
try {
|
|
@@ -888,8 +902,7 @@ var RunnerFactory = class {
|
|
|
888
902
|
}
|
|
889
903
|
}
|
|
890
904
|
};
|
|
891
|
-
|
|
892
|
-
//#region src/lib/package-manager/package-manager-configs.ts
|
|
905
|
+
// src/lib/package-manager/package-manager-configs.ts
|
|
893
906
|
const PM_CONFIGS = {
|
|
894
907
|
["bun"]: {
|
|
895
908
|
binary: "bun",
|
|
@@ -965,8 +978,7 @@ const PM_CONFIGS = {
|
|
|
965
978
|
}
|
|
966
979
|
}
|
|
967
980
|
};
|
|
968
|
-
|
|
969
|
-
//#region src/lib/package-manager/package-manager.factory.ts
|
|
981
|
+
// src/lib/package-manager/package-manager.factory.ts
|
|
970
982
|
const LOCK_FILE_MAP = {
|
|
971
983
|
"bun.lock": "bun",
|
|
972
984
|
"package-lock.json": "npm",
|
|
@@ -996,8 +1008,7 @@ var PackageManagerFactory = class {
|
|
|
996
1008
|
return "npm";
|
|
997
1009
|
}
|
|
998
1010
|
};
|
|
999
|
-
|
|
1000
|
-
//#region src/lib/utils/files.ts
|
|
1011
|
+
// src/lib/utils/files.ts
|
|
1001
1012
|
const copyFiles = (from, to) => {
|
|
1002
1013
|
if (!fs.existsSync(from)) return;
|
|
1003
1014
|
if (!fs.existsSync(to)) throw new FileSystemError("directory not found", to);
|
|
@@ -1012,8 +1023,7 @@ const resetFolder = (folder) => {
|
|
|
1012
1023
|
});
|
|
1013
1024
|
fs.mkdirSync(folder, { recursive: true });
|
|
1014
1025
|
};
|
|
1015
|
-
|
|
1016
|
-
//#region src/lib/utils/run-safe.ts
|
|
1026
|
+
// src/lib/utils/run-safe.ts
|
|
1017
1027
|
const runSafe = async (fn, fallback) => {
|
|
1018
1028
|
try {
|
|
1019
1029
|
return await fn();
|
|
@@ -1023,8 +1033,7 @@ const runSafe = async (fn, fallback) => {
|
|
|
1023
1033
|
return fallback;
|
|
1024
1034
|
}
|
|
1025
1035
|
};
|
|
1026
|
-
|
|
1027
|
-
//#region src/action/abstract.action.ts
|
|
1036
|
+
// src/action/abstract.action.ts
|
|
1028
1037
|
var AbstractAction = class {
|
|
1029
1038
|
async run(args, options, extraFlags) {
|
|
1030
1039
|
this.logStart();
|
|
@@ -1052,8 +1061,7 @@ var AbstractAction = class {
|
|
|
1052
1061
|
process.exit(0);
|
|
1053
1062
|
}
|
|
1054
1063
|
};
|
|
1055
|
-
|
|
1056
|
-
//#region src/action/actions/build.action.ts
|
|
1064
|
+
// src/action/actions/build.action.ts
|
|
1057
1065
|
var BuildAction = class extends AbstractAction {
|
|
1058
1066
|
startMessage = Messages.BUILD_START;
|
|
1059
1067
|
successMessage = Messages.BUILD_SUCCESS;
|
|
@@ -1070,7 +1078,17 @@ var BuildAction = class extends AbstractAction {
|
|
|
1070
1078
|
}
|
|
1071
1079
|
resolveTargets(workspaceConfig, baseDirectory, options, isEditor) {
|
|
1072
1080
|
const projects = resolveProjects(workspaceConfig, baseDirectory);
|
|
1073
|
-
|
|
1081
|
+
const targets = projects.map((project) => this.createTarget(project, baseDirectory, options, isEditor, projects.length > 1));
|
|
1082
|
+
if (!isPeerToPeer(workspaceConfig)) return targets;
|
|
1083
|
+
const client = targets.find((target) => target.platform === "browser");
|
|
1084
|
+
if (!client) return targets;
|
|
1085
|
+
const browserServers = targets.filter((target) => target.platform === "node").map((server) => ({
|
|
1086
|
+
...server,
|
|
1087
|
+
name: `${server.name} (browser)`,
|
|
1088
|
+
output: relative(server.directory, join$1(client.directory, client.output, "server")),
|
|
1089
|
+
platform: "browser"
|
|
1090
|
+
}));
|
|
1091
|
+
return [...targets, ...browserServers];
|
|
1074
1092
|
}
|
|
1075
1093
|
createTarget(project, baseDirectory, options, isEditor, disambiguate) {
|
|
1076
1094
|
const isClient = project.config.type === "client";
|
|
@@ -1085,7 +1103,8 @@ var BuildAction = class extends AbstractAction {
|
|
|
1085
1103
|
entry: getStringInputWithDefault(options, isClient ? "clientEntry" : "serverEntry", defaultEntry),
|
|
1086
1104
|
static: getStringInputWithDefault(options, isClient ? "clientStaticDir" : "serverStaticDir", project.config.dir?.assets ?? defaults.dir.assets),
|
|
1087
1105
|
output: getStringInputWithDefault(options, isClient ? "clientOutDir" : "serverOutDir", project.config.out?.dir ?? defaults.out.dir),
|
|
1088
|
-
platform: isClient ? "browser" : "node"
|
|
1106
|
+
platform: isClient ? "browser" : "node",
|
|
1107
|
+
sourcemap: isEditor
|
|
1089
1108
|
};
|
|
1090
1109
|
}
|
|
1091
1110
|
async buildAll(targets, isWatch) {
|
|
@@ -1105,14 +1124,15 @@ var BuildAction = class extends AbstractAction {
|
|
|
1105
1124
|
"--asset-naming",
|
|
1106
1125
|
"[name].[ext]",
|
|
1107
1126
|
"--target",
|
|
1108
|
-
target.platform
|
|
1127
|
+
target.platform,
|
|
1128
|
+
...target.sourcemap ? ["--sourcemap=linked"] : []
|
|
1109
1129
|
], rebuild);
|
|
1110
1130
|
}, false);
|
|
1111
1131
|
if (isWatch) this.watchDirectory(target.directory, target.entry, () => executeBuild(true));
|
|
1112
1132
|
return await executeBuild() !== false;
|
|
1113
1133
|
}
|
|
1114
1134
|
watchDirectory(directory, entry, onChange) {
|
|
1115
|
-
const watchPath = dirname(join$1(getCwd(directory), entry));
|
|
1135
|
+
const watchPath = dirname$1(join$1(getCwd(directory), entry));
|
|
1116
1136
|
watch(watchPath).on("change", onChange);
|
|
1117
1137
|
}
|
|
1118
1138
|
enterWatchMode() {
|
|
@@ -1131,8 +1151,7 @@ var BuildAction = class extends AbstractAction {
|
|
|
1131
1151
|
copyFiles(from, to);
|
|
1132
1152
|
}
|
|
1133
1153
|
};
|
|
1134
|
-
|
|
1135
|
-
//#region src/lib/schematics/abstract.collection.ts
|
|
1154
|
+
// src/lib/schematics/abstract.collection.ts
|
|
1136
1155
|
var AbstractCollection = class {
|
|
1137
1156
|
collection;
|
|
1138
1157
|
runner;
|
|
@@ -1157,7 +1176,7 @@ var AbstractCollection = class {
|
|
|
1157
1176
|
]) {
|
|
1158
1177
|
return [
|
|
1159
1178
|
...flags,
|
|
1160
|
-
|
|
1179
|
+
`${getModulePath(this.collection + "/collection.json")}:${name}`,
|
|
1161
1180
|
...this.serializeOptions(options)
|
|
1162
1181
|
];
|
|
1163
1182
|
}
|
|
@@ -1165,8 +1184,7 @@ var AbstractCollection = class {
|
|
|
1165
1184
|
return options.flatMap((option) => option.toCommandString());
|
|
1166
1185
|
}
|
|
1167
1186
|
};
|
|
1168
|
-
|
|
1169
|
-
//#region src/lib/schematics/nanoforge.collection.ts
|
|
1187
|
+
// src/lib/schematics/nanoforge.collection.ts
|
|
1170
1188
|
var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
1171
1189
|
static schematics = [
|
|
1172
1190
|
{
|
|
@@ -1188,6 +1206,11 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1188
1206
|
name: "system",
|
|
1189
1207
|
alias: "system",
|
|
1190
1208
|
description: "Generate a System for an application"
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
name: "plugin",
|
|
1212
|
+
alias: "plugin",
|
|
1213
|
+
description: "Generate an editor plugin"
|
|
1191
1214
|
}
|
|
1192
1215
|
];
|
|
1193
1216
|
constructor(runner, cwd) {
|
|
@@ -1206,8 +1229,7 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1206
1229
|
return schematic.name;
|
|
1207
1230
|
}
|
|
1208
1231
|
};
|
|
1209
|
-
|
|
1210
|
-
//#region src/lib/schematics/collection.factory.ts
|
|
1232
|
+
// src/lib/schematics/collection.factory.ts
|
|
1211
1233
|
var CollectionFactory = class {
|
|
1212
1234
|
static create(collection, directory) {
|
|
1213
1235
|
const schematicRunner = RunnerFactory.createSchematic();
|
|
@@ -1215,14 +1237,12 @@ var CollectionFactory = class {
|
|
|
1215
1237
|
throw new CLIError(`Unknown collection: ${collection}`);
|
|
1216
1238
|
}
|
|
1217
1239
|
};
|
|
1218
|
-
|
|
1219
|
-
//#region src/lib/utils/formatting.ts
|
|
1240
|
+
// src/lib/utils/formatting.ts
|
|
1220
1241
|
const toKebabCase = (str) => {
|
|
1221
1242
|
return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
1222
1243
|
};
|
|
1223
1244
|
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1224
|
-
|
|
1225
|
-
//#region src/lib/schematics/schematic.option.ts
|
|
1245
|
+
// src/lib/schematics/schematic.option.ts
|
|
1226
1246
|
var SchematicOption = class {
|
|
1227
1247
|
name;
|
|
1228
1248
|
value;
|
|
@@ -1235,25 +1255,15 @@ var SchematicOption = class {
|
|
|
1235
1255
|
}
|
|
1236
1256
|
toCommandString(prefix) {
|
|
1237
1257
|
const normalizedName = `${prefix ? `${prefix}.` : ""}${this.normalizedName}`;
|
|
1238
|
-
if (typeof this.value === "string") {
|
|
1239
|
-
|
|
1240
|
-
else if (this.name === "version" || this.name === "path") return [`--${normalizedName}=${this.value}`];
|
|
1241
|
-
else return [`--${normalizedName}="${this.value}"`];
|
|
1242
|
-
} else if (typeof this.value === "boolean") {
|
|
1258
|
+
if (typeof this.value === "string") return [`--${normalizedName}=${this.name === "name" ? toKebabCase(this.value) : this.value}`];
|
|
1259
|
+
else if (typeof this.value === "boolean") {
|
|
1243
1260
|
const str = normalizedName;
|
|
1244
1261
|
return this.value ? [`--${str}=true`] : [`--${str}=false`];
|
|
1245
1262
|
} else if (Array.isArray(this.value)) return this.value.reduce((old, option) => [...old, ...option.toCommandString(normalizedName)], []);
|
|
1246
1263
|
else return [`--${normalizedName}=${this.value}`];
|
|
1247
1264
|
}
|
|
1248
|
-
format() {
|
|
1249
|
-
return toKebabCase(this.value).split("").reduce((content, char) => {
|
|
1250
|
-
if (char === "(" || char === ")" || char === "[" || char === "]") return `${content}\\${char}`;
|
|
1251
|
-
return `${content}${char}`;
|
|
1252
|
-
}, "");
|
|
1253
|
-
}
|
|
1254
1265
|
};
|
|
1255
|
-
|
|
1256
|
-
//#region src/action/common/schematics.ts
|
|
1266
|
+
// src/action/common/schematics.ts
|
|
1257
1267
|
const executeSchematic = async (name, collection, schematicName, options, fileToWatch) => {
|
|
1258
1268
|
const execute = async (isRebuild = false) => {
|
|
1259
1269
|
const message = isRebuild ? Messages.SCHEMATIC_WATCH_IN_PROGRESS(name) : Messages.SCHEMATIC_IN_PROGRESS(name);
|
|
@@ -1273,19 +1283,19 @@ const mapSchematicOptions = (inputs) => {
|
|
|
1273
1283
|
return acc;
|
|
1274
1284
|
}, []);
|
|
1275
1285
|
};
|
|
1276
|
-
|
|
1277
|
-
//#region src/action/actions/create.action.ts
|
|
1286
|
+
// src/action/actions/create.action.ts
|
|
1278
1287
|
var CreateAction = class extends AbstractAction {
|
|
1279
1288
|
startMessage = Messages.CREATE_START;
|
|
1280
1289
|
successMessage = Messages.CREATE_SUCCESS;
|
|
1281
1290
|
failureMessage = Messages.CREATE_FAILED;
|
|
1282
1291
|
async handle(args, options) {
|
|
1283
1292
|
const directory = getDirectoryInput(options);
|
|
1293
|
+
const type = getCreateTypeInput(args);
|
|
1294
|
+
if (type === "plugin") return this.generatePlugin(directory, options);
|
|
1284
1295
|
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1285
1296
|
if (workspaceConfig.type === "workspace") throw new CLIError(`Cannot run 'create' at a workspace root ('${directory}').`, "Run it from within a specific client/server project directory instead (-d <project-directory>).");
|
|
1286
1297
|
const { config } = workspaceConfig;
|
|
1287
1298
|
const defaults = config.type === "client" ? defaultClientConfig : defaultServerConfig;
|
|
1288
|
-
const type = getCreateTypeInput(args);
|
|
1289
1299
|
const name = await getCreateNameInputOrAsk(options);
|
|
1290
1300
|
const path = getPathInputWithDefault(options, config.dir?.[type === "component" ? "components" : "systems"] ?? defaults.dir[type === "component" ? "components" : "systems"]);
|
|
1291
1301
|
await this.generateElement(directory, type, {
|
|
@@ -1296,13 +1306,29 @@ var CreateAction = class extends AbstractAction {
|
|
|
1296
1306
|
});
|
|
1297
1307
|
return {};
|
|
1298
1308
|
}
|
|
1309
|
+
/** Generates a new editor plugin in `<directory>/<path or the plugin's short name>`. */
|
|
1310
|
+
async generatePlugin(directory, options) {
|
|
1311
|
+
const name = await getPluginNameInputOrAsk(options);
|
|
1312
|
+
const path = getPathInputWithDefault(options, name.split("/").at(-1) ?? name);
|
|
1313
|
+
const target = resolve$1(directory, path);
|
|
1314
|
+
if (existsSync$1(target) && readdirSync(target).length) throw new CLIError(`'${target}' already exists and is not empty.`, "Choose another folder with --path.");
|
|
1315
|
+
const template = getStringInputWithDefault(options, "template", "panel");
|
|
1316
|
+
if (template !== "panel" && template !== "theme") throw new CLIError(`'${template}' is not a plugin template.`, "Use --template panel (a panel, a command and a setting) or --template theme (a color theme).");
|
|
1317
|
+
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1318
|
+
await executeSchematic("Plugin", collection, "plugin", {
|
|
1319
|
+
name,
|
|
1320
|
+
directory: path,
|
|
1321
|
+
template
|
|
1322
|
+
});
|
|
1323
|
+
console.info(template === "theme" ? Messages.CREATE_THEME_NEXT(target) : Messages.CREATE_PLUGIN_NEXT(target));
|
|
1324
|
+
return {};
|
|
1325
|
+
}
|
|
1299
1326
|
async generateElement(directory, type, values) {
|
|
1300
1327
|
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1301
1328
|
await executeSchematic(capitalize(type), collection, type, values);
|
|
1302
1329
|
}
|
|
1303
1330
|
};
|
|
1304
|
-
|
|
1305
|
-
//#region src/action/actions/dev.action.ts
|
|
1331
|
+
// src/action/actions/dev.action.ts
|
|
1306
1332
|
var DevAction = class extends AbstractAction {
|
|
1307
1333
|
startMessage = Messages.DEV_START;
|
|
1308
1334
|
successMessage = Messages.DEV_SUCCESS;
|
|
@@ -1336,8 +1362,31 @@ var DevAction = class extends AbstractAction {
|
|
|
1336
1362
|
});
|
|
1337
1363
|
}
|
|
1338
1364
|
};
|
|
1339
|
-
|
|
1340
|
-
|
|
1365
|
+
// src/lib/utils/editor-target.ts
|
|
1366
|
+
/**
|
|
1367
|
+
* Where `nf editor [path]` roots the editor: the working directory, or the project's parent
|
|
1368
|
+
* folder when the project is outside of it.
|
|
1369
|
+
*/
|
|
1370
|
+
const resolveEditorTarget = (directory, path) => {
|
|
1371
|
+
const fsRoot = resolve$1(directory);
|
|
1372
|
+
if (!path) return { fsRoot };
|
|
1373
|
+
const project = resolve$1(fsRoot, path);
|
|
1374
|
+
const inside = relative(fsRoot, project);
|
|
1375
|
+
if (!inside.startsWith("..") && !isAbsolute(inside)) return {
|
|
1376
|
+
fsRoot,
|
|
1377
|
+
projectPath: inside || "."
|
|
1378
|
+
};
|
|
1379
|
+
return {
|
|
1380
|
+
fsRoot: dirname$1(project),
|
|
1381
|
+
projectPath: basename(project)
|
|
1382
|
+
};
|
|
1383
|
+
};
|
|
1384
|
+
/** URL the browser opens: the project when there is one, the project list otherwise. */
|
|
1385
|
+
const editorUrl = (port, target) => {
|
|
1386
|
+
const base = `http://localhost:${port}`;
|
|
1387
|
+
return target.projectPath === void 0 ? base : `${base}/load?path=${encodeURIComponent(target.projectPath)}`;
|
|
1388
|
+
};
|
|
1389
|
+
// src/action/actions/editor.action.ts
|
|
1341
1390
|
var EditorAction = class extends AbstractAction {
|
|
1342
1391
|
startMessage = Messages.EDITOR_START;
|
|
1343
1392
|
successMessage = Messages.EDITOR_SUCCESS;
|
|
@@ -1345,30 +1394,47 @@ var EditorAction = class extends AbstractAction {
|
|
|
1345
1394
|
async handle(args, options) {
|
|
1346
1395
|
const directory = getDirectoryInput(options);
|
|
1347
1396
|
const path = getPathInput(args);
|
|
1397
|
+
const port = getEditorPortInput(options);
|
|
1348
1398
|
const shouldOpen = getEditorOpenInput(options, !!path);
|
|
1349
|
-
const
|
|
1399
|
+
const target = resolveEditorTarget(getCwd(directory), path);
|
|
1400
|
+
const url = editorUrl(port, target);
|
|
1350
1401
|
console.log(`\n🔗 Editor running! Open it in your browser: \x1b[36m${url}\x1b[0m\n`);
|
|
1351
|
-
this.startEditor(
|
|
1352
|
-
if (shouldOpen) await this.openBrowser(url);
|
|
1402
|
+
this.startEditor(target.fsRoot, port);
|
|
1403
|
+
if (shouldOpen && await this.waitForEditor(port)) await this.openBrowser(url);
|
|
1353
1404
|
return { keepAlive: true };
|
|
1354
1405
|
}
|
|
1355
|
-
async startEditor(
|
|
1406
|
+
async startEditor(fsRoot, port) {
|
|
1356
1407
|
const editorPath = join(getModulePath("@nanoforge-dev/editor/package.json", true), "dist", "index.js");
|
|
1357
1408
|
await runSafe(async () => {
|
|
1358
|
-
await PackageManagerFactory.create("local_bun").run("Editor",
|
|
1409
|
+
await PackageManagerFactory.create("local_bun").run("Editor", fsRoot, editorPath, [], {
|
|
1410
|
+
PORT: String(port),
|
|
1411
|
+
FS_ROOT: fsRoot,
|
|
1412
|
+
HOST: "127.0.0.1",
|
|
1413
|
+
PUBLIC_MODE: "OFFLINE"
|
|
1414
|
+
}, [], true);
|
|
1359
1415
|
});
|
|
1360
1416
|
}
|
|
1417
|
+
/** Waits until the editor answers (up to 30 s) so the browser doesn't open on an error page. */
|
|
1418
|
+
async waitForEditor(port) {
|
|
1419
|
+
for (const deadline = Date.now() + 3e4; Date.now() < deadline;) {
|
|
1420
|
+
try {
|
|
1421
|
+
if ((await fetch(`http://127.0.0.1:${port}/healthz`)).ok) return true;
|
|
1422
|
+
} catch {}
|
|
1423
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
1424
|
+
}
|
|
1425
|
+
return false;
|
|
1426
|
+
}
|
|
1361
1427
|
async openBrowser(url) {
|
|
1362
1428
|
await open(url);
|
|
1363
1429
|
}
|
|
1364
1430
|
};
|
|
1365
|
-
|
|
1366
|
-
//#region src/lib/constants.ts
|
|
1431
|
+
// src/lib/constants.ts
|
|
1367
1432
|
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1368
|
-
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1369
1433
|
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1370
|
-
|
|
1371
|
-
|
|
1434
|
+
const NANOFORGE_DIR = ".nanoforge";
|
|
1435
|
+
/** The API holding `/registry/…`: set at build time (`.env.build`), the editor's default too. */
|
|
1436
|
+
const REGISTRY_URL = "https://api.nanoforge.eu";
|
|
1437
|
+
// src/lib/utils/object.ts
|
|
1372
1438
|
const isObject = (item) => {
|
|
1373
1439
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
1374
1440
|
};
|
|
@@ -1382,11 +1448,9 @@ const deepMerge = (target, ...sources) => {
|
|
|
1382
1448
|
return deepMerge(target, ...sources);
|
|
1383
1449
|
};
|
|
1384
1450
|
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1385
|
-
|
|
1386
|
-
//#region src/lib/global-config/global-config-defaults.ts
|
|
1451
|
+
// src/lib/global-config/global-config-defaults.ts
|
|
1387
1452
|
const GLOBAL_CONFIG_DEFAULTS = {};
|
|
1388
|
-
|
|
1389
|
-
//#region src/lib/global-config/global-config-handler.ts
|
|
1453
|
+
// src/lib/global-config/global-config-handler.ts
|
|
1390
1454
|
var GlobalConfigHandler = class {
|
|
1391
1455
|
static read(dir) {
|
|
1392
1456
|
const dirConfig = this._readConfig(read, false, dir);
|
|
@@ -1400,8 +1464,12 @@ var GlobalConfigHandler = class {
|
|
|
1400
1464
|
name: GLOBAL_CONFIG_FILE_NAME,
|
|
1401
1465
|
dir
|
|
1402
1466
|
};
|
|
1403
|
-
if (local)
|
|
1404
|
-
|
|
1467
|
+
if (local) {
|
|
1468
|
+
const path = resolve$1(dir ?? process.cwd(), GLOBAL_CONFIG_FILE_NAME);
|
|
1469
|
+
closeSync(openSync(path, "a", 384));
|
|
1470
|
+
chmodSync(path, 384);
|
|
1471
|
+
write(config, options);
|
|
1472
|
+
} else writeUserConfig(config, options);
|
|
1405
1473
|
}
|
|
1406
1474
|
static _readConfig(func, force, dir) {
|
|
1407
1475
|
const res = func({
|
|
@@ -1411,257 +1479,136 @@ var GlobalConfigHandler = class {
|
|
|
1411
1479
|
if (!force) {
|
|
1412
1480
|
if (isEmpty(res)) return null;
|
|
1413
1481
|
}
|
|
1414
|
-
return deepMerge(GLOBAL_CONFIG_DEFAULTS, res);
|
|
1415
|
-
}
|
|
1416
|
-
};
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
//#endregion
|
|
1510
|
-
//#region src/lib/http/repository.ts
|
|
1511
|
-
var Repository = class {
|
|
1512
|
-
_client;
|
|
1513
|
-
constructor(client) {
|
|
1514
|
-
this._client = client;
|
|
1515
|
-
}
|
|
1516
|
-
get(path, options) {
|
|
1517
|
-
return this.runRequest("get", path, options);
|
|
1518
|
-
}
|
|
1519
|
-
getFile(path, options) {
|
|
1520
|
-
return this.runFileRequest("get", path, options);
|
|
1521
|
-
}
|
|
1522
|
-
post(path, body, options) {
|
|
1523
|
-
return this.runRequestBody("post", path, body ?? {}, options);
|
|
1524
|
-
}
|
|
1525
|
-
put(path, body, options) {
|
|
1526
|
-
return this.runRequestBody("put", path, body ?? {}, options);
|
|
1527
|
-
}
|
|
1528
|
-
patch(path, body, options) {
|
|
1529
|
-
return this.runRequestBody("patch", path, body ?? {}, options);
|
|
1530
|
-
}
|
|
1531
|
-
delete(path, options) {
|
|
1532
|
-
return this.runRequest("delete", path, options);
|
|
1533
|
-
}
|
|
1534
|
-
async runRequest(request, path, options) {
|
|
1535
|
-
const res = await this._client[request](path, options);
|
|
1536
|
-
const data = await res.json();
|
|
1537
|
-
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1538
|
-
return data;
|
|
1539
|
-
}
|
|
1540
|
-
async runFileRequest(request, path, options) {
|
|
1541
|
-
const res = await this._client[request](path, options);
|
|
1542
|
-
if (!res.ok) throw new ApiRequestError(res.status, (await res.json())["error"]);
|
|
1543
|
-
return await res.blob();
|
|
1544
|
-
}
|
|
1545
|
-
async runRequestBody(request, path, body, options) {
|
|
1546
|
-
const res = await this._client[request](path, body === void 0 ? void 0 : body instanceof FormData ? body : JSON.stringify(body), options);
|
|
1547
|
-
const data = await res.json();
|
|
1548
|
-
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1549
|
-
return data;
|
|
1550
|
-
}
|
|
1551
|
-
};
|
|
1552
|
-
new Repository(new HttpClient("https://api.nanoforge.eu"));
|
|
1553
|
-
const withAuth = (apiKey, force = false, headers = { "Content-Type": "application/json" }) => {
|
|
1554
|
-
if (!apiKey && force) throw new RegistryAuthenticationError();
|
|
1555
|
-
return new Repository(new HttpClient("https://api.nanoforge.eu", { headers: {
|
|
1556
|
-
Authorization: apiKey,
|
|
1557
|
-
...headers
|
|
1558
|
-
} }));
|
|
1559
|
-
};
|
|
1560
|
-
//#endregion
|
|
1561
|
-
//#region src/lib/manifest/manifest-resolver.ts
|
|
1562
|
-
const resolveManifestDependencies = async (names, dir) => {
|
|
1563
|
-
const client = withAuth(GlobalConfigHandler.read(dir).apiKey, false);
|
|
1564
|
-
return concatDeps(await Promise.all(names.map(async (d) => resolveDeps(d, client))));
|
|
1565
|
-
};
|
|
1566
|
-
const resolveManifest = async (name, client) => {
|
|
1567
|
-
return await client.get(`/registry/${name}`);
|
|
1568
|
-
};
|
|
1569
|
-
const resolveDeps = async (name, client) => {
|
|
1570
|
-
const manifest = await resolveManifest(name, client);
|
|
1571
|
-
const baseDeps = manifest.dependencies ?? [];
|
|
1572
|
-
const deps = await Promise.all(baseDeps.map(async (d) => resolveDeps(d, client)));
|
|
1573
|
-
return concatDeps([{
|
|
1574
|
-
nf: { [manifest.name]: manifest },
|
|
1575
|
-
npm: getNpmDeps(manifest)
|
|
1576
|
-
}].concat(deps));
|
|
1577
|
-
};
|
|
1578
|
-
const getNpmDeps = (manifest) => {
|
|
1579
|
-
return Object.entries({
|
|
1580
|
-
...manifest.npmDependencies,
|
|
1581
|
-
...manifest.libDependencies
|
|
1582
|
-
});
|
|
1583
|
-
};
|
|
1584
|
-
const concatDeps = (deps) => {
|
|
1585
|
-
return {
|
|
1586
|
-
npm: deps.map(({ npm }) => npm).flat(),
|
|
1587
|
-
nf: Object.fromEntries(deps.map(({ nf }) => Object.entries(nf)).flat())
|
|
1482
|
+
return deepMerge({}, GLOBAL_CONFIG_DEFAULTS, res);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
// src/lib/registry/registry.ts
|
|
1486
|
+
/** The registry, with `apiKey` sent to it (and only to it) when given. */
|
|
1487
|
+
const createRegistry = (apiKey) => new RegistryClient({
|
|
1488
|
+
baseUrl: REGISTRY_URL,
|
|
1489
|
+
headers: () => apiKey ? { authorization: `Bearer ${apiKey}` } : {}
|
|
1490
|
+
});
|
|
1491
|
+
/** The registry with the key `nf login` saved for `directory`; refuses without one. */
|
|
1492
|
+
const createAuthenticatedRegistry = (directory) => {
|
|
1493
|
+
const { apiKey } = GlobalConfigHandler.read(directory);
|
|
1494
|
+
if (!apiKey) throw new RegistryAuthenticationError();
|
|
1495
|
+
return createRegistry(apiKey);
|
|
1496
|
+
};
|
|
1497
|
+
/** Folders never packed by `nf publish`, wherever they are. */
|
|
1498
|
+
const DENIED_FOLDERS = /* @__PURE__ */ new Set([
|
|
1499
|
+
".git",
|
|
1500
|
+
"node_modules",
|
|
1501
|
+
"nf_modules",
|
|
1502
|
+
NANOFORGE_DIR,
|
|
1503
|
+
".aws",
|
|
1504
|
+
".docker"
|
|
1505
|
+
]);
|
|
1506
|
+
/** Files that hold secrets: env files, credentials, keys and keystores, private SSH keys. */
|
|
1507
|
+
const DENIED_FILES = [
|
|
1508
|
+
/^\.env/i,
|
|
1509
|
+
/^\.npmrc$/i,
|
|
1510
|
+
/^\.netrc$/i,
|
|
1511
|
+
/^\.git-credentials$/i,
|
|
1512
|
+
/^\.pgpass$/i,
|
|
1513
|
+
/^credentials\.json$/i,
|
|
1514
|
+
/\.(pem|key|p12|pfx|keystore|ppk)$/i,
|
|
1515
|
+
/^id_[^.]*$/i,
|
|
1516
|
+
/^id_(rsa|dsa|ecdsa|ed25519|xmss)(?!.*\.pub$)/i
|
|
1517
|
+
];
|
|
1518
|
+
/** What a plugin build writes next to its `entry`: the only files packed from that folder. */
|
|
1519
|
+
const BUILD_FILES = /\.(c?js|mjs|css|map|wasm|svg|png|jpe?g|gif|webp|avif|woff2?|ttf|otf)$/i;
|
|
1520
|
+
/** Files at the root packed with every package. */
|
|
1521
|
+
const ROOT_FILES = /^(readme|license|licence|changelog)(\..*)?$/i;
|
|
1522
|
+
const isDenied = (path, isDirectory) => {
|
|
1523
|
+
const name = basename(path);
|
|
1524
|
+
if (isDirectory) return DENIED_FOLDERS.has(name.toLowerCase());
|
|
1525
|
+
return name === ".nanoforgerc" || DENIED_FILES.some((pattern) => pattern.test(name));
|
|
1526
|
+
};
|
|
1527
|
+
/** Every string a value holds, at any depth. */
|
|
1528
|
+
const strings = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(strings) : typeof value === "object" && value !== null ? Object.values(value).flatMap(strings) : [];
|
|
1529
|
+
/** Every `path` field a value holds, at any depth (a plugin's `contributes`: icons…). */
|
|
1530
|
+
const pathFields = (value) => Array.isArray(value) ? value.flatMap(pathFields) : typeof value === "object" && value !== null ? Object.entries(value).flatMap(([key, field]) => key === "path" ? [field] : pathFields(field)) : [];
|
|
1531
|
+
/** The SVG files an icon theme maps its icon names to (`contributes.iconThemes[].icons`). */
|
|
1532
|
+
const iconThemeFiles = (contributes) => {
|
|
1533
|
+
const themes = contributes?.iconThemes;
|
|
1534
|
+
return Array.isArray(themes) ? themes.flatMap((theme) => strings(theme?.icons)) : [];
|
|
1535
|
+
};
|
|
1536
|
+
const readJson = async (file) => JSON.parse(await readFile(file, "utf8"));
|
|
1537
|
+
/**
|
|
1538
|
+
* What the manifest names, from the package root: its `contents` and older `items`, its
|
|
1539
|
+
* sub-manifests (`include`) and their contents, its `readme`; for a plugin, the `path` fields of
|
|
1540
|
+
* `contributes` and the files of its icon themes. Folders end with `/`. A plugin's `entry` folders are `buildFolders`.
|
|
1541
|
+
*/
|
|
1542
|
+
const namedPaths = async (root, manifest) => {
|
|
1543
|
+
const described = await readPackageContents(manifest, (path) => readJson(join$1(root, path)));
|
|
1544
|
+
const plugin = manifest.type === "plugin";
|
|
1545
|
+
return [
|
|
1546
|
+
MANIFEST_FILE,
|
|
1547
|
+
...described.contents.map(({ path }) => path),
|
|
1548
|
+
...described.manifests,
|
|
1549
|
+
...pathFields(manifest.items).flatMap(strings),
|
|
1550
|
+
...strings(manifest.readme),
|
|
1551
|
+
...plugin ? [...pathFields(manifest.contributes).flatMap(strings), ...iconThemeFiles(manifest.contributes)] : []
|
|
1552
|
+
].map((path) => path.replace(/^\.\//, "")).filter((path) => isInsidePath(path.replace(/\/$/, ""))).map((path) => path.endsWith("/") || !statSync(join$1(root, path), { throwIfNoEntry: false })?.isDirectory() ? path : `${path}/`);
|
|
1553
|
+
};
|
|
1554
|
+
/** The folders of a plugin's `entry` files, `""` for the root: only build output is packed there. */
|
|
1555
|
+
const buildFolders = (manifest) => manifest.type !== "plugin" ? [] : strings(manifest.entry).map((entry) => dirname$1(normalize(entry))).filter((folder) => folder === "." || isInsidePath(folder)).map((folder) => folder === "." ? "" : `${folder}/`);
|
|
1556
|
+
/**
|
|
1557
|
+
* What `nf publish` leaves out of the package at `root`. Only what the manifest names is packed
|
|
1558
|
+
* (see `namedPaths`), with the root's `README*`, `LICENSE*` and `CHANGELOG*`; inside that, secrets
|
|
1559
|
+
* (`.env*`, `.npmrc`, `.netrc`, `.git-credentials`, `.pgpass`, `credentials.json`, the
|
|
1560
|
+
* `.nanoforgerc` of `nf login --local`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `*.keystore`, `*.ppk`,
|
|
1561
|
+
* private SSH keys `id_*`) and `.git`, `node_modules`, `nf_modules`, `.nanoforge`, `.aws` and
|
|
1562
|
+
* `.docker` folders stay out at any depth. `.gitignore` is not read.
|
|
1563
|
+
*/
|
|
1564
|
+
const publishIgnore = async (root, manifest) => {
|
|
1565
|
+
const named = await namedPaths(root, manifest);
|
|
1566
|
+
const builds = buildFolders(manifest);
|
|
1567
|
+
const folders = named.filter((path) => path.endsWith("/"));
|
|
1568
|
+
const files = new Set(named.filter((path) => !path.endsWith("/")));
|
|
1569
|
+
const inFolder = (path) => folders.some((folder) => path.startsWith(folder));
|
|
1570
|
+
const inBuild = (path) => builds.some((folder) => path.startsWith(folder));
|
|
1571
|
+
return (path, isDirectory) => {
|
|
1572
|
+
if (isDenied(path, isDirectory)) return true;
|
|
1573
|
+
if (inFolder(isDirectory ? `${path}/` : path)) return false;
|
|
1574
|
+
if (isDirectory ? inBuild(`${path}/`) : inBuild(path) && BUILD_FILES.test(path)) return false;
|
|
1575
|
+
if (isDirectory) return ![...folders, ...files].some((allowed) => allowed.startsWith(`${path}/`));
|
|
1576
|
+
return !files.has(path) && !(!path.includes("/") && ROOT_FILES.test(path));
|
|
1588
1577
|
};
|
|
1589
1578
|
};
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
const filename = manifest.publish?.paths?.package ?? "index.ts";
|
|
1596
|
-
const file = await this._getPackageFile(filename, dir);
|
|
1597
|
-
const data = new FormData();
|
|
1598
|
-
for (const key of Object.keys(manifest)) {
|
|
1599
|
-
const value = manifest[key];
|
|
1600
|
-
if (!value) continue;
|
|
1601
|
-
data.append(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
1602
|
-
}
|
|
1603
|
-
data.append("_packageFile", file, filename);
|
|
1604
|
-
await client.put(`/registry/${manifest.name}`, data);
|
|
1605
|
-
}
|
|
1606
|
-
static async unpublish(manifest, dir) {
|
|
1607
|
-
await this._getClient(dir, true).delete(`/registry/${manifest.name}`);
|
|
1608
|
-
}
|
|
1609
|
-
static async install(manifests, dir) {
|
|
1610
|
-
const cwd = getCwd(dir);
|
|
1611
|
-
const client = this._getClient(dir, false);
|
|
1612
|
-
for (const manifest of manifests) await this.installPackage(client, manifest, cwd);
|
|
1613
|
-
}
|
|
1614
|
-
static async installPackage(client, manifest, dir) {
|
|
1615
|
-
const file = await client.getFile(`/registry/${manifest.name}/-/${manifest._file}`);
|
|
1616
|
-
const path = join(dir, this.getTypeSubFolder(manifest.type));
|
|
1617
|
-
fs.mkdirSync(path, { recursive: true });
|
|
1618
|
-
fs.writeFileSync(join(path, manifest._file), await file.bytes());
|
|
1619
|
-
}
|
|
1620
|
-
static getTypeSubFolder(type) {
|
|
1621
|
-
if (type === "component") return "components";
|
|
1622
|
-
if (type === "system") return "systems";
|
|
1623
|
-
return ".";
|
|
1624
|
-
}
|
|
1625
|
-
static _getClient(dir, force, headers = true) {
|
|
1626
|
-
const config = GlobalConfigHandler.read(dir);
|
|
1627
|
-
return withAuth(config.apiKey, force, !headers ? {} : void 0);
|
|
1628
|
-
}
|
|
1629
|
-
static _getPackageFile(filename, dir) {
|
|
1630
|
-
const path = join(getCwd(dir ?? "."), filename);
|
|
1631
|
-
if (!fs.existsSync(path)) throw new CLIError("Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!");
|
|
1632
|
-
try {
|
|
1633
|
-
fs.accessSync(path, fs.constants.R_OK);
|
|
1634
|
-
return fs.openAsBlob(path);
|
|
1635
|
-
} catch {
|
|
1636
|
-
throw new CLIError("Cannot read package file, please verify your file permissions!");
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1579
|
+
// src/action/actions/install.action.ts
|
|
1580
|
+
/** `@scope/name@^1.2.0` → `["@scope/name", "^1.2.0"]`; no range after the name → undefined. */
|
|
1581
|
+
const parsePackageSpec = (spec) => {
|
|
1582
|
+
const at = spec.lastIndexOf("@");
|
|
1583
|
+
return at > 0 ? [spec.slice(0, at), spec.slice(at + 1) || void 0] : [spec, void 0];
|
|
1639
1584
|
};
|
|
1640
|
-
//#endregion
|
|
1641
|
-
//#region src/action/actions/install.action.ts
|
|
1642
1585
|
var InstallAction = class extends AbstractAction {
|
|
1643
1586
|
startMessage = Messages.INSTALL_START;
|
|
1644
1587
|
successMessage = Messages.INSTALL_SUCCESS;
|
|
1645
1588
|
failureMessage = Messages.INSTALL_FAILED;
|
|
1646
1589
|
async handle(args, options) {
|
|
1647
|
-
const names = await getInstallNamesInputOrAsk(args);
|
|
1648
1590
|
const directory = getDirectoryInput(options);
|
|
1649
|
-
|
|
1650
|
-
const isServer = getServerInput(options);
|
|
1651
|
-
return isLib ? this._installLibs(directory, names) : this._installNfPackages(directory, names, isServer);
|
|
1591
|
+
return getInstallLibInput(options) ? this._installLibs(directory, await getInstallNamesInputOrAsk(args)) : this._installNfPackages(directory, getArrayInput(args, "names") ?? []);
|
|
1652
1592
|
}
|
|
1653
1593
|
async _installLibs(directory, names) {
|
|
1654
1594
|
return { success: await (await PackageManagerFactory.find(directory)).addDevelopment(directory, names) };
|
|
1655
1595
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1596
|
+
/**
|
|
1597
|
+
* Installs registry packages into `nf_modules` (list, lock and tsconfig paths updated). Without
|
|
1598
|
+
* names, installs what the lock lists (a fresh clone).
|
|
1599
|
+
*/
|
|
1600
|
+
_installNfPackages(directory, names) {
|
|
1601
|
+
const packages = new ProjectPackages(getCwd(directory), createRegistry());
|
|
1602
|
+
return withSpinner(async () => {
|
|
1603
|
+
if (!names.length) {
|
|
1604
|
+
await packages.restore();
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
for (const spec of names) await packages.install(...parsePackageSpec(spec));
|
|
1608
|
+
}, Messages.INSTALL_PACKAGES_IN_PROGRESS);
|
|
1661
1609
|
}
|
|
1662
1610
|
};
|
|
1663
|
-
|
|
1664
|
-
//#region src/action/actions/login.action.ts
|
|
1611
|
+
// src/action/actions/login.action.ts
|
|
1665
1612
|
var LoginAction = class extends AbstractAction {
|
|
1666
1613
|
startMessage = Messages.LOGIN_START;
|
|
1667
1614
|
successMessage = Messages.LOGIN_SUCCESS;
|
|
@@ -1670,13 +1617,12 @@ var LoginAction = class extends AbstractAction {
|
|
|
1670
1617
|
const directory = getDirectoryInput(options);
|
|
1671
1618
|
const isLocal = getLocalInput(options);
|
|
1672
1619
|
const apiKey = await getLoginApiKeyInputOrAsk(options);
|
|
1673
|
-
await
|
|
1620
|
+
await createRegistry(apiKey).whoami();
|
|
1674
1621
|
GlobalConfigHandler.write({ apiKey }, isLocal, directory);
|
|
1675
1622
|
return { success: true };
|
|
1676
1623
|
}
|
|
1677
1624
|
};
|
|
1678
|
-
|
|
1679
|
-
//#region src/action/actions/logout.action.ts
|
|
1625
|
+
// src/action/actions/logout.action.ts
|
|
1680
1626
|
var LogoutAction = class extends AbstractAction {
|
|
1681
1627
|
startMessage = Messages.LOGOUT_START;
|
|
1682
1628
|
successMessage = Messages.LOGOUT_SUCCESS;
|
|
@@ -1688,8 +1634,7 @@ var LogoutAction = class extends AbstractAction {
|
|
|
1688
1634
|
return { success: true };
|
|
1689
1635
|
}
|
|
1690
1636
|
};
|
|
1691
|
-
|
|
1692
|
-
//#region src/lib/git/git-runner.ts
|
|
1637
|
+
// src/lib/git/git-runner.ts
|
|
1693
1638
|
const GIT = "git";
|
|
1694
1639
|
const GIT_COMMANDS = {
|
|
1695
1640
|
init: "init",
|
|
@@ -1726,8 +1671,7 @@ var GitRunner = class {
|
|
|
1726
1671
|
return this.runner.fullCommand(args);
|
|
1727
1672
|
}
|
|
1728
1673
|
};
|
|
1729
|
-
|
|
1730
|
-
//#region src/lib/input/inputs/new/git-remote.input.ts
|
|
1674
|
+
// src/lib/input/inputs/new/git-remote.input.ts
|
|
1731
1675
|
const getGitRemoteInput = (inputs) => {
|
|
1732
1676
|
return getStringInput(inputs, "gitRemote");
|
|
1733
1677
|
};
|
|
@@ -1737,16 +1681,14 @@ const getNewGitRemoteInputOrAsk = (inputs) => {
|
|
|
1737
1681
|
default: ""
|
|
1738
1682
|
}));
|
|
1739
1683
|
};
|
|
1740
|
-
|
|
1741
|
-
//#region src/lib/input/inputs/new/git.input.ts
|
|
1684
|
+
// src/lib/input/inputs/new/git.input.ts
|
|
1742
1685
|
const getNewGitInput = (inputs) => {
|
|
1743
1686
|
return getBooleanInput(inputs, "git");
|
|
1744
1687
|
};
|
|
1745
1688
|
const getNewGitOrAsk = (inputs) => {
|
|
1746
1689
|
return getInputOrAsk(getNewGitInput(inputs), () => askConfirm(Messages.NEW_GIT_QUESTION, { default: true }));
|
|
1747
1690
|
};
|
|
1748
|
-
|
|
1749
|
-
//#region src/action/actions/new.action.ts
|
|
1691
|
+
// src/action/actions/new.action.ts
|
|
1750
1692
|
var NewAction = class extends AbstractAction {
|
|
1751
1693
|
startMessage = Messages.NEW_START;
|
|
1752
1694
|
successMessage = Messages.NEW_SUCCESS;
|
|
@@ -1771,6 +1713,7 @@ var NewAction = class extends AbstractAction {
|
|
|
1771
1713
|
skipInstall: await getNewSkipInstallOrAsk(inputs),
|
|
1772
1714
|
docker: await getNewDockerOrAsk(inputs),
|
|
1773
1715
|
lint: getNewLintInput(inputs),
|
|
1716
|
+
agents: getNewAgentsInput(inputs),
|
|
1774
1717
|
editor: getEditorInput(inputs),
|
|
1775
1718
|
git: await getNewGitOrAsk(inputs)
|
|
1776
1719
|
};
|
|
@@ -1798,7 +1741,8 @@ var NewAction = class extends AbstractAction {
|
|
|
1798
1741
|
language: values.language,
|
|
1799
1742
|
strict: values.strict,
|
|
1800
1743
|
packageManager: values.packageManager,
|
|
1801
|
-
docker: values.docker
|
|
1744
|
+
docker: values.docker,
|
|
1745
|
+
agents: values.agents
|
|
1802
1746
|
});
|
|
1803
1747
|
}
|
|
1804
1748
|
generateClientProject(collection, values) {
|
|
@@ -1821,7 +1765,8 @@ var NewAction = class extends AbstractAction {
|
|
|
1821
1765
|
packageManager: values.packageManager,
|
|
1822
1766
|
workspace: values.multiplayer,
|
|
1823
1767
|
docker: values.docker,
|
|
1824
|
-
editor: values.editor
|
|
1768
|
+
editor: values.editor,
|
|
1769
|
+
agents: values.agents
|
|
1825
1770
|
};
|
|
1826
1771
|
}
|
|
1827
1772
|
async installDependencies(packageManagerName, directory) {
|
|
@@ -1835,133 +1780,53 @@ var NewAction = class extends AbstractAction {
|
|
|
1835
1780
|
return res;
|
|
1836
1781
|
}
|
|
1837
1782
|
};
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
if (
|
|
1843
|
-
|
|
1844
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1845
|
-
}
|
|
1846
|
-
//#endregion
|
|
1847
|
-
//#region src/lib/manifest/manifest.type.ts
|
|
1848
|
-
let ManifestPackageTypeEnum = /* @__PURE__ */ function(ManifestPackageTypeEnum) {
|
|
1849
|
-
ManifestPackageTypeEnum["COMPONENT"] = "component";
|
|
1850
|
-
ManifestPackageTypeEnum["SYSTEM"] = "system";
|
|
1851
|
-
return ManifestPackageTypeEnum;
|
|
1852
|
-
}({});
|
|
1853
|
-
var PathsPublishManifest = class {
|
|
1854
|
-
package;
|
|
1855
|
-
};
|
|
1856
|
-
__decorate([
|
|
1857
|
-
Expose(),
|
|
1858
|
-
IsString(),
|
|
1859
|
-
IsNotEmpty(),
|
|
1860
|
-
IsOptional()
|
|
1861
|
-
], PathsPublishManifest.prototype, "package", void 0);
|
|
1862
|
-
var PublishManifest = class {
|
|
1863
|
-
paths;
|
|
1864
|
-
};
|
|
1865
|
-
__decorate([
|
|
1866
|
-
Expose(),
|
|
1867
|
-
IsOptional(),
|
|
1868
|
-
ValidateNested(),
|
|
1869
|
-
Type(() => PathsPublishManifest)
|
|
1870
|
-
], PublishManifest.prototype, "paths", void 0);
|
|
1871
|
-
var Manifest = class {
|
|
1872
|
-
name;
|
|
1873
|
-
type;
|
|
1874
|
-
description;
|
|
1875
|
-
tags;
|
|
1876
|
-
dependencies;
|
|
1877
|
-
publish;
|
|
1878
|
-
libDependencies;
|
|
1879
|
-
npmDependencies;
|
|
1880
|
-
};
|
|
1881
|
-
__decorate([
|
|
1882
|
-
Expose(),
|
|
1883
|
-
IsString(),
|
|
1884
|
-
Matches(/^[A-Za-z0-9-]+\/[A-Za-z0-9-]+$/),
|
|
1885
|
-
IsNotEmpty()
|
|
1886
|
-
], Manifest.prototype, "name", void 0);
|
|
1887
|
-
__decorate([
|
|
1888
|
-
Expose(),
|
|
1889
|
-
IsString(),
|
|
1890
|
-
IsEnum(ManifestPackageTypeEnum),
|
|
1891
|
-
IsNotEmpty()
|
|
1892
|
-
], Manifest.prototype, "type", void 0);
|
|
1893
|
-
__decorate([
|
|
1894
|
-
Expose(),
|
|
1895
|
-
IsString(),
|
|
1896
|
-
IsOptional()
|
|
1897
|
-
], Manifest.prototype, "description", void 0);
|
|
1898
|
-
__decorate([
|
|
1899
|
-
Expose(),
|
|
1900
|
-
IsString({ each: true }),
|
|
1901
|
-
IsOptional()
|
|
1902
|
-
], Manifest.prototype, "tags", void 0);
|
|
1903
|
-
__decorate([
|
|
1904
|
-
Expose(),
|
|
1905
|
-
IsString({ each: true }),
|
|
1906
|
-
IsNotEmpty({ each: true }),
|
|
1907
|
-
IsOptional()
|
|
1908
|
-
], Manifest.prototype, "dependencies", void 0);
|
|
1909
|
-
__decorate([
|
|
1910
|
-
Expose(),
|
|
1911
|
-
IsOptional(),
|
|
1912
|
-
ValidateNested(),
|
|
1913
|
-
Type(() => PublishManifest)
|
|
1914
|
-
], Manifest.prototype, "publish", void 0);
|
|
1915
|
-
__decorate([
|
|
1916
|
-
Expose(),
|
|
1917
|
-
IsObject(),
|
|
1918
|
-
IsOptional()
|
|
1919
|
-
], Manifest.prototype, "libDependencies", void 0);
|
|
1920
|
-
__decorate([
|
|
1921
|
-
Expose(),
|
|
1922
|
-
IsObject(),
|
|
1923
|
-
IsOptional()
|
|
1924
|
-
], Manifest.prototype, "npmDependencies", void 0);
|
|
1925
|
-
//#endregion
|
|
1926
|
-
//#region src/lib/manifest/manifest-loader.ts
|
|
1927
|
-
const getManifestPath = (directory) => {
|
|
1928
|
-
for (const n of [MANIFEST_FILE_NAME]) {
|
|
1929
|
-
const path = join$1(directory, n);
|
|
1930
|
-
if (existsSync$1(path)) return path;
|
|
1931
|
-
}
|
|
1932
|
-
throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1933
|
-
};
|
|
1934
|
-
const loadManifest = async (directory) => {
|
|
1935
|
-
let rawData;
|
|
1936
|
-
const path = getManifestPath(directory);
|
|
1783
|
+
// src/lib/manifest/manifest-loader.ts
|
|
1784
|
+
/** The `nanoforge.manifest.json` of a package folder, checked against the registry's schema. */
|
|
1785
|
+
const loadManifest = (directory) => {
|
|
1786
|
+
const path = join$1(directory, MANIFEST_FILE);
|
|
1787
|
+
if (!existsSync$1(path)) throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1788
|
+
let json;
|
|
1937
1789
|
try {
|
|
1938
|
-
|
|
1790
|
+
json = JSON.parse(readFileSync(path, "utf-8"));
|
|
1939
1791
|
} catch {
|
|
1940
|
-
|
|
1792
|
+
throw new ManifestError(`Unable to read or parse file at ${path}`);
|
|
1941
1793
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1794
|
+
const parsed = ItemManifest.safeParse(json);
|
|
1795
|
+
if (!parsed.success) {
|
|
1796
|
+
const issue = parsed.error.issues[0];
|
|
1797
|
+
throw new ManifestError(`Validation failed: ${issue?.path.join(".") || "manifest"}: ${issue?.message ?? "invalid"}`);
|
|
1798
|
+
}
|
|
1799
|
+
return parsed.data;
|
|
1947
1800
|
};
|
|
1948
|
-
|
|
1949
|
-
|
|
1801
|
+
// src/action/actions/publish.action.ts
|
|
1802
|
+
const formatSize = (bytes) => bytes < 1024 ? `${bytes} B` : bytes < 1048576 ? `${(bytes / 1024).toFixed(1)} KiB` : `${(bytes / 1024 / 1024).toFixed(1)} MiB`;
|
|
1950
1803
|
var PublishAction = class extends AbstractAction {
|
|
1951
1804
|
startMessage = Messages.PUBLISH_START;
|
|
1952
1805
|
successMessage = Messages.PUBLISH_SUCCESS;
|
|
1953
1806
|
failureMessage = Messages.PUBLISH_FAILED;
|
|
1807
|
+
/**
|
|
1808
|
+
* Zips what the manifest names (secrets left out), lists what it packed, and publishes it;
|
|
1809
|
+
* `--dry-run` stops after the list.
|
|
1810
|
+
*/
|
|
1954
1811
|
async handle(_args, options) {
|
|
1955
1812
|
const directory = getDirectoryInput(options);
|
|
1956
|
-
const manifest =
|
|
1957
|
-
const
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1960
|
-
|
|
1813
|
+
const manifest = loadManifest(directory);
|
|
1814
|
+
const subject = `${manifest.name}@${manifest.version}`;
|
|
1815
|
+
const root = getCwd(directory);
|
|
1816
|
+
const archive = await zipFolder(root, { ignore: await publishIgnore(root, manifest) });
|
|
1817
|
+
const files = [...readArchive(archive)];
|
|
1818
|
+
for (const [path, content] of files) console.info(` ${path} (${formatSize(content.length)})`);
|
|
1819
|
+
const unpacked = files.reduce((total, [, content]) => total + content.length, 0);
|
|
1820
|
+
console.info(Messages.PUBLISH_FILES(subject, files.length, formatSize(unpacked)));
|
|
1821
|
+
if (getDryRunInput(options)) {
|
|
1822
|
+
this.successMessage = Messages.PUBLISH_DRY_RUN_SUCCESS;
|
|
1823
|
+
return { success: true };
|
|
1824
|
+
}
|
|
1825
|
+
const registry = createAuthenticatedRegistry(directory);
|
|
1826
|
+
return withSpinner(() => registry.publish(manifest.name, archive), Messages.PUBLISH_IN_PROGRESS(subject));
|
|
1961
1827
|
}
|
|
1962
1828
|
};
|
|
1963
|
-
|
|
1964
|
-
//#region src/action/actions/start.action.ts
|
|
1829
|
+
// src/action/actions/start.action.ts
|
|
1965
1830
|
const isClientTarget = (target) => target.platform === "client";
|
|
1966
1831
|
const isServerTarget = (target) => target.platform === "server";
|
|
1967
1832
|
var StartAction = class extends AbstractAction {
|
|
@@ -1977,6 +1842,7 @@ var StartAction = class extends AbstractAction {
|
|
|
1977
1842
|
const clientTargets = targets.filter(isClientTarget);
|
|
1978
1843
|
if (targets.length === 0) throw new CLIError(`No client or server project found at '${directory}'.`, "Check your nanoforge.config's 'packages' patterns, or run 'nf new' to scaffold one.");
|
|
1979
1844
|
const env = this.parseEnv(directory);
|
|
1845
|
+
if (isPeerToPeer(workspaceConfig)) env.client.NANOFORGE_NETWORK_MODE = env.server.NANOFORGE_NETWORK_MODE = "p2p";
|
|
1980
1846
|
const packageManager = await PackageManagerFactory.find(directory);
|
|
1981
1847
|
const tasks = this.buildStartTasks(packageManager, serverTargets, clientTargets, watch, env);
|
|
1982
1848
|
await Promise.all(tasks);
|
|
@@ -2078,20 +1944,20 @@ var StartAction = class extends AbstractAction {
|
|
|
2078
1944
|
});
|
|
2079
1945
|
}
|
|
2080
1946
|
};
|
|
2081
|
-
|
|
2082
|
-
//#region src/action/actions/unpublish.action.ts
|
|
1947
|
+
// src/action/actions/unpublish.action.ts
|
|
2083
1948
|
var UnpublishAction = class extends AbstractAction {
|
|
2084
1949
|
startMessage = Messages.UNPUBLISH_START;
|
|
2085
1950
|
successMessage = Messages.UNPUBLISH_SUCCESS;
|
|
2086
1951
|
failureMessage = Messages.UNPUBLISH_FAILED;
|
|
1952
|
+
/** Unpublishes the version the manifest names: that number can never be published again. */
|
|
2087
1953
|
async handle(_args, options) {
|
|
2088
1954
|
const directory = getDirectoryInput(options);
|
|
2089
|
-
const manifest =
|
|
2090
|
-
|
|
1955
|
+
const manifest = loadManifest(directory);
|
|
1956
|
+
const registry = createAuthenticatedRegistry(directory);
|
|
1957
|
+
return withSpinner(() => registry.unpublish(manifest.name, manifest.version), Messages.UNPUBLISH_IN_PROGRESS(`${manifest.name}@${manifest.version}`));
|
|
2091
1958
|
}
|
|
2092
1959
|
};
|
|
2093
|
-
|
|
2094
|
-
//#region src/command/abstract.command.ts
|
|
1960
|
+
// src/command/abstract.command.ts
|
|
2095
1961
|
var AbstractCommand = class {
|
|
2096
1962
|
action;
|
|
2097
1963
|
constructor(action) {
|
|
@@ -2103,8 +1969,7 @@ var AbstractCommand = class {
|
|
|
2103
1969
|
return input;
|
|
2104
1970
|
}
|
|
2105
1971
|
};
|
|
2106
|
-
|
|
2107
|
-
//#region src/command/commands/build.command.ts
|
|
1972
|
+
// src/command/commands/build.command.ts
|
|
2108
1973
|
var BuildCommand = class extends AbstractCommand {
|
|
2109
1974
|
load(program) {
|
|
2110
1975
|
program.command("build").description("build your game").option("-d, --directory <directory>", "specify the working directory of the command").option("--client-entry <clientEntry>", "specify the entry file of the client").option("--server-entry <serverEntry>", "specify the entry file of the server").option("--client-static-dir <clientStaticDir>", "specify the static directory of the client").option("--server-static-dir <serverStaticDir>", "specify the static directory of the server").option("--client-out-dir <clientOutDir>", "specify the output directory of the client").option("--server-out-dir <serverOutDir>", "specify the output directory of the server").option("--editor", "specify if the project must build with editor config").option("--watch", "build app in watching mode", false).action(async (rawOptions) => {
|
|
@@ -2123,23 +1988,22 @@ var BuildCommand = class extends AbstractCommand {
|
|
|
2123
1988
|
});
|
|
2124
1989
|
}
|
|
2125
1990
|
};
|
|
2126
|
-
|
|
2127
|
-
//#region src/command/commands/create.command.ts
|
|
1991
|
+
// src/command/commands/create.command.ts
|
|
2128
1992
|
var CreateCommand = class extends AbstractCommand {
|
|
2129
1993
|
load(program) {
|
|
2130
|
-
program.command("create <type>").description("create
|
|
1994
|
+
program.command("create <type>").description("create a component or a system in an app, or an editor plugin (create plugin)").option("-d, --directory <directory>", "specify the working directory of the command").option("-n, --name <name>", "name of the component/system, or @scope/name of the plugin").option("-p, --path <path>", "path to the component/system folder (default: <part>/<components|systems>), or the folder of the new plugin (default: its name)").option("-t, --template <template>", "what a plugin starts from: panel (a panel, a command and a setting) or theme (a color theme, no code)").action(async (type, rawOptions) => {
|
|
2131
1995
|
const args = AbstractCommand.mapToInput({ type });
|
|
2132
1996
|
const options = AbstractCommand.mapToInput({
|
|
2133
1997
|
directory: rawOptions.directory,
|
|
2134
1998
|
name: rawOptions.name,
|
|
2135
|
-
path: rawOptions.path
|
|
1999
|
+
path: rawOptions.path,
|
|
2000
|
+
template: rawOptions.template
|
|
2136
2001
|
});
|
|
2137
2002
|
await this.action.run(args, options);
|
|
2138
2003
|
});
|
|
2139
2004
|
}
|
|
2140
2005
|
};
|
|
2141
|
-
|
|
2142
|
-
//#region src/command/commands/dev.command.ts
|
|
2006
|
+
// src/command/commands/dev.command.ts
|
|
2143
2007
|
var DevCommand = class extends AbstractCommand {
|
|
2144
2008
|
load(program) {
|
|
2145
2009
|
program.command("dev").description("run your game in dev mode").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("-e, --editor", "run the editor", false).action(async (rawOptions) => {
|
|
@@ -2152,37 +2016,34 @@ var DevCommand = class extends AbstractCommand {
|
|
|
2152
2016
|
});
|
|
2153
2017
|
}
|
|
2154
2018
|
};
|
|
2155
|
-
|
|
2156
|
-
//#region src/command/commands/editor.command.ts
|
|
2019
|
+
// src/command/commands/editor.command.ts
|
|
2157
2020
|
var EditorCommand = class extends AbstractCommand {
|
|
2158
2021
|
load(program) {
|
|
2159
|
-
program.command("editor [path]").description("start the editor").option("-d, --directory <directory>", "specify the working directory of the command").option("--open", "open the editor on the default web browser (default: true if path is specified, false otherwise)").option("--no-open", "do not open the editor on the default web browser").action(async (path, rawOptions) => {
|
|
2022
|
+
program.command("editor [path]").description("start the editor").option("-d, --directory <directory>", "specify the working directory of the command").option("--open", "open the editor on the default web browser (default: true if path is specified, false otherwise)").option("--no-open", "do not open the editor on the default web browser").option("-p, --port <port>", "port of the editor (default: 5173)").action(async (path, rawOptions) => {
|
|
2160
2023
|
const args = AbstractCommand.mapToInput({ path });
|
|
2161
2024
|
const options = AbstractCommand.mapToInput({
|
|
2162
2025
|
directory: rawOptions.directory,
|
|
2163
|
-
open: rawOptions.open
|
|
2026
|
+
open: rawOptions.open,
|
|
2027
|
+
port: rawOptions.port
|
|
2164
2028
|
});
|
|
2165
2029
|
await this.action.run(args, options);
|
|
2166
2030
|
});
|
|
2167
2031
|
}
|
|
2168
2032
|
};
|
|
2169
|
-
|
|
2170
|
-
//#region src/command/commands/install.command.ts
|
|
2033
|
+
// src/command/commands/install.command.ts
|
|
2171
2034
|
var InstallCommand = class extends AbstractCommand {
|
|
2172
2035
|
load(program) {
|
|
2173
|
-
program.command("install [names...]").alias("add").description("add
|
|
2036
|
+
program.command("install [names...]").alias("add").description("add NanoForge registry packages to your project").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --lib", "install npm libraries with the package manager instead", false).action(async (names, rawOptions) => {
|
|
2174
2037
|
const options = AbstractCommand.mapToInput({
|
|
2175
2038
|
directory: rawOptions.directory,
|
|
2176
|
-
lib: rawOptions.lib
|
|
2177
|
-
server: rawOptions.server
|
|
2039
|
+
lib: rawOptions.lib
|
|
2178
2040
|
});
|
|
2179
2041
|
const args = AbstractCommand.mapToInput({ names: names.length ? names : void 0 });
|
|
2180
2042
|
await this.action.run(args, options);
|
|
2181
2043
|
});
|
|
2182
2044
|
}
|
|
2183
2045
|
};
|
|
2184
|
-
|
|
2185
|
-
//#region src/command/commands/login.command.ts
|
|
2046
|
+
// src/command/commands/login.command.ts
|
|
2186
2047
|
var LoginCommand = class extends AbstractCommand {
|
|
2187
2048
|
load(program) {
|
|
2188
2049
|
program.command("login").description("login to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --local", "login only for the project", false).option("-k, --api-key <key>", "api key for Nanoforge registry (find it at https://registry.nanoforge.eu/dashboard/registry)").action(async (rawOptions) => {
|
|
@@ -2195,8 +2056,7 @@ var LoginCommand = class extends AbstractCommand {
|
|
|
2195
2056
|
});
|
|
2196
2057
|
}
|
|
2197
2058
|
};
|
|
2198
|
-
|
|
2199
|
-
//#region src/command/commands/logout.command.ts
|
|
2059
|
+
// src/command/commands/logout.command.ts
|
|
2200
2060
|
var LogoutCommand = class extends AbstractCommand {
|
|
2201
2061
|
load(program) {
|
|
2202
2062
|
program.command("logout").description("logout from Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").option("-l, --local", "logout only for the project").action(async (rawOptions) => {
|
|
@@ -2208,11 +2068,10 @@ var LogoutCommand = class extends AbstractCommand {
|
|
|
2208
2068
|
});
|
|
2209
2069
|
}
|
|
2210
2070
|
};
|
|
2211
|
-
|
|
2212
|
-
//#region src/command/commands/new.command.ts
|
|
2071
|
+
// src/command/commands/new.command.ts
|
|
2213
2072
|
var NewCommand = class extends AbstractCommand {
|
|
2214
2073
|
load(program) {
|
|
2215
|
-
program.command("new").description("create a new nanoforge project").option("-d, --directory <directory>", "specify the working directory of the command").option("--name <name>", "specify the name of your project").option("--path <path>", "specify the relative path where your project will be created (default: name of the project)").option("--package-manager <packageManager>", "specify the package manager of your project").option("--language <language>", "specify the language of your project").option("--strict", "use strict mode").option("--no-strict", "do not use strict mode").option("--server", "create a server").option("--no-server", "do not create a server").option("--init-functions", "initialize functions").option("--no-init-functions", "do not initialize functions").option("--skip-install", "skip installing dependencies").option("--no-skip-install", "do not skip installing dependencies").option("--docker", "generate docker files").option("--no-docker", "do not generate docker files").option("--no-lint", "do not generate lint files").option("--editor", "do add editor dependencies").option("--git", "generate git repository").option("--no-git", "do not generate git repository").option("--git-remote <gitRemote>", "setup git remote to git repository (required if --git is used)").option("--no-git-remote", "do not setup git remote to git repository").action(async (rawOptions) => {
|
|
2074
|
+
program.command("new").description("create a new nanoforge project").option("-d, --directory <directory>", "specify the working directory of the command").option("--name <name>", "specify the name of your project").option("--path <path>", "specify the relative path where your project will be created (default: name of the project)").option("--package-manager <packageManager>", "specify the package manager of your project").option("--language <language>", "specify the language of your project").option("--strict", "use strict mode").option("--no-strict", "do not use strict mode").option("--server", "create a server").option("--no-server", "do not create a server").option("--init-functions", "initialize functions").option("--no-init-functions", "do not initialize functions").option("--skip-install", "skip installing dependencies").option("--no-skip-install", "do not skip installing dependencies").option("--docker", "generate docker files").option("--no-docker", "do not generate docker files").option("--no-lint", "do not generate lint files").option("--no-agents", "do not generate AGENTS.md and CLAUDE.md files for AI coding agents").option("--editor", "do add editor dependencies").option("--git", "generate git repository").option("--no-git", "do not generate git repository").option("--git-remote <gitRemote>", "setup git remote to git repository (required if --git is used)").option("--no-git-remote", "do not setup git remote to git repository").action(async (rawOptions) => {
|
|
2216
2075
|
const options = AbstractCommand.mapToInput({
|
|
2217
2076
|
directory: rawOptions.directory,
|
|
2218
2077
|
name: rawOptions.name,
|
|
@@ -2225,6 +2084,7 @@ var NewCommand = class extends AbstractCommand {
|
|
|
2225
2084
|
skipInstall: rawOptions.skipInstall,
|
|
2226
2085
|
docker: rawOptions.docker,
|
|
2227
2086
|
lint: rawOptions.lint,
|
|
2087
|
+
agents: rawOptions.agents,
|
|
2228
2088
|
editor: rawOptions.editor,
|
|
2229
2089
|
git: rawOptions.git
|
|
2230
2090
|
});
|
|
@@ -2234,18 +2094,19 @@ var NewCommand = class extends AbstractCommand {
|
|
|
2234
2094
|
});
|
|
2235
2095
|
}
|
|
2236
2096
|
};
|
|
2237
|
-
|
|
2238
|
-
//#region src/command/commands/publish.command.ts
|
|
2097
|
+
// src/command/commands/publish.command.ts
|
|
2239
2098
|
var PublishCommand = class extends AbstractCommand {
|
|
2240
2099
|
load(program) {
|
|
2241
|
-
program.command("publish").description("publish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
|
|
2242
|
-
const options = AbstractCommand.mapToInput({
|
|
2100
|
+
program.command("publish").description("publish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").option("--dry-run", "list the files to publish, and publish nothing", false).action(async (rawOptions) => {
|
|
2101
|
+
const options = AbstractCommand.mapToInput({
|
|
2102
|
+
directory: rawOptions.directory,
|
|
2103
|
+
dryRun: rawOptions.dryRun
|
|
2104
|
+
});
|
|
2243
2105
|
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
2244
2106
|
});
|
|
2245
2107
|
}
|
|
2246
2108
|
};
|
|
2247
|
-
|
|
2248
|
-
//#region src/command/commands/start.command.ts
|
|
2109
|
+
// src/command/commands/start.command.ts
|
|
2249
2110
|
var StartCommand = class extends AbstractCommand {
|
|
2250
2111
|
load(program) {
|
|
2251
2112
|
program.command("start").description("start your game").option("-d, --directory <directory>", "specify the working directory of the command").option("-p, --port <port>", "specify the port of the loader (the website to load the game)").option("--client-dir <clientDirectory>", "specify the output directory of the client").option("--server-dir <serverDirectory>", "specify the output directory of the server").option("--watch", "run app in watching mode", false).option("--cert <cert>", "path to the TLS certificate for HTTPS").option("--key <key>", "path to the TLS key for HTTPS").action(async (rawOptions) => {
|
|
@@ -2262,8 +2123,7 @@ var StartCommand = class extends AbstractCommand {
|
|
|
2262
2123
|
});
|
|
2263
2124
|
}
|
|
2264
2125
|
};
|
|
2265
|
-
|
|
2266
|
-
//#region src/command/commands/unpublish.command.ts
|
|
2126
|
+
// src/command/commands/unpublish.command.ts
|
|
2267
2127
|
var UnpublishCommand = class extends AbstractCommand {
|
|
2268
2128
|
load(program) {
|
|
2269
2129
|
program.command("unpublish").description("unpublish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
|
|
@@ -2272,8 +2132,7 @@ var UnpublishCommand = class extends AbstractCommand {
|
|
|
2272
2132
|
});
|
|
2273
2133
|
}
|
|
2274
2134
|
};
|
|
2275
|
-
|
|
2276
|
-
//#region src/command/command.loader.ts
|
|
2135
|
+
// src/command/command.loader.ts
|
|
2277
2136
|
var CommandLoader = class {
|
|
2278
2137
|
static async load(program) {
|
|
2279
2138
|
new NewCommand(new NewAction()).load(program);
|
|
@@ -2297,11 +2156,9 @@ var CommandLoader = class {
|
|
|
2297
2156
|
});
|
|
2298
2157
|
}
|
|
2299
2158
|
};
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region src/bin/nf.ts
|
|
2159
|
+
// package.json
|
|
2160
|
+
var version = "3.0.2";
|
|
2161
|
+
// src/bin/nf.ts
|
|
2305
2162
|
const bootstrap = async () => {
|
|
2306
2163
|
[
|
|
2307
2164
|
"SIGINT",
|
|
@@ -2323,5 +2180,4 @@ const bootstrap = async () => {
|
|
|
2323
2180
|
if (!process.argv.slice(2).length) program.outputHelp();
|
|
2324
2181
|
};
|
|
2325
2182
|
bootstrap();
|
|
2326
|
-
//#endregion
|
|
2327
2183
|
export {};
|