@capgo/cli 0.8.2 → 0.8.6

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.8.2"
4
+ version = "0.8.6"
5
5
  version_files = [
6
6
  "package.json:version",
7
7
  ".cz.toml"
package/.eslintrc CHANGED
@@ -11,6 +11,8 @@
11
11
  }
12
12
  },
13
13
  "rules": {
14
+ "no-shadow": "off",
15
+ "@typescript-eslint/no-shadow": ["error"],
14
16
  "import/prefer-default-export": 0,
15
17
  "no-param-reassign": 0,
16
18
  "import/no-extraneous-dependencies": [
package/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## 0.8.6 (2022-05-11)
2
+
3
+ ### Fix
4
+
5
+ - typo
6
+
7
+ ## 0.8.5 (2022-05-11)
8
+
9
+ ### Fix
10
+
11
+ - lint issue
12
+
13
+ ## 0.8.4 (2022-05-11)
14
+
15
+ ### Fix
16
+
17
+ - issue for app less than 1mb
18
+
19
+ ## 0.8.3 (2022-05-05)
20
+
21
+ ### Fix
22
+
23
+ - remove debug comments
24
+ - build and add auto retry
25
+
1
26
  ## 0.8.2 (2022-04-29)
2
27
 
3
28
  ### Fix
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={307:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),d=t(147),l=t(470),c=t(11),u=t(406);o.addApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r;let{name:a,icon:v}=o;const{apikey:f}=o;let h,g;try{h=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.appId),a=a||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.appName)||"Unknown",v=v||"resources/icon.png",f||s.program.error("Missing API key, you need to provide a API key to add your app"),e&&a||s.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);try{console.log("Adding...");const o={appid:e,name:a};if(v&&(0,l.existsSync)(v)){const e=(0,d.readFileSync)(v),t=(0,c.getType)(v);o.icon=e.toString("base64"),o.iconType=t}g=yield(0,i.default)({method:"POST",url:`${u.host}/api/add`,data:o,validateStatus:()=>!0,headers:{authorization:f}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}g&&200===g.status||s.program.error(`Server Error \n${p.default.render(g.data)}`),console.log("App added to server, you can upload a version now")}))},755:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),d=t(406);o.deleteApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t;const{apikey:r,version:a}=o;let l,c;try{l=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==l?void 0:l.app)||void 0===t?void 0:t.appId),r||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log(`Delete ${e} to Capgo`);try{console.log("Deleting..."),c=yield(0,i.default)({method:"POST",url:`${d.host}/api/delete`,data:{appid:e,version:a},validateStatus:()=>!0,headers:{authorization:r}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}c&&200===c.status||s.program.error(`Server Error \n${p.default.render(c.data)}`),console.log("App deleted to server")}))},655:function(e,o,t){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const a=t(304),n=t(307),i=t(755),p=t(527),s=t(571),d=r(t(598));a.program.version(d.default.version).command("add [appid]").alias("a").action(n.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),a.program.command("upload [appid]").alias("u").action(s.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, --external <url>","link to external url intead of upload to capgo cloud").option("-v, --version <version>","version number of the file to upload"),a.program.command("set [appid]").alias("s").action(p.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"),a.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("a").action(i.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-v, --version <version>","version number of the app to delete"),a.program.parse(process.argv)},527:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),d=t(406);o.setChannel=(e,o)=>r(void 0,void 0,void 0,(function*(){var t;const{apikey:r,version:a,state:l,channel:c="dev"}=o;let u,v,f;try{u=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==u?void 0:u.app)||void 0===t?void 0:t.appId),"public"!==l&&"private"!==l||(f="public"===l),r||s.program.error("Missing API key, you need to provide a API key to add your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),a||f||s.program.error("Missing argument, you need to provide a state or a version"),a?console.log(`Set ${c} to @${a} in ${e}`):console.log(`Set${c} to @${l} in ${e}`);try{v=yield(0,i.default)({method:"POST",url:`${d.host}/api/channel`,data:{version:a,public:f,appid:e,channel:c},validateStatus:()=>!0,headers:{authorization:r}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}v&&200===v.status||s.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: ${d.host}/api/latest?appid=${e}&channel=${c}`)}))},571:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const n=t(778),i=a(t(844)),p=a(t(167)),s=a(t(867)),d=t(304),l=a(t(295)),c=t(406),u=1048576,v="binary";o.uploadVersion=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r,a,f,h,g;let{version:y,path:m,channel:k}=o;const{apikey:b,external:w}=o;let x;k=k||"dev";try{x=yield(0,n.loadConfig)()}catch(e){d.program.error("No capacitor config file found, run `cap init` first")}if(e=e||(null===(t=null==x?void 0:x.app)||void 0===t?void 0:t.appId),y=y||(null===(a=null===(r=null==x?void 0:x.app)||void 0===r?void 0:r.package)||void 0===a?void 0:a.version),m=m||(null===(f=null==x?void 0:x.app)||void 0===f?void 0:f.webDir),b||d.program.error("Missing API key, you need to provide a API key to add your app"),e&&y&&m||d.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 ${e}@${y} started from path "${m}" to Capgo cloud`),w)try{const o=yield(0,p.default)({method:"POST",url:c.hostUpload,data:{version:y,appid:e,channel:k,external:w},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:b,authorization:`Bearer ${c.supaAnon}`}});200!==o.status&&d.program.error(`Server Error \n${s.default.render((null==o?void 0:o.data)||"")}`)}catch(e){e.response?d.program.error(`Network Error \n${s.default.render((null===(h=e.response)||void 0===h?void 0:h.data)||"")}`):d.program.error(`Network Error \n${s.default.render(e||"")}`)}else{const o=new l.default.SingleBar({},l.default.Presets.shades_grey);try{const t=new i.default;t.addLocalFolder(m),console.log("Uploading:");const r=t.toBuffer(),a=r.toString(v),n=Buffer.byteLength(r),l=(_=r.length,$=u,Math.round(_/((e,o)=>e<o?e:Math.round(e/o))(_,$)));n>31457280&&d.program.error(`The app is too big, the limit is 30 Mb, your is ${Math.round(n/u)} Mb`);const f=[];for(let e=0;e<a.length;e+=l)f.push(a.slice(e,e+l));let h;o.start(f.length,0,{speed:"N/A"});for(let t=0;t<f.length;t+=1){const r=yield(0,p.default)({method:"POST",url:c.hostUpload,data:{version:y,appid:e,fileName:h,channel:k,format:v,app:f[t],isMultipart:f.length>1,chunk:t+1,totalChunks:f.length},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:b,authorization:`Bearer ${c.supaAnon}`}});200!==r.status&&(o.stop(),d.program.error(`Server Error \n${s.default.render((null==r?void 0:r.data)||"")}`)),o.update(t+1),h=r.data.fileName}o.stop()}catch(e){o.stop(),e.response?d.program.error(`Network Error \n${s.default.render((null===(g=e.response)||void 0===g?void 0:g.data)||"")}`):d.program.error(`Network Error \n${s.default.render(e||"")}`)}}var _,$;console.log("App uploaded to server"),console.log(`Try it in mobile app: ${c.host}/app_mobile`),console.log(`Or set the channel ${k} as public here: ${c.hostWeb}/app/package/${e}`),console.log("To use with live update in your own app")}))},406:(e,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.supaAnon=o.hostUpload=o.hostWeb=o.host=void 0,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostUpload="https://xvwzpoazmxkqosrdewyv.functions.supabase.co/upload",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w"},778:e=>{e.exports=require("@capacitor/cli/dist/config")},844:e=>{e.exports=require("adm-zip")},167:e=>{e.exports=require("axios")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},147:e=>{e.exports=require("fs")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"0.8.2","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development&& npx webpack --config webpack.config.js","no-debug":"node dist/index.js","build":"set NODE_ENV=production&& npx webpack --config webpack.config.js","pack":"pkg","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"^3.4.3","adm-zip":"^0.5.9","axios":"^0.26.1","cli-progress":"^3.10.0","commander":"^9.0.0","form-data":"^4.0.0","fs-extra":"^10.0.1","mime":"^3.0.0","node-stream-zip":"^1.15.0","prettyjson":"^1.2.5","upath":"^2.0.1"},"devDependencies":{"@types/adm-zip":"^0.4.34","@types/fs-extra":"^9.0.13","@typescript-eslint/eslint-plugin":"5.14.0","@typescript-eslint/parser":"^5.14.0","awesome-typescript-loader":"^5.2.1","eslint":"^8.11.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"^2.5.0","eslint-plugin-import":"^2.25.4","eslint-plugin-prettier":"^4.0.0","git-format-staged":"^2.1.3","husky":"^7.0.4","nodemon":"^2.0.15","pkg":"^5.5.2","prettier":"^2.5.1","ts-node":"^10.7.0","tsconfig-paths":"^3.14.0","typescript":"^4.6.2","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"}}')}},o={};!function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r].call(n.exports,n,n.exports,t),n.exports}(655)})();
2
+ (()=>{"use strict";var e={548:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),l=t(147),d=t(470),c=t(11),u=t(233);o.addApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r;let{name:a,icon:f}=o;const{apikey:h}=o;let v,g;try{v=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==v?void 0:v.app)||void 0===t?void 0:t.appId),a=a||(null===(r=null==v?void 0:v.app)||void 0===r?void 0:r.appName)||"Unknown",f=f||"resources/icon.png",h||s.program.error("Missing API key, you need to provide a API key to add your app"),e&&a||s.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);try{console.log("Adding...");const o={appid:e,name:a};if(f&&(0,d.existsSync)(f)){const e=(0,l.readFileSync)(f),t=(0,c.getType)(f);o.icon=e.toString("base64"),o.iconType=t}g=yield(0,i.default)({method:"POST",url:`${u.host}/api/add`,data:o,validateStatus:()=>!0,headers:{authorization:h}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}g&&200===g.status||s.program.error(`Server Error \n${p.default.render(g.data)}`),console.log("App added to server, you can upload a version now")}))},453:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),l=t(233);o.deleteApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t;const{apikey:r,version:a}=o;let d,c;try{d=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),r||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log(`Delete ${e} to Capgo`);try{console.log("Deleting..."),c=yield(0,i.default)({method:"POST",url:`${l.host}/api/delete`,data:{appid:e,version:a},validateStatus:()=>!0,headers:{authorization:r}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}c&&200===c.status||s.program.error(`Server Error \n${p.default.render(c.data)}`),console.log("App deleted to server")}))},473:function(e,o,t){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const a=t(304),n=t(548),i=t(453),p=t(666),s=t(310),l=r(t(598));a.program.version(l.default.version).command("add [appid]").alias("a").action(n.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),a.program.command("upload [appid]").alias("u").action(s.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, --external <url>","link to external url intead of upload to capgo cloud").option("-f, --format <base64|hex|binary|utf8>","choose the upload format default base64").option("-v, --version <version>","version number of the file to upload"),a.program.command("set [appid]").alias("s").action(p.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"),a.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("a").action(i.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-v, --version <version>","version number of the app to delete"),a.program.parse(process.argv)},666:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const n=t(778),i=a(t(167)),p=a(t(867)),s=t(304),l=t(233);o.setChannel=(e,o)=>r(void 0,void 0,void 0,(function*(){var t;const{apikey:r,version:a,state:d,channel:c="dev"}=o;let u,f,h;try{u=yield(0,n.loadConfig)()}catch(e){s.program.error("No capacitor config file found, run `cap init` first")}e=e||(null===(t=null==u?void 0:u.app)||void 0===t?void 0:t.appId),"public"!==d&&"private"!==d||(h="public"===d),r||s.program.error("Missing API key, you need to provide a API key to add your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),a||h||s.program.error("Missing argument, you need to provide a state or a version"),a?console.log(`Set ${c} to @${a} in ${e}`):console.log(`Set${c} to @${d} in ${e}`);try{f=yield(0,i.default)({method:"POST",url:`${l.host}/api/channel`,data:{version:a,public:h,appid:e,channel:c},validateStatus:()=>!0,headers:{authorization:r}})}catch(e){s.program.error(`Network Error \n${p.default.render(e.response.data)}`)}f&&200===f.status||s.program.error(`Server Error \n${p.default.render(f.data)}`),a?console.log("Done ✅"):console.log(`You can use now is channel in your app with the url: ${l.host}/api/latest?appid=${e}&channel=${c}`)}))},310:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(a,n){function i(e){try{s(r.next(e))}catch(e){n(e)}}function p(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,p)}s((r=r.apply(e,o||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const n=t(778),i=a(t(844)),p=a(t(167)),s=a(t(867)),l=t(304),d=a(t(295)),c=a(t(188)),u=t(233);(0,c.default)(p.default,{retries:3,retryDelay:c.default.exponentialDelay});const f=1048576;var h;!function(e){e.uft8="utf8",e.base64="base64",e.hex="hex",e.binary="binary"}(h||(h={}));const v=h.binary,g=(e,o)=>e<o?1:Math.floor(e/o),y={base64:e=>Math.floor(4*e/3),hex:e=>Math.floor(2*e),binary:e=>e,utf8:e=>e},m=(e,o)=>r(void 0,void 0,void 0,(function*(){return yield(0,p.default)({method:"POST",url:u.hostUpload,data:e,validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:o,authorization:`Bearer ${u.supaAnon}`}})}));o.uploadVersion=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r,a,c,b,k;let{version:x,path:w,channel:_}=o;const{apikey:$,external:M,format:A}=o;let I;_=_||"dev";let N=v;A in h&&(N=A);try{I=yield(0,n.loadConfig)()}catch(e){l.program.error("No capacitor config file found, run `cap init` first")}if(e=e||(null===(t=null==I?void 0:I.app)||void 0===t?void 0:t.appId),x=x||(null===(a=null===(r=null==I?void 0:I.app)||void 0===r?void 0:r.package)||void 0===a?void 0:a.version),w=w||(null===(c=null==I?void 0:I.app)||void 0===c?void 0:c.webDir),$||l.program.error("Missing API key, you need to provide a API key to add your app"),e&&x&&w||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 ${e}@${x} started from path "${w}" to Capgo cloud`),M)try{const o=yield(0,p.default)({method:"POST",url:u.hostUpload,data:{version:x,appid:e,channel:_,external:M},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:$,authorization:`Bearer ${u.supaAnon}`}});200!==o.status&&l.program.error(`Server Error \n${s.default.render((null==o?void 0:o.data)||"")}`)}catch(e){e.response?l.program.error(`Network Error \n${s.default.render((null===(b=e.response)||void 0===b?void 0:b.data)||"")}`):l.program.error(`Network Error \n${s.default.render(e||"")}`)}else{const o=new d.default.SingleBar({format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Mb"},d.default.Presets.shades_grey);try{const t=new i.default;t.addLocalFolder(w);const r=t.toBuffer().toString(N),a=r.length,n=Math.floor(a/y[N](f)),p=g(a,y[N](f))>1?(P=a,S=y[N](f),Math.floor(P/g(P,S))):a;n>30&&l.program.error(`The app is too big, the limit is 30 Mb, your is ${n} Mb`),n>25&&console.log(`WARNING !!\nThe app size is ${n} Mb, the limit is 30 Mb`);const d=[];for(let e=0;e<r.length;e+=p)d.push(r.slice(e,e+p));let c;o.start(d.length,0,{speed:"N/A"});for(let t=0;t<d.length;t+=1){const r=yield m({version:x,appid:e,fileName:c,channel:_,format:N,app:d[t],isMultipart:d.length>1,chunk:t+1,totalChunks:d.length},$);200!==r.status&&(o.stop(),l.program.error(`Server Error \n${s.default.render((null==r?void 0:r.data)||"")}`)),o.update(t+1),c=r.data.fileName}o.stop()}catch(e){o.stop(),e.response?l.program.error(`Network Error \n${s.default.render((null===(k=e.response)||void 0===k?void 0:k.data)||"")}`):l.program.error(`Network Error \n${s.default.render(e||"")}`)}}var P,S;console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${_} as public here: ${u.hostWeb}/app/package/${e}`),console.log("To use with live update in your own app")}))},233:(e,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.supaAnon=o.hostUpload=o.hostWeb=o.host=void 0,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostUpload="https://xvwzpoazmxkqosrdewyv.functions.supabase.co/upload",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w"},778:e=>{e.exports=require("@capacitor/cli/dist/config")},844:e=>{e.exports=require("adm-zip")},167:e=>{e.exports=require("axios")},188:e=>{e.exports=require("axios-retry")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},147:e=>{e.exports=require("fs")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"0.8.6","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development&& npx webpack --config webpack.config.js","no-debug":"node dist/index.js","build":"set NODE_ENV=production&& npx webpack --config webpack.config.js","pack":"pkg","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"3.5.1","adm-zip":"^0.5.9","axios":"0.27.2","axios-retry":"^3.2.5","cli-progress":"3.11.0","commander":"9.2.0","form-data":"^4.0.0","fs-extra":"10.1.0","mime":"^3.0.0","node-stream-zip":"^1.15.0","prettyjson":"^1.2.5","upath":"^2.0.1"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^9.0.13","@types/node":"^17.0.31","@typescript-eslint/eslint-plugin":"5.22.0","@typescript-eslint/parser":"5.22.0","eslint":"8.14.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"2.7.1","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.0.0","git-format-staged":"3.0.0","husky":"^7.0.4","nodemon":"2.0.16","pkg":"5.6.0","prettier":"2.6.2","ts-loader":"^9.3.0","ts-node":"^10.7.0","tsconfig-paths":"4.0.0","typescript":"4.6.4","webpack":"5.72.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"}}')}},o={};!function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r].call(n.exports,n,n.exports,t),n.exports}(473)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "0.8.2",
3
+ "version": "0.8.6",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -34,39 +34,41 @@
34
34
  "author": "github.com/riderx",
