@nanoforge-dev/cli 1.6.2-beta.654158d → 2.3.0
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 +436 -0
- package/README.md +4 -14
- package/dist/command.loader.d.ts +1 -3
- package/dist/command.loader.d.ts.map +1 -1
- package/dist/command.loader.js +255 -500
- package/dist/command.loader.js.map +1 -1
- package/dist/nf.js +268 -515
- package/package.json +37 -29
package/dist/nf.js
CHANGED
|
@@ -7,16 +7,18 @@ import { join, posix, resolve } from "path";
|
|
|
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
|
+
import { defaultClientConfig, defaultServerConfig, parseConfig } from "@nanoforge-dev/config";
|
|
10
11
|
import { watch } from "chokidar";
|
|
11
|
-
import { dirname, join as join$1 } from "node:path";
|
|
12
|
+
import { dirname, join as join$1, relative } from "node:path";
|
|
13
|
+
import { existsSync as existsSync$1, readFileSync, statSync } from "node:fs";
|
|
14
|
+
import { glob } from "node:fs/promises";
|
|
12
15
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
13
16
|
import { spawn as spawn$1 } from "child_process";
|
|
14
17
|
import * as process$1 from "node:process";
|
|
15
|
-
import { Expose, Type, plainToInstance } from "class-transformer";
|
|
16
|
-
import { IsBoolean, IsEnum, IsNotEmpty, IsObject, IsOptional, IsPort, IsString, Matches, ValidateNested, validate } from "class-validator";
|
|
17
|
-
import { existsSync as existsSync$1, readFileSync } from "node:fs";
|
|
18
18
|
import open from "open";
|
|
19
19
|
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";
|
|
20
22
|
import dotenv from "dotenv";
|
|
21
23
|
//#region src/lib/tree-kill/tree-kill.ts
|
|
22
24
|
const treeKill = (pid, signal) => {
|
|
@@ -38,20 +40,18 @@ const treeKill = (pid, signal) => {
|
|
|
38
40
|
resolve();
|
|
39
41
|
});
|
|
40
42
|
break;
|
|
41
|
-
default:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
break;
|
|
43
|
+
default: buildProcessTree(pid, tree, pidsToProcess, function(parentPid) {
|
|
44
|
+
return spawn("ps", [
|
|
45
|
+
"-o",
|
|
46
|
+
"pid",
|
|
47
|
+
"--no-headers",
|
|
48
|
+
"--ppid",
|
|
49
|
+
parentPid
|
|
50
|
+
]);
|
|
51
|
+
}, function() {
|
|
52
|
+
killAll(tree, signal);
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return new Promise((resolve) => {
|
|
@@ -182,10 +182,6 @@ const Messages = {
|
|
|
182
182
|
CREATE_SUCCESS: success("Element successfully created!"),
|
|
183
183
|
CREATE_FAILED: failure("Creation failed!"),
|
|
184
184
|
CREATE_NAME_QUESTION: "What is the name of your component/system?",
|
|
185
|
-
GENERATE_START: "NanoForge Generate",
|
|
186
|
-
GENERATE_SUCCESS: success("Generation succeeded!"),
|
|
187
|
-
GENERATE_FAILED: failure("Generation failed!"),
|
|
188
|
-
GENERATE_WATCH_START: "Watching for changes...",
|
|
189
185
|
DEV_START: "NanoForge Dev Mode",
|
|
190
186
|
DEV_SUCCESS: "Dev mode ended",
|
|
191
187
|
DEV_FAILED: failure("Dev mode failed!"),
|
|
@@ -299,6 +295,87 @@ const promptError = (err) => {
|
|
|
299
295
|
throw err;
|
|
300
296
|
};
|
|
301
297
|
//#endregion
|
|
298
|
+
//#region src/lib/config/config-loader.ts
|
|
299
|
+
const CONFIG_BASE_NAME = "nanoforge.config";
|
|
300
|
+
const CONFIG_EXTENSIONS = ["ts", "js"];
|
|
301
|
+
const getConfigPath = (directory) => {
|
|
302
|
+
for (const ext of CONFIG_EXTENSIONS) {
|
|
303
|
+
const path = join$1(directory, `${CONFIG_BASE_NAME}.${ext}`);
|
|
304
|
+
if (existsSync$1(path)) return path;
|
|
305
|
+
}
|
|
306
|
+
throw new ConfigNotFoundError(join$1(directory, `${CONFIG_BASE_NAME}.ts`));
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Looks up a `nanoforge.config.ts` file in `directory`, falling back to
|
|
310
|
+
* `nanoforge.config.js` when no `.ts` file exists. Throws a
|
|
311
|
+
* `ConfigNotFoundError` when neither is present.
|
|
312
|
+
*/
|
|
313
|
+
const loadConfig = async (directory) => {
|
|
314
|
+
const path = getConfigPath(directory);
|
|
315
|
+
return parseConfig(path);
|
|
316
|
+
};
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/lib/config/workspace-config-parser.ts
|
|
319
|
+
const resolvePackageConfig = async (packageDir) => {
|
|
320
|
+
let config;
|
|
321
|
+
try {
|
|
322
|
+
config = await loadConfig(packageDir);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (error instanceof ConfigNotFoundError) return void 0;
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
if (config.type === "workspace") throw new CLIError(`Invalid config at '${packageDir}': a workspace package cannot itself be of type 'workspace'.`, "Nest projects and libs under the root workspace instead of another workspace.");
|
|
328
|
+
return config.type === "lib" ? {
|
|
329
|
+
type: "lib",
|
|
330
|
+
config
|
|
331
|
+
} : {
|
|
332
|
+
type: "project",
|
|
333
|
+
config
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
const resolvePackagePattern = async (directory, pattern) => {
|
|
337
|
+
const projects = {};
|
|
338
|
+
for await (const relativePath of glob(pattern, { cwd: directory })) {
|
|
339
|
+
const packageDir = join$1(directory, relativePath);
|
|
340
|
+
if (!existsSync$1(packageDir) || !statSync(packageDir).isDirectory()) continue;
|
|
341
|
+
const entry = await resolvePackageConfig(packageDir);
|
|
342
|
+
if (entry) projects[relativePath] = entry;
|
|
343
|
+
}
|
|
344
|
+
if (Object.keys(projects).length === 0) console.warn(`[nanoforge] No project or lib config found for workspace package pattern '${pattern}' in '${directory}'.`);
|
|
345
|
+
return projects;
|
|
346
|
+
};
|
|
347
|
+
const parseBaseWorkspaceConfig = async (directory, config) => {
|
|
348
|
+
const patterns = config.packages ?? [];
|
|
349
|
+
const projects = {};
|
|
350
|
+
for (const pattern of patterns) Object.assign(projects, await resolvePackagePattern(directory, pattern));
|
|
351
|
+
return {
|
|
352
|
+
type: "workspace",
|
|
353
|
+
config,
|
|
354
|
+
projects
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
const parseWorkspaceConfig = async (directory) => {
|
|
358
|
+
const config = await loadConfig(directory);
|
|
359
|
+
if (config.type === "lib") throw new CLIError(`Invalid config at '${directory}': the root config cannot be of type 'lib'.`, "Use a 'workspace' or a 'client'/'server' project config at the root.");
|
|
360
|
+
if (config.type === "workspace") return parseBaseWorkspaceConfig(directory, config);
|
|
361
|
+
return {
|
|
362
|
+
type: "project",
|
|
363
|
+
config
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/lib/config/workspace-loader.ts
|
|
368
|
+
const resolveProjects = (workspace, baseDirectory) => {
|
|
369
|
+
if (workspace.type === "project") return [{
|
|
370
|
+
directory: baseDirectory,
|
|
371
|
+
config: workspace.config
|
|
372
|
+
}];
|
|
373
|
+
return Object.entries(workspace.projects).filter((entry) => entry[1].type === "project").map(([relativePath, project]) => ({
|
|
374
|
+
directory: join$1(baseDirectory, relativePath),
|
|
375
|
+
config: project.config
|
|
376
|
+
}));
|
|
377
|
+
};
|
|
378
|
+
//#endregion
|
|
302
379
|
//#region src/lib/input/base-inputs.ts
|
|
303
380
|
const getStringInput = (input, field) => {
|
|
304
381
|
const value = input.get(field)?.value;
|
|
@@ -340,11 +417,6 @@ function getDirectoryInput(inputs, withDefault = true) {
|
|
|
340
417
|
return getStringInput(inputs, "directory");
|
|
341
418
|
}
|
|
342
419
|
//#endregion
|
|
343
|
-
//#region src/lib/input/inputs/config.input.ts
|
|
344
|
-
const getConfigInput = (inputs) => {
|
|
345
|
-
return getStringInputWithDefault(inputs, "config", ".");
|
|
346
|
-
};
|
|
347
|
-
//#endregion
|
|
348
420
|
//#region src/lib/input/inputs/editor.input.ts
|
|
349
421
|
const getEditorInput = (inputs) => {
|
|
350
422
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
@@ -352,12 +424,13 @@ const getEditorInput = (inputs) => {
|
|
|
352
424
|
//#endregion
|
|
353
425
|
//#region src/lib/question/questions/confirm.question.ts
|
|
354
426
|
const askConfirm = async (question, baseOptions) => {
|
|
427
|
+
const options = {
|
|
428
|
+
default: false,
|
|
429
|
+
...baseOptions ?? {}
|
|
430
|
+
};
|
|
355
431
|
return await confirm({
|
|
356
432
|
message: question,
|
|
357
|
-
default:
|
|
358
|
-
default: false,
|
|
359
|
-
...baseOptions ?? {}
|
|
360
|
-
}.default
|
|
433
|
+
default: options.default
|
|
361
434
|
}).catch(promptError);
|
|
362
435
|
};
|
|
363
436
|
//#endregion
|
|
@@ -444,11 +517,6 @@ const getCreateTypeInput = (inputs) => {
|
|
|
444
517
|
throw new InvalidCommandArgumentError("type", "'component' or 'system'");
|
|
445
518
|
};
|
|
446
519
|
//#endregion
|
|
447
|
-
//#region src/lib/input/inputs/dev/generate.input.ts
|
|
448
|
-
const getDevGenerateInput = (inputs) => {
|
|
449
|
-
return getBooleanInputWithDefault(inputs, "generate", false);
|
|
450
|
-
};
|
|
451
|
-
//#endregion
|
|
452
520
|
//#region src/lib/input/inputs/editor/open.input.ts
|
|
453
521
|
const getEditorOpenInput = (inputs, defaultValue) => {
|
|
454
522
|
return getBooleanInputWithDefault(inputs, "open", defaultValue);
|
|
@@ -488,11 +556,6 @@ const getNewDockerOrAsk = (inputs) => {
|
|
|
488
556
|
return getInputOrAsk(getNewDockerInput(inputs), () => askConfirm(Messages.NEW_DOCKER_QUESTION, { default: true }));
|
|
489
557
|
};
|
|
490
558
|
//#endregion
|
|
491
|
-
//#region src/lib/input/inputs/new/init-functions.input.ts
|
|
492
|
-
const getNewInitFunctionsWithDefault = (inputs) => {
|
|
493
|
-
return getBooleanInputWithDefault(inputs, "initFunctions", false);
|
|
494
|
-
};
|
|
495
|
-
//#endregion
|
|
496
559
|
//#region src/lib/input/inputs/new/language.input.ts
|
|
497
560
|
const getLanguageInput = (inputs) => {
|
|
498
561
|
return getStringInput(inputs, "language");
|
|
@@ -961,253 +1024,6 @@ const runSafe = async (fn, fallback) => {
|
|
|
961
1024
|
}
|
|
962
1025
|
};
|
|
963
1026
|
//#endregion
|
|
964
|
-
//#region \0@oxc-project+runtime@0.138.0/helpers/esm/decorate.js
|
|
965
|
-
function __decorate(decorators, target, key, desc) {
|
|
966
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
967
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
968
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
969
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
970
|
-
}
|
|
971
|
-
//#endregion
|
|
972
|
-
//#region src/lib/config/config.type.ts
|
|
973
|
-
var BuildConfig = class {
|
|
974
|
-
entry;
|
|
975
|
-
staticDir;
|
|
976
|
-
};
|
|
977
|
-
__decorate([
|
|
978
|
-
Expose(),
|
|
979
|
-
IsString(),
|
|
980
|
-
IsNotEmpty()
|
|
981
|
-
], BuildConfig.prototype, "entry", void 0);
|
|
982
|
-
__decorate([
|
|
983
|
-
Expose(),
|
|
984
|
-
IsString(),
|
|
985
|
-
IsNotEmpty()
|
|
986
|
-
], BuildConfig.prototype, "staticDir", void 0);
|
|
987
|
-
var EditorConfig = class {
|
|
988
|
-
entry;
|
|
989
|
-
save;
|
|
990
|
-
};
|
|
991
|
-
__decorate([
|
|
992
|
-
Expose(),
|
|
993
|
-
IsString(),
|
|
994
|
-
IsNotEmpty()
|
|
995
|
-
], EditorConfig.prototype, "entry", void 0);
|
|
996
|
-
__decorate([
|
|
997
|
-
Expose(),
|
|
998
|
-
IsString(),
|
|
999
|
-
IsNotEmpty()
|
|
1000
|
-
], EditorConfig.prototype, "save", void 0);
|
|
1001
|
-
var DirsConfig = class {
|
|
1002
|
-
components;
|
|
1003
|
-
systems;
|
|
1004
|
-
};
|
|
1005
|
-
__decorate([
|
|
1006
|
-
Expose(),
|
|
1007
|
-
IsString(),
|
|
1008
|
-
IsNotEmpty()
|
|
1009
|
-
], DirsConfig.prototype, "components", void 0);
|
|
1010
|
-
__decorate([
|
|
1011
|
-
Expose(),
|
|
1012
|
-
IsString(),
|
|
1013
|
-
IsNotEmpty()
|
|
1014
|
-
], DirsConfig.prototype, "systems", void 0);
|
|
1015
|
-
var ClientConfig = class {
|
|
1016
|
-
enable;
|
|
1017
|
-
port;
|
|
1018
|
-
outDir;
|
|
1019
|
-
build;
|
|
1020
|
-
editor;
|
|
1021
|
-
dirs;
|
|
1022
|
-
};
|
|
1023
|
-
__decorate([Expose(), IsBoolean()], ClientConfig.prototype, "enable", void 0);
|
|
1024
|
-
__decorate([Expose(), IsPort()], ClientConfig.prototype, "port", void 0);
|
|
1025
|
-
__decorate([
|
|
1026
|
-
Expose(),
|
|
1027
|
-
IsString(),
|
|
1028
|
-
IsNotEmpty()
|
|
1029
|
-
], ClientConfig.prototype, "outDir", void 0);
|
|
1030
|
-
__decorate([
|
|
1031
|
-
Expose(),
|
|
1032
|
-
Type(() => BuildConfig),
|
|
1033
|
-
ValidateNested()
|
|
1034
|
-
], ClientConfig.prototype, "build", void 0);
|
|
1035
|
-
__decorate([
|
|
1036
|
-
Expose(),
|
|
1037
|
-
Type(() => EditorConfig),
|
|
1038
|
-
ValidateNested()
|
|
1039
|
-
], ClientConfig.prototype, "editor", void 0);
|
|
1040
|
-
__decorate([
|
|
1041
|
-
Expose(),
|
|
1042
|
-
Type(() => DirsConfig),
|
|
1043
|
-
ValidateNested()
|
|
1044
|
-
], ClientConfig.prototype, "dirs", void 0);
|
|
1045
|
-
var ServerConfig = class {
|
|
1046
|
-
enable;
|
|
1047
|
-
outDir;
|
|
1048
|
-
build;
|
|
1049
|
-
editor;
|
|
1050
|
-
dirs;
|
|
1051
|
-
};
|
|
1052
|
-
__decorate([Expose(), IsBoolean()], ServerConfig.prototype, "enable", void 0);
|
|
1053
|
-
__decorate([
|
|
1054
|
-
Expose(),
|
|
1055
|
-
IsString(),
|
|
1056
|
-
IsNotEmpty()
|
|
1057
|
-
], ServerConfig.prototype, "outDir", void 0);
|
|
1058
|
-
__decorate([
|
|
1059
|
-
Expose(),
|
|
1060
|
-
Type(() => BuildConfig),
|
|
1061
|
-
ValidateNested()
|
|
1062
|
-
], ServerConfig.prototype, "build", void 0);
|
|
1063
|
-
__decorate([
|
|
1064
|
-
Expose(),
|
|
1065
|
-
Type(() => EditorConfig),
|
|
1066
|
-
ValidateNested()
|
|
1067
|
-
], ServerConfig.prototype, "editor", void 0);
|
|
1068
|
-
__decorate([
|
|
1069
|
-
Expose(),
|
|
1070
|
-
Type(() => DirsConfig),
|
|
1071
|
-
ValidateNested()
|
|
1072
|
-
], ServerConfig.prototype, "dirs", void 0);
|
|
1073
|
-
var SslConfig = class {
|
|
1074
|
-
enable;
|
|
1075
|
-
cert;
|
|
1076
|
-
key;
|
|
1077
|
-
};
|
|
1078
|
-
__decorate([Expose(), IsBoolean()], SslConfig.prototype, "enable", void 0);
|
|
1079
|
-
__decorate([Expose(), IsString()], SslConfig.prototype, "cert", void 0);
|
|
1080
|
-
__decorate([Expose(), IsString()], SslConfig.prototype, "key", void 0);
|
|
1081
|
-
var Config = class {
|
|
1082
|
-
name;
|
|
1083
|
-
language;
|
|
1084
|
-
initFunctions;
|
|
1085
|
-
client;
|
|
1086
|
-
server;
|
|
1087
|
-
ssl;
|
|
1088
|
-
};
|
|
1089
|
-
__decorate([
|
|
1090
|
-
Expose(),
|
|
1091
|
-
IsString(),
|
|
1092
|
-
IsNotEmpty()
|
|
1093
|
-
], Config.prototype, "name", void 0);
|
|
1094
|
-
__decorate([Expose(), IsEnum(["ts", "js"])], Config.prototype, "language", void 0);
|
|
1095
|
-
__decorate([Expose(), IsBoolean()], Config.prototype, "initFunctions", void 0);
|
|
1096
|
-
__decorate([
|
|
1097
|
-
Expose(),
|
|
1098
|
-
Type(() => ClientConfig),
|
|
1099
|
-
ValidateNested()
|
|
1100
|
-
], Config.prototype, "client", void 0);
|
|
1101
|
-
__decorate([
|
|
1102
|
-
Expose(),
|
|
1103
|
-
Type(() => ServerConfig),
|
|
1104
|
-
ValidateNested()
|
|
1105
|
-
], Config.prototype, "server", void 0);
|
|
1106
|
-
__decorate([
|
|
1107
|
-
Expose(),
|
|
1108
|
-
Type(() => SslConfig),
|
|
1109
|
-
ValidateNested()
|
|
1110
|
-
], Config.prototype, "ssl", void 0);
|
|
1111
|
-
//#endregion
|
|
1112
|
-
//#region src/lib/constants.ts
|
|
1113
|
-
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1114
|
-
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1115
|
-
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1116
|
-
//#endregion
|
|
1117
|
-
//#region src/lib/utils/object.ts
|
|
1118
|
-
const isObject = (item) => {
|
|
1119
|
-
return item && typeof item === "object" && !Array.isArray(item);
|
|
1120
|
-
};
|
|
1121
|
-
const deepMerge = (target, ...sources) => {
|
|
1122
|
-
if (!sources.length) return target;
|
|
1123
|
-
const source = sources.shift();
|
|
1124
|
-
if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
|
|
1125
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
1126
|
-
deepMerge(target[key], source[key]);
|
|
1127
|
-
} else Object.assign(target, { [key]: source[key] });
|
|
1128
|
-
return deepMerge(target, ...sources);
|
|
1129
|
-
};
|
|
1130
|
-
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1131
|
-
//#endregion
|
|
1132
|
-
//#region src/lib/config/config-defaults.ts
|
|
1133
|
-
const CONFIG_DEFAULTS = {
|
|
1134
|
-
name: "nanoforge-app",
|
|
1135
|
-
language: "ts",
|
|
1136
|
-
initFunctions: true,
|
|
1137
|
-
ssl: {
|
|
1138
|
-
enable: false,
|
|
1139
|
-
cert: "",
|
|
1140
|
-
key: ""
|
|
1141
|
-
},
|
|
1142
|
-
client: {
|
|
1143
|
-
enable: true,
|
|
1144
|
-
port: "3000",
|
|
1145
|
-
outDir: ".nanoforge/client",
|
|
1146
|
-
build: {
|
|
1147
|
-
entry: "client/main.ts",
|
|
1148
|
-
staticDir: "client/static"
|
|
1149
|
-
},
|
|
1150
|
-
editor: {
|
|
1151
|
-
entry: ".nanoforge/editor/client/main.ts",
|
|
1152
|
-
save: ".nanoforge/client.save.json"
|
|
1153
|
-
},
|
|
1154
|
-
dirs: {
|
|
1155
|
-
components: "client/components",
|
|
1156
|
-
systems: "client/systems"
|
|
1157
|
-
}
|
|
1158
|
-
},
|
|
1159
|
-
server: {
|
|
1160
|
-
enable: false,
|
|
1161
|
-
outDir: ".nanoforge/server",
|
|
1162
|
-
build: {
|
|
1163
|
-
entry: "server/main.ts",
|
|
1164
|
-
staticDir: "server/static"
|
|
1165
|
-
},
|
|
1166
|
-
editor: {
|
|
1167
|
-
entry: ".nanoforge/editor/server/main.ts",
|
|
1168
|
-
save: ".nanoforge/server.save.json"
|
|
1169
|
-
},
|
|
1170
|
-
dirs: {
|
|
1171
|
-
components: "server/components",
|
|
1172
|
-
systems: "server/systems"
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
//#endregion
|
|
1177
|
-
//#region src/lib/config/config-loader.ts
|
|
1178
|
-
let config;
|
|
1179
|
-
const getConfigPath = (directory, name) => {
|
|
1180
|
-
if (name) return join$1(directory, name);
|
|
1181
|
-
else {
|
|
1182
|
-
for (const n of [CONFIG_FILE_NAME]) {
|
|
1183
|
-
const path = join$1(directory, n);
|
|
1184
|
-
if (existsSync$1(path)) return path;
|
|
1185
|
-
}
|
|
1186
|
-
throw new ConfigNotFoundError(join$1(directory, CONFIG_FILE_NAME));
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
const loadConfig = async (directory, name, noThrow = false) => {
|
|
1190
|
-
if (config) return config;
|
|
1191
|
-
let rawData;
|
|
1192
|
-
const path = getConfigPath(directory, name);
|
|
1193
|
-
try {
|
|
1194
|
-
rawData = deepMerge(CONFIG_DEFAULTS, JSON.parse(readFileSync(path, "utf-8")));
|
|
1195
|
-
} catch {
|
|
1196
|
-
rawData = noThrow ? CONFIG_DEFAULTS : null;
|
|
1197
|
-
}
|
|
1198
|
-
if (!rawData) throw new FileSystemError("read config file", path);
|
|
1199
|
-
const data = plainToInstance(Config, rawData, { excludeExtraneousValues: true });
|
|
1200
|
-
const errors = await validate(data);
|
|
1201
|
-
if (errors.length > 0) throw new CLIError(`Invalid config:\n${errors.toString().replace(/,/g, "\n")}`);
|
|
1202
|
-
config = data;
|
|
1203
|
-
return config;
|
|
1204
|
-
};
|
|
1205
|
-
//#endregion
|
|
1206
|
-
//#region src/action/common/config.ts
|
|
1207
|
-
const getConfig = (inputs, dir, noThrow) => {
|
|
1208
|
-
return loadConfig(dir, getConfigInput(inputs), noThrow);
|
|
1209
|
-
};
|
|
1210
|
-
//#endregion
|
|
1211
1027
|
//#region src/action/abstract.action.ts
|
|
1212
1028
|
var AbstractAction = class {
|
|
1213
1029
|
async run(args, options, extraFlags) {
|
|
@@ -1244,54 +1060,60 @@ var BuildAction = class extends AbstractAction {
|
|
|
1244
1060
|
failureMessage = Messages.BUILD_FAILED;
|
|
1245
1061
|
async handle(_args, options) {
|
|
1246
1062
|
const directory = getDirectoryInput(options);
|
|
1247
|
-
const
|
|
1063
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1248
1064
|
const isEditor = getEditorInput(options);
|
|
1249
1065
|
const isWatch = getWatchInput(options);
|
|
1250
|
-
const targets = this.resolveTargets(
|
|
1251
|
-
const results = await this.buildAll(targets,
|
|
1066
|
+
const targets = this.resolveTargets(workspaceConfig, directory, options, isEditor);
|
|
1067
|
+
const results = await this.buildAll(targets, isWatch);
|
|
1252
1068
|
if (isWatch) return this.enterWatchMode();
|
|
1253
1069
|
return { success: results.every(Boolean) };
|
|
1254
1070
|
}
|
|
1255
|
-
resolveTargets(
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1071
|
+
resolveTargets(workspaceConfig, baseDirectory, options, isEditor) {
|
|
1072
|
+
const projects = resolveProjects(workspaceConfig, baseDirectory);
|
|
1073
|
+
return projects.map((project) => this.createTarget(project, baseDirectory, options, isEditor, projects.length > 1));
|
|
1074
|
+
}
|
|
1075
|
+
createTarget(project, baseDirectory, options, isEditor, disambiguate) {
|
|
1076
|
+
const isClient = project.config.type === "client";
|
|
1077
|
+
const label = isClient ? "Client" : "Server";
|
|
1078
|
+
const relativePath = relative(baseDirectory, project.directory);
|
|
1079
|
+
const name = disambiguate && relativePath !== "" ? `${label} (${relativePath})` : label;
|
|
1080
|
+
const defaults = isClient ? defaultClientConfig : defaultServerConfig;
|
|
1081
|
+
const defaultEntry = isEditor ? project.config.editor?.entryFile ?? defaults.editor.entryFile : project.config.entryFile ?? defaults.entryFile;
|
|
1262
1082
|
return {
|
|
1263
1083
|
name,
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1084
|
+
directory: project.directory,
|
|
1085
|
+
entry: getStringInputWithDefault(options, isClient ? "clientEntry" : "serverEntry", defaultEntry),
|
|
1086
|
+
static: getStringInputWithDefault(options, isClient ? "clientStaticDir" : "serverStaticDir", project.config.dir?.assets ?? defaults.dir.assets),
|
|
1087
|
+
output: getStringInputWithDefault(options, isClient ? "clientOutDir" : "serverOutDir", project.config.out?.dir ?? defaults.out.dir),
|
|
1088
|
+
platform: isClient ? "browser" : "node"
|
|
1268
1089
|
};
|
|
1269
1090
|
}
|
|
1270
|
-
async buildAll(targets,
|
|
1091
|
+
async buildAll(targets, isWatch) {
|
|
1271
1092
|
const results = [];
|
|
1272
1093
|
for (const target of targets) {
|
|
1273
|
-
const result = await this.buildTarget(target,
|
|
1094
|
+
const result = await this.buildTarget(target, isWatch);
|
|
1274
1095
|
results.push(result);
|
|
1275
1096
|
}
|
|
1276
1097
|
return results;
|
|
1277
1098
|
}
|
|
1278
|
-
async buildTarget(target,
|
|
1099
|
+
async buildTarget(target, isWatch) {
|
|
1279
1100
|
const packageManager = PackageManagerFactory.create("local_bun");
|
|
1280
1101
|
const executeBuild = (rebuild = false) => runSafe(() => {
|
|
1281
|
-
this.resetOut(target.output, directory);
|
|
1282
|
-
this.copyFiles(target, directory);
|
|
1283
|
-
return packageManager.build(target.name, directory, target.entry, target.output, [
|
|
1102
|
+
this.resetOut(target.output, target.directory);
|
|
1103
|
+
this.copyFiles(target, target.directory);
|
|
1104
|
+
return packageManager.build(target.name, target.directory, target.entry, target.output, [
|
|
1284
1105
|
"--asset-naming",
|
|
1285
1106
|
"[name].[ext]",
|
|
1286
1107
|
"--target",
|
|
1287
1108
|
target.platform
|
|
1288
1109
|
], rebuild);
|
|
1289
1110
|
}, false);
|
|
1290
|
-
if (isWatch) this.watchDirectory(directory, target.entry, () => executeBuild(true));
|
|
1111
|
+
if (isWatch) this.watchDirectory(target.directory, target.entry, () => executeBuild(true));
|
|
1291
1112
|
return await executeBuild() !== false;
|
|
1292
1113
|
}
|
|
1293
1114
|
watchDirectory(directory, entry, onChange) {
|
|
1294
|
-
|
|
1115
|
+
const watchPath = dirname(join$1(getCwd(directory), entry));
|
|
1116
|
+
watch(watchPath).on("change", onChange);
|
|
1295
1117
|
}
|
|
1296
1118
|
enterWatchMode() {
|
|
1297
1119
|
console.info();
|
|
@@ -1303,6 +1125,7 @@ var BuildAction = class extends AbstractAction {
|
|
|
1303
1125
|
resetFolder(getCwd(join$1(directory, outDir)));
|
|
1304
1126
|
}
|
|
1305
1127
|
copyFiles(target, directory) {
|
|
1128
|
+
if (!target.static) return;
|
|
1306
1129
|
const from = getCwd(join$1(directory, target.static));
|
|
1307
1130
|
const to = getCwd(join$1(directory, target.output));
|
|
1308
1131
|
copyFiles(from, to);
|
|
@@ -1347,29 +1170,14 @@ var AbstractCollection = class {
|
|
|
1347
1170
|
var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
1348
1171
|
static schematics = [
|
|
1349
1172
|
{
|
|
1350
|
-
name: "
|
|
1351
|
-
alias: "
|
|
1352
|
-
description: "Generate a new
|
|
1353
|
-
},
|
|
1354
|
-
{
|
|
1355
|
-
name: "configuration",
|
|
1356
|
-
alias: "config",
|
|
1357
|
-
description: "Generate a CLI configuration file"
|
|
1358
|
-
},
|
|
1359
|
-
{
|
|
1360
|
-
name: "part-base",
|
|
1361
|
-
alias: "base",
|
|
1362
|
-
description: "Generate a NanoForge Part Base"
|
|
1173
|
+
name: "project",
|
|
1174
|
+
alias: "project",
|
|
1175
|
+
description: "Generate a new project"
|
|
1363
1176
|
},
|
|
1364
1177
|
{
|
|
1365
|
-
name: "
|
|
1366
|
-
alias: "
|
|
1367
|
-
description: "Generate a
|
|
1368
|
-
},
|
|
1369
|
-
{
|
|
1370
|
-
name: "docker",
|
|
1371
|
-
alias: "docker",
|
|
1372
|
-
description: "Generate a Dockerfile for the application"
|
|
1178
|
+
name: "workspace",
|
|
1179
|
+
alias: "workspace",
|
|
1180
|
+
description: "Generate a new workspace"
|
|
1373
1181
|
},
|
|
1374
1182
|
{
|
|
1375
1183
|
name: "component",
|
|
@@ -1427,10 +1235,11 @@ var SchematicOption = class {
|
|
|
1427
1235
|
}
|
|
1428
1236
|
toCommandString(prefix) {
|
|
1429
1237
|
const normalizedName = `${prefix ? `${prefix}.` : ""}${this.normalizedName}`;
|
|
1430
|
-
if (typeof this.value === "string")
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1238
|
+
if (typeof this.value === "string") {
|
|
1239
|
+
if (this.name === "name") return [`--${normalizedName}=${this.format()}`];
|
|
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") {
|
|
1434
1243
|
const str = normalizedName;
|
|
1435
1244
|
return this.value ? [`--${str}=true`] : [`--${str}=false`];
|
|
1436
1245
|
} else if (Array.isArray(this.value)) return this.value.reduce((old, option) => [...old, ...option.toCommandString(normalizedName)], []);
|
|
@@ -1472,16 +1281,18 @@ var CreateAction = class extends AbstractAction {
|
|
|
1472
1281
|
failureMessage = Messages.CREATE_FAILED;
|
|
1473
1282
|
async handle(args, options) {
|
|
1474
1283
|
const directory = getDirectoryInput(options);
|
|
1475
|
-
const
|
|
1284
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1285
|
+
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
|
+
const { config } = workspaceConfig;
|
|
1287
|
+
const defaults = config.type === "client" ? defaultClientConfig : defaultServerConfig;
|
|
1476
1288
|
const type = getCreateTypeInput(args);
|
|
1477
1289
|
const name = await getCreateNameInputOrAsk(options);
|
|
1478
|
-
const
|
|
1479
|
-
const path = getPathInputWithDefault(options, config[isServer ? "server" : "client"].dirs[type === "component" ? "components" : "systems"]);
|
|
1290
|
+
const path = getPathInputWithDefault(options, config.dir?.[type === "component" ? "components" : "systems"] ?? defaults.dir[type === "component" ? "components" : "systems"]);
|
|
1480
1291
|
await this.generateElement(directory, type, {
|
|
1481
1292
|
name,
|
|
1482
1293
|
directory: path,
|
|
1483
|
-
part:
|
|
1484
|
-
language: config.language
|
|
1294
|
+
part: config.type,
|
|
1295
|
+
language: config.language ?? defaults.language
|
|
1485
1296
|
});
|
|
1486
1297
|
return {};
|
|
1487
1298
|
}
|
|
@@ -1498,19 +1309,14 @@ var DevAction = class extends AbstractAction {
|
|
|
1498
1309
|
failureMessage = Messages.DEV_FAILED;
|
|
1499
1310
|
async handle(_args, options) {
|
|
1500
1311
|
const directory = getDirectoryInput(options);
|
|
1501
|
-
const generate = getDevGenerateInput(options);
|
|
1502
1312
|
const editor = getEditorInput(options);
|
|
1503
|
-
const tasks = this.buildTaskList(directory,
|
|
1313
|
+
const tasks = this.buildTaskList(directory, editor);
|
|
1504
1314
|
await Promise.all(tasks);
|
|
1505
1315
|
return { keepAlive: true };
|
|
1506
1316
|
}
|
|
1507
|
-
buildTaskList(directory,
|
|
1317
|
+
buildTaskList(directory, editor) {
|
|
1508
1318
|
const tasks = [];
|
|
1509
1319
|
const extraFlags = editor ? ["--editor"] : [];
|
|
1510
|
-
if (generate) tasks.push(this.runSubCommand("generate", directory, {
|
|
1511
|
-
silent: true,
|
|
1512
|
-
extraFlags
|
|
1513
|
-
}));
|
|
1514
1320
|
tasks.push(this.runSubCommand("build", directory, {
|
|
1515
1321
|
silent: true,
|
|
1516
1322
|
extraFlags
|
|
@@ -1557,55 +1363,25 @@ var EditorAction = class extends AbstractAction {
|
|
|
1557
1363
|
}
|
|
1558
1364
|
};
|
|
1559
1365
|
//#endregion
|
|
1560
|
-
//#region src/
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
language: config.language,
|
|
1578
|
-
initFunctions: config.initFunctions
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
async generateParts(config, directory, isEditor, watch) {
|
|
1582
|
-
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1583
|
-
const values = this.extractValues(config);
|
|
1584
|
-
if (config.client.enable) await executeSchematic("Client main file", collection, "part-main", {
|
|
1585
|
-
...values,
|
|
1586
|
-
part: "client",
|
|
1587
|
-
outFile: !isEditor ? config.client.build.entry : config.client.editor.entry,
|
|
1588
|
-
saveFile: config.client.editor.save,
|
|
1589
|
-
editor: isEditor
|
|
1590
|
-
}, watch ? this.watchPath(directory, values.directory, config.client.editor.save) : void 0);
|
|
1591
|
-
if (config.server.enable) await executeSchematic("Server main file", collection, "part-main", {
|
|
1592
|
-
...values,
|
|
1593
|
-
part: "server",
|
|
1594
|
-
outFile: !isEditor ? config.server.build.entry : config.server.editor.entry,
|
|
1595
|
-
saveFile: config.server.editor.save,
|
|
1596
|
-
editor: isEditor
|
|
1597
|
-
}, this.watchPath(directory, values.directory, config.server.editor.save));
|
|
1598
|
-
}
|
|
1599
|
-
watchPath(directory, subDir, saveFile) {
|
|
1600
|
-
return join$1(getCwd(directory), subDir, saveFile);
|
|
1601
|
-
}
|
|
1602
|
-
enterWatchMode() {
|
|
1603
|
-
console.info();
|
|
1604
|
-
console.info(Messages.GENERATE_WATCH_START);
|
|
1605
|
-
console.info();
|
|
1606
|
-
return { keepAlive: true };
|
|
1607
|
-
}
|
|
1366
|
+
//#region src/lib/constants.ts
|
|
1367
|
+
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1368
|
+
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1369
|
+
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1370
|
+
//#endregion
|
|
1371
|
+
//#region src/lib/utils/object.ts
|
|
1372
|
+
const isObject = (item) => {
|
|
1373
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
1374
|
+
};
|
|
1375
|
+
const deepMerge = (target, ...sources) => {
|
|
1376
|
+
if (!sources.length) return target;
|
|
1377
|
+
const source = sources.shift();
|
|
1378
|
+
if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
|
|
1379
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
1380
|
+
deepMerge(target[key], source[key]);
|
|
1381
|
+
} else Object.assign(target, { [key]: source[key] });
|
|
1382
|
+
return deepMerge(target, ...sources);
|
|
1608
1383
|
};
|
|
1384
|
+
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1609
1385
|
//#endregion
|
|
1610
1386
|
//#region src/lib/global-config/global-config-defaults.ts
|
|
1611
1387
|
const GLOBAL_CONFIG_DEFAULTS = {};
|
|
@@ -1991,8 +1767,7 @@ var NewAction = class extends AbstractAction {
|
|
|
1991
1767
|
packageManager: await getNewPackageManagerInputOrAsk(inputs),
|
|
1992
1768
|
language: await getNewLanguageInputOrAsk(inputs),
|
|
1993
1769
|
strict: await getNewStrictOrAsk(inputs),
|
|
1994
|
-
|
|
1995
|
-
initFunctions: getNewInitFunctionsWithDefault(inputs),
|
|
1770
|
+
multiplayer: await getNewServerOrAsk(inputs),
|
|
1996
1771
|
skipInstall: await getNewSkipInstallOrAsk(inputs),
|
|
1997
1772
|
docker: await getNewDockerOrAsk(inputs),
|
|
1998
1773
|
lint: getNewLintInput(inputs),
|
|
@@ -2010,61 +1785,43 @@ var NewAction = class extends AbstractAction {
|
|
|
2010
1785
|
console.info();
|
|
2011
1786
|
console.info(Messages.NEW_GENERATION_START);
|
|
2012
1787
|
console.info();
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
return executeSchematic("
|
|
1788
|
+
if (values.multiplayer) {
|
|
1789
|
+
await this.generateWorkspace(collection, values);
|
|
1790
|
+
await this.generateClientProject(collection, values);
|
|
1791
|
+
await this.generateServerProject(collection, values);
|
|
1792
|
+
} else await this.generateClientProject(collection, values);
|
|
1793
|
+
}
|
|
1794
|
+
generateWorkspace(collection, values) {
|
|
1795
|
+
return executeSchematic("Workspace", collection, "workspace", {
|
|
2021
1796
|
name: values.name,
|
|
2022
1797
|
directory: values.directory,
|
|
2023
|
-
packageManager: values.packageManager,
|
|
2024
1798
|
language: values.language,
|
|
2025
1799
|
strict: values.strict,
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
editor: values.editor
|
|
2029
|
-
});
|
|
2030
|
-
}
|
|
2031
|
-
generateConfiguration(collection, values) {
|
|
2032
|
-
return executeSchematic("Configuration", collection, "configuration", {
|
|
2033
|
-
name: values.name,
|
|
2034
|
-
directory: values.directory,
|
|
2035
|
-
server: values.server,
|
|
2036
|
-
language: values.language,
|
|
2037
|
-
initFunctions: values.initFunctions
|
|
1800
|
+
packageManager: values.packageManager,
|
|
1801
|
+
docker: values.docker
|
|
2038
1802
|
});
|
|
2039
1803
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
server: values.server
|
|
1804
|
+
generateClientProject(collection, values) {
|
|
1805
|
+
return executeSchematic("Client project", collection, "project", {
|
|
1806
|
+
...this.projectOptions(values, "client"),
|
|
1807
|
+
hasServer: values.multiplayer
|
|
2045
1808
|
});
|
|
2046
|
-
await executeSchematic("Client main file", collection, "part-main", { ...partOptions });
|
|
2047
1809
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
await executeSchematic("Server base", collection, "part-base", {
|
|
2051
|
-
...partOptions,
|
|
2052
|
-
server: values.server
|
|
2053
|
-
});
|
|
2054
|
-
await executeSchematic("Server main file", collection, "part-main", { ...partOptions });
|
|
1810
|
+
generateServerProject(collection, values) {
|
|
1811
|
+
return executeSchematic("Server project", collection, "project", this.projectOptions(values, "server"));
|
|
2055
1812
|
}
|
|
2056
|
-
|
|
2057
|
-
await executeSchematic("Docker", collection, "docker", {
|
|
2058
|
-
directory: values.directory,
|
|
2059
|
-
packageManager: values.packageManager
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
partOptions(values, part) {
|
|
1813
|
+
projectOptions(values, part) {
|
|
2063
1814
|
return {
|
|
2064
1815
|
part,
|
|
2065
|
-
|
|
1816
|
+
workspaceName: values.multiplayer ? values.name : void 0,
|
|
1817
|
+
name: values.multiplayer ? part : values.name,
|
|
1818
|
+
directory: values.multiplayer ? join$1(values.directory, "apps", part) : values.directory,
|
|
2066
1819
|
language: values.language,
|
|
2067
|
-
|
|
1820
|
+
strict: values.strict,
|
|
1821
|
+
packageManager: values.packageManager,
|
|
1822
|
+
workspace: values.multiplayer,
|
|
1823
|
+
docker: values.docker,
|
|
1824
|
+
editor: values.editor
|
|
2068
1825
|
};
|
|
2069
1826
|
}
|
|
2070
1827
|
async installDependencies(packageManagerName, directory) {
|
|
@@ -2079,6 +1836,14 @@ var NewAction = class extends AbstractAction {
|
|
|
2079
1836
|
}
|
|
2080
1837
|
};
|
|
2081
1838
|
//#endregion
|
|
1839
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorate.js
|
|
1840
|
+
function __decorate(decorators, target, key, desc) {
|
|
1841
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1842
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1843
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1844
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1845
|
+
}
|
|
1846
|
+
//#endregion
|
|
2082
1847
|
//#region src/lib/manifest/manifest.type.ts
|
|
2083
1848
|
let ManifestPackageTypeEnum = /* @__PURE__ */ function(ManifestPackageTypeEnum) {
|
|
2084
1849
|
ManifestPackageTypeEnum["COMPONENT"] = "component";
|
|
@@ -2197,87 +1962,96 @@ var PublishAction = class extends AbstractAction {
|
|
|
2197
1962
|
};
|
|
2198
1963
|
//#endregion
|
|
2199
1964
|
//#region src/action/actions/start.action.ts
|
|
1965
|
+
const isClientTarget = (target) => target.platform === "client";
|
|
1966
|
+
const isServerTarget = (target) => target.platform === "server";
|
|
2200
1967
|
var StartAction = class extends AbstractAction {
|
|
2201
1968
|
startMessage = Messages.START_START;
|
|
2202
1969
|
successMessage = Messages.START_SUCCESS;
|
|
2203
1970
|
failureMessage = Messages.START_FAILED;
|
|
2204
1971
|
async handle(_args, options) {
|
|
2205
1972
|
const directory = getDirectoryInput(options);
|
|
2206
|
-
const
|
|
2207
|
-
const clientDir = getStringInputWithDefault(options, "clientDir", config.client.outDir);
|
|
2208
|
-
const serverDir = getStringInputWithDefault(options, "serverDir", config.server.outDir);
|
|
1973
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
2209
1974
|
const watch = getWatchInput(options);
|
|
2210
|
-
const
|
|
2211
|
-
const
|
|
2212
|
-
const
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
ssl
|
|
2218
|
-
});
|
|
1975
|
+
const targets = this.resolveTargets(workspaceConfig, directory, options);
|
|
1976
|
+
const serverTargets = targets.filter(isServerTarget);
|
|
1977
|
+
const clientTargets = targets.filter(isClientTarget);
|
|
1978
|
+
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
|
+
const env = this.parseEnv(directory);
|
|
1980
|
+
const packageManager = await PackageManagerFactory.find(directory);
|
|
1981
|
+
const tasks = this.buildStartTasks(packageManager, serverTargets, clientTargets, watch, env);
|
|
2219
1982
|
await Promise.all(tasks);
|
|
2220
1983
|
return { keepAlive: true };
|
|
2221
1984
|
}
|
|
2222
|
-
|
|
1985
|
+
resolveTLS(options, config) {
|
|
2223
1986
|
const cliCert = getStringInput(options, "cert");
|
|
2224
1987
|
const cliKey = getStringInput(options, "key");
|
|
2225
|
-
|
|
2226
|
-
const
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
1988
|
+
const tls = config.tls;
|
|
1989
|
+
const configTls = tls && tls.enable ? tls : void 0;
|
|
1990
|
+
if (!Boolean(cliCert || cliKey || configTls)) return void 0;
|
|
1991
|
+
const cert = cliCert ?? configTls?.cert;
|
|
1992
|
+
const key = cliKey ?? configTls?.key;
|
|
1993
|
+
if (!cert) throw new CLIError("No certificate found for TLS.", "Please provide a certificate path with --cert or configure 'tls.cert' in your nanoforge.config.ts");
|
|
1994
|
+
if (!key) throw new CLIError("No key found for TLS.", "Please provide a key path with --key or configure 'tls.key' in your nanoforge.config.ts");
|
|
2230
1995
|
return {
|
|
2231
1996
|
cert,
|
|
2232
1997
|
key
|
|
2233
1998
|
};
|
|
2234
1999
|
}
|
|
2235
|
-
|
|
2236
|
-
|
|
2000
|
+
resolveTargets(workspaceConfig, baseDirectory, options) {
|
|
2001
|
+
return resolveProjects(workspaceConfig, baseDirectory).map((project) => this.createTarget(project, options));
|
|
2002
|
+
}
|
|
2003
|
+
createTarget(project, options) {
|
|
2004
|
+
if (project.config.type === "server") return {
|
|
2005
|
+
directory: project.directory,
|
|
2006
|
+
outDir: getStringInputWithDefault(options, "serverDir", project.config.out?.dir ?? defaultServerConfig.out.dir),
|
|
2007
|
+
platform: "server"
|
|
2008
|
+
};
|
|
2009
|
+
return {
|
|
2010
|
+
directory: project.directory,
|
|
2011
|
+
outDir: getStringInputWithDefault(options, "clientDir", project.config.out?.dir ?? defaultClientConfig.out.dir),
|
|
2012
|
+
platform: "client",
|
|
2013
|
+
port: getStringInputWithDefault(options, "port", project.config.port ?? defaultClientConfig.port),
|
|
2014
|
+
tls: this.resolveTLS(options, project.config)
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
buildStartTasks(packageManager, serverTargets, clientTargets, watch, env) {
|
|
2237
2018
|
const tasks = [];
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
serverDir,
|
|
2241
|
-
watch
|
|
2242
|
-
}, env));
|
|
2243
|
-
if (config.client.enable) tasks.push(this.startClient(directory, config, {
|
|
2244
|
-
clientDir,
|
|
2245
|
-
serverDir,
|
|
2019
|
+
for (const target of serverTargets) tasks.push(this.startServer(packageManager, target, watch, env));
|
|
2020
|
+
for (const target of clientTargets) tasks.push(this.startClient(packageManager, target, {
|
|
2246
2021
|
watch,
|
|
2247
|
-
|
|
2248
|
-
ssl
|
|
2022
|
+
serverTargets
|
|
2249
2023
|
}, env));
|
|
2250
2024
|
return tasks;
|
|
2251
2025
|
}
|
|
2252
|
-
async startClient(
|
|
2026
|
+
async startClient(packageManager, target, options, env) {
|
|
2253
2027
|
const loaderPath = getModulePath("@nanoforge-dev/loader-client/package.json", true);
|
|
2254
|
-
const params = this.buildClientParams(
|
|
2255
|
-
await this.runLoader("Client", loaderPath, params, env.client);
|
|
2028
|
+
const params = this.buildClientParams(target, options);
|
|
2029
|
+
await this.runLoader(packageManager, "Client", loaderPath, params, env.client);
|
|
2256
2030
|
}
|
|
2257
|
-
async startServer(
|
|
2031
|
+
async startServer(packageManager, target, watch, env) {
|
|
2258
2032
|
const loaderPath = getModulePath("@nanoforge-dev/loader-server/package.json", true);
|
|
2259
|
-
const params = this.buildServerParams(
|
|
2260
|
-
await this.runLoader("Server", loaderPath, params, env.server);
|
|
2033
|
+
const params = this.buildServerParams(target, watch);
|
|
2034
|
+
await this.runLoader(packageManager, "Server", loaderPath, params, env.server);
|
|
2261
2035
|
}
|
|
2262
|
-
buildClientParams(
|
|
2036
|
+
buildClientParams(target, options) {
|
|
2263
2037
|
const params = {
|
|
2264
|
-
"-d": getCwd(join(directory,
|
|
2265
|
-
"-p":
|
|
2038
|
+
"-d": getCwd(join(target.directory, target.outDir)),
|
|
2039
|
+
"-p": target.port
|
|
2266
2040
|
};
|
|
2267
|
-
if (options.watch) params["--watch"] = true;
|
|
2268
2041
|
if (options.watch) {
|
|
2269
2042
|
params["--watch"] = true;
|
|
2270
|
-
|
|
2043
|
+
const [server] = options.serverTargets;
|
|
2044
|
+
if (server && options.serverTargets.length === 1) params["--watch-server-dir"] = getCwd(join(server.directory, server.outDir));
|
|
2271
2045
|
}
|
|
2272
|
-
if (
|
|
2273
|
-
params["--cert"] =
|
|
2274
|
-
params["--key"] =
|
|
2046
|
+
if (target.tls) {
|
|
2047
|
+
params["--cert"] = target.tls.cert;
|
|
2048
|
+
params["--key"] = target.tls.key;
|
|
2275
2049
|
}
|
|
2276
2050
|
return this.buildParams(params);
|
|
2277
2051
|
}
|
|
2278
|
-
buildServerParams(
|
|
2279
|
-
const params = { "-d": getCwd(join(directory,
|
|
2280
|
-
if (
|
|
2052
|
+
buildServerParams(target, watch) {
|
|
2053
|
+
const params = { "-d": getCwd(join(target.directory, target.outDir)) };
|
|
2054
|
+
if (watch) params["--watch"] = true;
|
|
2281
2055
|
return this.buildParams(params);
|
|
2282
2056
|
}
|
|
2283
2057
|
buildParams(params) {
|
|
@@ -2298,9 +2072,9 @@ var StartAction = class extends AbstractAction {
|
|
|
2298
2072
|
server: Object.fromEntries(baseEnv.filter(([key]) => !key.startsWith(clientPrefix)).map(([key, value]) => [key.replace(serverPrefix, prefix), value]))
|
|
2299
2073
|
};
|
|
2300
2074
|
}
|
|
2301
|
-
async runLoader(name, directory, params, env) {
|
|
2075
|
+
async runLoader(packageManager, name, directory, params, env) {
|
|
2302
2076
|
await runSafe(async () => {
|
|
2303
|
-
await
|
|
2077
|
+
await packageManager.run(name, directory, "start", params, env, [], true);
|
|
2304
2078
|
});
|
|
2305
2079
|
}
|
|
2306
2080
|
};
|
|
@@ -2333,10 +2107,9 @@ var AbstractCommand = class {
|
|
|
2333
2107
|
//#region src/command/commands/build.command.ts
|
|
2334
2108
|
var BuildCommand = class extends AbstractCommand {
|
|
2335
2109
|
load(program) {
|
|
2336
|
-
program.command("build").description("build your game").option("-d, --directory <directory>", "specify the working directory of the command").option("
|
|
2110
|
+
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) => {
|
|
2337
2111
|
const options = AbstractCommand.mapToInput({
|
|
2338
2112
|
directory: rawOptions.directory,
|
|
2339
|
-
config: rawOptions.config,
|
|
2340
2113
|
clientEntry: rawOptions.clientEntry,
|
|
2341
2114
|
serverEntry: rawOptions.serverEntry,
|
|
2342
2115
|
clientStaticDir: rawOptions.clientStaticDir,
|
|
@@ -2354,13 +2127,11 @@ var BuildCommand = class extends AbstractCommand {
|
|
|
2354
2127
|
//#region src/command/commands/create.command.ts
|
|
2355
2128
|
var CreateCommand = class extends AbstractCommand {
|
|
2356
2129
|
load(program) {
|
|
2357
|
-
program.command("create <type>").description("create nanoforge components or systems").option("-d, --directory <directory>", "specify the working directory of the command").option("-
|
|
2130
|
+
program.command("create <type>").description("create nanoforge components or systems").option("-d, --directory <directory>", "specify the working directory of the command").option("-n, --name <name>", "name of the component/system").option("-p, --path <path>", "path to the component/system folder (default: <part>/<components|systems>)").action(async (type, rawOptions) => {
|
|
2358
2131
|
const args = AbstractCommand.mapToInput({ type });
|
|
2359
2132
|
const options = AbstractCommand.mapToInput({
|
|
2360
2133
|
directory: rawOptions.directory,
|
|
2361
|
-
config: rawOptions.config,
|
|
2362
2134
|
name: rawOptions.name,
|
|
2363
|
-
server: rawOptions.server,
|
|
2364
2135
|
path: rawOptions.path
|
|
2365
2136
|
});
|
|
2366
2137
|
await this.action.run(args, options);
|
|
@@ -2371,11 +2142,10 @@ var CreateCommand = class extends AbstractCommand {
|
|
|
2371
2142
|
//#region src/command/commands/dev.command.ts
|
|
2372
2143
|
var DevCommand = class extends AbstractCommand {
|
|
2373
2144
|
load(program) {
|
|
2374
|
-
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("
|
|
2145
|
+
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) => {
|
|
2375
2146
|
const options = AbstractCommand.mapToInput({
|
|
2376
2147
|
directory: rawOptions.directory,
|
|
2377
2148
|
config: rawOptions.config,
|
|
2378
|
-
generate: rawOptions.generate,
|
|
2379
2149
|
editor: rawOptions.editor
|
|
2380
2150
|
});
|
|
2381
2151
|
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
@@ -2397,21 +2167,6 @@ var EditorCommand = class extends AbstractCommand {
|
|
|
2397
2167
|
}
|
|
2398
2168
|
};
|
|
2399
2169
|
//#endregion
|
|
2400
|
-
//#region src/command/commands/generate.command.ts
|
|
2401
|
-
var GenerateCommand = class extends AbstractCommand {
|
|
2402
|
-
load(program) {
|
|
2403
|
-
program.command("generate").description("generate nanoforge files from config").option("-d, --directory <directory>", "specify the working directory of the command").option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME).option("--editor", "specify if the project must generate editor main file").option("--watch", "generate app in watching mode", false).action(async (rawOptions) => {
|
|
2404
|
-
const options = AbstractCommand.mapToInput({
|
|
2405
|
-
directory: rawOptions.directory,
|
|
2406
|
-
config: rawOptions.config,
|
|
2407
|
-
editor: rawOptions.editor,
|
|
2408
|
-
watch: rawOptions.watch
|
|
2409
|
-
});
|
|
2410
|
-
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
2411
|
-
});
|
|
2412
|
-
}
|
|
2413
|
-
};
|
|
2414
|
-
//#endregion
|
|
2415
2170
|
//#region src/command/commands/install.command.ts
|
|
2416
2171
|
var InstallCommand = class extends AbstractCommand {
|
|
2417
2172
|
load(program) {
|
|
@@ -2493,10 +2248,9 @@ var PublishCommand = class extends AbstractCommand {
|
|
|
2493
2248
|
//#region src/command/commands/start.command.ts
|
|
2494
2249
|
var StartCommand = class extends AbstractCommand {
|
|
2495
2250
|
load(program) {
|
|
2496
|
-
program.command("start").description("start your game").option("-d, --directory <directory>", "specify the working directory of the command").option("-
|
|
2251
|
+
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) => {
|
|
2497
2252
|
const options = AbstractCommand.mapToInput({
|
|
2498
2253
|
directory: rawOptions.directory,
|
|
2499
|
-
config: rawOptions.config,
|
|
2500
2254
|
port: rawOptions.port,
|
|
2501
2255
|
clientDir: rawOptions.clientDir,
|
|
2502
2256
|
serverDir: rawOptions.serverDir,
|
|
@@ -2528,7 +2282,6 @@ var CommandLoader = class {
|
|
|
2528
2282
|
new StartCommand(new StartAction()).load(program);
|
|
2529
2283
|
new DevCommand(new DevAction()).load(program);
|
|
2530
2284
|
new EditorCommand(new EditorAction()).load(program);
|
|
2531
|
-
new GenerateCommand(new GenerateAction()).load(program);
|
|
2532
2285
|
new CreateCommand(new CreateAction()).load(program);
|
|
2533
2286
|
new LoginCommand(new LoginAction()).load(program);
|
|
2534
2287
|
new LogoutCommand(new LogoutAction()).load(program);
|
|
@@ -2546,7 +2299,7 @@ var CommandLoader = class {
|
|
|
2546
2299
|
};
|
|
2547
2300
|
//#endregion
|
|
2548
2301
|
//#region package.json
|
|
2549
|
-
var version = "
|
|
2302
|
+
var version = "2.3.0";
|
|
2550
2303
|
//#endregion
|
|
2551
2304
|
//#region src/bin/nf.ts
|
|
2552
2305
|
const bootstrap = async () => {
|