@capgo/cli 0.7.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  [tool.commitizen]
2
2
  name = "cz_conventional_commits"
3
3
  tag_format = "$major.$minor.$patch$prerelease"
4
- version = "0.7.3"
4
+ version = "0.7.4"
5
5
  version_files = [
6
6
  "package.json:version",
7
7
  ".cz.toml"
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.7.4 (2022-04-21)
2
+
3
+ ### Fix
4
+
5
+ - upload use base64 to have more portable
6
+
1
7
  ## 0.7.3 (2022-04-20)
2
8
 
3
9
  ### Fix
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=1048576,v="binary";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().toString(v),a=c;t.length>31457280&&l.program.error(`The app is too big, the limit is 30 Mb, your is ${Math.round(t.length/c)} 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:y,appid:o,fileName:s,channel:k,format:v,app:n[r],isMultipart:n.length>1,chunk:r+1,totalChunks:n.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),s=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||"")}`)}}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)})()})();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
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 = 'binary';
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;
@@ -65,11 +73,13 @@ export const uploadVersion = async (appid, options) => {
65
73
  const zip = new AdmZip();
66
74
  zip.addLocalFolder(path);
67
75
  console.log('Uploading:');
68
- const appData = zip.toBuffer().toString(formatType);
76
+ const zipped = zip.toBuffer();
77
+ const appData = zipped.toString(formatType);
69
78
  // split appData in chunks and send them sequentially with axios
70
- const chunkSize = oneMb;
71
- if (appData.length > limitMb) {
72
- program.error(`The app is too big, the limit is ${maxMb} Mb, your is ${Math.round(appData.length / oneMb)} Mb`);
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`);
73
83
  }
74
84
  const chunks = [];
75
85
  for (let i = 0; i < appData.length; i += chunkSize) {