@cocos/ccbuild 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +12 -0
- package/README.md +14 -14
- package/lib/api-builder.d.ts +1 -0
- package/lib/api-builder.d.ts.map +1 -0
- package/lib/api-builder.js +1 -1
- package/lib/build-engine/engine-js/index.d.ts +3 -0
- package/lib/build-engine/engine-js/index.d.ts.map +1 -0
- package/lib/build-engine/engine-js/index.js +460 -0
- package/lib/build-engine/engine-js/index.js.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-ref.d.ts +37 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-ref.d.ts.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-ref.js +88 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-ref.js.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-url.d.ts +8 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-url.d.ts.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-url.js +93 -0
- package/lib/build-engine/engine-js/rollup-plugins/asset-url.js.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/code-asset.d.ts +29 -0
- package/lib/build-engine/engine-js/rollup-plugins/code-asset.d.ts.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/code-asset.js +136 -0
- package/lib/build-engine/engine-js/rollup-plugins/code-asset.js.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.d.ts +3 -0
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.d.ts.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.js +38 -0
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.js.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.d.ts +5 -0
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.d.ts.map +1 -0
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.js +43 -0
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.js.map +1 -0
- package/lib/build-engine/index.d.ts +119 -0
- package/lib/build-engine/index.d.ts.map +1 -0
- package/lib/build-engine/index.js +125 -0
- package/lib/build-engine/index.js.map +1 -0
- package/lib/engine-builder.d.ts +54 -46
- package/lib/engine-builder.d.ts.map +1 -0
- package/lib/engine-builder.js +549 -547
- package/lib/engine-builder.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +34 -5
- package/lib/index.js.map +1 -1
- package/lib/module-resolver.d.ts +8 -7
- package/lib/module-resolver.d.ts.map +1 -0
- package/lib/module-resolver.js +28 -28
- package/lib/stats-query/config-interface.d.ts +130 -129
- package/lib/stats-query/config-interface.d.ts.map +1 -0
- package/lib/stats-query/config-interface.js +3 -3
- package/lib/stats-query/constant-manager.d.ts +67 -67
- package/lib/stats-query/constant-manager.d.ts.map +1 -0
- package/lib/stats-query/constant-manager.js +262 -262
- package/lib/stats-query/index.d.ts +162 -91
- package/lib/stats-query/index.d.ts.map +1 -0
- package/lib/stats-query/index.js +527 -263
- package/lib/stats-query/index.js.map +1 -1
- package/lib/stats-query/path-utils.d.ts +3 -2
- package/lib/stats-query/path-utils.d.ts.map +1 -0
- package/lib/stats-query/path-utils.js +35 -35
- package/lib/transformer/babel.d.ts +6 -0
- package/lib/transformer/babel.d.ts.map +1 -0
- package/lib/{config-parser.js → transformer/babel.js} +35 -34
- package/lib/transformer/babel.js.map +1 -0
- package/lib/transformer/index.d.ts +3 -0
- package/lib/transformer/index.d.ts.map +1 -0
- package/lib/{config-paerser/config-parser.js → transformer/index.js} +29 -34
- package/lib/transformer/index.js.map +1 -0
- package/lib/transformer.js +6 -6
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/utils.d.ts +3 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +15 -0
- package/lib/utils.js.map +1 -0
- package/package.json +70 -51
- package/static/helper-dynamic-constants.txt +12 -12
- package/static/helper-global-exporter.txt +8 -8
- package/static/lib.dom.d.ts +20227 -20227
- package/lib/babel-plugins/transform-virtual-specifier.js +0 -71
- package/lib/babel-plugins/transform-virtual-specifier.js.map +0 -1
- package/lib/config-interface.js +0 -3
- package/lib/config-interface.js.map +0 -1
- package/lib/config-paerser/config-interface.js +0 -3
- package/lib/config-paerser/config-interface.js.map +0 -1
- package/lib/config-paerser/config-parser.js.map +0 -1
- package/lib/config-parser/config-interface.js +0 -4
- package/lib/config-parser/config-interface.js.map +0 -1
- package/lib/config-parser/config-parser.js +0 -37
- package/lib/config-parser/config-parser.js.map +0 -1
- package/lib/config-parser/constant-interface.js +0 -3
- package/lib/config-parser/constant-interface.js.map +0 -1
- package/lib/config-parser/constant-manager.js +0 -263
- package/lib/config-parser/constant-manager.js.map +0 -1
- package/lib/config-parser/index.js +0 -286
- package/lib/config-parser/index.js.map +0 -1
- package/lib/config-parser/stats-query.js +0 -248
- package/lib/config-parser/stats-query.js.map +0 -1
- package/lib/config-parser.js.map +0 -1
- package/lib/stats-query/constant-interface.js +0 -3
- package/lib/stats-query/constant-interface.js.map +0 -1
- package/lib/stats-query/stats-query.js +0 -248
- package/lib/stats-query/stats-query.js.map +0 -1
- package/lib/transformer.d.ts +0 -2
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ConstantManager = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
class ConstantManager {
|
|
10
|
-
constructor(engineRoot) {
|
|
11
|
-
this._engineRoot = engineRoot;
|
|
12
|
-
}
|
|
13
|
-
//#region export string
|
|
14
|
-
exportDynamicConstants({ mode, platform, flags, }) {
|
|
15
|
-
const config = this._getConfig();
|
|
16
|
-
// init helper
|
|
17
|
-
let result = '';
|
|
18
|
-
if (this._hasCCGlobal(config)) {
|
|
19
|
-
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-global-exporter.txt'), 'utf8') + '\n';
|
|
20
|
-
}
|
|
21
|
-
if (this._hasDynamic(config)) {
|
|
22
|
-
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-dynamic-constants.txt'), 'utf8') + '\n';
|
|
23
|
-
}
|
|
24
|
-
// update value
|
|
25
|
-
if (config[mode]) {
|
|
26
|
-
config[mode].value = true;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
console.warn(`Unknown mode: ${mode}`);
|
|
30
|
-
}
|
|
31
|
-
if (config[platform]) {
|
|
32
|
-
config[platform].value = true;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
console.warn(`Unknown platform: ${platform}`);
|
|
36
|
-
}
|
|
37
|
-
for (const key in flags) {
|
|
38
|
-
const value = flags[key];
|
|
39
|
-
if (config[key]) {
|
|
40
|
-
config[key].value = value;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
console.warn(`Unknown flag: ${key}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// eval value
|
|
47
|
-
for (const key in config) {
|
|
48
|
-
const info = config[key];
|
|
49
|
-
if (typeof info.value === 'string') {
|
|
50
|
-
info.value = this._evalExpression(info.value, config);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// generate export content
|
|
54
|
-
for (const key in config) {
|
|
55
|
-
const info = config[key];
|
|
56
|
-
const value = info.value;
|
|
57
|
-
if (info.dynamic || info.internal) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
result += `export const ${key} = ${value};\n`;
|
|
61
|
-
if (info.ccGlobal) {
|
|
62
|
-
result += `tryDefineGlobal('CC_${key}', ${value});\n`;
|
|
63
|
-
}
|
|
64
|
-
result += '\n';
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
genBuildTimeConstants(options) {
|
|
69
|
-
const config = this._getConfig();
|
|
70
|
-
this._applyOptionsToConfig(config, options);
|
|
71
|
-
// generate json object
|
|
72
|
-
const jsonObj = {};
|
|
73
|
-
for (const key in config) {
|
|
74
|
-
const info = config[key];
|
|
75
|
-
jsonObj[key] = info.value;
|
|
76
|
-
}
|
|
77
|
-
return jsonObj;
|
|
78
|
-
}
|
|
79
|
-
genCCEnvConstants(options) {
|
|
80
|
-
const config = this._getConfig();
|
|
81
|
-
this._applyOptionsToConfig(config, options);
|
|
82
|
-
// generate json object
|
|
83
|
-
const jsonObj = {};
|
|
84
|
-
for (const key in config) {
|
|
85
|
-
const info = config[key];
|
|
86
|
-
if (!info.internal) {
|
|
87
|
-
jsonObj[key] = info.value;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return jsonObj;
|
|
91
|
-
}
|
|
92
|
-
exportStaticConstants({ mode, platform, flags, }) {
|
|
93
|
-
const config = this._getConfig();
|
|
94
|
-
// init helper
|
|
95
|
-
let result = '';
|
|
96
|
-
if (this._hasCCGlobal(config)) {
|
|
97
|
-
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-global-exporter.txt'), 'utf8') + '\n';
|
|
98
|
-
}
|
|
99
|
-
// update value
|
|
100
|
-
if (config[mode]) {
|
|
101
|
-
config[mode].value = true;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
console.warn(`Unknown mode: ${mode}`);
|
|
105
|
-
}
|
|
106
|
-
if (config[platform]) {
|
|
107
|
-
config[platform].value = true;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
console.warn(`Unknown platform: ${platform}`);
|
|
111
|
-
}
|
|
112
|
-
for (const key in flags) {
|
|
113
|
-
const value = flags[key];
|
|
114
|
-
if (config[key]) {
|
|
115
|
-
config[key].value = value;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.warn(`Unknown flag: ${key}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// eval value
|
|
122
|
-
for (const key in config) {
|
|
123
|
-
const info = config[key];
|
|
124
|
-
if (typeof info.value === 'string') {
|
|
125
|
-
info.value = this._evalExpression(info.value, config);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// generate export content
|
|
129
|
-
for (const key in config) {
|
|
130
|
-
const info = config[key];
|
|
131
|
-
const value = info.value;
|
|
132
|
-
result += `export const ${key} = ${value};\n`;
|
|
133
|
-
if (info.ccGlobal) {
|
|
134
|
-
result += `tryDefineGlobal('CC_${key}', ${value});\n`;
|
|
135
|
-
}
|
|
136
|
-
result += '\n';
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
//#endregion export string
|
|
141
|
-
//#region declaration
|
|
142
|
-
genInternalConstants() {
|
|
143
|
-
const config = this._getConfig();
|
|
144
|
-
let result = `declare module 'internal:constants'{\n`;
|
|
145
|
-
for (const name in config) {
|
|
146
|
-
const info = config[name];
|
|
147
|
-
result += this._genConstantDeclaration(name, info);
|
|
148
|
-
}
|
|
149
|
-
result += '}\n';
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
genCCEnv() {
|
|
153
|
-
const config = this._getConfig();
|
|
154
|
-
let result = `declare module 'cc/env'{\n`;
|
|
155
|
-
for (const name in config) {
|
|
156
|
-
const info = config[name];
|
|
157
|
-
if (info.internal) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
result += this._genConstantDeclaration(name, info);
|
|
161
|
-
}
|
|
162
|
-
result += '}\n';
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
_genConstantDeclaration(name, info) {
|
|
166
|
-
let result = '\t/**\n';
|
|
167
|
-
let comments = info.comment.split('\n');
|
|
168
|
-
for (const comment of comments) {
|
|
169
|
-
result += `\t * ${comment}\n`;
|
|
170
|
-
}
|
|
171
|
-
result += '\t */\n';
|
|
172
|
-
result += `\texport const ${name}: ${info.type};\n\n`;
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
//#endregion declaration
|
|
176
|
-
//#region utils
|
|
177
|
-
_getConfig() {
|
|
178
|
-
const engineConfig = fs_extra_1.default.readJsonSync(path_1.default.join(this._engineRoot, './cc.config.json').replace(/\\/g, '/'));
|
|
179
|
-
const config = engineConfig.constants;
|
|
180
|
-
// init default value
|
|
181
|
-
for (const key in config) {
|
|
182
|
-
const info = config[key];
|
|
183
|
-
if (typeof info.ccGlobal === 'undefined') {
|
|
184
|
-
info.ccGlobal = false;
|
|
185
|
-
}
|
|
186
|
-
if (typeof info.dynamic === 'undefined') {
|
|
187
|
-
info.dynamic = false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return config;
|
|
191
|
-
}
|
|
192
|
-
_hasCCGlobal(config) {
|
|
193
|
-
for (let key in config) {
|
|
194
|
-
const info = config[key];
|
|
195
|
-
if (info.ccGlobal) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
_hasDynamic(config) {
|
|
202
|
-
for (let key in config) {
|
|
203
|
-
const info = config[key];
|
|
204
|
-
if (info.dynamic) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
_evalExpression(expression, config) {
|
|
211
|
-
// eval sub expression
|
|
212
|
-
const matchResult = expression.match(/(?<=\$)\w+/g);
|
|
213
|
-
if (matchResult) {
|
|
214
|
-
for (let name of matchResult) {
|
|
215
|
-
const value = config[name].value;
|
|
216
|
-
if (typeof value === 'string') {
|
|
217
|
-
config[name].value = this._evalExpression(value, config);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
// $EDITOR to $EDITOR.value
|
|
222
|
-
expression = expression.replace(/(?<=\$)(\w+)/g, '$1.value');
|
|
223
|
-
// $EDITOR to $.EDITOR.value
|
|
224
|
-
expression = expression.replace(/\$/g, '$.');
|
|
225
|
-
// do eval
|
|
226
|
-
const evalFn = new Function('$', `return ${expression}`);
|
|
227
|
-
return evalFn(config);
|
|
228
|
-
}
|
|
229
|
-
_applyOptionsToConfig(config, options) {
|
|
230
|
-
const { mode, platform, flags } = options;
|
|
231
|
-
// update value
|
|
232
|
-
if (config[mode]) {
|
|
233
|
-
config[mode].value = true;
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
console.warn(`Unknown mode: ${mode}`);
|
|
237
|
-
}
|
|
238
|
-
if (config[platform]) {
|
|
239
|
-
config[platform].value = true;
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
console.warn(`Unknown platform: ${platform}`);
|
|
243
|
-
}
|
|
244
|
-
for (const key in flags) {
|
|
245
|
-
const value = flags[key];
|
|
246
|
-
if (config[key]) {
|
|
247
|
-
config[key].value = value;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
console.warn(`Unknown flag: ${key}`);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
// eval value
|
|
254
|
-
for (const key in config) {
|
|
255
|
-
const info = config[key];
|
|
256
|
-
if (typeof info.value === 'string') {
|
|
257
|
-
info.value = this._evalExpression(info.value, config);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
exports.ConstantManager = ConstantManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConstantManager = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class ConstantManager {
|
|
10
|
+
constructor(engineRoot) {
|
|
11
|
+
this._engineRoot = engineRoot;
|
|
12
|
+
}
|
|
13
|
+
//#region export string
|
|
14
|
+
exportDynamicConstants({ mode, platform, flags, }) {
|
|
15
|
+
const config = this._getConfig();
|
|
16
|
+
// init helper
|
|
17
|
+
let result = '';
|
|
18
|
+
if (this._hasCCGlobal(config)) {
|
|
19
|
+
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-global-exporter.txt'), 'utf8') + '\n';
|
|
20
|
+
}
|
|
21
|
+
if (this._hasDynamic(config)) {
|
|
22
|
+
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-dynamic-constants.txt'), 'utf8') + '\n';
|
|
23
|
+
}
|
|
24
|
+
// update value
|
|
25
|
+
if (config[mode]) {
|
|
26
|
+
config[mode].value = true;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.warn(`Unknown mode: ${mode}`);
|
|
30
|
+
}
|
|
31
|
+
if (config[platform]) {
|
|
32
|
+
config[platform].value = true;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.warn(`Unknown platform: ${platform}`);
|
|
36
|
+
}
|
|
37
|
+
for (const key in flags) {
|
|
38
|
+
const value = flags[key];
|
|
39
|
+
if (config[key]) {
|
|
40
|
+
config[key].value = value;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.warn(`Unknown flag: ${key}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// eval value
|
|
47
|
+
for (const key in config) {
|
|
48
|
+
const info = config[key];
|
|
49
|
+
if (typeof info.value === 'string') {
|
|
50
|
+
info.value = this._evalExpression(info.value, config);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// generate export content
|
|
54
|
+
for (const key in config) {
|
|
55
|
+
const info = config[key];
|
|
56
|
+
const value = info.value;
|
|
57
|
+
if (info.dynamic || info.internal) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
result += `export const ${key} = ${value};\n`;
|
|
61
|
+
if (info.ccGlobal) {
|
|
62
|
+
result += `tryDefineGlobal('CC_${key}', ${value});\n`;
|
|
63
|
+
}
|
|
64
|
+
result += '\n';
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
genBuildTimeConstants(options) {
|
|
69
|
+
const config = this._getConfig();
|
|
70
|
+
this._applyOptionsToConfig(config, options);
|
|
71
|
+
// generate json object
|
|
72
|
+
const jsonObj = {};
|
|
73
|
+
for (const key in config) {
|
|
74
|
+
const info = config[key];
|
|
75
|
+
jsonObj[key] = info.value;
|
|
76
|
+
}
|
|
77
|
+
return jsonObj;
|
|
78
|
+
}
|
|
79
|
+
genCCEnvConstants(options) {
|
|
80
|
+
const config = this._getConfig();
|
|
81
|
+
this._applyOptionsToConfig(config, options);
|
|
82
|
+
// generate json object
|
|
83
|
+
const jsonObj = {};
|
|
84
|
+
for (const key in config) {
|
|
85
|
+
const info = config[key];
|
|
86
|
+
if (!info.internal) {
|
|
87
|
+
jsonObj[key] = info.value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return jsonObj;
|
|
91
|
+
}
|
|
92
|
+
exportStaticConstants({ mode, platform, flags, }) {
|
|
93
|
+
const config = this._getConfig();
|
|
94
|
+
// init helper
|
|
95
|
+
let result = '';
|
|
96
|
+
if (this._hasCCGlobal(config)) {
|
|
97
|
+
result += fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../static/helper-global-exporter.txt'), 'utf8') + '\n';
|
|
98
|
+
}
|
|
99
|
+
// update value
|
|
100
|
+
if (config[mode]) {
|
|
101
|
+
config[mode].value = true;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.warn(`Unknown mode: ${mode}`);
|
|
105
|
+
}
|
|
106
|
+
if (config[platform]) {
|
|
107
|
+
config[platform].value = true;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.warn(`Unknown platform: ${platform}`);
|
|
111
|
+
}
|
|
112
|
+
for (const key in flags) {
|
|
113
|
+
const value = flags[key];
|
|
114
|
+
if (config[key]) {
|
|
115
|
+
config[key].value = value;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.warn(`Unknown flag: ${key}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// eval value
|
|
122
|
+
for (const key in config) {
|
|
123
|
+
const info = config[key];
|
|
124
|
+
if (typeof info.value === 'string') {
|
|
125
|
+
info.value = this._evalExpression(info.value, config);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// generate export content
|
|
129
|
+
for (const key in config) {
|
|
130
|
+
const info = config[key];
|
|
131
|
+
const value = info.value;
|
|
132
|
+
result += `export const ${key} = ${value};\n`;
|
|
133
|
+
if (info.ccGlobal) {
|
|
134
|
+
result += `tryDefineGlobal('CC_${key}', ${value});\n`;
|
|
135
|
+
}
|
|
136
|
+
result += '\n';
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
//#endregion export string
|
|
141
|
+
//#region declaration
|
|
142
|
+
genInternalConstants() {
|
|
143
|
+
const config = this._getConfig();
|
|
144
|
+
let result = `declare module 'internal:constants'{\n`;
|
|
145
|
+
for (const name in config) {
|
|
146
|
+
const info = config[name];
|
|
147
|
+
result += this._genConstantDeclaration(name, info);
|
|
148
|
+
}
|
|
149
|
+
result += '}\n';
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
genCCEnv() {
|
|
153
|
+
const config = this._getConfig();
|
|
154
|
+
let result = `declare module 'cc/env'{\n`;
|
|
155
|
+
for (const name in config) {
|
|
156
|
+
const info = config[name];
|
|
157
|
+
if (info.internal) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
result += this._genConstantDeclaration(name, info);
|
|
161
|
+
}
|
|
162
|
+
result += '}\n';
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
_genConstantDeclaration(name, info) {
|
|
166
|
+
let result = '\t/**\n';
|
|
167
|
+
let comments = info.comment.split('\n');
|
|
168
|
+
for (const comment of comments) {
|
|
169
|
+
result += `\t * ${comment}\n`;
|
|
170
|
+
}
|
|
171
|
+
result += '\t */\n';
|
|
172
|
+
result += `\texport const ${name}: ${info.type};\n\n`;
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
//#endregion declaration
|
|
176
|
+
//#region utils
|
|
177
|
+
_getConfig() {
|
|
178
|
+
const engineConfig = fs_extra_1.default.readJsonSync(path_1.default.join(this._engineRoot, './cc.config.json').replace(/\\/g, '/'));
|
|
179
|
+
const config = engineConfig.constants;
|
|
180
|
+
// init default value
|
|
181
|
+
for (const key in config) {
|
|
182
|
+
const info = config[key];
|
|
183
|
+
if (typeof info.ccGlobal === 'undefined') {
|
|
184
|
+
info.ccGlobal = false;
|
|
185
|
+
}
|
|
186
|
+
if (typeof info.dynamic === 'undefined') {
|
|
187
|
+
info.dynamic = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return config;
|
|
191
|
+
}
|
|
192
|
+
_hasCCGlobal(config) {
|
|
193
|
+
for (let key in config) {
|
|
194
|
+
const info = config[key];
|
|
195
|
+
if (info.ccGlobal) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
_hasDynamic(config) {
|
|
202
|
+
for (let key in config) {
|
|
203
|
+
const info = config[key];
|
|
204
|
+
if (info.dynamic) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
_evalExpression(expression, config) {
|
|
211
|
+
// eval sub expression
|
|
212
|
+
const matchResult = expression.match(/(?<=\$)\w+/g);
|
|
213
|
+
if (matchResult) {
|
|
214
|
+
for (let name of matchResult) {
|
|
215
|
+
const value = config[name].value;
|
|
216
|
+
if (typeof value === 'string') {
|
|
217
|
+
config[name].value = this._evalExpression(value, config);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// $EDITOR to $EDITOR.value
|
|
222
|
+
expression = expression.replace(/(?<=\$)(\w+)/g, '$1.value');
|
|
223
|
+
// $EDITOR to $.EDITOR.value
|
|
224
|
+
expression = expression.replace(/\$/g, '$.');
|
|
225
|
+
// do eval
|
|
226
|
+
const evalFn = new Function('$', `return ${expression}`);
|
|
227
|
+
return evalFn(config);
|
|
228
|
+
}
|
|
229
|
+
_applyOptionsToConfig(config, options) {
|
|
230
|
+
const { mode, platform, flags } = options;
|
|
231
|
+
// update value
|
|
232
|
+
if (config[mode]) {
|
|
233
|
+
config[mode].value = true;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
console.warn(`Unknown mode: ${mode}`);
|
|
237
|
+
}
|
|
238
|
+
if (config[platform]) {
|
|
239
|
+
config[platform].value = true;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
console.warn(`Unknown platform: ${platform}`);
|
|
243
|
+
}
|
|
244
|
+
for (const key in flags) {
|
|
245
|
+
const value = flags[key];
|
|
246
|
+
if (config[key]) {
|
|
247
|
+
config[key].value = value;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
console.warn(`Unknown flag: ${key}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// eval value
|
|
254
|
+
for (const key in config) {
|
|
255
|
+
const info = config[key];
|
|
256
|
+
if (typeof info.value === 'string') {
|
|
257
|
+
info.value = this._evalExpression(info.value, config);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.ConstantManager = ConstantManager;
|
|
263
263
|
//# sourceMappingURL=constant-manager.js.map
|