@alipay-inc/mpaas-ide-openapi-common
Advanced tools
Comparing version 1.0.0-beta.22 to 1.0.2
@@ -1,1 +0,1 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.remoteFileToLocal=exports.pollBuildStatusPrivate=exports.pollBuildStatusAlipay=exports.getFile=exports.getCloudBuildData=exports.cloudBuildPrivate=exports.cloudBuildAlipay=exports.cloudBuild=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_superagent=_interopRequireDefault(require("superagent")),_path=_interopRequireDefault(require("path")),_fsExtra=_interopRequireDefault(require("fs-extra")),_=require("./"),_archiver=_interopRequireDefault(require("archiver")),_excluded=["file"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){(0,_defineProperty2["default"])(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}var POLL_DELAY_TIME=4e3,IGNORE_DIR=[".idea",".vscode",".git",".DS_Store",".umi",".umi-production",".miniu",".node",".tea"],getCloudBuildData=function(a){var b=a.build_url,c=void 0===b?null:b;return c?{type:"private",CLOUD_BUILD_EXEC_URL:"".concat(c,"/miniApp/buildIdeMiniApp"),CLOUD_BUILD_POLL_URL:"".concat(c,"/miniApp/queryMiniAppBuildResult")}:{type:"alipay",CLOUD_BUILD_EXEC_URL:"https://hpmweb.alipay.com/tinyApp/cloudBuild/execute",CLOUD_BUILD_POLL_URL:"https://hpmweb.alipay.com/tinyApp/cloudBuild/result"}};exports.getCloudBuildData=getCloudBuildData;var cloudBuild=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,c=b.config,d=b.file,e=(0,_objectWithoutProperties2["default"])(b,_excluded),f=getCloudBuildData(c),a.next=6,getFile({file:d,type:f.type});case 6:if(d=a.sent,g=_objectSpread(_objectSpread({},e),{},{file:d}),"private"!==f.type){a.next=13;break}return(0,_.logger)("cloudBuild: private"),a.next=12,cloudBuildPrivate(g);case 12:return a.abrupt("return",a.sent);case 13:return(0,_.logger)("cloudBuild: alipay"),a.next=16,cloudBuildAlipay(g);case 16:return a.abrupt("return",a.sent);case 19:throw a.prev=19,a.t0=a["catch"](0),new Error(a.t0.message);case 22:case"end":return a.stop();}},a,null,[[0,19]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuild=cloudBuild;var compressFile=function(a){var b=a.resourceFile,c=a.targetFile,d=a.type;return new Promise(function(a,e){var f=_fsExtra["default"].createWriteStream(c),g=(0,_archiver["default"])("zip",{zlib:{level:9}});g.pipe(f),f.on("close",function(){a(c)}),g.on("error",function(a){e(a)}),"directory"===d?g.directory("".concat(b),""):g.file("".concat(b),{name:_path["default"].basename(b)}),g.finalize()})},getFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.file,d=b.type,a.prev=1,_fsExtra["default"].existsSync(c)){a.next=4;break}throw new Error("\u6587\u4EF6\u4E0D\u5B58\u5728\uFF01");case 4:if(!_fsExtra["default"].lstatSync(c).isFile()){a.next=8;break}if(".amr"===_path["default"].extname(c)){a.next=7;break}throw new Error("\u6587\u4EF6\u683C\u5F0F\u9519\u8BEF\uFF01");case 7:return a.abrupt("return",c);case 8:if(!_fsExtra["default"].lstatSync(c).isDirectory()){a.next=22;break}return e=(0,_.getTmpDir)(),f=(0,_.getTmpDir)(),_fsExtra["default"].copySync(c,e),a.next=14,compressFile({resourceFile:e,targetFile:_path["default"].join(f,"dist.tar"),type:"directory"});case 14:if(g=a.sent,"alipay"!==d){a.next=17;break}return a.abrupt("return",g);case 17:return h=(0,_.getTmpDir)(),a.next=20,compressFile({resourceFile:_path["default"].join(f,"dist.tar"),targetFile:_path["default"].join(h,"dist.amr")});case 20:return i=a.sent,a.abrupt("return",i);case 22:return a.abrupt("return",c);case 25:throw a.prev=25,a.t0=a["catch"](1),new Error(a.t0.message);case 28:case"end":return a.stop();}},a,null,[[1,25]])}));return function(){return a.apply(this,arguments)}}();exports.getFile=getFile;var cloudBuildAlipay=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,c=b.file,d=b.config,e=void 0===d?{}:d,f=b.adaptorId,g=void 0===f?"mPaaS":f,h=b.h5Id,i=e.appId,j=getCloudBuildData(e),k=j.CLOUD_BUILD_EXEC_URL,l=j.CLOUD_BUILD_POLL_URL,m={params:"[\"--scriptName\",\"buildpack\",\"--ADAPTOR_NAME\",\"adaptor-mpaas-".concat(g,"\",\"--limitation\",\"--preview\"]"),env:"{}",operationType:"build",extraInfo:JSON.stringify({appId:i,doneCommand:"pack",client:"IDE",scene:"IDE",fileFormat:"tar"})},(0,_.logger)("uploadBundle start",m),n={value:_fsExtra["default"].readFileSync(c),options:{filename:"".concat(i,".tar"),contentType:"application/zip"}},a.next=9,_superagent["default"].post(k).field(m).attach("file",n.value,n.options);case 9:if(o=a.sent,p=JSON.parse(o.text),p.success){a.next=13;break}throw new Error(p.msg);case 13:return q=p.data.taskId,a.next=16,pollBuildStatusAlipay({CLOUD_BUILD_POLL_URL:l,taskId:q});case 16:return r=a.sent,s=r.data,s=void 0===s?{}:s,t=s.zipFile,a.next=22,remoteFileToLocal({originFile:t,h5Id:h});case 22:return a.abrupt("return",a.sent);case 25:throw a.prev=25,a.t0=a["catch"](0),new Error(a.t0.message);case 28:case"end":return a.stop();}},a,null,[[0,25]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuildAlipay=cloudBuildAlipay;var pollBuildStatusAlipay=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.CLOUD_BUILD_POLL_URL,d=b.taskId,a.prev=1,a.next=4,_superagent["default"].get(c).query({taskId:d});case 4:if(e=a.sent,f=JSON.parse(e.text),f.success){a.next=8;break}throw new Error(f.msg);case 8:if("COMPLETE"!==f.status){a.next=10;break}return a.abrupt("return",f);case 10:;return a.next=13,(0,_.delay)(POLL_DELAY_TIME);case 13:return a.next=15,pollBuildStatusAlipay({CLOUD_BUILD_POLL_URL:c,taskId:d});case 15:return a.abrupt("return",a.sent);case 18:throw a.prev=18,a.t0=a["catch"](1),new Error(a.t0.message);case 21:case"end":return a.stop();}},a,null,[[1,18]])}));return function(){return a.apply(this,arguments)}}();exports.pollBuildStatusAlipay=pollBuildStatusAlipay;var cloudBuildPrivate=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,c=b.file,d=b.config,e=void 0===d?{}:d,f=b.h5Id,g=e.appId,h=e.workspaceId,i=e.tenantId,j=getCloudBuildData(e),k=j.CLOUD_BUILD_EXEC_URL,l=j.CLOUD_BUILD_POLL_URL,m={value:_fsExtra["default"].readFileSync(c),options:{filename:"".concat(g,".tar"),contentType:"application/zip"}},a.next=7,_superagent["default"].post(k).field({appId:g,workspaceId:h,tenantId:i}).attach("file",m.value,m.options);case 7:return n=a.sent,o=JSON.parse(n.text),a.next=11,pollBuildStatusPrivate({CLOUD_BUILD_POLL_URL:l,buildId:o.data});case 11:return p=a.sent,q=p.data.downloadUrl,a.next=15,remoteFileToLocal({originFile:q,h5Id:f});case 15:return a.abrupt("return",a.sent);case 18:throw a.prev=18,a.t0=a["catch"](0),new Error(a.t0.message);case 21:case"end":return a.stop();}},a,null,[[0,18]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuildPrivate=cloudBuildPrivate;var pollBuildStatusPrivate=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.CLOUD_BUILD_POLL_URL,d=b.buildId,a.prev=1,a.next=4,_superagent["default"].get(c).query({buildId:d});case 4:if(g=a.sent,h=JSON.parse(g.text),h.success){a.next=8;break}throw new Error(h.message);case 8:if("FAILURE"!==(null===h||void 0===h||null===(e=h.data)||void 0===e?void 0:e.result)){a.next=10;break}throw new Error(null===h||void 0===h||null===(i=h.data)||void 0===i?void 0:i.logUrl);case 10:;if("SUCCESS"!==(null===h||void 0===h||null===(f=h.data)||void 0===f?void 0:f.result)){a.next=13;break}return a.abrupt("return",h);case 13:;return a.next=16,(0,_.delay)(POLL_DELAY_TIME);case 16:return a.next=18,pollBuildStatusPrivate({CLOUD_BUILD_POLL_URL:c,buildId:d});case 18:return a.abrupt("return",a.sent);case 21:throw a.prev=21,a.t0=a["catch"](1),new Error(a.t0.message);case 24:case"end":return a.stop();}},a,null,[[1,21]])}));return function(){return a.apply(this,arguments)}}();exports.pollBuildStatusPrivate=pollBuildStatusPrivate;var remoteFileToLocal=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.originFile,d=b.h5Id,a.prev=1,a.next=4,(0,_.downloadFile)({url:c});case 4:return e=a.sent,f=e.data,a.next=8,(0,_.getZipFromTar)({tarFilePath:f,h5Id:d});case 8:return g=a.sent,h=g.data,a.abrupt("return",{data:{file:h,originFile:c},success:!0});case 13:throw a.prev=13,a.t0=a["catch"](1),new Error(a.t0.message);case 16:case"end":return a.stop();}},a,null,[[1,13]])}));return function(){return a.apply(this,arguments)}}();exports.remoteFileToLocal=remoteFileToLocal; | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.remoteFileToLocal=exports.pollBuildStatusPrivate=exports.pollBuildStatusAlipay=exports.getFile=exports.getCloudBuildData=exports.cloudBuildPrivate=exports.cloudBuildAlipay=exports.cloudBuild=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_superagent=_interopRequireDefault(require("superagent")),_path=_interopRequireDefault(require("path")),_fsExtra=_interopRequireDefault(require("fs-extra")),_=require("./"),_archiver=_interopRequireDefault(require("archiver")),_chalk=_interopRequireDefault(require("chalk")),_excluded=["file"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){(0,_defineProperty2["default"])(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}var POLL_DELAY_TIME=4e3,IGNORE_DIR=[".idea",".vscode",".git",".DS_Store",".umi",".umi-production",".miniu",".node",".tea"],getCloudBuildData=function(a){var b=a.build_url,c=void 0===b?null:b;return c?{type:"private",CLOUD_BUILD_EXEC_URL:"".concat(c,"/miniApp/buildIdeMiniApp"),CLOUD_BUILD_POLL_URL:"".concat(c,"/miniApp/queryMiniAppBuildResult")}:{type:"alipay",CLOUD_BUILD_EXEC_URL:"https://hpmweb.alipay.com/tinyApp/cloudBuild/execute",CLOUD_BUILD_POLL_URL:"https://hpmweb.alipay.com/tinyApp/cloudBuild/result"}};exports.getCloudBuildData=getCloudBuildData;var cloudBuild=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return _.logger.info("cloudBuild req",b),a.prev=1,c=b.config,d=b.file,e=(0,_objectWithoutProperties2["default"])(b,_excluded),f=getCloudBuildData(c),a.next=7,getFile({file:d,type:f.type});case 7:if(d=a.sent,g=_objectSpread(_objectSpread({},e),{},{file:d}),"private"!==f.type){a.next=14;break}return _.logger.info("cloudBuild: private"),a.next=13,cloudBuildPrivate(g);case 13:return a.abrupt("return",a.sent);case 14:return _.logger.info("cloudBuild: alipay"),a.next=17,cloudBuildAlipay(g);case 17:return h=a.sent,_.logger.info("cloudBuild res",h),console.log(_chalk["default"].green("cloudBuild done")),a.abrupt("return",h);case 23:return a.prev=23,a.t0=a["catch"](1),_.logger.error("cloudBuild error",a.t0.message),a.next=28,(0,_.delay)(0);case 28:throw new Error(a.t0.message);case 29:case"end":return a.stop();}},a,null,[[1,23]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuild=cloudBuild;var compressFile=function(a){var b=a.resourceFile,c=a.targetFile,d=a.type;return new Promise(function(a,e){var f=_fsExtra["default"].createWriteStream(c),g=(0,_archiver["default"])("zip",{zlib:{level:9}});g.pipe(f),f.on("close",function(){a(c)}),g.on("error",function(a){e(a)}),"directory"===d?g.directory("".concat(b),""):g.file("".concat(b),{name:_path["default"].basename(b)}),g.finalize()})},getFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.file,d=b.type,a.prev=1,_fsExtra["default"].existsSync(c)){a.next=4;break}throw new Error("\u6587\u4EF6\u4E0D\u5B58\u5728\uFF01");case 4:if(!_fsExtra["default"].lstatSync(c).isFile()){a.next=8;break}if(".amr"===_path["default"].extname(c)){a.next=7;break}throw new Error("\u6587\u4EF6\u683C\u5F0F\u9519\u8BEF\uFF01");case 7:return a.abrupt("return",c);case 8:if(!_fsExtra["default"].lstatSync(c).isDirectory()){a.next=22;break}return e=(0,_.getTmpDir)(),f=(0,_.getTmpDir)(),_fsExtra["default"].copySync(c,e),a.next=14,compressFile({resourceFile:e,targetFile:_path["default"].join(f,"dist.tar"),type:"directory"});case 14:if(g=a.sent,"alipay"!==d){a.next=17;break}return a.abrupt("return",g);case 17:return h=(0,_.getTmpDir)(),a.next=20,compressFile({resourceFile:_path["default"].join(f,"dist.tar"),targetFile:_path["default"].join(h,"dist.amr")});case 20:return i=a.sent,a.abrupt("return",i);case 22:return a.abrupt("return",c);case 25:throw a.prev=25,a.t0=a["catch"](1),new Error(a.t0.message);case 28:case"end":return a.stop();}},a,null,[[1,25]])}));return function(){return a.apply(this,arguments)}}();exports.getFile=getFile;var cloudBuildAlipay=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,c=b.file,d=b.config,e=void 0===d?{}:d,f=b.adaptorId,g=void 0===f?"mPaaS":f,h=b.h5Id,i=e.appId,j=getCloudBuildData(e),k=j.CLOUD_BUILD_EXEC_URL,l=j.CLOUD_BUILD_POLL_URL,m={params:"[\"--scriptName\",\"buildpack\",\"--ADAPTOR_NAME\",\"adaptor-mpaas-".concat(g,"\",\"--limitation\",\"--debug\"]"),env:"{}",operationType:"build",extraInfo:JSON.stringify({appId:i,doneCommand:"pack",client:"IDE",scene:"IDE",fileFormat:"tar"})},n={value:_fsExtra["default"].readFileSync(c),options:{filename:"".concat(i,".tar"),contentType:"application/zip"}},a.next=8,_superagent["default"].post(k).field(m).attach("file",n.value,n.options);case 8:if(o=a.sent,p=JSON.parse(o.text),p.success){a.next=12;break}throw new Error(p.msg);case 12:return q=p.data.taskId,a.next=15,pollBuildStatusAlipay({CLOUD_BUILD_POLL_URL:l,taskId:q});case 15:return r=a.sent,s=r.data,s=void 0===s?{}:s,t=s.zipFile,a.next=21,remoteFileToLocal({originFile:t,h5Id:h});case 21:return a.abrupt("return",a.sent);case 24:throw a.prev=24,a.t0=a["catch"](0),new Error(a.t0.message);case 27:case"end":return a.stop();}},a,null,[[0,24]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuildAlipay=cloudBuildAlipay;var pollBuildStatusAlipay=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.CLOUD_BUILD_POLL_URL,d=b.taskId,a.prev=1,a.next=4,_superagent["default"].get(c).query({taskId:d});case 4:if(e=a.sent,f=JSON.parse(e.text),f.success){a.next=8;break}throw new Error(f.msg);case 8:if("COMPLETE"!==f.status){a.next=10;break}return a.abrupt("return",f);case 10:;return a.next=13,(0,_.delay)(POLL_DELAY_TIME);case 13:return a.next=15,pollBuildStatusAlipay({CLOUD_BUILD_POLL_URL:c,taskId:d});case 15:return a.abrupt("return",a.sent);case 18:throw a.prev=18,a.t0=a["catch"](1),new Error(a.t0.message);case 21:case"end":return a.stop();}},a,null,[[1,18]])}));return function(){return a.apply(this,arguments)}}();exports.pollBuildStatusAlipay=pollBuildStatusAlipay;var cloudBuildPrivate=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,c=b.file,d=b.config,e=void 0===d?{}:d,f=b.h5Id,g=e.appId,h=e.workspaceId,i=e.tenantId,j=getCloudBuildData(e),k=j.CLOUD_BUILD_EXEC_URL,l=j.CLOUD_BUILD_POLL_URL,m={value:_fsExtra["default"].readFileSync(c),options:{filename:"".concat(g,".tar"),contentType:"application/zip"}},a.next=7,_superagent["default"].post(k).field({appId:g,workspaceId:h,tenantId:i}).attach("file",m.value,m.options);case 7:return n=a.sent,o=JSON.parse(n.text),a.next=11,pollBuildStatusPrivate({CLOUD_BUILD_POLL_URL:l,buildId:o.data});case 11:return p=a.sent,q=p.data.downloadUrl,a.next=15,remoteFileToLocal({originFile:q,h5Id:f});case 15:return a.abrupt("return",a.sent);case 18:throw a.prev=18,a.t0=a["catch"](0),new Error(a.t0.message);case 21:case"end":return a.stop();}},a,null,[[0,18]])}));return function(){return a.apply(this,arguments)}}();exports.cloudBuildPrivate=cloudBuildPrivate;var pollBuildStatusPrivate=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.CLOUD_BUILD_POLL_URL,d=b.buildId,a.prev=1,a.next=4,_superagent["default"].get(c).query({buildId:d});case 4:if(g=a.sent,h=JSON.parse(g.text),h.success){a.next=8;break}throw new Error(h.message);case 8:if("FAILURE"!==(null===h||void 0===h||null===(e=h.data)||void 0===e?void 0:e.result)){a.next=10;break}throw new Error(null===h||void 0===h||null===(i=h.data)||void 0===i?void 0:i.logUrl);case 10:;if("SUCCESS"!==(null===h||void 0===h||null===(f=h.data)||void 0===f?void 0:f.result)){a.next=13;break}return a.abrupt("return",h);case 13:;return a.next=16,(0,_.delay)(POLL_DELAY_TIME);case 16:return a.next=18,pollBuildStatusPrivate({CLOUD_BUILD_POLL_URL:c,buildId:d});case 18:return a.abrupt("return",a.sent);case 21:throw a.prev=21,a.t0=a["catch"](1),new Error(a.t0.message);case 24:case"end":return a.stop();}},a,null,[[1,21]])}));return function(){return a.apply(this,arguments)}}();exports.pollBuildStatusPrivate=pollBuildStatusPrivate;var remoteFileToLocal=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.originFile,d=b.h5Id,a.prev=1,a.next=4,(0,_.downloadFile)({url:c});case 4:return e=a.sent,f=e.data,a.next=8,(0,_.getZipFromTar)({tarFilePath:f,h5Id:d});case 8:return g=a.sent,h=g.data,a.abrupt("return",{data:{file:h,originFile:c},success:!0});case 13:throw a.prev=13,a.t0=a["catch"](1),new Error(a.t0.message);case 16:case"end":return a.stop();}},a,null,[[1,13]])}));return function(){return a.apply(this,arguments)}}();exports.remoteFileToLocal=remoteFileToLocal; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _exportNames={delay:!0,getConfigType:!0,login:!0,defaultTinyappConfig:!0,getDefaultTinyappConfig:!0,getTmpDirRoot:!0,getTmpDir:!0,cleanCache:!0,getVersion:!0,getUUID:!0,getZipFile:!0,getZipFromTar:!0,logger:!0,getPackageType:!0,looseJsonParse:!0,downloadFile:!0,getUploadData:!0};var _excluded=["config"];Object.defineProperty(exports,"__esModule",{value:!0});exports.looseJsonParse=exports.login=exports.logger=exports.getZipFromTar=exports.getZipFile=exports.getVersion=exports.getUploadData=exports.getUUID=exports.getTmpDirRoot=exports.getTmpDir=exports.getPackageType=exports.getDefaultTinyappConfig=exports.getConfigType=exports.downloadFile=exports.delay=exports.defaultTinyappConfig=exports.cleanCache=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")),_slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_superagent=_interopRequireDefault(require("superagent")),_tar=_interopRequireDefault(require("tar")),_archiver=_interopRequireDefault(require("archiver")),_os=require("os"),_path=_interopRequireDefault(require("path")),_uuid=_interopRequireDefault(require("uuid")),_progress=_interopRequireDefault(require("progress")),_fsExtra=require("fs-extra"),_cloudBuild=require("./cloudBuild");Object.keys(_cloudBuild).forEach(function(a){"default"===a||"__esModule"===a||Object.prototype.hasOwnProperty.call(_exportNames,a)||a in exports&&exports[a]===_cloudBuild[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _cloudBuild[a]}})});function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){(0,_defineProperty2["default"])(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}var tmpdirRoot="".concat((0,_os.tmpdir)(),"/.mpaas_ide_openapi"),delay=function(a){return new Promise(function(b){return setTimeout(b,a)})};exports.delay=delay;var getConfigType=function(a){var b="",c=a.openapi;if(!c)b="classic";else{var d=c.type;"aliyun"===d?b="aliyun":"antfin"===d&&(b="antfin")}return{data:b,success:!0}};exports.getConfigType=getConfigType;var login=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:c=b.config,d=(0,_objectWithoutProperties2["default"])(b,_excluded),a.prev=1,e=getConfigType(c),f=e.data,g={},a.t0=f,a.next="classic"===a.t0?7:13;break;case 7:return h=c.login_url,a.next=10,_superagent["default"].post(h).field(_objectSpread(_objectSpread({},d),{},{config:JSON.stringify(c)}));case 10:return i=a.sent,g=JSON.parse(i.text).data,a.abrupt("break",16);case 13:return j=c.userId,g={data:{id:j,loginName:j,nickName:j,realName:j}},a.abrupt("break",16);case 16:return a.abrupt("return",g);case 19:throw a.prev=19,a.t1=a["catch"](1),new Error(a.t1.message);case 22:case"end":return a.stop();}},a,null,[[1,19]])}));return function(){return a.apply(this,arguments)}}();exports.login=login;var defaultTinyappConfig={appCode:"",autoInstall:1,clientVersionMax:"",clientVersionMin:"0.0.0.0;0.0.0.0",downloadUrl:"",debugUrl:"",extendInfo:"",extraData:"{\"enableKeepAlive\":\"0\",\"enableOptionMenu\":\"1\",\"enableTabBar\":\"0\",\"iconUrl\":\"\",\"resourceType\":\"4\"}",fallbackBaseUrl:"",fileSize:"",gmtCreate:"",gmtModified:"",h5Version:"1.0.0.0",installType:1,lazyLoad:0,mainUrl:"/index.html#pages/index/index",md5:"",memo:"",modifier:"success",platform:"all",publishPeriod:5,releaseVersion:"",resourceType:"4",status:1};exports.defaultTinyappConfig=defaultTinyappConfig;var getDefaultTinyappConfig=function(a){return{data:_objectSpread(_objectSpread({},defaultTinyappConfig),a),success:!0}};exports.getDefaultTinyappConfig=getDefaultTinyappConfig;var getTmpDirRoot=function(){var a=(0,_fsExtra.existsSync)(tmpdirRoot);return a||(0,_fsExtra.mkdirSync)(tmpdirRoot),tmpdirRoot};exports.getTmpDirRoot=getTmpDirRoot;var getTmpDir=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"appid",b=getTmpDirRoot(),c="".concat(b,"/").concat(a,"_").concat(new Date().valueOf(),"_").concat(_uuid["default"].v4()),d=(0,_fsExtra.existsSync)(c);return d||(0,_fsExtra.mkdirSync)(c),c};exports.getTmpDir=getTmpDir;var cleanCache=function(){try{var a=getTmpDirRoot();return(0,_fsExtra.emptydirSync)(a),{data:"OK",success:!0}}catch(a){throw new Error(a.message)}};exports.cleanCache=cleanCache;var getVersion=function(a){try{var b=a.split("."),c=(0,_slicedToArray2["default"])(b,4),d=c[0],e=c[1],f=c[2],g=c[3],h=void 0===g?0:g,i=[d,e,f,h].join("."),j=[d,e,1*f+1,0].join("."),k=[d,e,f,1*h+1].join(".");return{data:{current:i,nextProd:j,nextDev:k},success:!0}}catch(a){throw new Error(a)}};exports.getVersion=getVersion;var getUUID=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,_superagent["default"].get(b);case 3:return c=a.sent,d=c.text,a.abrupt("return",{data:d,success:!0});case 8:throw a.prev=8,a.t0=a["catch"](0),new Error(a.t0);case 11:case"end":return a.stop();}},a,null,[[0,8]])}));return function(){return a.apply(this,arguments)}}();exports.getUUID=getUUID;var getZipFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.pathname,d=b.version,e=b.h5Id,a.abrupt("return",new Promise(function(a,b){var f=getTmpDir();(0,_fsExtra.ensureDirSync)(f);try{var g="".concat(f,"/").concat(e,".zip");d&&(g="".concat(f,"/").concat(e,"_").concat(d.replace(/\./ig,"_"),".zip"));var h=(0,_fsExtra.createWriteStream)(g),i=(0,_archiver["default"])("zip",{zlib:{level:9}});i.pipe(h),h.on("close",function(){a(g)}),i.on("error",function(a){b(a)}),i.directory("".concat(c),e),i.finalize()}catch(a){(0,_fsExtra.removeSync)(f),b(a)}}));case 2:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}();exports.getZipFile=getZipFile;var getZipFromTar=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(){var b,c,d,e,f,g,h=arguments;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b=0<h.length&&void 0!==h[0]?h[0]:{},c=b.tarFilePath,d=b.h5Id,e=getTmpDir(),f=_path["default"].join(e,d),(0,_fsExtra.ensureDirSync)(f),a.prev=4,a.next=7,_tar["default"].x({file:_path["default"].resolve(c),cwd:f});case 7:return a.next=9,getZipFile({pathname:f,h5Id:d});case 9:return g=a.sent,a.abrupt("return",{data:g,success:!0});case 13:throw a.prev=13,a.t0=a["catch"](4),new Error(a.t0.message);case 16:return a.prev=16,(0,_fsExtra.removeSync)(e),a.finish(16);case 19:case"end":return a.stop();}},a,null,[[4,13,16,19]])}));return function(){return a.apply(this,arguments)}}();exports.getZipFromTar=getZipFromTar;var logger=function(){for(var a,b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c,f=["%c[mpaas-ide-openapi]","color: blue;"];if(Array.isArray(c))try{f[0]="".concat(f[0]," %c").concat(c[0]),f.push("color: red;"),e=c.slice(1)}catch(a){console.log(a)}(a=console).log.apply(a,f.concat((0,_toConsumableArray2["default"])(e)))};exports.logger=logger;var getPackageType=function(a){return{data:["1","2"].includes(a)?"production":"development",success:!0}};exports.getPackageType=getPackageType;var looseJsonParse=function(a){try{return{data:Function("\"use strict\";return (".concat(a,")"))(),success:!0}}catch(b){return{data:JSON.parse(a.replace(/"/ig,"\"")),success:!0}}};exports.looseJsonParse=looseJsonParse;var downloadFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.url,d=b.target,a.prev=1,a.t0=d,a.t0){a.next=7;break}return a.next=6,getTmpDir();case 6:a.t0=a.sent;case 7:return e=a.t0,f="".concat(_uuid["default"].v4()).concat(_path["default"].extname(new URL(c).pathname)),g=_path["default"].join(e,f),logger("downloadFile","\u4E0B\u8F7D\u6587\u4EF6:".concat(c)),logger("downloadFile","\u672C\u5730\u8DEF\u5F84:".concat(g)),a.next=14,_superagent["default"].get(c);case 14:return h=a.sent,a.next=17,(0,_fsExtra.writeFileSync)(g,h.body,"binary");case 17:return logger("downloadFile","\u4E0B\u8F7D\u5B8C\u6210"),a.abrupt("return",{data:g,success:!0});case 21:throw a.prev=21,a.t1=a["catch"](1),new Error(a.t1.message);case 24:case"end":return a.stop();}},a,null,[[1,21]])}));return function(){return a.apply(this,arguments)}}();exports.downloadFile=downloadFile;var getUploadData=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.type,d=b.config,e=b.req,f=b.getVhostByApi,g=b.createWhitelistByApi,h=b.uploadFile,a.prev=1,i=d.appId,j=d.workspaceId,k=d.tenantId,l=d.userId,m=d.uuid_url,n=e.appInfo,o=e.packageType,p=e.resourceFile,q=e.iconFile,r=e.whiteListValue,s=e.sourceCodeFile,t=n||{},u=t.h5Id,v=t.h5Name,w=t.mainUrl,x=t.suburl,y=void 0===x?"":x,z=t.extendInfo,A=t.autoInstall,B=t.resourceType,C=t.installType,D=t.platform,E=t.clientVersionMin,F=t.clientVersionMax,G=t.enableTabBar,H=void 0===G?1:G,I=t.enableOptionMenu,J=void 0===I?1:I,K=t.enableKeepAlive,L=void 0===K?1:K,M=t.extraData,N=void 0===M?"":M,O={appId:i,workspaceId:j,tenantId:k,userId:l,h5Id:u,h5Name:v,mainUrl:w,suburl:y,extendInfo:z,autoInstall:A,resourceType:B,installType:C,platform:D,clientVersionMin:E,clientVersionMax:F,enableTabBar:H,enableOptionMenu:J,enableKeepAlive:L,packageType:1*o},p){a.next=8;break}throw new Error("\u6CA1\u6709\u5C0F\u7A0B\u5E8F\u5305\u8D44\u6E90\u6587\u4EF6\uFF01");case 8:if(o){a.next=10;break}throw new Error("\u6CA1\u6709\u5305\u7C7B\u578B\uFF01");case 10:return a.next=12,f();case 12:if(P=a.sent,P.success){a.next=15;break}throw new Error(P.resultMsg);case 15:if(P.data){a.next=17;break}throw new Error("\u65E0\u865A\u62DF\u57DF\u540D\uFF0C\u9700\u8981\u5148\u81F3\u63A7\u5236\u53F0\u8BBE\u7F6E\u865A\u62DF\u57DF\u540D");case 17:if(O.vhost="".concat(u,".").concat(P.data),"development"!==getPackageType(o).data){a.next=33;break}if(r){a.next=21;break}throw new Error("\u975E\u6B63\u5F0F\u5305\u9700\u8981\u6709\u767D\u540D\u5355\uFF01");case 21:if(0!=o-3){a.next=28;break}return a.next=24,getUUID(m);case 24:if(Q=a.sent,Q.success){a.next=27;break}throw new Error("\u8BF7\u6C42UUID\u9519\u8BEF\uFF01");case 27:O.uuid=Q.data;case 28:return a.next=30,g();case 30:if(R=a.sent,R.success){a.next=33;break}throw new Error(R.resultMsg);case 33:S=e.h5Version,S||(T=getVersion(null===n||void 0===n?void 0:n.h5Version).data,S="production"===getPackageType(o).data?T.nextProd:T.nextDev);;O.h5Version=S,U=looseJsonParse(N),V=U.data,V=void 0===V?{}:V,W=V.iconUrl,a.t0=c,a.next="aliyun"===a.t0?43:70;break;case 43:if(!p){a.next=50;break}return a.next=46,h(p);case 46:if(X=a.sent,X.success){a.next=49;break}throw new Error(X.resultMsg);case 49:O.resourceFileUrl=X.data;case 50:if(!q){a.next=60;break}return logger("\u4F20\u5165iconFile: ".concat(q)),a.next=54,h(p);case 54:if(Y=a.sent,Y.success){a.next=57;break}throw new Error(Y.resultMsg);case 57:O.iconFileUrl=Y.data,a.next=61;break;case 60:W&&(logger("\u672A\u4F20\u5165iconFile\uFF0C\u4E0A\u6B21\u53D1\u5E03\u6709iconUrl\uFF0C\u672C\u6B21\u53D1\u5E03\u7EE7\u7EED\u4F7F\u7528".concat(W)),O.iconUrl=W);case 61:;if(!s){a.next=69;break}return a.next=65,h(s);case 65:if(Z=a.sent,Z.success){a.next=68;break}throw new Error(Z.resultMsg);case 68:O.sourceCodeFileUrl=Z.data;case 69:return a.abrupt("break",76);case 70:$=[{name:"resourceFile",file:p}],q?(logger("\u4F20\u5165iconFile: ".concat(q)),$.push({name:"iconFile",file:q})):W&&(logger("\u672A\u4F20\u5165iconFile\uFF0C\u4E0A\u6B21\u53D1\u5E03\u6709iconUrl\uFF0C\u672C\u6B21\u53D1\u5E03\u7EE7\u7EED\u4F7F\u7528".concat(W)),O.iconUrl=W);;return s&&$.push({name:"sourceCodeFile",file:s}),O.files=$,a.abrupt("break",76);case 76:return a.abrupt("return",O);case 79:throw a.prev=79,a.t1=a["catch"](1),new Error(a.t1.message);case 82:case"end":return a.stop();}},a,null,[[1,79]])}));return function(){return a.apply(this,arguments)}}();exports.getUploadData=getUploadData; | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _exportNames={delay:!0,getConfigType:!0,login:!0,defaultTinyappConfig:!0,getDefaultTinyappConfig:!0,getTmpDirRoot:!0,getTmpDir:!0,cleanCache:!0,getVersion:!0,getUUID:!0,getZipFile:!0,getZipFromTar:!0,logger:!0,getPackageType:!0,looseJsonParse:!0,downloadFile:!0,getUploadData:!0};Object.defineProperty(exports,"__esModule",{value:!0});exports.looseJsonParse=exports.login=exports.logger=exports.getZipFromTar=exports.getZipFile=exports.getVersion=exports.getUploadData=exports.getUUID=exports.getTmpDirRoot=exports.getTmpDir=exports.getPackageType=exports.getDefaultTinyappConfig=exports.getConfigType=exports.downloadFile=exports.delay=exports.defaultTinyappConfig=exports.cleanCache=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_superagent=_interopRequireDefault(require("superagent")),_tar=_interopRequireDefault(require("tar")),_archiver=_interopRequireDefault(require("archiver")),_os=require("os"),_path=_interopRequireDefault(require("path")),_uuid=_interopRequireDefault(require("uuid")),_progress=_interopRequireDefault(require("progress")),_fsExtra=require("fs-extra"),_cloudBuild=require("./cloudBuild");Object.keys(_cloudBuild).forEach(function(a){"default"===a||"__esModule"===a||Object.prototype.hasOwnProperty.call(_exportNames,a)||a in exports&&exports[a]===_cloudBuild[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _cloudBuild[a]}})});var _log4js=_interopRequireDefault(require("log4js")),_excluded=["config"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){(0,_defineProperty2["default"])(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}var tmpdirRoot="".concat((0,_os.tmpdir)(),"/.mpaas_ide_openapi"),delay=function(a){return new Promise(function(b){return setTimeout(b,a)})};exports.delay=delay;var getConfigType=function(a){var b="",c=a.openapi;if(!c)b="classic";else{var d=c.type;"aliyun"===d?b="aliyun":"antfin"===d&&(b="antfin")}return{data:b,success:!0}};exports.getConfigType=getConfigType;var login=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:c=b.config,d=(0,_objectWithoutProperties2["default"])(b,_excluded),a.prev=1,e=getConfigType(c),f=e.data,g={},a.t0=f,a.next="classic"===a.t0?7:13;break;case 7:return h=c.login_url,a.next=10,_superagent["default"].post(h).field(_objectSpread(_objectSpread({},d),{},{config:JSON.stringify(c)}));case 10:return i=a.sent,g=JSON.parse(i.text).data,a.abrupt("break",16);case 13:return j=c.userId,g={data:{id:j,loginName:j,nickName:j,realName:j}},a.abrupt("break",16);case 16:return a.abrupt("return",g);case 19:throw a.prev=19,a.t1=a["catch"](1),new Error(a.t1.message);case 22:case"end":return a.stop();}},a,null,[[1,19]])}));return function(){return a.apply(this,arguments)}}();exports.login=login;var defaultTinyappConfig={appCode:"",autoInstall:1,clientVersionMax:"",clientVersionMin:"0.0.0.0;0.0.0.0",downloadUrl:"",debugUrl:"",extendInfo:"",extraData:"{\"enableKeepAlive\":\"0\",\"enableOptionMenu\":\"1\",\"enableTabBar\":\"0\",\"iconUrl\":\"\",\"resourceType\":\"4\"}",fallbackBaseUrl:"",fileSize:"",gmtCreate:"",gmtModified:"",h5Version:"1.0.0.0",installType:1,lazyLoad:0,mainUrl:"/index.html#pages/index/index",md5:"",memo:"",modifier:"success",platform:"all",publishPeriod:5,releaseVersion:"",resourceType:"4",status:1};exports.defaultTinyappConfig=defaultTinyappConfig;var getDefaultTinyappConfig=function(a){return{data:_objectSpread(_objectSpread({},defaultTinyappConfig),a),success:!0}};exports.getDefaultTinyappConfig=getDefaultTinyappConfig;var getTmpDirRoot=function(){var a=(0,_fsExtra.existsSync)(tmpdirRoot);return a||(0,_fsExtra.mkdirSync)(tmpdirRoot),tmpdirRoot};exports.getTmpDirRoot=getTmpDirRoot;var getTmpDir=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"appid",b=getTmpDirRoot(),c="".concat(b,"/").concat(a,"_").concat(new Date().valueOf(),"_").concat(_uuid["default"].v4()),d=(0,_fsExtra.existsSync)(c);return d||(0,_fsExtra.mkdirSync)(c),c};exports.getTmpDir=getTmpDir;var cleanCache=function(){try{var a=getTmpDirRoot();return(0,_fsExtra.emptydirSync)(a),{data:"OK",success:!0}}catch(a){throw new Error(a.message)}};exports.cleanCache=cleanCache;var getVersion=function(a){try{var b=a.split("."),c=(0,_slicedToArray2["default"])(b,4),d=c[0],e=c[1],f=c[2],g=c[3],h=void 0===g?0:g,i=[d,e,f,h].join("."),j=[d,e,1*f+1,0].join("."),k=[d,e,f,1*h+1].join(".");return{data:{current:i,nextProd:j,nextDev:k},success:!0}}catch(a){throw new Error(a)}};exports.getVersion=getVersion;var getUUID=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,_superagent["default"].get(b);case 3:return c=a.sent,d=c.text,a.abrupt("return",{data:d,success:!0});case 8:throw a.prev=8,a.t0=a["catch"](0),new Error(a.t0);case 11:case"end":return a.stop();}},a,null,[[0,8]])}));return function(){return a.apply(this,arguments)}}();exports.getUUID=getUUID;var getZipFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=b.pathname,d=b.version,e=b.h5Id,a.abrupt("return",new Promise(function(a,b){var f=getTmpDir();(0,_fsExtra.ensureDirSync)(f);try{var g="".concat(f,"/").concat(e,".zip");d&&(g="".concat(f,"/").concat(e,"_").concat(d.replace(/\./ig,"_"),".zip"));var h=(0,_fsExtra.createWriteStream)(g),i=(0,_archiver["default"])("zip",{zlib:{level:9}});i.pipe(h),h.on("close",function(){a(g)}),i.on("error",function(a){b(a)}),i.directory("".concat(c),e),i.finalize()}catch(a){(0,_fsExtra.removeSync)(f),b(a)}}));case 2:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}();exports.getZipFile=getZipFile;var getZipFromTar=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(){var b,c,d,e,f,g,h=arguments;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b=0<h.length&&void 0!==h[0]?h[0]:{},c=b.tarFilePath,d=b.h5Id,e=getTmpDir(),f=_path["default"].join(e,d),(0,_fsExtra.ensureDirSync)(f),a.prev=4,a.next=7,_tar["default"].x({file:_path["default"].resolve(c),cwd:f});case 7:return a.next=9,getZipFile({pathname:f,h5Id:d});case 9:return g=a.sent,a.abrupt("return",{data:g,success:!0});case 13:throw a.prev=13,a.t0=a["catch"](4),new Error(a.t0.message);case 16:return a.prev=16,(0,_fsExtra.removeSync)(e),a.finish(16);case 19:case"end":return a.stop();}},a,null,[[4,13,16,19]])}));return function(){return a.apply(this,arguments)}}();exports.getZipFromTar=getZipFromTar;var showLog=function(a,b){_log4js["default"].configure({appenders:{"[mpaas-ide-openapi]":{type:"dateFile",filename:".mpaas-ide-openapi",pattern:"yyyy-MM-dd.log",alwaysIncludePattern:!0,category:"normal"}},categories:{default:{appenders:["[mpaas-ide-openapi]"],level:"trace"}}}),_log4js["default"].getLogger("[mpaas-ide-openapi]")[a](JSON.stringify(b))},logger=(0,_defineProperty2["default"])({trace:function trace(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("trace",b):null},debug:function debug(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("debug",b):null},info:function info(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("info",b):null},warn:function warn(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("warn",b):null},error:function error(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("error",b):null}},"debug",function debug(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return global.log?showLog("debug",b):null});exports.logger=logger;var getPackageType=function(a){return{data:["1","2"].includes(a)?"production":"development",success:!0}};exports.getPackageType=getPackageType;var looseJsonParse=function(a){try{return{data:Function("\"use strict\";return (".concat(a,")"))(),success:!0}}catch(b){return{data:JSON.parse(a.replace(/"/ig,"\"")),success:!0}}};exports.looseJsonParse=looseJsonParse;var downloadFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.url,d=b.target,a.prev=1,a.t0=d,a.t0){a.next=7;break}return a.next=6,getTmpDir();case 6:a.t0=a.sent;case 7:return e=a.t0,f="".concat(_uuid["default"].v4()).concat(_path["default"].extname(new URL(c).pathname)),g=_path["default"].join(e,f),a.next=12,_superagent["default"].get(c);case 12:return h=a.sent,a.next=15,(0,_fsExtra.writeFileSync)(g,h.body,"binary");case 15:return a.abrupt("return",{data:g,success:!0});case 18:throw a.prev=18,a.t1=a["catch"](1),new Error(a.t1.message);case 21:case"end":return a.stop();}},a,null,[[1,18]])}));return function(){return a.apply(this,arguments)}}();exports.downloadFile=downloadFile;var getUploadData=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function a(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=b.type,d=b.config,e=b.req,f=b.getVhostByApi,g=b.createWhitelistByApi,h=b.uploadFile,a.prev=1,i=d.appId,j=d.workspaceId,k=d.tenantId,l=d.userId,m=d.uuid_url,n=e.appInfo,o=e.packageType,p=e.resourceFile,q=e.iconFile,r=e.whiteListValue,s=e.sourceCodeFile,t=n||{},u=t.h5Id,v=t.h5Name,w=t.mainUrl,x=t.suburl,y=void 0===x?"":x,z=t.extendInfo,A=t.autoInstall,B=t.resourceType,C=t.installType,D=t.platform,E=t.clientVersionMin,F=t.clientVersionMax,G=t.enableTabBar,H=void 0===G?1:G,I=t.enableOptionMenu,J=void 0===I?1:I,K=t.enableKeepAlive,L=void 0===K?1:K,M=t.extraData,N=void 0===M?"":M,O={appId:i,workspaceId:j,tenantId:k,userId:l,h5Id:u,h5Name:v,mainUrl:w,suburl:y,extendInfo:z,autoInstall:A,resourceType:B,installType:C,platform:D,clientVersionMin:E,clientVersionMax:F,enableTabBar:H,enableOptionMenu:J,enableKeepAlive:L,packageType:1*o},p){a.next=8;break}throw new Error("\u6CA1\u6709\u5C0F\u7A0B\u5E8F\u5305\u8D44\u6E90\u6587\u4EF6\uFF01");case 8:if(o){a.next=10;break}throw new Error("\u6CA1\u6709\u5305\u7C7B\u578B\uFF01");case 10:return a.next=12,f();case 12:if(P=a.sent,P.success){a.next=15;break}throw new Error(P.resultMsg);case 15:if(P.data){a.next=17;break}throw new Error("\u65E0\u865A\u62DF\u57DF\u540D\uFF0C\u9700\u8981\u5148\u81F3\u63A7\u5236\u53F0\u8BBE\u7F6E\u865A\u62DF\u57DF\u540D");case 17:if(O.vhost="".concat(u,".").concat(P.data),"development"!==getPackageType(o).data){a.next=33;break}if(r){a.next=21;break}throw new Error("\u975E\u6B63\u5F0F\u5305\u9700\u8981\u6709\u767D\u540D\u5355\uFF01");case 21:if(0!=o-3){a.next=28;break}return a.next=24,getUUID(m);case 24:if(Q=a.sent,Q.success){a.next=27;break}throw new Error("\u8BF7\u6C42UUID\u9519\u8BEF\uFF01");case 27:O.uuid=Q.data;case 28:return a.next=30,g();case 30:if(R=a.sent,R.success){a.next=33;break}throw new Error(R.resultMsg);case 33:S=e.h5Version,S||(T=getVersion(null===n||void 0===n?void 0:n.h5Version).data,S="production"===getPackageType(o).data?T.nextProd:T.nextDev);;O.h5Version=S,U=looseJsonParse(N),V=U.data,V=void 0===V?{}:V,W=V.iconUrl,a.t0=c,a.next="aliyun"===a.t0?43:69;break;case 43:if(!p){a.next=50;break}return a.next=46,h(p);case 46:if(X=a.sent,X.success){a.next=49;break}throw new Error(X.resultMsg);case 49:O.resourceFileUrl=X.data;case 50:if(!q){a.next=59;break}return a.next=53,h(p);case 53:if(Y=a.sent,Y.success){a.next=56;break}throw new Error(Y.resultMsg);case 56:O.iconFileUrl=Y.data,a.next=60;break;case 59:W&&(O.iconUrl=W);case 60:;if(!s){a.next=68;break}return a.next=64,h(s);case 64:if(Z=a.sent,Z.success){a.next=67;break}throw new Error(Z.resultMsg);case 67:O.sourceCodeFileUrl=Z.data;case 68:return a.abrupt("break",75);case 69:$=[{name:"resourceFile",file:p}],q?$.push({name:"iconFile",file:q}):W&&(O.iconUrl=W);;return s&&$.push({name:"sourceCodeFile",file:s}),O.files=$,a.abrupt("break",75);case 75:return a.abrupt("return",O);case 78:throw a.prev=78,a.t1=a["catch"](1),new Error(a.t1.message);case 81:case"end":return a.stop();}},a,null,[[1,78]])}));return function(){return a.apply(this,arguments)}}();exports.getUploadData=getUploadData; |
{ | ||
"name": "@alipay-inc/mpaas-ide-openapi-common", | ||
"version": "1.0.0-beta.22", | ||
"version": "1.0.2", | ||
"main": "dist/index.js", | ||
@@ -16,4 +16,6 @@ "repository": "https://code.alipay.com/mPaaS-IDE-Adaptor/mPaaS-IDE-openAPI.git", | ||
"archiver": "^5.3.0", | ||
"chalk": "^4.1.2", | ||
"fs-extra": "^10.0.0", | ||
"get-folder-size": "^3.1.0", | ||
"log4js": "^6.3.0", | ||
"progress": "^2.0.3", | ||
@@ -31,3 +33,3 @@ "superagent": "^6.1.0", | ||
}, | ||
"gitHead": "9c893ccdbf7a1b80998272f992ae8e4ccddfeb75" | ||
"gitHead": "2f2c02d08b24cf2359e5f54a429176fe0c4504e4" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25356
3
9
+ Addedchalk@^4.1.2
+ Addedlog4js@^6.3.0
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddate-format@4.0.14(transitive)
+ Addedflatted@3.3.2(transitive)
+ Addedfs-extra@8.1.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedlog4js@6.9.1(transitive)
+ Addedrfdc@1.4.1(transitive)
+ Addedstreamroller@3.1.5(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addeduniversalify@0.1.2(transitive)