@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.
- package/README.md +3 -0
- package/dist/index.cjs +15 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -15
- package/dist/index.js.map +1 -1
- package/dist/libs/application/application.factory.d.ts +10 -13
- package/dist/libs/application/application.factory.d.ts.map +1 -0
- package/dist/libs/application/application.factory.js +52 -68
- package/dist/libs/application/application.factory.js.map +1 -1
- package/dist/libs/application/files/js/README.md +165 -0
- package/dist/libs/application/files/js/__dot__env +6 -0
- package/dist/libs/application/files/js/__dot__gitignore +134 -0
- package/dist/libs/application/files/ts/README.md +165 -0
- package/dist/libs/application/files/ts/__dot__env +6 -0
- package/dist/libs/application/files/ts/__dot__gitignore +134 -0
- package/dist/libs/application/schema.json +5 -0
- package/dist/libs/component/component.factory.d.ts +6 -6
- package/dist/libs/component/component.factory.d.ts.map +1 -0
- package/dist/libs/component/component.factory.js +32 -47
- package/dist/libs/component/component.factory.js.map +1 -1
- package/dist/libs/component/files/js/__fileName__.component.js +21 -27
- package/dist/libs/component/files/ts/__fileName__.component.ts +21 -27
- package/dist/libs/configuration/configuration.factory.d.ts +6 -7
- package/dist/libs/configuration/configuration.factory.d.ts.map +1 -0
- package/dist/libs/configuration/configuration.factory.js +91 -133
- package/dist/libs/configuration/configuration.factory.js.map +1 -1
- package/dist/libs/docker/docker.factory.d.ts +6 -4
- package/dist/libs/docker/docker.factory.d.ts.map +1 -0
- package/dist/libs/docker/docker.factory.js +17 -36
- package/dist/libs/docker/docker.factory.js.map +1 -1
- package/dist/libs/part-base/part-base.factory.d.ts +6 -7
- package/dist/libs/part-base/part-base.factory.d.ts.map +1 -0
- package/dist/libs/part-base/part-base.factory.js +30 -41
- package/dist/libs/part-base/part-base.factory.js.map +1 -1
- package/dist/libs/part-main/part-main.factory.d.ts +6 -9
- package/dist/libs/part-main/part-main.factory.d.ts.map +1 -0
- package/dist/libs/part-main/part-main.factory.js +228 -260
- package/dist/libs/part-main/part-main.factory.js.map +1 -1
- package/dist/libs/system/system.factory.d.ts +6 -6
- package/dist/libs/system/system.factory.d.ts.map +1 -0
- package/dist/libs/system/system.factory.js +32 -50
- package/dist/libs/system/system.factory.js.map +1 -1
- package/package.json +18 -18
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
import { Rule } from
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|