@nanoforge-dev/schematics 2.1.3 → 2.1.4-beta.131e794

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.
Files changed (47) hide show
  1. package/README.md +3 -0
  2. package/dist/index.cjs +15 -46
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +3 -1
  5. package/dist/index.d.cts.map +1 -0
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +10 -15
  9. package/dist/index.js.map +1 -1
  10. package/dist/libs/application/application.factory.d.ts +10 -13
  11. package/dist/libs/application/application.factory.d.ts.map +1 -0
  12. package/dist/libs/application/application.factory.js +52 -68
  13. package/dist/libs/application/application.factory.js.map +1 -1
  14. package/dist/libs/application/files/js/README.md +165 -0
  15. package/dist/libs/application/files/js/__dot__env +6 -0
  16. package/dist/libs/application/files/js/__dot__gitignore +134 -0
  17. package/dist/libs/application/files/ts/README.md +165 -0
  18. package/dist/libs/application/files/ts/__dot__env +6 -0
  19. package/dist/libs/application/files/ts/__dot__gitignore +134 -0
  20. package/dist/libs/application/schema.json +5 -0
  21. package/dist/libs/component/component.factory.d.ts +6 -6
  22. package/dist/libs/component/component.factory.d.ts.map +1 -0
  23. package/dist/libs/component/component.factory.js +32 -47
  24. package/dist/libs/component/component.factory.js.map +1 -1
  25. package/dist/libs/component/files/js/__fileName__.component.js +21 -27
  26. package/dist/libs/component/files/ts/__fileName__.component.ts +21 -27
  27. package/dist/libs/configuration/configuration.factory.d.ts +6 -7
  28. package/dist/libs/configuration/configuration.factory.d.ts.map +1 -0
  29. package/dist/libs/configuration/configuration.factory.js +91 -133
  30. package/dist/libs/configuration/configuration.factory.js.map +1 -1
  31. package/dist/libs/docker/docker.factory.d.ts +6 -4
  32. package/dist/libs/docker/docker.factory.d.ts.map +1 -0
  33. package/dist/libs/docker/docker.factory.js +17 -36
  34. package/dist/libs/docker/docker.factory.js.map +1 -1
  35. package/dist/libs/part-base/part-base.factory.d.ts +6 -7
  36. package/dist/libs/part-base/part-base.factory.d.ts.map +1 -0
  37. package/dist/libs/part-base/part-base.factory.js +30 -41
  38. package/dist/libs/part-base/part-base.factory.js.map +1 -1
  39. package/dist/libs/part-main/part-main.factory.d.ts +6 -9
  40. package/dist/libs/part-main/part-main.factory.d.ts.map +1 -0
  41. package/dist/libs/part-main/part-main.factory.js +228 -260
  42. package/dist/libs/part-main/part-main.factory.js.map +1 -1
  43. package/dist/libs/system/system.factory.d.ts +6 -6
  44. package/dist/libs/system/system.factory.d.ts.map +1 -0
  45. package/dist/libs/system/system.factory.js +32 -50
  46. package/dist/libs/system/system.factory.js.map +1 -1
  47. package/package.json +18 -18
@@ -1,42 +1,39 @@
1
- import { Rule } from '@angular-devkit/schematics';
1
+ import { Rule } from "@angular-devkit/schematics";
2
2
 
3
+ //#region src/libs/part-main/part-main.schema.d.ts
3
4
  interface PartMainSchema {
4
5
  /**
5
6
  * NanoForge application destination directory
6
7
  */
7
8
  directory: string;
8
-
9
9
  /**
10
10
  * The part of the application to generate
11
11
  */
12
12
  part: "client" | "server";
13
-
14
13
  /**
15
14
  * NanoForge Application language
16
15
  */
17
16
  language: "js" | "ts";
18
-
19
17
  /**
20
18
  * Add init functions to the application
21
19
  */
22
20
  initFunctions: boolean;
23
-
24
21
  /**
25
22
  * Save file path with components and systems in JSON format
26
23
  */
27
24
  saveFile?: string;
28
-
29
25
  /**
30
26
  * Path of the out file
31
27
  */
32
28
  outFile?: string;
33
-
34
29
  /**
35
30
  * Build main editor
36
31
  */
37
32
  editor: boolean;
38
33
  }