35
35
  "license": "Apache 2.0",
36
36
  "dependencies": {
37
- "@capacitor/cli": "^3.4.3",
37
+ "@capacitor/cli": "3.5.1",
38
38
  "adm-zip": "^0.5.9",
39
- "axios": "^0.26.1",
40
- "cli-progress": "^3.10.0",
41
- "commander": "^9.0.0",
39
+ "axios": "0.27.2",
40
+ "axios-retry": "^3.2.5",
41
+ "cli-progress": "3.11.0",
42
+ "commander": "9.2.0",
42
43
  "form-data": "^4.0.0",
43
- "fs-extra": "^10.0.1",
44
+ "fs-extra": "10.1.0",
44
45
  "mime": "^3.0.0",
45
46
  "node-stream-zip": "^1.15.0",
46
47
  "prettyjson": "^1.2.5",
47
48
  "upath": "^2.0.1"
48
49
  },
49
50
  "devDependencies": {
50
- "@types/adm-zip": "^0.4.34",
51
+ "@types/adm-zip": "0.5.0",
51
52
  "@types/fs-extra": "^9.0.13",
52
- "@typescript-eslint/eslint-plugin": "5.14.0",
53
- "@typescript-eslint/parser": "^5.14.0",
54
- "awesome-typescript-loader": "^5.2.1",
55
- "eslint": "^8.11.0",
53
+ "@types/node": "^17.0.31",
54
+ "@typescript-eslint/eslint-plugin": "5.22.0",
55
+ "@typescript-eslint/parser": "5.22.0",
56
+ "eslint": "8.14.0",
56
57
  "eslint-config-airbnb-base": "^15.0.0",
57
58
  "eslint-config-prettier": "^8.5.0",
58
- "eslint-import-resolver-typescript": "^2.5.0",
59
- "eslint-plugin-import": "^2.25.4",
59
+ "eslint-import-resolver-typescript": "2.7.1",
60
+ "eslint-plugin-import": "2.26.0",
60
61
  "eslint-plugin-prettier": "^4.0.0",
61
- "git-format-staged": "^2.1.3",
62
+ "git-format-staged": "3.0.0",
62
63
  "husky": "^7.0.4",
63
- "nodemon": "^2.0.15",
64
- "pkg": "^5.5.2",
65
- "prettier": "^2.5.1",
64
+ "nodemon": "2.0.16",
65
+ "pkg": "5.6.0",
66
+ "prettier": "2.6.2",
67
+ "ts-loader": "^9.3.0",
66
68
  "ts-node": "^10.7.0",
67
- "tsconfig-paths": "^3.14.0",
68
- "typescript": "^4.6.2",
69
- "webpack": "^5.70.0",
69
+ "tsconfig-paths": "4.0.0",
70
+ "typescript": "4.6.4",
71
+ "webpack": "5.72.0",
70
72
  "webpack-cli": "^4.9.2",
71
73
  "webpack-node-externals": "^3.0.0"
72
74
  }
