@hyext/builder-revues 1.0.9 → 1.0.12
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"),i=require("os"),o=require("chalk"),a=require("util"),r=require("download"),u=require("glob"),s=require("handlebars"),c=require("tapable"),l=require("live-server"),d=require("archiver"),p=require("axios"),f=require("ramda");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m,h=g(e),y=g(t),v=g(i),j=g(o),P=g(r),x=g(s),b=g(l),S=g(d),k=g(p),w=g(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 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"),T=m.Integration,_=process.env.HYEXT_BUILD_ENV||"dev",O=h.default.resolve(__dirname,"../static"),E=h.default.join(O,"template");var U;!function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(U||(U={}));const $=v.default.gray("·");var C=(e=>{e=` ${e}`;return{log(...t){const n=i.format.apply(i.format,t);console.log(v.default.white(e),$,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),$,n),process.exit(1)},success(...t){const n=i.format.apply(i.format,t);console.log(v.default.green(e),$,n)}}})("REVUE");const M="project.config.json";function F(e,t){g.default.copyFileSync(h.default.join(e,M),h.default.join(t,M))}function N(){g.default.existsSync(w)||g.default.mkdirSync(w)}function q(e,t,o){return k(this,void 0,void 0,(function*(){const a="prod"===e,i=a?{minify:!0,autoPrefixWXSS:!0,minifyWXSS:!0}:{};N(),yield n.compilerManager.init({projectPath:t,outputPath:o,cachePath:w,compileSettings:i});const r=a?"compile":"compileDev";yield n.compilerManager[r](),F(t,o)}))}function D(e,t,o){return k(this,void 0,void 0,(function*(){N(),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](),F(t,o)}))}const B=Date.now(),V="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=${B}`;function R(e,t,n){const o=g.default.readFileSync(e).toString();g.default.outputFileSync(t,function(e,t,n){return j.default.compile(e,{noEscape:!0})(t,n)}(o,n))}j.default.registerHelper("toJSON",(function(e){return new j.default.SafeString(JSON.stringify(e))}));const z={context:{deviceOrientation:"portrait"},hooks:{onMergedMainPackge:new u.SyncHook(["IOnMergedMainPackge"]),onSrartBefore:new u.SyncHook(["IOnSrartBefore"])}};class G{apply(e){e.hooks.onMergedMainPackge.tap("InjectWebviewUrlParamsPlugin",(t=>{const{compileType:n,mainPath:o}=t,a=n===U.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 L(){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):C.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=T===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:{extInfo:r,paramsStr:L()}});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:V,buildEnv:_,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=T===m.Integration?h.default.relative(o,n):"",l=JSON.stringify(u),d=[{input:h.default.join(E,"service.hbs"),output:h.default.join(o,"service.html"),data:{sourcePathPrefix:c}}];r&&d.push({input:h.default.join(E,"remote-debugger.hbs"),output:h.default.join(o,"remote-debugger.html"),data:{extInfo:s,paramsStr:L()}});a.map((e=>({input:h.default.join(E,"miniapp-page-manager.hbs"),output:h.default.join(o,e.entryFilename),data:{sourcePathPrefix:c,packageExtConfig:l,hyextSDKUrl:e.sdkUrl,debug:i,buildEnv:_,sentryScript:V,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 C.log("正在合并分包..."),a||function(e){const t=h.default.join(O,"framework");if(T===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:U.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:U.miniProgram}),{entrys:r,mainPublicPath:"package/"+o.name,mainPath:i,packagePath:a}}(t,n),!a&&Q(Object.assign(Object.assign({},o),i))),C.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(t){throw new Error(`urlToBase64 failed, url is "${e}", error msg is ${t.message}`)}}))}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=L(),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&&(C.log(`检测到本机有多个 ip 地址:\n- ${n.map((e=>e.address)).join("\n- ")}`),C.log("请在 project.config.json 的 host 中指定正确的 ip"),process.exit(1)),n&&n.length<=0&&(C.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)})):C.fatal("请在project.config.json相应地方填写supportExtTypes."),t.length>0&&C.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}/`}function le(e){return"game"===e.compileType?"miniGame":"miniProgram"}const de=new class{constructor(){var e;e=z,(new G).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:p}=Z(a,n,{builderConfig:d,extInfo:{projectType:le(a),extUuid:r,extName:s,extVersion:u,extVersionId:c,extLogo:yield oe(l)}});return yield ae("production",{entrys:p,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?C.fatal("请填写正确的appid"):t.length>10&&C.fatal("appid错误,请登录 https://ext.huya.com/ 在您的小程序概要中查看小程序ID"),t}(i),l=(d=i).projectname||d.projectName||"小程序";var d;const p={extUuid:c,extName:l,projectType:le(i),extVersion:void 0,extVersionId:void 0,extLogo:void 0};let f=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 D("dev",e,t),n.compilerManager.watch({graphId:"game"},((a,i)=>k(this,void 0,void 0,(function*(){C.log("detected change:",i),C.log("recompile..."),n.compilerManager.destroy(),yield n.compilerManager.init({projectPath:e,outputPath:t,cachePath:w,compileSettings:{cocos:!0}}),yield n.compilerManager.compileDev(!0),o&&o()}))))}))}(a,m,(()=>{f(!0)})):yield function(e,t,o){return k(this,void 0,void 0,(function*(){yield q("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,(()=>{f(!0)}));const{entrys:y,mainPublicPath:v,retry:j}=Z(i,m,{builderConfig:u,extInfo:p,debug:o,dev:!0});return f=j,C.log("启动 live server 服务..."),C.success("本地访问地址:",ce(u)+(null===(t=y[0])||void 0===t?void 0:t.entryPath)),C.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};x.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),C.log("开始打包");const a=o.projectName||o.projectname||"project",i=h.default.join(n,a);"game"==o.compileType?yield D("prod",t,i):yield q("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()}))),C.success("打包成功,zip包地址:"+r)}))}config(){}providedProjectConfig(){}clearCache(){try{g.default.existsSync(w)&&g.default.removeSync(w),C.success("项目缓存清除成功~")}catch(e){C.success("项目缓存清除失败 \n"+e.message)}}};module.exports=de,exports.default=de;
|
21
|
+
function I(e,t,n,i){return new(n||(n=Promise))((function(o,a){function r(e){try{s(i.next(e))}catch(e){a(e)}}function u(e){try{s(i.throw(e))}catch(e){a(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((i=i.apply(e,t||[])).next())}))}!function(e){e[e.Integration=0]="Integration",e[e.Separate=1]="Separate"}(m||(m={}));const O=v.default.tmpdir(),T=y.default.join(O,".revue_cache"),_=y.default.join(O,".revues-projects"),C="__plugin__",$=y.default.join(_,C),E="https://hd.huya.com/h5/static-source/alex/wx-plugin",M=m.Integration,U=process.env.HYEXT_BUILD_ENV||"dev",F=y.default.resolve(__dirname,"../static"),N=y.default.join(F,"template");var D;!function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(D||(D={}));const q=j.default.gray("·");var z=(e=>{e=` ${e}`;return{log(...t){const n=a.format.apply(a.format,t);console.log(j.default.white(e),q,n)},fatal(...t){t[0]instanceof Error&&(t[0]=t[0].message.trim());const n=a.format.apply(a.format,t);console.error(j.default.red(e),q,n),process.exit(1)},success(...t){const n=a.format.apply(a.format,t);console.log(j.default.green(e),q,n)}}})("REVUE");const B="project.config.json";function V(e,t){h.default.copyFileSync(y.default.join(e,B),y.default.join(t,B))}function R(){h.default.existsSync(T)||h.default.mkdirSync(T)}var J;function K(e,t){e.status=t}function G(e){return I(this,void 0,void 0,(function*(){const t=yield function(e){return I(this,void 0,void 0,(function*(){const t=["app","game","plugin"];for(let n=0;n<t.length;n++){const i=y.default.join(e,`${t[n]}.json`);if(yield h.default.exists(i))return{data:yield h.default.readJson(i),fileType:t[n]}}return null}))}(e);if(null!=t){const{data:n,fileType:i}=t;if("game"===i)return yield L(e,$,n);{const t=yield L(e,$,n);if(n.subpackages&&n.subpackages.length>0){const i=yield function(e,t){return I(this,void 0,void 0,(function*(){let n=[];for(let i=0;i<e.subpackages.length;i++){const o=e.subpackages[i];null!=o.export&&(o.export=o.rootDir+"/"+o.export);const a=yield L(t,$,o);n=n.concat(a.plugins)}return n}))}(n,e);if(i.length>0)return{plugins:[...t.plugins,...i]}}return t}}return{plugins:[]}}))}function L(e,t,n){return I(this,void 0,void 0,(function*(){const i=t,o=n.gamePlugins||n.plugins;if(null!=o){const t=Object.keys(o).map((e=>{const t=o[e];return function(e,t,n){const i=y.default.join(e,n.provider,n.version),o=Object.assign(Object.assign({},n),{key:t,id:n.provider,releasePath:y.default.join(i,n.provider),dir:i,status:J.None});return o.request=function(e,t){return`${E}/${e}-${t}.zip`}(n.provider,n.version),o}(i,e,t)}));if(t.length>0)return yield h.default.ensureDir(i),yield function(e){return I(this,void 0,void 0,(function*(){const t=e.map((e=>function(e){return I(this,void 0,void 0,(function*(){if(yield h.default.exists(e.releasePath))K(e,J.OK),H("reuse",e);else try{yield P.default(e.request,e.releasePath,{extract:!0}),K(e,J.OK),H("load success",e)}catch(t){K(e,J.Fail),H("load fail: "+t.message+"\n",e)}}))}(e)));yield Promise.all(t)}))}(t),yield function(e,t){return I(this,void 0,void 0,(function*(){let n=e.filter((e=>e.status===J.OK));const i=e.filter((e=>e.status===J.Fail));if(i.length>0){const e=function(e,t){return e.filter((e=>null!=e.path)).map((e=>(e.localDir=function(e,t){return y.default.join(e,t.path)}(t,e),H("use local plugin <projectRoot>/"+e.path,e),K(e,J.OK),e)))}(i,t);e.length>0&&(n=n.concat(e))}return{plugins:W(n)}}))}(t,e)}return{plugins:[]}}))}function W(e){return e.map((e=>{const t=e.localDir||e.releasePath,n=h.default.readJSONSync(y.default.join(t,"plugin.json"));return e.json=n,e}))}function H(e,t){z.success(`${e} provider:`+t.provider+", version:"+t.version)}function X(e,t,i){return I(this,void 0,void 0,(function*(){const o="prod"===e,a=o?{minify:!0,autoPrefixWXSS:!0,minifyWXSS:!0}:{},{plugins:r}=yield G(t);R(),yield n.compilerManager.init({projectPath:t,outputPath:i,cachePath:T,compileSettings:a,plugins:r});const u=o?"compile":"compileDev";yield n.compilerManager[u](),V(t,i)}))}function Y(e,t,i){return I(this,void 0,void 0,(function*(){R();const{plugins:o}=yield G(t),a={projectPath:t,outputPath:i,cachePath:T,plugins:o,compileSettings:{cocos:!0,minify:"prod"===e}};yield n.compilerManager.init(Object.assign({},a));const r="dev"===e?"compileDev":"compile";return yield n.compilerManager[r](),V(t,i),a}))}!function(e){e[e.Fail=-1]="Fail",e[e.None=0]="None",e[e.OK=1]="OK"}(J||(J={}));const A={plugin:function(e){return I(this,void 0,void 0,(function*(){const{projectPath:t,outputPath:i,cb:o}=e;yield X("dev",t,i),n.compilerManager.watch({graphId:"miniprogram"},((e,t)=>I(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"miniprogram"}),o&&o()})))),n.compilerManager.watch({graphId:"plugin"},((e,t)=>I(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"plugin"}),o&&o()}))))}))},game:function(e){return I(this,void 0,void 0,(function*(){const{projectPath:t,outputPath:i,cb:o}=e,a=yield Y("dev",t,i);n.compilerManager.watch({graphId:"game"},((e,t)=>I(this,void 0,void 0,(function*(){z.log("detected change:",t),z.log("recompile..."),n.compilerManager.destroy(),yield n.compilerManager.init(Object.assign({},a)),yield n.compilerManager.compileDev(!0),o&&o()}))))}))},miniprogram:function(e){return I(this,void 0,void 0,(function*(){const{projectPath:t,outputPath:i,cb:o}=e;yield X("dev",t,i),n.compilerManager.watch({graphId:"miniprogram"},((e,t)=>I(this,void 0,void 0,(function*(){yield n.compilerManager.compileSingleCode({type:e,filePath:t,graphId:"miniprogram"}),o&&o()}))))}))}};const Q=Date.now(),Z="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=${Q}`;function ee(e,t,n){const i=h.default.readFileSync(e).toString();h.default.outputFileSync(t,function(e,t,n){return x.default.compile(e,{noEscape:!0})(t,n)}(i,n))}x.default.registerHelper("toJSON",(function(e){return new x.default.SafeString(JSON.stringify(e))}));const te={context:{deviceOrientation:"portrait"},hooks:{onMergedMainPackge:new c.SyncHook(["IOnMergedMainPackge"]),onSrartBefore:new c.SyncHook(["IOnSrartBefore"])}};class ne{apply(e){e.hooks.onMergedMainPackge.tap("InjectWebviewUrlParamsPlugin",(t=>{const{compileType:n,mainPath:i}=t,o=n===D.miniGame;if(o){const t=h.default.readJsonSync(y.default.join(i,"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,hideloading:1}}))}}function ie(){const e=te.context.webviewUrlParams;return e?(t=e,Object.keys(t).reduce(((e,n)=>e+`&${n}=${encodeURIComponent(t[n])}`),"")):"";var t}const oe={test:"//test-extsdk.msstatic.com",prod:"//extsdk-msstatic.cdn.huya.com"};function ae(e,t){const i=y.default.join(e,"package"),o=function(e){const t=y.default.join(e,"packageConfig.json");return h.default.readJSONSync(t)}(i),a=o.findIndex((e=>{return(t=e).name===n.pkgFileType.MainPkg&&"."===t.root;var t}));if(-1===a)throw new Error("无法找到主包构建信息");const r=o[a];o.splice(a,1);const u=o;return u.length>0&&function(e,t,n,i){const o=y.default.join(e,t.name);n.forEach((t=>{const n=y.default.join(e,t.name),a=y.default.join(n,t.root),r=y.default.join(o,t.root);i&&i(n,o,t),h.default.moveSync(a,r,{overwrite:!0}),h.default.removeSync(y.default.join(e,t.name))}))}(i,r,u,t),{mainPakConf:r,packagePath:i}}function re(e,t){const n=require.resolve(t);let i=y.default.join(n,"../");"dist"===y.default.basename(i)?h.default.copySync(i,e):(i=y.default.resolve(i,"../"),i=y.default.join(i,"dist"),h.default.existsSync(i)?h.default.copySync(i,e):z.log(`Builder can't resolve ${t} entry from ${n}`))}function ue(e){const{builderConfig:t,mainPakConf:n,extUuid:i}=e;return t.supportExtTypes.map((e=>{const o=`index_${e}.html`;return{extType:e,entryPath:"package/"+n.name+"/"+o,sdkUrl:(a={extType:e,extUuid:i,hostId:t.hostId,isTestEnv:t.isTestEnv},`${a.isTestEnv?oe.test:oe.prod}/sdk/${a.extType}/${a.hostId}/${a.extUuid||0}/sdk.js`),entryFilename:o};var a}))}function se(e){!function(e){const{releasePath:t,mainPath:n,entrys:i,debug:o,dev:a,extInfo:r,builderConfig:u}=e,s=y.default.join(F,"template"),c=M===m.Integration?y.default.relative(n,t):"",l=[{input:y.default.join(s,"game-frame.hbs"),output:y.default.join(n,"game-frame.html"),data:{sourcePathPrefix:c}}];a&&l.push({input:y.default.join(s,"remote-debugger.hbs"),output:y.default.join(n,"remote-debugger.html"),data:{extInfo:r,paramsStr:ie()}});const d=i.map((e=>({input:y.default.join(s,"minigame-page-manager.hbs"),output:y.default.join(n,e.entryFilename),data:{sourcePathPrefix:c,hyextSDKUrl:e.sdkUrl,debug:o,sentryScript:a?void 0:Z,buildEnv:U,extInfo:Object.assign(Object.assign({},r),{envVersion:a?"develop":"release",extType:e.extType}),deviceOrientation:te.context.deviceOrientation,builderConfig:u}})));d.concat(l).forEach((e=>{ee(e.input,e.output,e.data)}))}(e),function(e){const t=u.sync("**/**.wasm",{cwd:e,ignore:ce,nodir:!0,absolute:!1});t.length&&console.log("transform wasm to base64 files: \n",t),t.forEach((t=>{const n=y.default.join(e,t),i=h.default.readFileSync(n).toString("base64");h.default.outputFileSync(n+".txt",i)}))}(e.mainPath)}const ce=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];function le(e,t,n){const i=n.name+".js",o=n.name+".js.map",a=y.default.join(e,i),r=y.default.join(e,o);h.default.existsSync(a)&&h.default.outputFileSync(y.default.join(t,i),h.default.readFileSync(a)),h.default.existsSync(r)&&h.default.outputFileSync(y.default.join(t,o),h.default.readFileSync(r))}function de(e){!function(e){const{packagePath:t,releasePath:n,mainPath:i,entrys:o,debug:a,dev:r,extInfo:u,builderConfig:s}=e,c=function(e){const t=y.default.join(e,"packageExtConfig.json");return h.default.readJSONSync(t)}(t),l=M===m.Integration?y.default.relative(i,n):"",d=JSON.stringify(c),p=[{input:y.default.join(N,"service.hbs"),output:y.default.join(i,"service.html"),data:{sourcePathPrefix:l}}];r&&p.push({input:y.default.join(N,"remote-debugger.hbs"),output:y.default.join(i,"remote-debugger.html"),data:{extInfo:u,paramsStr:ie()}});o.map((e=>({input:y.default.join(N,"miniapp-page-manager.hbs"),output:y.default.join(i,e.entryFilename),data:{sourcePathPrefix:l,packageExtConfig:d,hyextSDKUrl:e.sdkUrl,debug:a,buildEnv:U,sentryScript:Z,extInfo:Object.assign(Object.assign({},u),{envVersion:r?"develop":"release",version:"",extType:e.extType}),builderConfig:s}}))).concat(p).forEach((e=>{ee(e.input,e.output,e.data)}))}(e)}function pe(e,t,n){const i={packagePath:"",mainPath:"",releasePath:t,entrys:[],extInfo:n.extInfo,debug:n.debug,dev:n.dev,builderConfig:n.builderConfig},o=o=>{let a;return z.log("正在合并分包..."),o||function(e){const t=y.default.join(F,"framework");if(M===m.Integration){h.default.copySync(t,y.default.join(e,"framework"));const n=y.default.join(e,"sdk");h.default.mkdirSync(n),re(n,"@revues/web-sdk-core"),re(n,"@revues/web-frame"),re(n,"@revues/hyext-adapter")}}(t),"game"==e.compileType?(a=function(e,t){const n=t.builderConfig,{mainPakConf:i,packagePath:o}=ae(e),a=y.default.join(o,i.name),r=ue({builderConfig:n,mainPakConf:i,extUuid:t.extInfo.extUuid});return te.hooks.onMergedMainPackge.call({mainConf:i,mainPath:a,compileType:D.miniGame}),{packagePath:o,mainPath:a,entrys:r,mainPublicPath:"package/"+i.name}}(t,n),!o&&se(Object.assign(Object.assign({},i),a))):(a=function(e,t){const n=t.builderConfig,{mainPakConf:i,packagePath:o}=ae(e,le),a=y.default.join(o,i.name),r=ue({builderConfig:n,mainPakConf:i,extUuid:t.extInfo.extUuid});return te.hooks.onMergedMainPackge.call({mainConf:i,mainPath:a,compileType:D.miniProgram}),{entrys:r,mainPublicPath:"package/"+i.name,mainPath:a,packagePath:o}}(t,n),!o&&de(Object.assign(Object.assign({},i),a))),z.success("合并分包完成"),a};return Object.assign(Object.assign({},o(!1)),{retry:o})}class fe{apply(e){e.hooks.onSrartBefore.tap("RemoveUnlessDIrPlugin",(e=>{const{inputPath:t}=e,n=y.default.join(t,"release"),i=y.default.join(t,"dist");ge(n),ge(i)}))}}function ge(e){h.default.existsSync(e)&&h.default.removeSync(e)}var me={cert:h.default.readFileSync(y.default.join(F,"./certs/cert.pem")),key:h.default.readFileSync(y.default.join(F,"./certs/key.pem")),passphrase:""};function he(e){return I(this,void 0,void 0,(function*(){try{const t=yield k.default.get(e,{responseType:"arraybuffer"}),n=Buffer.from(t.data),i=function(e){var t;const n=e.split("?")[0],i=n.split("/"),[o,a]=null===(t=i[i.length-1])||void 0===t?void 0:t.split(".");if(null==a||""==a)throw new Error(`url:${e}格式错误,无法获取文件信息`);return{filename:o,ext:a}}(e);return`data:image/${i.ext};base64,${n.toString("base64")}`}catch(t){throw new Error(`urlToBase64 failed, url is "${e}", error msg is ${t.message}`)}}))}function ye(e,t){return I(this,void 0,void 0,(function*(){const{baseURI:n,entrys:i,outputPath:o}=t,a=y.default.join(o,"build-result"),r={},u=ie(),s=i.map((e=>{const t={type:"HTML",content:{pages:[{path:ve(e,u)}],baseURI:n}};return r[e.extType]=t,{type:e.extType,buildResult:{[e.extType]:t}}}));if("development"===e){const e=s.map((e=>h.default.outputFile(y.default.join(a,e.type+".json"),JSON.stringify(e.buildResult,null,2))));yield Promise.all(e)}return r}))}function ve(e,t){const n=e.extType;let i=e.entryPath;return n.endsWith("_h5")&&(i+="?__module_busi__=kiwi-ExtSDK"+t),i}const je=e=>{var t;const n=(()=>{const e=v.default.networkInterfaces(),t=w.default.flatten(w.default.values(e));return w.default.filter((e=>/(ipv)?4/gi.test(e.family)&&!/^127\./.test(e.address)),t)})();return n&&n.length>1&&(z.log(`检测到本机有多个 ip 地址:\n- ${n.map((e=>e.address)).join("\n- ")}`),z.log("请在 project.config.json 的 host 中指定正确的 ip"),process.exit(1)),n&&n.length<=0&&(z.log("未能找到本机 ip 地址, 本地开发 app 侧将无法加载小程序"),process.exit(1)),null===(t=n[0])||void 0===t?void 0:t.address},Pe=new Set(["app_inner_h5","web_video_com","app_panel_h5","zs_anchor_panel_h5","pc_anchor_panel","pc_panel"]);function xe(e,t){const n=Object.assign({},t);return function(e){let t=[];e&&0!==e.length?e.forEach((e=>{Pe.has(e)||t.push(e)})):z.fatal("请在project.config.json相应地方填写supportExtTypes."),t.length>0&&z.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=je()||""),null==e.port&&(e.port=18080)}(n),n}function be(e){return`${e.https?"https":"http"}://${e.host}:${e.port}/`}function Se(e){const t=e.appId||e.appid;return null==t||""===t?z.fatal("请填写正确的appid"):t.length>10&&z.fatal("appid错误,请登录 https://ext.huya.com/ 在您的小程序概要中查看小程序ID"),t}function ke(e){return"game"===e.compileType?"miniGame":"miniProgram"}const we=new class{constructor(){var e;e=te,(new ne).apply(e),(new fe).apply(e)}build(e){return I(this,void 0,void 0,(function*(){const{inputPath:t,outputPath:n,publicPath:i,projectConfig:o,config:a,extUuid:r,extName:u,extVersion:s,extVersionId:c,extLogo:l}=e,d=xe("production",a);h.default.existsSync(n)&&h.default.removeSync(n),yield h.default.copy(t,n,{overwrite:!0});const{entrys:p}=pe(o,n,{builderConfig:d,extInfo:{projectType:ke(o),extUuid:r,extName:u,extVersion:s,extVersionId:c,extLogo:yield he(l)}});return yield ye("production",{entrys:p,baseURI:i,outputPath:n})}))}start(e){var t;return I(this,void 0,void 0,(function*(){const{debug:n,inputPath:i,projectConfig:o,outputPath:a,config:r}=e;te.hooks.onSrartBefore.call({inputPath:i});const u=xe("development",r),s=Se(o),c=(l=o).projectname||l.projectName||"小程序";var l;const d={extUuid:s,extName:c,projectType:ke(o),extVersion:void 0,extVersionId:void 0,extLogo:void 0};let p=e=>{};const f=(g=`${c}-${s}`,y.default.join(_,g));var g;yield function(e){return I(this,void 0,void 0,(function*(){const{projectConfig:t}=e,n=A[t.compileType];if(null==n)throw new Error("Unsupported compileType: "+String(t.compileType));yield n(e)}))}({projectConfig:o,projectPath:i,outputPath:f,cb:()=>{p(!0)}});const{entrys:m,mainPublicPath:h,retry:v}=pe(o,f,{builderConfig:u,extInfo:d,debug:n,dev:!0});return p=v,z.log("启动 live server 服务..."),z.success("本地访问地址:",be(u)+(null===(t=m[0])||void 0===t?void 0:t.entryPath)),z.success("扫码预览地址:",be(u)+h+"/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:me};b.default.start(t)}(Object.assign(Object.assign({},u),{root:f,ignore:"node_modules"})),yield ye("development",{entrys:m,baseURI:be(u),outputPath:a})}))}release(e){return I(this,void 0,void 0,(function*(){const{contextPath:t,releasePath:i,projectConfig:o,zip:a=!0}=e;h.default.existsSync(i)&&h.default.removeSync(i),z.log("开始打包");const r=o.projectName||o.projectname||"project",u=y.default.join(i,r),s=o.compileType;if("game"==s?yield Y("prod",t,u):"plugin"==s?yield function(e,t){return I(this,void 0,void 0,(function*(){R(),yield n.compilerManager.init({projectPath:e,outputPath:t,cachePath:T,compileSettings:{minify:!0,autoPrefixWXSS:!0,minifyWXSS:!0}}),yield n.compilerManager.compileDevPlugin({outputPath:t,remove:!0})}))}(t,u):yield X("prod",t,u),"plugin"===s&&(yield function(e,t){return I(this,void 0,void 0,(function*(){const n=Se(t),i=y.default.join(e,C,n);h.default.existsSync(i)&&(yield h.default.copy(i,e),h.default.removeSync(y.default.join(e,C)))}))}(u,o)),a){let e=u+".zip";yield(c=u,new Promise(((e,t)=>{const n=h.default.createWriteStream(`${c}.zip`),i=S.default("zip",{zlib:{level:9}});n.on("close",(()=>{const t=i.pointer();e({name:`${y.default.basename(c)}.zip`,size:t})})),i.on("warning",(e=>{if("ENOENT"!==e.code)throw e})),i.on("error",(e=>{throw t(e),e})),i.pipe(n),i.directory(`${c}`,!1),i.finalize()}))),"plugin"===s&&(e=function(e,t,n){const i=y.default.join(t,`${Se(n)}-${n.version||"1.0.0"}.zip`);return h.default.existsSync(e)?(h.default.renameSync(e,i),i):e}(e,i,o)),z.success("打包成功,zip包地址:"+e)}var c}))}config(){}providedProjectConfig(){}clearCache(){try{h.default.existsSync(T)&&h.default.removeSync(T),z.success("项目缓存清除成功~"),h.default.existsSync($)&&h.default.removeSync($),z.success("插件缓存清除成功~")}catch(e){z.success("缓存清除失败 \n"+e.message)}}};module.exports=we,exports.default=we;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hyext/builder-revues",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.12",
|
4
4
|
"description": "> TODO: description",
|
5
5
|
"author": "loler",
|
6
6
|
"homepage": "",
|
@@ -24,14 +24,15 @@
|
|
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.12",
|
28
|
+
"@revues/code-compiler": "1.0.12",
|
29
|
+
"@revues/hyext-adapter": "1.0.12",
|
30
|
+
"@revues/web-frame": "1.0.12",
|
31
|
+
"@revues/web-sdk-core": "1.0.12",
|
32
32
|
"archiver": "^7.0.1",
|
33
33
|
"axios": "^1.7.1",
|
34
34
|
"chalk": "^2.4.2",
|
35
|
+
"download": "^8.0.0",
|
35
36
|
"fs-extra": "8.1.0",
|
36
37
|
"glob": "^10.3.10",
|
37
38
|
"handlebars": "^4.7.8",
|
@@ -46,5 +47,5 @@
|
|
46
47
|
"@types/ramda": "^0.29.11",
|
47
48
|
"terser": "^5.31.0"
|
48
49
|
},
|
49
|
-
"gitHead": "
|
50
|
+
"gitHead": "d0c2814bba6c389af6e99f8f380ed7ebf4bd2e11"
|
50
51
|
}
|