vivo-hap-toolkit
Version:
A command line toolkit for developing Quick Apps.
3 lines (2 loc) • 1.79 kB
JavaScript
;const webpack=require("webpack"),{setCustomConfig:setCustomConfig,colorconsole:colorconsole}=require("@vivo-hap-toolkit/shared-utils"),{compileOptionsMeta:compileOptionsMeta}=require("@vivo-hap-toolkit/shared-utils/compilation-config"),globalConfig=require("@vivo-hap-toolkit/shared-utils/config"),genWebpackConf=require("../../gen-webpack-conf"),{summaryErrors:summaryErrors}=require("./utils");let watching=null;function showVersion(){const o=require("../../package.json").version,e=require("@babel/core/package.json").version,n=require("webpack/package.json").version;colorconsole.info(`vivo-hap-toolkit: ${o}; babel: ${e}; webpack: ${n};`)}showVersion(),module.exports.compile=function(o,e,n,r={}){const i=r.onerror;return new Promise((s,t)=>{function c(o,e){if(o&&(i&&i(o),colorconsole.error(o)),e){if(e.hasErrors()||e.hasWarnings()){const o=summaryErrors(e);i&&i(o),colorconsole.error(o)}e.hasErrors()&&(process.exitCode=1)}}colorconsole.attach(r.log),setCustomConfig(r.cwd),process.env.NODE_PLATFORM=o,process.env.NODE_PHASE=e;const a="prod"===e?"production":"development";r.disableSignOnline?r.signOnline=!1:globalConfig.signOnLine&&globalConfig.signOnLine.match(/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/)&&(r.signOnline=!0,r.signMode=compileOptionsMeta.signModeEnum.NULL);try{const o=genWebpackConf(r,a);if(n){const e=webpack(o);watching=e.watch({aggregateTimeout:300},(o,e)=>{c(o,e),s({compileError:o,stats:e,watching:watching})})}else webpack(o,(o,e)=>{c(o,e),s({compileError:o,stats:e})})}catch(o){t(o)}})},module.exports.stopWatch=function(){return new Promise(o=>{watching?watching.close(()=>{watching=null,o({stopWatchError:null})}):o({stopWatchError:"no watching"})})};
//# sourceMappingURL=compile.js.map