package/src/bin/add.ts CHANGED
@@ -2,9 +2,9 @@ import { loadConfig } from '@capacitor/cli/dist/config';
2
2
  import axios from 'axios';
3
3
  import prettyjson from 'prettyjson';
4
4
  import { program } from 'commander';
5
- import { readFileSync } from 'fs';
5
+ import { readFileSync } from 'fs';
6
6
  import { existsSync } from 'fs-extra';
7
- import { getType } from 'mime';
7
+ import { getType } from 'mime';
8
8
  import { host } from './utils';
9
9
 
10
10
  export const addApp = async (appid: string, options: any) => {
@@ -22,7 +22,7 @@ export const addApp = async (appid: string, options: any) => {
22
22
  if (!apikey) {
23
23
  program.error("Missing API key, you need to provide a API key to add your app");
24
24
  }
25
- if(!appid || !name) {
25
+ if (!appid || !name) {
26
26
  program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project");
27
27
  }
28
28
  console.log(`Add ${appid} to Capgo`);
@@ -30,7 +30,7 @@ export const addApp = async (appid: string, options: any) => {
30
30
  try {
31
31
  console.log('Adding...');
32
32
  const data: any = { appid, name }
33
- if(icon && existsSync(icon)) {
33
+ if (icon && existsSync(icon)) {
34
34
  const iconBuff = readFileSync(icon);
35
35
  const contentType = getType(icon);
36
36
  data.icon = iconBuff.toString('base64');
@@ -38,12 +38,13 @@ export const addApp = async (appid: string, options: any) => {
38
38
  }
39
39
  res = await axios({
40
40
  method: 'POST',
41
- url:`${host}/api/add`,
41
+ url: `${host}/api/add`,
42
42
  data,
43
43
  validateStatus: () => true,
44
44
  headers: {
45
45
  'authorization': apikey
46
- }})
46
+ }
47
+ })
47
48
  } catch (err) {
48
49
  program.error(`Network Error \n${prettyjson.render(err.response.data)}`);
49
50
  }
package/src/bin/delete.ts CHANGED
@@ -16,7 +16,7 @@ export const deleteApp = async (appid: string, options: any) => {
16
16
  if (!apikey) {
17
17
  program.error('Missing API key, you need to provide an API key to delete your app');
18
18
  }
19
- if(!appid) {
19
+ if (!appid) {
20
20
  program.error('Missing argument, you need to provide a appid, or be in a capacitor project');
21
21
  }
22
22
  console.log(`Delete ${appid} to Capgo`);
@@ -30,12 +30,13 @@ export const deleteApp = async (appid: string, options: any) => {
30
30
  validateStatus: () => true,
31
31
  headers: {
32
32
  'authorization': apikey
33
- }})
33
+ }
34
+ })
34
35
  } catch (err) {
35
36
  program.error(`Network Error \n${prettyjson.render(err.response.data)}`);
36
37
  }
