@hyext/builder-revues 1.0.1 → 1.0.3

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,4 +3,19 @@
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"),a=require("@revues/code-compiler"),n=require("os"),o=require("chalk"),i=require("util"),r=require("glob"),u=require("handlebars"),s=require("tapable"),c=require("live-server"),l=require("archiver"),d=require("ramda");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f,m=p(e),g=p(t),h=p(n),y=p(o),x=p(u),P=p(c),j=p(l),v=p(d);!function(e){e[e.Integration=0]="Integration",e[e.Separate=1]="Separate"}(f||(f={}));const S=h.default.tmpdir(),b=g.default.join(S,".revue_cache"),w=f.Integration,k=g.default.resolve(__dirname,"../static");var U;!function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(U||(U={}));const I="project.config.json";function _(e,t){m.default.copyFileSync(g.default.join(e,I),g.default.join(t,I))}function C(){m.default.existsSync(b)||m.default.mkdirSync(b)}async function T(e,t){C(),await a.compilerManager.init({projectPath:e,outputPath:t,cachePath:b}),await a.compilerManager.compileDev(),_(e,t)}async function E(e,t){C(),await a.compilerManager.init({projectPath:e,outputPath:t,cachePath:b,compileSettings:{cocos:!0}}),await a.compilerManager.compileDev(),_(e,t)}const N=y.default.gray("·");var M=(e=>{e=` ${e}`;return{log(...t){const a=i.format.apply(i.format,t);console.log(y.default.white(e),N,a)},fatal(...t){t[0]instanceof Error&&(t[0]=t[0].message.trim());const a=i.format.apply(i.format,t);console.error(y.default.red(e),N,a),process.exit(1)},success(...t){const a=i.format.apply(i.format,t);console.log(y.default.green(e),N,a)}}})("REVUE");const $=Date.now(),O="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 F(e,t,a){const n=m.default.readFileSync(e).toString();m.default.outputFileSync(t,function(e,t,a){return x.default.compile(e,{noEscape:!0})(t,a)}(n,a))}x.default.registerHelper("toJSON",(function(e){return new x.default.SafeString(JSON.stringify(e))}));const q={context:{deviceOrientation:"portrait"},hooks:{onMergedMainPackge:new s.SyncHook(["IOnMergedMainPackge"]),onSrartBefore:new s.SyncHook(["IOnSrartBefore"])}};class D{apply(e){e.hooks.onMergedMainPackge.tap("InjectWebviewUrlParamsPlugin",(t=>{const{compileType:a,mainPath:n}=t,o=a===U.miniGame;if(o){const t=m.default.readJsonSync(g.default.join(n,"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 R(){const e=q.context.webviewUrlParams;return e?(t=e,Object.keys(t).reduce(((e,a)=>e+`&${a}=${encodeURIComponent(t[a])}`),"")):"";var t}const z={test:"//test-extsdk.msstatic.com",prod:"//extsdk-msstatic.cdn.huya.com"};function B(e,t,n){const o=g.default.join(t,"package"),i=function(e){const t=g.default.join(e,"packageConfig.json");return m.default.readJSONSync(t)}(o),r=i.findIndex((e=>{return(t=e).name===a.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,a,n){const o=g.default.join(e,t.name);a.forEach((t=>{const a=g.default.join(e,t.name),i=g.default.join(a,t.root),r=g.default.join(o,t.root);n&&n(a,o,t),m.default.moveSync(i,r,{overwrite:!0}),m.default.removeSync(g.default.join(e,t.name))}))}(o,u,s,n),!e){const e=g.default.join(k,"framework");if(w===f.Integration){m.default.copySync(e,g.default.join(t,"framework"));const a=g.default.join(t,"sdk");m.default.mkdirSync(a),G(a,"@revues/web-sdk-core"),G(a,"@revues/web-frame"),G(a,"@revues/hyext-adapter")}}return{mainPakConf:u,packagePath:o}}function G(e,t){const a=require.resolve(t);let n=g.default.join(a,"../");"dist"===g.default.basename(n)?m.default.copySync(n,e):(n=g.default.resolve(n,"../"),n=g.default.join(n,"dist"),m.default.existsSync(n)?m.default.copySync(n,e):M.log(`Builder can't resolve ${t} entry from ${a}`))}function J(e){const{builderConfig:t,mainPakConf:a,extUuid:n}=e;return t.supportExtTypes.map((e=>{const o=`index_${e}.html`;return{extType:e,entryPath:"package/"+a.name+"/"+o,sdkUrl:(i={extType:e,extUuid:n,hostId:t.hostId,isTestEnv:t.isTestEnv},`${i.isTestEnv?z.test:z.prod}/sdk/${i.extType}/${i.hostId}/${i.extUuid||0}/sdk.js`),entryFilename:o};var i}))}function H(e,t){const a=t.extName,n=t.extUuid,o=t.builderConfig,i=!!t.watch,{mainPakConf:u,packagePath:s}=B(i,e),c=g.default.join(k,"template"),l=g.default.join(s,u.name),d=J({builderConfig:o,mainPakConf:u,extUuid:n});return q.hooks.onMergedMainPackge.call({mainConf:u,mainPath:l,compileType:U.miniGame}),i||(function(e){const{mainPath:t,sourcePathPrefix:a,templatePath:n,entrys:o,debug:i,dev:r,extUuid:u,extName:s}=e,c=[{input:g.default.join(n,"game-frame.hbs"),output:g.default.join(t,"game-frame.html"),data:{sourcePathPrefix:a}}];r&&c.push({input:g.default.join(n,"remote-debugger.hbs"),output:g.default.join(t,"remote-debugger.html"),data:{extUuid:u,paramsStr:R()}});const l=o.map((e=>({input:g.default.join(n,"minigame-page-manager.hbs"),output:g.default.join(t,e.entryFilename),data:{sourcePathPrefix:a,hyextSDKUrl:e.sdkUrl,debug:i,sentryScript:r?void 0:O,extInfo:{extUuid:u,envVersion:r?"develop":"release",extType:e.extType,extName:s},deviceOrientation:q.context.deviceOrientation}})));l.concat(c).forEach((e=>{F(e.input,e.output,e.data)}))}({entrys:d,sourcePathPrefix:w===f.Integration?g.default.relative(l,e):"",templatePath:c,mainPath:l,extUuid:n,extName:a,...t.template}),function(e){const t=r.sync("**/**.wasm",{cwd:e,ignore:L,nodir:!0,absolute:!1});t.length&&console.log("transform wasm to base64 files: \n",t),t.forEach((t=>{const a=g.default.join(e,t),n=m.default.readFileSync(a).toString("base64");m.default.outputFileSync(a+".txt",n)}))}(l)),{entrys:d,mainPublicPath:"package/"+u.name}}const L=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];function V(e,t,a){const n=a.name+".js",o=a.name+".js.map",i=g.default.join(e,n),r=g.default.join(e,o);m.default.existsSync(i)&&m.default.outputFileSync(g.default.join(t,n),m.default.readFileSync(i)),m.default.existsSync(r)&&m.default.outputFileSync(g.default.join(t,o),m.default.readFileSync(r))}function K(e,t){const a=t.extName,n=t.extUuid,o=t.builderConfig,i=!!t.watch,{mainPakConf:r,packagePath:u}=B(i,e,V),s=function(e){const t=g.default.join(e,"packageExtConfig.json");return m.default.readJSONSync(t)}(u),c=g.default.join(k,"template"),l=g.default.join(u,r.name),d=J({builderConfig:o,mainPakConf:r,extUuid:n});return q.hooks.onMergedMainPackge.call({mainConf:r,mainPath:l,compileType:U.miniProgram}),i||function(e){const{mainPath:t,sourcePathPrefix:a,templatePath:n,entrys:o,packageExtConfig:i,debug:r,dev:u,extUuid:s,extName:c}=e,l=JSON.stringify(i),d=[{input:g.default.join(n,"service.hbs"),output:g.default.join(t,"service.html"),data:{sourcePathPrefix:a}}];u&&d.push({input:g.default.join(n,"remote-debugger.hbs"),output:g.default.join(t,"remote-debugger.html"),data:{extUuid:s,paramsStr:R()}});const p=o.map((e=>({input:g.default.join(n,"miniapp-page-manager.hbs"),output:g.default.join(t,e.entryFilename),data:{sourcePathPrefix:a,packageExtConfig:l,hyextSDKUrl:e.sdkUrl,debug:r,sentryScript:u?void 0:O,extInfo:{extUuid:s,envVersion:u?"develop":"release",version:"",extType:e.extType,extName:c}}})));p.concat(d).forEach((e=>{F(e.input,e.output,e.data)}))}({entrys:d,sourcePathPrefix:w===f.Integration?g.default.relative(l,e):"",packageExtConfig:s,templatePath:c,mainPath:l,extUuid:n,extName:a,...t.template}),{entrys:d,mainPublicPath:"package/"+r.name}}class W{apply(e){e.hooks.onSrartBefore.tap("RemoveUnlessDIrPlugin",(e=>{const{inputPath:t}=e,a=g.default.join(t,"release"),n=g.default.join(t,"dist");X(a),X(n)}))}}function X(e){m.default.existsSync(e)&&m.default.removeSync(e)}var Y={cert:m.default.readFileSync(g.default.join(k,"./certs/cert.pem")),key:m.default.readFileSync(g.default.join(k,"./certs/key.pem")),passphrase:""};async function A(e,t){const{baseURI:a,entrys:n,outputPath:o}=t,i=g.default.join(o,"build-result"),r={},u=R(),s=n.map((e=>{const t={type:"HTML",content:{pages:[{path:Q(e,u)}],baseURI:a}};return r[e.extType]=t,{type:e.extType,buildResult:{[e.extType]:t}}}));if("development"===e){const e=s.map((e=>m.default.outputFile(g.default.join(i,e.type+".json"),JSON.stringify(e.buildResult,null,2))));await Promise.all(e)}return r}function Q(e,t){const a=e.extType;let n=e.entryPath;return a.endsWith("_h5")&&(n+="?__module_busi__=kiwi-ExtSDK"+t),n}const Z=e=>{const t=(()=>{const e=h.default.networkInterfaces(),t=v.default.flatten(v.default.values(e));return v.default.filter((e=>/(ipv)?4/gi.test(e.family)&&!/^127\./.test(e.address)),t)})();return t&&t.length>1&&(M.log(`检测到本机有多个 ip 地址:\n- ${t.map((e=>e.address)).join("\n- ")}`),M.log("请在 project.config.json 的 host 中指定正确的 ip"),process.exit(1)),t&&t.length<=0&&(M.log("未能找到本机 ip 地址, 本地开发 app 侧将无法加载小程序"),process.exit(1)),t[0]?.address},ee=new Set(["app_inner_h5","web_video_com","app_panel_h5","zs_anchor_panel_h5","pc_anchor_panel","pc_panel"]);function te(e,t){const a={...t};return function(e){let t=[];e&&0!==e.length?e.forEach((e=>{ee.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")}(a),"development"===e&&function(e){e.https=!0,null==e.host&&(e.host=Z()||""),null==e.port&&(e.port=18080)}(a),a}function ae(e){return`${e.https?"https":"http"}://${e.host}:${e.port}/`}function ne(e,t,a){M.log("正在合并分包...");const n=("game"==e.compileType?H:K)(t,a);return M.success("合并分包完成"),n}const oe=new class{constructor(){var e;e=q,(new D).apply(e),(new W).apply(e)}async build(e){const{inputPath:t,outputPath:a,publicPath:n,projectConfig:o,config:i,extUuid:r,extName:u}=e,s=te("production",i);m.default.existsSync(a)&&m.default.removeSync(a),await m.default.copy(t,a,{overwrite:!0});const{entrys:c}=ne(o,a,{builderConfig:s,extUuid:r,extName:u});return await A("production",{entrys:c,baseURI:n,outputPath:a})}async start(e){const{debug:t,inputPath:n,projectConfig:o,outputPath:i,config:r}=e;q.hooks.onSrartBefore.call({inputPath:n});const u=(s=g.default.basename(n),g.default.join(S,".revues-projects",s));var s;const c=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}(o),l=(d=o).projectname||d.projectName||"小程序";var d;const p=te("development",r);"game"==o.compileType?await async function(e,t,n){await E(e,t),a.compilerManager.watch({graphId:"game"},(async(e,t)=>{await a.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"game"}),n&&n()}))}(n,u,(()=>{ne(o,u,{builderConfig:p,watch:!0})})):await async function(e,t,n){await T(e,t),a.compilerManager.watch({graphId:"miniprogram"},(async(e,t)=>{await a.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"miniprogram"}),n&&n()}))}(n,u,(()=>{ne(o,u,{builderConfig:p,watch:!0})}));const{entrys:f,mainPublicPath:m}=ne(o,u,{builderConfig:p,extUuid:c,extName:l,template:{debug:t,dev:!0}});return M.log("启动 live server 服务..."),M.success("本地访问地址:",ae(p)+f[0]?.entryPath),M.success("扫码预览地址:",ae(p)+m+"/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:Y};P.default.start(t)}({...p,root:u,ignore:"node_modules"}),await A("development",{entrys:f,baseURI:ae(p),outputPath:i})}async release(e){const{contextPath:t,releasePath:a,projectConfig:n}=e;m.default.existsSync(a)&&m.default.removeSync(a),M.log("开始打包");const o=n.projectName||n.projectname||"project",i=g.default.join(a,o);"game"==n.compileType?await E(t,i):await T(t,i);const r=g.default.join(a,o);var u;await(u=r,new Promise(((e,t)=>{const a=m.default.createWriteStream(`${u}.zip`),n=j.default("zip",{zlib:{level:9}});a.on("close",(()=>{const t=n.pointer();e({name:`${g.default.basename(u)}.zip`,size:t})})),n.on("warning",(e=>{if("ENOENT"!==e.code)throw e})),n.on("error",(e=>{throw t(e),e})),n.pipe(a),n.directory(`${u}`,!1),n.finalize()}))),M.success("打包成功,zip包地址:"+r)}config(){}providedProjectConfig(){}clearCache(){try{m.default.existsSync(b)&&m.default.removeSync(b),M.success("项目缓存清除成功~")}catch(e){M.success("项目缓存清除失败 \n"+e.message)}}};module.exports=oe,exports.default=oe;
6
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs-extra"),t=require("path"),n=require("@revues/code-compiler"),a=require("os"),o=require("chalk"),i=require("util"),r=require("glob"),u=require("handlebars"),s=require("tapable"),c=require("live-server"),l=require("archiver"),d=require("ramda");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f,m=p(e),h=p(t),g=p(a),y=p(o),v=p(u),x=p(c),P=p(l),j=p(d);
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyext/builder-revues",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "> TODO: description",
5
5
  "author": "diamondloler <857276958@qq.com>",
6
6
  "homepage": "",
@@ -24,11 +24,11 @@
24
24
  "minify": "node scripts/minify"
25
25
  },
26
26
  "dependencies": {
27
- "@revues/cocos-web-adapter": "1.0.1",
28
- "@revues/code-compiler": "1.0.1",
29
- "@revues/hyext-adapter": "1.0.1",
30
- "@revues/web-frame": "1.0.1",
31
- "@revues/web-sdk-core": "1.0.1",
27
+ "@revues/cocos-web-adapter": "1.0.3",
28
+ "@revues/code-compiler": "1.0.3",
29
+ "@revues/hyext-adapter": "1.0.3",
30
+ "@revues/web-frame": "1.0.3",
31
+ "@revues/web-sdk-core": "1.0.3",
32
32
  "archiver": "^7.0.1",
33
33
  "chalk": "^2.4.2",
34
34
  "fs-extra": "8.1.0",
@@ -45,5 +45,5 @@
45
45
  "@types/ramda": "^0.29.11",
46
46
  "terser": "^5.31.0"
47
47
  },
48
- "gitHead": "4ad689f5091fd9727b3f28cedf0a9643c4a8b570"
48
+ "gitHead": "4a8ff28b18f4a093529a9087f302e1f4b91d9af6"
49
49
  }
@@ -64,6 +64,7 @@
64
64
  <script charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/vConsole/3.15.1/vconsole.min.js"></script>
65
65
  <script>
66
66
  new VConsole()
67
+ window.__debug = true
67
68
  </script>
68
69
  {{/if}}
69
70
  {{#if sentryScript}}
@@ -63,6 +63,7 @@
63
63
  <script charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/vConsole/3.15.1/vconsole.min.js"></script>
64
64
  <script>
65
65
  new VConsole()
66
+ window.__debug = true
66
67
  </script>
67
68
  {{/if}}
68
69
  {{#if sentryScript}}