@capgo/cli 0.7.0 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cz.toml +1 -1
- package/CHANGELOG.md +24 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/bin/upload.ts +25 -13
package/.cz.toml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 0.7.4 (2022-04-21)
|
|
2
|
+
|
|
3
|
+
### Fix
|
|
4
|
+
|
|
5
|
+
- upload use base64 to have more portable
|
|
6
|
+
|
|
7
|
+
## 0.7.3 (2022-04-20)
|
|
8
|
+
|
|
9
|
+
### Fix
|
|
10
|
+
|
|
11
|
+
- error mb limit
|
|
12
|
+
|
|
13
|
+
## 0.7.2 (2022-04-16)
|
|
14
|
+
|
|
15
|
+
### Fix
|
|
16
|
+
|
|
17
|
+
- tigger CI
|
|
18
|
+
|
|
19
|
+
## 0.7.1 (2022-04-16)
|
|
20
|
+
|
|
21
|
+
### Fix
|
|
22
|
+
|
|
23
|
+
- migrate to new npm namespace
|
|
24
|
+
|
|
1
25
|
## 0.7.0 (2022-04-08)
|
|
2
26
|
|
|
3
27
|
### Feat
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
(()=>{"use strict";var o={307:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.addApp=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(147),s=r(470),u=r(11),c=r(406);e.addApp=(o,e)=>t(void 0,void 0,void 0,(function*(){var r,t;let{name:a,icon:v}=e;const{apikey:h}=e;let f,g;try{f=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),a=a||(null===(t=null==f?void 0:f.app)||void 0===t?void 0:t.appName)||"Unknown",v=v||"resources/icon.png",h||d.program.error("Missing API key, you need to provide a API key to add your app"),o&&a||d.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${o} to Capgo`);try{console.log("Adding...");const e={appid:o,name:a};if(v&&(0,s.existsSync)(v)){const o=(0,l.readFileSync)(v),r=(0,u.getType)(v);e.icon=o.toString("base64"),e.iconType=r}g=yield(0,i.default)({method:"POST",url:`${c.host}/api/add`,data:e,validateStatus:()=>!0,headers:{authorization:h}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}g&&200===g.status||d.program.error(`Server Error \n${p.default.render(g.data)}`),console.log("App added to server, you can upload a version now")}))},755:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.deleteApp=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(406);e.deleteApp=(o,e)=>t(void 0,void 0,void 0,(function*(){var r;const{apikey:t,version:a}=e;let s,u;try{s=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==s?void 0:s.app)||void 0===r?void 0:r.appId),t||d.program.error("Missing API key, you need to provide an API key to delete your app"),o||d.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log(`Delete ${o} to Capgo`);try{console.log("Deleting..."),u=yield(0,i.default)({method:"POST",url:`${l.host}/api/delete`,data:{appid:o,version:a},validateStatus:()=>!0,headers:{authorization:t}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}u&&200===u.status||d.program.error(`Server Error \n${p.default.render(u.data)}`),console.log("App deleted to server")}))},527:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.setChannel=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(406);e.setChannel=(o,e)=>t(void 0,void 0,void 0,(function*(){var r;const{apikey:t,version:a,state:s,channel:u="dev"}=e;let c,v,h;try{c=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==c?void 0:c.app)||void 0===r?void 0:r.appId),"public"!==s&&"private"!==s||(h="public"===s),t||d.program.error("Missing API key, you need to provide a API key to add your app"),o||d.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),a||h||d.program.error("Missing argument, you need to provide a state or a version"),a?console.log(`Set ${u} to @${a} in ${o}`):console.log(`Set${u} to @${s} in ${o}`);try{v=yield(0,i.default)({method:"POST",url:`${l.host}/api/channel`,data:{version:a,public:h,appid:o,channel:u},validateStatus:()=>!0,headers:{authorization:t}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}v&&200===v.status||d.program.error(`Server Error \n${p.default.render(v.data)}`),a?console.log("Done ✅"):console.log(`You can use now is channel in your app with the url: ${l.host}/api/latest?appid=${o}&channel=${u}`)}))},571:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.uploadVersion=void 0;const n=r(778),i=a(r(844)),p=a(r(167)),d=a(r(867)),l=r(304),s=a(r(295)),u=r(406),c="binary";e.uploadVersion=(o,e)=>t(void 0,void 0,void 0,(function*(){var r,t,a,v,h,f;let{version:g,path:y,channel:m}=e;const{apikey:k,external:w}=e;let _;m=m||"dev";try{_=yield(0,n.loadConfig)()}catch(o){l.program.error("No capacitor config file found, run `cap init` first")}if(o=o||(null===(r=null==_?void 0:_.app)||void 0===r?void 0:r.appId),g=g||(null===(a=null===(t=null==_?void 0:_.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version),y=y||(null===(v=null==_?void 0:_.app)||void 0===v?void 0:v.webDir),k||l.program.error("Missing API key, you need to provide a API key to add your app"),o&&g&&y||l.program.error("Missing argument, you need to provide a appid and a version and a path, or be in a capacitor project"),console.log(`Upload ${o}@${g} started from path "${y}" to Capgo cloud`),w)try{const e=yield(0,p.default)({method:"POST",url:u.hostUpload,data:{version:g,appid:o,channel:m,external:w},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:k,authorization:`Bearer ${u.supaAnon}`}});200!==e.status&&l.program.error(`Server Error \n${d.default.render((null==e?void 0:e.data)||"")}`)}catch(o){o.response?l.program.error(`Network Error \n${d.default.render((null===(h=o.response)||void 0===h?void 0:h.data)||"")}`):l.program.error(`Network Error \n${d.default.render(o||"")}`)}else{const e=new s.default.SingleBar({},s.default.Presets.shades_grey);try{const r=new i.default;r.addLocalFolder(y),console.log("Uploading:");const t=r.toBuffer().toString(c),a=1048576;t.length>31457280&&l.program.error("The app is too big, the limit is 30 Mb");const n=[];for(let o=0;o<t.length;o+=a)n.push(t.slice(o,o+a));let s;e.start(n.length,0,{speed:"N/A"});for(let r=0;r<n.length;r+=1){const t=yield(0,p.default)({method:"POST",url:u.hostUpload,data:{version:g,appid:o,fileName:s,channel:m,format:c,app:n[r],isMultipart:n.length>1,chunk:r+1,totalChunks:n.length},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:k,authorization:`Bearer ${u.supaAnon}`}});200!==t.status&&(e.stop(),l.program.error(`Server Error \n${d.default.render((null==t?void 0:t.data)||"")}`)),e.update(r+1),s=t.data.fileName}e.stop()}catch(o){e.stop(),o.response?l.program.error(`Network Error \n${d.default.render((null===(f=o.response)||void 0===f?void 0:f.data)||"")}`):l.program.error(`Network Error \n${d.default.render(o||"")}`)}}console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${m} as public here: ${u.hostWeb}/app/package/${o}`),console.log("To use with live update in your own app")}))},406:(o,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.supaAnon=e.hostUpload=e.hostWeb=e.host=void 0,e.host="https://capgo.app",e.hostWeb="https://web.capgo.app",e.hostUpload="https://xvwzpoazmxkqosrdewyv.functions.supabase.co/upload",e.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w"},778:o=>{o.exports=require("@capacitor/cli/dist/config")},844:o=>{o.exports=require("adm-zip")},167:o=>{o.exports=require("axios")},295:o=>{o.exports=require("cli-progress")},304:o=>{o.exports=require("commander")},470:o=>{o.exports=require("fs-extra")},11:o=>{o.exports=require("mime")},867:o=>{o.exports=require("prettyjson")},147:o=>{o.exports=require("fs")}},e={};function r(t){var a=e[t];if(void 0!==a)return a.exports;var n=e[t]={exports:{}};return o[t].call(n.exports,n,n.exports,r),n.exports}(()=>{const o=r(304),e=r(307),t=r(755),a=r(527),n=r(571);o.program.command("add [appid]").alias("a").action(e.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),o.program.command("upload [appid]").alias("u").action(n.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file to upload").option("-c, --channel <channel>","channel to link to").option("-e, --externa <url>","link to external url intead of upload to capgo cloud").option("-v, --version <version>","version number of the file to upload"),o.program.command("set [appid]").alias("s").action(a.setChannel).option("-c, --channel <channel>","channel to link to").option("-v, --version <version>","version number of the file to upload").option("-s, --state <state>","set the state of the channel, public or private").option("-a, --apikey <apikey>","apikey to link to your account"),o.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("a").action(t.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-v, --version <version>","version number of the app to delete"),o.program.parse(process.argv)})()})();
|
|
2
|
+
(()=>{"use strict";var o={307:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.addApp=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(147),s=r(470),u=r(11),c=r(406);e.addApp=(o,e)=>t(void 0,void 0,void 0,(function*(){var r,t;let{name:a,icon:v}=e;const{apikey:h}=e;let f,g;try{f=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),a=a||(null===(t=null==f?void 0:f.app)||void 0===t?void 0:t.appName)||"Unknown",v=v||"resources/icon.png",h||d.program.error("Missing API key, you need to provide a API key to add your app"),o&&a||d.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${o} to Capgo`);try{console.log("Adding...");const e={appid:o,name:a};if(v&&(0,s.existsSync)(v)){const o=(0,l.readFileSync)(v),r=(0,u.getType)(v);e.icon=o.toString("base64"),e.iconType=r}g=yield(0,i.default)({method:"POST",url:`${c.host}/api/add`,data:e,validateStatus:()=>!0,headers:{authorization:h}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}g&&200===g.status||d.program.error(`Server Error \n${p.default.render(g.data)}`),console.log("App added to server, you can upload a version now")}))},755:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.deleteApp=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(406);e.deleteApp=(o,e)=>t(void 0,void 0,void 0,(function*(){var r;const{apikey:t,version:a}=e;let s,u;try{s=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==s?void 0:s.app)||void 0===r?void 0:r.appId),t||d.program.error("Missing API key, you need to provide an API key to delete your app"),o||d.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log(`Delete ${o} to Capgo`);try{console.log("Deleting..."),u=yield(0,i.default)({method:"POST",url:`${l.host}/api/delete`,data:{appid:o,version:a},validateStatus:()=>!0,headers:{authorization:t}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}u&&200===u.status||d.program.error(`Server Error \n${p.default.render(u.data)}`),console.log("App deleted to server")}))},527:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.setChannel=void 0;const n=r(778),i=a(r(167)),p=a(r(867)),d=r(304),l=r(406);e.setChannel=(o,e)=>t(void 0,void 0,void 0,(function*(){var r;const{apikey:t,version:a,state:s,channel:u="dev"}=e;let c,v,h;try{c=yield(0,n.loadConfig)()}catch(o){d.program.error("No capacitor config file found, run `cap init` first")}o=o||(null===(r=null==c?void 0:c.app)||void 0===r?void 0:r.appId),"public"!==s&&"private"!==s||(h="public"===s),t||d.program.error("Missing API key, you need to provide a API key to add your app"),o||d.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),a||h||d.program.error("Missing argument, you need to provide a state or a version"),a?console.log(`Set ${u} to @${a} in ${o}`):console.log(`Set${u} to @${s} in ${o}`);try{v=yield(0,i.default)({method:"POST",url:`${l.host}/api/channel`,data:{version:a,public:h,appid:o,channel:u},validateStatus:()=>!0,headers:{authorization:t}})}catch(o){d.program.error(`Network Error \n${p.default.render(o.response.data)}`)}v&&200===v.status||d.program.error(`Server Error \n${p.default.render(v.data)}`),a?console.log("Done ✅"):console.log(`You can use now is channel in your app with the url: ${l.host}/api/latest?appid=${o}&channel=${u}`)}))},571:function(o,e,r){var t=this&&this.__awaiter||function(o,e,r,t){return new(r||(r=Promise))((function(a,n){function i(o){try{d(t.next(o))}catch(o){n(o)}}function p(o){try{d(t.throw(o))}catch(o){n(o)}}function d(o){var e;o.done?a(o.value):(e=o.value,e instanceof r?e:new r((function(o){o(e)}))).then(i,p)}d((t=t.apply(o,e||[])).next())}))},a=this&&this.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(e,"__esModule",{value:!0}),e.uploadVersion=void 0;const n=r(778),i=a(r(844)),p=a(r(167)),d=a(r(867)),l=r(304),s=a(r(295)),u=r(406),c=1048576,v="base64";e.uploadVersion=(o,e)=>t(void 0,void 0,void 0,(function*(){var r,t,a,h,f,g;let{version:y,path:m,channel:k}=e;const{apikey:w,external:_}=e;let $;k=k||"dev";try{$=yield(0,n.loadConfig)()}catch(o){l.program.error("No capacitor config file found, run `cap init` first")}if(o=o||(null===(r=null==$?void 0:$.app)||void 0===r?void 0:r.appId),y=y||(null===(a=null===(t=null==$?void 0:$.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version),m=m||(null===(h=null==$?void 0:$.app)||void 0===h?void 0:h.webDir),w||l.program.error("Missing API key, you need to provide a API key to add your app"),o&&y&&m||l.program.error("Missing argument, you need to provide a appid and a version and a path, or be in a capacitor project"),console.log(`Upload ${o}@${y} started from path "${m}" to Capgo cloud`),_)try{const e=yield(0,p.default)({method:"POST",url:u.hostUpload,data:{version:y,appid:o,channel:k,external:_},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:w,authorization:`Bearer ${u.supaAnon}`}});200!==e.status&&l.program.error(`Server Error \n${d.default.render((null==e?void 0:e.data)||"")}`)}catch(o){o.response?l.program.error(`Network Error \n${d.default.render((null===(f=o.response)||void 0===f?void 0:f.data)||"")}`):l.program.error(`Network Error \n${d.default.render(o||"")}`)}else{const e=new s.default.SingleBar({},s.default.Presets.shades_grey);try{const r=new i.default;r.addLocalFolder(m),console.log("Uploading:");const t=r.toBuffer(),a=t.toString(v),n=Buffer.byteLength(t),s=(b=t.length,x=c,Math.round(b/((o,e)=>o<e?o:Math.round(o/e))(b,x)));n>31457280&&l.program.error(`The app is too big, the limit is 30 Mb, your is ${Math.round(n/c)} Mb`);const h=[];for(let o=0;o<a.length;o+=s)h.push(a.slice(o,o+s));let f;e.start(h.length,0,{speed:"N/A"});for(let r=0;r<h.length;r+=1){const t=yield(0,p.default)({method:"POST",url:u.hostUpload,data:{version:y,appid:o,fileName:f,channel:k,format:v,app:h[r],isMultipart:h.length>1,chunk:r+1,totalChunks:h.length},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:w,authorization:`Bearer ${u.supaAnon}`}});200!==t.status&&(e.stop(),l.program.error(`Server Error \n${d.default.render((null==t?void 0:t.data)||"")}`)),e.update(r+1),f=t.data.fileName}e.stop()}catch(o){e.stop(),o.response?l.program.error(`Network Error \n${d.default.render((null===(g=o.response)||void 0===g?void 0:g.data)||"")}`):l.program.error(`Network Error \n${d.default.render(o||"")}`)}}var b,x;console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${k} as public here: ${u.hostWeb}/app/package/${o}`),console.log("To use with live update in your own app")}))},406:(o,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.supaAnon=e.hostUpload=e.hostWeb=e.host=void 0,e.host="https://capgo.app",e.hostWeb="https://web.capgo.app",e.hostUpload="https://xvwzpoazmxkqosrdewyv.functions.supabase.co/upload",e.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w"},778:o=>{o.exports=require("@capacitor/cli/dist/config")},844:o=>{o.exports=require("adm-zip")},167:o=>{o.exports=require("axios")},295:o=>{o.exports=require("cli-progress")},304:o=>{o.exports=require("commander")},470:o=>{o.exports=require("fs-extra")},11:o=>{o.exports=require("mime")},867:o=>{o.exports=require("prettyjson")},147:o=>{o.exports=require("fs")}},e={};function r(t){var a=e[t];if(void 0!==a)return a.exports;var n=e[t]={exports:{}};return o[t].call(n.exports,n,n.exports,r),n.exports}(()=>{const o=r(304),e=r(307),t=r(755),a=r(527),n=r(571);o.program.command("add [appid]").alias("a").action(e.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),o.program.command("upload [appid]").alias("u").action(n.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file to upload").option("-c, --channel <channel>","channel to link to").option("-e, --externa <url>","link to external url intead of upload to capgo cloud").option("-v, --version <version>","version number of the file to upload"),o.program.command("set [appid]").alias("s").action(a.setChannel).option("-c, --channel <channel>","channel to link to").option("-v, --version <version>","version number of the file to upload").option("-s, --state <state>","set the state of the channel, public or private").option("-a, --apikey <apikey>","apikey to link to your account"),o.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("a").action(t.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-v, --version <version>","version number of the app to delete"),o.program.parse(process.argv)})()})();
|
package/package.json
CHANGED
package/src/bin/upload.ts
CHANGED
|
@@ -6,10 +6,18 @@ import { program } from 'commander';
|
|
|
6
6
|
import cliProgress from 'cli-progress';
|
|
7
7
|
import { host, hostWeb, hostUpload, supaAnon } from './utils';
|
|
8
8
|
|
|
9
|
-
const oneMb = 1048576; // size of one mb
|
|
9
|
+
const oneMb = 1048576; // size of one mb in bytes
|
|
10
10
|
const maxMb = 30;
|
|
11
11
|
const limitMb = oneMb * maxMb; // size of 1/2 mb
|
|
12
|
-
const formatType = '
|
|
12
|
+
const formatType = 'base64';
|
|
13
|
+
const byteConvert = {
|
|
14
|
+
'base64': (s: string) => (3 * (s.length / 4)) - ((s.match(/=/g) || []).length),
|
|
15
|
+
'hex': (s: string) => s.length / 2,
|
|
16
|
+
'binary': (s: string) => s.length / 10,
|
|
17
|
+
'utf8': (s: string) => s.length,
|
|
18
|
+
}
|
|
19
|
+
const chuckNumber = (l: number, divider: number) => l < divider ? l : Math.round(l / divider)
|
|
20
|
+
const chuckSize = (l: number, divider: number) => Math.round(l / chuckNumber(l, divider))
|
|
13
21
|
|
|
14
22
|
export const uploadVersion = async (appid, options) => {
|
|
15
23
|
let { version, path, channel } = options;
|
|
@@ -27,7 +35,7 @@ export const uploadVersion = async (appid, options) => {
|
|
|
27
35
|
if (!apikey) {
|
|
28
36
|
program.error("Missing API key, you need to provide a API key to add your app");
|
|
29
37
|
}
|
|
30
|
-
if(!appid || !version || !path) {
|
|
38
|
+
if (!appid || !version || !path) {
|
|
31
39
|
program.error("Missing argument, you need to provide a appid and a version and a path, or be in a capacitor project");
|
|
32
40
|
}
|
|
33
41
|
console.log(`Upload ${appid}@${version} started from path "${path}" to Capgo cloud`);
|
|
@@ -46,8 +54,9 @@ export const uploadVersion = async (appid, options) => {
|
|
|
46
54
|
headers: {
|
|
47
55
|
'Content-Type': 'application/json',
|
|
48
56
|
'apikey': apikey,
|
|
49
|
-
authorization
|
|
50
|
-
}
|
|
57
|
+
authorization: `Bearer ${supaAnon}`
|
|
58
|
+
}
|
|
59
|
+
})
|
|
51
60
|
if (res.status !== 200) {
|
|
52
61
|
program.error(`Server Error \n${prettyjson.render(res?.data || "")}`);
|
|
53
62
|
}
|
|
@@ -64,11 +73,13 @@ export const uploadVersion = async (appid, options) => {
|
|
|
64
73
|
const zip = new AdmZip();
|
|
65
74
|
zip.addLocalFolder(path);
|
|
66
75
|
console.log('Uploading:');
|
|
67
|
-
const
|
|
76
|
+
const zipped = zip.toBuffer();
|
|
77
|
+
const appData = zipped.toString(formatType);
|
|
68
78
|
// split appData in chunks and send them sequentially with axios
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
const zippedSize = Buffer.byteLength(zipped);
|
|
80
|
+
const chunkSize = chuckSize(zipped.length, oneMb);
|
|
81
|
+
if (zippedSize > limitMb) {
|
|
82
|
+
program.error(`The app is too big, the limit is ${maxMb} Mb, your is ${Math.round(zippedSize / oneMb)} Mb`);
|
|
72
83
|
}
|
|
73
84
|
const chunks = [];
|
|
74
85
|
for (let i = 0; i < appData.length; i += chunkSize) {
|
|
@@ -78,7 +89,7 @@ export const uploadVersion = async (appid, options) => {
|
|
|
78
89
|
speed: "N/A"
|
|
79
90
|
});
|
|
80
91
|
let fileName
|
|
81
|
-
for (let i = 0; i < chunks.length; i +=1) {
|
|
92
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
82
93
|
const res = await axios({
|
|
83
94
|
method: 'POST',
|
|
84
95
|
url: hostUpload,
|
|
@@ -97,13 +108,14 @@ export const uploadVersion = async (appid, options) => {
|
|
|
97
108
|
headers: {
|
|
98
109
|
'Content-Type': 'application/json',
|
|
99
110
|
'apikey': apikey,
|
|
100
|
-
authorization
|
|
101
|
-
}
|
|
111
|
+
authorization: `Bearer ${supaAnon}`
|
|
112
|
+
}
|
|
113
|
+
})
|
|
102
114
|
if (res.status !== 200) {
|
|
103
115
|
b1.stop();
|
|
104
116
|
program.error(`Server Error \n${prettyjson.render(res?.data || "")}`);
|
|
105
117
|
}
|
|
106
|
-
b1.update(i+1)
|
|
118
|
+
b1.update(i + 1)
|
|
107
119
|
fileName = res.data.fileName
|
|
108
120
|
}
|
|
109
121
|
b1.stop();
|