37
38
  if (!res || res.status !== 200) {
38
39
  program.error(`Server Error \n${prettyjson.render(res.data)}`);
39
40
  }
40
- console.log("App deleted to server")
41
+ console.log("App deleted to server")
41
42
  }
package/src/bin/index.ts CHANGED
@@ -20,8 +20,8 @@ program
20
20
  .option('-p, --path <path>', 'path of the file to upload')
21
21
  .option('-c, --channel <channel>', 'channel to link to')
22
22
  .option('-e, --external <url>', 'link to external url intead of upload to capgo cloud')
23
+ .option('-f, --format <base64|hex|binary|utf8>', 'choose the upload format default base64')
23
24
  .option('-v, --version <version>', 'version number of the file to upload');
24
-
25
25
  program
26
26
  .command('set [appid]').alias('s')
27
27
  .action(setChannel)
package/src/bin/set.ts CHANGED
@@ -15,15 +15,15 @@ export const setChannel = async (appid, options) => {
15
15
  }
16
16
  appid = appid || config?.app?.appId
17
17
  let parsedState
18
- if (state === 'public' || state === 'private')
18
+ if (state === 'public' || state === 'private')
19
19
  parsedState = state === 'public'
20
20
  if (!apikey) {
21
21
  program.error("Missing API key, you need to provide a API key to add your app");
22
22
  }
