This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
1 lines (1 loc) · 11 KB
/
index.js
1
module.exports=function(e){var t={};function r(s){if(t[s])return t[s].exports;var n=t[s]={i:s,l:!1,exports:{}};return e[s].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(s,n,function(t){return e[t]}.bind(null,n));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([function(e,t,r){const s=r(1),n=r(2),o=r(3).Writable;e.exports={merge:function(){const e=(t,r)=>{for(let s in t)t[s]&&t[s].constructor===Object?(r[s]=r[s]||{},r[s]=e(t[s],r[s])):r[s]=t[s];return r};return Array.from(arguments).reduce((t,r)=>e(r,t),{})},mkdirp:function(e){e=e||"";let t=n.resolve(e).split(n.sep);for(let e=1;e<t.length;e++){let r=n.join(t.slice(0,e+1).join(n.sep)+n.sep);s.existsSync(r)||s.mkdirSync(r)}},TextStream:class extends o{constructor(){super(),this._chunks=[]}_write(e,t,r){this._chunks.push(e),r()}toString(){return this._chunks.join("")}},getPath:e=>{let t,r;return e.endsWith(n.sep)||s.existsSync(e)&&s.statSync(e).isDirectory()?r=e:(r=n.dirname(e),t=n.basename(e)),{filename:t,directory:r}}}},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("stream")},function(e,t){e.exports=require("url")},function(e,t,r){"use strict";const s=r(0).merge,n=r(0).getPath,o=r(0).mkdirp,a=r(6),i=r(8),p=r(1),l=r(2),u=r(11),d=r(4).parse;e.exports=(e=>new class{constructor(e){this.defaults=s(e),this.baseUrl=this.defaults.baseUrl||"https://build.phonegap.com/api/v1",delete this.defaults.baseUrl}_get(e,t){return a.get(this.baseUrl+e,s(this.defaults,t))}_post(e,t){return a.post(this.baseUrl+e,s(this.defaults,t))}_put(e,t){return a.put(this.baseUrl+e,s(this.defaults,t))}_del(e,t){return a.del(this.baseUrl+e,s(this.defaults,t))}me(){return this._get("/me")}getToken(){return this._post("/token")}getApps(){return this._get("/apps")}getStatus(e){return this._get(`/apps/${e}/status`)}getApp(e){return this._get(`/apps/${e}`)}getAppLog(e,t){return this._get(`/apps/${e}/logs/${t}/build`)}_app(e,t){return e?this._put(`/apps/${e}`,{data:t}):this._post("/apps",{data:t})}deleteApp(e){return this._del(`/apps/${e}`)}downloadApp(e,t,r){return this._get(`/apps/${e}/${t}`,{save:r})}buildApp(e){let t=[].slice.call(arguments).slice(1);return t=[].concat.apply([],t).join(","),this._post(`/apps/${e}/build`,{data:{platforms:t}})}addCollaborator(e,t,r){return this._post(`/apps/${e}/collaborators`,{data:{email:t,role:r}})}updateCollaborator(e,t,r){return this._put(`/apps/${e}/collaborators/${t}`,{data:{role:r}})}deleteCollaborator(e,t){return this._del(`/apps/${e}/collaborators/${t}`)}getKeys(e){return this._get(`/keys/${e||""}/`)}getKey(e,t){return this._get(`/keys/${e}/${t}`)}addKey(e,t){return this._post(`/keys/${e}`,{data:t})}updateKey(e,t,r){return this._put(`/keys/${e}/${t}`,{data:r})}deleteKey(e,t){return this._del(`/keys/${e}/${t}`)}currentSupport(){return this._get("/current_support")}isRepo(e){try{return e.toString().match(/^[a-z0-9_-][a-z0-9_.-]*\/[a-z0-9_.-]+(#[a-z0-9_.-]*)?$/i)||d(e).hostname}catch(e){return!1}}addApp(e,t){return this.updateApp(null,e,t)}updateApp(e,t,r){r||"string"==typeof t||(r=t,t=null);let s=p.existsSync(t);return t?s&&p.statSync(t).isDirectory()?this.addAppFromDir(e,t,r):this.isRepo(t)?this.addAppfromRepo(e,t,r):this.addAppFromFile(e,t,r):this._app(e,r)}addAppFromDir(e,t,r){return new Promise((s,a)=>{let d=!1,h=r.zip;delete r.zip;let c=r.ignore||[];delete r.ignore,h||(h=l.join(u.tmpdir(),"pgb-"+Math.random().toString(32).slice(2)+".zip"),d=!0);let f=n(h);f.filename=f.filename||"app.zip",o(f.directory),h=l.join(f.directory,f.filename);const m=(e,t)=>{this.defaults.events&&this.defaults.events.emit&&this.defaults.events.emit(e,t)},y=()=>{d&&p.existsSync(h)&&p.statSync(h).isFile()&&(p.unlinkSync(h),m("debug",`archive deleted ${h}`))};m("debug",`archiving ${t} to ${h}`),i(t,h,this.defaults.events,c).then(()=>this.addAppFromFile(e,h,r)).then(e=>{y(),s(e)}).catch(e=>{y(),a(e)})})}addAppfromRepo(e,t,r){return this._app(e,s(r,{repo:t}))}addAppFromFile(e,t,r){return new Promise((n,o)=>{let a=p.createReadStream(t);a.once("error",o),this._app(e,s(r,{file:a})).then(n,o)})}pullApp(e,t){return this._app(e,s(t,{pull:!0}))}lockKey(e,t){return this.updateKey(e,t,{lock:!0})}addIOSKey(e,t,r,n){return new Promise((o,a)=>{let i=p.createReadStream(t);i.once("error",a);let l=p.createReadStream(r);return l.once("error",a),this.addKey("ios",s({title:e,profile:i,cert:l},n)).then(o,a)})}addWindowsKey(e,t,r){return new Promise((n,o)=>{let a=p.createReadStream(t);return a.once("error",o),this.addKey("windows",s({title:e,keystore:a},r)).then(n,o)})}addAndroidKey(e,t,r,n){return new Promise((o,a)=>{let i=p.createReadStream(r);return i.once("error",a),this.addKey("android",s({title:e,keystore:i,alias:t},n)).then(o,a)})}addWinphoneKey(e,t,r){return this.addKey("winphone",s({title:e,publisher_id:t},r))}unlockIOSKey(e,t){return this.updateKey("ios",e,{password:t})}unlockAndroidKey(e,t,r){return this.updateKey("android",e,{keystore_pw:t,key_pw:r})}unlockWindowsKey(e,t){return this.updateKey("windows",e,{password:t})}hasAuth(){return!(!this.defaults.headers||!this.defaults.headers.Authorization)}clearAuth(){this.hasAuth()&&delete this.defaults.headers.Authorization}addAuth(e,t){if(this.defaults.headers=this.defaults.headers||{},e&&t){let r=`${e}:${t}`;r=Buffer.from!==Uint8Array.from?Buffer.from(r):new Buffer(r),this.defaults.headers.Authorization=`Basic ${r.toString("base64")}`}else e&&(this.defaults.headers.Authorization=`token ${e}`);return this}}(e))},function(e,t,r){const s=r(0).merge,n=r(0).mkdirp,o=r(0).TextStream,a=r(0).getPath,i=r(4),p=r(1),l=r(2),u=r(3).Stream,d=r(7),h={headers:{"User-Agent":`pgb-api/1.1.2 node/${process.version} (${process.platform})`}},c=(e,t,r)=>{e.opts.events&&e.opts.events.emit&&e.opts.events.emit(t,r)},f=(e,t)=>(t=t||{},new Promise((u,g)=>{let _=0,b={},$=i.parse(e);b.opts=s(h,$,t),m(b),c(b,"api/headers",b.opts.headers),c(b,"debug",`${b.opts.method||"GET"} ${e}`),b.req=d.request(b.opts,s=>{b.response=s;let d=Number.parseInt(s.headers["content-length"])||null,h=Math.trunc(s.statusCode/100);if(3===h&&"location"in s.headers){let r=i.parse(s.headers.location);return t.headers&&b.opts.hostname!==r.hostname&&delete t.headers.Authorization,r=i.resolve(e,r.href),c(b,"debug",`${b.req.method} ${e} -> ${s.statusCode} ${r}`),u(f(r,t))}if(b.opts.save&&2===h)if(b.opts.save instanceof r(3).Writable)b.output=b.opts.save;else{let e=a(b.opts.save);e.filename=decodeURI(e.filename||l.basename(b.opts.pathname)||"app.download"),b.output=l.join(e.directory,e.filename);try{n(e.directory),p.closeSync(p.openSync(b.output,"w")),b.path=l.resolve(b.output)}catch(e){return g(e)}c(b,"debug",`saving to ${b.path}`),b.output=p.createWriteStream(b.output)}c(b,"api/connect",{statusCode:s.statusCode,size:d,headers:s.headers,path:b.path,url:e,method:b.req.method}),c(b,"debug",`${b.req.method} ${e} -> ${s.statusCode}`),b.output=b.output||new o,b.output.once("error",g),s.pipe(b.output),s.on("data",e=>{_+=e.length,c(b,"api/read",{size:d,pos:_,delta:e.length})}),s.once("end",()=>{let e=(e=>{let t,r;if(e.output.constructor===o){t=e.output.toString();try{r=JSON.parse(t)}catch(e){}}return e.path||r||t})(b);if(2===h)u(e);else{let t=new Error(e.error||e);t.statusCode=s.statusCode,g(t)}})}),b.req.once("error",g),y(b)})),m=e=>{if(e._payload=[],e._contentLength=0,null==e.opts.data)return;for(let t in e.opts.data){let r=e.opts.data[t];if(e._payload.push("------pgbapi\r\n"),r instanceof u){let s=l.basename(r.path);e._payload.push(`Content-Disposition: form-data; name="${t}"; filename="${s.replace('"','\\"')}"\r\n`),e._payload.push("Content-Type: application/octet-stream\r\n\r\n"),e._payload.push(r),e._payload.push("\r\n")}else e._payload.push(`Content-Disposition: form-data; name="${t}";\r\n\r\n`),r&&"Object"===r.constructor.name&&(r=JSON.stringify(r)),e._payload.push(`${r}\r\n`)}e._payload.push("------pgbapi--\r\n");for(let t of e._payload)e._contentLength+=t.length||p.statSync(t.path).size;e.opts.headers["Content-Length"]=e._contentLength,e.opts.headers["Content-Type"]="multipart/form-data; boundary=----pgbapi"},y=e=>{if(0===e._payload.length)return e.req.end();let t=0;let r=e._payload.slice(0),s=()=>{((r,s)=>{r instanceof u?(r.on("data",r=>{t+=r.length,c(e,"api/write",{size:e._contentLength,pos:t,delta:r.length})}),r.once("end",s),r.pipe(e.req,{end:!1})):(t+=r.length,e.req.write(r),c(e,"api/write",{size:e._contentLength,pos:t,delta:r.length}),s())})(r.shift(),()=>0===r.length?e.req.end():s())};s()};e.exports={post:(e,t)=>f(e,s(t,{method:"POST"})),put:(e,t)=>f(e,s(t,{method:"PUT"})),del:(e,t)=>f(e,s(t,{method:"DELETE"})),get:f}},function(e,t){e.exports=require("https")},function(e,t,r){const s=r(1),n=r(9),o=r(2),a=r(10).glob;e.exports=((e,t,r,i)=>new Promise((p,l)=>{let u=a(e,i),d=s.createWriteStream(t),h=new n.ZipFile,c="",f=0,m=[0],y=0,g=0;const _=(e,t)=>{r&&r.emit(e,t)};_("zip/files",u);for(let t of u.list){let r=o.resolve(o.join(e,t.path));s.statSync(r).isDirectory()?(h.addEmptyDirectory(t.path),y+=46+t.path.length+1):(h.addFile(r,t.path),y+=46+t.path.length),m.push(y+=t.size)}d.on("error",l),h.outputStream.on("error",l),h.outputStream.pipe(d).once("close",()=>{_("zip/write",{size:y,file:c,pos:y,delta:m[m.length-1]-g}),_("zip/end",!0),p()}),h.outputStream.on("data",e=>{for(let e=f;e<h.entries.length;e++){let t=h.entries[e];if(2===t.state){c=t.utf8FileName.toString(),f=e;break}}_("zip/write",{size:y,file:c,pos:m[f],delta:m[f]-g}),g=m[f]}),h.end()}))},function(e,t){e.exports=require("yazl")},function(e,t,r){const s=r(1),n=r(2),o=e=>{if(null==e||"#"===e[0]||""===e.trim())return null;let t=0===e.indexOf("!"),r=!1;return e.endsWith("/")&&(e=e.slice(0,-1),r=!0),(t||"/"===e[0])&&(e=e.slice(1)),-1===(e=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\?/g,".").replace(/\*\*\//g,"^e^").replace(/\*\*/g,"^e^").replace(/\*/g,"[^/]+").replace(/\^e\^/g,".*")).indexOf("/")&&(e+="/?"),{dir:r,not:t,regex:new RegExp(`^${e}$`)}},a=(e,t,r)=>{let s=!1;e=e.split(n.sep).join("/");for(let n of r)if(null!=n&&(!n.dir||t)&&n.regex.test(e)){if(n.dir&&t)return!n.not;s=!n.not}return s};e.exports={glob:(e,t)=>{let r=[],i=[],p=(t||[]).map(o),l=t=>{s.readdirSync(t).forEach(o=>{let u=n.join(t,o),d=n.relative(e,u);if(!o.startsWith(".")||o.match(/^\.pgb/))try{let e=s.statSync(u);s.closeSync(s.openSync(u,"r"));let t=a(d,e.isDirectory(),p);e.isDirectory()?t?i.push(`${d}${n.sep} [IGNORED]`):(r.push({path:d,size:0}),l(u)):(t?i.push(`${d} [IGNORED]`):r.push({path:d,size:e.size}),r.push())}catch(e){i.push(`${d} [${e.code}]`)}else i.push(`${d} [HIDDEN]`)})};return l(e),{list:r,skipped:i}},toGlobRegex:o,filter:a}},function(e,t){e.exports=require("os")}]);