@nanoforge-dev/cli 1.6.2 → 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/command.loader.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { bgRgb, bold, cyan, green, red, yellow } from "ansis";
|
|
2
2
|
import { get } from "node-emoji";
|
|
3
3
|
import ora from "ora";
|
|
4
|
+
import { defaultClientConfig, defaultServerConfig, parseConfig } from "@nanoforge-dev/config";
|
|
4
5
|
import { watch } from "chokidar";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
+
import { dirname, join, relative } from "node:path";
|
|
7
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
8
|
+
import { glob } from "node:fs/promises";
|
|
6
9
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
7
10
|
import fs from "fs";
|
|
8
11
|
import { join as join$1, resolve } from "path";
|
|
9
12
|
import { spawn } from "child_process";
|
|
10
13
|
import * as process$1 from "node:process";
|
|
11
|
-
import { Expose, Type, plainToInstance } from "class-transformer";
|
|
12
|
-
import { IsBoolean, IsEnum, IsNotEmpty, IsObject, IsOptional, IsPort, IsString, Matches, ValidateNested, validate } from "class-validator";
|
|
13
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
14
14
|
import open from "open";
|
|
15
15
|
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";
|
|
16
18
|
import dotenv from "dotenv";
|
|
17
19
|
//#region src/lib/ui/emojis.ts
|
|
18
20
|
const Emojis = {
|
|
@@ -76,10 +78,6 @@ const Messages = {
|
|
|
76
78
|
CREATE_SUCCESS: success("Element successfully created!"),
|
|
77
79
|
CREATE_FAILED: failure("Creation failed!"),
|
|
78
80
|
CREATE_NAME_QUESTION: "What is the name of your component/system?",
|
|
79
|
-
GENERATE_START: "NanoForge Generate",
|
|
80
|
-
GENERATE_SUCCESS: success("Generation succeeded!"),
|
|
81
|
-
GENERATE_FAILED: failure("Generation failed!"),
|
|
82
|
-
GENERATE_WATCH_START: "Watching for changes...",
|
|
83
81
|
DEV_START: "NanoForge Dev Mode",
|
|
84
82
|
DEV_SUCCESS: "Dev mode ended",
|
|
85
83
|
DEV_FAILED: failure("Dev mode failed!"),
|
|
@@ -193,6 +191,87 @@ const promptError = (err) => {
|
|
|
193
191
|
throw err;
|
|
194
192
|
};
|
|
195
193
|
//#endregion
|
|
194
|
+
//#region src/lib/config/config-loader.ts
|
|
195
|
+
const CONFIG_BASE_NAME = "nanoforge.config";
|
|
196
|
+
const CONFIG_EXTENSIONS = ["ts", "js"];
|
|
197
|
+
const getConfigPath = (directory) => {
|
|
198
|
+
for (const ext of CONFIG_EXTENSIONS) {
|
|
199
|
+
const path = join(directory, `${CONFIG_BASE_NAME}.${ext}`);
|
|
200
|
+
if (existsSync(path)) return path;
|
|
201
|
+
}
|
|
202
|
+
throw new ConfigNotFoundError(join(directory, `${CONFIG_BASE_NAME}.ts`));
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Looks up a `nanoforge.config.ts` file in `directory`, falling back to
|
|
206
|
+
* `nanoforge.config.js` when no `.ts` file exists. Throws a
|
|
207
|
+
* `ConfigNotFoundError` when neither is present.
|
|
208
|
+
*/
|
|
209
|
+
const loadConfig = async (directory) => {
|
|
210
|
+
const path = getConfigPath(directory);
|
|
211
|
+
return parseConfig(path);
|
|
212
|
+
};
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/lib/config/workspace-config-parser.ts
|
|
215
|
+
const resolvePackageConfig = async (packageDir) => {
|
|
216
|
+
let config;
|
|
217
|
+
try {
|
|
218
|
+
config = await loadConfig(packageDir);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
if (error instanceof ConfigNotFoundError) return void 0;
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
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.");
|
|
224
|
+
return config.type === "lib" ? {
|
|
225
|
+
type: "lib",
|
|
226
|
+
config
|
|
227
|
+
} : {
|
|
228
|
+
type: "project",
|
|
229
|
+
config
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
const resolvePackagePattern = async (directory, pattern) => {
|
|
233
|
+
const projects = {};
|
|
234
|
+
for await (const relativePath of glob(pattern, { cwd: directory })) {
|
|
235
|
+
const packageDir = join(directory, relativePath);
|
|
236
|
+
if (!existsSync(packageDir) || !statSync(packageDir).isDirectory()) continue;
|
|
237
|
+
const entry = await resolvePackageConfig(packageDir);
|
|
238
|
+
if (entry) projects[relativePath] = entry;
|
|
239
|
+
}
|
|
240
|
+
if (Object.keys(projects).length === 0) console.warn(`[nanoforge] No project or lib config found for workspace package pattern '${pattern}' in '${directory}'.`);
|
|
241
|
+
return projects;
|
|
242
|
+
};
|
|
243
|
+
const parseBaseWorkspaceConfig = async (directory, config) => {
|
|
244
|
+
const patterns = config.packages ?? [];
|
|
245
|
+
const projects = {};
|
|
246
|
+
for (const pattern of patterns) Object.assign(projects, await resolvePackagePattern(directory, pattern));
|
|
247
|
+
return {
|
|
248
|
+
type: "workspace",
|
|
249
|
+
config,
|
|
250
|
+
projects
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const parseWorkspaceConfig = async (directory) => {
|
|
254
|
+
const config = await loadConfig(directory);
|
|
255
|
+
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.");
|
|
256
|
+
if (config.type === "workspace") return parseBaseWorkspaceConfig(directory, config);
|
|
257
|
+
return {
|
|
258
|
+
type: "project",
|
|
259
|
+
config
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/lib/config/workspace-loader.ts
|
|
264
|
+
const resolveProjects = (workspace, baseDirectory) => {
|
|
265
|
+
if (workspace.type === "project") return [{
|
|
266
|
+
directory: baseDirectory,
|
|
267
|
+
config: workspace.config
|
|
268
|
+
}];
|
|
269
|
+
return Object.entries(workspace.projects).filter((entry) => entry[1].type === "project").map(([relativePath, project]) => ({
|
|
270
|
+
directory: join(baseDirectory, relativePath),
|
|
271
|
+
config: project.config
|
|
272
|
+
}));
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
196
275
|
//#region src/lib/input/base-inputs.ts
|
|
197
276
|
const getStringInput = (input, field) => {
|
|
198
277
|
const value = input.get(field)?.value;
|
|
@@ -234,11 +313,6 @@ function getDirectoryInput(inputs, withDefault = true) {
|
|
|
234
313
|
return getStringInput(inputs, "directory");
|
|
235
314
|
}
|
|
236
315
|
//#endregion
|
|
237
|
-
//#region src/lib/input/inputs/config.input.ts
|
|
238
|
-
const getConfigInput = (inputs) => {
|
|
239
|
-
return getStringInputWithDefault(inputs, "config", ".");
|
|
240
|
-
};
|
|
241
|
-
//#endregion
|
|
242
316
|
//#region src/lib/input/inputs/editor.input.ts
|
|
243
317
|
const getEditorInput = (inputs) => {
|
|
244
318
|
return getBooleanInputWithDefault(inputs, "editor", false);
|
|
@@ -246,12 +320,13 @@ const getEditorInput = (inputs) => {
|
|
|
246
320
|
//#endregion
|
|
247
321
|
//#region src/lib/question/questions/confirm.question.ts
|
|
248
322
|
const askConfirm = async (question, baseOptions) => {
|
|
323
|
+
const options = {
|
|
324
|
+
default: false,
|
|
325
|
+
...baseOptions ?? {}
|
|
326
|
+
};
|
|
249
327
|
return await confirm({
|
|
250
328
|
message: question,
|
|
251
|
-
default:
|
|
252
|
-
default: false,
|
|
253
|
-
...baseOptions ?? {}
|
|
254
|
-
}.default
|
|
329
|
+
default: options.default
|
|
255
330
|
}).catch(promptError);
|
|
256
331
|
};
|
|
257
332
|
//#endregion
|
|
@@ -338,11 +413,6 @@ const getCreateTypeInput = (inputs) => {
|
|
|
338
413
|
throw new InvalidCommandArgumentError("type", "'component' or 'system'");
|
|
339
414
|
};
|
|
340
415
|
//#endregion
|
|
341
|
-
//#region src/lib/input/inputs/dev/generate.input.ts
|
|
342
|
-
const getDevGenerateInput = (inputs) => {
|
|
343
|
-
return getBooleanInputWithDefault(inputs, "generate", false);
|
|
344
|
-
};
|
|
345
|
-
//#endregion
|
|
346
416
|
//#region src/lib/input/inputs/editor/open.input.ts
|
|
347
417
|
const getEditorOpenInput = (inputs, defaultValue) => {
|
|
348
418
|
return getBooleanInputWithDefault(inputs, "open", defaultValue);
|
|
@@ -382,11 +452,6 @@ const getNewDockerOrAsk = (inputs) => {
|
|
|
382
452
|
return getInputOrAsk(getNewDockerInput(inputs), () => askConfirm(Messages.NEW_DOCKER_QUESTION, { default: true }));
|
|
383
453
|
};
|
|
384
454
|
//#endregion
|
|
385
|
-
//#region src/lib/input/inputs/new/init-functions.input.ts
|
|
386
|
-
const getNewInitFunctionsWithDefault = (inputs) => {
|
|
387
|
-
return getBooleanInputWithDefault(inputs, "initFunctions", false);
|
|
388
|
-
};
|
|
389
|
-
//#endregion
|
|
390
455
|
//#region src/lib/input/inputs/new/language.input.ts
|
|
391
456
|
const getLanguageInput = (inputs) => {
|
|
392
457
|
return getStringInput(inputs, "language");
|
|
@@ -855,253 +920,6 @@ const runSafe = async (fn, fallback) => {
|
|
|
855
920
|
}
|
|
856
921
|
};
|
|
857
922
|
//#endregion
|
|
858
|
-
//#region \0@oxc-project+runtime@0.138.0/helpers/esm/decorate.js
|
|
859
|
-
function __decorate(decorators, target, key, desc) {
|
|
860
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
861
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
862
|
-
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;
|
|
863
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
864
|
-
}
|
|
865
|
-
//#endregion
|
|
866
|
-
//#region src/lib/config/config.type.ts
|
|
867
|
-
var BuildConfig = class {
|
|
868
|
-
entry;
|
|
869
|
-
staticDir;
|
|
870
|
-
};
|
|
871
|
-
__decorate([
|
|
872
|
-
Expose(),
|
|
873
|
-
IsString(),
|
|
874
|
-
IsNotEmpty()
|
|
875
|
-
], BuildConfig.prototype, "entry", void 0);
|
|
876
|
-
__decorate([
|
|
877
|
-
Expose(),
|
|
878
|
-
IsString(),
|
|
879
|
-
IsNotEmpty()
|
|
880
|
-
], BuildConfig.prototype, "staticDir", void 0);
|
|
881
|
-
var EditorConfig = class {
|
|
882
|
-
entry;
|
|
883
|
-
save;
|
|
884
|
-
};
|
|
885
|
-
__decorate([
|
|
886
|
-
Expose(),
|
|
887
|
-
IsString(),
|
|
888
|
-
IsNotEmpty()
|
|
889
|
-
], EditorConfig.prototype, "entry", void 0);
|
|
890
|
-
__decorate([
|
|
891
|
-
Expose(),
|
|
892
|
-
IsString(),
|
|
893
|
-
IsNotEmpty()
|
|
894
|
-
], EditorConfig.prototype, "save", void 0);
|
|
895
|
-
var DirsConfig = class {
|
|
896
|
-
components;
|
|
897
|
-
systems;
|
|
898
|
-
};
|
|
899
|
-
__decorate([
|
|
900
|
-
Expose(),
|
|
901
|
-
IsString(),
|
|
902
|
-
IsNotEmpty()
|
|
903
|
-
], DirsConfig.prototype, "components", void 0);
|
|
904
|
-
__decorate([
|
|
905
|
-
Expose(),
|
|
906
|
-
IsString(),
|
|
907
|
-
IsNotEmpty()
|
|
908
|
-
], DirsConfig.prototype, "systems", void 0);
|
|
909
|
-
var ClientConfig = class {
|
|
910
|
-
enable;
|
|
911
|
-
port;
|
|
912
|
-
outDir;
|
|
913
|
-
build;
|
|
914
|
-
editor;
|
|
915
|
-
dirs;
|
|
916
|
-
};
|
|
917
|
-
__decorate([Expose(), IsBoolean()], ClientConfig.prototype, "enable", void 0);
|
|
918
|
-
__decorate([Expose(), IsPort()], ClientConfig.prototype, "port", void 0);
|
|
919
|
-
__decorate([
|
|
920
|
-
Expose(),
|
|
921
|
-
IsString(),
|
|
922
|
-
IsNotEmpty()
|
|
923
|
-
], ClientConfig.prototype, "outDir", void 0);
|
|
924
|
-
__decorate([
|
|
925
|
-
Expose(),
|
|
926
|
-
Type(() => BuildConfig),
|
|
927
|
-
ValidateNested()
|
|
928
|
-
], ClientConfig.prototype, "build", void 0);
|
|
929
|
-
__decorate([
|
|
930
|
-
Expose(),
|
|
931
|
-
Type(() => EditorConfig),
|
|
932
|
-
ValidateNested()
|
|
933
|
-
], ClientConfig.prototype, "editor", void 0);
|
|
934
|
-
__decorate([
|
|
935
|
-
Expose(),
|
|
936
|
-
Type(() => DirsConfig),
|
|
937
|
-
ValidateNested()
|
|
938
|
-
], ClientConfig.prototype, "dirs", void 0);
|
|
939
|
-
var ServerConfig = class {
|
|
940
|
-
enable;
|
|
941
|
-
outDir;
|
|
942
|
-
build;
|
|
943
|
-
editor;
|
|
944
|
-
dirs;
|
|
945
|
-
};
|
|
946
|
-
__decorate([Expose(), IsBoolean()], ServerConfig.prototype, "enable", void 0);
|
|
947
|
-
__decorate([
|
|
948
|
-
Expose(),
|
|
949
|
-
IsString(),
|
|
950
|
-
IsNotEmpty()
|
|
951
|
-
], ServerConfig.prototype, "outDir", void 0);
|
|
952
|
-
__decorate([
|
|
953
|
-
Expose(),
|
|
954
|
-
Type(() => BuildConfig),
|
|
955
|
-
ValidateNested()
|
|
956
|
-
], ServerConfig.prototype, "build", void 0);
|
|
957
|
-
__decorate([
|
|
958
|
-
Expose(),
|
|
959
|
-
Type(() => EditorConfig),
|
|
960
|
-
ValidateNested()
|
|
961
|
-
], ServerConfig.prototype, "editor", void 0);
|
|
962
|
-
__decorate([
|
|
963
|
-
Expose(),
|
|
964
|
-
Type(() => DirsConfig),
|
|
965
|
-
ValidateNested()
|
|
966
|
-
], ServerConfig.prototype, "dirs", void 0);
|
|
967
|
-
var SslConfig = class {
|
|
968
|
-
enable;
|
|
969
|
-
cert;
|
|
970
|
-
key;
|
|
971
|
-
};
|
|
972
|
-
__decorate([Expose(), IsBoolean()], SslConfig.prototype, "enable", void 0);
|
|
973
|
-
__decorate([Expose(), IsString()], SslConfig.prototype, "cert", void 0);
|
|
974
|
-
__decorate([Expose(), IsString()], SslConfig.prototype, "key", void 0);
|
|
975
|
-
var Config = class {
|
|
976
|
-
name;
|
|
977
|
-
language;
|
|
978
|
-
initFunctions;
|
|
979
|
-
client;
|
|
980
|
-
server;
|
|
981
|
-
ssl;
|
|
982
|
-
};
|
|
983
|
-
__decorate([
|
|
984
|
-
Expose(),
|
|
985
|
-
IsString(),
|
|
986
|
-
IsNotEmpty()
|
|
987
|
-
], Config.prototype, "name", void 0);
|
|
988
|
-
__decorate([Expose(), IsEnum(["ts", "js"])], Config.prototype, "language", void 0);
|
|
989
|
-
__decorate([Expose(), IsBoolean()], Config.prototype, "initFunctions", void 0);
|
|
990
|
-
__decorate([
|
|
991
|
-
Expose(),
|
|
992
|
-
Type(() => ClientConfig),
|
|
993
|
-
ValidateNested()
|
|
994
|
-
], Config.prototype, "client", void 0);
|
|
995
|
-
__decorate([
|
|
996
|
-
Expose(),
|
|
997
|
-
Type(() => ServerConfig),
|
|
998
|
-
ValidateNested()
|
|
999
|
-
], Config.prototype, "server", void 0);
|
|
1000
|
-
__decorate([
|
|
1001
|
-
Expose(),
|
|
1002
|
-
Type(() => SslConfig),
|
|
1003
|
-
ValidateNested()
|
|
1004
|
-
], Config.prototype, "ssl", void 0);
|
|
1005
|
-
//#endregion
|
|
1006
|
-
//#region src/lib/constants.ts
|
|
1007
|
-
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1008
|
-
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1009
|
-
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1010
|
-
//#endregion
|
|
1011
|
-
//#region src/lib/utils/object.ts
|
|
1012
|
-
const isObject = (item) => {
|
|
1013
|
-
return item && typeof item === "object" && !Array.isArray(item);
|
|
1014
|
-
};
|
|
1015
|
-
const deepMerge = (target, ...sources) => {
|
|
1016
|
-
if (!sources.length) return target;
|
|
1017
|
-
const source = sources.shift();
|
|
1018
|
-
if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
|
|
1019
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
1020
|
-
deepMerge(target[key], source[key]);
|
|
1021
|
-
} else Object.assign(target, { [key]: source[key] });
|
|
1022
|
-
return deepMerge(target, ...sources);
|
|
1023
|
-
};
|
|
1024
|
-
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1025
|
-
//#endregion
|
|
1026
|
-
//#region src/lib/config/config-defaults.ts
|
|
1027
|
-
const CONFIG_DEFAULTS = {
|
|
1028
|
-
name: "nanoforge-app",
|
|
1029
|
-
language: "ts",
|
|
1030
|
-
initFunctions: false,
|
|
1031
|
-
ssl: {
|
|
1032
|
-
enable: false,
|
|
1033
|
-
cert: "",
|
|
1034
|
-
key: ""
|
|
1035
|
-
},
|
|
1036
|
-
client: {
|
|
1037
|
-
enable: true,
|
|
1038
|
-
port: "3000",
|
|
1039
|
-
outDir: ".nanoforge/client",
|
|
1040
|
-
build: {
|
|
1041
|
-
entry: "client/main.ts",
|
|
1042
|
-
staticDir: "client/static"
|
|
1043
|
-
},
|
|
1044
|
-
editor: {
|
|
1045
|
-
entry: ".nanoforge/editor/client/main.ts",
|
|
1046
|
-
save: ".nanoforge/client.save.json"
|
|
1047
|
-
},
|
|
1048
|
-
dirs: {
|
|
1049
|
-
components: "client/components",
|
|
1050
|
-
systems: "client/systems"
|
|
1051
|
-
}
|
|
1052
|
-
},
|
|
1053
|
-
server: {
|
|
1054
|
-
enable: false,
|
|
1055
|
-
outDir: ".nanoforge/server",
|
|
1056
|
-
build: {
|
|
1057
|
-
entry: "server/main.ts",
|
|
1058
|
-
staticDir: "server/static"
|
|
1059
|
-
},
|
|
1060
|
-
editor: {
|
|
1061
|
-
entry: ".nanoforge/editor/server/main.ts",
|
|
1062
|
-
save: ".nanoforge/server.save.json"
|
|
1063
|
-
},
|
|
1064
|
-
dirs: {
|
|
1065
|
-
components: "server/components",
|
|
1066
|
-
systems: "server/systems"
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
};
|
|
1070
|
-
//#endregion
|
|
1071
|
-
//#region src/lib/config/config-loader.ts
|
|
1072
|
-
let config;
|
|
1073
|
-
const getConfigPath = (directory, name) => {
|
|
1074
|
-
if (name) return join(directory, name);
|
|
1075
|
-
else {
|
|
1076
|
-
for (const n of [CONFIG_FILE_NAME]) {
|
|
1077
|
-
const path = join(directory, n);
|
|
1078
|
-
if (existsSync(path)) return path;
|
|
1079
|
-
}
|
|
1080
|
-
throw new ConfigNotFoundError(join(directory, CONFIG_FILE_NAME));
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
const loadConfig = async (directory, name, noThrow = false) => {
|
|
1084
|
-
if (config) return config;
|
|
1085
|
-
let rawData;
|
|
1086
|
-
const path = getConfigPath(directory, name);
|
|
1087
|
-
try {
|
|
1088
|
-
rawData = deepMerge(CONFIG_DEFAULTS, JSON.parse(readFileSync(path, "utf-8")));
|
|
1089
|
-
} catch {
|
|
1090
|
-
rawData = noThrow ? CONFIG_DEFAULTS : null;
|
|
1091
|
-
}
|
|
1092
|
-
if (!rawData) throw new FileSystemError("read config file", path);
|
|
1093
|
-
const data = plainToInstance(Config, rawData, { excludeExtraneousValues: true });
|
|
1094
|
-
const errors = await validate(data);
|
|
1095
|
-
if (errors.length > 0) throw new CLIError(`Invalid config:\n${errors.toString().replace(/,/g, "\n")}`);
|
|
1096
|
-
config = data;
|
|
1097
|
-
return config;
|
|
1098
|
-
};
|
|
1099
|
-
//#endregion
|
|
1100
|
-
//#region src/action/common/config.ts
|
|
1101
|
-
const getConfig = (inputs, dir, noThrow) => {
|
|
1102
|
-
return loadConfig(dir, getConfigInput(inputs), noThrow);
|
|
1103
|
-
};
|
|
1104
|
-
//#endregion
|
|
1105
923
|
//#region src/action/abstract.action.ts
|
|
1106
924
|
var AbstractAction = class {
|
|
1107
925
|
async run(args, options, extraFlags) {
|
|
@@ -1138,54 +956,60 @@ var BuildAction = class extends AbstractAction {
|
|
|
1138
956
|
failureMessage = Messages.BUILD_FAILED;
|
|
1139
957
|
async handle(_args, options) {
|
|
1140
958
|
const directory = getDirectoryInput(options);
|
|
1141
|
-
const
|
|
959
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1142
960
|
const isEditor = getEditorInput(options);
|
|
1143
961
|
const isWatch = getWatchInput(options);
|
|
1144
|
-
const targets = this.resolveTargets(
|
|
1145
|
-
const results = await this.buildAll(targets,
|
|
962
|
+
const targets = this.resolveTargets(workspaceConfig, directory, options, isEditor);
|
|
963
|
+
const results = await this.buildAll(targets, isWatch);
|
|
1146
964
|
if (isWatch) return this.enterWatchMode();
|
|
1147
965
|
return { success: results.every(Boolean) };
|
|
1148
966
|
}
|
|
1149
|
-
resolveTargets(
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
967
|
+
resolveTargets(workspaceConfig, baseDirectory, options, isEditor) {
|
|
968
|
+
const projects = resolveProjects(workspaceConfig, baseDirectory);
|
|
969
|
+
return projects.map((project) => this.createTarget(project, baseDirectory, options, isEditor, projects.length > 1));
|
|
970
|
+
}
|
|
971
|
+
createTarget(project, baseDirectory, options, isEditor, disambiguate) {
|
|
972
|
+
const isClient = project.config.type === "client";
|
|
973
|
+
const label = isClient ? "Client" : "Server";
|
|
974
|
+
const relativePath = relative(baseDirectory, project.directory);
|
|
975
|
+
const name = disambiguate && relativePath !== "" ? `${label} (${relativePath})` : label;
|
|
976
|
+
const defaults = isClient ? defaultClientConfig : defaultServerConfig;
|
|
977
|
+
const defaultEntry = isEditor ? project.config.editor?.entryFile ?? defaults.editor.entryFile : project.config.entryFile ?? defaults.entryFile;
|
|
1156
978
|
return {
|
|
1157
979
|
name,
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
980
|
+
directory: project.directory,
|
|
981
|
+
entry: getStringInputWithDefault(options, isClient ? "clientEntry" : "serverEntry", defaultEntry),
|
|
982
|
+
static: getStringInputWithDefault(options, isClient ? "clientStaticDir" : "serverStaticDir", project.config.dir?.assets ?? defaults.dir.assets),
|
|
983
|
+
output: getStringInputWithDefault(options, isClient ? "clientOutDir" : "serverOutDir", project.config.out?.dir ?? defaults.out.dir),
|
|
984
|
+
platform: isClient ? "browser" : "node"
|
|
1162
985
|
};
|
|
1163
986
|
}
|
|
1164
|
-
async buildAll(targets,
|
|
987
|
+
async buildAll(targets, isWatch) {
|
|
1165
988
|
const results = [];
|
|
1166
989
|
for (const target of targets) {
|
|
1167
|
-
const result = await this.buildTarget(target,
|
|
990
|
+
const result = await this.buildTarget(target, isWatch);
|
|
1168
991
|
results.push(result);
|
|
1169
992
|
}
|
|
1170
993
|
return results;
|
|
1171
994
|
}
|
|
1172
|
-
async buildTarget(target,
|
|
995
|
+
async buildTarget(target, isWatch) {
|
|
1173
996
|
const packageManager = PackageManagerFactory.create("local_bun");
|
|
1174
997
|
const executeBuild = (rebuild = false) => runSafe(() => {
|
|
1175
|
-
this.resetOut(target.output, directory);
|
|
1176
|
-
this.copyFiles(target, directory);
|
|
1177
|
-
return packageManager.build(target.name, directory, target.entry, target.output, [
|
|
998
|
+
this.resetOut(target.output, target.directory);
|
|
999
|
+
this.copyFiles(target, target.directory);
|
|
1000
|
+
return packageManager.build(target.name, target.directory, target.entry, target.output, [
|
|
1178
1001
|
"--asset-naming",
|
|
1179
1002
|
"[name].[ext]",
|
|
1180
1003
|
"--target",
|
|
1181
1004
|
target.platform
|
|
1182
1005
|
], rebuild);
|
|
1183
1006
|
}, false);
|
|
1184
|
-
if (isWatch) this.watchDirectory(directory, target.entry, () => executeBuild(true));
|
|
1007
|
+
if (isWatch) this.watchDirectory(target.directory, target.entry, () => executeBuild(true));
|
|
1185
1008
|
return await executeBuild() !== false;
|
|
1186
1009
|
}
|
|
1187
1010
|
watchDirectory(directory, entry, onChange) {
|
|
1188
|
-
|
|
1011
|
+
const watchPath = dirname(join(getCwd(directory), entry));
|
|
1012
|
+
watch(watchPath).on("change", onChange);
|
|
1189
1013
|
}
|
|
1190
1014
|
enterWatchMode() {
|
|
1191
1015
|
console.info();
|
|
@@ -1197,6 +1021,7 @@ var BuildAction = class extends AbstractAction {
|
|
|
1197
1021
|
resetFolder(getCwd(join(directory, outDir)));
|
|
1198
1022
|
}
|
|
1199
1023
|
copyFiles(target, directory) {
|
|
1024
|
+
if (!target.static) return;
|
|
1200
1025
|
const from = getCwd(join(directory, target.static));
|
|
1201
1026
|
const to = getCwd(join(directory, target.output));
|
|
1202
1027
|
copyFiles(from, to);
|
|
@@ -1241,29 +1066,14 @@ var AbstractCollection = class {
|
|
|
1241
1066
|
var NanoforgeCollection = class NanoforgeCollection extends AbstractCollection {
|
|
1242
1067
|
static schematics = [
|
|
1243
1068
|
{
|
|
1244
|
-
name: "
|
|
1245
|
-
alias: "
|
|
1246
|
-
description: "Generate a new
|
|
1069
|
+
name: "project",
|
|
1070
|
+
alias: "project",
|
|
1071
|
+
description: "Generate a new project"
|
|
1247
1072
|
},
|
|
1248
1073
|
{
|
|
1249
|
-
name: "
|
|
1250
|
-
alias: "
|
|
1251
|
-
description: "Generate a
|
|
1252
|
-
},
|
|
1253
|
-
{
|
|
1254
|
-
name: "part-base",
|
|
1255
|
-
alias: "base",
|
|
1256
|
-
description: "Generate a NanoForge Part Base"
|
|
1257
|
-
},
|
|
1258
|
-
{
|
|
1259
|
-
name: "part-main",
|
|
1260
|
-
alias: "main",
|
|
1261
|
-
description: "Generate a NanoForge Part Main file"
|
|
1262
|
-
},
|
|
1263
|
-
{
|
|
1264
|
-
name: "docker",
|
|
1265
|
-
alias: "docker",
|
|
1266
|
-
description: "Generate a Dockerfile for the application"
|
|
1074
|
+
name: "workspace",
|
|
1075
|
+
alias: "workspace",
|
|
1076
|
+
description: "Generate a new workspace"
|
|
1267
1077
|
},
|
|
1268
1078
|
{
|
|
1269
1079
|
name: "component",
|
|
@@ -1321,10 +1131,11 @@ var SchematicOption = class {
|
|
|
1321
1131
|
}
|
|
1322
1132
|
toCommandString(prefix) {
|
|
1323
1133
|
const normalizedName = `${prefix ? `${prefix}.` : ""}${this.normalizedName}`;
|
|
1324
|
-
if (typeof this.value === "string")
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1134
|
+
if (typeof this.value === "string") {
|
|
1135
|
+
if (this.name === "name") return [`--${normalizedName}=${this.format()}`];
|
|
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") {
|
|
1328
1139
|
const str = normalizedName;
|
|
1329
1140
|
return this.value ? [`--${str}=true`] : [`--${str}=false`];
|
|
1330
1141
|
} else if (Array.isArray(this.value)) return this.value.reduce((old, option) => [...old, ...option.toCommandString(normalizedName)], []);
|
|
@@ -1366,16 +1177,18 @@ var CreateAction = class extends AbstractAction {
|
|
|
1366
1177
|
failureMessage = Messages.CREATE_FAILED;
|
|
1367
1178
|
async handle(args, options) {
|
|
1368
1179
|
const directory = getDirectoryInput(options);
|
|
1369
|
-
const
|
|
1180
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
1181
|
+
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
|
+
const { config } = workspaceConfig;
|
|
1183
|
+
const defaults = config.type === "client" ? defaultClientConfig : defaultServerConfig;
|
|
1370
1184
|
const type = getCreateTypeInput(args);
|
|
1371
1185
|
const name = await getCreateNameInputOrAsk(options);
|
|
1372
|
-
const
|
|
1373
|
-
const path = getPathInputWithDefault(options, config[isServer ? "server" : "client"].dirs[type === "component" ? "components" : "systems"]);
|
|
1186
|
+
const path = getPathInputWithDefault(options, config.dir?.[type === "component" ? "components" : "systems"] ?? defaults.dir[type === "component" ? "components" : "systems"]);
|
|
1374
1187
|
await this.generateElement(directory, type, {
|
|
1375
1188
|
name,
|
|
1376
1189
|
directory: path,
|
|
1377
|
-
part:
|
|
1378
|
-
language: config.language
|
|
1190
|
+
part: config.type,
|
|
1191
|
+
language: config.language ?? defaults.language
|
|
1379
1192
|
});
|
|
1380
1193
|
return {};
|
|
1381
1194
|
}
|
|
@@ -1392,19 +1205,14 @@ var DevAction = class extends AbstractAction {
|
|
|
1392
1205
|
failureMessage = Messages.DEV_FAILED;
|
|
1393
1206
|
async handle(_args, options) {
|
|
1394
1207
|
const directory = getDirectoryInput(options);
|
|
1395
|
-
const generate = getDevGenerateInput(options);
|
|
1396
1208
|
const editor = getEditorInput(options);
|
|
1397
|
-
const tasks = this.buildTaskList(directory,
|
|
1209
|
+
const tasks = this.buildTaskList(directory, editor);
|
|
1398
1210
|
await Promise.all(tasks);
|
|
1399
1211
|
return { keepAlive: true };
|
|
1400
1212
|
}
|
|
1401
|
-
buildTaskList(directory,
|
|
1213
|
+
buildTaskList(directory, editor) {
|
|
1402
1214
|
const tasks = [];
|
|
1403
1215
|
const extraFlags = editor ? ["--editor"] : [];
|
|
1404
|
-
if (generate) tasks.push(this.runSubCommand("generate", directory, {
|
|
1405
|
-
silent: true,
|
|
1406
|
-
extraFlags
|
|
1407
|
-
}));
|
|
1408
1216
|
tasks.push(this.runSubCommand("build", directory, {
|
|
1409
1217
|
silent: true,
|
|
1410
1218
|
extraFlags
|
|
@@ -1451,55 +1259,25 @@ var EditorAction = class extends AbstractAction {
|
|
|
1451
1259
|
}
|
|
1452
1260
|
};
|
|
1453
1261
|
//#endregion
|
|
1454
|
-
//#region src/
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
const isEditor = getEditorInput(options);
|
|
1463
|
-
const isWatch = getWatchInput(options);
|
|
1464
|
-
await this.generateParts(config, directory, isEditor, isWatch);
|
|
1465
|
-
if (isWatch) return this.enterWatchMode();
|
|
1466
|
-
return {};
|
|
1467
|
-
}
|
|
1468
|
-
extractValues(config) {
|
|
1469
|
-
return {
|
|
1470
|
-
directory: ".",
|
|
1471
|
-
language: config.language,
|
|
1472
|
-
initFunctions: config.initFunctions
|
|
1473
|
-
};
|
|
1474
|
-
}
|
|
1475
|
-
async generateParts(config, directory, isEditor, watch) {
|
|
1476
|
-
const collection = CollectionFactory.create("@nanoforge-dev/schematics", directory);
|
|
1477
|
-
const values = this.extractValues(config);
|
|
1478
|
-
if (config.client.enable) await executeSchematic("Client main file", collection, "part-main", {
|
|
1479
|
-
...values,
|
|
1480
|
-
part: "client",
|
|
1481
|
-
outFile: !isEditor ? config.client.build.entry : config.client.editor.entry,
|
|
1482
|
-
saveFile: config.client.editor.save,
|
|
1483
|
-
editor: isEditor
|
|
1484
|
-
}, watch ? this.watchPath(directory, values.directory, config.client.editor.save) : void 0);
|
|
1485
|
-
if (config.server.enable) await executeSchematic("Server main file", collection, "part-main", {
|
|
1486
|
-
...values,
|
|
1487
|
-
part: "server",
|
|
1488
|
-
outFile: !isEditor ? config.server.build.entry : config.server.editor.entry,
|
|
1489
|
-
saveFile: config.server.editor.save,
|
|
1490
|
-
editor: isEditor
|
|
1491
|
-
}, this.watchPath(directory, values.directory, config.server.editor.save));
|
|
1492
|
-
}
|
|
1493
|
-
watchPath(directory, subDir, saveFile) {
|
|
1494
|
-
return join(getCwd(directory), subDir, saveFile);
|
|
1495
|
-
}
|
|
1496
|
-
enterWatchMode() {
|
|
1497
|
-
console.info();
|
|
1498
|
-
console.info(Messages.GENERATE_WATCH_START);
|
|
1499
|
-
console.info();
|
|
1500
|
-
return { keepAlive: true };
|
|
1501
|
-
}
|
|
1262
|
+
//#region src/lib/constants.ts
|
|
1263
|
+
const CONFIG_FILE_NAME = "nanoforge.config.json";
|
|
1264
|
+
const MANIFEST_FILE_NAME = "nanoforge.manifest.json";
|
|
1265
|
+
const GLOBAL_CONFIG_FILE_NAME = ".nanoforgerc";
|
|
1266
|
+
//#endregion
|
|
1267
|
+
//#region src/lib/utils/object.ts
|
|
1268
|
+
const isObject = (item) => {
|
|
1269
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
1502
1270
|
};
|
|
1271
|
+
const deepMerge = (target, ...sources) => {
|
|
1272
|
+
if (!sources.length) return target;
|
|
1273
|
+
const source = sources.shift();
|
|
1274
|
+
if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
|
|
1275
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
1276
|
+
deepMerge(target[key], source[key]);
|
|
1277
|
+
} else Object.assign(target, { [key]: source[key] });
|
|
1278
|
+
return deepMerge(target, ...sources);
|
|
1279
|
+
};
|
|
1280
|
+
const isEmpty = (target) => Object.keys(target).length === 0;
|
|
1503
1281
|
//#endregion
|
|
1504
1282
|
//#region src/lib/global-config/global-config-defaults.ts
|
|
1505
1283
|
const GLOBAL_CONFIG_DEFAULTS = {};
|
|
@@ -1885,8 +1663,7 @@ var NewAction = class extends AbstractAction {
|
|
|
1885
1663
|
packageManager: await getNewPackageManagerInputOrAsk(inputs),
|
|
1886
1664
|
language: await getNewLanguageInputOrAsk(inputs),
|
|
1887
1665
|
strict: await getNewStrictOrAsk(inputs),
|
|
1888
|
-
|
|
1889
|
-
initFunctions: getNewInitFunctionsWithDefault(inputs),
|
|
1666
|
+
multiplayer: await getNewServerOrAsk(inputs),
|
|
1890
1667
|
skipInstall: await getNewSkipInstallOrAsk(inputs),
|
|
1891
1668
|
docker: await getNewDockerOrAsk(inputs),
|
|
1892
1669
|
lint: getNewLintInput(inputs),
|
|
@@ -1904,61 +1681,43 @@ var NewAction = class extends AbstractAction {
|
|
|
1904
1681
|
console.info();
|
|
1905
1682
|
console.info(Messages.NEW_GENERATION_START);
|
|
1906
1683
|
console.info();
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
return executeSchematic("
|
|
1684
|
+
if (values.multiplayer) {
|
|
1685
|
+
await this.generateWorkspace(collection, values);
|
|
1686
|
+
await this.generateClientProject(collection, values);
|
|
1687
|
+
await this.generateServerProject(collection, values);
|
|
1688
|
+
} else await this.generateClientProject(collection, values);
|
|
1689
|
+
}
|
|
1690
|
+
generateWorkspace(collection, values) {
|
|
1691
|
+
return executeSchematic("Workspace", collection, "workspace", {
|
|
1915
1692
|
name: values.name,
|
|
1916
1693
|
directory: values.directory,
|
|
1917
|
-
packageManager: values.packageManager,
|
|
1918
1694
|
language: values.language,
|
|
1919
1695
|
strict: values.strict,
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
editor: values.editor
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
generateConfiguration(collection, values) {
|
|
1926
|
-
return executeSchematic("Configuration", collection, "configuration", {
|
|
1927
|
-
name: values.name,
|
|
1928
|
-
directory: values.directory,
|
|
1929
|
-
server: values.server,
|
|
1930
|
-
language: values.language,
|
|
1931
|
-
initFunctions: values.initFunctions
|
|
1932
|
-
});
|
|
1933
|
-
}
|
|
1934
|
-
async generateClientParts(collection, values) {
|
|
1935
|
-
const partOptions = this.partOptions(values, "client");
|
|
1936
|
-
await executeSchematic("Client base", collection, "part-base", {
|
|
1937
|
-
...partOptions,
|
|
1938
|
-
server: values.server
|
|
1696
|
+
packageManager: values.packageManager,
|
|
1697
|
+
docker: values.docker
|
|
1939
1698
|
});
|
|
1940
|
-
await executeSchematic("Client main file", collection, "part-main", { ...partOptions });
|
|
1941
1699
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
server: values.server
|
|
1700
|
+
generateClientProject(collection, values) {
|
|
1701
|
+
return executeSchematic("Client project", collection, "project", {
|
|
1702
|
+
...this.projectOptions(values, "client"),
|
|
1703
|
+
hasServer: values.multiplayer
|
|
1947
1704
|
});
|
|
1948
|
-
await executeSchematic("Server main file", collection, "part-main", { ...partOptions });
|
|
1949
1705
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
directory: values.directory,
|
|
1953
|
-
packageManager: values.packageManager
|
|
1954
|
-
});
|
|
1706
|
+
generateServerProject(collection, values) {
|
|
1707
|
+
return executeSchematic("Server project", collection, "project", this.projectOptions(values, "server"));
|
|
1955
1708
|
}
|
|
1956
|
-
|
|
1709
|
+
projectOptions(values, part) {
|
|
1957
1710
|
return {
|
|
1958
1711
|
part,
|
|
1959
|
-
|
|
1712
|
+
workspaceName: values.multiplayer ? values.name : void 0,
|
|
1713
|
+
name: values.multiplayer ? part : values.name,
|
|
1714
|
+
directory: values.multiplayer ? join(values.directory, "apps", part) : values.directory,
|
|
1960
1715
|
language: values.language,
|
|
1961
|
-
|
|
1716
|
+
strict: values.strict,
|
|
1717
|
+
packageManager: values.packageManager,
|
|
1718
|
+
workspace: values.multiplayer,
|
|
1719
|
+
docker: values.docker,
|
|
1720
|
+
editor: values.editor
|
|
1962
1721
|
};
|
|
1963
1722
|
}
|
|
1964
1723
|
async installDependencies(packageManagerName, directory) {
|
|
@@ -1973,6 +1732,14 @@ var NewAction = class extends AbstractAction {
|
|
|
1973
1732
|
}
|
|
1974
1733
|
};
|
|
1975
1734
|
//#endregion
|
|
1735
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorate.js
|
|
1736
|
+
function __decorate(decorators, target, key, desc) {
|
|
1737
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1738
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1739
|
+
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;
|
|
1740
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1741
|
+
}
|
|
1742
|
+
//#endregion
|
|
1976
1743
|
//#region src/lib/manifest/manifest.type.ts
|
|
1977
1744
|
let ManifestPackageTypeEnum = /* @__PURE__ */ function(ManifestPackageTypeEnum) {
|
|
1978
1745
|
ManifestPackageTypeEnum["COMPONENT"] = "component";
|
|
@@ -2091,87 +1858,96 @@ var PublishAction = class extends AbstractAction {
|
|
|
2091
1858
|
};
|
|
2092
1859
|
//#endregion
|
|
2093
1860
|
//#region src/action/actions/start.action.ts
|
|
1861
|
+
const isClientTarget = (target) => target.platform === "client";
|
|
1862
|
+
const isServerTarget = (target) => target.platform === "server";
|
|
2094
1863
|
var StartAction = class extends AbstractAction {
|
|
2095
1864
|
startMessage = Messages.START_START;
|
|
2096
1865
|
successMessage = Messages.START_SUCCESS;
|
|
2097
1866
|
failureMessage = Messages.START_FAILED;
|
|
2098
1867
|
async handle(_args, options) {
|
|
2099
1868
|
const directory = getDirectoryInput(options);
|
|
2100
|
-
const
|
|
2101
|
-
const clientDir = getStringInputWithDefault(options, "clientDir", config.client.outDir);
|
|
2102
|
-
const serverDir = getStringInputWithDefault(options, "serverDir", config.server.outDir);
|
|
1869
|
+
const workspaceConfig = await parseWorkspaceConfig(directory);
|
|
2103
1870
|
const watch = getWatchInput(options);
|
|
2104
|
-
const
|
|
2105
|
-
const
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
ssl
|
|
2112
|
-
});
|
|
1871
|
+
const targets = this.resolveTargets(workspaceConfig, directory, options);
|
|
1872
|
+
const serverTargets = targets.filter(isServerTarget);
|
|
1873
|
+
const clientTargets = targets.filter(isClientTarget);
|
|
1874
|
+
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
|
+
const env = this.parseEnv(directory);
|
|
1876
|
+
const packageManager = await PackageManagerFactory.find(directory);
|
|
1877
|
+
const tasks = this.buildStartTasks(packageManager, serverTargets, clientTargets, watch, env);
|
|
2113
1878
|
await Promise.all(tasks);
|
|
2114
1879
|
return { keepAlive: true };
|
|
2115
1880
|
}
|
|
2116
|
-
|
|
1881
|
+
resolveTLS(options, config) {
|
|
2117
1882
|
const cliCert = getStringInput(options, "cert");
|
|
2118
1883
|
const cliKey = getStringInput(options, "key");
|
|
2119
|
-
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
1884
|
+
const tls = config.tls;
|
|
1885
|
+
const configTls = tls && tls.enable ? tls : void 0;
|
|
1886
|
+
if (!Boolean(cliCert || cliKey || configTls)) return void 0;
|
|
1887
|
+
const cert = cliCert ?? configTls?.cert;
|
|
1888
|
+
const key = cliKey ?? configTls?.key;
|
|
1889
|
+
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");
|
|
1890
|
+
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");
|
|
2124
1891
|
return {
|
|
2125
1892
|
cert,
|
|
2126
1893
|
key
|
|
2127
1894
|
};
|
|
2128
1895
|
}
|
|
2129
|
-
|
|
2130
|
-
|
|
1896
|
+
resolveTargets(workspaceConfig, baseDirectory, options) {
|
|
1897
|
+
return resolveProjects(workspaceConfig, baseDirectory).map((project) => this.createTarget(project, options));
|
|
1898
|
+
}
|
|
1899
|
+
createTarget(project, options) {
|
|
1900
|
+
if (project.config.type === "server") return {
|
|
1901
|
+
directory: project.directory,
|
|
1902
|
+
outDir: getStringInputWithDefault(options, "serverDir", project.config.out?.dir ?? defaultServerConfig.out.dir),
|
|
1903
|
+
platform: "server"
|
|
1904
|
+
};
|
|
1905
|
+
return {
|
|
1906
|
+
directory: project.directory,
|
|
1907
|
+
outDir: getStringInputWithDefault(options, "clientDir", project.config.out?.dir ?? defaultClientConfig.out.dir),
|
|
1908
|
+
platform: "client",
|
|
1909
|
+
port: getStringInputWithDefault(options, "port", project.config.port ?? defaultClientConfig.port),
|
|
1910
|
+
tls: this.resolveTLS(options, project.config)
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
buildStartTasks(packageManager, serverTargets, clientTargets, watch, env) {
|
|
2131
1914
|
const tasks = [];
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2134
|
-
serverDir,
|
|
2135
|
-
watch
|
|
2136
|
-
}, env));
|
|
2137
|
-
if (config.client.enable) tasks.push(this.startClient(directory, config, {
|
|
2138
|
-
clientDir,
|
|
2139
|
-
serverDir,
|
|
1915
|
+
for (const target of serverTargets) tasks.push(this.startServer(packageManager, target, watch, env));
|
|
1916
|
+
for (const target of clientTargets) tasks.push(this.startClient(packageManager, target, {
|
|
2140
1917
|
watch,
|
|
2141
|
-
|
|
2142
|
-
ssl
|
|
1918
|
+
serverTargets
|
|
2143
1919
|
}, env));
|
|
2144
1920
|
return tasks;
|
|
2145
1921
|
}
|
|
2146
|
-
async startClient(
|
|
1922
|
+
async startClient(packageManager, target, options, env) {
|
|
2147
1923
|
const loaderPath = getModulePath("@nanoforge-dev/loader-client/package.json", true);
|
|
2148
|
-
const params = this.buildClientParams(
|
|
2149
|
-
await this.runLoader("Client", loaderPath, params, env.client);
|
|
1924
|
+
const params = this.buildClientParams(target, options);
|
|
1925
|
+
await this.runLoader(packageManager, "Client", loaderPath, params, env.client);
|
|
2150
1926
|
}
|
|
2151
|
-
async startServer(
|
|
1927
|
+
async startServer(packageManager, target, watch, env) {
|
|
2152
1928
|
const loaderPath = getModulePath("@nanoforge-dev/loader-server/package.json", true);
|
|
2153
|
-
const params = this.buildServerParams(
|
|
2154
|
-
await this.runLoader("Server", loaderPath, params, env.server);
|
|
1929
|
+
const params = this.buildServerParams(target, watch);
|
|
1930
|
+
await this.runLoader(packageManager, "Server", loaderPath, params, env.server);
|
|
2155
1931
|
}
|
|
2156
|
-
buildClientParams(
|
|
1932
|
+
buildClientParams(target, options) {
|
|
2157
1933
|
const params = {
|
|
2158
|
-
"-d": getCwd(join$1(directory,
|
|
2159
|
-
"-p":
|
|
1934
|
+
"-d": getCwd(join$1(target.directory, target.outDir)),
|
|
1935
|
+
"-p": target.port
|
|
2160
1936
|
};
|
|
2161
|
-
if (options.watch) params["--watch"] = true;
|
|
2162
1937
|
if (options.watch) {
|
|
2163
1938
|
params["--watch"] = true;
|
|
2164
|
-
|
|
1939
|
+
const [server] = options.serverTargets;
|
|
1940
|
+
if (server && options.serverTargets.length === 1) params["--watch-server-dir"] = getCwd(join$1(server.directory, server.outDir));
|
|
2165
1941
|
}
|
|
2166
|
-
if (
|
|
2167
|
-
params["--cert"] =
|
|
2168
|
-
params["--key"] =
|
|
1942
|
+
if (target.tls) {
|
|
1943
|
+
params["--cert"] = target.tls.cert;
|
|
1944
|
+
params["--key"] = target.tls.key;
|
|
2169
1945
|
}
|
|
2170
1946
|
return this.buildParams(params);
|
|
2171
1947
|
}
|
|
2172
|
-
buildServerParams(
|
|
2173
|
-
const params = { "-d": getCwd(join$1(directory,
|
|
2174
|
-
if (
|
|
1948
|
+
buildServerParams(target, watch) {
|
|
1949
|
+
const params = { "-d": getCwd(join$1(target.directory, target.outDir)) };
|
|
1950
|
+
if (watch) params["--watch"] = true;
|
|
2175
1951
|
return this.buildParams(params);
|
|
2176
1952
|
}
|
|
2177
1953
|
buildParams(params) {
|
|
@@ -2192,9 +1968,9 @@ var StartAction = class extends AbstractAction {
|
|
|
2192
1968
|
server: Object.fromEntries(baseEnv.filter(([key]) => !key.startsWith(clientPrefix)).map(([key, value]) => [key.replace(serverPrefix, prefix), value]))
|
|
2193
1969
|
};
|
|
2194
1970
|
}
|
|
2195
|
-
async runLoader(name, directory, params, env) {
|
|
1971
|
+
async runLoader(packageManager, name, directory, params, env) {
|
|
2196
1972
|
await runSafe(async () => {
|
|
2197
|
-
await
|
|
1973
|
+
await packageManager.run(name, directory, "start", params, env, [], true);
|
|
2198
1974
|
});
|
|
2199
1975
|
}
|
|
2200
1976
|
};
|
|
@@ -2227,10 +2003,9 @@ var AbstractCommand = class {
|
|
|
2227
2003
|
//#region src/command/commands/build.command.ts
|
|
2228
2004
|
var BuildCommand = class extends AbstractCommand {
|
|
2229
2005
|
load(program) {
|
|
2230
|
-
program.command("build").description("build your game").option("-d, --directory <directory>", "specify the working directory of the command").option("
|
|
2006
|
+
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) => {
|
|
2231
2007
|
const options = AbstractCommand.mapToInput({
|
|
2232
2008
|
directory: rawOptions.directory,
|
|
2233
|
-
config: rawOptions.config,
|
|
2234
2009
|
clientEntry: rawOptions.clientEntry,
|
|
2235
2010
|
serverEntry: rawOptions.serverEntry,
|
|
2236
2011
|
clientStaticDir: rawOptions.clientStaticDir,
|
|
@@ -2248,13 +2023,11 @@ var BuildCommand = class extends AbstractCommand {
|
|
|
2248
2023
|
//#region src/command/commands/create.command.ts
|
|
2249
2024
|
var CreateCommand = class extends AbstractCommand {
|
|
2250
2025
|
load(program) {
|
|
2251
|
-
program.command("create <type>").description("create nanoforge components or systems").option("-d, --directory <directory>", "specify the working directory of the command").option("-
|
|
2026
|
+
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) => {
|
|
2252
2027
|
const args = AbstractCommand.mapToInput({ type });
|
|
2253
2028
|
const options = AbstractCommand.mapToInput({
|
|
2254
2029
|
directory: rawOptions.directory,
|
|
2255
|
-
config: rawOptions.config,
|
|
2256
2030
|
name: rawOptions.name,
|
|
2257
|
-
server: rawOptions.server,
|
|
2258
2031
|
path: rawOptions.path
|
|
2259
2032
|
});
|
|
2260
2033
|
await this.action.run(args, options);
|
|
@@ -2265,11 +2038,10 @@ var CreateCommand = class extends AbstractCommand {
|
|
|
2265
2038
|
//#region src/command/commands/dev.command.ts
|
|
2266
2039
|
var DevCommand = class extends AbstractCommand {
|
|
2267
2040
|
load(program) {
|
|
2268
|
-
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("
|
|
2041
|
+
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) => {
|
|
2269
2042
|
const options = AbstractCommand.mapToInput({
|
|
2270
2043
|
directory: rawOptions.directory,
|
|
2271
2044
|
config: rawOptions.config,
|
|
2272
|
-
generate: rawOptions.generate,
|
|
2273
2045
|
editor: rawOptions.editor
|
|
2274
2046
|
});
|
|
2275
2047
|
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
@@ -2291,21 +2063,6 @@ var EditorCommand = class extends AbstractCommand {
|
|
|
2291
2063
|
}
|
|
2292
2064
|
};
|
|
2293
2065
|
//#endregion
|
|
2294
|
-
//#region src/command/commands/generate.command.ts
|
|
2295
|
-
var GenerateCommand = class extends AbstractCommand {
|
|
2296
|
-
load(program) {
|
|
2297
|
-
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) => {
|
|
2298
|
-
const options = AbstractCommand.mapToInput({
|
|
2299
|
-
directory: rawOptions.directory,
|
|
2300
|
-
config: rawOptions.config,
|
|
2301
|
-
editor: rawOptions.editor,
|
|
2302
|
-
watch: rawOptions.watch
|
|
2303
|
-
});
|
|
2304
|
-
await this.action.run(/* @__PURE__ */ new Map(), options);
|
|
2305
|
-
});
|
|
2306
|
-
}
|
|
2307
|
-
};
|
|
2308
|
-
//#endregion
|
|
2309
2066
|
//#region src/command/commands/install.command.ts
|
|
2310
2067
|
var InstallCommand = class extends AbstractCommand {
|
|
2311
2068
|
load(program) {
|
|
@@ -2387,10 +2144,9 @@ var PublishCommand = class extends AbstractCommand {
|
|
|
2387
2144
|
//#region src/command/commands/start.command.ts
|
|
2388
2145
|
var StartCommand = class extends AbstractCommand {
|
|
2389
2146
|
load(program) {
|
|
2390
|
-
program.command("start").description("start your game").option("-d, --directory <directory>", "specify the working directory of the command").option("-
|
|
2147
|
+
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) => {
|
|
2391
2148
|
const options = AbstractCommand.mapToInput({
|
|
2392
2149
|
directory: rawOptions.directory,
|
|
2393
|
-
config: rawOptions.config,
|
|
2394
2150
|
port: rawOptions.port,
|
|
2395
2151
|
clientDir: rawOptions.clientDir,
|
|
2396
2152
|
serverDir: rawOptions.serverDir,
|
|
@@ -2422,7 +2178,6 @@ var CommandLoader = class {
|
|
|
2422
2178
|
new StartCommand(new StartAction()).load(program);
|
|
2423
2179
|
new DevCommand(new DevAction()).load(program);
|
|
2424
2180
|
new EditorCommand(new EditorAction()).load(program);
|
|
2425
|
-
new GenerateCommand(new GenerateAction()).load(program);
|
|
2426
2181
|
new CreateCommand(new CreateAction()).load(program);
|
|
2427
2182
|
new LoginCommand(new LoginAction()).load(program);
|
|
2428
2183
|
new LogoutCommand(new LogoutAction()).load(program);
|