23
- if(!appid) {
23
+ if (!appid) {
24
24
  program.error("Missing argument, you need to provide a appid, or be in a capacitor project");
25
25
  }
26
- if(!version && !parsedState) {
26
+ if (!version && !parsedState) {
27
27
  program.error("Missing argument, you need to provide a state or a version");
28
28
  }
29
29
  if (version) {
@@ -34,7 +34,7 @@ export const setChannel = async (appid, options) => {
34
34
  try {
35
35
  res = await axios({
36
36
  method: 'POST',
37
- url:`${host}/api/channel`,
37
+ url: `${host}/api/channel`,
38
38
  data: {
39
39
  version,
40
40
  public: parsedState,
@@ -44,7 +44,8 @@ export const setChannel = async (appid, options) => {
44
44
  validateStatus: () => true,
45
45
  headers: {
46
46
  'authorization': apikey
47
- }})
47
+ }
48
+ })
48
49
  } catch (err) {
49
50
  program.error(`Network Error \n${prettyjson.render(err.response.data)}`);
50
51
  }
package/src/bin/upload.ts CHANGED
@@ -4,20 +4,67 @@ import axios from 'axios';
4
4
  import prettyjson from 'prettyjson';
5
5
  import { program } from 'commander';
6
6
  import cliProgress from 'cli-progress';
7
+ import axiosRetry from 'axios-retry';
7
8
  import { host, hostWeb, hostUpload, supaAnon } from './utils';
8
9
 
10
+ axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
9
11
  const oneMb = 1048576; // size of one mb in bytes
10
12
  const maxMb = 30;
11
- const limitMb = oneMb * maxMb; // size of 1/2 mb
12
- const formatType = 'binary';
13
- const chuckNumber = (l: number, divider: number) => l < divider ? l : Math.round(l / divider)
14
- const chuckSize = (l: number, divider: number) => Math.round(l / chuckNumber(l, divider))
13
+ const alertMb = 25;
14
+ // enum string format
15
+ enum UploadMode {
16
+ uft8 = 'utf8',
17
+ base64 = 'base64',
18
+ hex = 'hex',
19
+ binary = 'binary'
20
+ }
21
+ interface uploadPayload {
22
+ version: string
23
+ appid: string
24
+ fileName: string
25
+ channel: string
26
+ format: UploadMode
27
+ app: string,
28
+ isMultipart: boolean,
29
+ chunk: number,
30
+ totalChunks: number,
31
+ }
32
+
33
+ const formatDefault = UploadMode.binary;
34
+ const chuckNumber = (l: number, divider: number) => l < divider ? 1 : Math.floor(l / divider)
35
+ const chuckSize = (l: number, divider: number) => Math.floor(l / chuckNumber(l, divider))
36
+
37
+ const mbConvert = {
38
+ 'base64': (l: number) => Math.floor((l * 4) / 3),
39
+ 'hex': (l: number) => Math.floor(l * 2),
40
+ 'binary': (l: number) => l,
41
+ 'utf8': (l: number) => l,
42
+ }
43
+
44
+ const sendToBack = async (data: uploadPayload, apikey: string) => {
45
+ const res = await axios({
46
+ method: 'POST',
47
+ url: hostUpload,
48
+ data,
49
+ validateStatus: () => true,
50
+ headers: {
51
+ 'Content-Type': 'application/json',
52
+ 'apikey': apikey,
53
+ authorization: `Bearer ${supaAnon}`
54
+ }
55
+ })
56
+ return res
57
+ }
15
58
 
16
59
  export const uploadVersion = async (appid, options) => {
17
60
  let { version, path, channel } = options;
18
- const { apikey, external } = options;
61
+ const { apikey, external, format } = options;
19
62
  channel = channel || 'dev';
20
63
  let config;
64
+ let formatType = formatDefault;
65
+ if (format in UploadMode) {
66
+ formatType = format as UploadMode;
67
+ }
21
68
  try {
22
69
  config = await loadConfig();
23
70
  } catch (err) {
@@ -62,18 +109,26 @@ export const uploadVersion = async (appid, options) => {
62
109
  }
63
110
  }
64
111
  } else {
65
- const b1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_grey);
112
+ const b1 = new cliProgress.SingleBar({
113
+ format: 'Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Mb'
114
+ }, cliProgress.Presets.shades_grey);
66
115
  try {
67
116
  const zip = new AdmZip();
68
117
  zip.addLocalFolder(path);
69
- console.log('Uploading:');
70
118
  const zipped = zip.toBuffer();
71
119
  const appData = zipped.toString(formatType);
72
120
  // split appData in chunks and send them sequentially with axios
73
- const zippedSize = Buffer.byteLength(zipped);
74
- const chunkSize = chuckSize(zipped.length, oneMb);
75
- if (zippedSize > limitMb) {
76
- program.error(`The app is too big, the limit is ${maxMb} Mb, your is ${Math.round(zippedSize / oneMb)} Mb`);
121
+ // console.log('appData size', appData.length)
122
+ const zippedSize = appData.length;
123
+ const mbSize = Math.floor(zippedSize / mbConvert[formatType](oneMb));
124
+ // console.log('mbSize', zippedSize, mbSize, mbConvert[formatType](oneMb))
125
+ const chunkSize = chuckNumber(zippedSize, mbConvert[formatType](oneMb)) > 1
126
+ ? chuckSize(zippedSize, mbConvert[formatType](oneMb)) : zippedSize;
127
+ if (mbSize > maxMb) {
128
+ program.error(`The app is too big, the limit is ${maxMb} Mb, your is ${mbSize} Mb`);
129
+ }
130
+ if (mbSize > alertMb) {
131
+ console.log(`WARNING !!\nThe app size is ${mbSize} Mb, the limit is ${maxMb} Mb`);
77
132
  }
78
133
  const chunks = [];
79
134
  for (let i = 0; i < appData.length; i += chunkSize) {
@@ -84,27 +139,17 @@ export const uploadVersion = async (appid, options) => {
84
139
  });
85
140
  let fileName
86
141
  for (let i = 0; i < chunks.length; i += 1) {
87
- const res = await axios({
88
- method: 'POST',
89
- url: hostUpload,
90
- data: {
91
- version,
92
- appid,
93
- fileName,
94
- channel,
95
- format: formatType,
96
- app: chunks[i],
97
- isMultipart: chunks.length > 1,
98
- chunk: i + 1,
99
- totalChunks: chunks.length,
100
- },
101
- validateStatus: () => true,
102
- headers: {
103
- 'Content-Type': 'application/json',
104
- 'apikey': apikey,
105
- authorization: `Bearer ${supaAnon}`
106
- }
107
- })
142
+ const res = await sendToBack({
143
+ version,
144
+ appid,
145
+ fileName,
146
+ channel,
147
+ format: formatType,
148
+ app: chunks[i],
149
+ isMultipart: chunks.length > 1,
150
+ chunk: i + 1,
151
+ totalChunks: chunks.length,
152
+ }, apikey)
108
153
  if (res.status !== 200) {
109
154
  b1.stop();
110
155
  program.error(`Server Error \n${prettyjson.render(res?.data || "")}`);
@@ -1,10 +1,16 @@
1
1
  import { lorem } from './data'
2
2
 
3
3
  const byteConvert = {
4
- 'base64': (s: string) => (3 * (s.length / 4)) - ((s.match(/=/g) || []).length),
5
- 'hex': (s: string) => s.length / 2,
6
- 'binary': (s: string) => s.length / 10,
7
- 'utf8': (s: string) => s.length,
4
+ 'base64': (s: string) => (3 * (s.length / 4)) - ((s.match(/=/g) || []).length),
5
+ 'hex': (s: string) => s.length / 2,
6
+ 'binary': (s: string) => s.length / 10,
7
+ 'utf8': (s: string) => s.length,
8
+ }
9
+ const mbConvert = {
10
+ 'base64': (l: number) => (3 * (l / 4)),
11
+ 'hex': (l: number) => l / 2,
12
+ 'binary': (l: number) => l / 10,
13
+ 'utf8': (l: number) => l,
8
14
  }
9
15
  const oneMb = 1048576;
10
16
 
package/webpack.config.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const path = require('path');
2
2
  const webpack = require('webpack');
3
3
  const nodeExternals = require('webpack-node-externals');
4
- const { CheckerPlugin } = require('awesome-typescript-loader');
5
4
  console.log(process.env.NODE_ENV || 'production');
6
5
  module.exports = {
7
6
  mode: process.env.NODE_ENV || 'production',
@@ -12,14 +11,14 @@ module.exports = {
12
11
  rules: [
13
12
  {
14
13
  test: /\.ts$/,
15
- use: 'awesome-typescript-loader',
14
+ loader: 'ts-loader',
16
15
  exclude: /node_modules/,
17
16
  },
18
17
  ],
19
18
  },
20
19
  devtool: process.env.NODE_ENV === 'development' ? 'eval-source-map' : undefined,
21
20
  watch: process.env.NODE_ENV === 'development',
22
- plugins: [new CheckerPlugin(), new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true })],
21
+ plugins: [new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true })],
23
22
  resolve: {
24
23
  extensions: ['.ts', '.js'],
25
24
  },