@alipay-inc/mpaas-ide-openapi-common
Advanced tools
Comparing version 1.0.9-alpha.0 to 1.0.9-alpha.1
@@ -1,1 +0,1 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _exportNames={uuid:!0,delay:!0,getConfigType:!0,getUserInfo:!0,setUserInfo:!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.uuid=exports.setUserInfo=exports.looseJsonParse=exports.login=exports.logger=exports.getZipFromTar=exports.getZipFile=exports.getVersion=exports.getUserInfo=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")),_isElectron=_interopRequireDefault(require("is-electron")),_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 uuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=0|16*Math.random(),c="x"==a?b:8|3&b;return c.toString(16)})};exports.uuid=uuid;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 userInfo={},getUserInfo=function(){return userInfo};exports.getUserInfo=getUserInfo;var setUserInfo=function(a){return userInfo=a};exports.setUserInfo=setUserInfo;var login=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function b(a){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:c=a.config,d=(0,_objectWithoutProperties2["default"])(a,_excluded),b.prev=1,e=getConfigType(c),f=e.data,g={},b.t0=f,b.next="classic"===b.t0?7:20;break;case 7:return h=c.login_url,i=d.username,j=d.password,k=c.sign,l={loginName:i.toLowerCase(),password:j,sign:k,config:JSON.stringify(c)},b.next=13,_superagent["default"].post(h).field(l);case 13:if(m=b.sent,g=JSON.parse(m.text).data,n=g,o=n.success,p=n.data,q=n.message,o){b.next=18;break}throw new Error(q);case 18:return setUserInfo(_objectSpread(_objectSpread({},p),{},{userId:g.data.id})),b.abrupt("break",26);case 20:return r=c.openapi,r=void 0===r?{}:r,s=r.userId,g={data:{id:s,loginName:s,nickName:s,realName:s,userId:s}},setUserInfo(g.data),b.abrupt("break",26);case 26:return b.abrupt("return",g);case 29:throw b.prev=29,b.t1=b["catch"](1),new Error(b.t1.message);case 32:case"end":return b.stop();}},b,null,[[1,29]])}));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()),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 b(a){var c,d;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return b.prev=0,b.next=3,_superagent["default"].get(a);case 3:return b.next=5,b.sent;case 5:return c=b.sent,d=c.text,b.abrupt("return",{data:d,success:!0});case 10:throw b.prev=10,b.t0=b["catch"](0),new Error(b.t0);case 13:case"end":return b.stop();}},b,null,[[0,10]])}));return function(){return a.apply(this,arguments)}}();exports.getUUID=getUUID;var getZipFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.pathname,d=a.version,e=a.h5Id,b.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 b.stop();}},b)}));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 printLog=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-adaptor]","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)))},showLog=function(a,b,c){if(c){var d=_path["default"].resolve((0,_os.homedir)(),".mpaas_ide_log");null!==c&&void 0!==c&&c.root&&!(0,_isElectron["default"])()&&((0,_fsExtra.ensureDirSync)(c.root),d=_path["default"].resolve(c.root,".mpaas-ide-openapi")),_log4js["default"].configure({appenders:{"[mpaas-ide-openapi]":{type:"dateFile",filename:d,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))}(0,_isElectron["default"])()&&printLog.apply(void 0,(0,_toConsumableArray2["default"])(b))},logger={trace:function trace(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("trace",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},info:function info(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("info",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},warn:function warn(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("warn",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},error:function error(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("error",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},debug:function debug(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("debug",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)}};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 b(a){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.url,d=a.target,b.prev=1,b.t0=d,b.t0){b.next=7;break}return b.next=6,getTmpDir();case 6:b.t0=b.sent;case 7:return e=b.t0,f="".concat(uuid()).concat(_path["default"].extname(new URL(c).pathname)),g=_path["default"].join(e,f),b.next=12,_superagent["default"].get(c);case 12:return h=b.sent,b.next=15,(0,_fsExtra.writeFileSync)(g,h.body,"binary");case 15:return b.abrupt("return",{data:g,success:!0});case 18:throw b.prev=18,b.t1=b["catch"](1),new Error(b.t1.message);case 21:case"end":return b.stop();}},b,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 b(a){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(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.type,d=a.config,e=a.req,f=a.getVhostByApi,g=a.createWhitelistByApi,h=a.uploadFile,b.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?0: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){b.next=8;break}throw new Error("\u6CA1\u6709\u5C0F\u7A0B\u5E8F\u5305\u8D44\u6E90\u6587\u4EF6\uFF01");case 8:if(o){b.next=10;break}throw new Error("\u6CA1\u6709\u5305\u7C7B\u578B\uFF01");case 10:return b.next=12,f();case 12:if(P=b.sent,P.success){b.next=15;break}throw new Error(P.resultMsg);case 15:if(P.data){b.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){b.next=33;break}if(r){b.next=21;break}throw new Error("\u975E\u6B63\u5F0F\u5305\u9700\u8981\u6709\u767D\u540D\u5355\uFF01");case 21:if(0!=o-3){b.next=28;break}return b.next=24,getUUID(m);case 24:if(Q=b.sent,Q.success){b.next=27;break}throw new Error("\u8BF7\u6C42UUID\u9519\u8BEF\uFF01");case 27:O.uuid=Q.data;case 28:return b.next=30,g();case 30:if(R=b.sent,R.success){b.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,b.t0=c,b.next="aliyun"===b.t0?43:69;break;case 43:if(!p){b.next=50;break}return b.next=46,h(p);case 46:if(X=b.sent,X.success){b.next=49;break}throw new Error(X.resultMsg);case 49:O.resourceFileUrl=X.data;case 50:if(!q){b.next=59;break}return b.next=53,h(p);case 53:if(Y=b.sent,Y.success){b.next=56;break}throw new Error(Y.resultMsg);case 56:O.iconFileUrl=Y.data,b.next=60;break;case 59:W&&(O.iconUrl=W);case 60:;if(!s){b.next=68;break}return b.next=64,h(s);case 64:if(Z=b.sent,Z.success){b.next=67;break}throw new Error(Z.resultMsg);case 67:O.sourceCodeFileUrl=Z.data;case 68:return b.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=$,b.abrupt("break",75);case 75:return b.abrupt("return",O);case 78:throw b.prev=78,b.t1=b["catch"](1),new Error(b.t1.message);case 81:case"end":return b.stop();}},b,null,[[1,78]])}));return function(){return a.apply(this,arguments)}}();exports.getUploadData=getUploadData; | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _exportNames={uuid:!0,delay:!0,getConfigType:!0,getUserInfo:!0,setUserInfo:!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.uuid=exports.setUserInfo=exports.looseJsonParse=exports.login=exports.logger=exports.getZipFromTar=exports.getZipFile=exports.getVersion=exports.getUserInfo=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")),_isElectron=_interopRequireDefault(require("is-electron")),_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 uuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=0|16*Math.random(),c="x"==a?b:8|3&b;return c.toString(16)})};exports.uuid=uuid;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 userInfo={},getUserInfo=function(){return userInfo};exports.getUserInfo=getUserInfo;var setUserInfo=function(a){return userInfo=a};exports.setUserInfo=setUserInfo;var login=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function b(a){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:c=a.config,d=(0,_objectWithoutProperties2["default"])(a,_excluded),b.prev=1,e=getConfigType(c),f=e.data,g={},b.t0=f,b.next="classic"===b.t0?7:20;break;case 7:return h=c.login_url,i=d.username,j=d.password,k=c.sign,l={loginName:i.toLowerCase(),password:j,sign:k,config:JSON.stringify(c)},b.next=13,_superagent["default"].post(h).field(l);case 13:if(m=b.sent,g=JSON.parse(m.text).data,n=g,o=n.success,p=n.data,q=n.message,o){b.next=18;break}throw new Error(q);case 18:return setUserInfo(_objectSpread(_objectSpread({},p),{},{userId:g.data.id})),b.abrupt("break",26);case 20:return r=c.openapi,r=void 0===r?{}:r,s=r.userId,g={data:{id:s,loginName:s,nickName:s,realName:s,userId:s},success:!0},setUserInfo(g.data),b.abrupt("break",26);case 26:return b.abrupt("return",g);case 29:throw b.prev=29,b.t1=b["catch"](1),new Error(b.t1.message);case 32:case"end":return b.stop();}},b,null,[[1,29]])}));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()),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 b(a){var c,d;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return b.prev=0,b.next=3,_superagent["default"].get(a);case 3:return b.next=5,b.sent;case 5:return c=b.sent,d=c.text,b.abrupt("return",{data:d,success:!0});case 10:throw b.prev=10,b.t0=b["catch"](0),new Error(b.t0);case 13:case"end":return b.stop();}},b,null,[[0,10]])}));return function(){return a.apply(this,arguments)}}();exports.getUUID=getUUID;var getZipFile=function(){var a=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.pathname,d=a.version,e=a.h5Id,b.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 b.stop();}},b)}));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 printLog=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-adaptor]","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)))},showLog=function(a,b,c){if(c){var d=_path["default"].resolve((0,_os.homedir)(),".mpaas_ide_log");null!==c&&void 0!==c&&c.root&&!(0,_isElectron["default"])()&&((0,_fsExtra.ensureDirSync)(c.root),d=_path["default"].resolve(c.root,".mpaas-ide-openapi")),_log4js["default"].configure({appenders:{"[mpaas-ide-openapi]":{type:"dateFile",filename:d,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))}(0,_isElectron["default"])()&&printLog.apply(void 0,(0,_toConsumableArray2["default"])(b))},logger={trace:function trace(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("trace",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},info:function info(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("info",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},warn:function warn(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("warn",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},error:function error(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("error",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)},debug:function debug(){for(var a,b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return showLog("debug",d,null===(a=global)||void 0===a||null===(b=a.mpaasOpenApi)||void 0===b?void 0:b.log)}};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 b(a){var c,d,e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.url,d=a.target,b.prev=1,b.t0=d,b.t0){b.next=7;break}return b.next=6,getTmpDir();case 6:b.t0=b.sent;case 7:return e=b.t0,f="".concat(uuid()).concat(_path["default"].extname(new URL(c).pathname)),g=_path["default"].join(e,f),b.next=12,_superagent["default"].get(c);case 12:return h=b.sent,b.next=15,(0,_fsExtra.writeFileSync)(g,h.body,"binary");case 15:return b.abrupt("return",{data:g,success:!0});case 18:throw b.prev=18,b.t1=b["catch"](1),new Error(b.t1.message);case 21:case"end":return b.stop();}},b,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 b(a){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(b){for(;;)switch(b.prev=b.next){case 0:if(c=a.type,d=a.config,e=a.req,f=a.getVhostByApi,g=a.createWhitelistByApi,h=a.uploadFile,b.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?0: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){b.next=8;break}throw new Error("\u6CA1\u6709\u5C0F\u7A0B\u5E8F\u5305\u8D44\u6E90\u6587\u4EF6\uFF01");case 8:if(o){b.next=10;break}throw new Error("\u6CA1\u6709\u5305\u7C7B\u578B\uFF01");case 10:return b.next=12,f();case 12:if(P=b.sent,P.success){b.next=15;break}throw new Error(P.resultMsg);case 15:if(P.data){b.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){b.next=33;break}if(r){b.next=21;break}throw new Error("\u975E\u6B63\u5F0F\u5305\u9700\u8981\u6709\u767D\u540D\u5355\uFF01");case 21:if(0!=o-3){b.next=28;break}return b.next=24,getUUID(m);case 24:if(Q=b.sent,Q.success){b.next=27;break}throw new Error("\u8BF7\u6C42UUID\u9519\u8BEF\uFF01");case 27:O.uuid=Q.data;case 28:return b.next=30,g();case 30:if(R=b.sent,R.success){b.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,b.t0=c,b.next="aliyun"===b.t0?43:69;break;case 43:if(!p){b.next=50;break}return b.next=46,h(p);case 46:if(X=b.sent,X.success){b.next=49;break}throw new Error(X.resultMsg);case 49:O.resourceFileUrl=X.data;case 50:if(!q){b.next=59;break}return b.next=53,h(p);case 53:if(Y=b.sent,Y.success){b.next=56;break}throw new Error(Y.resultMsg);case 56:O.iconFileUrl=Y.data,b.next=60;break;case 59:W&&(O.iconUrl=W);case 60:;if(!s){b.next=68;break}return b.next=64,h(s);case 64:if(Z=b.sent,Z.success){b.next=67;break}throw new Error(Z.resultMsg);case 67:O.sourceCodeFileUrl=Z.data;case 68:return b.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=$,b.abrupt("break",75);case 75:return b.abrupt("return",O);case 78:throw b.prev=78,b.t1=b["catch"](1),new Error(b.t1.message);case 81:case"end":return b.stop();}},b,null,[[1,78]])}));return function(){return a.apply(this,arguments)}}();exports.getUploadData=getUploadData; |
{ | ||
"name": "@alipay-inc/mpaas-ide-openapi-common", | ||
"version": "1.0.9-alpha.0", | ||
"version": "1.0.9-alpha.1", | ||
"main": "dist/index.js", | ||
@@ -33,3 +33,3 @@ "repository": "https://code.alipay.com/mPaaS-IDE-Adaptor/mPaaS-IDE-openAPI.git", | ||
}, | ||
"gitHead": "52a4e697ddcee0fecc9b9d759b1dc2d0e7fde273" | ||
"gitHead": "3a9b29d0915b030bf0d19255a14f6ef7a85cc2f3" | ||
} |
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
27050