@nanoforge-dev/schematics 2.1.2 → 2.1.4-beta.af6c1e0
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/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 +6 -13
- package/dist/libs/application/application.factory.d.ts.map +1 -0
- package/dist/libs/application/application.factory.js +49 -68
- package/dist/libs/application/application.factory.js.map +1 -1
- 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/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/files/js/__nanoforgeFolder__/client.save.json +2 -2
- package/dist/libs/part-base/files/js/__nanoforgeFolder__/server.save.json +2 -2
- package/dist/libs/part-base/files/js/__part__/components/example.component.js +21 -27
- package/dist/libs/part-base/files/ts/__nanoforgeFolder__/client.save.json +2 -2
- package/dist/libs/part-base/files/ts/__nanoforgeFolder__/server.save.json +2 -2
- package/dist/libs/part-base/files/ts/__part__/components/example.component.ts +21 -27
- 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 +225 -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,44 +1,33 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/libs/part-base/part-base.factory.ts
|
|
5
1
|
import { join, normalize, strings } from "@angular-devkit/core";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const splited = path2.split("/");
|
|
31
|
-
return splited.at(-2) !== ".nanoforge" || splited.at(-1) === `${options.part}.save.json`;
|
|
32
|
-
})
|
|
33
|
-
];
|
|
34
|
-
if (!initFunctions) rules.push(filter((path2) => path2.split("/").at(-2) !== "init"));
|
|
35
|
-
return apply(url(join("./files", language)), rules);
|
|
36
|
-
}, "generate");
|
|
37
|
-
var main = /* @__PURE__ */ __name((schema) => {
|
|
38
|
-
const options = transform(schema);
|
|
39
|
-
return mergeWith(generate(options, schema.directory, schema.initFunctions, schema.language));
|
|
40
|
-
}, "main");
|
|
41
|
-
export {
|
|
42
|
-
main
|
|
2
|
+
import { apply, filter, mergeWith, move, template, url } from "@angular-devkit/schematics";
|
|
3
|
+
//#region src/libs/part-base/part-base.factory.ts
|
|
4
|
+
const transform = (schema) => {
|
|
5
|
+
return {
|
|
6
|
+
part: schema.part,
|
|
7
|
+
server: schema.server,
|
|
8
|
+
appClass: schema.part === "client" ? "NanoforgeClient" : "NanoforgeServer",
|
|
9
|
+
nanoforgeFolder: ".nanoforge"
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const generate = (options, path, initFunctions, language) => {
|
|
13
|
+
const rules = [
|
|
14
|
+
template({
|
|
15
|
+
...strings,
|
|
16
|
+
...options
|
|
17
|
+
}),
|
|
18
|
+
move(normalize(path)),
|
|
19
|
+
filter((path) => {
|
|
20
|
+
const splited = path.split("/");
|
|
21
|
+
return splited.at(-2) !== ".nanoforge" || splited.at(-1) === `${options.part}.save.json`;
|
|
22
|
+
})
|
|
23
|
+
];
|
|
24
|
+
if (!initFunctions) rules.push(filter((path) => path.split("/").at(-2) !== "init"));
|
|
25
|
+
return apply(url(join("./files", language)), rules);
|
|
43
26
|
};
|
|
27
|
+
const main = (schema) => {
|
|
28
|
+
return mergeWith(generate(transform(schema), schema.directory, schema.initFunctions, schema.language));
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { main };
|
|
32
|
+
|
|
44
33
|
//# sourceMappingURL=part-base.factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/libs/part-base/part-base.factory.ts"],"sourcesContent":["import { type Path, join, normalize, strings } from \"@angular-devkit/core\";\nimport {\n type Rule,\n type Source,\n apply,\n filter,\n mergeWith,\n move,\n template,\n url,\n} from \"@angular-devkit/schematics\";\n\nimport { type PartBaseOptions } from \"./part-base.options\";\nimport { type PartBaseSchema } from \"./part-base.schema\";\n\nconst transform = (schema: PartBaseSchema): PartBaseOptions => {\n return {\n part: schema.part,\n server: schema.server,\n appClass: schema.part === \"client\" ? \"NanoforgeClient\" : \"NanoforgeServer\",\n nanoforgeFolder: \".nanoforge\",\n };\n};\n\nconst generate = (\n options: PartBaseOptions,\n path: string,\n initFunctions: boolean,\n language: \"ts\" | \"js\",\n): Source => {\n const rules = [\n template({\n ...strings,\n ...options,\n }),\n move(normalize(path)),\n filter((path) => {\n const splited = path.split(\"/\");\n return splited.at(-2) !== \".nanoforge\" || splited.at(-1) === `${options.part}.save.json`;\n }),\n ];\n if (!initFunctions) rules.push(filter((path) => path.split(\"/\").at(-2) !== \"init\"));\n\n return apply(url(join(\"./files\" as Path, language)), rules);\n};\n\nexport const main = (schema: PartBaseSchema): Rule => {\n const options = transform(schema);\n\n return mergeWith(generate(options, schema.directory, schema.initFunctions, schema.language));\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"part-base.factory.js","names":[],"sources":["../../../src/libs/part-base/part-base.factory.ts"],"sourcesContent":["import { type Path, join, normalize, strings } from \"@angular-devkit/core\";\nimport {\n type Rule,\n type Source,\n apply,\n filter,\n mergeWith,\n move,\n template,\n url,\n} from \"@angular-devkit/schematics\";\n\nimport { type PartBaseOptions } from \"./part-base.options\";\nimport { type PartBaseSchema } from \"./part-base.schema\";\n\nconst transform = (schema: PartBaseSchema): PartBaseOptions => {\n return {\n part: schema.part,\n server: schema.server,\n appClass: schema.part === \"client\" ? \"NanoforgeClient\" : \"NanoforgeServer\",\n nanoforgeFolder: \".nanoforge\",\n };\n};\n\nconst generate = (\n options: PartBaseOptions,\n path: string,\n initFunctions: boolean,\n language: \"ts\" | \"js\",\n): Source => {\n const rules = [\n template({\n ...strings,\n ...options,\n }),\n move(normalize(path)),\n filter((path) => {\n const splited = path.split(\"/\");\n return splited.at(-2) !== \".nanoforge\" || splited.at(-1) === `${options.part}.save.json`;\n }),\n ];\n if (!initFunctions) rules.push(filter((path) => path.split(\"/\").at(-2) !== \"init\"));\n\n return apply(url(join(\"./files\" as Path, language)), rules);\n};\n\nexport const main = (schema: PartBaseSchema): Rule => {\n const options = transform(schema);\n\n return mergeWith(generate(options, schema.directory, schema.initFunctions, schema.language));\n};\n"],"mappings":";;;AAeA,MAAM,aAAa,WAA4C;CAC7D,OAAO;EACL,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,UAAU,OAAO,SAAS,WAAW,oBAAoB;EACzD,iBAAiB;CACnB;AACF;AAEA,MAAM,YACJ,SACA,MACA,eACA,aACW;CACX,MAAM,QAAQ;EACZ,SAAS;GACP,GAAG;GACH,GAAG;EACL,CAAC;EACD,KAAK,UAAU,IAAI,CAAC;EACpB,QAAQ,SAAS;GACf,MAAM,UAAU,KAAK,MAAM,GAAG;GAC9B,OAAO,QAAQ,GAAG,EAAE,MAAM,gBAAgB,QAAQ,GAAG,EAAE,MAAM,GAAG,QAAQ,KAAK;EAC/E,CAAC;CACH;CACA,IAAI,CAAC,eAAe,MAAM,KAAK,QAAQ,SAAS,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;CAElF,OAAO,MAAM,IAAI,KAAK,WAAmB,QAAQ,CAAC,GAAG,KAAK;AAC5D;AAEA,MAAa,QAAQ,WAAiC;CAGpD,OAAO,UAAU,SAFD,UAAU,MAEA,GAAS,OAAO,WAAW,OAAO,eAAe,OAAO,QAAQ,CAAC;AAC7F"}
|
|
@@ -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,231 @@
|
|
|
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
|
-
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 }) => this.writeLine(`import { ${name} } from "${relative ? joinRelative(this.pathToRoot, path) : path}";`));
|
|
154
|
+
this.endSection();
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
generateEntity(components, entity, entityIndex) {
|
|
158
|
+
this.writeLine(`const ${entity.id} = registry.spawnEntity();`);
|
|
159
|
+
Object.entries(entity.components).forEach(([componentName, rawParams]) => {
|
|
160
|
+
const originalsParams = components.find(({ name }) => name === componentName)?.paramsNames;
|
|
161
|
+
if (!originalsParams) throw new Error("Missing component in entity or inexistent saved component");
|
|
162
|
+
const params = !this.editor ? Object.values(originalsParams).map((ogParam) => {
|
|
163
|
+
return getStringParam(rawParams[ogParam]);
|
|
164
|
+
}) : Object.values(originalsParams).map((ogParam) => {
|
|
165
|
+
return `options.editor.save.entities[${entityIndex}].components["${componentName}"]["${ogParam}"]`;
|
|
166
|
+
});
|
|
167
|
+
this.writeLine(`registry.addComponent(${entity.id}, new ${componentName}(${params.join(", ")}));`);
|
|
168
|
+
});
|
|
169
|
+
if (this.editor) this.writeLine(`registry.addComponent(${entity.id}, { name: "__RESERVED_entityId", entityId: "${entity.id}" });`);
|
|
170
|
+
this.endSection();
|
|
171
|
+
}
|
|
172
|
+
getInitFunction(name, type) {
|
|
173
|
+
const baseName = LIBS_FUNCTIONS_NAME[type];
|
|
174
|
+
if (baseName) return `app.${baseName}(${name});`;
|
|
175
|
+
return `app.use(Symbol("${type}"), ${name});`;
|
|
176
|
+
}
|
|
177
|
+
writeLine(text, indentation = true) {
|
|
178
|
+
const line = `${" ".repeat(indentation ? this.indentation * 2 : 0)}${text}\n`;
|
|
179
|
+
this.buffer += line;
|
|
180
|
+
}
|
|
181
|
+
endSection() {
|
|
182
|
+
this.writeLine("");
|
|
183
|
+
}
|
|
205
184
|
};
|
|
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
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/utils/main/main-functions.ts
|
|
187
|
+
const generateMain = (options, save) => {
|
|
188
|
+
const isServer = options.part === "server";
|
|
189
|
+
const hasTypes = options.language === "ts";
|
|
190
|
+
const initFunctions = options.initFunctions;
|
|
191
|
+
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) => {
|
|
192
|
+
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");
|
|
193
|
+
}).toString();
|
|
194
|
+
};
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/libs/part-main/part-main.factory.ts
|
|
197
|
+
const transform = (schema) => {
|
|
198
|
+
return {};
|
|
199
|
+
};
|
|
200
|
+
const generate = (options, path, schema) => {
|
|
201
|
+
const rules = [template({
|
|
202
|
+
...strings,
|
|
203
|
+
...options
|
|
204
|
+
}), move(normalize(path))];
|
|
205
|
+
return apply(asSource(writeMain(schema, path)), rules);
|
|
206
|
+
};
|
|
207
|
+
const getMainPath = (schema) => {
|
|
208
|
+
if (schema.outFile) return schema.outFile;
|
|
209
|
+
if (schema.editor) return join(".nanoforge/editor", schema.part, `main.${schema.language}`);
|
|
210
|
+
return join(schema.part, `main.${schema.language}`);
|
|
265
211
|
};
|
|
212
|
+
const writeMain = (schema, path) => {
|
|
213
|
+
return (tree) => {
|
|
214
|
+
const save = getSave(path, schema.part, schema.saveFile);
|
|
215
|
+
const resPath = getMainPath(schema);
|
|
216
|
+
const content = generateMain(schema, save);
|
|
217
|
+
fs.rmSync(join(path, resPath), { force: true });
|
|
218
|
+
tree.create(resPath, content);
|
|
219
|
+
return tree;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
const getSave = (path, part, saveFile) => {
|
|
223
|
+
return JSON.parse(fs.readFileSync(saveFile ?? join(path, `.nanoforge/${part}.save.json`), "utf-8"));
|
|
224
|
+
};
|
|
225
|
+
const main = (schema) => {
|
|
226
|
+
return mergeWith(generate(transform(schema), schema.directory, schema));
|
|
227
|
+
};
|
|
228
|
+
//#endregion
|
|
229
|
+
export { main };
|
|
230
|
+
|
|
266
231
|
//# sourceMappingURL=part-main.factory.js.map
|