@capgo/cli 0.8.6 → 0.9.0
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/.eslintrc +0 -1
- package/CHANGELOG.md +11 -0
- package/dist/index.js +1 -1
- package/package.json +4 -1
- package/src/bin/add.ts +39 -20
- package/src/bin/delete.ts +16 -12
- package/src/bin/set.ts +21 -13
- package/src/bin/types.d.ts +6 -0
- package/src/bin/upload.ts +54 -54
- package/src/bin/utils.ts +27 -4
- package/tsconfig.json +4 -1
package/.cz.toml
CHANGED
package/.eslintrc
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={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)})();
|
|
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(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function p(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var o;e.done?n(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())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const a=n(t(167)),i=n(t(867)),p=t(304),s=t(147),l=t(470),d=t(11),u=t(233),c="assets/icon.png";o.addApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r,n;let{name:f,icon:v}=o;const{apikey:g}=o,h=yield(0,u.getConfig)();let y;e=e||(null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.appId),f=f||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.appName)||"Unknown",v=v||"resources/icon.png",g||p.program.error("Missing API key, you need to provide a API key to add your app"),e&&f||p.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`),console.log("Adding...");const m={appid:e,name:f};if(v&&(0,l.existsSync)(v)){const e=(0,s.readFileSync)(v),o=(0,d.getType)(v);m.icon=e.toString("base64"),m.iconType=o||"image/png"}else if((0,l.existsSync)(c)){const e=(0,s.readFileSync)(c),o=(0,d.getType)(c);m.icon=e.toString("base64"),m.iconType=o||"image/png"}else console.warn(`Cannot find app icon in any of the following locations: ${v}, ${c}`);try{y=yield(0,a.default)({method:"POST",url:`${u.hostSupa}/add`,data:m,validateStatus:()=>!0,headers:{apikey:g,authorization:`Bearer ${u.supaAnon}`}})}catch(e){a.default.isAxiosError(e)&&e.response?p.program.error(`Network Error \n${i.default.render(null===(n=e.response)||void 0===n?void 0:n.data)}`):p.program.error(`Unknow error \n${i.default.render(e)}`)}y&&200===y.status||p.program.error(`Server Error \n${i.default.render(y.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(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function p(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var o;e.done?n(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())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const a=n(t(167)),i=n(t(867)),p=t(304),s=t(233);o.deleteApp=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r;const{apikey:n,version:l}=o,d=yield(0,s.getConfig)();let u;e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),n||p.program.error("Missing API key, you need to provide an API key to delete your app"),e||p.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..."),u=yield(0,a.default)({method:"POST",url:`${s.hostSupa}/delete`,data:{appid:e,version:l},validateStatus:()=>!0,headers:{apikey:n,authorization:`Bearer ${s.supaAnon}`}})}catch(e){a.default.isAxiosError(e)&&e.response?p.program.error(`Network Error \n${i.default.render(null===(r=e.response)||void 0===r?void 0:r.data)}`):p.program.error(`Unknow error \n${i.default.render(e)}`)}u&&200===u.status||p.program.error(`Server Error \n${i.default.render(u.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 n=t(304),a=t(548),i=t(453),p=t(666),s=t(310),l=r(t(598));n.program.version(l.default.version).command("add [appid]").alias("a").action(a.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),n.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"),n.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"),n.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"),n.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(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function p(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var o;e.done?n(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())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const a=n(t(167)),i=n(t(867)),p=t(304),s=t(233);o.setChannel=(e,o)=>r(void 0,void 0,void 0,(function*(){var t,r,n,l;let{version:d}=o;const{apikey:u,state:c,channel:f="dev"}=o,v=yield(0,s.getConfig)();let g,h;e=e||(null===(t=null==v?void 0:v.app)||void 0===t?void 0:t.appId),d=d||(null===(n=null===(r=null==v?void 0:v.app)||void 0===r?void 0:r.package)||void 0===n?void 0:n.version),"public"!==c&&"private"!==c||(h="public"===c),u||p.program.error("Missing API key, you need to provide a API key to add your app"),e||p.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),d||h||p.program.error("Missing argument, you need to provide a state or a version"),d?console.log(`Set ${f} to @${d} in ${e}`):console.log(`Set${f} to @${c} in ${e}`);try{g=yield(0,a.default)({method:"POST",url:`${s.hostSupa}/channel`,data:{version:d,public:h,appid:e,channel:f},validateStatus:()=>!0,headers:{apikey:u,authorization:`Bearer ${s.supaAnon}`}})}catch(e){a.default.isAxiosError(e)&&e.response?p.program.error(`Network Error \n${i.default.render(null===(l=e.response)||void 0===l?void 0:l.data)}`):p.program.error(`Unknow error \n${i.default.render(e)}`)}g&&200===g.status||p.program.error(`Server Error \n${i.default.render(g.data)}`),d?console.log("Done ✅"):console.log(`You can use now is channel in your app with the url: ${s.host}/api/latest?appid=${e}&channel=${f}`)}))},310:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function p(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var o;e.done?n(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())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const a=n(t(844)),i=n(t(167)),p=n(t(867)),s=t(304),l=n(t(295)),d=n(t(188)),u=t(233);(0,d.default)(i.default,{retries:5,retryDelay:d.default.exponentialDelay});const c=1048576;var f;!function(e){e.uft8="utf8",e.base64="base64",e.hex="hex",e.binary="binary"}(f||(f={}));const v=f.binary,g=(e,o)=>e<o?1:Math.floor(e/o),h={base64:e=>Math.floor(4*e/3),hex:e=>Math.floor(2*e),binary:e=>e,utf8:e=>e},y=(e,o)=>r(void 0,void 0,void 0,(function*(){return(0,i.default)({method:"POST",url:`${u.hostSupa}/upload`,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,n,d,m,k;let{version:b,path:x,channel:w}=o;const{apikey:_,external:$,format:A}=o;w=w||"dev";const M=yield(0,u.getConfig)();let S=v;if(A&&A in f&&(S=A),e=e||(null===(t=null==M?void 0:M.app)||void 0===t?void 0:t.appId),b=b||(null===(n=null===(r=null==M?void 0:M.app)||void 0===r?void 0:r.package)||void 0===n?void 0:n.version),x=x||(null===(d=null==M?void 0:M.app)||void 0===d?void 0:d.webDir),_||s.program.error("Missing API key, you need to provide a API key to add your app"),e&&b&&x||s.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 "${x}" to Capgo cloud`),$)try{const o=yield y({version:b,appid:e,channel:w,external:$},_);200!==o.status&&s.program.error(`Server Error \n${p.default.render((null==o?void 0:o.data)||"")}`)}catch(e){i.default.isAxiosError(e)&&e.response?s.program.error(`Network Error \n${p.default.render(null===(m=e.response)||void 0===m?void 0:m.data)}`):s.program.error(`Unknow error \n${p.default.render(e)}`)}else{const o=new l.default.SingleBar({format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Mb"},l.default.Presets.shades_grey);try{const t=new a.default;t.addLocalFolder(x);const r=t.toBuffer().toString(S),n=r.length,i=Math.floor(n/h[S](c)),l=g(n,h[S](c))>1?(I=n,P=h[S](c),Math.floor(I/g(I,P))):n;i>30&&s.program.error(`The app is too big, the limit is 30 Mb, your is ${i} Mb`),i>25&&console.log(`WARNING !!\nThe app size is ${i} Mb, the limit is 30 Mb`);const d=[];for(let e=0;e<r.length;e+=l)d.push(r.slice(e,e+l));let u;o.start(d.length,0,{speed:"N/A"});for(let t=0;t<d.length;t+=1){const r=yield y({version:b,appid:e,fileName:u,channel:w,format:S,app:d[t],isMultipart:d.length>1,chunk:t+1,totalChunks:d.length},_);200===r.status&&r.data.fileName||(o.stop(),s.program.error(`Server Error \n${p.default.render((null==r?void 0:r.data)||"")}`)),o.update(t+1),u=r.data.fileName}o.stop()}catch(e){o.stop(),i.default.isAxiosError(e)&&e.response?s.program.error(`Network Error \n${p.default.render(null===(k=e.response)||void 0===k?void 0:k.data)}`):s.program.error(`Unknow error \n${p.default.render(e)}`)}}var I,P;console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${w} as public here: ${u.hostWeb}/app/package/${e}`),console.log("To use with live update in your own app")}))},233:function(e,o,t){var r=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function p(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var o;e.done?n(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())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getConfig=o.supaAnon=o.hostSupa=o.hostWeb=o.host=void 0;const n=t(778),a=t(304);o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.functions.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.getConfig=()=>r(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,n.loadConfig)()}catch(e){a.program.error("No capacitor config file found, run `cap init` first")}return e}))},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.9.0","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/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^2.0.3","@types/node":"^17.0.31","@types/prettyjson":"^0.0.30","@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 n=o[r];if(void 0!==n)return n.exports;var a=o[r]={exports:{}};return e[r].call(a.exports,a,a.exports,t),a.exports}(473)})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A CLI to upload to capgo servers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -49,8 +49,11 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/adm-zip": "0.5.0",
|
|
52
|
+
"@types/cli-progress": "^3.11.0",
|
|
52
53
|
"@types/fs-extra": "^9.0.13",
|
|
54
|
+
"@types/mime": "^2.0.3",
|
|
53
55
|
"@types/node": "^17.0.31",
|
|
56
|
+
"@types/prettyjson": "^0.0.30",
|
|
54
57
|
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
55
58
|
"@typescript-eslint/parser": "5.22.0",
|
|
56
59
|
"eslint": "8.14.0",
|
package/src/bin/add.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import prettyjson from 'prettyjson';
|
|
4
3
|
import { program } from 'commander';
|
|
5
4
|
import { readFileSync } from 'fs';
|
|
6
5
|
import { existsSync } from 'fs-extra';
|
|
7
6
|
import { getType } from 'mime';
|
|
8
|
-
import {
|
|
7
|
+
import { getConfig, hostSupa, supaAnon } from './utils';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
interface AppAdd {
|
|
10
|
+
appid: string;
|
|
11
|
+
name: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
iconType?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Options {
|
|
16
|
+
apikey: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
icon?: string;
|
|
19
|
+
}
|
|
20
|
+
const newIconPath = "assets/icon.png"
|
|
21
|
+
export const addApp = async (appid: string, options: Options) => {
|
|
11
22
|
let { name, icon } = options;
|
|
12
23
|
const { apikey } = options;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
config = await loadConfig();
|
|
16
|
-
} catch (err) {
|
|
17
|
-
program.error("No capacitor config file found, run `cap init` first");
|
|
18
|
-
}
|
|
24
|
+
const config = await getConfig();
|
|
19
25
|
appid = appid || config?.app?.appId
|
|
20
26
|
name = name || config?.app?.appName || 'Unknown'
|
|
21
27
|
icon = icon || "resources/icon.png" // default path for capacitor app
|
|
@@ -27,26 +33,39 @@ export const addApp = async (appid: string, options: any) => {
|
|
|
27
33
|
}
|
|
28
34
|
console.log(`Add ${appid} to Capgo`);
|
|
29
35
|
let res;
|
|
36
|
+
console.log('Adding...');
|
|
37
|
+
const data: AppAdd = { appid, name }
|
|
38
|
+
if (icon && existsSync(icon)) {
|
|
39
|
+
const iconBuff = readFileSync(icon);
|
|
40
|
+
const contentType = getType(icon);
|
|
41
|
+
data.icon = iconBuff.toString('base64');
|
|
42
|
+
data.iconType = contentType || 'image/png';
|
|
43
|
+
}
|
|
44
|
+
else if (existsSync(newIconPath)) {
|
|
45
|
+
const iconBuff = readFileSync(newIconPath);
|
|
46
|
+
const contentType = getType(newIconPath);
|
|
47
|
+
data.icon = iconBuff.toString('base64');
|
|
48
|
+
data.iconType = contentType || 'image/png';
|
|
49
|
+
} else {
|
|
50
|
+
console.warn(`Cannot find app icon in any of the following locations: ${icon}, ${newIconPath}`);
|
|
51
|
+
}
|
|
30
52
|
try {
|
|
31
|
-
console.log('Adding...');
|
|
32
|
-
const data: any = { appid, name }
|
|
33
|
-
if (icon && existsSync(icon)) {
|
|
34
|
-
const iconBuff = readFileSync(icon);
|
|
35
|
-
const contentType = getType(icon);
|
|
36
|
-
data.icon = iconBuff.toString('base64');
|
|
37
|
-
data.iconType = contentType;
|
|
38
|
-
}
|
|
39
53
|
res = await axios({
|
|
40
54
|
method: 'POST',
|
|
41
|
-
url: `${
|
|
55
|
+
url: `${hostSupa}/add`,
|
|
42
56
|
data,
|
|
43
57
|
validateStatus: () => true,
|
|
44
58
|
headers: {
|
|
45
|
-
'
|
|
59
|
+
'apikey': apikey,
|
|
60
|
+
'authorization': `Bearer ${supaAnon}`
|
|
46
61
|
}
|
|
47
62
|
})
|
|
48
63
|
} catch (err) {
|
|
49
|
-
|
|
64
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
65
|
+
program.error(`Network Error \n${prettyjson.render(err.response?.data)}`);
|
|
66
|
+
} else {
|
|
67
|
+
program.error(`Unknow error \n${prettyjson.render(err)}`);
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
70
|
if (!res || res.status !== 200) {
|
|
52
71
|
program.error(`Server Error \n${prettyjson.render(res.data)}`);
|
package/src/bin/delete.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import prettyjson from 'prettyjson';
|
|
4
3
|
import { program } from 'commander';
|
|
5
|
-
import {
|
|
4
|
+
import { supaAnon, hostSupa, getConfig } from './utils';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
interface Options {
|
|
7
|
+
apikey: string;
|
|
8
|
+
version: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const deleteApp = async (appid: string, options: Options) => {
|
|
8
12
|
const { apikey, version } = options;
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
config = await loadConfig();
|
|
12
|
-
} catch (err) {
|
|
13
|
-
program.error("No capacitor config file found, run `cap init` first");
|
|
14
|
-
}
|
|
13
|
+
const config = await getConfig();
|
|
15
14
|
appid = appid || config?.app?.appId
|
|
16
15
|
if (!apikey) {
|
|
17
16
|
program.error('Missing API key, you need to provide an API key to delete your app');
|
|
@@ -25,15 +24,20 @@ export const deleteApp = async (appid: string, options: any) => {
|
|
|
25
24
|
console.log('Deleting...');
|
|
26
25
|
res = await axios({
|
|
27
26
|
method: 'POST',
|
|
28
|
-
url: `${
|
|
27
|
+
url: `${hostSupa}/delete`,
|
|
29
28
|
data: { appid, version },
|
|
30
29
|
validateStatus: () => true,
|
|
31
30
|
headers: {
|
|
32
|
-
'
|
|
31
|
+
'apikey': apikey,
|
|
32
|
+
'authorization': `Bearer ${supaAnon}`
|
|
33
33
|
}
|
|
34
34
|
})
|
|
35
35
|
} catch (err) {
|
|
36
|
-
|
|
36
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
37
|
+
program.error(`Network Error \n${prettyjson.render(err.response?.data)}`);
|
|
38
|
+
} else {
|
|
39
|
+
program.error(`Unknow error \n${prettyjson.render(err)}`);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
if (!res || res.status !== 200) {
|
|
39
43
|
program.error(`Server Error \n${prettyjson.render(res.data)}`);
|
package/src/bin/set.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import prettyjson from 'prettyjson';
|
|
4
3
|
import { program } from 'commander';
|
|
5
|
-
import { host } from './utils';
|
|
4
|
+
import { getConfig, host, hostSupa, supaAnon } from './utils';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
interface Options {
|
|
7
|
+
apikey: string;
|
|
8
|
+
version: string;
|
|
9
|
+
state: string;
|
|
10
|
+
channel?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const setChannel = async (appid: string, options: Options) => {
|
|
14
|
+
let { version } = options;
|
|
15
|
+
const { apikey, state, channel = 'dev' } = options;
|
|
16
|
+
const config = await getConfig();
|
|
10
17
|
let res;
|
|
11
|
-
try {
|
|
12
|
-
config = await loadConfig();
|
|
13
|
-
} catch (err) {
|
|
14
|
-
program.error("No capacitor config file found, run `cap init` first");
|
|
15
|
-
}
|
|
16
18
|
appid = appid || config?.app?.appId
|
|
19
|
+
version = version || config?.app?.package?.version
|
|
17
20
|
let parsedState
|
|
18
21
|
if (state === 'public' || state === 'private')
|
|
19
22
|
parsedState = state === 'public'
|
|
@@ -34,7 +37,7 @@ export const setChannel = async (appid, options) => {
|
|
|
34
37
|
try {
|
|
35
38
|
res = await axios({
|
|
36
39
|
method: 'POST',
|
|
37
|
-
url: `${
|
|
40
|
+
url: `${hostSupa}/channel`,
|
|
38
41
|
data: {
|
|
39
42
|
version,
|
|
40
43
|
public: parsedState,
|
|
@@ -43,11 +46,16 @@ export const setChannel = async (appid, options) => {
|
|
|
43
46
|
},
|
|
44
47
|
validateStatus: () => true,
|
|
45
48
|
headers: {
|
|
46
|
-
'
|
|
49
|
+
'apikey': apikey,
|
|
50
|
+
'authorization': `Bearer ${supaAnon}`
|
|
47
51
|
}
|
|
48
52
|
})
|
|
49
53
|
} catch (err) {
|
|
50
|
-
|
|
54
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
55
|
+
program.error(`Network Error \n${prettyjson.render(err.response?.data)}`);
|
|
56
|
+
} else {
|
|
57
|
+
program.error(`Unknow error \n${prettyjson.render(err)}`);
|
|
58
|
+
}
|
|
51
59
|
}
|
|
52
60
|
if (!res || res.status !== 200) {
|
|
53
61
|
program.error(`Server Error \n${prettyjson.render(res.data)}`);
|
package/src/bin/upload.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
1
|
import AdmZip from 'adm-zip';
|
|
3
|
-
import axios from 'axios';
|
|
2
|
+
import axios, { AxiosResponse } from 'axios';
|
|
4
3
|
import prettyjson from 'prettyjson';
|
|
5
4
|
import { program } from 'commander';
|
|
6
5
|
import cliProgress from 'cli-progress';
|
|
7
6
|
import axiosRetry from 'axios-retry';
|
|
8
|
-
import { host, hostWeb,
|
|
7
|
+
import { host, hostWeb, supaAnon, hostSupa, getConfig } from './utils';
|
|
9
8
|
|
|
10
|
-
axiosRetry(axios, { retries:
|
|
9
|
+
axiosRetry(axios, { retries: 5, retryDelay: axiosRetry.exponentialDelay });
|
|
11
10
|
const oneMb = 1048576; // size of one mb in bytes
|
|
12
11
|
const maxMb = 30;
|
|
13
12
|
const alertMb = 25;
|
|
@@ -21,7 +20,7 @@ enum UploadMode {
|
|
|
21
20
|
interface uploadPayload {
|
|
22
21
|
version: string
|
|
23
22
|
appid: string
|
|
24
|
-
fileName
|
|
23
|
+
fileName?: string
|
|
25
24
|
channel: string
|
|
26
25
|
format: UploadMode
|
|
27
26
|
app: string,
|
|
@@ -29,6 +28,16 @@ interface uploadPayload {
|
|
|
29
28
|
chunk: number,
|
|
30
29
|
totalChunks: number,
|
|
31
30
|
}
|
|
31
|
+
interface uploadExternal {
|
|
32
|
+
version: string
|
|
33
|
+
appid: string
|
|
34
|
+
channel: string
|
|
35
|
+
external: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ResApi {
|
|
39
|
+
fileName: string
|
|
40
|
+
}
|
|
32
41
|
|
|
33
42
|
const formatDefault = UploadMode.binary;
|
|
34
43
|
const chuckNumber = (l: number, divider: number) => l < divider ? 1 : Math.floor(l / divider)
|
|
@@ -41,34 +50,34 @@ const mbConvert = {
|
|
|
41
50
|
'utf8': (l: number) => l,
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
const sendToBack = async (data: uploadPayload, apikey: string) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
return res
|
|
57
|
-
}
|
|
53
|
+
const sendToBack = async (data: uploadPayload | uploadExternal, apikey: string): Promise<AxiosResponse<ResApi>> => axios({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
url: `${hostSupa}/upload`,
|
|
56
|
+
data,
|
|
57
|
+
validateStatus: () => true,
|
|
58
|
+
headers: {
|
|
59
|
+
'Content-Type': 'application/json',
|
|
60
|
+
'apikey': apikey,
|
|
61
|
+
authorization: `Bearer ${supaAnon}`
|
|
62
|
+
}
|
|
63
|
+
})
|
|
58
64
|
|
|
59
|
-
|
|
65
|
+
interface Options {
|
|
66
|
+
version: string
|
|
67
|
+
path: string
|
|
68
|
+
apikey: string
|
|
69
|
+
channel?: string
|
|
70
|
+
external?: string
|
|
71
|
+
format?: UploadMode
|
|
72
|
+
}
|
|
73
|
+
export const uploadVersion = async (appid: string, options: Options) => {
|
|
60
74
|
let { version, path, channel } = options;
|
|
61
75
|
const { apikey, external, format } = options;
|
|
62
76
|
channel = channel || 'dev';
|
|
63
|
-
|
|
77
|
+
const config = await getConfig();
|
|
64
78
|
let formatType = formatDefault;
|
|
65
|
-
if (format in UploadMode) {
|
|
66
|
-
formatType = format
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
config = await loadConfig();
|
|
70
|
-
} catch (err) {
|
|
71
|
-
program.error("No capacitor config file found, run `cap init` first");
|
|
79
|
+
if (format && format in UploadMode) {
|
|
80
|
+
formatType = format;
|
|
72
81
|
}
|
|
73
82
|
appid = appid || config?.app?.appId
|
|
74
83
|
version = version || config?.app?.package?.version
|
|
@@ -82,30 +91,20 @@ export const uploadVersion = async (appid, options) => {
|
|
|
82
91
|
console.log(`Upload ${appid}@${version} started from path "${path}" to Capgo cloud`);
|
|
83
92
|
if (external) {
|
|
84
93
|
try {
|
|
85
|
-
const res = await
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
channel,
|
|
92
|
-
external,
|
|
93
|
-
},
|
|
94
|
-
validateStatus: () => true,
|
|
95
|
-
headers: {
|
|
96
|
-
'Content-Type': 'application/json',
|
|
97
|
-
'apikey': apikey,
|
|
98
|
-
authorization: `Bearer ${supaAnon}`
|
|
99
|
-
}
|
|
100
|
-
})
|
|
94
|
+
const res = await sendToBack({
|
|
95
|
+
version,
|
|
96
|
+
appid,
|
|
97
|
+
channel,
|
|
98
|
+
external
|
|
99
|
+
}, apikey)
|
|
101
100
|
if (res.status !== 200) {
|
|
102
101
|
program.error(`Server Error \n${prettyjson.render(res?.data || "")}`);
|
|
103
102
|
}
|
|
104
103
|
} catch (err) {
|
|
105
|
-
if (err.response) {
|
|
106
|
-
program.error(`Network Error \n${prettyjson.render(err.response?.data
|
|
104
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
105
|
+
program.error(`Network Error \n${prettyjson.render(err.response?.data)}`);
|
|
107
106
|
} else {
|
|
108
|
-
program.error(`
|
|
107
|
+
program.error(`Unknow error \n${prettyjson.render(err)}`);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
} else {
|
|
@@ -139,7 +138,7 @@ export const uploadVersion = async (appid, options) => {
|
|
|
139
138
|
});
|
|
140
139
|
let fileName
|
|
141
140
|
for (let i = 0; i < chunks.length; i += 1) {
|
|
142
|
-
const
|
|
141
|
+
const response = await sendToBack({
|
|
143
142
|
version,
|
|
144
143
|
appid,
|
|
145
144
|
fileName,
|
|
@@ -150,20 +149,21 @@ export const uploadVersion = async (appid, options) => {
|
|
|
150
149
|
chunk: i + 1,
|
|
151
150
|
totalChunks: chunks.length,
|
|
152
151
|
}, apikey)
|
|
153
|
-
if (
|
|
152
|
+
if (response.status !== 200 || !response.data.fileName) {
|
|
154
153
|
b1.stop();
|
|
155
|
-
program.error(`Server Error \n${prettyjson.render(
|
|
154
|
+
program.error(`Server Error \n${prettyjson.render(response?.data || "")}`);
|
|
156
155
|
}
|
|
157
156
|
b1.update(i + 1)
|
|
158
|
-
|
|
157
|
+
const data: ResApi = response.data as ResApi
|
|
158
|
+
fileName = data.fileName
|
|
159
159
|
}
|
|
160
160
|
b1.stop();
|
|
161
161
|
} catch (err) {
|
|
162
162
|
b1.stop();
|
|
163
|
-
if (err.response) {
|
|
164
|
-
program.error(`Network Error \n${prettyjson.render(err.response?.data
|
|
163
|
+
if (axios.isAxiosError(err) && err.response) {
|
|
164
|
+
program.error(`Network Error \n${prettyjson.render(err.response?.data)}`);
|
|
165
165
|
} else {
|
|
166
|
-
program.error(`
|
|
166
|
+
program.error(`Unknow error \n${prettyjson.render(err)}`);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
}
|
package/src/bin/utils.ts
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import { loadConfig } from '@capacitor/cli/dist/config';
|
|
2
|
+
import { program } from 'commander';
|
|
3
|
+
|
|
2
4
|
export const host = 'https://capgo.app';
|
|
3
5
|
export const hostWeb = 'https://web.capgo.app';
|
|
4
|
-
export const
|
|
6
|
+
export const hostSupa = 'https://xvwzpoazmxkqosrdewyv.functions.supabase.co';
|
|
7
|
+
// export const hostSupa = 'https://aucsybvnhavogdmzwtcw.functions.supabase.co';
|
|
8
|
+
|
|
5
9
|
// For local test purposes
|
|
6
10
|
// export const host = 'http://localhost:3334';
|
|
7
|
-
// export const hostUpload = 'http://localhost:54321/functions/v1/upload';
|
|
8
|
-
/* eslint-enable */
|
|
9
11
|
|
|
10
12
|
/* eslint-disable */
|
|
11
13
|
export const supaAnon = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w'
|
|
14
|
+
// export const supaAnon = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImF1Y3N5YnZuaGF2b2dkbXp3dGN3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTE4NDE4MjMsImV4cCI6MTk2NzQxNzgyM30.AYzjGigPxlTw4eEkCjoGfYph8WRU3QXgIDcMWptQyAQ'
|
|
12
15
|
/* eslint-enable */
|
|
16
|
+
|
|
17
|
+
interface Config {
|
|
18
|
+
app: {
|
|
19
|
+
appId: string;
|
|
20
|
+
appName: string;
|
|
21
|
+
webDir: string;
|
|
22
|
+
package: {
|
|
23
|
+
version: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export const getConfig = async () => {
|
|
28
|
+
let config: Config;
|
|
29
|
+
try {
|
|
30
|
+
config = await loadConfig();
|
|
31
|
+
} catch (err) {
|
|
32
|
+
program.error("No capacitor config file found, run `cap init` first");
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
3
5
|
"module": "commonjs",
|
|
4
6
|
"esModuleInterop": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
5
8
|
"resolveJsonModule": true,
|
|
6
9
|
"target": "es6",
|
|
7
10
|
"moduleResolution": "node",
|
|
@@ -11,5 +14,5 @@
|
|
|
11
14
|
"lib": ["es2016", "dom"]
|
|
12
15
|
},
|
|
13
16
|
"include": ["src/**/*"],
|
|
14
|
-
"exclude": ["node_modules", "__tests__", "**/*.spec.ts"]
|
|
17
|
+
"exclude": ["node_modules", "dist", "__tests__", "**/*.spec.ts"]
|
|
15
18
|
}
|