@hyext/builder-revues 0.0.1-beta.10
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 +11 -0
- package/dist/index.js +589 -0
- package/package.json +44 -0
- package/static/certs/cert.pem +23 -0
- package/static/certs/key.pem +28 -0
- package/static/framework/.DS_Store +0 -0
- package/static/framework/css/index.css +4896 -0
- package/static/framework/script/console.js +1 -0
- package/static/framework/script/game-adapt.js +9715 -0
- package/static/framework/script/game-service.js +27004 -0
- package/static/framework/script/service.js +49536 -0
- package/static/framework/script/view.js +83900 -0
- package/static/framework/script/worker.js +1 -0
- package/static/template/game-frame.hbs +44 -0
- package/static/template/miniapp-page-manager.hbs +69 -0
- package/static/template/minigame-page-manager.hbs +48 -0
- package/static/template/service.hbs +28 -0
package/README.md
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,589 @@
|
|
1
|
+
/*!
|
2
|
+
* @revues/builder-revues
|
3
|
+
* (c) 2024-2024 Alex
|
4
|
+
* Released under the MIT License.
|
5
|
+
*/
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
9
|
+
|
10
|
+
var fs = require('fs-extra');
|
11
|
+
var path = require('path');
|
12
|
+
var codeCompiler = require('@revues/code-compiler');
|
13
|
+
var os = require('os');
|
14
|
+
var chalk = require('chalk');
|
15
|
+
var util = require('util');
|
16
|
+
var glob = require('glob');
|
17
|
+
var handlebars = require('handlebars');
|
18
|
+
var liveServer = require('live-server');
|
19
|
+
var archiver = require('archiver');
|
20
|
+
var R = require('ramda');
|
21
|
+
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
23
|
+
|
24
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
25
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
26
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
27
|
+
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
28
|
+
var handlebars__default = /*#__PURE__*/_interopDefaultLegacy(handlebars);
|
29
|
+
var liveServer__default = /*#__PURE__*/_interopDefaultLegacy(liveServer);
|
30
|
+
var archiver__default = /*#__PURE__*/_interopDefaultLegacy(archiver);
|
31
|
+
var R__default = /*#__PURE__*/_interopDefaultLegacy(R);
|
32
|
+
|
33
|
+
var EDeployMode;
|
34
|
+
(function (EDeployMode) {
|
35
|
+
EDeployMode[EDeployMode["Integration"] = 0] = "Integration";
|
36
|
+
EDeployMode[EDeployMode["Separate"] = 1] = "Separate";
|
37
|
+
})(EDeployMode || (EDeployMode = {}));
|
38
|
+
|
39
|
+
const cacheDir = path__default["default"].join(os__default["default"].tmpdir(), '.revue_cache');
|
40
|
+
// 根据环境变量判断 要不要把运行框架代码留在项目内 还是 CDN
|
41
|
+
const deployMode = EDeployMode.Integration;
|
42
|
+
const staticPath = path__default["default"].resolve(__dirname, '../static' );
|
43
|
+
|
44
|
+
const filename = 'project.config.json';
|
45
|
+
function copyProjectConfigJSON(srcDir, destDir) {
|
46
|
+
fs__default["default"].copyFileSync(path__default["default"].join(srcDir, filename), path__default["default"].join(destDir, filename));
|
47
|
+
}
|
48
|
+
|
49
|
+
function initCacheDir() {
|
50
|
+
if (fs__default["default"].existsSync(cacheDir))
|
51
|
+
return;
|
52
|
+
fs__default["default"].mkdirSync(cacheDir);
|
53
|
+
}
|
54
|
+
|
55
|
+
const sep = chalk__default["default"].gray('·');
|
56
|
+
const createLogger = (prefix) => {
|
57
|
+
prefix = ` ${prefix}`;
|
58
|
+
const logger = {
|
59
|
+
log(...args) {
|
60
|
+
const msg = util.format.apply(util.format, args);
|
61
|
+
console.log(chalk__default["default"].white(prefix), sep, msg);
|
62
|
+
},
|
63
|
+
fatal(...args) {
|
64
|
+
if (args[0] instanceof Error)
|
65
|
+
args[0] = args[0].message.trim();
|
66
|
+
const msg = util.format.apply(util.format, args);
|
67
|
+
console.error(chalk__default["default"].red(prefix), sep, msg);
|
68
|
+
process.exit(1);
|
69
|
+
},
|
70
|
+
success(...args) {
|
71
|
+
const msg = util.format.apply(util.format, args);
|
72
|
+
console.log(chalk__default["default"].green(prefix), sep, msg);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
return logger;
|
76
|
+
};
|
77
|
+
var logger = createLogger('REVUE');
|
78
|
+
|
79
|
+
// 写成构建插件是最好的,不入侵中间产物,现在图个快
|
80
|
+
function replaceWebAdapter(projectPath) {
|
81
|
+
const sourcePath = path__default["default"].join(projectPath, 'web-adapter.js');
|
82
|
+
const nodePath = require.resolve('@revues/cocos-web-adapter/dist/index.js');
|
83
|
+
if (fs__default["default"].existsSync(sourcePath)) {
|
84
|
+
fs__default["default"].writeFileSync(sourcePath, fs__default["default"].readFileSync(nodePath));
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
logger.log('The web-adapter.js was not found from project root.');
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
async function compile(projectPath, outputPath) {
|
92
|
+
initCacheDir();
|
93
|
+
await codeCompiler.compilerManager.init({
|
94
|
+
projectPath,
|
95
|
+
outputPath,
|
96
|
+
cachePath: cacheDir
|
97
|
+
});
|
98
|
+
await codeCompiler.compilerManager.compileDev();
|
99
|
+
copyProjectConfigJSON(projectPath, outputPath);
|
100
|
+
}
|
101
|
+
async function compileGame(projectPath, outputPath) {
|
102
|
+
initCacheDir();
|
103
|
+
replaceWebAdapter(projectPath);
|
104
|
+
await codeCompiler.compilerManager.init({
|
105
|
+
projectPath,
|
106
|
+
outputPath,
|
107
|
+
cachePath: cacheDir
|
108
|
+
});
|
109
|
+
await codeCompiler.compilerManager.compileDev();
|
110
|
+
copyProjectConfigJSON(projectPath, outputPath);
|
111
|
+
}
|
112
|
+
|
113
|
+
const HOST = {
|
114
|
+
test: '//test-extsdk.msstatic.com',
|
115
|
+
prod: '//extsdk-msstatic.cdn.huya.com'
|
116
|
+
};
|
117
|
+
// $1是动态的extType
|
118
|
+
function getSDKUrlTemplate(opts) {
|
119
|
+
return `${HOST.prod}/sdk/$1/${opts.hostId}/${opts.extUuid || 0}/sdk.js`;
|
120
|
+
}
|
121
|
+
|
122
|
+
function render(content, data, opts) {
|
123
|
+
const temp = handlebars__default["default"].compile(content, {
|
124
|
+
noEscape: true
|
125
|
+
});
|
126
|
+
return temp(data, opts);
|
127
|
+
}
|
128
|
+
function renderTemplate(input, output, data) {
|
129
|
+
const content = fs__default["default"]
|
130
|
+
.readFileSync(input)
|
131
|
+
.toString();
|
132
|
+
fs__default["default"].outputFileSync(output, render(content, data));
|
133
|
+
}
|
134
|
+
|
135
|
+
function isMainPackage(config) {
|
136
|
+
return config.name === codeCompiler.pkgFileType.MainPkg && config.root === '.';
|
137
|
+
}
|
138
|
+
function getPackageConfig(basePath) {
|
139
|
+
const filePath = path__default["default"].join(basePath, 'packageConfig.json');
|
140
|
+
return fs__default["default"].readJSONSync(filePath);
|
141
|
+
}
|
142
|
+
function getPackageExtConfig(basePath) {
|
143
|
+
const filePath = path__default["default"].join(basePath, 'packageExtConfig.json');
|
144
|
+
return fs__default["default"].readJSONSync(filePath);
|
145
|
+
}
|
146
|
+
function mergeSubPackagesToMainPackage(packagePath, main, subList, onMoveBefore) {
|
147
|
+
const mainPath = path__default["default"].join(packagePath, main.name);
|
148
|
+
subList.forEach(conf => {
|
149
|
+
const subRoot = path__default["default"].join(packagePath, conf.name);
|
150
|
+
const subPath = path__default["default"].join(subRoot, conf.root);
|
151
|
+
const dest = path__default["default"].join(mainPath, conf.root);
|
152
|
+
onMoveBefore && onMoveBefore(subRoot, mainPath, conf);
|
153
|
+
fs__default["default"].moveSync(subPath, dest, { overwrite: true });
|
154
|
+
fs__default["default"].removeSync(path__default["default"].join(packagePath, conf.name));
|
155
|
+
});
|
156
|
+
}
|
157
|
+
|
158
|
+
function mergeMainPackage(releasePath, onMoveBefore) {
|
159
|
+
const packagePath = path__default["default"].join(releasePath, 'package');
|
160
|
+
const packageConfig = getPackageConfig(packagePath);
|
161
|
+
const targetIndex = packageConfig.findIndex(item => {
|
162
|
+
return isMainPackage(item);
|
163
|
+
});
|
164
|
+
if (targetIndex === -1) {
|
165
|
+
throw new Error('无法找到主包构建信息');
|
166
|
+
}
|
167
|
+
const mainPakConf = packageConfig[targetIndex];
|
168
|
+
packageConfig.splice(targetIndex, 1);
|
169
|
+
const subPakConfList = packageConfig;
|
170
|
+
if (subPakConfList.length > 0) {
|
171
|
+
// 合并分包资源到子包
|
172
|
+
mergeSubPackagesToMainPackage(packagePath, mainPakConf, subPakConfList, onMoveBefore);
|
173
|
+
}
|
174
|
+
const frameworkPath = path__default["default"].join(staticPath, 'framework');
|
175
|
+
// 安置本地框架文件
|
176
|
+
if (deployMode === EDeployMode.Integration) {
|
177
|
+
// 迁移运行框架
|
178
|
+
fs__default["default"].copySync(frameworkPath, path__default["default"].join(releasePath, 'framework'));
|
179
|
+
// 迁移SDK
|
180
|
+
const sdkPath = path__default["default"].join(releasePath, 'sdk');
|
181
|
+
fs__default["default"].mkdirSync(sdkPath);
|
182
|
+
injectNpm(sdkPath, '@revues/web-sdk-core');
|
183
|
+
injectNpm(sdkPath, '@revues/web-frame');
|
184
|
+
}
|
185
|
+
return {
|
186
|
+
mainPakConf,
|
187
|
+
packagePath
|
188
|
+
};
|
189
|
+
}
|
190
|
+
function injectNpm(dest, packageName) {
|
191
|
+
const nodePath = require.resolve(packageName);
|
192
|
+
let dirPath = path__default["default"].join(nodePath, '../');
|
193
|
+
let dirname = path__default["default"].basename(dirPath);
|
194
|
+
if (dirname === 'dist') {
|
195
|
+
fs__default["default"].copySync(dirPath, dest);
|
196
|
+
}
|
197
|
+
else {
|
198
|
+
// 开发模式 可能是src/index
|
199
|
+
dirPath = path__default["default"].resolve(dirPath, '../');
|
200
|
+
dirPath = path__default["default"].join(dirPath, 'dist');
|
201
|
+
if (fs__default["default"].existsSync(dirPath)) {
|
202
|
+
fs__default["default"].copySync(dirPath, dest);
|
203
|
+
}
|
204
|
+
else {
|
205
|
+
logger.log(`Builder can't resolve ${packageName} entry from ${nodePath}`);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
// TODO: 改异步
|
211
|
+
// 合并游戏分包到主包
|
212
|
+
function mergeGamePackage(releasePath, opts) {
|
213
|
+
const publicPath = ''; // 留口子,cdn资源路径
|
214
|
+
const { mainPakConf, packagePath } = mergeMainPackage(releasePath);
|
215
|
+
const templatePath = path__default["default"].join(staticPath, 'template');
|
216
|
+
const mainPath = path__default["default"].join(packagePath, mainPakConf.name);
|
217
|
+
// 渲染模版
|
218
|
+
renderGameTemplate({
|
219
|
+
hyextSDKUrl: getSDKUrlTemplate({
|
220
|
+
hostId: opts.hostId,
|
221
|
+
extUuid: opts.extUuid
|
222
|
+
}),
|
223
|
+
sourcePathPrefix: deployMode === EDeployMode.Integration
|
224
|
+
? path__default["default"].relative(mainPath, releasePath)
|
225
|
+
: publicPath,
|
226
|
+
templatePath,
|
227
|
+
mainPath
|
228
|
+
});
|
229
|
+
// wasn文件 会被 cocos 同步请求,由于二进制文件同步请求失败 所以改为 base64 文本
|
230
|
+
transformWasnFileToBase64File(mainPath);
|
231
|
+
return {
|
232
|
+
mainPath,
|
233
|
+
main: mainPakConf,
|
234
|
+
entryPath: 'package/' + mainPakConf.name + '/index.html'
|
235
|
+
};
|
236
|
+
}
|
237
|
+
function renderGameTemplate(opts) {
|
238
|
+
const { mainPath, sourcePathPrefix, templatePath, hyextSDKUrl } = opts;
|
239
|
+
const data = {
|
240
|
+
sourcePathPrefix,
|
241
|
+
hyextSDKUrl
|
242
|
+
};
|
243
|
+
const templateConfList = [
|
244
|
+
{
|
245
|
+
input: path__default["default"].join(templatePath, 'game-frame.hbs'),
|
246
|
+
output: path__default["default"].join(mainPath, 'game-frame.html'),
|
247
|
+
data
|
248
|
+
},
|
249
|
+
{
|
250
|
+
input: path__default["default"].join(templatePath, 'minigame-page-manager.hbs'),
|
251
|
+
output: path__default["default"].join(mainPath, 'index.html'),
|
252
|
+
data
|
253
|
+
}
|
254
|
+
];
|
255
|
+
templateConfList.forEach(config => {
|
256
|
+
renderTemplate(config.input, config.output, config.data);
|
257
|
+
});
|
258
|
+
}
|
259
|
+
const ignorePath = [
|
260
|
+
"node_modules/**/*",
|
261
|
+
"**/node_modules/**",
|
262
|
+
"**/.git/**",
|
263
|
+
".git/**/*",
|
264
|
+
"**/.svn/**",
|
265
|
+
".svn/**/*",
|
266
|
+
".DS_Store",
|
267
|
+
"**/.DS_Store",
|
268
|
+
];
|
269
|
+
function transformWasnFileToBase64File(mainPath) {
|
270
|
+
const files = glob.sync('**/**.wasm', {
|
271
|
+
cwd: mainPath,
|
272
|
+
ignore: ignorePath,
|
273
|
+
nodir: true,
|
274
|
+
absolute: false,
|
275
|
+
});
|
276
|
+
console.log('transform wasm to base64 files: \n', files);
|
277
|
+
files.forEach((file) => {
|
278
|
+
const abs = path__default["default"].join(mainPath, file);
|
279
|
+
const text = fs__default["default"].readFileSync(abs).toString('base64');
|
280
|
+
fs__default["default"].outputFileSync(abs + '.txt', text);
|
281
|
+
});
|
282
|
+
}
|
283
|
+
|
284
|
+
function copyServiceBundleToDest(subRoot, mainRoot, config) {
|
285
|
+
const bundleName = config.name + '.js';
|
286
|
+
const bundleMapName = config.name + '.js.map';
|
287
|
+
const bundlePath = path__default["default"].join(subRoot, bundleName);
|
288
|
+
const bundleMapPath = path__default["default"].join(subRoot, bundleMapName);
|
289
|
+
if (fs__default["default"].existsSync(bundlePath)) {
|
290
|
+
fs__default["default"].outputFileSync(path__default["default"].join(mainRoot, bundleName), fs__default["default"].readFileSync(bundlePath));
|
291
|
+
}
|
292
|
+
if (fs__default["default"].existsSync(bundleMapPath)) {
|
293
|
+
fs__default["default"].outputFileSync(path__default["default"].join(mainRoot, bundleMapName), fs__default["default"].readFileSync(bundleMapPath));
|
294
|
+
}
|
295
|
+
}
|
296
|
+
function mergeMiniprogramPackage(releasePath, opts) {
|
297
|
+
const publicPath = ''; // 留口子,cdn资源路径
|
298
|
+
const { mainPakConf, packagePath } = mergeMainPackage(releasePath, copyServiceBundleToDest);
|
299
|
+
const extConfig = getPackageExtConfig(packagePath);
|
300
|
+
const templatePath = path__default["default"].join(staticPath, 'template');
|
301
|
+
const mainPath = path__default["default"].join(packagePath, mainPakConf.name);
|
302
|
+
// 渲染模版
|
303
|
+
renderMiniprogramTemplate({
|
304
|
+
hyextSDKUrl: getSDKUrlTemplate({
|
305
|
+
hostId: opts.hostId,
|
306
|
+
extUuid: opts.extUuid
|
307
|
+
}),
|
308
|
+
sourcePathPrefix: deployMode === EDeployMode.Integration
|
309
|
+
? path__default["default"].relative(mainPath, releasePath)
|
310
|
+
: publicPath,
|
311
|
+
packageExtConfig: extConfig,
|
312
|
+
templatePath,
|
313
|
+
mainPath
|
314
|
+
});
|
315
|
+
return {
|
316
|
+
mainPath,
|
317
|
+
main: mainPakConf,
|
318
|
+
entryPath: 'package/' + mainPakConf.name + '/index.html'
|
319
|
+
};
|
320
|
+
}
|
321
|
+
function renderMiniprogramTemplate(opts) {
|
322
|
+
const { mainPath, sourcePathPrefix, templatePath, hyextSDKUrl, packageExtConfig } = opts;
|
323
|
+
const data = {
|
324
|
+
sourcePathPrefix,
|
325
|
+
hyextSDKUrl,
|
326
|
+
packageExtConfig: JSON.stringify(packageExtConfig)
|
327
|
+
};
|
328
|
+
const templateConfList = [
|
329
|
+
{
|
330
|
+
input: path__default["default"].join(templatePath, 'miniapp-page-manager.hbs'),
|
331
|
+
output: path__default["default"].join(mainPath, 'index.html'),
|
332
|
+
data
|
333
|
+
},
|
334
|
+
{
|
335
|
+
input: path__default["default"].join(templatePath, 'service.hbs'),
|
336
|
+
output: path__default["default"].join(mainPath, 'service.html'),
|
337
|
+
data
|
338
|
+
}
|
339
|
+
];
|
340
|
+
templateConfList.forEach(config => {
|
341
|
+
renderTemplate(config.input, config.output, config.data);
|
342
|
+
});
|
343
|
+
}
|
344
|
+
|
345
|
+
var httpsConf = {
|
346
|
+
cert: fs__default["default"].readFileSync(path__default["default"].join(staticPath, "./certs/cert.pem")),
|
347
|
+
key: fs__default["default"].readFileSync(path__default["default"].join(staticPath, "./certs/key.pem")),
|
348
|
+
passphrase: ""
|
349
|
+
};
|
350
|
+
|
351
|
+
function startLiveServer(opts) {
|
352
|
+
var params = {
|
353
|
+
port: opts.port,
|
354
|
+
host: opts.host,
|
355
|
+
root: opts.root,
|
356
|
+
open: false,
|
357
|
+
ignore: opts.ignore,
|
358
|
+
file: "index.html",
|
359
|
+
wait: 1000,
|
360
|
+
mount: opts.mount,
|
361
|
+
logLevel: 1,
|
362
|
+
https: httpsConf
|
363
|
+
};
|
364
|
+
// @ts-expect-error
|
365
|
+
liveServer__default["default"].start(params);
|
366
|
+
}
|
367
|
+
|
368
|
+
function compress(output) {
|
369
|
+
return new Promise((resolve, reject) => {
|
370
|
+
const stream = fs__default["default"].createWriteStream(`${output}.zip`), archive = archiver__default["default"]('zip', { zlib: { level: 9 } });
|
371
|
+
stream.on('close', () => {
|
372
|
+
const size = archive.pointer();
|
373
|
+
resolve({ name: `${path__default["default"].basename(output)}.zip`, size });
|
374
|
+
}),
|
375
|
+
archive.on('warning', e => {
|
376
|
+
if ('ENOENT' !== e.code)
|
377
|
+
throw e;
|
378
|
+
}),
|
379
|
+
archive.on('error', e => {
|
380
|
+
reject(e);
|
381
|
+
throw e;
|
382
|
+
}),
|
383
|
+
archive.pipe(stream),
|
384
|
+
archive.directory(`${output}`, false),
|
385
|
+
archive.finalize();
|
386
|
+
});
|
387
|
+
}
|
388
|
+
|
389
|
+
async function makeBuildResults(mode, opts) {
|
390
|
+
const { baseURI, extTypes, entryInfo, outputPath } = opts;
|
391
|
+
const releasePath = path__default["default"].join(outputPath, 'build-result');
|
392
|
+
const buildResultMap = {};
|
393
|
+
const buildResultList = extTypes.map(type => {
|
394
|
+
const result = {
|
395
|
+
type: 'HTML',
|
396
|
+
content: {
|
397
|
+
pages: [
|
398
|
+
{
|
399
|
+
path: getPagePath(type, entryInfo)
|
400
|
+
}
|
401
|
+
],
|
402
|
+
baseURI
|
403
|
+
}
|
404
|
+
};
|
405
|
+
buildResultMap[type] = result;
|
406
|
+
return {
|
407
|
+
type,
|
408
|
+
buildResult: {
|
409
|
+
[type]: result
|
410
|
+
}
|
411
|
+
};
|
412
|
+
});
|
413
|
+
if (mode === 'development') {
|
414
|
+
const fsTasks = buildResultList.map((buildResultInfo) => {
|
415
|
+
return fs__default["default"].outputFile(path__default["default"].join(releasePath, buildResultInfo.type + '.json'), JSON.stringify(buildResultInfo.buildResult, null, 2));
|
416
|
+
});
|
417
|
+
await Promise.all(fsTasks);
|
418
|
+
}
|
419
|
+
return buildResultMap;
|
420
|
+
}
|
421
|
+
function getPagePath(extType, entryInfo) {
|
422
|
+
let entry = entryInfo.entryPath + `?extType=${extType}`;
|
423
|
+
// 移动端需要补 __module_busi__
|
424
|
+
if (extType.endsWith('_h5')) {
|
425
|
+
entry += '&__module_busi__=kiwi-ExtSDK';
|
426
|
+
}
|
427
|
+
return entry;
|
428
|
+
}
|
429
|
+
|
430
|
+
const getIPAddress = () => {
|
431
|
+
const ifaces = os__default["default"].networkInterfaces();
|
432
|
+
const addresses = R__default["default"].flatten(R__default["default"].values(ifaces));
|
433
|
+
const address = R__default["default"].filter((iface) => /(ipv)?4/ig.test(iface.family) && !/^127\./.test(iface.address), addresses);
|
434
|
+
return address;
|
435
|
+
};
|
436
|
+
const getPublicIP = (config) => {
|
437
|
+
const address = getIPAddress();
|
438
|
+
/*
|
439
|
+
* 有多个 ip 地址又没有在 config.host 中指定的话, 直接退出
|
440
|
+
*/
|
441
|
+
if (address && address.length > 1) {
|
442
|
+
logger.log(`检测到本机有多个 ip 地址:\n- ${address
|
443
|
+
.map((x) => x.address)
|
444
|
+
.join('\n- ')}`);
|
445
|
+
logger.log('请在 project.config.json 的 host 中指定正确的 ip');
|
446
|
+
process.exit(1);
|
447
|
+
}
|
448
|
+
if (address && address.length <= 0) {
|
449
|
+
logger.log('未能找到本机 ip 地址, 本地开发 app 侧将无法加载小程序');
|
450
|
+
process.exit(1);
|
451
|
+
}
|
452
|
+
return address[0]?.address;
|
453
|
+
};
|
454
|
+
|
455
|
+
const supportedExtTypeSet = new Set([
|
456
|
+
'web_video_com',
|
457
|
+
'app_panel_h5',
|
458
|
+
'zs_anchor_panel_h5',
|
459
|
+
'pc_anchor_panel',
|
460
|
+
'pc_panel'
|
461
|
+
]);
|
462
|
+
function checkExtTypes(extTypes) {
|
463
|
+
let unsupportList = [];
|
464
|
+
if (!extTypes || extTypes.length === 0) {
|
465
|
+
logger.fatal('请在project.config.json相应地方填写supportExtTypes.');
|
466
|
+
}
|
467
|
+
else {
|
468
|
+
extTypes.forEach((item) => {
|
469
|
+
if (!supportedExtTypeSet.has(item)) {
|
470
|
+
unsupportList.push(item);
|
471
|
+
}
|
472
|
+
});
|
473
|
+
}
|
474
|
+
if (unsupportList.length > 0) {
|
475
|
+
logger.fatal(`未支持的小程序类型:${unsupportList.join('|')}.`);
|
476
|
+
}
|
477
|
+
}
|
478
|
+
function processDevConfig(config) {
|
479
|
+
// 强制开启
|
480
|
+
config.https = true;
|
481
|
+
if (config.host == null) {
|
482
|
+
config.host = getPublicIP() || ''; // 用ip地址不用localshot
|
483
|
+
}
|
484
|
+
if (config.port == null) {
|
485
|
+
config.port = 18080;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
function processGlobalConfig(config) {
|
489
|
+
if (config.hostId == null) {
|
490
|
+
config.hostId = 'huyaext';
|
491
|
+
}
|
492
|
+
}
|
493
|
+
function processBuilderConfigJSON(mode, config) {
|
494
|
+
const opts = { ...config };
|
495
|
+
checkExtTypes(config.supportExtTypes);
|
496
|
+
processGlobalConfig(opts);
|
497
|
+
if (mode === 'development') {
|
498
|
+
processDevConfig(opts);
|
499
|
+
}
|
500
|
+
return opts;
|
501
|
+
}
|
502
|
+
function getDevBaseURI(config) {
|
503
|
+
const protocol = config.https ? 'https' : 'http';
|
504
|
+
return `${protocol}://${config.host}:${config.port}/`;
|
505
|
+
}
|
506
|
+
|
507
|
+
function mergePackage(projectConfig, outputPath, opts) {
|
508
|
+
logger.log('正在合并分包...');
|
509
|
+
const mergeMethod = projectConfig.compileType == 'game'
|
510
|
+
? mergeGamePackage
|
511
|
+
: mergeMiniprogramPackage;
|
512
|
+
const entryInfo = mergeMethod(outputPath, opts);
|
513
|
+
logger.success('合并分包完成');
|
514
|
+
return entryInfo;
|
515
|
+
}
|
516
|
+
class RevueBuilder {
|
517
|
+
// 这里拿到打包好的代码 原样输出 + build result
|
518
|
+
async build(opts) {
|
519
|
+
const { inputPath, outputPath, publicPath, projectConfig, config, extUuid } = opts;
|
520
|
+
const processedConfig = processBuilderConfigJSON('production', config);
|
521
|
+
fs__default["default"].existsSync(outputPath) && fs__default["default"].removeSync(outputPath);
|
522
|
+
// 把 inputPath 的文件 迁移到 outputPath
|
523
|
+
await fs__default["default"].copy(inputPath, outputPath, { overwrite: true });
|
524
|
+
const entryInfo = mergePackage(projectConfig, outputPath, {
|
525
|
+
hostId: processedConfig.hostId,
|
526
|
+
extUuid: extUuid
|
527
|
+
});
|
528
|
+
return await makeBuildResults('production', {
|
529
|
+
entryInfo,
|
530
|
+
baseURI: publicPath,
|
531
|
+
extTypes: processedConfig.supportExtTypes,
|
532
|
+
outputPath
|
533
|
+
});
|
534
|
+
}
|
535
|
+
async start(opts) {
|
536
|
+
const { inputPath, projectConfig, outputPath: outputPath$1, config } = opts;
|
537
|
+
const outputPath = outputPath$1 || path__default["default"].join(__dirname, '../../temp');
|
538
|
+
const processedConfig = processBuilderConfigJSON('development', config);
|
539
|
+
if (projectConfig.compileType == 'game') {
|
540
|
+
await compileGame(inputPath, outputPath);
|
541
|
+
}
|
542
|
+
else {
|
543
|
+
await compile(inputPath, outputPath);
|
544
|
+
}
|
545
|
+
const entryInfo = mergePackage(projectConfig, outputPath, {
|
546
|
+
hostId: processedConfig.hostId,
|
547
|
+
extUuid: undefined
|
548
|
+
});
|
549
|
+
logger.log('启动 live server 服务...');
|
550
|
+
logger.success('本地访问地址:', getDevBaseURI(processedConfig) +
|
551
|
+
entryInfo.entryPath +
|
552
|
+
'?extType=web_video_com');
|
553
|
+
startLiveServer({
|
554
|
+
...processedConfig,
|
555
|
+
root: outputPath
|
556
|
+
});
|
557
|
+
return await makeBuildResults('development', {
|
558
|
+
entryInfo,
|
559
|
+
baseURI: getDevBaseURI(processedConfig),
|
560
|
+
extTypes: processedConfig.supportExtTypes,
|
561
|
+
outputPath
|
562
|
+
});
|
563
|
+
}
|
564
|
+
// 这里仅仅在 client 打包 小程序/小游戏
|
565
|
+
async release(opts) {
|
566
|
+
const { contextPath, releasePath, projectConfig } = opts;
|
567
|
+
if (fs__default["default"].existsSync(releasePath)) {
|
568
|
+
fs__default["default"].removeSync(releasePath);
|
569
|
+
}
|
570
|
+
const projectName = projectConfig.projectName || projectConfig.projectname || 'project';
|
571
|
+
const outputPath = path__default["default"].join(releasePath, projectName);
|
572
|
+
if (projectConfig.compileType == 'game') {
|
573
|
+
await compileGame(contextPath, outputPath);
|
574
|
+
}
|
575
|
+
else {
|
576
|
+
await compile(contextPath, outputPath);
|
577
|
+
}
|
578
|
+
// zip
|
579
|
+
const zipPath = path__default["default"].join(releasePath, projectName);
|
580
|
+
await compress(zipPath);
|
581
|
+
}
|
582
|
+
config() { }
|
583
|
+
providedProjectConfig() { }
|
584
|
+
}
|
585
|
+
const revueBuilder = new RevueBuilder();
|
586
|
+
|
587
|
+
module.exports = revueBuilder;
|
588
|
+
|
589
|
+
exports["default"] = revueBuilder;
|
package/package.json
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"name": "@hyext/builder-revues",
|
3
|
+
"version": "0.0.1-beta.10",
|
4
|
+
"description": "> TODO: description",
|
5
|
+
"author": "diamondloler <857276958@qq.com>",
|
6
|
+
"homepage": "",
|
7
|
+
"license": "ISC",
|
8
|
+
"main": "dist",
|
9
|
+
"directories": {
|
10
|
+
"src": "src"
|
11
|
+
},
|
12
|
+
"files": [
|
13
|
+
"dist",
|
14
|
+
"static"
|
15
|
+
],
|
16
|
+
"publishConfig": {
|
17
|
+
"access": "public"
|
18
|
+
},
|
19
|
+
"repository": {
|
20
|
+
"type": "git",
|
21
|
+
"url": "https://git.huya.com/exc/web/remax.git"
|
22
|
+
},
|
23
|
+
"scripts": {},
|
24
|
+
"dependencies": {
|
25
|
+
"@revues/cocos-web-adapter": "0.0.1-beta.10",
|
26
|
+
"@revues/code-compiler": "0.0.1-beta.10",
|
27
|
+
"@revues/web-frame": "0.0.1-beta.10",
|
28
|
+
"@revues/web-sdk-core": "0.0.1-beta.10",
|
29
|
+
"archiver": "^7.0.1",
|
30
|
+
"chalk": "^2.4.2",
|
31
|
+
"fs-extra": "8.1.0",
|
32
|
+
"glob": "^10.3.10",
|
33
|
+
"handlebars": "^4.7.8",
|
34
|
+
"live-server": "^1.2.2",
|
35
|
+
"ramda": "^0.29.1",
|
36
|
+
"util": "^0.12.5"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"@types/archiver": "^6.0.2",
|
40
|
+
"@types/live-server": "^1.2.3",
|
41
|
+
"@types/ramda": "^0.29.11"
|
42
|
+
},
|
43
|
+
"gitHead": "336615b481a4f6162c7a04088aa0c671ddeb659b"
|
44
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIID6zCCAtOgAwIBAgIUPDlH/8sZ9WTUpxrVsQPQgxweFkcwDQYJKoZIhvcNAQEL
|
3
|
+
BQAwgYQxCzAJBgNVBAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxEjAQBgNVBAcM
|
4
|
+
CUd1YW5nemhvdTENMAsGA1UECgwESFVZQTEOMAwGA1UECwwFSFlFWFQxDTALBgNV
|
5
|
+
BAMMBEFsZXgxHzAdBgkqhkiG9w0BCQEWEDg1NzI3Njk1OEBxcS5jb20wHhcNMjQw
|
6
|
+
MzE0MDMwNjA2WhcNMzQwMzEyMDMwNjA2WjCBhDELMAkGA1UEBhMCQ04xEjAQBgNV
|
7
|
+
BAgMCUd1YW5nRG9uZzESMBAGA1UEBwwJR3Vhbmd6aG91MQ0wCwYDVQQKDARIVVlB
|
8
|
+
MQ4wDAYDVQQLDAVIWUVYVDENMAsGA1UEAwwEQWxleDEfMB0GCSqGSIb3DQEJARYQ
|
9
|
+
ODU3Mjc2OTU4QHFxLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
10
|
+
AKw2HdDc+7KreihQzErKxvMoGdW6jem9qvwEwGTpy2N9knj2mE4im7MK107zeklI
|
11
|
+
S6BpJrn9uzpWvDpk/beF+nEeKaEGEgxaGVM7YMVVmdlqvfFTcGzYFBuUtO/Benk5
|
12
|
+
ESNlsG5U58g3BoMjC3YyxE0W0O7hCWjHN1eC8F85Mq4LB2GlWtRpQRifqdR/H9ql
|
13
|
+
GZNBtwOxv5FP1vGwEi6u7YXZhCqMeOcUKmGcd0hO5OJrhjdV9cV0V838s0jWghzc
|
14
|
+
RrNvZihlbXeNeWkMYJHf0fbcXswF0N/CRdQkJ9Vmj5S+ET1rfjiSJxoV68bFk8M7
|
15
|
+
7M2iZyklUHXoY3o7MVm5h4sCAwEAAaNTMFEwHQYDVR0OBBYEFJln0RGjC3q0WDsq
|
16
|
+
272Lskjg5gliMB8GA1UdIwQYMBaAFJln0RGjC3q0WDsq272Lskjg5gliMA8GA1Ud
|
17
|
+
EwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAHDwHlPp9VF1JD7OVijPCCGy
|
18
|
+
HYXFOmfre0GUBeBRYYwENbvENkL64sWTlkl11Ij90hONAmtN70gu9w+rq9fXdWlP
|
19
|
+
/GBsT846QnXByw9lkdxUEUDI9M1oGMDuiWPAoW10yvPpEaL1OQeJ/wcVwMF7MiY8
|
20
|
+
OFypybsVY7K9EoNOutQvi2KVm+Y91hkO3mlCdkJsaHDOmGD7hghTUnvNwsXgzTJW
|
21
|
+
N6rCMBqGwZRiWfynjSjTs4qxucMal/ynKv9n20JTDuXiDJZvna+RpOWEFu5zrylO
|
22
|
+
LOjzkwNiSLJ2XlWf19LKoSLep22R8dKmFEYlUmwNhv7CgCCsQO00Zci5I3ovkEU=
|
23
|
+
-----END CERTIFICATE-----
|