@capgo/cli 0.8.2 → 0.8.3
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 +0 -6
- package/dist/index.js +1 -1
- package/package.json +22 -20
- package/src/bin/index.ts +1 -1
- package/src/bin/upload.ts +76 -32
- package/test/chunk_convert.ts +10 -4
- package/webpack.config.js +2 -3
- package/pnpm-lock.yaml +0 -4535
package/.cz.toml
CHANGED
package/CHANGELOG.md
CHANGED
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=t(233),u=a(t(188));(0,u.default)(p.default,{retries:3,retryDelay:u.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={base64:e=>4*e/3,hex:e=>2*e,binary:e=>e,utf8:e=>e},g=(e,o)=>r(void 0,void 0,void 0,(function*(){return yield(0,p.default)({method:"POST",url:c.hostUpload,data:e,validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:o,authorization:`Bearer ${c.supaAnon}`}})}));o.uploadVersion=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r,a,u,y,m;let{version:b,path:k,channel:x}=o;const{apikey:w,external:_,format:$}=o;let M;x=x||"dev";let A="binary";$ in h&&(A=$);try{M=yield(0,n.loadConfig)()}catch(e){l.program.error("No capacitor config file found, run `cap init` first")}if(e=e||(null===(t=null==M?void 0:M.app)||void 0===t?void 0:t.appId),b=b||(null===(a=null===(r=null==M?void 0:M.app)||void 0===r?void 0:r.package)||void 0===a?void 0:a.version),k=k||(null===(u=null==M?void 0:M.app)||void 0===u?void 0:u.webDir),w||l.program.error("Missing API key, you need to provide a API key to add your app"),e&&b&&k||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}@${b} started from path "${k}" to Capgo cloud`),_)try{const o=yield(0,p.default)({method:"POST",url:c.hostUpload,data:{version:b,appid:e,channel:x,external:_},validateStatus:()=>!0,headers:{"Content-Type":"application/json",apikey:w,authorization:`Bearer ${c.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===(y=e.response)||void 0===y?void 0:y.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(k);const r=t.toBuffer().toString(A);console.log("appData size",r.length);const a=r.length,n=Math.floor(a/v[A](f));console.log("mbSize",a,n,v[A](f));const p=(I=a,N=v[A](f),Math.floor(I/((e,o)=>e<o?e:Math.floor(e/o))(I,N)));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 g({version:b,appid:e,fileName:c,channel:x,format:A,app:d[t],isMultipart:d.length>1,chunk:t+1,totalChunks:d.length},w);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===(m=e.response)||void 0===m?void 0:m.data)||"")}`):l.program.error(`Network Error \n${s.default.render(e||"")}`)}}var I,N;console.log("App uploaded to server"),console.log(`Try it in mobile app: ${c.host}/app_mobile`),console.log(`Or set the channel ${x} as public here: ${c.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.3","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.
|
|
3
|
+
"version": "0.8.3",
|
|
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": "
|
|
37
|
+
"@capacitor/cli": "3.5.1",
|
|
38
38
|
"adm-zip": "^0.5.9",
|
|
39
|
-
"axios": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
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": "
|
|
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": "
|
|
51
|
+
"@types/adm-zip": "0.5.0",
|
|
51
52
|
"@types/fs-extra": "^9.0.13",
|
|
52
|
-
"@
|
|
53
|
-
"@typescript-eslint/
|
|
54
|
-
"
|
|
55
|
-
"eslint": "
|
|
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": "
|
|
59
|
-
"eslint-plugin-import": "
|
|
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": "
|
|
62
|
+
"git-format-staged": "3.0.0",
|
|
62
63
|
"husky": "^7.0.4",
|
|
63
|
-
"nodemon": "
|
|
64
|
-
"pkg": "
|
|
65
|
-
"prettier": "
|
|
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": "
|
|
68
|
-
"typescript": "
|
|
69
|
-
"webpack": "
|
|
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/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/upload.ts
CHANGED
|
@@ -5,19 +5,66 @@ import prettyjson from 'prettyjson';
|
|
|
5
5
|
import { program } from 'commander';
|
|
6
6
|
import cliProgress from 'cli-progress';
|
|
7
7
|
import { host, hostWeb, hostUpload, supaAnon } from './utils';
|
|
8
|
+
import axiosRetry from 'axios-retry';
|
|
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
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const alertMb = 25;
|
|
14
|
+
// enum string format
|
|
15
|
+
enum UploadFormat {
|
|
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: UploadFormat
|
|
27
|
+
app: string,
|
|
28
|
+
isMultipart: boolean,
|
|
29
|
+
chunk: number,
|
|
30
|
+
totalChunks: number,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const formatDefault: UploadFormat = 'binary' as UploadFormat;
|
|
34
|
+
const chuckNumber = (l: number, divider: number) => l < divider ? l : 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) => ((l * 4) / 3),
|
|
39
|
+
'hex': (l: number) => 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 UploadFormat) {
|
|
66
|
+
formatType = format as UploadFormat;
|
|
67
|
+
}
|
|
21
68
|
try {
|
|
22
69
|
config = await loadConfig();
|
|
23
70
|
} catch (err) {
|
|
@@ -62,18 +109,25 @@ export const uploadVersion = async (appid, options) => {
|
|
|
62
109
|
}
|
|
63
110
|
}
|
|
64
111
|
} else {
|
|
65
|
-
const b1 = new cliProgress.SingleBar({
|
|
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
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
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 = chuckSize(zippedSize, mbConvert[formatType](oneMb));
|
|
126
|
+
if (mbSize > maxMb) {
|
|
127
|
+
program.error(`The app is too big, the limit is ${maxMb} Mb, your is ${mbSize} Mb`);
|
|
128
|
+
}
|
|
129
|
+
if (mbSize > alertMb) {
|
|
130
|
+
console.log(`WARNING !!\nThe app size is ${mbSize} Mb, the limit is ${maxMb} Mb`);
|
|
77
131
|
}
|
|
78
132
|
const chunks = [];
|
|
79
133
|
for (let i = 0; i < appData.length; i += chunkSize) {
|
|
@@ -84,27 +138,17 @@ export const uploadVersion = async (appid, options) => {
|
|
|
84
138
|
});
|
|
85
139
|
let fileName
|
|
86
140
|
for (let i = 0; i < chunks.length; i += 1) {
|
|
87
|
-
const res = await
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
})
|
|
141
|
+
const res = await sendToBack({
|
|
142
|
+
version,
|
|
143
|
+
appid,
|
|
144
|
+
fileName,
|
|
145
|
+
channel,
|
|
146
|
+
format: formatType,
|
|
147
|
+
app: chunks[i],
|
|
148
|
+
isMultipart: chunks.length > 1,
|
|
149
|
+
chunk: i + 1,
|
|
150
|
+
totalChunks: chunks.length,
|
|
151
|
+
}, apikey)
|
|
108
152
|
if (res.status !== 200) {
|
|
109
153
|
b1.stop();
|
|
110
154
|
program.error(`Server Error \n${prettyjson.render(res?.data || "")}`);
|
package/test/chunk_convert.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { lorem } from './data'
|
|
2
2
|
|
|
3
3
|
const byteConvert = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
|
21
|
+
plugins: [new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true })],
|
|
23
22
|
resolve: {
|
|
24
23
|
extensions: ['.ts', '.js'],
|
|
25
24
|
},
|