@hyext/builder-revues 1.3.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js
CHANGED
@@ -19,6 +19,7 @@ var glob = require('glob');
|
|
19
19
|
var handlebars = require('handlebars');
|
20
20
|
var tapable = require('tapable');
|
21
21
|
var axios = require('axios');
|
22
|
+
var preload = require('@hyext/preload');
|
22
23
|
var liveServer = require('live-server');
|
23
24
|
var archiver = require('archiver');
|
24
25
|
var R = require('ramda');
|
@@ -625,6 +626,21 @@ const HOST = {
|
|
625
626
|
// $1是动态的extType
|
626
627
|
function getSDKUrlTemplate(opts) {
|
627
628
|
return `${opts.isTestEnv ? HOST.test : HOST.prod}/sdk/${opts.extType}/${opts.hostId}/${opts.extUuid || 0}/sdk.js`;
|
629
|
+
}
|
630
|
+
function tryGetDirectSDKUrl(sdkConfig, extType) {
|
631
|
+
var _a, _b, _c, _d, _e;
|
632
|
+
if (sdkConfig.directSdkUrl && !((_a = sdkConfig.bindSdkInfo) === null || _a === void 0 ? void 0 : _a.existDeliveryRule)) {
|
633
|
+
const diliverSdkUrl = (_e = (_d = (_c = (_b = sdkConfig.bindSdkInfo) === null || _b === void 0 ? void 0 : _b.sdkDetail) === null || _c === void 0 ? void 0 : _c.find) === null || _d === void 0 ? void 0 : _d.call(_c, (xs) => xs.extTypeList.includes(extType))) === null || _e === void 0 ? void 0 : _e.sdkUrl;
|
634
|
+
if (diliverSdkUrl)
|
635
|
+
return diliverSdkUrl;
|
636
|
+
}
|
637
|
+
return null;
|
638
|
+
}
|
639
|
+
function getSDKUrl(opts) {
|
640
|
+
if (opts.sdkConfig) {
|
641
|
+
return tryGetDirectSDKUrl(opts.sdkConfig, opts.extType) || getSDKUrlTemplate(opts);
|
642
|
+
}
|
643
|
+
return getSDKUrlTemplate(opts);
|
628
644
|
}
|
629
645
|
|
630
646
|
function isMainPackage(config) {
|
@@ -693,24 +709,25 @@ function injectNpm(dest, packageName) {
|
|
693
709
|
}
|
694
710
|
}
|
695
711
|
function genEntrys(props) {
|
696
|
-
const { builderConfig, mainPakConf, extUuid } = props;
|
712
|
+
const { builderConfig, mainPakConf, extUuid, sdkConfig } = props;
|
697
713
|
return builderConfig.supportExtTypes.map(extType => {
|
698
714
|
const entryFilename = `index_${extType}.html`;
|
699
715
|
return {
|
700
716
|
extType,
|
701
717
|
entryPath: 'package/' + mainPakConf.name + '/' + entryFilename,
|
702
|
-
sdkUrl:
|
718
|
+
sdkUrl: getSDKUrl({
|
703
719
|
extType,
|
704
720
|
extUuid,
|
705
721
|
hostId: builderConfig.hostId,
|
706
|
-
isTestEnv: builderConfig.isTestEnv
|
722
|
+
isTestEnv: builderConfig.isTestEnv,
|
723
|
+
sdkConfig
|
707
724
|
}),
|
708
725
|
entryFilename
|
709
726
|
};
|
710
727
|
});
|
711
728
|
}
|
712
729
|
|
713
|
-
const libVersion = "1.
|
730
|
+
const libVersion = "1.3.0" ;
|
714
731
|
const libCdn = '//a.msstatic.com/huya/hd/h5/static-source/revue/lib';
|
715
732
|
|
716
733
|
function getLibVersion(builderConfig) {
|
@@ -748,6 +765,21 @@ function checkCdnSourceExist(baseUrl) {
|
|
748
765
|
});
|
749
766
|
}
|
750
767
|
|
768
|
+
const defualtPreloadConf = {
|
769
|
+
firstScreen: {
|
770
|
+
mode: 'loading',
|
771
|
+
}
|
772
|
+
};
|
773
|
+
function resolvePreloadCodeByProject(opts) {
|
774
|
+
const staticPath = path__default["default"].join(opts.projectPath, 'static');
|
775
|
+
return preload.resolvePreloadCodeByExtType({
|
776
|
+
// @ts-ignore
|
777
|
+
extInfo: opts.extInfo,
|
778
|
+
preloadEntry: opts.builderConfig.preload || defualtPreloadConf,
|
779
|
+
staticDir: fs__default["default"].existsSync(staticPath) ? staticPath : undefined
|
780
|
+
});
|
781
|
+
}
|
782
|
+
|
751
783
|
// TODO: 改异步
|
752
784
|
// 合并游戏分包到主包
|
753
785
|
function mergeGamePackage(releasePath, opts) {
|
@@ -757,7 +789,8 @@ function mergeGamePackage(releasePath, opts) {
|
|
757
789
|
const entrys = genEntrys({
|
758
790
|
builderConfig,
|
759
791
|
mainPakConf,
|
760
|
-
extUuid: opts.extInfo.extUuid
|
792
|
+
extUuid: opts.extInfo.extUuid,
|
793
|
+
sdkConfig: opts.sdkConfig
|
761
794
|
});
|
762
795
|
PluginDriver.hooks.onMergedMainPackge.call({
|
763
796
|
mainConf: mainPakConf,
|
@@ -783,7 +816,7 @@ function renderGame(opts) {
|
|
783
816
|
// mark 热更新 整个函数不会重渲染。
|
784
817
|
function renderGameTemplate(opts) {
|
785
818
|
return __awaiter(this, void 0, void 0, function* () {
|
786
|
-
const { releasePath, mainPath, entrys, debug, dev, extInfo, builderConfig } = opts;
|
819
|
+
const { releasePath, mainPath, entrys, debug, dev, extInfo, builderConfig, inputPath } = opts;
|
787
820
|
const templatePath = path__default["default"].join(staticPath, 'template');
|
788
821
|
const sourcePathPrefix = yield getLibUrl(builderConfig, path__default["default"].relative(mainPath, releasePath));
|
789
822
|
const renderConfigList = [
|
@@ -806,19 +839,15 @@ function renderGameTemplate(opts) {
|
|
806
839
|
});
|
807
840
|
}
|
808
841
|
const entryRenderConfList = entrys.map(info => {
|
842
|
+
const finalExtInfo = Object.assign(Object.assign({}, extInfo), { envVersion: dev ? 'develop' : 'release', extType: info.extType });
|
809
843
|
return {
|
810
844
|
input: path__default["default"].join(templatePath, 'minigame-page-manager.hbs'),
|
811
845
|
output: path__default["default"].join(mainPath, info.entryFilename),
|
812
|
-
data: {
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
buildEnv: buildEnv,
|
818
|
-
extInfo: Object.assign(Object.assign({}, extInfo), { envVersion: dev ? 'develop' : 'release', extType: info.extType }),
|
819
|
-
deviceOrientation: PluginDriver.context.deviceOrientation,
|
820
|
-
builderConfig: builderConfig
|
821
|
-
}
|
846
|
+
data: Object.assign({ sourcePathPrefix, hyextSDKUrl: info.sdkUrl, debug, sentryScript: dev ? undefined : sentryScriptUrl, buildEnv: buildEnv, extInfo: finalExtInfo, deviceOrientation: PluginDriver.context.deviceOrientation, builderConfig: builderConfig }, resolvePreloadCodeByProject({
|
847
|
+
builderConfig,
|
848
|
+
extInfo: finalExtInfo,
|
849
|
+
projectPath: inputPath
|
850
|
+
}))
|
822
851
|
};
|
823
852
|
});
|
824
853
|
entryRenderConfList.concat(renderConfigList).forEach(config => {
|
@@ -870,7 +899,8 @@ function mergeMiniprogramPackage(releasePath, opts) {
|
|
870
899
|
const entrys = genEntrys({
|
871
900
|
builderConfig,
|
872
901
|
mainPakConf,
|
873
|
-
extUuid: opts.extInfo.extUuid
|
902
|
+
extUuid: opts.extInfo.extUuid,
|
903
|
+
sdkConfig: opts.sdkConfig
|
874
904
|
});
|
875
905
|
PluginDriver.hooks.onMergedMainPackge.call({
|
876
906
|
mainConf: mainPakConf,
|
@@ -878,7 +908,12 @@ function mergeMiniprogramPackage(releasePath, opts) {
|
|
878
908
|
compileType: COMPILE_TYPE.miniProgram,
|
879
909
|
extInfo: opts.extInfo
|
880
910
|
});
|
881
|
-
return {
|
911
|
+
return {
|
912
|
+
entrys,
|
913
|
+
mainPublicPath: 'package/' + mainPakConf.name,
|
914
|
+
mainPath,
|
915
|
+
packagePath
|
916
|
+
};
|
882
917
|
}
|
883
918
|
function renderMiniProgram(opts) {
|
884
919
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -892,7 +927,7 @@ function rerenderHTML(opts) {
|
|
892
927
|
}
|
893
928
|
function renderMiniprogramTemplate(opts) {
|
894
929
|
return __awaiter(this, void 0, void 0, function* () {
|
895
|
-
const { packagePath, releasePath, mainPath, entrys, debug, dev, extInfo, builderConfig } = opts;
|
930
|
+
const { packagePath, releasePath, inputPath, mainPath, entrys, debug, dev, extInfo, builderConfig } = opts;
|
896
931
|
const extConfig = getPackageExtConfig(packagePath);
|
897
932
|
const sourcePathPrefix = yield getLibUrl(builderConfig, path__default["default"].relative(mainPath, releasePath));
|
898
933
|
const packageExtConfigStr = JSON.stringify(extConfig);
|
@@ -912,9 +947,7 @@ function renderMiniprogramTemplate(opts) {
|
|
912
947
|
}
|
913
948
|
}
|
914
949
|
];
|
915
|
-
const renderConfigList = [
|
916
|
-
...htmlRenderConfigList
|
917
|
-
];
|
950
|
+
const renderConfigList = [...htmlRenderConfigList];
|
918
951
|
if (dev) {
|
919
952
|
renderConfigList.push({
|
920
953
|
input: path__default["default"].join(templatePath, 'remote-debugger.hbs'),
|
@@ -926,21 +959,17 @@ function renderMiniprogramTemplate(opts) {
|
|
926
959
|
});
|
927
960
|
}
|
928
961
|
const entryRenderConfList = entrys.map(info => {
|
962
|
+
const finalExtInfo = Object.assign(Object.assign({}, extInfo), { envVersion: dev ? 'develop' : 'release', version: '', extType: info.extType });
|
929
963
|
return {
|
930
964
|
input: path__default["default"].join(templatePath, 'miniapp-page-manager.hbs'),
|
931
965
|
output: path__default["default"].join(mainPath, info.entryFilename),
|
932
|
-
data: {
|
933
|
-
sourcePathPrefix,
|
934
|
-
packageExtConfig: packageExtConfigStr,
|
935
|
-
hyextSDKUrl: info.sdkUrl,
|
936
|
-
debug,
|
937
|
-
buildEnv: buildEnv,
|
938
|
-
isProd: buildEnv != 'dev',
|
966
|
+
data: Object.assign({ sourcePathPrefix, packageExtConfig: packageExtConfigStr, hyextSDKUrl: info.sdkUrl, debug, buildEnv: buildEnv, isProd: buildEnv != 'dev',
|
939
967
|
// sentryScript: dev ? undefined : sentryScriptUrl,
|
940
|
-
sentryScript: sentryScriptUrl,
|
941
|
-
|
942
|
-
|
943
|
-
|
968
|
+
sentryScript: sentryScriptUrl, extInfo: finalExtInfo, builderConfig }, resolvePreloadCodeByProject({
|
969
|
+
builderConfig,
|
970
|
+
extInfo: finalExtInfo,
|
971
|
+
projectPath: inputPath
|
972
|
+
}))
|
944
973
|
};
|
945
974
|
});
|
946
975
|
entryRenderConfList.concat(renderConfigList).forEach(config => {
|
@@ -952,12 +981,13 @@ function renderMiniprogramTemplate(opts) {
|
|
952
981
|
});
|
953
982
|
}
|
954
983
|
|
955
|
-
function mergePackages(projectConfig, outputPath, opts) {
|
984
|
+
function mergePackages(projectConfig, inputPath, outputPath, opts) {
|
956
985
|
return __awaiter(this, void 0, void 0, function* () {
|
957
986
|
const baseRenderOpts = {
|
958
987
|
packagePath: '',
|
959
988
|
mainPath: '',
|
960
989
|
releasePath: outputPath,
|
990
|
+
inputPath,
|
961
991
|
entrys: [],
|
962
992
|
extInfo: opts.extInfo,
|
963
993
|
debug: opts.debug,
|
@@ -996,7 +1026,6 @@ function injectRuntimeLib(releasePath) {
|
|
996
1026
|
const releaseFrameworkPath = path__default["default"].join(releasePath, 'framework');
|
997
1027
|
fs__default["default"].copySync(frameworkPath, releaseFrameworkPath);
|
998
1028
|
injectNpm(path__default["default"].join(releaseFrameworkPath, 'script'), '@revues/web-sdk-core');
|
999
|
-
injectNpm(path__default["default"].join(releaseFrameworkPath, 'script'), '@revues/web-frame');
|
1000
1029
|
// TODO: 这段代码是测试 @revues/js-sdk 增加构建变量去决定执行
|
1001
1030
|
// injectNpm(sdkPath, '@revues/js-sdk')
|
1002
1031
|
}
|
@@ -1067,33 +1096,6 @@ function compress(output) {
|
|
1067
1096
|
});
|
1068
1097
|
}
|
1069
1098
|
|
1070
|
-
function urlToBase64(url) {
|
1071
|
-
return __awaiter(this, void 0, void 0, function* () {
|
1072
|
-
try {
|
1073
|
-
const res = yield axios__default["default"].get(url, { responseType: 'arraybuffer' });
|
1074
|
-
const buffer = Buffer.from(res.data);
|
1075
|
-
const info = getFileInfoByUrl(url);
|
1076
|
-
return `data:image/${info.ext};base64,` + `${buffer.toString('base64')}`;
|
1077
|
-
}
|
1078
|
-
catch (e) {
|
1079
|
-
throw new Error(`urlToBase64 failed, url is "${url}", error msg is ${e.message}`);
|
1080
|
-
}
|
1081
|
-
});
|
1082
|
-
}
|
1083
|
-
function getFileInfoByUrl(url) {
|
1084
|
-
var _a;
|
1085
|
-
const main = url.split('?')[0];
|
1086
|
-
const arr = main.split('/');
|
1087
|
-
const [filename, ext] = (_a = arr[arr.length - 1]) === null || _a === void 0 ? void 0 : _a.split('.');
|
1088
|
-
if (ext == null || ext == '') {
|
1089
|
-
throw new Error(`url:${url}格式错误,无法获取文件信息`);
|
1090
|
-
}
|
1091
|
-
return {
|
1092
|
-
filename,
|
1093
|
-
ext
|
1094
|
-
};
|
1095
|
-
}
|
1096
|
-
|
1097
1099
|
// 36PX
|
1098
1100
|
function makeBuildResults(mode, opts) {
|
1099
1101
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -1269,12 +1271,13 @@ class RevueBuilder {
|
|
1269
1271
|
// 这里拿到打包好的代码 原样输出 + build result
|
1270
1272
|
build(opts) {
|
1271
1273
|
return __awaiter(this, void 0, void 0, function* () {
|
1272
|
-
const { inputPath, outputPath, publicPath, projectConfig, config, extUuid, extName, extVersion, extVersionId, extLogo } = opts;
|
1274
|
+
const { inputPath, outputPath, publicPath, projectConfig, config, extUuid, extName, extVersion, extVersionId, extLogo, directSdkUrl, bindSdkInfo } = opts;
|
1275
|
+
const hasDirectSDKConfig = bindSdkInfo && directSdkUrl;
|
1273
1276
|
const processedConfig = processBuilderConfigJSON('production', config);
|
1274
1277
|
fs__default["default"].existsSync(outputPath) && fs__default["default"].removeSync(outputPath);
|
1275
1278
|
// 把 inputPath 的文件 迁移到 outputPath
|
1276
1279
|
yield fs__default["default"].copy(inputPath, outputPath, { overwrite: true });
|
1277
|
-
const { entrys } = yield mergePackages(projectConfig, outputPath, {
|
1280
|
+
const { entrys } = yield mergePackages(projectConfig, inputPath, outputPath, {
|
1278
1281
|
builderConfig: processedConfig,
|
1279
1282
|
extInfo: {
|
1280
1283
|
forceUsePatchApi: projectConfig.forceUsePatchApi,
|
@@ -1284,8 +1287,12 @@ class RevueBuilder {
|
|
1284
1287
|
extName,
|
1285
1288
|
extVersion,
|
1286
1289
|
extVersionId,
|
1287
|
-
extLogo:
|
1288
|
-
}
|
1290
|
+
extLogo: extLogo
|
1291
|
+
},
|
1292
|
+
sdkConfig: hasDirectSDKConfig ? {
|
1293
|
+
bindSdkInfo,
|
1294
|
+
directSdkUrl
|
1295
|
+
} : undefined
|
1289
1296
|
});
|
1290
1297
|
return yield makeBuildResults('production', {
|
1291
1298
|
entrys: entrys,
|
@@ -1324,7 +1331,7 @@ class RevueBuilder {
|
|
1324
1331
|
retryRef(true);
|
1325
1332
|
}
|
1326
1333
|
});
|
1327
|
-
const { entrys, mainPublicPath, retry } = yield mergePackages(projectConfig, outputPath, {
|
1334
|
+
const { entrys, mainPublicPath, retry } = yield mergePackages(projectConfig, inputPath, outputPath, {
|
1328
1335
|
builderConfig: processedConfig,
|
1329
1336
|
extInfo,
|
1330
1337
|
debug: debugWsc,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hyext/builder-revues",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.0",
|
4
4
|
"description": "> TODO: description",
|
5
5
|
"author": "loler",
|
6
6
|
"homepage": "",
|
@@ -24,10 +24,10 @@
|
|
24
24
|
"url": "https://git.huya.com/exc/web/revue.git"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@
|
28
|
-
"@revues/
|
29
|
-
"@revues/
|
30
|
-
"@revues/web-sdk-core": "1.
|
27
|
+
"@hyext/preload": "^1.1.3",
|
28
|
+
"@revues/cocos-web-adapter": "1.4.0",
|
29
|
+
"@revues/code-compiler": "1.4.0",
|
30
|
+
"@revues/web-sdk-core": "1.4.0",
|
31
31
|
"archiver": "^7.0.1",
|
32
32
|
"axios": "^1.7.3",
|
33
33
|
"chalk": "^2.4.2",
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"@types/ramda": "^0.29.11",
|
48
48
|
"terser": "^5.31.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "1d19521460b8377316d5e179c6d889ca85a65fbe"
|
51
51
|
}
|
@@ -16,8 +16,7 @@
|
|
16
16
|
<meta name="ext-busi-type" content="ext">
|
17
17
|
<meta name="ext-build-env" content="{{buildEnv}}">
|
18
18
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
19
|
-
|
20
|
-
<script charset="utf-8" src="{{sourcePathPrefix}}/framework/script/web-frame.js"></script>
|
19
|
+
{{headerContent}}
|
21
20
|
<style>
|
22
21
|
html,
|
23
22
|
body {
|
@@ -66,6 +65,11 @@
|
|
66
65
|
box-sizing: border-box;
|
67
66
|
}
|
68
67
|
</style>
|
68
|
+
<link rel="preload" href="{{sourcePathPrefix}}/framework/script/service.js" as="script" onload="__handleLinkLoad()">
|
69
|
+
<link rel="preload" href="{{sourcePathPrefix}}/framework/script/view.js" as="script" onload="__handleLinkLoad()">
|
70
|
+
<link rel="preload" href="{{sourcePathPrefix}}/framework/css/index.css" as="style" onload="__handleLinkLoad()">
|
71
|
+
<link rel="preload" href="./__APP__.js" as="script" onload="__handleLinkLoad()">
|
72
|
+
<link rel="preload" href="./pageframe.js" as="script" onload="__handleLinkLoad()">
|
69
73
|
<script charset="utf-8">
|
70
74
|
(function () {
|
71
75
|
window.__extInfo = {{ toJSON extInfo }}
|
@@ -92,24 +96,20 @@
|
|
92
96
|
window.__debug = true
|
93
97
|
</script>
|
94
98
|
{{/if}}
|
95
|
-
{{#if isProd}}
|
96
|
-
<script src="https://fedlib.msstatic.com/fedbasic/hyext-inner/hyext-performance/performance.global.js"></script>
|
97
|
-
<script src="https://a.msstatic.com/huya/hd/cdn_libs/performance_report-min.js"></script>
|
98
|
-
{{/if}}
|
99
|
-
<script charset="utf-8" src="{{hyextSDKUrl}}"></script>
|
100
|
-
<script charset="utf-8" src="{{sourcePathPrefix}}/framework/script/web-sdk-core.js"></script>
|
101
99
|
</head>
|
102
100
|
|
103
101
|
<body>
|
102
|
+
{{bodyContent}}
|
104
103
|
<div class="views" id="webview-container">
|
105
104
|
<iframe class="service" id="webview-service"></iframe>
|
106
105
|
<iframe class="webview" frameborder="0" id="webview-first-view"></iframe>
|
107
106
|
</div>
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
<
|
107
|
+
{{#if isProd}}
|
108
|
+
<script src="https://fedlib.msstatic.com/fedbasic/hyext-inner/hyext-performance/performance.global.js"></script>
|
109
|
+
<script src="https://a.msstatic.com/huya/hd/cdn_libs/performance_report-min.js"></script>
|
110
|
+
{{/if}}
|
111
|
+
<script charset="utf-8" src="{{hyextSDKUrl}}"></script>
|
112
|
+
<script charset="utf-8" src="{{sourcePathPrefix}}/framework/script/web-sdk-core.js"></script>
|
113
113
|
{{#if sentryScript}}
|
114
114
|
<script charset="utf-8" src="{{sentryScript}}" defer></script>
|
115
115
|
{{/if}}
|
@@ -17,6 +17,7 @@
|
|
17
17
|
{{/if}}
|
18
18
|
<meta name="ext-busi-type" content="game">
|
19
19
|
<meta name="ext-build-env" content="{{buildEnv}}">
|
20
|
+
{{headerContent}}
|
20
21
|
<style>
|
21
22
|
.service,
|
22
23
|
.service-preload,
|
@@ -74,13 +75,12 @@
|
|
74
75
|
window.__debug = true
|
75
76
|
</script>
|
76
77
|
{{/if}}
|
77
|
-
<link rel="stylesheet" href="{{sourcePathPrefix}}/framework/script/web-frame.css"></link>
|
78
|
-
<script charset="utf-8" src="{{sourcePathPrefix}}/framework/script/web-frame.js"></script>
|
79
78
|
<script charset="utf-8" src="{{hyextSDKUrl}}"></script>
|
80
79
|
<script charset="utf-8" src="{{sourcePathPrefix}}/framework/script/web-sdk-core.js"></script>
|
81
80
|
</head>
|
82
81
|
|
83
82
|
<body>
|
83
|
+
{{bodyContent}}
|
84
84
|
<div class="views" id="webview-container">
|
85
85
|
<iframe class="service service-view" id="webview-service" src="./game-frame.html"></iframe>
|
86
86
|
</div>
|