From d17fc3685a0178152d8fbb0dfe12fccab5f9560e Mon Sep 17 00:00:00 2001 From: goya Date: Mon, 3 Sep 2018 15:25:13 -0700 Subject: [PATCH] allow multiple platforms for build --- CHEATSHEET.md | 2 +- index.js | 2 +- src/api.js | 6 ++++-- test/api.js | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CHEATSHEET.md b/CHEATSHEET.md index 4270acb..f9bb9dd 100644 --- a/CHEATSHEET.md +++ b/CHEATSHEET.md @@ -62,7 +62,7 @@ pgb.getApp(id) // get single app pgb.getAppLog(id, platform) // get build log for a single platform pgb.downloadApp(id, platform, [path]) // save app to optional path pgb.pullApp(id) // pull new version from repo and trigger a build -pgb.buildApp(id, [platform]) // build app, optionally by single platform +pgb.buildApp(id, [platforms...]) // build app, optionally by specified platforms pgb.deleteApp(id) // delete app /* COLLABORATORS */ diff --git a/index.js b/index.js index da523f4..c68dad6 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},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 n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},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 n=r(1),s=r(2),o=r(3).Writable;e.exports={merge:function(){const e=(t,r)=>{for(let n in t)t[n]&&t[n].constructor===Object?(r[n]=r[n]||{},r[n]=e(t[n],r[n])):r[n]=t[n];return r};return Array.from(arguments).reduce((t,r)=>e(r,t),{})},mkdirp:function(e){e=e||"";let t=s.resolve(e).split(s.sep);for(let e=1;e{let t,r;return e.endsWith(s.sep)||n.existsSync(e)&&n.statSync(e).isDirectory()?r=e:(r=s.dirname(e),t=s.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 n=r(0).merge,s=r(0).getPath,o=r(0).mkdirp,a=r(6),i=r(9),p=r(1),u=r(2),d=r(11),l=r(4).parse,h="https://build.phonegap.com/api/v1";e.exports=(e=>new class{constructor(e){this.defaults=n(e)}_get(e,t){return a.get(h+e,n(this.defaults,t))}_post(e,t){return a.post(h+e,n(this.defaults,t))}_put(e,t){return a.put(h+e,n(this.defaults,t))}_del(e,t){return a.del(h+e,n(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,t){return this._post(`/apps/${e}/build/${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)||l(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 n=p.existsSync(t);return t?n&&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((n,a)=>{let l=!1,h=r.zip;delete r.zip,h||(h=u.join(d.tmpdir(),"pgb-"+Math.random().toString(32).slice(2)+".zip"),l=!0);let c=s(h);c.filename=c.filename||"app.zip",o(c.directory),h=u.join(c.directory,c.filename);const f=(e,t)=>{this.defaults.events&&this.defaults.events.emit&&this.defaults.events.emit(e,t)},m=()=>{l&&p.existsSync(h)&&p.statSync(h).isFile()&&(p.unlinkSync(h),f("debug",`archive deleted ${h}`))};f("debug",`archiving ${t} to ${h}`),i.zipDir(t,h,this.defaults.events).then(()=>this.addAppFromFile(e,h,r)).then(e=>{m(),n(e)}).catch(e=>{m(),a(e)})})}addAppfromRepo(e,t,r){return this._app(e,n(r,{repo:t}))}addAppFromFile(e,t,r){return new Promise((s,o)=>{let a=p.createReadStream(t);a.once("error",o),this._app(e,n(r,{file:a})).then(s,o)})}pullApp(e,t){return this._app(e,n(t,{pull:!0}))}lockKey(e,t){return this.updateKey(e,t,{lock:!0})}addIOSKey(e,t,r,s){return new Promise((o,a)=>{let i=p.createReadStream(t);i.once("error",a);let u=p.createReadStream(r);return u.once("error",a),this.addKey("ios",n({title:e,profile:i,cert:u},s)).then(o,a)})}addWindowsKey(e,t,r){return new Promise((s,o)=>{let a=p.createReadStream(t);return a.once("error",o),this.addKey("windows",n({title:e,keystore:a},r)).then(s,o)})}addAndroidKey(e,t,r,s){return new Promise((o,a)=>{let i=p.createReadStream(r);return i.once("error",a),this.addKey("android",n({title:e,keystore:i,alias:t},s)).then(o,a)})}addWinphoneKey(e,t,r){return this.addKey("winphone",n({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 n=r(0).merge,s=r(0).mkdirp,o=r(0).TextStream,a=r(0).getPath,i=r(4),p=r(1),u=r(2),d=r(3).Stream,l=r(7).version,h=r(8),c={headers:{"User-Agent":`pgb-api/${l} node/${process.version} (${process.platform})`}},f=(e,t,r)=>{e.opts.events&&e.opts.events.emit&&e.opts.events.emit(t,r)},m=(e,t)=>(t=t||{},new Promise((d,l)=>{let _=0,b={},$=i.parse(e);b.opts=n(c,$,t),y(b),f(b,"api/headers",b.opts.headers),f(b,"debug",`${b.opts.method||"GET"} ${e}`),b.req=h.request(b.opts,n=>{b.response=n;let h=Number.parseInt(n.headers["content-length"])||null,c=Math.trunc(n.statusCode/100);if(3===c&&"location"in n.headers){let r=i.parse(n.headers.location);return t.headers&&b.opts.hostname!==r.hostname&&delete t.headers.Authorization,r=i.resolve(e,r.href),f(b,"debug",`${b.req.method} ${e} -> ${n.statusCode} ${r}`),d(m(r,t))}if(b.opts.save&&2===c)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||u.basename(b.opts.pathname)||"app.download"),b.output=u.join(e.directory,e.filename);try{s(e.directory),p.closeSync(p.openSync(b.output,"w")),b.path=u.resolve(b.output)}catch(e){return l(e)}f(b,"debug",`saving to ${b.path}`),b.output=p.createWriteStream(b.output)}f(b,"api/connect",{statusCode:n.statusCode,size:h,headers:n.headers,path:b.path,url:e,method:b.req.method}),f(b,"debug",`${b.req.method} ${e} -> ${n.statusCode}`),b.output=b.output||new o,b.output.once("error",l),n.pipe(b.output),n.on("data",e=>{_+=e.length,f(b,"api/read",{size:h,pos:_,delta:e.length})}),n.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===c)d(e);else{let t=new Error(e.error||e);t.statusCode=n.statusCode,l(t)}})}),b.req.once("error",l),g(b)})),y=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 d){let n=u.basename(r.path);e._payload.push(`Content-Disposition: form-data; name="${t}"; filename="${n.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"},g=e=>{if(0===e._payload.length)return e.req.end();let t=0;let r=e._payload.slice(0),n=()=>{((r,n)=>{r instanceof d?(r.on("data",r=>{t+=r.length,f(e,"api/write",{size:e._contentLength,pos:t,delta:r.length})}),r.once("end",n),r.pipe(e.req,{end:!1})):(t+=r.length,e.req.write(r),f(e,"api/write",{size:e._contentLength,pos:t,delta:r.length}),n())})(r.shift(),()=>0===r.length?e.req.end():n())};n()};e.exports={post:(e,t)=>m(e,n(t,{method:"POST"})),put:(e,t)=>m(e,n(t,{method:"PUT"})),del:(e,t)=>m(e,n(t,{method:"DELETE"})),get:m}},function(e){e.exports={name:"pgb-api",version:"1.0.4",description:"nodeJS API to PhoneGap Build",keywords:["PhoneGap","Cordova","PhoneGap Build","api"],bugs:{url:"https://github.com/phonegap-build/pgb-api/issues"},main:"./index.js",scripts:{build:"npm test && webpack",test:"eslint . && jest --coverage"},engines:{node:">= 4.0.0"},author:"Brett Rudd ",license:"MIT",repository:{type:"git",url:"phonegap-build/pgb-api"},devDependencies:{eslint:"^5.1.0","eslint-config-standard":"^12.0.0","eslint-plugin-import":"^2.10.0","eslint-plugin-jest":"^21.15.0","eslint-plugin-node":"^7.0.1","eslint-plugin-promise":"^4.0.0","eslint-plugin-standard":"^4.0.0",express:"^4.16.3",jest:"^23.4.1","jest-plugin-fs":"^2.9.0",multer:"^1.3.0",webpack:"^4.16.0","webpack-cli":"^3.0.8","webpack-node-externals":"^1.7.2"},dependencies:{yazl:"^2.4.3"}}},function(e,t){e.exports=require("https")},function(e,t,r){const n=r(1),s=r(10),o=r(2),a=e=>{let t=[],r=[],s=e=>{n.readdirSync(e).forEach(a=>{let i=o.join(e,a);if(!a.startsWith(".")||a.match(/^\.pgb/))try{let e=n.statSync(i);n.closeSync(n.openSync(i,"r")),e.isDirectory()?(t.push({path:i,size:0}),s(i)):t.push({path:i,size:e.size})}catch(e){r.push(`${i} [${e.code}]`)}else r.push(`${i} [HIDDEN]`)})};return s(e),{list:t,skipped:r}};e.exports={getFileList:a,zipDir:(e,t,r)=>new Promise((i,p)=>{let u=a(e),d=n.createWriteStream(t),l=new s.ZipFile,h="",c=0,f=[0],m=0,y=0;const g=(e,t)=>{r&&r.emit(e,t)};g("zip/files",u);for(let t of u.list){let r=o.relative(e,t.path);n.statSync(t.path).isDirectory()?(l.addEmptyDirectory(r),m+=46+r.length+1):(l.addFile(t.path,r),m+=46+r.length),f.push(m+=t.size)}d.on("error",p),l.outputStream.on("error",p),l.outputStream.pipe(d).once("close",()=>{g("zip/write",{size:m,file:h,pos:m,delta:f[f.length-1]-y}),g("zip/end",!0),i()}),l.outputStream.on("data",e=>{for(let e=c;e{for(let n in t)t[n]&&t[n].constructor===Object?(r[n]=r[n]||{},r[n]=e(t[n],r[n])):r[n]=t[n];return r};return Array.from(arguments).reduce((t,r)=>e(r,t),{})},mkdirp:function(e){e=e||"";let t=s.resolve(e).split(s.sep);for(let e=1;e{let t,r;return e.endsWith(s.sep)||n.existsSync(e)&&n.statSync(e).isDirectory()?r=e:(r=s.dirname(e),t=s.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 n=r(0).merge,s=r(0).getPath,o=r(0).mkdirp,a=r(6),i=r(9),p=r(1),u=r(2),d=r(11),l=r(4).parse,h="https://build.phonegap.com/api/v1";e.exports=(e=>new class{constructor(e){this.defaults=n(e)}_get(e,t){return a.get(h+e,n(this.defaults,t))}_post(e,t){return a.post(h+e,n(this.defaults,t))}_put(e,t){return a.put(h+e,n(this.defaults,t))}_del(e,t){return a.del(h+e,n(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)||l(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 n=p.existsSync(t);return t?n&&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((n,a)=>{let l=!1,h=r.zip;delete r.zip,h||(h=u.join(d.tmpdir(),"pgb-"+Math.random().toString(32).slice(2)+".zip"),l=!0);let c=s(h);c.filename=c.filename||"app.zip",o(c.directory),h=u.join(c.directory,c.filename);const f=(e,t)=>{this.defaults.events&&this.defaults.events.emit&&this.defaults.events.emit(e,t)},m=()=>{l&&p.existsSync(h)&&p.statSync(h).isFile()&&(p.unlinkSync(h),f("debug",`archive deleted ${h}`))};f("debug",`archiving ${t} to ${h}`),i.zipDir(t,h,this.defaults.events).then(()=>this.addAppFromFile(e,h,r)).then(e=>{m(),n(e)}).catch(e=>{m(),a(e)})})}addAppfromRepo(e,t,r){return this._app(e,n(r,{repo:t}))}addAppFromFile(e,t,r){return new Promise((s,o)=>{let a=p.createReadStream(t);a.once("error",o),this._app(e,n(r,{file:a})).then(s,o)})}pullApp(e,t){return this._app(e,n(t,{pull:!0}))}lockKey(e,t){return this.updateKey(e,t,{lock:!0})}addIOSKey(e,t,r,s){return new Promise((o,a)=>{let i=p.createReadStream(t);i.once("error",a);let u=p.createReadStream(r);return u.once("error",a),this.addKey("ios",n({title:e,profile:i,cert:u},s)).then(o,a)})}addWindowsKey(e,t,r){return new Promise((s,o)=>{let a=p.createReadStream(t);return a.once("error",o),this.addKey("windows",n({title:e,keystore:a},r)).then(s,o)})}addAndroidKey(e,t,r,s){return new Promise((o,a)=>{let i=p.createReadStream(r);return i.once("error",a),this.addKey("android",n({title:e,keystore:i,alias:t},s)).then(o,a)})}addWinphoneKey(e,t,r){return this.addKey("winphone",n({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 n=r(0).merge,s=r(0).mkdirp,o=r(0).TextStream,a=r(0).getPath,i=r(4),p=r(1),u=r(2),d=r(3).Stream,l=r(7).version,h=r(8),c={headers:{"User-Agent":`pgb-api/${l} node/${process.version} (${process.platform})`}},f=(e,t,r)=>{e.opts.events&&e.opts.events.emit&&e.opts.events.emit(t,r)},m=(e,t)=>(t=t||{},new Promise((d,l)=>{let _=0,b={},$=i.parse(e);b.opts=n(c,$,t),y(b),f(b,"api/headers",b.opts.headers),f(b,"debug",`${b.opts.method||"GET"} ${e}`),b.req=h.request(b.opts,n=>{b.response=n;let h=Number.parseInt(n.headers["content-length"])||null,c=Math.trunc(n.statusCode/100);if(3===c&&"location"in n.headers){let r=i.parse(n.headers.location);return t.headers&&b.opts.hostname!==r.hostname&&delete t.headers.Authorization,r=i.resolve(e,r.href),f(b,"debug",`${b.req.method} ${e} -> ${n.statusCode} ${r}`),d(m(r,t))}if(b.opts.save&&2===c)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||u.basename(b.opts.pathname)||"app.download"),b.output=u.join(e.directory,e.filename);try{s(e.directory),p.closeSync(p.openSync(b.output,"w")),b.path=u.resolve(b.output)}catch(e){return l(e)}f(b,"debug",`saving to ${b.path}`),b.output=p.createWriteStream(b.output)}f(b,"api/connect",{statusCode:n.statusCode,size:h,headers:n.headers,path:b.path,url:e,method:b.req.method}),f(b,"debug",`${b.req.method} ${e} -> ${n.statusCode}`),b.output=b.output||new o,b.output.once("error",l),n.pipe(b.output),n.on("data",e=>{_+=e.length,f(b,"api/read",{size:h,pos:_,delta:e.length})}),n.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===c)d(e);else{let t=new Error(e.error||e);t.statusCode=n.statusCode,l(t)}})}),b.req.once("error",l),g(b)})),y=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 d){let n=u.basename(r.path);e._payload.push(`Content-Disposition: form-data; name="${t}"; filename="${n.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"},g=e=>{if(0===e._payload.length)return e.req.end();let t=0;let r=e._payload.slice(0),n=()=>{((r,n)=>{r instanceof d?(r.on("data",r=>{t+=r.length,f(e,"api/write",{size:e._contentLength,pos:t,delta:r.length})}),r.once("end",n),r.pipe(e.req,{end:!1})):(t+=r.length,e.req.write(r),f(e,"api/write",{size:e._contentLength,pos:t,delta:r.length}),n())})(r.shift(),()=>0===r.length?e.req.end():n())};n()};e.exports={post:(e,t)=>m(e,n(t,{method:"POST"})),put:(e,t)=>m(e,n(t,{method:"PUT"})),del:(e,t)=>m(e,n(t,{method:"DELETE"})),get:m}},function(e){e.exports={name:"pgb-api",version:"1.0.5",description:"nodeJS API to PhoneGap Build",keywords:["PhoneGap","Cordova","PhoneGap Build","api"],bugs:{url:"https://github.com/phonegap-build/pgb-api/issues"},main:"./index.js",scripts:{build:"npm test && webpack",test:"eslint . && jest --coverage"},engines:{node:">= 4.0.0"},author:"Brett Rudd ",license:"MIT",repository:{type:"git",url:"phonegap-build/pgb-api"},devDependencies:{eslint:"^5.1.0","eslint-config-standard":"^12.0.0","eslint-plugin-import":"^2.10.0","eslint-plugin-jest":"^21.15.0","eslint-plugin-node":"^7.0.1","eslint-plugin-promise":"^4.0.0","eslint-plugin-standard":"^4.0.0",express:"^4.16.3",jest:"^23.4.1","jest-plugin-fs":"^2.9.0",multer:"^1.3.0",webpack:"^4.16.0","webpack-cli":"^3.0.8","webpack-node-externals":"^1.7.2"},dependencies:{yazl:"^2.4.3"}}},function(e,t){e.exports=require("https")},function(e,t,r){const n=r(1),s=r(10),o=r(2),a=e=>{let t=[],r=[],s=e=>{n.readdirSync(e).forEach(a=>{let i=o.join(e,a);if(!a.startsWith(".")||a.match(/^\.pgb/))try{let e=n.statSync(i);n.closeSync(n.openSync(i,"r")),e.isDirectory()?(t.push({path:i,size:0}),s(i)):t.push({path:i,size:e.size})}catch(e){r.push(`${i} [${e.code}]`)}else r.push(`${i} [HIDDEN]`)})};return s(e),{list:t,skipped:r}};e.exports={getFileList:a,zipDir:(e,t,r)=>new Promise((i,p)=>{let u=a(e),d=n.createWriteStream(t),l=new s.ZipFile,h="",c=0,f=[0],m=0,y=0;const g=(e,t)=>{r&&r.emit(e,t)};g("zip/files",u);for(let t of u.list){let r=o.relative(e,t.path);n.statSync(t.path).isDirectory()?(l.addEmptyDirectory(r),m+=46+r.length+1):(l.addFile(t.path,r),m+=46+r.length),f.push(m+=t.size)}d.on("error",p),l.outputStream.on("error",p),l.outputStream.pipe(d).once("close",()=>{g("zip/write",{size:m,file:h,pos:m,delta:f[f.length-1]-y}),g("zip/end",!0),i()}),l.outputStream.on("data",e=>{for(let e=c;e { }) ) - test('buildApp with platform', () => + test('buildApp with single platform', () => api.buildApp(12, 'ios').then((val) => { - expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build/ios', { }) + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': 'ios' } }) + expect(val).toEqual(ret) + }) + ) + + test('buildApp with single platform array', () => + api.buildApp(12, ['ios']).then((val) => { + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': 'ios' } }) + expect(val).toEqual(ret) + }) + ) + + test('buildApp with platform array', () => + api.buildApp(12, ['ios', 'windows']).then((val) => { + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': 'ios,windows' } }) + expect(val).toEqual(ret) + }) + ) + + test('buildApp with platform array string', () => + api.buildApp(12, 'ios,windows').then((val) => { + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': 'ios,windows' } }) + expect(val).toEqual(ret) + }) + ) + + test('buildApp with platform as separate arguments', () => + api.buildApp(12, 'ios', 'windows').then((val) => { + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': 'ios,windows' } }) expect(val).toEqual(ret) }) ) test('buildApp without platform', () => api.buildApp(12).then((val) => { - expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build/', { }) + expect(restClient.post).lastCalledWith('https://build.phonegap.com/api/v1/apps/12/build', { 'data': { 'platforms': '' } }) expect(val).toEqual(ret) }) )