39
-
34
+ //#endregion
35
+ //#region src/libs/part-main/part-main.factory.d.ts
40
36
  declare const main: (schema: PartMainSchema) => Rule;
41
-
37
+ //#endregion
42
38
  export { main };
39
+ //# sourceMappingURL=part-main.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"part-main.factory.d.ts","names":["directory","part","language","initFunctions","saveFile","outFile","editor"],"sources":["../../../src/libs/part-main/part-main.schema.d.ts","../../../src/libs/part-main/part-main.factory.ts"],"mappings":";;;UAAiB,cAAA;;;AAAjB;EAIEA,SAAAA;EAJ6B;;;EAS7BC,IAAAA;EAeAG;;;EAVAF,QAAAA;;;;EAKAC,aAAAA;;;;EAKAC,QAAAA;EC2CD;AAAA;;EDtCCC,OAAAA;;;;EAKAC,MAAAA;AAAAA;;;cC6BW,IAAA,GAAQ,MAAA,EAAQ,cAAA,KAAiB,IAI7C"}
@@ -1,266 +1,234 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/libs/part-main/part-main.factory.ts
5
- import { join as join3, normalize, strings } from "@angular-devkit/core";
6
- import {
7
- apply,
8
- asSource,
9
- mergeWith,
10
- move,
11
- template
12
- } from "@angular-devkit/schematics";
1
+ import { join, normalize, strings } from "@angular-devkit/core";
2
+ import { apply, asSource, mergeWith, move, template } from "@angular-devkit/schematics";
13
3
  import * as fs from "fs";
