@hyext/builder-revues 1.0.2 → 1.0.4
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.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* (c) 2024-2024 Alex
|
4
4
|
* Released under the MIT License.
|
5
5
|
*/
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs-extra"),t=require("path"),n=require("@revues/code-compiler"),
|
6
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs-extra"),t=require("path"),n=require("@revues/code-compiler"),o=require("os"),a=require("chalk"),i=require("util"),r=require("glob"),s=require("handlebars"),u=require("tapable"),c=require("live-server"),l=require("archiver"),d=require("axios"),f=require("ramda");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m,g=p(e),h=p(t),y=p(o),v=p(a),x=p(s),j=p(c),P=p(l),b=p(d),S=p(f);
|
7
7
|
/*! *****************************************************************************
|
8
8
|
Copyright (c) Microsoft Corporation.
|
9
9
|
|
@@ -18,4 +18,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
18
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
20
20
|
***************************************************************************** */
|
21
|
-
function S(e,t,n,a){return new(n||(n=Promise))((function(o,i){function r(e){try{s(a.next(e))}catch(e){i(e)}}function u(e){try{s(a.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,u)}s((a=a.apply(e,t||[])).next())}))}!function(e){e[e.Integration=0]="Integration",e[e.Separate=1]="Separate"}(f||(f={}));const b=g.default.tmpdir(),k=h.default.join(b,".revue_cache"),w=f.Integration,U=h.default.resolve(__dirname,"../static");var I;!function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(I||(I={}));const _="project.config.json";function C(e,t){m.default.copyFileSync(h.default.join(e,_),h.default.join(t,_))}function T(){m.default.existsSync(k)||m.default.mkdirSync(k)}function E(e,t){return S(this,void 0,void 0,(function*(){T(),yield n.compilerManager.init({projectPath:e,outputPath:t,cachePath:k}),yield n.compilerManager.compileDev(),C(e,t)}))}function N(e,t){return S(this,void 0,void 0,(function*(){T(),yield n.compilerManager.init({projectPath:e,outputPath:t,cachePath:k,compileSettings:{cocos:!0}}),yield n.compilerManager.compileDev(),C(e,t)}))}const O=y.default.gray("·");var M=(e=>{e=` ${e}`;return{log(...t){const n=i.format.apply(i.format,t);console.log(y.default.white(e),O,n)},fatal(...t){t[0]instanceof Error&&(t[0]=t[0].message.trim());const n=i.format.apply(i.format,t);console.error(y.default.red(e),O,n),process.exit(1)},success(...t){const n=i.format.apply(i.format,t);console.log(y.default.green(e),O,n)}}})("REVUE");const $=Date.now(),F="production"!==process.env.HYEXT_BUILD_ENV?"//test-hd.huya.com/h5/hyext-sentry-setup-script/test/sentry-setup.js":`//a.msstatic.com/huya/hd/h5/hyext-sentry-setup-script/sentry-setup.js?hash=${$}`;function q(e,t,n){const a=m.default.readFileSync(e).toString();m.default.outputFileSync(t,function(e,t,n){return v.default.compile(e,{noEscape:!0})(t,n)}(a,n))}v.default.registerHelper("toJSON",(function(e){return new v.default.SafeString(JSON.stringify(e))}));const D={context:{deviceOrientation:"portrait"},hooks:{onMergedMainPackge:new s.SyncHook(["IOnMergedMainPackge"]),onSrartBefore:new s.SyncHook(["IOnSrartBefore"])}};class R{apply(e){e.hooks.onMergedMainPackge.tap("InjectWebviewUrlParamsPlugin",(t=>{const{compileType:n,mainPath:a}=t,o=n===I.miniGame;if(o){const t=m.default.readJsonSync(h.default.join(a,"game.json"));"string"==typeof t.deviceOrientation&&t.deviceOrientation.includes("landscape")&&(e.context.deviceOrientation="landscape")}e.context.webviewUrlParams={isLandscape:0,disablePopGesture:1,hideStatusBar:o?1:0,hideBar:1,bounces:0}}))}}function z(){const e=D.context.webviewUrlParams;return e?(t=e,Object.keys(t).reduce(((e,n)=>e+`&${n}=${encodeURIComponent(t[n])}`),"")):"";var t}const B={test:"//test-extsdk.msstatic.com",prod:"//extsdk-msstatic.cdn.huya.com"};function G(e,t,a){const o=h.default.join(t,"package"),i=function(e){const t=h.default.join(e,"packageConfig.json");return m.default.readJSONSync(t)}(o),r=i.findIndex((e=>{return(t=e).name===n.pkgFileType.MainPkg&&"."===t.root;var t}));if(-1===r)throw new Error("无法找到主包构建信息");const u=i[r];i.splice(r,1);const s=i;if(s.length>0&&function(e,t,n,a){const o=h.default.join(e,t.name);n.forEach((t=>{const n=h.default.join(e,t.name),i=h.default.join(n,t.root),r=h.default.join(o,t.root);a&&a(n,o,t),m.default.moveSync(i,r,{overwrite:!0}),m.default.removeSync(h.default.join(e,t.name))}))}(o,u,s,a),!e){const e=h.default.join(U,"framework");if(w===f.Integration){m.default.copySync(e,h.default.join(t,"framework"));const n=h.default.join(t,"sdk");m.default.mkdirSync(n),J(n,"@revues/web-sdk-core"),J(n,"@revues/web-frame"),J(n,"@revues/hyext-adapter")}}return{mainPakConf:u,packagePath:o}}function J(e,t){const n=require.resolve(t);let a=h.default.join(n,"../");"dist"===h.default.basename(a)?m.default.copySync(a,e):(a=h.default.resolve(a,"../"),a=h.default.join(a,"dist"),m.default.existsSync(a)?m.default.copySync(a,e):M.log(`Builder can't resolve ${t} entry from ${n}`))}function H(e){const{builderConfig:t,mainPakConf:n,extUuid:a}=e;return t.supportExtTypes.map((e=>{const o=`index_${e}.html`;return{extType:e,entryPath:"package/"+n.name+"/"+o,sdkUrl:(i={extType:e,extUuid:a,hostId:t.hostId,isTestEnv:t.isTestEnv},`${i.isTestEnv?B.test:B.prod}/sdk/${i.extType}/${i.hostId}/${i.extUuid||0}/sdk.js`),entryFilename:o};var i}))}function L(e,t){const n=t.extName,a=t.extUuid,o=t.builderConfig,i=!!t.watch,{mainPakConf:u,packagePath:s}=G(i,e),c=h.default.join(U,"template"),l=h.default.join(s,u.name),d=H({builderConfig:o,mainPakConf:u,extUuid:a});return D.hooks.onMergedMainPackge.call({mainConf:u,mainPath:l,compileType:I.miniGame}),i||(function(e){const{mainPath:t,sourcePathPrefix:n,templatePath:a,entrys:o,debug:i,dev:r,extUuid:u,extName:s}=e,c=[{input:h.default.join(a,"game-frame.hbs"),output:h.default.join(t,"game-frame.html"),data:{sourcePathPrefix:n}}];r&&c.push({input:h.default.join(a,"remote-debugger.hbs"),output:h.default.join(t,"remote-debugger.html"),data:{extUuid:u,paramsStr:z()}});const l=o.map((e=>({input:h.default.join(a,"minigame-page-manager.hbs"),output:h.default.join(t,e.entryFilename),data:{sourcePathPrefix:n,hyextSDKUrl:e.sdkUrl,debug:i,sentryScript:r?void 0:F,extInfo:{extUuid:u,envVersion:r?"develop":"release",extType:e.extType,extName:s},deviceOrientation:D.context.deviceOrientation}})));l.concat(c).forEach((e=>{q(e.input,e.output,e.data)}))}(Object.assign({entrys:d,sourcePathPrefix:w===f.Integration?h.default.relative(l,e):"",templatePath:c,mainPath:l,extUuid:a,extName:n},t.template)),function(e){const t=r.sync("**/**.wasm",{cwd:e,ignore:V,nodir:!0,absolute:!1});t.length&&console.log("transform wasm to base64 files: \n",t),t.forEach((t=>{const n=h.default.join(e,t),a=m.default.readFileSync(n).toString("base64");m.default.outputFileSync(n+".txt",a)}))}(l)),{entrys:d,mainPublicPath:"package/"+u.name}}const V=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];function K(e,t,n){const a=n.name+".js",o=n.name+".js.map",i=h.default.join(e,a),r=h.default.join(e,o);m.default.existsSync(i)&&m.default.outputFileSync(h.default.join(t,a),m.default.readFileSync(i)),m.default.existsSync(r)&&m.default.outputFileSync(h.default.join(t,o),m.default.readFileSync(r))}function W(e,t){const n=t.extName,a=t.extUuid,o=t.builderConfig,i=!!t.watch,{mainPakConf:r,packagePath:u}=G(i,e,K),s=function(e){const t=h.default.join(e,"packageExtConfig.json");return m.default.readJSONSync(t)}(u),c=h.default.join(U,"template"),l=h.default.join(u,r.name),d=H({builderConfig:o,mainPakConf:r,extUuid:a});return D.hooks.onMergedMainPackge.call({mainConf:r,mainPath:l,compileType:I.miniProgram}),i||function(e){const{mainPath:t,sourcePathPrefix:n,templatePath:a,entrys:o,packageExtConfig:i,debug:r,dev:u,extUuid:s,extName:c}=e,l=JSON.stringify(i),d=[{input:h.default.join(a,"service.hbs"),output:h.default.join(t,"service.html"),data:{sourcePathPrefix:n}}];u&&d.push({input:h.default.join(a,"remote-debugger.hbs"),output:h.default.join(t,"remote-debugger.html"),data:{extUuid:s,paramsStr:z()}});const p=o.map((e=>({input:h.default.join(a,"miniapp-page-manager.hbs"),output:h.default.join(t,e.entryFilename),data:{sourcePathPrefix:n,packageExtConfig:l,hyextSDKUrl:e.sdkUrl,debug:r,sentryScript:u?void 0:F,extInfo:{extUuid:s,envVersion:u?"develop":"release",version:"",extType:e.extType,extName:c}}})));p.concat(d).forEach((e=>{q(e.input,e.output,e.data)}))}(Object.assign({entrys:d,sourcePathPrefix:w===f.Integration?h.default.relative(l,e):"",packageExtConfig:s,templatePath:c,mainPath:l,extUuid:a,extName:n},t.template)),{entrys:d,mainPublicPath:"package/"+r.name}}class X{apply(e){e.hooks.onSrartBefore.tap("RemoveUnlessDIrPlugin",(e=>{const{inputPath:t}=e,n=h.default.join(t,"release"),a=h.default.join(t,"dist");Y(n),Y(a)}))}}function Y(e){m.default.existsSync(e)&&m.default.removeSync(e)}var A={cert:m.default.readFileSync(h.default.join(U,"./certs/cert.pem")),key:m.default.readFileSync(h.default.join(U,"./certs/key.pem")),passphrase:""};function Q(e,t){return S(this,void 0,void 0,(function*(){const{baseURI:n,entrys:a,outputPath:o}=t,i=h.default.join(o,"build-result"),r={},u=z(),s=a.map((e=>{const t={type:"HTML",content:{pages:[{path:Z(e,u)}],baseURI:n}};return r[e.extType]=t,{type:e.extType,buildResult:{[e.extType]:t}}}));if("development"===e){const e=s.map((e=>m.default.outputFile(h.default.join(i,e.type+".json"),JSON.stringify(e.buildResult,null,2))));yield Promise.all(e)}return r}))}function Z(e,t){const n=e.extType;let a=e.entryPath;return n.endsWith("_h5")&&(a+="?__module_busi__=kiwi-ExtSDK"+t),a}const ee=e=>{var t;const n=(()=>{const e=g.default.networkInterfaces(),t=j.default.flatten(j.default.values(e));return j.default.filter((e=>/(ipv)?4/gi.test(e.family)&&!/^127\./.test(e.address)),t)})();return n&&n.length>1&&(M.log(`检测到本机有多个 ip 地址:\n- ${n.map((e=>e.address)).join("\n- ")}`),M.log("请在 project.config.json 的 host 中指定正确的 ip"),process.exit(1)),n&&n.length<=0&&(M.log("未能找到本机 ip 地址, 本地开发 app 侧将无法加载小程序"),process.exit(1)),null===(t=n[0])||void 0===t?void 0:t.address},te=new Set(["app_inner_h5","web_video_com","app_panel_h5","zs_anchor_panel_h5","pc_anchor_panel","pc_panel"]);function ne(e,t){const n=Object.assign({},t);return function(e){let t=[];e&&0!==e.length?e.forEach((e=>{te.has(e)||t.push(e)})):M.fatal("请在project.config.json相应地方填写supportExtTypes."),t.length>0&&M.fatal(`未支持的小程序类型:${t.join("|")}.`)}(t.supportExtTypes),function(e){null==e.hostId&&(e.hostId="huyaext")}(n),"development"===e&&function(e){e.https=!0,null==e.host&&(e.host=ee()||""),null==e.port&&(e.port=18080)}(n),n}function ae(e){return`${e.https?"https":"http"}://${e.host}:${e.port}/`}function oe(e,t,n){M.log("正在合并分包...");const a=("game"==e.compileType?L:W)(t,n);return M.success("合并分包完成"),a}const ie=new class{constructor(){var e;e=D,(new R).apply(e),(new X).apply(e)}build(e){return S(this,void 0,void 0,(function*(){const{inputPath:t,outputPath:n,publicPath:a,projectConfig:o,config:i,extUuid:r,extName:u}=e,s=ne("production",i);m.default.existsSync(n)&&m.default.removeSync(n),yield m.default.copy(t,n,{overwrite:!0});const{entrys:c}=oe(o,n,{builderConfig:s,extUuid:r,extName:u});return yield Q("production",{entrys:c,baseURI:a,outputPath:n})}))}start(e){var t;return S(this,void 0,void 0,(function*(){const{debug:a,inputPath:o,projectConfig:i,outputPath:r,config:u}=e;D.hooks.onSrartBefore.call({inputPath:o});const s=(c=h.default.basename(o),h.default.join(b,".revues-projects",c));var c;const l=function(e){const t=e.appId||e.appid;return null==t||""===t?M.fatal("请填写正确的appid"):t.length>10&&M.fatal("appid错误,请登录 https://ext.huya.com/ 在您的小程序概要中查看小程序ID"),t}(i),d=(p=i).projectname||p.projectName||"小程序";var p;const f=ne("development",u);"game"==i.compileType?yield function(e,t,a){return S(this,void 0,void 0,(function*(){yield N(e,t),n.compilerManager.watch({graphId:"game"},((e,t)=>S(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"game"}),a&&a()}))))}))}(o,s,(()=>{oe(i,s,{builderConfig:f,watch:!0})})):yield function(e,t,a){return S(this,void 0,void 0,(function*(){yield E(e,t),n.compilerManager.watch({graphId:"miniprogram"},((e,t)=>S(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"miniprogram"}),a&&a()}))))}))}(o,s,(()=>{oe(i,s,{builderConfig:f,watch:!0})}));const{entrys:m,mainPublicPath:g}=oe(i,s,{builderConfig:f,extUuid:l,extName:d,template:{debug:a,dev:!0}});return M.log("启动 live server 服务..."),M.success("本地访问地址:",ae(f)+(null===(t=m[0])||void 0===t?void 0:t.entryPath)),M.success("扫码预览地址:",ae(f)+g+"/remote-debugger.html"),function(e){var t={port:e.port,host:e.host,root:e.root,open:!1,ignore:e.ignore,file:"index.html",wait:1e3,mount:e.mount,logLevel:1,https:A};x.default.start(t)}(Object.assign(Object.assign({},f),{root:s,ignore:"node_modules"})),yield Q("development",{entrys:m,baseURI:ae(f),outputPath:r})}))}release(e){return S(this,void 0,void 0,(function*(){const{contextPath:t,releasePath:n,projectConfig:a}=e;m.default.existsSync(n)&&m.default.removeSync(n),M.log("开始打包");const o=a.projectName||a.projectname||"project",i=h.default.join(n,o);"game"==a.compileType?yield N(t,i):yield E(t,i);const r=h.default.join(n,o);var u;yield(u=r,new Promise(((e,t)=>{const n=m.default.createWriteStream(`${u}.zip`),a=P.default("zip",{zlib:{level:9}});n.on("close",(()=>{const t=a.pointer();e({name:`${h.default.basename(u)}.zip`,size:t})})),a.on("warning",(e=>{if("ENOENT"!==e.code)throw e})),a.on("error",(e=>{throw t(e),e})),a.pipe(n),a.directory(`${u}`,!1),a.finalize()}))),M.success("打包成功,zip包地址:"+r)}))}config(){}providedProjectConfig(){}clearCache(){try{m.default.existsSync(k)&&m.default.removeSync(k),M.success("项目缓存清除成功~")}catch(e){M.success("项目缓存清除失败 \n"+e.message)}}};module.exports=ie,exports.default=ie;
|
21
|
+
function k(e,t,n,o){return new(n||(n=Promise))((function(a,i){function r(e){try{u(o.next(e))}catch(e){i(e)}}function s(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,s)}u((o=o.apply(e,t||[])).next())}))}!function(e){e[e.Integration=0]="Integration",e[e.Separate=1]="Separate"}(m||(m={}));const I=y.default.tmpdir(),w=h.default.join(I,".revue_cache"),_=m.Integration,U=process.env.HYEXT_BUILD_ENV||"dev",O=h.default.resolve(__dirname,"../static"),T=h.default.join(O,"template");var E;!function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(E||(E={}));const C="project.config.json";function $(e,t){g.default.copyFileSync(h.default.join(e,C),h.default.join(t,C))}function M(){g.default.existsSync(w)||g.default.mkdirSync(w)}function F(e,t,o){return k(this,void 0,void 0,(function*(){const a="prod"===e,i=a?{minify:!0,autoPrefixWXSS:!0,minifyWXSS:!0}:{};M(),yield n.compilerManager.init({projectPath:t,outputPath:o,cachePath:w,compileSettings:i});const r=a?"compile":"compileDev";yield n.compilerManager[r](),$(t,o)}))}function N(e,t,o){return k(this,void 0,void 0,(function*(){M(),yield n.compilerManager.init({projectPath:t,outputPath:o,cachePath:w,compileSettings:{cocos:!0,minify:"prod"===e}});const a="dev"===e?"compileDev":"compile";yield n.compilerManager[a](),$(t,o)}))}const q=v.default.gray("·");var D=(e=>{e=` ${e}`;return{log(...t){const n=i.format.apply(i.format,t);console.log(v.default.white(e),q,n)},fatal(...t){t[0]instanceof Error&&(t[0]=t[0].message.trim());const n=i.format.apply(i.format,t);console.error(v.default.red(e),q,n),process.exit(1)},success(...t){const n=i.format.apply(i.format,t);console.log(v.default.green(e),q,n)}}})("REVUE");const V=Date.now(),B="production"!==process.env.HYEXT_BUILD_ENV?"//test-hd.huya.com/h5/hyext-sentry-setup-script/test/sentry-setup.js":`//a.msstatic.com/huya/hd/h5/hyext-sentry-setup-script/sentry-setup.js?hash=${V}`;function R(e,t,n){const o=g.default.readFileSync(e).toString();g.default.outputFileSync(t,function(e,t,n){return x.default.compile(e,{noEscape:!0})(t,n)}(o,n))}x.default.registerHelper("toJSON",(function(e){return new x.default.SafeString(JSON.stringify(e))}));const z={context:{deviceOrientation:"portrait"},hooks:{onMergedMainPackge:new u.SyncHook(["IOnMergedMainPackge"]),onSrartBefore:new u.SyncHook(["IOnSrartBefore"])}};class L{apply(e){e.hooks.onMergedMainPackge.tap("InjectWebviewUrlParamsPlugin",(t=>{const{compileType:n,mainPath:o}=t,a=n===E.miniGame;if(a){const t=g.default.readJsonSync(h.default.join(o,"game.json"));"string"==typeof t.deviceOrientation&&t.deviceOrientation.includes("landscape")&&(e.context.deviceOrientation="landscape")}e.context.webviewUrlParams={isLandscape:0,disablePopGesture:1,hideStatusBar:a?1:0,hideBar:1,bounces:0,hideloading:1}}))}}function G(){const e=z.context.webviewUrlParams;return e?(t=e,Object.keys(t).reduce(((e,n)=>e+`&${n}=${encodeURIComponent(t[n])}`),"")):"";var t}const J={test:"//test-extsdk.msstatic.com",prod:"//extsdk-msstatic.cdn.huya.com"};function H(e,t){const o=h.default.join(e,"package"),a=function(e){const t=h.default.join(e,"packageConfig.json");return g.default.readJSONSync(t)}(o),i=a.findIndex((e=>{return(t=e).name===n.pkgFileType.MainPkg&&"."===t.root;var t}));if(-1===i)throw new Error("无法找到主包构建信息");const r=a[i];a.splice(i,1);const s=a;return s.length>0&&function(e,t,n,o){const a=h.default.join(e,t.name);n.forEach((t=>{const n=h.default.join(e,t.name),i=h.default.join(n,t.root),r=h.default.join(a,t.root);o&&o(n,a,t),g.default.moveSync(i,r,{overwrite:!0}),g.default.removeSync(h.default.join(e,t.name))}))}(o,r,s,t),{mainPakConf:r,packagePath:o}}function W(e,t){const n=require.resolve(t);let o=h.default.join(n,"../");"dist"===h.default.basename(o)?g.default.copySync(o,e):(o=h.default.resolve(o,"../"),o=h.default.join(o,"dist"),g.default.existsSync(o)?g.default.copySync(o,e):D.log(`Builder can't resolve ${t} entry from ${n}`))}function X(e){const{builderConfig:t,mainPakConf:n,extUuid:o}=e;return t.supportExtTypes.map((e=>{const a=`index_${e}.html`;return{extType:e,entryPath:"package/"+n.name+"/"+a,sdkUrl:(i={extType:e,extUuid:o,hostId:t.hostId,isTestEnv:t.isTestEnv},`${i.isTestEnv?J.test:J.prod}/sdk/${i.extType}/${i.hostId}/${i.extUuid||0}/sdk.js`),entryFilename:a};var i}))}function K(e){!function(e){const{releasePath:t,mainPath:n,entrys:o,debug:a,dev:i,extInfo:r}=e,s=h.default.join(O,"template"),u=_===m.Integration?h.default.relative(n,t):"",c=[{input:h.default.join(s,"game-frame.hbs"),output:h.default.join(n,"game-frame.html"),data:{sourcePathPrefix:u}}];i&&c.push({input:h.default.join(s,"remote-debugger.hbs"),output:h.default.join(n,"remote-debugger.html"),data:{extUuid:r.extUuid,paramsStr:G()}});const l=o.map((e=>({input:h.default.join(s,"minigame-page-manager.hbs"),output:h.default.join(n,e.entryFilename),data:{sourcePathPrefix:u,hyextSDKUrl:e.sdkUrl,debug:a,sentryScript:i?void 0:B,buildEnv:U,extInfo:Object.assign(Object.assign({},r),{envVersion:i?"develop":"release",extType:e.extType}),deviceOrientation:z.context.deviceOrientation}})));l.concat(c).forEach((e=>{R(e.input,e.output,e.data)}))}(e),function(e){const t=r.sync("**/**.wasm",{cwd:e,ignore:Y,nodir:!0,absolute:!1});t.length&&console.log("transform wasm to base64 files: \n",t),t.forEach((t=>{const n=h.default.join(e,t),o=g.default.readFileSync(n).toString("base64");g.default.outputFileSync(n+".txt",o)}))}(e.mainPath)}const Y=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];function A(e,t,n){const o=n.name+".js",a=n.name+".js.map",i=h.default.join(e,o),r=h.default.join(e,a);g.default.existsSync(i)&&g.default.outputFileSync(h.default.join(t,o),g.default.readFileSync(i)),g.default.existsSync(r)&&g.default.outputFileSync(h.default.join(t,a),g.default.readFileSync(r))}function Q(e){!function(e){const{packagePath:t,releasePath:n,mainPath:o,entrys:a,debug:i,dev:r,extInfo:s}=e,u=function(e){const t=h.default.join(e,"packageExtConfig.json");return g.default.readJSONSync(t)}(t),c=_===m.Integration?h.default.relative(o,n):"",l=JSON.stringify(u),d=[{input:h.default.join(T,"service.hbs"),output:h.default.join(o,"service.html"),data:{sourcePathPrefix:c}}];r&&d.push({input:h.default.join(T,"remote-debugger.hbs"),output:h.default.join(o,"remote-debugger.html"),data:{extUuid:s.extUuid,paramsStr:G()}});a.map((e=>({input:h.default.join(T,"miniapp-page-manager.hbs"),output:h.default.join(o,e.entryFilename),data:{sourcePathPrefix:c,packageExtConfig:l,hyextSDKUrl:e.sdkUrl,debug:i,buildEnv:U,sentryScript:B,extInfo:Object.assign(Object.assign({},s),{envVersion:r?"develop":"release",version:"",extType:e.extType})}}))).concat(d).forEach((e=>{R(e.input,e.output,e.data)}))}(e)}function Z(e,t,n){const o={packagePath:"",mainPath:"",releasePath:t,entrys:[],extInfo:n.extInfo,debug:n.debug,dev:n.dev},a=a=>{let i;return D.log("正在合并分包..."),a||function(e){const t=h.default.join(O,"framework");if(_===m.Integration){g.default.copySync(t,h.default.join(e,"framework"));const n=h.default.join(e,"sdk");g.default.mkdirSync(n),W(n,"@revues/web-sdk-core"),W(n,"@revues/web-frame"),W(n,"@revues/hyext-adapter")}}(t),"game"==e.compileType?(i=function(e,t){const n=t.builderConfig,{mainPakConf:o,packagePath:a}=H(e),i=h.default.join(a,o.name),r=X({builderConfig:n,mainPakConf:o,extUuid:t.extInfo.extUuid});return z.hooks.onMergedMainPackge.call({mainConf:o,mainPath:i,compileType:E.miniGame}),{packagePath:a,mainPath:i,entrys:r,mainPublicPath:"package/"+o.name}}(t,n),!a&&K(Object.assign(Object.assign({},o),i))):(i=function(e,t){const n=t.builderConfig,{mainPakConf:o,packagePath:a}=H(e,A),i=h.default.join(a,o.name),r=X({builderConfig:n,mainPakConf:o,extUuid:t.extInfo.extUuid});return z.hooks.onMergedMainPackge.call({mainConf:o,mainPath:i,compileType:E.miniProgram}),{entrys:r,mainPublicPath:"package/"+o.name,mainPath:i,packagePath:a}}(t,n),!a&&Q(Object.assign(Object.assign({},o),i))),D.success("合并分包完成"),i};return Object.assign(Object.assign({},a(!1)),{retry:a})}class ee{apply(e){e.hooks.onSrartBefore.tap("RemoveUnlessDIrPlugin",(e=>{const{inputPath:t}=e,n=h.default.join(t,"release"),o=h.default.join(t,"dist");te(n),te(o)}))}}function te(e){g.default.existsSync(e)&&g.default.removeSync(e)}var ne={cert:g.default.readFileSync(h.default.join(O,"./certs/cert.pem")),key:g.default.readFileSync(h.default.join(O,"./certs/key.pem")),passphrase:""};function oe(e){return k(this,void 0,void 0,(function*(){try{const t=yield b.default.get(e,{responseType:"arraybuffer"}),n=Buffer.from(t.data),o=function(e){var t;const n=e.split("?")[0],o=n.split("/"),[a,i]=null===(t=o[o.length-1])||void 0===t?void 0:t.split(".");if(null==i||""==i)throw new Error(`url:${e}格式错误,无法获取文件信息`);return{filename:a,ext:i}}(e);return`data:image/${o.ext};base64,${n.toString("base64")}`}catch(e){return}}))}function ae(e,t){return k(this,void 0,void 0,(function*(){const{baseURI:n,entrys:o,outputPath:a}=t,i=h.default.join(a,"build-result"),r={},s=G(),u=o.map((e=>{const t={type:"HTML",content:{pages:[{path:ie(e,s)}],baseURI:n}};return r[e.extType]=t,{type:e.extType,buildResult:{[e.extType]:t}}}));if("development"===e){const e=u.map((e=>g.default.outputFile(h.default.join(i,e.type+".json"),JSON.stringify(e.buildResult,null,2))));yield Promise.all(e)}return r}))}function ie(e,t){const n=e.extType;let o=e.entryPath;return n.endsWith("_h5")&&(o+="?__module_busi__=kiwi-ExtSDK"+t),o}const re=e=>{var t;const n=(()=>{const e=y.default.networkInterfaces(),t=S.default.flatten(S.default.values(e));return S.default.filter((e=>/(ipv)?4/gi.test(e.family)&&!/^127\./.test(e.address)),t)})();return n&&n.length>1&&(D.log(`检测到本机有多个 ip 地址:\n- ${n.map((e=>e.address)).join("\n- ")}`),D.log("请在 project.config.json 的 host 中指定正确的 ip"),process.exit(1)),n&&n.length<=0&&(D.log("未能找到本机 ip 地址, 本地开发 app 侧将无法加载小程序"),process.exit(1)),null===(t=n[0])||void 0===t?void 0:t.address},se=new Set(["app_inner_h5","web_video_com","app_panel_h5","zs_anchor_panel_h5","pc_anchor_panel","pc_panel"]);function ue(e,t){const n=Object.assign({},t);return function(e){let t=[];e&&0!==e.length?e.forEach((e=>{se.has(e)||t.push(e)})):D.fatal("请在project.config.json相应地方填写supportExtTypes."),t.length>0&&D.fatal(`未支持的小程序类型:${t.join("|")}.`)}(t.supportExtTypes),function(e){null==e.hostId&&(e.hostId="huyaext")}(n),"development"===e&&function(e){e.https=!0,null==e.host&&(e.host=re()||""),null==e.port&&(e.port=18080)}(n),n}function ce(e){return`${e.https?"https":"http"}://${e.host}:${e.port}/`}const le=new class{constructor(){var e;e=z,(new L).apply(e),(new ee).apply(e)}build(e){return k(this,void 0,void 0,(function*(){const{inputPath:t,outputPath:n,publicPath:o,projectConfig:a,config:i,extUuid:r,extName:s,extVersion:u,extVersionId:c,extLogo:l}=e,d=ue("production",i);g.default.existsSync(n)&&g.default.removeSync(n),yield g.default.copy(t,n,{overwrite:!0});const{entrys:f}=Z(a,n,{builderConfig:d,extInfo:{extUuid:r,extName:s,extVersion:u,extVersionId:c,extLogo:yield oe(l)}});return yield ae("production",{entrys:f,baseURI:o,outputPath:n})}))}start(e){var t;return k(this,void 0,void 0,(function*(){const{debug:o,inputPath:a,projectConfig:i,outputPath:r,config:s}=e;z.hooks.onSrartBefore.call({inputPath:a});const u=ue("development",s),c=function(e){const t=e.appId||e.appid;return null==t||""===t?D.fatal("请填写正确的appid"):t.length>10&&D.fatal("appid错误,请登录 https://ext.huya.com/ 在您的小程序概要中查看小程序ID"),t}(i),l=(d=i).projectname||d.projectName||"小程序";var d;const f={extUuid:c,extName:l,extVersion:void 0,extVersionId:void 0,extLogo:yield oe("https://huyaimg.msstatic.com/avatar/1080/b2/ef4543945bd245f4ab659f24e5781b_180_135.jpg?1577952143")};let p=e=>{};const m=(g=`${l}-${c}`,h.default.join(I,".revues-projects",g));var g;"game"==i.compileType?yield function(e,t,o){return k(this,void 0,void 0,(function*(){yield N("dev",e,t),n.compilerManager.watch({graphId:"game"},((e,t)=>k(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"game"}),o&&o()}))))}))}(a,m,(()=>{p(!0)})):yield function(e,t,o){return k(this,void 0,void 0,(function*(){yield F("dev",e,t),n.compilerManager.watch({graphId:"miniprogram"},((e,t)=>k(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"miniprogram"}),o&&o()}))))}))}(a,m,(()=>{p(!0)}));const{entrys:y,mainPublicPath:v,retry:x}=Z(i,m,{builderConfig:u,extInfo:f,debug:o,dev:!0});return p=x,D.log("启动 live server 服务..."),D.success("本地访问地址:",ce(u)+(null===(t=y[0])||void 0===t?void 0:t.entryPath)),D.success("扫码预览地址:",ce(u)+v+"/remote-debugger.html"),function(e){var t={port:e.port,host:e.host,root:e.root,open:!1,ignore:e.ignore,file:"index.html",wait:1e3,mount:e.mount,logLevel:1,https:ne};j.default.start(t)}(Object.assign(Object.assign({},u),{root:m,ignore:"node_modules"})),yield ae("development",{entrys:y,baseURI:ce(u),outputPath:r})}))}release(e){return k(this,void 0,void 0,(function*(){const{contextPath:t,releasePath:n,projectConfig:o}=e;g.default.existsSync(n)&&g.default.removeSync(n),D.log("开始打包");const a=o.projectName||o.projectname||"project",i=h.default.join(n,a);"game"==o.compileType?yield N("prod",t,i):yield F("prod",t,i);const r=h.default.join(n,a);var s;yield(s=r,new Promise(((e,t)=>{const n=g.default.createWriteStream(`${s}.zip`),o=P.default("zip",{zlib:{level:9}});n.on("close",(()=>{const t=o.pointer();e({name:`${h.default.basename(s)}.zip`,size:t})})),o.on("warning",(e=>{if("ENOENT"!==e.code)throw e})),o.on("error",(e=>{throw t(e),e})),o.pipe(n),o.directory(`${s}`,!1),o.finalize()}))),D.success("打包成功,zip包地址:"+r)}))}config(){}providedProjectConfig(){}clearCache(){try{g.default.existsSync(w)&&g.default.removeSync(w),D.success("项目缓存清除成功~")}catch(e){D.success("项目缓存清除失败 \n"+e.message)}}};module.exports=le,exports.default=le;
|
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hyext/builder-revues",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"description": "> TODO: description",
|
5
|
-
"author": "
|
5
|
+
"author": "loler",
|
6
6
|
"homepage": "",
|
7
7
|
"license": "ISC",
|
8
8
|
"main": "dist",
|
@@ -18,18 +18,19 @@
|
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|
21
|
-
"url": "https://git.huya.com/exc/web/
|
21
|
+
"url": "https://git.huya.com/exc/web/revue.git"
|
22
22
|
},
|
23
23
|
"scripts": {
|
24
24
|
"minify": "node scripts/minify"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@revues/cocos-web-adapter": "1.0.
|
28
|
-
"@revues/code-compiler": "1.0.
|
29
|
-
"@revues/hyext-adapter": "1.0.
|
30
|
-
"@revues/web-frame": "1.0.
|
31
|
-
"@revues/web-sdk-core": "1.0.
|
27
|
+
"@revues/cocos-web-adapter": "1.0.3",
|
28
|
+
"@revues/code-compiler": "1.0.4",
|
29
|
+
"@revues/hyext-adapter": "1.0.4",
|
30
|
+
"@revues/web-frame": "1.0.4",
|
31
|
+
"@revues/web-sdk-core": "1.0.4",
|
32
32
|
"archiver": "^7.0.1",
|
33
|
+
"axios": "^1.7.1",
|
33
34
|
"chalk": "^2.4.2",
|
34
35
|
"fs-extra": "8.1.0",
|
35
36
|
"glob": "^10.3.10",
|
@@ -45,5 +46,5 @@
|
|
45
46
|
"@types/ramda": "^0.29.11",
|
46
47
|
"terser": "^5.31.0"
|
47
48
|
},
|
48
|
-
"gitHead": "
|
49
|
+
"gitHead": "a8f4d4c4717129215884f10c18600845f59d55e5"
|
49
50
|
}
|
@@ -6,8 +6,15 @@
|
|
6
6
|
<meta id="viewport" name="viewport"
|
7
7
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
|
8
8
|
<meta name="content-type" content="text/html; charset=utf-8">
|
9
|
+
<meta name="ext-name" content="{{extInfo.extName}}">
|
9
10
|
<meta name="ext-type" content="{{extInfo.extType}}">
|
10
11
|
<meta name="ext-uuid" content="{{extInfo.extUuid}}">
|
12
|
+
{{#if extInfo.extVersion}}
|
13
|
+
<meta name="ext-version" content="{{extInfo.extVersion}}">
|
14
|
+
<meta name="ext-version-id" content="{{extInfo.extVersionId}}">
|
15
|
+
{{/if}}
|
16
|
+
<meta name="ext-busi-type" content="ext">
|
17
|
+
<meta name="ext-build-env" content="{{buildEnv}}">
|
11
18
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
12
19
|
<style>
|
13
20
|
html,
|
@@ -67,9 +74,6 @@
|
|
67
74
|
window.__debug = true
|
68
75
|
</script>
|
69
76
|
{{/if}}
|
70
|
-
{{#if sentryScript}}
|
71
|
-
<script charset="utf-8" src="{{sentryScript}}"></script>
|
72
|
-
{{/if}}
|
73
77
|
<script charset="utf-8">
|
74
78
|
window.__packageExtConfig = {{ packageExtConfig }}
|
75
79
|
</script>
|
@@ -84,6 +88,9 @@
|
|
84
88
|
<div class="views" id="webview-container">
|
85
89
|
<iframe class="service" id="webview-service" src="./service.html"></iframe>
|
86
90
|
</div>
|
91
|
+
{{#if sentryScript}}
|
92
|
+
<script charset="utf-8" src="{{sentryScript}}"></script>
|
93
|
+
{{/if}}
|
87
94
|
</body>
|
88
95
|
|
89
96
|
</html>
|
@@ -7,8 +7,15 @@
|
|
7
7
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
|
8
8
|
<meta name="content-type" content="text/html; charset=utf-8">
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
10
|
+
<meta name="ext-name" content="{{extInfo.extName}}">
|
10
11
|
<meta name="ext-type" content="{{extInfo.extType}}">
|
11
12
|
<meta name="ext-uuid" content="{{extInfo.extUuid}}">
|
13
|
+
{{#if extInfo.extVersion}}
|
14
|
+
<meta name="ext-version" content="{{extInfo.extVersion}}">
|
15
|
+
<meta name="ext-version-id" content="{{extInfo.extVersionId}}">
|
16
|
+
{{/if}}
|
17
|
+
<meta name="ext-busi-type" content="game">
|
18
|
+
<meta name="ext-build-env" content="{{buildEnv}}">
|
12
19
|
<style>
|
13
20
|
.service,
|
14
21
|
.service-preload,
|
@@ -66,9 +73,6 @@
|
|
66
73
|
window.__debug = true
|
67
74
|
</script>
|
68
75
|
{{/if}}
|
69
|
-
{{#if sentryScript}}
|
70
|
-
<script charset="utf-8" src="{{sentryScript}}"></script>
|
71
|
-
{{/if}}
|
72
76
|
<link rel='stylesheet' href='{{sourcePathPrefix}}/sdk/web-frame.css'>
|
73
77
|
<script charset="utf-8" src="{{sourcePathPrefix}}/sdk/web-frame.js"></script>
|
74
78
|
<script charset="utf-8" src="{{hyextSDKUrl}}"></script>
|
@@ -80,6 +84,9 @@
|
|
80
84
|
<div class="views" id="webview-container">
|
81
85
|
<iframe class="service service-view" id="webview-service" src="./game-frame.html"></iframe>
|
82
86
|
</div>
|
87
|
+
{{#if sentryScript}}
|
88
|
+
<script charset="utf-8" src="{{sentryScript}}"></script>
|
89
|
+
{{/if}}
|
83
90
|
</body>
|
84
91
|
|
85
92
|
</html>
|
@@ -46,7 +46,7 @@
|
|
46
46
|
<div class="container">
|
47
47
|
<canvas id="canvas"></canvas>
|
48
48
|
<span class="title">扫码调试</span>
|
49
|
-
<span class="tip">如未绑定全局小程序下发,请先<a href="">绑定</a></span>
|
49
|
+
<span class="tip">如未绑定全局小程序下发,请先<a href="https://dev.huya.com/docs/miniapp/dev/game/wechat-debug/" target="_blank">绑定</a></span>
|
50
50
|
<span class="tip">如需查看 vconsole, 可在 project.config.json 把 debug 字段设置为 true</a></span>
|
51
51
|
</div>
|
52
52
|
<script>
|