@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/command.loader.js
CHANGED
|
@@ -3,20 +3,20 @@ import { get } from "node-emoji";
|
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { defaultClientConfig, defaultServerConfig, parseConfig } from "@nanoforge-dev/config";
|
|
5
5
|
import { watch } from "chokidar";
|
|
6
|
-
import { dirname, join, relative } from "node:path";
|
|
7
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
8
|
-
import {
|
|
6
|
+
import { basename, dirname, isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
7
|
+
import { chmodSync, closeSync, existsSync, openSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
8
|
+
import { ItemManifest, MANIFEST_FILE, ProjectPackages, RegistryClient, RegistryError, isInsidePath, readArchive, readPackageContents, zipFolder } from "@nanoforge-dev/registry";
|
|
9
|
+
import { glob, readFile } from "node:fs/promises";
|
|
9
10
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
10
11
|
import fs from "fs";
|
|
11
|
-
import { join as join$1, resolve } from "path";
|
|
12
|
+
import { dirname as dirname$1, join as join$1, resolve as resolve$1, sep } from "path";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
12
14
|
import { spawn } from "child_process";
|
|
13
15
|
import * as process$1 from "node:process";
|
|
14
16
|
import open from "open";
|
|
15
17
|
import { read, readUserConfig, write, writeUserConfig } from "rc9";
|
|
16
|
-
import { Expose, Type, plainToInstance } from "class-transformer";
|
|
17
|
-
import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, Matches, ValidateNested, validate } from "class-validator";
|
|
18
18
|
import dotenv from "dotenv";
|
|
19
|
-
|
|
19
|
+
// src/lib/ui/emojis.ts
|
|
20
20
|
const Emojis = {
|
|
21
21
|
HEART: get("heart"),
|
|
22
22
|
COFFEE: get("coffee"),
|
|
@@ -36,8 +36,7 @@ const Emojis = {
|
|
|
36
36
|
PRAY: get("pray"),
|
|
37
37
|
WINE: get("wine_glass")
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
//#region src/lib/ui/messages.ts
|
|
39
|
+
// src/lib/ui/messages.ts
|
|
41
40
|
const success = (text) => `${Emojis.ROCKET} ${text}`;
|
|
42
41
|
const failure = (text) => `${Emojis.SCREAM} ${text}`;
|
|
43
42
|
const Messages = {
|
|
@@ -78,6 +77,9 @@ const Messages = {
|
|
|
78
77
|
CREATE_SUCCESS: success("Element successfully created!"),
|
|
79
78
|
CREATE_FAILED: failure("Creation failed!"),
|
|
80
79
|
CREATE_NAME_QUESTION: "What is the name of your component/system?",
|
|
80
|
+
CREATE_PLUGIN_NAME_QUESTION: "What is the name of your plugin (@scope/name)?",
|
|
81
|
+
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`,
|
|
82
|
+
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`,
|
|
81
83
|
DEV_START: "NanoForge Dev Mode",
|
|
82
84
|
DEV_SUCCESS: "Dev mode ended",
|
|
83
85
|
DEV_FAILED: failure("Dev mode failed!"),
|
|
@@ -94,6 +96,8 @@ const Messages = {
|
|
|
94
96
|
PUBLISH_SUCCESS: success("Publish completed!"),
|
|
95
97
|
PUBLISH_FAILED: failure("Publish failed!"),
|
|
96
98
|
PUBLISH_IN_PROGRESS: (name) => `Publishing ${name}...`,
|
|
99
|
+
PUBLISH_FILES: (name, count, size) => `${name}: ${count} file${count === 1 ? "" : "s"}, ${size} unpacked`,
|
|
100
|
+
PUBLISH_DRY_RUN_SUCCESS: success("Dry run completed: nothing was published."),
|
|
97
101
|
UNPUBLISH_START: "NanoForge Unpublish",
|
|
98
102
|
UNPUBLISH_SUCCESS: success("Unpublish completed!"),
|
|
99
103
|
UNPUBLISH_FAILED: failure("Unpublish failed!"),
|
|
@@ -114,17 +118,14 @@ const Messages = {
|
|
|
114
118
|
GIT_REMOTE_FAILED: (command) => failure(`Git remote addition failed!\nTry running manually: ${bold(command)}`),
|
|
115
119
|
RUNNER_EXECUTION_ERROR: (command) => `\nFailed to execute command: ${bold(command)}`
|
|
116
120
|
};
|
|
117
|
-
|
|
118
|
-
//#region src/lib/ui/prefixes.ts
|
|
121
|
+
// src/lib/ui/prefixes.ts
|
|
119
122
|
const Prefixes = {
|
|
120
123
|
INFO: bgRgb(60, 190, 100).bold.rgb(0, 0, 0)(" Info "),
|
|
121
124
|
ERROR: bgRgb(210, 0, 75).bold.rgb(0, 0, 0)(" Error ")
|
|
122
125
|
};
|
|
123
|
-
|
|
124
|
-
//#region src/lib/ui/spinner.ts
|
|
126
|
+
// src/lib/ui/spinner.ts
|
|
125
127
|
const getSpinner = (message) => ora({ text: message });
|
|
126
|
-
|
|
127
|
-
//#region src/lib/utils/errors.ts
|
|
128
|
+
// src/lib/utils/errors.ts
|
|
128
129
|
var CLIError = class extends Error {
|
|
129
130
|
suggestion;
|
|
130
131
|
constructor(message, suggestion) {
|
|
@@ -159,12 +160,6 @@ var FileSystemError = class extends CLIError {
|
|
|
159
160
|
super(`File System Error [${action}]: ${targetPath}`, "Verify your file permissions and ensure the path exists.");
|
|
160
161
|
}
|
|
161
162
|
};
|
|
162
|
-
var ApiRequestError = class extends CLIError {
|
|
163
|
-
constructor(status, cause) {
|
|
164
|
-
const causeStr = cause && typeof cause === "object" ? JSON.stringify(cause, null, 2) : cause;
|
|
165
|
-
super(`API Request failed (Status ${status})${causeStr ? `\nDetails: ${causeStr}` : ""}`, "Check your network connection, API key, or the registry status.");
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
163
|
const getErrorString = (error) => {
|
|
169
164
|
const stack = error.stack ? error.stack : error.message;
|
|
170
165
|
const cause = error.cause && typeof error.cause === "object" ? JSON.stringify(error.cause, null, 2) : error.cause;
|
|
@@ -174,12 +169,22 @@ const getErrorMessage = (error) => {
|
|
|
174
169
|
if (error instanceof Error) return getErrorString(error);
|
|
175
170
|
if (typeof error === "string") return error;
|
|
176
171
|
};
|
|
172
|
+
const REGISTRY_SUGGESTIONS = {
|
|
173
|
+
NOT_FOUND: "Check the package name and version.",
|
|
174
|
+
UNAVAILABLE: "Check your connection and REGISTRY_URL, then try again.",
|
|
175
|
+
CONFLICT: "Raise the version in nanoforge.manifest.json before publishing again."
|
|
176
|
+
};
|
|
177
|
+
/** C0 controls but tab and newline, DEL and C1 controls, bidi overrides and isolates. */
|
|
178
|
+
const isControl = (code) => code < 32 && code !== 9 && code !== 10 || code >= 127 && code <= 159 || code >= 8234 && code <= 8238 || code >= 8294 && code <= 8297;
|
|
179
|
+
/** Registry text comes from the network: no terminal control characters. */
|
|
180
|
+
const printable = (text) => [...text].filter((char) => !isControl(char.codePointAt(0) ?? 0)).join("");
|
|
177
181
|
const handleActionError = (context, error) => {
|
|
178
182
|
console.error();
|
|
179
183
|
console.error(red(context));
|
|
180
|
-
if (error instanceof CLIError) {
|
|
181
|
-
console.error(error.message);
|
|
182
|
-
|
|
184
|
+
if (error instanceof CLIError || error instanceof RegistryError) {
|
|
185
|
+
console.error(printable(error.message));
|
|
186
|
+
const suggestion = error instanceof CLIError ? error.suggestion : REGISTRY_SUGGESTIONS[error.code];
|
|
187
|
+
if (suggestion) console.info(cyan(`\n💡 Suggestion: ${suggestion}`));
|
|
183
188
|
process.exit(1);
|
|
184
189
|
}
|
|
185
190
|
const msg = getErrorMessage(error);
|
|
@@ -190,8 +195,7 @@ const promptError = (err) => {
|
|
|
190
195
|
if (err.name === "ExitPromptError") process.exit(1);
|
|
191
196
|
throw err;
|
|
192
197
|
};
|
|
193
|
-
|
|
194
|
-
//#region src/lib/config/config-loader.ts
|
|
198
|
+
// src/lib/config/config-loader.ts
|
|
195
199
|
const CONFIG_BASE_NAME = "nanoforge.config";
|
|
196
200
|
const CONFIG_EXTENSIONS = ["ts", "js"];
|
|
197
201
|
const getConfigPath = (directory) => {
|
|
@@ -210,8 +214,7 @@ const loadConfig = async (directory) => {
|
|
|
210
214
|
const path = getConfigPath(directory);
|
|
211
215
|
return parseConfig(path);
|
|
212
216
|
};
|
|
213
|
-
|
|
214
|
-
//#region src/lib/config/workspace-config-parser.ts
|
|
217
|
+
// src/lib/config/workspace-config-parser.ts
|
|
215
218
|
const resolvePackageConfig = async (packageDir) => {
|
|
216
219
|
let config;
|
|
217
220
|
try {
|
|
@@ -259,8 +262,8 @@ const parseWorkspaceConfig = async (directory) => {
|
|
|
259
262
|
config
|
|
260
263
|
};
|
|
261
264
|
};
|
|
262
|
-
|
|
263
|
-
|
|
265
|
+
// src/lib/config/workspace-loader.ts
|
|
266
|
+
const isPeerToPeer = (workspace) => workspace.type === "workspace" && workspace.config.network === "p2p";
|
|
264
267
|
const resolveProjects = (workspace, baseDirectory) => {
|
|
265
268
|
if (workspace.type === "project") return [{
|
|
266
269
|
directory: baseDirectory,
|
|
@@ -271,8 +274,7 @@ const resolveProjects = (workspace, baseDirectory) => {
|
|
|
271
274
|
config: project.config
|
|
272
275
|
}));
|
|
273
276
|
};
|
|
274
|
-
|
|
275
|
-
//#region src/lib/input/base-inputs.ts
|
|
277
|
+
// src/lib/input/base-inputs.ts
|
|
276
278
|
const getStringInput = (input, field) => {
|
|
277
279
|
const value = input.get(field)?.value;
|
|
278
280
|
if (value === void 0) return void 0;
|
|
@@ -297,8 +299,7 @@ const getArrayInput = (input, field) => {
|
|
|
297
299
|
if (typeof value === "object" && Array.isArray(value)) return value;
|
|
298
300
|
throw new InvalidCommandArgumentError(field, "array");
|
|
299
301
|
};
|
|
300
|
-
|
|
301
|
-
//#region src/lib/input/ask-inputs.ts
|
|
302
|
+
// src/lib/input/ask-inputs.ts
|
|
302
303
|
const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
303
304
|
if (baseInput !== void 0) return baseInput;
|
|
304
305
|
const res = await askCb();
|
|
@@ -306,19 +307,16 @@ const getInputOrAsk = async (baseInput, askCb, defaultValue) => {
|
|
|
306
307
|
if (defaultValue !== void 0) return defaultValue;
|
|
307
308
|
throw new CLIError("No input provided. Please provide a valid value.");
|
|
308
309
|
};
|
|
309
|
-
|
|
310
|
-
//#region src/lib/input/inputs/directory.input.ts
|
|
310
|
+
// src/lib/input/inputs/directory.input.ts
|
|
311
311
|
function getDirectoryInput(inputs, withDefault = true) {
|
|
312
312
|
if (withDefault) return getStringInputWithDefault(inputs, "directory", ".");
|
|
313
313
|
return getStringInput(inputs, "directory");
|
|
314
314
|
}
|
|
315
|
-
|
|
316
|
-
//#region src/lib/input/inputs/editor.input.ts
|
|
315
|
+
// src/lib/input/inputs/editor.input.ts
|
|
317
316
|
const getEditorInput = (inputs) => {
|
|
318
317
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
319
318
|
};
|
|
320
|
-
|
|
321
|
-
//#region src/lib/question/questions/confirm.question.ts
|
|
319
|
+
// src/lib/question/questions/confirm.question.ts
|
|
322
320
|
const askConfirm = async (question, baseOptions) => {
|
|
323
321
|
const options = {
|
|
324
322
|
default: false,
|
|
@@ -329,8 +327,7 @@ const askConfirm = async (question, baseOptions) => {
|
|
|
329
327
|
default: options.default
|
|
330
328
|
}).catch(promptError);
|
|
331
329
|
};
|
|
332
|
-
|
|
333
|
-
//#region src/lib/question/questions/input.question.ts
|
|
330
|
+
// src/lib/question/questions/input.question.ts
|
|
334
331
|
const askInput = async (question, baseOptions) => {
|
|
335
332
|
const options = {
|
|
336
333
|
required: false,
|
|
@@ -356,8 +353,7 @@ const askInputArray = async (question, baseOptions) => {
|
|
|
356
353
|
}).catch(promptError)).split(options.split);
|
|
357
354
|
return options.filter ? res.filter((r) => r.length) : res;
|
|
358
355
|
};
|
|
359
|
-
|
|
360
|
-
//#region src/lib/question/questions/select.question.ts
|
|
356
|
+
// src/lib/question/questions/select.question.ts
|
|
361
357
|
const askSelect = async (question, choices, baseOptions) => {
|
|
362
358
|
const options = {
|
|
363
359
|
loop: true,
|
|
@@ -370,8 +366,7 @@ const askSelect = async (question, choices, baseOptions) => {
|
|
|
370
366
|
default: options.default
|
|
371
367
|
}).catch(promptError);
|
|
372
368
|
};
|
|
373
|
-
|
|
374
|
-
//#region src/lib/input/inputs/name.input.ts
|
|
369
|
+
// src/lib/input/inputs/name.input.ts
|
|
375
370
|
const getNameInput = (inputs) => {
|
|
376
371
|
return getStringInput(inputs, "name");
|
|
377
372
|
};
|
|
@@ -381,91 +376,98 @@ const getNewNameInputOrAsk = (inputs) => {
|
|
|
381
376
|
default: "nanoforge-app"
|
|
382
377
|
}));
|
|
383
378
|
};
|
|
379
|
+
const getPluginNameInputOrAsk = (inputs) => {
|
|
380
|
+
return getInputOrAsk(getNameInput(inputs), () => askInput(Messages.CREATE_PLUGIN_NAME_QUESTION, {
|
|
381
|
+
required: true,
|
|
382
|
+
default: "@nanoforge/ecs"
|
|
383
|
+
}));
|
|
384
|
+
};
|
|
384
385
|
const getCreateNameInputOrAsk = (inputs) => {
|
|
385
386
|
return getInputOrAsk(getNameInput(inputs), () => askInput(Messages.CREATE_NAME_QUESTION, {
|
|
386
387
|
required: true,
|
|
387
388
|
default: "example"
|
|
388
389
|
}));
|
|
389
390
|
};
|
|
390
|
-
|
|
391
|
-
//#region src/lib/input/inputs/path.input.ts
|
|
391
|
+
// src/lib/input/inputs/path.input.ts
|
|
392
392
|
const getPathInput = (inputs) => {
|
|
393
393
|
return getStringInput(inputs, "path");
|
|
394
394
|
};
|
|
395
395
|
const getPathInputWithDefault = (inputs, defaultValue) => {
|
|
396
396
|
return getStringInputWithDefault(inputs, "path", defaultValue);
|
|
397
397
|
};
|
|
398
|
-
|
|
399
|
-
//#region src/lib/input/inputs/server.input.ts
|
|
400
|
-
function getServerInput(inputs) {
|
|
401
|
-
return getBooleanInputWithDefault(inputs, "server", false);
|
|
402
|
-
}
|
|
403
|
-
//#endregion
|
|
404
|
-
//#region src/lib/input/inputs/watch.input.ts
|
|
398
|
+
// src/lib/input/inputs/watch.input.ts
|
|
405
399
|
const getWatchInput = (inputs) => {
|
|
406
400
|
return getBooleanInputWithDefault(inputs, "watch", false);
|
|
407
401
|
};
|
|
408
|
-
|
|
409
|
-
//#region src/lib/input/inputs/create/type.input.ts
|
|
402
|
+
// src/lib/input/inputs/create/type.input.ts
|
|
410
403
|
const getCreateTypeInput = (inputs) => {
|
|
411
404
|
const res = getStringInput(inputs, "type");
|
|
412
|
-
if (res && [
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
405
|
+
if (res && [
|
|
406
|
+
"component",
|
|
407
|
+
"system",
|
|
408
|
+
"plugin"
|
|
409
|
+
].includes(res)) return res;
|
|
410
|
+
throw new InvalidCommandArgumentError("type", "'component', 'system' or 'plugin'");
|
|
411
|
+
};
|
|
412
|
+
// src/lib/input/inputs/editor/open.input.ts
|
|
417
413
|
const getEditorOpenInput = (inputs, defaultValue) => {
|
|
418
414
|
return getBooleanInputWithDefault(inputs, "open", defaultValue);
|
|
419
415
|
};
|
|
420
|
-
|
|
421
|
-
|
|
416
|
+
// src/lib/input/inputs/editor/port.input.ts
|
|
417
|
+
/** Default port of `nf editor` (the loaders use 3000). */
|
|
418
|
+
const DEFAULT_EDITOR_PORT = 5173;
|
|
419
|
+
const getEditorPortInput = (inputs) => {
|
|
420
|
+
const raw = getStringInput(inputs, "port");
|
|
421
|
+
if (raw === void 0) return DEFAULT_EDITOR_PORT;
|
|
422
|
+
const port = Number(raw);
|
|
423
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid editor port: ${raw}`);
|
|
424
|
+
return port;
|
|
425
|
+
};
|
|
426
|
+
// src/lib/input/inputs/install/lib.input.ts
|
|
422
427
|
function getInstallLibInput(inputs) {
|
|
423
428
|
return getBooleanInputWithDefault(inputs, "lib", false);
|
|
424
429
|
}
|
|
425
|
-
|
|
426
|
-
//#region src/lib/input/inputs/install/names.input.ts
|
|
430
|
+
// src/lib/input/inputs/install/names.input.ts
|
|
427
431
|
const getNamesInput = (inputs) => {
|
|
428
432
|
return getArrayInput(inputs, "names");
|
|
429
433
|
};
|
|
430
434
|
const getInstallNamesInputOrAsk = (inputs) => {
|
|
431
435
|
return getInputOrAsk(getNamesInput(inputs), () => askInputArray(Messages.INSTALL_NAMES_QUESTION, { required: true }));
|
|
432
436
|
};
|
|
433
|
-
|
|
434
|
-
//#region src/lib/input/inputs/login-out/api-key.input.ts
|
|
437
|
+
// src/lib/input/inputs/login-out/api-key.input.ts
|
|
435
438
|
const getApiKeyInput = (inputs) => {
|
|
436
439
|
return getStringInput(inputs, "apiKey");
|
|
437
440
|
};
|
|
438
441
|
const getLoginApiKeyInputOrAsk = (inputs) => {
|
|
439
442
|
return getInputOrAsk(getApiKeyInput(inputs), () => askInput(Messages.LOGIN_API_KEY_QUESTION, { required: true }));
|
|
440
443
|
};
|
|
441
|
-
|
|
442
|
-
//#region src/lib/input/inputs/login-out/local.input.ts
|
|
444
|
+
// src/lib/input/inputs/login-out/local.input.ts
|
|
443
445
|
function getLocalInput(inputs) {
|
|
444
446
|
return getBooleanInputWithDefault(inputs, "local", false);
|
|
445
447
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
+
// src/lib/input/inputs/new/agents.input.ts
|
|
449
|
+
const getNewAgentsInput = (inputs) => {
|
|
450
|
+
return getBooleanInputWithDefault(inputs, "agents", true);
|
|
451
|
+
};
|
|
452
|
+
// src/lib/input/inputs/new/docker.input.ts
|
|
448
453
|
const getNewDockerInput = (inputs) => {
|
|
449
454
|
return getBooleanInput(inputs, "docker");
|
|
450
455
|
};
|
|
451
456
|
const getNewDockerOrAsk = (inputs) => {
|
|
452
457
|
return getInputOrAsk(getNewDockerInput(inputs), () => askConfirm(Messages.NEW_DOCKER_QUESTION, { default: true }));
|
|
453
458
|
};
|
|
454
|
-
|
|
455
|
-
//#region src/lib/input/inputs/new/language.input.ts
|
|
459
|
+
// src/lib/input/inputs/new/language.input.ts
|
|
456
460
|
const getLanguageInput = (inputs) => {
|
|
457
461
|
return getStringInput(inputs, "language");
|
|
458
462
|
};
|
|
459
463
|
const getNewLanguageInputOrAsk = (inputs) => {
|
|
460
464
|
return getInputOrAsk(getLanguageInput(inputs), () => askSelect(Messages.NEW_LANGUAGE_QUESTION, [{ value: "ts" }, { value: "js" }], { default: "ts" }));
|
|
461
465
|
};
|
|
462
|
-
|
|
463
|
-
//#region src/lib/input/inputs/new/lint.input.ts
|
|
466
|
+
// src/lib/input/inputs/new/lint.input.ts
|
|
464
467
|
const getNewLintInput = (inputs) => {
|
|
465
468
|
return getBooleanInputWithDefault(inputs, "lint", true);
|
|
466
469
|
};
|
|
467
|
-
|
|
468
|
-
//#region src/lib/input/inputs/new/package-manager.input.ts
|
|
470
|
+
// src/lib/input/inputs/new/package-manager.input.ts
|
|
469
471
|
const getPackageManagerInput = (inputs) => {
|
|
470
472
|
return getStringInput(inputs, "packageManager");
|
|
471
473
|
};
|
|
@@ -477,32 +479,32 @@ const getNewPackageManagerInputOrAsk = (inputs) => {
|
|
|
477
479
|
{ value: "bun" }
|
|
478
480
|
], { default: "npm" }));
|
|
479
481
|
};
|
|
480
|
-
|
|
481
|
-
//#region src/lib/input/inputs/new/server.input.ts
|
|
482
|
+
// src/lib/input/inputs/new/server.input.ts
|
|
482
483
|
const getNewServerInput = (inputs) => {
|
|
483
484
|
return getBooleanInput(inputs, "server");
|
|
484
485
|
};
|
|
485
486
|
const getNewServerOrAsk = (inputs) => {
|
|
486
487
|
return getInputOrAsk(getNewServerInput(inputs), () => askConfirm(Messages.NEW_SERVER_QUESTION, { default: false }));
|
|
487
488
|
};
|
|
488
|
-
|
|
489
|
-
//#region src/lib/input/inputs/new/skip-install.input.ts
|
|
489
|
+
// src/lib/input/inputs/new/skip-install.input.ts
|
|
490
490
|
const getNewSkipInstallInput = (inputs) => {
|
|
491
491
|
return getBooleanInput(inputs, "skipInstall");
|
|
492
492
|
};
|
|
493
493
|
const getNewSkipInstallOrAsk = (inputs) => {
|
|
494
494
|
return getInputOrAsk(getNewSkipInstallInput(inputs), () => askConfirm(Messages.NEW_SKIP_INSTALL_QUESTION, { default: false }));
|
|
495
495
|
};
|
|
496
|
-
|
|
497
|
-
//#region src/lib/input/inputs/new/strict.input.ts
|
|
496
|
+
// src/lib/input/inputs/new/strict.input.ts
|
|
498
497
|
const getNewStrictInput = (inputs) => {
|
|
499
498
|
return getBooleanInput(inputs, "strict");
|
|
500
499
|
};
|
|
501
500
|
const getNewStrictOrAsk = (inputs) => {
|
|
502
501
|
return getInputOrAsk(getNewStrictInput(inputs), () => askConfirm(Messages.NEW_STRICT_QUESTION, { default: true }));
|
|
503
502
|
};
|
|
504
|
-
|
|
505
|
-
|
|
503
|
+
// src/lib/input/inputs/publish/dry-run.input.ts
|
|
504
|
+
const getDryRunInput = (inputs) => {
|
|
505
|
+
return getBooleanInputWithDefault(inputs, "dryRun", false);
|
|
506
|
+
};
|
|
507
|
+
// src/lib/runner/process-logger.ts
|
|
506
508
|
const formatLines = (chunk) => {
|
|
507
509
|
return chunk.toString().replace(/\r\n|\n/g, "\n").replace(/^\n+|\n+$/g, "").split("\n");
|
|
508
510
|
};
|
|
@@ -515,14 +517,13 @@ const createStderrLogger = (name) => (chunk) => {
|
|
|
515
517
|
const prefix = red(`(${name}) ERROR -`);
|
|
516
518
|
for (const line of formatLines(chunk)) console.error(`${timestamp()} ${prefix} ${line}`);
|
|
517
519
|
};
|
|
518
|
-
|
|
519
|
-
//#region src/lib/utils/path.ts
|
|
520
|
+
// src/lib/utils/path.ts
|
|
520
521
|
const getCwd = (directory) => {
|
|
521
|
-
return resolve(directory);
|
|
522
|
+
return resolve$1(directory);
|
|
522
523
|
};
|
|
523
524
|
const getModulePath = (name, removeLast = false) => {
|
|
524
|
-
const path = import.meta.resolve(name)
|
|
525
|
-
if (removeLast) return path.
|
|
525
|
+
const path = fileURLToPath(import.meta.resolve(name));
|
|
526
|
+
if (removeLast) return path.endsWith(sep) ? path.slice(0, -1) : dirname$1(path);
|
|
526
527
|
return path;
|
|
527
528
|
};
|
|
528
529
|
const resolveCLINodeBinaryPath = (name) => {
|
|
@@ -538,8 +539,7 @@ const resolveCLINodeBinaryPath = (name) => {
|
|
|
538
539
|
}
|
|
539
540
|
throw new FileSystemError("resolve binary", name);
|
|
540
541
|
};
|
|
541
|
-
|
|
542
|
-
//#region src/lib/utils/spinner.ts
|
|
542
|
+
// src/lib/utils/spinner.ts
|
|
543
543
|
const withSpinner = async (task, loadingMessage, successMessage, failureMessage, onError) => {
|
|
544
544
|
const spinner = getSpinner(loadingMessage);
|
|
545
545
|
spinner.start();
|
|
@@ -559,8 +559,7 @@ const withSpinner = async (task, loadingMessage, successMessage, failureMessage,
|
|
|
559
559
|
};
|
|
560
560
|
}
|
|
561
561
|
};
|
|
562
|
-
|
|
563
|
-
//#region src/lib/package-manager/package-manager.ts
|
|
562
|
+
// src/lib/package-manager/package-manager.ts
|
|
564
563
|
var PackageManager = class {
|
|
565
564
|
name;
|
|
566
565
|
commands;
|
|
@@ -692,8 +691,23 @@ var PackageManager = class {
|
|
|
692
691
|
console.info();
|
|
693
692
|
}
|
|
694
693
|
};
|
|
695
|
-
|
|
696
|
-
|
|
694
|
+
// src/lib/runner/runner.ts
|
|
695
|
+
const IS_WINDOWS = process$1.platform === "win32";
|
|
696
|
+
/**
|
|
697
|
+
* Quotes one argument for cmd.exe: npm, pnpm and yarn are `.cmd` shims there, which Node only starts
|
|
698
|
+
* through a shell. Elsewhere, arguments go to the binary as an array, with no shell. cmd.exe has no
|
|
699
|
+
* escape for `"` and expands `%VAR%` (and `!VAR!` with delayed expansion) inside quotes, so arguments holding them are refused.
|
|
700
|
+
* shortcut: refuses `"`, `%`, `!` and line breaks on Windows, use cross-spawn if real arguments need them.
|
|
701
|
+
*/
|
|
702
|
+
const quoteForCmd = (arg) => {
|
|
703
|
+
if (/["%!\r\n]/.test(arg)) throw new Error(`error: argument not supported on Windows (holds ", %, ! or a line break): ${arg}`);
|
|
704
|
+
return `"${arg.replace(/(\\+)$/, "$1$1")}"`;
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* The cmd.exe command line for a binary and its arguments. A bare name (`npm`) stays unquoted:
|
|
708
|
+
* started as `"npm"`, a `.cmd` shim resolves `%~dp0` to the working directory and can't find itself.
|
|
709
|
+
*/
|
|
710
|
+
const cmdLine = (binary, args) => [/^[\w.-]+$/.test(binary) ? binary : quoteForCmd(binary), ...args.map(quoteForCmd)].join(" ");
|
|
697
711
|
var Runner = class {
|
|
698
712
|
binary;
|
|
699
713
|
baseArgs;
|
|
@@ -704,10 +718,11 @@ var Runner = class {
|
|
|
704
718
|
async run(args, options = {}) {
|
|
705
719
|
const { collect = false, cwd = process$1.cwd(), env, listeners, onFail } = options;
|
|
706
720
|
const spawnOpts = this.buildSpawnOptions(collect, cwd, env);
|
|
707
|
-
const fullArgs = [...this.baseArgs, ...args];
|
|
721
|
+
const fullArgs = [...this.baseArgs, ...args].filter((arg) => arg !== "");
|
|
708
722
|
return new Promise((resolve, reject) => {
|
|
709
|
-
const child = spawn(
|
|
723
|
+
const child = IS_WINDOWS ? spawn(cmdLine(this.binary, fullArgs), spawnOpts) : spawn(this.binary, fullArgs, spawnOpts);
|
|
710
724
|
const output = this.attachOutputHandlers(child, listeners);
|
|
725
|
+
child.on("error", reject);
|
|
711
726
|
child.on("close", (code) => {
|
|
712
727
|
if (code === 0) resolve(this.formatOutput(output, collect));
|
|
713
728
|
else {
|
|
@@ -728,7 +743,7 @@ var Runner = class {
|
|
|
728
743
|
return {
|
|
729
744
|
cwd,
|
|
730
745
|
stdio: collect ? "pipe" : "inherit",
|
|
731
|
-
shell:
|
|
746
|
+
shell: IS_WINDOWS,
|
|
732
747
|
env: {
|
|
733
748
|
...process$1.env,
|
|
734
749
|
...env
|
|
@@ -764,8 +779,7 @@ var Runner = class {
|
|
|
764
779
|
return /* @__PURE__ */ new Error(`Command "${this.binary} ${args.join(" ")}" exited with code ${code}`);
|
|
765
780
|
}
|
|
766
781
|
};
|
|
767
|
-
|
|
768
|
-
//#region src/lib/runner/runner.factory.ts
|
|
782
|
+
// src/lib/runner/runner.factory.ts
|
|
769
783
|
var RunnerFactory = class {
|
|
770
784
|
static create(binary, args) {
|
|
771
785
|
return new Runner(binary, args);
|
|
@@ -774,7 +788,7 @@ var RunnerFactory = class {
|
|
|
774
788
|
return new Runner(resolveCLINodeBinaryPath(binary), args);
|
|
775
789
|
}
|
|
776
790
|
static createSchematic() {
|
|
777
|
-
return new Runner("node", [
|
|
791
|
+
return new Runner("node", [this.resolveSchematicBinary()]);
|
|
778
792
|
}
|
|
779
793
|
static resolveSchematicBinary() {
|
|
780
794
|
try {
|
|
@@ -784,8 +798,7 @@ var RunnerFactory = class {
|
|
|
784
798
|
}
|
|
785
799
|
}
|
|
786
800
|
};
|
|
787
|
-
|
|
788
|
-
//#region src/lib/package-manager/package-manager-configs.ts
|
|
801
|
+
// src/lib/package-manager/package-manager-configs.ts
|
|
789
802
|
const PM_CONFIGS = {
|
|
790
803
|
["bun"]: {
|
|
791
804
|
binary: "bun",
|
|
@@ -861,8 +874,7 @@ const PM_CONFIGS = {
|
|
|
861
874
|
}
|
|
862
875
|
}
|
|
863
876
|
};
|
|
864
|
-
|
|
865
|
-
//#region src/lib/package-manager/package-manager.factory.ts
|
|
877
|
+
// src/lib/package-manager/package-manager.factory.ts
|
|
866
878
|
const LOCK_FILE_MAP = {
|
|
867
879
|
"bun.lock": "bun",
|
|
868
880
|
"package-lock.json": "npm",
|
|
@@ -886,14 +898,13 @@ var PackageManagerFactory = class {
|
|
|
886
898
|
}
|
|
887
899
|
static async detectFromLockFile(directory) {
|
|
888
900
|
try {
|
|
889
|
-
const files = await fs.promises.readdir(resolve(directory));
|
|
901
|
+
const files = await fs.promises.readdir(resolve$1(directory));
|
|
890
902
|
for (const [lockFile, pmName] of Object.entries(LOCK_FILE_MAP)) if (files.includes(lockFile)) return pmName;
|
|
891
903
|
} catch {}
|
|
892
904
|
return "npm";
|
|
893
905
|
}
|
|
894
906
|
};
|
|
895
|
-
|
|
896
|
-
//#region src/lib/utils/files.ts
|
|
907
|
+
// src/lib/utils/files.ts
|
|
897
908
|
const copyFiles = (from, to) => {
|
|
898
909
|
if (!fs.existsSync(from)) return;
|
|
899
910
|
if (!fs.existsSync(to)) throw new FileSystemError("directory not found", to);
|
|
@@ -908,8 +919,7 @@ const resetFolder = (folder) => {
|
|
|
908
919
|
});
|
|
909
920
|
fs.mkdirSync(folder, { recursive: true });
|
|
910
921
|
};
|
|
911
|
-
|
|
912
|
-
//#region src/lib/utils/run-safe.ts
|
|
922
|
+
// src/lib/utils/run-safe.ts
|
|
913
923
|
const runSafe = async (fn, fallback) => {
|
|
914
924
|
try {
|
|
915
925
|
return await fn();
|
|
@@ -919,8 +929,7 @@ const runSafe = async (fn, fallback) => {
|
|
|
919
929
|
return fallback;
|
|
920
930
|
}
|
|
921
931
|
};
|
|
922
|
-
|
|
923
|
-
//#region src/action/abstract.action.ts
|
|
932
|
+
// src/action/abstract.action.ts
|
|
924
933
|
var AbstractAction = class {
|
|
925
934
|
async run(args, options, extraFlags) {
|
|
926
935
|
this.logStart();
|
|
@@ -948,8 +957,7 @@ var AbstractAction = class {
|
|
|
948
957
|
process.exit(0);
|
|
949
958
|
}
|
|
950
959
|
};
|
|
951
|
-
|
|
952
|
-
//#region src/action/actions/build.action.ts
|
|
960
|
+
// src/action/actions/build.action.ts
|
|
953
961
|
var BuildAction = class extends AbstractAction {
|
|
954
962
|
startMessage = Messages.BUILD_START;
|
|
955
963
|
successMessage = Messages.BUILD_SUCCESS;
|
|
@@ -966,7 +974,17 @@ var BuildAction = class extends AbstractAction {
|
|
|
966
974
|
}
|
|
967
975
|
resolveTargets(workspaceConfig, baseDirectory, options, isEditor) {
|
|
968
976
|
const projects = resolveProjects(workspaceConfig, baseDirectory);
|
|
969
|
-
|
|
977
|
+
const targets = projects.map((project) => this.createTarget(project, baseDirectory, options, isEditor, projects.length > 1));
|
|
978
|
+
if (!isPeerToPeer(workspaceConfig)) return targets;
|
|
979
|
+
const client = targets.find((target) => target.platform === "browser");
|
|
980
|
+
if (!client) return targets;
|
|
981
|
+
const browserServers = targets.filter((target) => target.platform === "node").map((server) => ({
|
|
982
|
+
...server,
|
|
983
|
+
name: `${server.name} (browser)`,
|
|
984
|
+
output: relative(server.directory, join(client.directory, client.output, "server")),
|
|
985
|
+
platform: "browser"
|
|
986
|
+
}));
|
|
987
|
+
return [...targets, ...browserServers];
|
|
970
988
|
}
|
|
971
989
|
createTarget(project, baseDirectory, options, isEditor, disambiguate) {
|
|
972
990
|
const isClient = project.config.type === "client";
|
|
@@ -981,7 +999,8 @@ var BuildAction = class extends AbstractAction {
|
|
|
981
999
|
entry: getStringInputWithDefault(options, isClient ? "clientEntry" : "serverEntry", defaultEntry),
|
|
982
1000
|
static: getStringInputWithDefault(options, isClient ? "clientStaticDir" : "serverStaticDir", project.config.dir?.assets ?? defaults.dir.assets),
|
|
983
1001
|
output: getStringInputWithDefault(options, isClient ? "clientOutDir" : "serverOutDir", project.config.out?.dir ?? defaults.out.dir),
|
|
984
|
-
platform: isClient ? "browser" : "node"
|
|
1002
|
+
platform: isClient ? "browser" : "node",
|
|
1003
|
+
sourcemap: isEditor
|
|
985
1004
|
};
|
|
986
1005
|
}
|
|
987
1006
|
async buildAll(targets, isWatch) {
|
|
@@ -1001,7 +1020,8 @@ var BuildAction = class extends AbstractAction {
|
|
|
1001
1020
|
"--asset-naming",
|
|
1002
1021
|
"[name].[ext]",
|
|
1003
1022
|
"--target",
|
|
1004
|
-
target.platform
|
|
1023
|
+
target.platform,
|
|
1024
|
+
...target.sourcemap ? ["--sourcemap=linked"] : []
|
|
1005
1025
|
], rebuild);
|
|
1006
1026
|
}, false);
|
|
1007
1027
|
if (isWatch) this.watchDirectory(target.directory, target.entry, () => executeBuild(true));
|
|
@@ -1027,8 +1047,7 @@ var BuildAction = class extends AbstractAction {
|
|
|
1027
1047
|
copyFiles(from, to);
|
|
1028
1048
|
}
|
|
1029
1049
|
};
|
|
1030
|
-
|
|
1031
|
-
//#region src/lib/schematics/abstract.collection.ts
|
|
1050
|
+
// src/lib/schematics/abstract.collection.ts
|
|
1032
1051
|
var AbstractCollection = class {
|
|
1033
1052
|
collection;
|
|
1034
1053
|
runner;
|
|
@@ -1053,7 +1072,7 @@ var AbstractCollection = class {
|
|
|
1053
1072
|
]) {
|
|
1054
1073
|
return [
|
|
1055
1074
|
...flags,
|
|
1056
|
-
|
|
1075
|
+
`${getModulePath(this.collection + "/collection.json")}:${name}`,
|
|
1057
1076
|
...this.serializeOptions(options)
|
|
1058
1077
|
];
|
|
1059
1078
|
}
|
|
@@ -1061,8 +1080,7 @@ var AbstractCollection = class {
|
|
|
1061
1080
|
return options.flatMap((option) => option.toCommandString());
|
|
1062
1081
|
}
|
|
1063
1082
|
};
|
|
1064
|
-
|
|
1065
|
-
//#region src/lib/schematics/nanoforge.collection.ts
|
|
1083
|
+
// src/lib/schematics/nanoforge.collection.ts
|
|
1066
1084
|
var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
1067
1085
|
static schematics = [
|
|
1068
1086
|
{
|
|
@@ -1084,6 +1102,11 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1084
1102
|
name: "system",
|
|
1085
1103
|
alias: "system",
|
|
1086
1104
|
description: "Generate a System for an application"
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
name: "plugin",
|
|
1108
|
+
alias: "plugin",
|
|
1109
|
+
description: "Generate an editor plugin"
|
|
1087
1110
|
}
|
|
1088
1111
|
];
|
|
1089
1112
|
constructor(runner, cwd) {
|
|
@@ -1102,8 +1125,7 @@ var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
|
1102
1125
|
return schematic.name;
|
|
1103
1126
|
}
|
|
1104
1127
|
};
|
|
1105
|
-
|
|
1106
|
-
//#region src/lib/schematics/collection.factory.ts
|
|
1128
|
+
// src/lib/schematics/collection.factory.ts
|
|
1107
1129
|
var CollectionFactory = class {
|
|
1108
1130
|
static create(collection, directory) {
|
|
1109
1131
|
const schematicRunner = RunnerFactory.createSchematic();
|
|
@@ -1111,14 +1133,12 @@ var CollectionFactory = class {
|
|
|
1111
1133
|
throw new CLIError(`Unknown collection: ${collection}`);
|
|
1112
1134
|
}
|
|
1113
1135
|
};
|
|
1114
|
-
|
|
1115
|
-
//#region src/lib/utils/formatting.ts
|
|
1136
|
+
// src/lib/utils/formatting.ts
|
|
1116
1137
|
const toKebabCase = (str) => {
|
|
1117
1138
|
return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
1118
1139
|
};
|
|
1119
1140
|
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1120
|
-
|
|
1121
|
-
//#region src/lib/schematics/schematic.option.ts
|
|
1141
|
+
// src/lib/schematics/schematic.option.ts
|
|
1122
1142
|
var SchematicOption = class {
|
|
1123
1143
|
name;
|
|
1124
1144
|
value;
|
|
@@ -1131,25 +1151,15 @@ var SchematicOption = class {
|
|
|
1131
1151
|
}
|
|
1132
1152
|
toCommandString(prefix) {
|
|
1133
1153
|
const normalizedName = `${prefix ? `${prefix}.` : ""}${this.normalizedName}`;
|
|
1134
|
-
if (typeof this.value === "string") {
|
|
1135
|
-
|
|
1136
|
-
else if (this.name === "version" || this.name === "path") return [`--${normalizedName}=${this.value}`];
|
|
1137
|
-
else return [`--${normalizedName}="${this.value}"`];
|
|
1138
|
-
} else if (typeof this.value === "boolean") {
|
|
1154
|
+
if (typeof this.value === "string") return [`--${normalizedName}=${this.name === "name" ? toKebabCase(this.value) : this.value}`];
|
|
1155
|
+
else if (typeof this.value === "boolean") {
|
|
1139
1156
|
const str = normalizedName;
|
|
1140
1157
|
return this.value ? [`--${str}=true`] : [`--${str}=false`];
|
|
1141
1158
|
} else if (Array.isArray(this.value)) return this.value.reduce((old, option) => [...old, ...option.toCommandString(normalizedName)], []);
|
|
1142
1159
|
else return [`--${normalizedName}=${this.value}`];
|
|
1143
1160
|
}
|
|
1144
|
-
format() {
|
|
1145
|
-
return toKebabCase(this.value).split("").reduce((content, char) => {
|
|
1146
|
-
if (char === "(" || char === ")" || char === "[" || char === "]") return `${content}\\${char}`;
|
|
1147
|
-
return `${content}${char}`;
|
|
1148
|
-
}, "");
|
|
1149
|
-
}
|
|
1150
1161
|
};
|
|
1151
|
-
|
|
1152
|
-
//#region src/action/common/schematics.ts
|
|
1162
|
+
// src/action/common/schematics.ts
|
|
1153
1163
|
const executeSchematic = async (name, collection, schematicName, options, fileToWatch) => {
|
|
1154
1164
|
const execute = async (isRebuild = false) => {
|
|
1155
1165
|
const message = isRebuild ? Messages.SCHEMATIC_WATCH_IN_PROGRESS(name) : Messages.SCHEMATIC_IN_PROGRESS(name);
|
|
@@ -1169,19 +1179,19 @@ const mapSchematicOptions = (inputs) => {
|
|
|
1169
1179
|
return acc;
|
|
1170
1180
|
}, []);
|
|
1171
1181
|
};
|
|
1172
|
-
|
|
1173
|
-
//#region src/action/actions/create.action.ts
|
|
1182
|
+
// src/action/actions/create.action.ts
|
|
1174
1183
|
var CreateAction = class extends AbstractAction {
|
|
1175
1184
|
startMessage = Messages.CREATE_START;
|
|
1176
1185
|
successMessage = Messages.CREATE_SUCCESS;
|
|
1177
1186
|
failureMessage = Messages.CREATE_FAILED;
|
|
1178
1187
|
async handle(args, options) {
|
|
1179
1188
|
const directory = getDirectoryInput(options);
|
|
1189
|
+
const type = getCreateTypeInput(args);
|
|
1190
|
+
if (type === "plugin") return this.generatePlugin(directory, options);
|
|
1180
1191
|
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1181
1192
|
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>).");
|
|
1182
1193
|
const { config } = workspaceConfig;
|
|
1183
1194
|
const defaults = config.type === "client" ? defaultClientConfig : defaultServerConfig;
|
|
1184
|
-
const type = getCreateTypeInput(args);
|
|
1185
1195
|
const name = await getCreateNameInputOrAsk(options);
|
|
1186
1196
|
const path = getPathInputWithDefault(options, config.dir?.[type === "component" ? "components" : "systems"] ?? defaults.dir[type === "component" ? "components" : "systems"]);
|
|
1187
1197
|
await this.generateElement(directory, type, {
|
|
@@ -1192,13 +1202,29 @@ var CreateAction = class extends AbstractAction {
|
|
|
1192
1202
|
});
|
|
1193
1203
|
return {};
|
|
1194
1204
|
}
|
|
1205
|
+
/** Generates a new editor plugin in `<directory>/<path or the plugin's short name>`. */
|
|
1206
|
+
async generatePlugin(directory, options) {
|
|
1207
|
+
const name = await getPluginNameInputOrAsk(options);
|
|
1208
|
+
const path = getPathInputWithDefault(options, name.split("/").at(-1) ?? name);
|
|
1209
|
+
const target = resolve(directory, path);
|
|
1210
|
+
if (existsSync(target) && readdirSync(target).length) throw new CLIError(`'${target}' already exists and is not empty.`, "Choose another folder with --path.");
|
|
1211
|
+
const template = getStringInputWithDefault(options, "template", "panel");
|
|
1212
|
+
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).");
|
|
1213
|
+
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1214
|
+
await executeSchematic("Plugin", collection, "plugin", {
|
|
1215
|
+
name,
|
|
1216
|
+
directory: path,
|
|
1217
|
+
template
|
|
1218
|
+
});
|
|
1219
|
+
console.info(template === "theme" ? Messages.CREATE_THEME_NEXT(target) : Messages.CREATE_PLUGIN_NEXT(target));
|
|
1220
|
+
return {};
|
|
1221
|
+
}
|
|
1195
1222
|
async generateElement(directory, type, values) {
|
|
1196
1223
|
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1197
1224
|
await executeSchematic(capitalize(type), collection, type, values);
|
|
1198
1225
|
}
|
|
1199
1226
|
};
|
|
1200
|
-
|
|
1201
|
-
//#region src/action/actions/dev.action.ts
|
|
1227
|
+
// src/action/actions/dev.action.ts
|
|
1202
1228
|
var DevAction = class extends AbstractAction {
|
|
1203
1229
|
startMessage = Messages.DEV_START;
|
|
1204
1230
|
successMessage = Messages.DEV_SUCCESS;
|
|
@@ -1232,8 +1258,31 @@ var DevAction = class extends AbstractAction {
|
|
|
1232
1258
|
});
|
|
1233
1259
|
}
|
|
1234
1260
|
};
|
|
1235
|
-
|
|
1236
|
-
|
|
1261
|
+
// src/lib/utils/editor-target.ts
|
|
1262
|
+
/**
|
|
1263
|
+
* Where `nf editor [path]` roots the editor: the working directory, or the project's parent
|
|
1264
|
+
* folder when the project is outside of it.
|
|
1265
|
+
*/
|
|
1266
|
+
const resolveEditorTarget = (directory, path) => {
|
|
1267
|
+
const fsRoot = resolve(directory);
|
|
1268
|
+
if (!path) return { fsRoot };
|
|
1269
|
+
const project = resolve(fsRoot, path);
|
|
1270
|
+
const inside = relative(fsRoot, project);
|
|
1271
|
+
if (!inside.startsWith("..") && !isAbsolute(inside)) return {
|
|
1272
|
+
fsRoot,
|
|
1273
|
+
projectPath: inside || "."
|
|
1274
|
+
};
|
|
1275
|
+
return {
|
|
1276
|
+
fsRoot: dirname(project),
|
|
1277
|
+
projectPath: basename(project)
|
|
1278
|
+
};
|
|
1279
|
+
};
|
|
1280
|
+
/** URL the browser opens: the project when there is one, the project list otherwise. */
|
|
1281
|
+
const editorUrl = (port, target) => {
|
|
1282
|
+
const base = `http://localhost:${port}`;
|
|
1283
|
+
return target.projectPath === void 0 ? base : `${base}/load?path=${encodeURIComponent(target.projectPath)}`;
|
|
1284
|
+
};
|
|
1285
|
+
// src/action/actions/editor.action.ts
|
|
1237
1286
|
var EditorAction = class extends AbstractAction {
|
|
1238
1287
|
startMessage = Messages.EDITOR_START;
|
|
1239
1288
|
successMessage = Messages.EDITOR_SUCCESS;
|
|
@@ -1241,30 +1290,47 @@ var EditorAction = class extends AbstractAction {
|
|
|
1241
1290
|
async handle(args, options) {
|
|
1242
1291
|
const directory = getDirectoryInput(options);
|
|
1243
1292
|
const path = getPathInput(args);
|
|
1293
|
+
const port = getEditorPortInput(options);
|
|
1244
1294
|
const shouldOpen = getEditorOpenInput(options, !!path);
|
|
1245
|
-
const
|
|
1295
|
+
const target = resolveEditorTarget(getCwd(directory), path);
|
|
1296
|
+
const url = editorUrl(port, target);
|
|
1246
1297
|
console.log(`\n🔗 Editor running! Open it in your browser: \x1b[36m${url}\x1b[0m\n`);
|
|
1247
|
-
this.startEditor(
|
|
1248
|
-
if (shouldOpen) await this.openBrowser(url);
|
|
1298
|
+
this.startEditor(target.fsRoot, port);
|
|
1299
|
+
if (shouldOpen && await this.waitForEditor(port)) await this.openBrowser(url);
|
|
1249
1300
|
return { keepAlive: true };
|
|
1250
1301
|
}
|
|
1251
|
-
async startEditor(
|
|
1302
|
+
async startEditor(fsRoot, port) {
|
|
1252
1303
|
const editorPath = join$1(getModulePath("@nanoforge-dev/editor/package.json", true), "dist", "index.js");
|
|
1253
1304
|
await runSafe(async () => {
|
|
1254
|
-
await PackageManagerFactory.create("local_bun").run("Editor",
|
|
1305
|
+
await PackageManagerFactory.create("local_bun").run("Editor", fsRoot, editorPath, [], {
|
|
1306
|
+
PORT: String(port),
|
|
1307
|
+
FS_ROOT: fsRoot,
|
|
1308
|
+
HOST: "127.0.0.1",
|
|
1309
|
+
PUBLIC_MODE: "OFFLINE"
|
|
1310
|
+
}, [], true);
|
|
1255
1311
|
});
|
|
1256
1312
|
}
|
|
1313
|
+
/** Waits until the editor answers (up to 30 s) so the browser doesn't open on an error page. */
|
|
1314
|
+
async waitForEditor(port) {
|
|
1315
|
+
for (const deadline = Date.now() + 3e4; Date.now() < deadline;) {
|
|
1316
|
+
try {
|
|
1317
|
+
if ((await fetch(`http://127.0.0.1:${port}/healthz`)).ok) return true;
|
|
1318
|
+
} catch {}
|
|
1319
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
1320
|
+
}
|
|
1321
|
+
return false;
|
|
1322
|
+
}
|
|
1257
1323
|
async openBrowser(url) {
|
|
1258
1324
|
await open(url);
|
|
1259
1325
|
}
|
|
1260
1326
|
};
|
|
1261
|
-
|
|
1262
|
-
//#region src/lib/constants.ts
|
|
1327
|
+
// src/lib/constants.ts
|
|
1263
1328
|
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1264
|
-
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1265
1329
|
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1266
|
-
|
|
1267
|
-
|
|
1330
|
+
const NANOFORGE_DIR = ".nanoforge";
|
|
1331
|
+
/** The API holding `/registry/…`: set at build time (`.env.build`), the editor's default too. */
|
|
1332
|
+
const REGISTRY_URL = "https://api.nanoforge.eu";
|
|
1333
|
+
// src/lib/utils/object.ts
|
|
1268
1334
|
const isObject = (item) => {
|
|
1269
1335
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
1270
1336
|
};
|
|
@@ -1278,11 +1344,9 @@ const deepMerge = (target, ...sources) => {
|
|
|
1278
1344
|
return deepMerge(target, ...sources);
|
|
1279
1345
|
};
|
|
1280
1346
|
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1281
|
-
|
|
1282
|
-
//#region src/lib/global-config/global-config-defaults.ts
|
|
1347
|
+
// src/lib/global-config/global-config-defaults.ts
|
|
1283
1348
|
const GLOBAL_CONFIG_DEFAULTS = {};
|
|
1284
|
-
|
|
1285
|
-
//#region src/lib/global-config/global-config-handler.ts
|
|
1349
|
+
// src/lib/global-config/global-config-handler.ts
|
|
1286
1350
|
var GlobalConfigHandler = class {
|
|
1287
1351
|
static read(dir) {
|
|
1288
1352
|
const dirConfig = this._readConfig(read, false, dir);
|
|
@@ -1296,8 +1360,12 @@ var GlobalConfigHandler = class {
|
|
|
1296
1360
|
name: GLOBAL_CONFIG_FILE_NAME,
|
|
1297
1361
|
dir
|
|
1298
1362
|
};
|
|
1299
|
-
if (local)
|
|
1300
|
-
|
|
1363
|
+
if (local) {
|
|
1364
|
+
const path = resolve(dir ?? process.cwd(), GLOBAL_CONFIG_FILE_NAME);
|
|
1365
|
+
closeSync(openSync(path, "a", 384));
|
|
1366
|
+
chmodSync(path, 384);
|
|
1367
|
+
write(config, options);
|
|
1368
|
+
} else writeUserConfig(config, options);
|
|
1301
1369
|
}
|
|
1302
1370
|
static _readConfig(func, force, dir) {
|
|
1303
1371
|
const res = func({
|
|
@@ -1307,257 +1375,136 @@ var GlobalConfigHandler = class {
|
|
|
1307
1375
|
if (!force) {
|
|
1308
1376
|
if (isEmpty(res)) return null;
|
|
1309
1377
|
}
|
|
1310
|
-
return deepMerge(GLOBAL_CONFIG_DEFAULTS, res);
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
//#endregion
|
|
1406
|
-
//#region src/lib/http/repository.ts
|
|
1407
|
-
var Repository = class {
|
|
1408
|
-
_client;
|
|
1409
|
-
constructor(client) {
|
|
1410
|
-
this._client = client;
|
|
1411
|
-
}
|
|
1412
|
-
get(path, options) {
|
|
1413
|
-
return this.runRequest("get", path, options);
|
|
1414
|
-
}
|
|
1415
|
-
getFile(path, options) {
|
|
1416
|
-
return this.runFileRequest("get", path, options);
|
|
1417
|
-
}
|
|
1418
|
-
post(path, body, options) {
|
|
1419
|
-
return this.runRequestBody("post", path, body ?? {}, options);
|
|
1420
|
-
}
|
|
1421
|
-
put(path, body, options) {
|
|
1422
|
-
return this.runRequestBody("put", path, body ?? {}, options);
|
|
1423
|
-
}
|
|
1424
|
-
patch(path, body, options) {
|
|
1425
|
-
return this.runRequestBody("patch", path, body ?? {}, options);
|
|
1426
|
-
}
|
|
1427
|
-
delete(path, options) {
|
|
1428
|
-
return this.runRequest("delete", path, options);
|
|
1429
|
-
}
|
|
1430
|
-
async runRequest(request, path, options) {
|
|
1431
|
-
const res = await this._client[request](path, options);
|
|
1432
|
-
const data = await res.json();
|
|
1433
|
-
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1434
|
-
return data;
|
|
1435
|
-
}
|
|
1436
|
-
async runFileRequest(request, path, options) {
|
|
1437
|
-
const res = await this._client[request](path, options);
|
|
1438
|
-
if (!res.ok) throw new ApiRequestError(res.status, (await res.json())["error"]);
|
|
1439
|
-
return await res.blob();
|
|
1440
|
-
}
|
|
1441
|
-
async runRequestBody(request, path, body, options) {
|
|
1442
|
-
const res = await this._client[request](path, body === void 0 ? void 0 : body instanceof FormData ? body : JSON.stringify(body), options);
|
|
1443
|
-
const data = await res.json();
|
|
1444
|
-
if (!res.ok) throw new ApiRequestError(res.status, data["error"]);
|
|
1445
|
-
return data;
|
|
1446
|
-
}
|
|
1447
|
-
};
|
|
1448
|
-
new Repository(new HttpClient("https://api.nanoforge.eu"));
|
|
1449
|
-
const withAuth = (apiKey, force = false, headers = { "Content-Type": "application/json" }) => {
|
|
1450
|
-
if (!apiKey && force) throw new RegistryAuthenticationError();
|
|
1451
|
-
return new Repository(new HttpClient("https://api.nanoforge.eu", { headers: {
|
|
1452
|
-
Authorization: apiKey,
|
|
1453
|
-
...headers
|
|
1454
|
-
} }));
|
|
1455
|
-
};
|
|
1456
|
-
//#endregion
|
|
1457
|
-
//#region src/lib/manifest/manifest-resolver.ts
|
|
1458
|
-
const resolveManifestDependencies = async (names, dir) => {
|
|
1459
|
-
const client = withAuth(GlobalConfigHandler.read(dir).apiKey, false);
|
|
1460
|
-
return concatDeps(await Promise.all(names.map(async (d) => resolveDeps(d, client))));
|
|
1461
|
-
};
|
|
1462
|
-
const resolveManifest = async (name, client) => {
|
|
1463
|
-
return await client.get(`/registry/${name}`);
|
|
1464
|
-
};
|
|
1465
|
-
const resolveDeps = async (name, client) => {
|
|
1466
|
-
const manifest = await resolveManifest(name, client);
|
|
1467
|
-
const baseDeps = manifest.dependencies ?? [];
|
|
1468
|
-
const deps = await Promise.all(baseDeps.map(async (d) => resolveDeps(d, client)));
|
|
1469
|
-
return concatDeps([{
|
|
1470
|
-
nf: { [manifest.name]: manifest },
|
|
1471
|
-
npm: getNpmDeps(manifest)
|
|
1472
|
-
}].concat(deps));
|
|
1473
|
-
};
|
|
1474
|
-
const getNpmDeps = (manifest) => {
|
|
1475
|
-
return Object.entries({
|
|
1476
|
-
...manifest.npmDependencies,
|
|
1477
|
-
...manifest.libDependencies
|
|
1478
|
-
});
|
|
1479
|
-
};
|
|
1480
|
-
const concatDeps = (deps) => {
|
|
1481
|
-
return {
|
|
1482
|
-
npm: deps.map(({ npm }) => npm).flat(),
|
|
1483
|
-
nf: Object.fromEntries(deps.map(({ nf }) => Object.entries(nf)).flat())
|
|
1378
|
+
return deepMerge({}, GLOBAL_CONFIG_DEFAULTS, res);
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
// src/lib/registry/registry.ts
|
|
1382
|
+
/** The registry, with `apiKey` sent to it (and only to it) when given. */
|
|
1383
|
+
const createRegistry = (apiKey) => new RegistryClient({
|
|
1384
|
+
baseUrl: REGISTRY_URL,
|
|
1385
|
+
headers: () => apiKey ? { authorization: `Bearer ${apiKey}` } : {}
|
|
1386
|
+
});
|
|
1387
|
+
/** The registry with the key `nf login` saved for `directory`; refuses without one. */
|
|
1388
|
+
const createAuthenticatedRegistry = (directory) => {
|
|
1389
|
+
const { apiKey } = GlobalConfigHandler.read(directory);
|
|
1390
|
+
if (!apiKey) throw new RegistryAuthenticationError();
|
|
1391
|
+
return createRegistry(apiKey);
|
|
1392
|
+
};
|
|
1393
|
+
/** Folders never packed by `nf publish`, wherever they are. */
|
|
1394
|
+
const DENIED_FOLDERS = /* @__PURE__ */ new Set([
|
|
1395
|
+
".git",
|
|
1396
|
+
"node_modules",
|
|
1397
|
+
"nf_modules",
|
|
1398
|
+
NANOFORGE_DIR,
|
|
1399
|
+
".aws",
|
|
1400
|
+
".docker"
|
|
1401
|
+
]);
|
|
1402
|
+
/** Files that hold secrets: env files, credentials, keys and keystores, private SSH keys. */
|
|
1403
|
+
const DENIED_FILES = [
|
|
1404
|
+
/^\.env/i,
|
|
1405
|
+
/^\.npmrc$/i,
|
|
1406
|
+
/^\.netrc$/i,
|
|
1407
|
+
/^\.git-credentials$/i,
|
|
1408
|
+
/^\.pgpass$/i,
|
|
1409
|
+
/^credentials\.json$/i,
|
|
1410
|
+
/\.(pem|key|p12|pfx|keystore|ppk)$/i,
|
|
1411
|
+
/^id_[^.]*$/i,
|
|
1412
|
+
/^id_(rsa|dsa|ecdsa|ed25519|xmss)(?!.*\.pub$)/i
|
|
1413
|
+
];
|
|
1414
|
+
/** What a plugin build writes next to its `entry`: the only files packed from that folder. */
|
|
1415
|
+
const BUILD_FILES = /\.(c?js|mjs|css|map|wasm|svg|png|jpe?g|gif|webp|avif|woff2?|ttf|otf)$/i;
|
|
1416
|
+
/** Files at the root packed with every package. */
|
|
1417
|
+
const ROOT_FILES = /^(readme|license|licence|changelog)(\..*)?$/i;
|
|
1418
|
+
const isDenied = (path, isDirectory) => {
|
|
1419
|
+
const name = basename(path);
|
|
1420
|
+
if (isDirectory) return DENIED_FOLDERS.has(name.toLowerCase());
|
|
1421
|
+
return name === ".nanoforgerc" || DENIED_FILES.some((pattern) => pattern.test(name));
|
|
1422
|
+
};
|
|
1423
|
+
/** Every string a value holds, at any depth. */
|
|
1424
|
+
const strings = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(strings) : typeof value === "object" && value !== null ? Object.values(value).flatMap(strings) : [];
|
|
1425
|
+
/** Every `path` field a value holds, at any depth (a plugin's `contributes`: icons…). */
|
|
1426
|
+
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)) : [];
|
|
1427
|
+
/** The SVG files an icon theme maps its icon names to (`contributes.iconThemes[].icons`). */
|
|
1428
|
+
const iconThemeFiles = (contributes) => {
|
|
1429
|
+
const themes = contributes?.iconThemes;
|
|
1430
|
+
return Array.isArray(themes) ? themes.flatMap((theme) => strings(theme?.icons)) : [];
|
|
1431
|
+
};
|
|
1432
|
+
const readJson = async (file) => JSON.parse(await readFile(file, "utf8"));
|
|
1433
|
+
/**
|
|
1434
|
+
* What the manifest names, from the package root: its `contents` and older `items`, its
|
|
1435
|
+
* sub-manifests (`include`) and their contents, its `readme`; for a plugin, the `path` fields of
|
|
1436
|
+
* `contributes` and the files of its icon themes. Folders end with `/`. A plugin's `entry` folders are `buildFolders`.
|
|
1437
|
+
*/
|
|
1438
|
+
const namedPaths = async (root, manifest) => {
|
|
1439
|
+
const described = await readPackageContents(manifest, (path) => readJson(join(root, path)));
|
|
1440
|
+
const plugin = manifest.type === "plugin";
|
|
1441
|
+
return [
|
|
1442
|
+
MANIFEST_FILE,
|
|
1443
|
+
...described.contents.map(({ path }) => path),
|
|
1444
|
+
...described.manifests,
|
|
1445
|
+
...pathFields(manifest.items).flatMap(strings),
|
|
1446
|
+
...strings(manifest.readme),
|
|
1447
|
+
...plugin ? [...pathFields(manifest.contributes).flatMap(strings), ...iconThemeFiles(manifest.contributes)] : []
|
|
1448
|
+
].map((path) => path.replace(/^\.\//, "")).filter((path) => isInsidePath(path.replace(/\/$/, ""))).map((path) => path.endsWith("/") || !statSync(join(root, path), { throwIfNoEntry: false })?.isDirectory() ? path : `${path}/`);
|
|
1449
|
+
};
|
|
1450
|
+
/** The folders of a plugin's `entry` files, `""` for the root: only build output is packed there. */
|
|
1451
|
+
const buildFolders = (manifest) => manifest.type !== "plugin" ? [] : strings(manifest.entry).map((entry) => dirname(normalize(entry))).filter((folder) => folder === "." || isInsidePath(folder)).map((folder) => folder === "." ? "" : `${folder}/`);
|
|
1452
|
+
/**
|
|
1453
|
+
* What `nf publish` leaves out of the package at `root`. Only what the manifest names is packed
|
|
1454
|
+
* (see `namedPaths`), with the root's `README*`, `LICENSE*` and `CHANGELOG*`; inside that, secrets
|
|
1455
|
+
* (`.env*`, `.npmrc`, `.netrc`, `.git-credentials`, `.pgpass`, `credentials.json`, the
|
|
1456
|
+
* `.nanoforgerc` of `nf login --local`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `*.keystore`, `*.ppk`,
|
|
1457
|
+
* private SSH keys `id_*`) and `.git`, `node_modules`, `nf_modules`, `.nanoforge`, `.aws` and
|
|
1458
|
+
* `.docker` folders stay out at any depth. `.gitignore` is not read.
|
|
1459
|
+
*/
|
|
1460
|
+
const publishIgnore = async (root, manifest) => {
|
|
1461
|
+
const named = await namedPaths(root, manifest);
|
|
1462
|
+
const builds = buildFolders(manifest);
|
|
1463
|
+
const folders = named.filter((path) => path.endsWith("/"));
|
|
1464
|
+
const files = new Set(named.filter((path) => !path.endsWith("/")));
|
|
1465
|
+
const inFolder = (path) => folders.some((folder) => path.startsWith(folder));
|
|
1466
|
+
const inBuild = (path) => builds.some((folder) => path.startsWith(folder));
|
|
1467
|
+
return (path, isDirectory) => {
|
|
1468
|
+
if (isDenied(path, isDirectory)) return true;
|
|
1469
|
+
if (inFolder(isDirectory ? `${path}/` : path)) return false;
|
|
1470
|
+
if (isDirectory ? inBuild(`${path}/`) : inBuild(path) && BUILD_FILES.test(path)) return false;
|
|
1471
|
+
if (isDirectory) return ![...folders, ...files].some((allowed) => allowed.startsWith(`${path}/`));
|
|
1472
|
+
return !files.has(path) && !(!path.includes("/") && ROOT_FILES.test(path));
|
|
1484
1473
|
};
|
|
1485
1474
|
};
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
const filename = manifest.publish?.paths?.package ?? "index.ts";
|
|
1492
|
-
const file = await this._getPackageFile(filename, dir);
|
|
1493
|
-
const data = new FormData();
|
|
1494
|
-
for (const key of Object.keys(manifest)) {
|
|
1495
|
-
const value = manifest[key];
|
|
1496
|
-
if (!value) continue;
|
|
1497
|
-
data.append(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
1498
|
-
}
|
|
1499
|
-
data.append("_packageFile", file, filename);
|
|
1500
|
-
await client.put(`/registry/${manifest.name}`, data);
|
|
1501
|
-
}
|
|
1502
|
-
static async unpublish(manifest, dir) {
|
|
1503
|
-
await this._getClient(dir, true).delete(`/registry/${manifest.name}`);
|
|
1504
|
-
}
|
|
1505
|
-
static async install(manifests, dir) {
|
|
1506
|
-
const cwd = getCwd(dir);
|
|
1507
|
-
const client = this._getClient(dir, false);
|
|
1508
|
-
for (const manifest of manifests) await this.installPackage(client, manifest, cwd);
|
|
1509
|
-
}
|
|
1510
|
-
static async installPackage(client, manifest, dir) {
|
|
1511
|
-
const file = await client.getFile(`/registry/${manifest.name}/-/${manifest._file}`);
|
|
1512
|
-
const path = join$1(dir, this.getTypeSubFolder(manifest.type));
|
|
1513
|
-
fs.mkdirSync(path, { recursive: true });
|
|
1514
|
-
fs.writeFileSync(join$1(path, manifest._file), await file.bytes());
|
|
1515
|
-
}
|
|
1516
|
-
static getTypeSubFolder(type) {
|
|
1517
|
-
if (type === "component") return "components";
|
|
1518
|
-
if (type === "system") return "systems";
|
|
1519
|
-
return ".";
|
|
1520
|
-
}
|
|
1521
|
-
static _getClient(dir, force, headers = true) {
|
|
1522
|
-
const config = GlobalConfigHandler.read(dir);
|
|
1523
|
-
return withAuth(config.apiKey, force, !headers ? {} : void 0);
|
|
1524
|
-
}
|
|
1525
|
-
static _getPackageFile(filename, dir) {
|
|
1526
|
-
const path = join$1(getCwd(dir ?? "."), filename);
|
|
1527
|
-
if (!fs.existsSync(path)) throw new CLIError("Package not found, please specify path in the nanoforge.manifest.json : `publish.paths.package`!");
|
|
1528
|
-
try {
|
|
1529
|
-
fs.accessSync(path, fs.constants.R_OK);
|
|
1530
|
-
return fs.openAsBlob(path);
|
|
1531
|
-
} catch {
|
|
1532
|
-
throw new CLIError("Cannot read package file, please verify your file permissions!");
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1475
|
+
// src/action/actions/install.action.ts
|
|
1476
|
+
/** `@scope/name@^1.2.0` → `["@scope/name", "^1.2.0"]`; no range after the name → undefined. */
|
|
1477
|
+
const parsePackageSpec = (spec) => {
|
|
1478
|
+
const at = spec.lastIndexOf("@");
|
|
1479
|
+
return at > 0 ? [spec.slice(0, at), spec.slice(at + 1) || void 0] : [spec, void 0];
|
|
1535
1480
|
};
|
|
1536
|
-
//#endregion
|
|
1537
|
-
//#region src/action/actions/install.action.ts
|
|
1538
1481
|
var InstallAction = class extends AbstractAction {
|
|
1539
1482
|
startMessage = Messages.INSTALL_START;
|
|
1540
1483
|
successMessage = Messages.INSTALL_SUCCESS;
|
|
1541
1484
|
failureMessage = Messages.INSTALL_FAILED;
|
|
1542
1485
|
async handle(args, options) {
|
|
1543
|
-
const names = await getInstallNamesInputOrAsk(args);
|
|
1544
1486
|
const directory = getDirectoryInput(options);
|
|
1545
|
-
|
|
1546
|
-
const isServer = getServerInput(options);
|
|
1547
|
-
return isLib ? this._installLibs(directory, names) : this._installNfPackages(directory, names, isServer);
|
|
1487
|
+
return getInstallLibInput(options) ? this._installLibs(directory, await getInstallNamesInputOrAsk(args)) : this._installNfPackages(directory, getArrayInput(args, "names") ?? []);
|
|
1548
1488
|
}
|
|
1549
1489
|
async _installLibs(directory, names) {
|
|
1550
1490
|
return { success: await (await PackageManagerFactory.find(directory)).addDevelopment(directory, names) };
|
|
1551
1491
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1492
|
+
/**
|
|
1493
|
+
* Installs registry packages into `nf_modules` (list, lock and tsconfig paths updated). Without
|
|
1494
|
+
* names, installs what the lock lists (a fresh clone).
|
|
1495
|
+
*/
|
|
1496
|
+
_installNfPackages(directory, names) {
|
|
1497
|
+
const packages = new ProjectPackages(getCwd(directory), createRegistry());
|
|
1498
|
+
return withSpinner(async () => {
|
|
1499
|
+
if (!names.length) {
|
|
1500
|
+
await packages.restore();
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
for (const spec of names) await packages.install(...parsePackageSpec(spec));
|
|
1504
|
+
}, Messages.INSTALL_PACKAGES_IN_PROGRESS);
|
|
1557
1505
|
}
|
|
1558
1506
|
};
|
|
1559
|
-
|
|
1560
|
-
//#region src/action/actions/login.action.ts
|
|
1507
|
+
// src/action/actions/login.action.ts
|
|
1561
1508
|
var LoginAction = class extends AbstractAction {
|
|
1562
1509
|
startMessage = Messages.LOGIN_START;
|
|
1563
1510
|
successMessage = Messages.LOGIN_SUCCESS;
|
|
@@ -1566,13 +1513,12 @@ var LoginAction = class extends AbstractAction {
|
|
|
1566
1513
|
const directory = getDirectoryInput(options);
|
|
1567
1514
|
const isLocal = getLocalInput(options);
|
|
1568
1515
|
const apiKey = await getLoginApiKeyInputOrAsk(options);
|
|
1569
|
-
await
|
|
1516
|
+
await createRegistry(apiKey).whoami();
|
|
1570
1517
|
GlobalConfigHandler.write({ apiKey }, isLocal, directory);
|
|
1571
1518
|
return { success: true };
|
|
1572
1519
|
}
|
|
1573
1520
|
};
|
|
1574
|
-
|
|
1575
|
-
//#region src/action/actions/logout.action.ts
|
|
1521
|
+
// src/action/actions/logout.action.ts
|
|
1576
1522
|
var LogoutAction = class extends AbstractAction {
|
|
1577
1523
|
startMessage = Messages.LOGOUT_START;
|
|
1578
1524
|
successMessage = Messages.LOGOUT_SUCCESS;
|
|
@@ -1584,8 +1530,7 @@ var LogoutAction = class extends AbstractAction {
|
|
|
1584
1530
|
return { success: true };
|
|
1585
1531
|
}
|
|
1586
1532
|
};
|
|
1587
|
-
|
|
1588
|
-
//#region src/lib/git/git-runner.ts
|
|
1533
|
+
// src/lib/git/git-runner.ts
|
|
1589
1534
|
const GIT = "git";
|
|
1590
1535
|
const GIT_COMMANDS = {
|
|
1591
1536
|
init: "init",
|
|
@@ -1622,8 +1567,7 @@ var GitRunner = class {
|
|
|
1622
1567
|
return this.runner.fullCommand(args);
|
|
1623
1568
|
}
|
|
1624
1569
|
};
|
|
1625
|
-
|
|
1626
|
-
//#region src/lib/input/inputs/new/git-remote.input.ts
|
|
1570
|
+
// src/lib/input/inputs/new/git-remote.input.ts
|
|
1627
1571
|
const getGitRemoteInput = (inputs) => {
|
|
1628
1572
|
return getStringInput(inputs, "gitRemote");
|
|
1629
1573
|
};
|
|
@@ -1633,16 +1577,14 @@ const getNewGitRemoteInputOrAsk = (inputs) => {
|
|
|
1633
1577
|
default: ""
|
|
1634
1578
|
}));
|
|
1635
1579
|
};
|
|
1636
|
-
|
|
1637
|
-
//#region src/lib/input/inputs/new/git.input.ts
|
|
1580
|
+
// src/lib/input/inputs/new/git.input.ts
|
|
1638
1581
|
const getNewGitInput = (inputs) => {
|
|
1639
1582
|
return getBooleanInput(inputs, "git");
|
|
1640
1583
|
};
|
|
1641
1584
|
const getNewGitOrAsk = (inputs) => {
|
|
1642
1585
|
return getInputOrAsk(getNewGitInput(inputs), () => askConfirm(Messages.NEW_GIT_QUESTION, { default: true }));
|
|
1643
1586
|
};
|
|
1644
|
-
|
|
1645
|
-
//#region src/action/actions/new.action.ts
|
|
1587
|
+
// src/action/actions/new.action.ts
|
|
1646
1588
|
var NewAction = class extends AbstractAction {
|
|
1647
1589
|
startMessage = Messages.NEW_START;
|
|
1648
1590
|
successMessage = Messages.NEW_SUCCESS;
|
|
@@ -1667,6 +1609,7 @@ var NewAction = class extends AbstractAction {
|
|
|
1667
1609
|
skipInstall: await getNewSkipInstallOrAsk(inputs),
|
|
1668
1610
|
docker: await getNewDockerOrAsk(inputs),
|
|
1669
1611
|
lint: getNewLintInput(inputs),
|
|
1612
|
+
agents: getNewAgentsInput(inputs),
|
|
1670
1613
|
editor: getEditorInput(inputs),
|
|
1671
1614
|
git: await getNewGitOrAsk(inputs)
|
|
1672
1615
|
};
|
|
@@ -1694,7 +1637,8 @@ var NewAction = class extends AbstractAction {
|
|
|
1694
1637
|
language: values.language,
|
|
1695
1638
|
strict: values.strict,
|
|
1696
1639
|
packageManager: values.packageManager,
|
|
1697
|
-
docker: values.docker
|
|
1640
|
+
docker: values.docker,
|
|
1641
|
+
agents: values.agents
|
|
1698
1642
|
});
|
|
1699
1643
|
}
|
|
1700
1644
|
generateClientProject(collection, values) {
|
|
@@ -1717,7 +1661,8 @@ var NewAction = class extends AbstractAction {
|
|
|
1717
1661
|
packageManager: values.packageManager,
|
|
1718
1662
|
workspace: values.multiplayer,
|
|
1719
1663
|
docker: values.docker,
|
|
1720
|
-
editor: values.editor
|
|
1664
|
+
editor: values.editor,
|
|
1665
|
+
agents: values.agents
|
|
1721
1666
|
};
|
|
1722
1667
|
}
|
|
1723
1668
|
async installDependencies(packageManagerName, directory) {
|
|
@@ -1731,133 +1676,53 @@ var NewAction = class extends AbstractAction {
|
|
|
1731
1676
|
return res;
|
|
1732
1677
|
}
|
|
1733
1678
|
};
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
if (
|
|
1739
|
-
|
|
1740
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1741
|
-
}
|
|
1742
|
-
//#endregion
|
|
1743
|
-
//#region src/lib/manifest/manifest.type.ts
|
|
1744
|
-
let ManifestPackageTypeEnum = /* @__PURE__ */ function(ManifestPackageTypeEnum) {
|
|
1745
|
-
ManifestPackageTypeEnum["COMPONENT"] = "component";
|
|
1746
|
-
ManifestPackageTypeEnum["SYSTEM"] = "system";
|
|
1747
|
-
return ManifestPackageTypeEnum;
|
|
1748
|
-
}({});
|
|
1749
|
-
var PathsPublishManifest = class {
|
|
1750
|
-
package;
|
|
1751
|
-
};
|
|
1752
|
-
__decorate([
|
|
1753
|
-
Expose(),
|
|
1754
|
-
IsString(),
|
|
1755
|
-
IsNotEmpty(),
|
|
1756
|
-
IsOptional()
|
|
1757
|
-
], PathsPublishManifest.prototype, "package", void 0);
|
|
1758
|
-
var PublishManifest = class {
|
|
1759
|
-
paths;
|
|
1760
|
-
};
|
|
1761
|
-
__decorate([
|
|
1762
|
-
Expose(),
|
|
1763
|
-
IsOptional(),
|
|
1764
|
-
ValidateNested(),
|
|
1765
|
-
Type(() => PathsPublishManifest)
|
|
1766
|
-
], PublishManifest.prototype, "paths", void 0);
|
|
1767
|
-
var Manifest = class {
|
|
1768
|
-
name;
|
|
1769
|
-
type;
|
|
1770
|
-
description;
|
|
1771
|
-
tags;
|
|
1772
|
-
dependencies;
|
|
1773
|
-
publish;
|
|
1774
|
-
libDependencies;
|
|
1775
|
-
npmDependencies;
|
|
1776
|
-
};
|
|
1777
|
-
__decorate([
|
|
1778
|
-
Expose(),
|
|
1779
|
-
IsString(),
|
|
1780
|
-
Matches(/^[A-Za-z0-9-]+\/[A-Za-z0-9-]+$/),
|
|
1781
|
-
IsNotEmpty()
|
|
1782
|
-
], Manifest.prototype, "name", void 0);
|
|
1783
|
-
__decorate([
|
|
1784
|
-
Expose(),
|
|
1785
|
-
IsString(),
|
|
1786
|
-
IsEnum(ManifestPackageTypeEnum),
|
|
1787
|
-
IsNotEmpty()
|
|
1788
|
-
], Manifest.prototype, "type", void 0);
|
|
1789
|
-
__decorate([
|
|
1790
|
-
Expose(),
|
|
1791
|
-
IsString(),
|
|
1792
|
-
IsOptional()
|
|
1793
|
-
], Manifest.prototype, "description", void 0);
|
|
1794
|
-
__decorate([
|
|
1795
|
-
Expose(),
|
|
1796
|
-
IsString({ each: true }),
|
|
1797
|
-
IsOptional()
|
|
1798
|
-
], Manifest.prototype, "tags", void 0);
|
|
1799
|
-
__decorate([
|
|
1800
|
-
Expose(),
|
|
1801
|
-
IsString({ each: true }),
|
|
1802
|
-
IsNotEmpty({ each: true }),
|
|
1803
|
-
IsOptional()
|
|
1804
|
-
], Manifest.prototype, "dependencies", void 0);
|
|
1805
|
-
__decorate([
|
|
1806
|
-
Expose(),
|
|
1807
|
-
IsOptional(),
|
|
1808
|
-
ValidateNested(),
|
|
1809
|
-
Type(() => PublishManifest)
|
|
1810
|
-
], Manifest.prototype, "publish", void 0);
|
|
1811
|
-
__decorate([
|
|
1812
|
-
Expose(),
|
|
1813
|
-
IsObject(),
|
|
1814
|
-
IsOptional()
|
|
1815
|
-
], Manifest.prototype, "libDependencies", void 0);
|
|
1816
|
-
__decorate([
|
|
1817
|
-
Expose(),
|
|
1818
|
-
IsObject(),
|
|
1819
|
-
IsOptional()
|
|
1820
|
-
], Manifest.prototype, "npmDependencies", void 0);
|
|
1821
|
-
//#endregion
|
|
1822
|
-
//#region src/lib/manifest/manifest-loader.ts
|
|
1823
|
-
const getManifestPath = (directory) => {
|
|
1824
|
-
for (const n of [MANIFEST_FILE_NAME]) {
|
|
1825
|
-
const path = join(directory, n);
|
|
1826
|
-
if (existsSync(path)) return path;
|
|
1827
|
-
}
|
|
1828
|
-
throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1829
|
-
};
|
|
1830
|
-
const loadManifest = async (directory) => {
|
|
1831
|
-
let rawData;
|
|
1832
|
-
const path = getManifestPath(directory);
|
|
1679
|
+
// src/lib/manifest/manifest-loader.ts
|
|
1680
|
+
/** The `nanoforge.manifest.json` of a package folder, checked against the registry's schema. */
|
|
1681
|
+
const loadManifest = (directory) => {
|
|
1682
|
+
const path = join(directory, MANIFEST_FILE);
|
|
1683
|
+
if (!existsSync(path)) throw new ManifestError(`No manifest file found in directory: ${directory}`);
|
|
1684
|
+
let json;
|
|
1833
1685
|
try {
|
|
1834
|
-
|
|
1686
|
+
json = JSON.parse(readFileSync(path, "utf-8"));
|
|
1835
1687
|
} catch {
|
|
1836
|
-
|
|
1688
|
+
throw new ManifestError(`Unable to read or parse file at ${path}`);
|
|
1837
1689
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1690
|
+
const parsed = ItemManifest.safeParse(json);
|
|
1691
|
+
if (!parsed.success) {
|
|
1692
|
+
const issue = parsed.error.issues[0];
|
|
1693
|
+
throw new ManifestError(`Validation failed: ${issue?.path.join(".") || "manifest"}: ${issue?.message ?? "invalid"}`);
|
|
1694
|
+
}
|
|
1695
|
+
return parsed.data;
|
|
1843
1696
|
};
|
|
1844
|
-
|
|
1845
|
-
|
|
1697
|
+
// src/action/actions/publish.action.ts
|
|
1698
|
+
const formatSize = (bytes) => bytes < 1024 ? `${bytes} B` : bytes < 1048576 ? `${(bytes / 1024).toFixed(1)} KiB` : `${(bytes / 1024 / 1024).toFixed(1)} MiB`;
|
|
1846
1699
|
var PublishAction = class extends AbstractAction {
|
|
1847
1700
|
startMessage = Messages.PUBLISH_START;
|
|
1848
1701
|
successMessage = Messages.PUBLISH_SUCCESS;
|
|
1849
1702
|
failureMessage = Messages.PUBLISH_FAILED;
|
|
1703
|
+
/**
|
|
1704
|
+
* Zips what the manifest names (secrets left out), lists what it packed, and publishes it;
|
|
1705
|
+
* `--dry-run` stops after the list.
|
|
1706
|
+
*/
|
|
1850
1707
|
async handle(_args, options) {
|
|
1851
1708
|
const directory = getDirectoryInput(options);
|
|
1852
|
-
const manifest =
|
|
1853
|
-
const
|
|
1854
|
-
const
|
|
1855
|
-
|
|
1856
|
-
|
|
1709
|
+
const manifest = loadManifest(directory);
|
|
1710
|
+
const subject = `${manifest.name}@${manifest.version}`;
|
|
1711
|
+
const root = getCwd(directory);
|
|
1712
|
+
const archive = await zipFolder(root, { ignore: await publishIgnore(root, manifest) });
|
|
1713
|
+
const files = [...readArchive(archive)];
|
|
1714
|
+
for (const [path, content] of files) console.info(` ${path} (${formatSize(content.length)})`);
|
|
1715
|
+
const unpacked = files.reduce((total, [, content]) => total + content.length, 0);
|
|
1716
|
+
console.info(Messages.PUBLISH_FILES(subject, files.length, formatSize(unpacked)));
|
|
1717
|
+
if (getDryRunInput(options)) {
|
|
1718
|
+
this.successMessage = Messages.PUBLISH_DRY_RUN_SUCCESS;
|
|
1719
|
+
return { success: true };
|
|
1720
|
+
}
|
|
1721
|
+
const registry = createAuthenticatedRegistry(directory);
|
|
1722
|
+
return withSpinner(() => registry.publish(manifest.name, archive), Messages.PUBLISH_IN_PROGRESS(subject));
|
|
1857
1723
|
}
|
|
1858
1724
|
};
|
|
1859
|
-
|
|
1860
|
-
//#region src/action/actions/start.action.ts
|
|
1725
|
+
// src/action/actions/start.action.ts
|
|
1861
1726
|
const isClientTarget = (target) => target.platform === "client";
|
|
1862
1727
|
const isServerTarget = (target) => target.platform === "server";
|
|
1863
1728
|
var StartAction = class extends AbstractAction {
|
|
@@ -1873,6 +1738,7 @@ var StartAction = class extends AbstractAction {
|
|
|
1873
1738
|
const clientTargets = targets.filter(isClientTarget);
|
|
1874
1739
|
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.");
|
|
1875
1740
|
const env = this.parseEnv(directory);
|
|
1741
|
+
if (isPeerToPeer(workspaceConfig)) env.client.NANOFORGE_NETWORK_MODE = env.server.NANOFORGE_NETWORK_MODE = "p2p";
|
|
1876
1742
|
const packageManager = await PackageManagerFactory.find(directory);
|
|
1877
1743
|
const tasks = this.buildStartTasks(packageManager, serverTargets, clientTargets, watch, env);
|
|
1878
1744
|
await Promise.all(tasks);
|
|
@@ -1959,7 +1825,7 @@ var StartAction = class extends AbstractAction {
|
|
|
1959
1825
|
const serverPrefix = `${prefix}SERVER_`;
|
|
1960
1826
|
const rawEnv = { ...process.env };
|
|
1961
1827
|
dotenv.config({
|
|
1962
|
-
path: resolve(getCwd(join$1(dir, ".env"))),
|
|
1828
|
+
path: resolve$1(getCwd(join$1(dir, ".env"))),
|
|
1963
1829
|
processEnv: rawEnv
|
|
1964
1830
|
});
|
|
1965
1831
|
const baseEnv = Object.entries(rawEnv).filter(([key, value]) => key.startsWith(prefix) && !!value);
|
|
@@ -1974,20 +1840,20 @@ var StartAction = class extends AbstractAction {
|
|
|
1974
1840
|
});
|
|
1975
1841
|
}
|
|
1976
1842
|
};
|
|
1977
|
-
|
|
1978
|
-
//#region src/action/actions/unpublish.action.ts
|
|
1843
|
+
// src/action/actions/unpublish.action.ts
|
|
1979
1844
|
var UnpublishAction = class extends AbstractAction {
|
|
1980
1845
|
startMessage = Messages.UNPUBLISH_START;
|
|
1981
1846
|
successMessage = Messages.UNPUBLISH_SUCCESS;
|
|
1982
1847
|
failureMessage = Messages.UNPUBLISH_FAILED;
|
|
1848
|
+
/** Unpublishes the version the manifest names: that number can never be published again. */
|
|
1983
1849
|
async handle(_args, options) {
|
|
1984
1850
|
const directory = getDirectoryInput(options);
|
|
1985
|
-
const manifest =
|
|
1986
|
-
|
|
1851
|
+
const manifest = loadManifest(directory);
|
|
1852
|
+
const registry = createAuthenticatedRegistry(directory);
|
|
1853
|
+
return withSpinner(() => registry.unpublish(manifest.name, manifest.version), Messages.UNPUBLISH_IN_PROGRESS(`${manifest.name}@${manifest.version}`));
|
|
1987
1854
|
}
|
|
1988
1855
|
};
|
|
1989
|
-
|
|
1990
|
-
//#region src/command/abstract.command.ts
|
|
1856
|
+
// src/command/abstract.command.ts
|
|
1991
1857
|
var AbstractCommand = class {
|
|
1992
1858
|
action;
|
|
1993
1859
|
constructor(action) {
|
|
@@ -1999,8 +1865,7 @@ var AbstractCommand = class {
|
|
|
1999
1865
|
return input;
|
|
2000
1866
|
}
|
|
2001
1867
|
};
|
|
2002
|
-
|
|
2003
|
-
//#region src/command/commands/build.command.ts
|
|
1868
|
+
// src/command/commands/build.command.ts
|
|
2004
1869
|
var BuildCommand = class extends AbstractCommand {
|
|
2005
1870
|
load(program) {
|
|
2006
1871
|
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) => {
|
|
@@ -2019,23 +1884,22 @@ var BuildCommand = class extends AbstractCommand {
|
|
|
2019
1884
|
});
|
|
2020
1885
|
}
|
|
2021
1886
|
};
|
|
2022
|
-
|
|
2023
|
-
//#region src/command/commands/create.command.ts
|
|
1887
|
+
// src/command/commands/create.command.ts
|
|
2024
1888
|
var CreateCommand = class extends AbstractCommand {
|
|
2025
1889
|
load(program) {
|
|
2026
|
-
program.command("create <type>").description("create
|
|
1890
|
+
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) => {
|
|
2027
1891
|
const args = AbstractCommand.mapToInput({ type });
|
|
2028
1892
|
const options = AbstractCommand.mapToInput({
|
|
2029
1893
|
directory: rawOptions.directory,
|
|
2030
1894
|
name: rawOptions.name,
|
|
2031
|
-
path: rawOptions.path
|
|
1895
|
+
path: rawOptions.path,
|
|
1896
|
+
template: rawOptions.template
|
|
2032
1897
|
});
|
|
2033
1898
|
await this.action.run(args, options);
|
|
2034
1899
|
});
|
|
2035
1900
|
}
|
|
2036
1901
|
};
|
|
2037
|
-
|
|
2038
|
-
//#region src/command/commands/dev.command.ts
|
|
1902
|
+
// src/command/commands/dev.command.ts
|
|
2039
1903
|
var DevCommand = class extends AbstractCommand {
|
|
2040
1904
|
load(program) {
|
|
2041
1905
|
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) => {
|
|
@@ -2048,37 +1912,34 @@ var DevCommand = class extends AbstractCommand {
|
|
|
2048
1912
|
});
|
|
2049
1913
|
}
|
|
2050
1914
|
};
|
|
2051
|
-
|
|
2052
|
-
//#region src/command/commands/editor.command.ts
|
|
1915
|
+
// src/command/commands/editor.command.ts
|
|
2053
1916
|
var EditorCommand = class extends AbstractCommand {
|
|
2054
1917
|
load(program) {
|
|
2055
|
-
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) => {
|
|
1918
|
+
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) => {
|
|
2056
1919
|
const args = AbstractCommand.mapToInput({ path });
|
|
2057
1920
|
const options = AbstractCommand.mapToInput({
|
|
2058
1921
|
directory: rawOptions.directory,
|
|
2059
|
-
open: rawOptions.open
|
|
1922
|
+
open: rawOptions.open,
|
|
1923
|
+
port: rawOptions.port
|
|
2060
1924
|
});
|
|
2061
1925
|
await this.action.run(args, options);
|
|
2062
1926
|
});
|
|
2063
1927
|
}
|
|
2064
1928
|
};
|
|
2065
|
-
|
|
2066
|
-
//#region src/command/commands/install.command.ts
|
|
1929
|
+
// src/command/commands/install.command.ts
|
|
2067
1930
|
var InstallCommand = class extends AbstractCommand {
|
|
2068
1931
|
load(program) {
|
|
2069
|
-
program.command("install [names...]").alias("add").description("add
|
|
1932
|
+
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) => {
|
|
2070
1933
|
const options = AbstractCommand.mapToInput({
|
|
2071
1934
|
directory: rawOptions.directory,
|
|
2072
|
-
lib: rawOptions.lib
|
|
2073
|
-
server: rawOptions.server
|
|
1935
|
+
lib: rawOptions.lib
|
|
2074
1936
|
});
|
|
2075
1937
|
const args = AbstractCommand.mapToInput({ names: names.length ? names : void 0 });
|
|
2076
1938
|
await this.action.run(args, options);
|
|
2077
1939
|
});
|
|
2078
1940
|
}
|
|
2079
1941
|
};
|
|
2080
|
-
|
|
2081
|
-
//#region src/command/commands/login.command.ts
|
|
1942
|
+
// src/command/commands/login.command.ts
|
|
2082
1943
|
var LoginCommand = class extends AbstractCommand {
|
|
2083
1944
|
load(program) {
|
|
2084
1945
|
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) => {
|
|
@@ -2091,8 +1952,7 @@ var LoginCommand = class extends AbstractCommand {
|
|
|
2091
1952
|
});
|
|
2092
1953
|
}
|
|
2093
1954
|
};
|
|
2094
|
-
|
|
2095
|
-
//#region src/command/commands/logout.command.ts
|
|
1955
|
+
// src/command/commands/logout.command.ts
|
|
2096
1956
|
var LogoutCommand = class extends AbstractCommand {
|
|
2097
1957
|
load(program) {
|
|
2098
1958
|
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) => {
|
|
@@ -2104,11 +1964,10 @@ var LogoutCommand = class extends AbstractCommand {
|
|
|
2104
1964
|
});
|
|
2105
1965
|
}
|
|
2106
1966
|
};
|
|
2107
|
-
|
|
2108
|
-
//#region src/command/commands/new.command.ts
|
|
1967
|
+
// src/command/commands/new.command.ts
|
|
2109
1968
|
var NewCommand = class extends AbstractCommand {
|
|
2110
1969
|
load(program) {
|
|
2111
|
-
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) => {
|
|
1970
|
+
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) => {
|
|
2112
1971
|
const options = AbstractCommand.mapToInput({
|
|
2113
1972
|
directory: rawOptions.directory,
|
|
2114
1973
|
name: rawOptions.name,
|
|
@@ -2121,6 +1980,7 @@ var NewCommand = class extends AbstractCommand {
|
|
|
2121
1980
|
skipInstall: rawOptions.skipInstall,
|
|
2122
1981
|
docker: rawOptions.docker,
|
|
2123
1982
|
lint: rawOptions.lint,
|
|
1983
|
+
agents: rawOptions.agents,
|
|
2124
1984
|
editor: rawOptions.editor,
|
|
2125
1985
|
git: rawOptions.git
|
|
2126
1986
|
});
|
|
@@ -2130,18 +1990,19 @@ var NewCommand = class extends AbstractCommand {
|
|
|
2130
1990
|
});
|
|
2131
1991
|
}
|
|
2132
1992
|
};
|
|
2133
|
-
|
|
2134
|
-
//#region src/command/commands/publish.command.ts
|
|
1993
|
+
// src/command/commands/publish.command.ts
|
|
2135
1994
|
var PublishCommand = class extends AbstractCommand {
|
|
2136
1995
|
load(program) {
|
|
2137
|
-
program.command("publish").description("publish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
|
|
2138
|
-
const options = AbstractCommand.mapToInput({
|
|
1996
|
+
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) => {
|
|
1997
|
+
const options = AbstractCommand.mapToInput({
|
|
1998
|
+
directory: rawOptions.directory,
|
|
1999
|
+
dryRun: rawOptions.dryRun
|
|
2000
|
+
});
|
|
2139
2001
|
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
2140
2002
|
});
|
|
2141
2003
|
}
|
|
2142
2004
|
};
|
|
2143
|
-
|
|
2144
|
-
//#region src/command/commands/start.command.ts
|
|
2005
|
+
// src/command/commands/start.command.ts
|
|
2145
2006
|
var StartCommand = class extends AbstractCommand {
|
|
2146
2007
|
load(program) {
|
|
2147
2008
|
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) => {
|
|
@@ -2158,8 +2019,7 @@ var StartCommand = class extends AbstractCommand {
|
|
|
2158
2019
|
});
|
|
2159
2020
|
}
|
|
2160
2021
|
};
|
|
2161
|
-
|
|
2162
|
-
//#region src/command/commands/unpublish.command.ts
|
|
2022
|
+
// src/command/commands/unpublish.command.ts
|
|
2163
2023
|
var UnpublishCommand = class extends AbstractCommand {
|
|
2164
2024
|
load(program) {
|
|
2165
2025
|
program.command("unpublish").description("unpublish package to Nanoforge registry").option("-d, --directory <directory>", "specify the working directory of the command").action(async (rawOptions) => {
|
|
@@ -2168,8 +2028,7 @@ var UnpublishCommand = class extends AbstractCommand {
|
|
|
2168
2028
|
});
|
|
2169
2029
|
}
|
|
2170
2030
|
};
|
|
2171
|
-
|
|
2172
|
-
//#region src/command/command.loader.ts
|
|
2031
|
+
// src/command/command.loader.ts
|
|
2173
2032
|
var CommandLoader = class {
|
|
2174
2033
|
static async load(program) {
|
|
2175
2034
|
new NewCommand(new NewAction()).load(program);
|
|
@@ -2193,7 +2052,6 @@ var CommandLoader = class {
|
|
|
2193
2052
|
});
|
|
2194
2053
|
}
|
|
2195
2054
|
};
|
|
2196
|
-
//#endregion
|
|
2197
2055
|
export { CommandLoader };
|
|
2198
2056
|
|
|
2199
2057
|
//# sourceMappingURL=command.loader.js.map
|