14
-
15
- // src/utils/main/main-functions.ts
16
- import { join as join2 } from "path";
17
-
18
- // src/utils/path.ts
19
- import { join } from "path";
20
- var joinRelative = /* @__PURE__ */ __name((...paths) => {
21
- const path = join(...paths);
22
- return path.startsWith("./") || path.startsWith("../") ? path : `./${path}`;
23
- }, "joinRelative");
24
-
25
- // src/utils/main/const.ts
26
- var LIBS_FUNCTIONS_NAME = {
27
- ["asset-manager" /* ASSET_MANAGER */]: "useAssetManager",
28
- ["component-system" /* COMPONENT_SYSTEM */]: "useComponentSystem",
29
- ["graphics" /* GRAPHICS */]: "useGraphics",
30
- ["input" /* INPUT */]: "useInput",
31
- ["network" /* NETWORK */]: "useNetwork",
32
- ["sound" /* SOUND */]: "useSound"
4
+ import { join as join$1 } from "path";
5
+ //#endregion
6
+ //#region src/utils/path.ts
7
+ const joinRelative = (...paths) => {
8
+ const path = join$1(...paths);
9
+ return path.startsWith("./") || path.startsWith("../") ? path : `./${path}`;
33
10
  };
34
-
35
- // src/utils/main/main-utils.ts
36
- var getStringParam = /* @__PURE__ */ __name((value) => {
37
- if (typeof value === "string") return `"${value}"`;
38
- if (typeof value === "number") return value.toString();
39
- if (typeof value === "boolean") return value ? "true" : "false";
40
- if (typeof value === "object") return JSON.stringify(value);
41
- return "undefined";
42
- }, "getStringParam");
43
-
44
- // src/utils/main/main.generator.ts
11
+ //#endregion
12
+ //#region src/utils/main/const.ts
13
+ const LIBS_FUNCTIONS_NAME = {
14
+ ["asset-manager"]: "useAssetManager",
15
+ ["component-system"]: "useComponentSystem",
16
+ ["graphics"]: "useGraphics",
17
+ ["input"]: "useInput",
18
+ ["network"]: "useNetwork",
19
+ ["sound"]: "useSound"
20
+ };
21
+ //#endregion
22
+ //#region src/utils/main/main-utils.ts
23
+ const getStringParam = (value) => {
24
+ if (typeof value === "string") return `"${value}"`;
25
+ if (typeof value === "number") return value.toString();
26
+ if (typeof value === "boolean") return value ? "true" : "false";
27
+ if (typeof value === "object") return JSON.stringify(value);
28
+ return "undefined";
29
+ };
30
+ //#endregion
31
+ //#region src/utils/main/main.generator.ts
45
32
  var MainGenerator = class {
46
- static {
47
- __name(this, "MainGenerator");
48
- }
49
- buffer = "";
50
- indentation = 0;
51
- editor;
52
- pathToRoot;
53
- constructor(editor = false, pathToRoot = "") {
54
- this.editor = editor;
55
- this.pathToRoot = pathToRoot;
56
- }
57
- toString() {
58
- return this.buffer;
59
- }
60
- generateBaseImports(hasTypes) {
61
- if (this.editor) {
62
- if (hasTypes)
63
- this.writeLine(
64
- `import { type IEditorRunOptions, NanoforgeFactory } from "@nanoforge-dev/core-editor";`
65
- );
66
- else this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core-editor";`);
67
- } else {
68
- if (hasTypes) this.writeLine(`import { type IRunOptions } from "@nanoforge-dev/common";`);
69
- this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core";`);
70
- }
71
- this.endSection();
72
- return this;
73
- }
74
- generateLibsImports(libs) {
75
- return this.generateImports(libs, false);
76
- }
77
- generateComponentsImports(libs) {
78
- return this.generateImports(libs, true);
79
- }
80
- generateSystemsImports(libs) {
81
- return this.generateImports(libs, true);
82
- }
83
- generateMainFunction(hasTypes, cb) {
84
- if (this.editor)
85
- this.writeLine(
86
- `export async function main(options${hasTypes ? ": IEditorRunOptions" : ""}) {`
87
- );
88
- else this.writeLine(`export async function main(options${hasTypes ? ": IRunOptions" : ""}) {`);
89
- this.indentation += 1;
90
- cb(this);
91
- this.indentation -= 1;
92
- this.writeLine("}");
93
- return this;
94
- }
95
- generateApp(isServer) {
96
- this.writeLine(`const app = NanoforgeFactory.create${isServer ? "Server" : "Client"}();`);
97
- this.endSection();
98
- return this;
99
- }
100
- generateAppInit() {
101
- this.writeLine(`await app.init(options);`);
102
- this.endSection();
103
- return this;
104
- }
105
- generateAppRun(hasInitFunctions) {
106
- this.writeLine(`await app.run();`);
107
- if (hasInitFunctions) this.endSection();
108
- return this;
109
- }
110
- generateLibsInstances(libs) {
111
- libs.forEach(({ id, name }) => this.writeLine(`const ${id} = new ${name}();`));
112
- this.endSection();
113
- return this;
114
- }
115
- generateLibsInit(libs) {
116
- libs.forEach(({ id, type }) => this.writeLine(this.getInitFunction(id, type)));
117
- this.endSection();
118
- return this;
119
- }
120
- generateRegistry(libs) {
121
- const libName = libs.find((lib) => lib.type === "component-system" /* COMPONENT_SYSTEM */)?.id ?? "ecsLibrary";
122
- this.writeLine(`const registry = ${libName}.registry;`);
123
- this.endSection();
124
- return this;
125
- }
126
- generateEntities(components, entities) {
127
- entities.forEach((entity, index) => this.generateEntity(components, entity, index));
128
- return this;
129
- }
130
- generateSystems(systems) {
131
- systems.forEach(({ name }) => this.writeLine(`registry.addSystem(${name});`));
132
- this.endSection();
133
- return this;
134
- }
135
- generateInitFunctionIfNeeded(needed, func) {
136
- if (needed) return this.generateInitFunction(func);
137
- return this;
138
- }
139
- generateInitFunctionsImportsIfNeeded(needed) {
140
- if (!needed) return this;
141
- return this.generateImports(
142
- [
143
- { name: "afterInit", path: "./init/after-init" },
144
- { name: "afterRegistryInit", path: "./init/after-registry-init" },
145
- { name: "afterRun", path: "./init/after-run" },
146
- { name: "beforeInit", path: "./init/before-init" },
147
- { name: "beforeRegistryInit", path: "./init/before-registry-init" },
148
- { name: "beforeRun", path: "./init/before-run" }
149
- ],
150
- true
151
- );
152
- }
153
- generateInitFunction(func) {
154
- const params = ["app"];
155
- if (["beforeRegistryInit" /* BEFORE_REGISTRY_INIT */, "afterRegistryInit" /* AFTER_REGISTRY_INIT */].includes(func))
156
- params.push("registry");
157
- this.writeLine(`await ${func}(${params.join(", ")});`);
158
- if (func !== "afterRun" /* AFTER_RUN */) this.endSection();
159
- return this;
160
- }
161
- generateImports(els, relative) {
162
- els.sort((a, b) => a.path.localeCompare(b.path)).forEach(
163
- ({ name, path }) => this.writeLine(
164
- `import { ${name} } from "${relative ? joinRelative(this.pathToRoot, path) : path}";`
165
- )
166
- );
167
- this.endSection();
168
- return this;
169
- }
170
- generateEntity(components, entity, entityIndex) {
171
- this.writeLine(`const ${entity.id} = registry.spawnEntity();`);
172
- Object.entries(entity.components).forEach(([componentName, rawParams]) => {
173
- const originalsParams = components.find(({ name }) => name === componentName)?.paramsNames;
174
- if (!originalsParams)
175
- throw new Error("Missing component in entity or inexistent saved component");
176
- const params = !this.editor ? Object.values(originalsParams).map((ogParam) => {
177
- return getStringParam(rawParams[ogParam]);
178
- }) : Object.values(originalsParams).map((ogParam) => {
179
- return `options.editor.save.entities[${entityIndex}].components["${componentName}"]["${ogParam}"]`;
180
- });
181
- this.writeLine(
182
- `registry.addComponent(${entity.id}, new ${componentName}(${params.join(", ")}));`
183
- );
184
- });
185
- if (this.editor) {
186
- this.writeLine(
187
- `registry.addComponent(${entity.id}, { name: "__RESERVED_entityId", entityId: "${entity.id}" });`
188
- );
189
- }
190
- this.endSection();
191
- }
192
- getInitFunction(name, type) {
193
- const baseName = LIBS_FUNCTIONS_NAME[type];
194
- if (baseName) return `app.${baseName}(${name});`;
195
- return `app.use(Symbol("${type}"), ${name});`;
196
- }
197
- writeLine(text, indentation = true) {
198
- const line = `${" ".repeat(indentation ? this.indentation * 2 : 0)}${text}
199
- `;
200
- this.buffer += line;
201
- }
202
- endSection() {
203
- this.writeLine("");
204
- }
33
+ buffer = "";
34
+ indentation = 0;
35
+ editor;
36
+ pathToRoot;
37
+ constructor(editor = false, pathToRoot = "") {
38
+ this.editor = editor;
39
+ this.pathToRoot = pathToRoot;
40
+ }
41
+ toString() {
42
+ return this.buffer;
43
+ }
44
+ generateBaseImports(hasTypes) {
45
+ if (this.editor) if (hasTypes) this.writeLine(`import { type IEditorRunOptions, NanoforgeFactory } from "@nanoforge-dev/core-editor";`);
46
+ else this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core-editor";`);
47
+ else {
48
+ if (hasTypes) this.writeLine(`import { type IRunOptions } from "@nanoforge-dev/common";`);
49
+ this.writeLine(`import { NanoforgeFactory } from "@nanoforge-dev/core";`);
50
+ }
51
+ this.endSection();
52
+ return this;
53
+ }
54
+ generateLibsImports(libs) {
55
+ return this.generateImports(libs, false);
56
+ }
57
+ generateComponentsImports(libs) {
58
+ return this.generateImports(libs, true);
59
+ }
60
+ generateSystemsImports(libs) {
61
+ return this.generateImports(libs, true);
62
+ }
63
+ generateMainFunction(hasTypes, cb) {
64
+ if (this.editor) this.writeLine(`export async function main(options${hasTypes ? ": IEditorRunOptions" : ""}) {`);
65
+ else this.writeLine(`export async function main(options${hasTypes ? ": IRunOptions" : ""}) {`);
66
+ this.indentation += 1;
67
+ cb(this);
68
+ this.indentation -= 1;
69
+ this.writeLine("}");
70
+ return this;
71
+ }
72
+ generateApp(isServer) {
73
+ this.writeLine(`const app = NanoforgeFactory.create${isServer ? "Server" : "Client"}();`);
74
+ this.endSection();
75
+ return this;
76
+ }
77
+ generateAppInit() {
78
+ this.writeLine(`await app.init(options);`);
79
+ this.endSection();
80
+ return this;
81
+ }
82
+ generateAppRun(hasInitFunctions) {
83
+ this.writeLine(`await app.run();`);
84
+ if (hasInitFunctions) this.endSection();
85
+ return this;
86
+ }
87
+ generateLibsInstances(libs) {
88
+ libs.forEach(({ id, name }) => this.writeLine(`const ${id} = new ${name}();`));
89
+ this.endSection();
90
+ return this;
91
+ }
92
+ generateLibsInit(libs) {
93
+ libs.forEach(({ id, type }) => this.writeLine(this.getInitFunction(id, type)));
94
+ this.endSection();
95
+ return this;
96
+ }
97
+ generateRegistry(libs) {
98
+ const libName = libs.find((lib) => lib.type === "component-system")?.id ?? "ecsLibrary";
99
+ this.writeLine(`const registry = ${libName}.registry;`);
100
+ this.endSection();
101
+ return this;
102
+ }
103
+ generateEntities(components, entities) {
104
+ entities.forEach((entity, index) => this.generateEntity(components, entity, index));
105
+ return this;
106
+ }
107
+ generateSystems(systems) {
108
+ systems.forEach(({ name }) => this.writeLine(`registry.addSystem(${name});`));
109
+ this.endSection();
110
+ return this;
111
+ }
112
+ generateInitFunctionIfNeeded(needed, func) {
113
+ if (needed) return this.generateInitFunction(func);
114
+ return this;
115
+ }
116
+ generateInitFunctionsImportsIfNeeded(needed) {
117
+ if (!needed) return this;
118
+ return this.generateImports([
119
+ {
120
+ name: "afterInit",
121
+ path: "./init/after-init"
122
+ },
123
+ {
124
+ name: "afterRegistryInit",
125
+ path: "./init/after-registry-init"
126
+ },
127
+ {
128
+ name: "afterRun",
129
+ path: "./init/after-run"
130
+ },
131
+ {
132
+ name: "beforeInit",
133
+ path: "./init/before-init"
134
+ },
135
+ {
136
+ name: "beforeRegistryInit",
137
+ path: "./init/before-registry-init"
138
+ },
139
+ {
140
+ name: "beforeRun",
141
+ path: "./init/before-run"
142
+ }
143
+ ], true);
144
+ }
145
+ generateInitFunction(func) {
146
+ const params = ["app"];
147
+ if (["beforeRegistryInit", "afterRegistryInit"].includes(func)) params.push("registry");
148
+ this.writeLine(`await ${func}(${params.join(", ")});`);
149
+ if (func !== "afterRun") this.endSection();
150
+ return this;
151
+ }
152
+ generateImports(els, relative) {
153
+ els.sort((a, b) => a.path.localeCompare(b.path)).forEach(({ name, path }) => {
154
+ path = path.replace(/\.(?:ts|js)$/, "");
155
+ this.writeLine(`import { ${name} } from "${relative ? joinRelative(this.pathToRoot, path) : path}";`);
156
+ });
157
+ this.endSection();
158
+ return this;
159
+ }
160
+ generateEntity(components, entity, entityIndex) {
161
+ this.writeLine(`const ${entity.id} = registry.spawnEntity();`);
162
+ Object.entries(entity.components).forEach(([componentName, rawParams]) => {
163
+ const originalsParams = components.find(({ name }) => name === componentName)?.paramsNames;
164
+ if (!originalsParams) throw new Error("Missing component in entity or inexistent saved component");
165
+ const params = !this.editor ? Object.values(originalsParams).map((ogParam) => {
166
+ return getStringParam(rawParams[ogParam]);
167
+ }) : Object.values(originalsParams).map((ogParam) => {
168
+ return `options.editor.save.entities[${entityIndex}].components["${componentName}"]["${ogParam}"]`;
169
+ });
170
+ this.writeLine(`registry.addComponent(${entity.id}, new ${componentName}(${params.join(", ")}));`);
171
+ });
172
+ if (this.editor) this.writeLine(`registry.addComponent(${entity.id}, { name: "__RESERVED_entityId", entityId: "${entity.id}" });`);
173
+ this.endSection();
174
+ }
175
+ getInitFunction(name, type) {
176
+ const baseName = LIBS_FUNCTIONS_NAME[type];
177
+ if (baseName) return `app.${baseName}(${name});`;
178
+ return `app.use(Symbol("${type}"), ${name});`;
179
+ }
180
+ writeLine(text, indentation = true) {
181
+ const line = `${" ".repeat(indentation ? this.indentation * 2 : 0)}${text}\n`;
182
+ this.buffer += line;
183
+ }
184
+ endSection() {
185
+ this.writeLine("");
186
+ }
205
187
  };
206
-
207
- // src/utils/main/main-functions.ts
208
- var generateMain = /* @__PURE__ */ __name((options, save) => {
209
- const isServer = options.part === "server";
210
- const hasTypes = options.language === "ts";
211
- const initFunctions = options.initFunctions;
212
- return (!options.editor ? new MainGenerator() : new MainGenerator(
213
- true,
214
- join2(
215
- "../".repeat(options.outFile ? options.outFile.split("/").length - 1 : 3),
216
- options.part
217
- )
218
- )).generateBaseImports(hasTypes).generateLibsImports(save.libraries).generateInitFunctionsImportsIfNeeded(initFunctions).generateComponentsImports(save.components).generateSystemsImports(save.systems).generateMainFunction(hasTypes, (generator) => {
219
- generator.generateApp(isServer).generateLibsInstances(save.libraries).generateLibsInit(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeInit" /* BEFORE_INIT */).generateAppInit().generateInitFunctionIfNeeded(initFunctions, "afterInit" /* AFTER_INIT */).generateRegistry(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeRegistryInit" /* BEFORE_REGISTRY_INIT */).generateEntities(save.components, save.entities).generateSystems(save.systems).generateInitFunctionIfNeeded(initFunctions, "afterRegistryInit" /* AFTER_REGISTRY_INIT */).generateInitFunctionIfNeeded(initFunctions, "beforeRun" /* BEFORE_RUN */).generateAppRun(initFunctions).generateInitFunctionIfNeeded(initFunctions, "afterRun" /* AFTER_RUN */);
220
- }).toString();
221
- }, "generateMain");
222
-
223
- // src/libs/part-main/part-main.factory.ts
224
- var transform = /* @__PURE__ */ __name((schema) => {
225
- void schema;
226
- return {};
227
- }, "transform");
228
- var generate = /* @__PURE__ */ __name((options, path, schema) => {
229
- const rules = [
230
- template({
231
- ...strings,
232
- ...options
233
- }),
234
- move(normalize(path))
235
- ];
236
- return apply(asSource(writeMain(schema, path)), rules);
237
- }, "generate");
238
- var getMainPath = /* @__PURE__ */ __name((schema) => {
239
- if (schema.outFile) return schema.outFile;
240
- if (schema.editor)
241
- return join3(".nanoforge/editor", schema.part, `main.${schema.language}`);
242
- return join3(schema.part, `main.${schema.language}`);
243
- }, "getMainPath");
244
- var writeMain = /* @__PURE__ */ __name((schema, path) => {
245
- return (tree) => {
246
- const save = getSave(path, schema.part, schema.saveFile);
247
- const resPath = getMainPath(schema);
248
- const content = generateMain(schema, save);
249
- fs.rmSync(join3(path, resPath), { force: true });
250
- tree.create(resPath, content);
251
- return tree;
252
- };
253
- }, "writeMain");
254
- var getSave = /* @__PURE__ */ __name((path, part, saveFile) => {
255
- return JSON.parse(
256
- fs.readFileSync(saveFile ?? join3(path, `.nanoforge/${part}.save.json`), "utf-8")
257
- );
258
- }, "getSave");
259
- var main = /* @__PURE__ */ __name((schema) => {
260
- const options = transform(schema);
261
- return mergeWith(generate(options, schema.directory, schema));
262
- }, "main");
263
- export {
264
- main
188
+ //#endregion
189
+ //#region src/utils/main/main-functions.ts
190
+ const generateMain = (options, save) => {
191
+ const isServer = options.part === "server";
192
+ const hasTypes = options.language === "ts";
193
+ const initFunctions = options.initFunctions;
194
+ return (!options.editor ? new MainGenerator() : new MainGenerator(true, join$1("../".repeat(options.outFile ? options.outFile.split("/").length - 1 : 3), options.part))).generateBaseImports(hasTypes).generateLibsImports(save.libraries).generateInitFunctionsImportsIfNeeded(initFunctions).generateComponentsImports(save.components).generateSystemsImports(save.systems).generateMainFunction(hasTypes, (generator) => {
195
+ generator.generateApp(isServer).generateLibsInstances(save.libraries).generateLibsInit(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeInit").generateAppInit().generateInitFunctionIfNeeded(initFunctions, "afterInit").generateRegistry(save.libraries).generateInitFunctionIfNeeded(initFunctions, "beforeRegistryInit").generateEntities(save.components, save.entities).generateSystems(save.systems).generateInitFunctionIfNeeded(initFunctions, "afterRegistryInit").generateInitFunctionIfNeeded(initFunctions, "beforeRun").generateAppRun(initFunctions).generateInitFunctionIfNeeded(initFunctions, "afterRun");
196
+ }).toString();
197
+ };
198
+ //#endregion
199
+ //#region src/libs/part-main/part-main.factory.ts
200
+ const transform = (schema) => {
201
+ return {};
202
+ };
203
+ const generate = (options, path, schema) => {
204
+ const rules = [template({
205
+ ...strings,
206
+ ...options
207
+ }), move(normalize(path))];
208
+ return apply(asSource(writeMain(schema, path)), rules);
209
+ };
210
+ const getMainPath = (schema) => {
211
+ if (schema.outFile) return schema.outFile;
212
+ if (schema.editor) return join(".nanoforge/editor", schema.part, `main.${schema.language}`);
213
+ return join(schema.part, `main.${schema.language}`);
265
214
  };
215
+ const writeMain = (schema, path) => {
216
+ return (tree) => {
217
+ const save = getSave(path, schema.part, schema.saveFile);
218
+ const resPath = getMainPath(schema);
219
+ const content = generateMain(schema, save);
220
+ fs.rmSync(join(path, resPath), { force: true });
221
+ tree.create(resPath, content);
222
+ return tree;
223
+ };
224
+ };
225
+ const getSave = (path, part, saveFile) => {
226
+ return JSON.parse(fs.readFileSync(saveFile ?? join(path, `.nanoforge/${part}.save.json`), "utf-8"));
227
+ };
228
+ const main = (schema) => {
229
+ return mergeWith(generate(transform(schema), schema.directory, schema));
230
+ };
231
+ //#endregion
232
+ export { main };
233
+
266
234
  //# sourceMappingURL=part-main.factory.js.map