@capgo/cli 5.0.0-alpha.7 → 7.0.1

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.
Files changed (59) hide show
  1. package/README.md +197 -41
  2. package/dist/index.js +335 -95820
  3. package/dist/package.json +83 -0
  4. package/package.json +48 -62
  5. package/.eslintignore +0 -4
  6. package/.github/FUNDING.yml +0 -1
  7. package/.github/workflows/build.yml +0 -46
  8. package/.github/workflows/bump_version.yml +0 -56
  9. package/.github/workflows/test.yml +0 -30
  10. package/.prettierignore +0 -6
  11. package/.vscode/launch.json +0 -23
  12. package/.vscode/settings.json +0 -5
  13. package/.vscode/tasks.json +0 -42
  14. package/CHANGELOG.md +0 -2861
  15. package/build.mjs +0 -23
  16. package/bun.lockb +0 -0
  17. package/capacitor.config.ts +0 -33
  18. package/crypto_explained.png +0 -0
  19. package/eslint.config.js +0 -3
  20. package/renovate.json +0 -23
  21. package/src/api/app.ts +0 -75
  22. package/src/api/channels.ts +0 -140
  23. package/src/api/crypto.ts +0 -121
  24. package/src/api/devices_override.ts +0 -41
  25. package/src/api/update.ts +0 -12
  26. package/src/api/versions.ts +0 -101
  27. package/src/app/add.ts +0 -191
  28. package/src/app/debug.ts +0 -220
  29. package/src/app/delete.ts +0 -106
  30. package/src/app/info.ts +0 -87
  31. package/src/app/list.ts +0 -67
  32. package/src/app/set.ts +0 -94
  33. package/src/bundle/check.ts +0 -42
  34. package/src/bundle/cleanup.ts +0 -127
  35. package/src/bundle/compatibility.ts +0 -70
  36. package/src/bundle/decrypt.ts +0 -65
  37. package/src/bundle/delete.ts +0 -53
  38. package/src/bundle/encrypt.ts +0 -69
  39. package/src/bundle/list.ts +0 -43
  40. package/src/bundle/unlink.ts +0 -86
  41. package/src/bundle/upload.ts +0 -516
  42. package/src/bundle/zip.ts +0 -139
  43. package/src/channel/add.ts +0 -73
  44. package/src/channel/currentBundle.ts +0 -72
  45. package/src/channel/delete.ts +0 -51
  46. package/src/channel/list.ts +0 -49
  47. package/src/channel/set.ts +0 -174
  48. package/src/index.ts +0 -290
  49. package/src/init.ts +0 -301
  50. package/src/key.ts +0 -158
  51. package/src/login.ts +0 -66
  52. package/src/types/capacitor__cli.d.ts +0 -6
  53. package/src/types/supabase.types.ts +0 -2471
  54. package/src/utils.ts +0 -738
  55. package/test/chunk_convert.ts +0 -28
  56. package/test/data.ts +0 -18769
  57. package/test/test_headers_rls.ts +0 -24
  58. package/test/test_semver.ts +0 -13
  59. package/tsconfig.json +0 -39
package/src/index.ts DELETED
@@ -1,290 +0,0 @@
1
- import { program } from 'commander'
2
- import pack from '../package.json'
3
- import { zipBundle } from './bundle/zip'
4
- import { initApp } from './init'
5
- import { listBundle } from './bundle/list'
6
- import { decryptZip } from './bundle/decrypt'
7
- import { encryptZip } from './bundle/encrypt'
8
- import { addCommand } from './app/add'
9
- import { getInfo } from './app/info'
10
- import { createKeyCommand, saveKeyCommand } from './key'
11
- import { deleteBundle } from './bundle/delete'
12
- import { setChannel } from './channel/set'
13
- import { currentBundle } from './channel/currentBundle'
14
- import { uploadCommand, uploadDeprecatedCommand } from './bundle/upload'
15
- import { loginCommand } from './login'
16
- import { listApp } from './app/list'
17
- import { cleanupBundle } from './bundle/cleanup'
18
- import { addChannelCommand } from './channel/add'
19
- import { deleteChannel } from './channel/delete'
20
- import { listChannels } from './channel/list'
21
- import { setApp } from './app/set'
22
- import { deleteApp } from './app/delete'
23
-
24
- // import { watchApp } from './app/watch';
25
- import { debugApp } from './app/debug'
26
- import { checkCompatibilityCommand } from './bundle/compatibility'
27
-
28
- program
29
- .name(pack.name)
30
- .description('Manage packages and bundle versions in Capgo Cloud')
31
- .version(pack.version)
32
-
33
- program
34
- .command('login [apikey]')
35
- .alias('l')
36
- .description('Save apikey to your machine or folder')
37
- .action(loginCommand)
38
- .option('--local', 'Only save in local folder')
39
-
40
- program
41
- .command('doctor')
42
- .description('Get info about your Capgo app install')
43
- .action(getInfo)
44
-
45
- program
46
- .command('init [apikey] [appId]')
47
- .description('Init a new app')
48
- .action(initApp)
49
- .option('-n, --name <name>', 'app name')
50
- .option('-i, --icon <icon>', 'app icon path')
51
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
52
-
53
- const app = program
54
- .command('app')
55
- .description('Manage app')
56
-
57
- app
58
- .command('add [appId]')
59
- .alias('a')
60
- .description('Add a new app in Capgo Cloud')
61
- .action(addCommand)
62
- .option('-n, --name <name>', 'app name')
63
- .option('-i, --icon <icon>', 'app icon path')
64
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
65
-
66
- app
67
- .command('delete [appId]')
68
- .description('Delete an app in Capgo Cloud')
69
- .action(deleteApp)
70
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
71
-
72
- app
73
- .command('list')
74
- .alias('l')
75
- .description('list apps in Capgo Cloud')
76
- .action(listApp)
77
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
78
-
79
- app
80
- .command('debug [appId]')
81
- .description('Listen for live updates event in Capgo Cloud to debug your app')
82
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
83
- .option('-d, --device <device>', 'the specific device to debug')
84
- .action(debugApp)
85
-
86
- // app
87
- // .command('watch [port]')
88
- // .alias('w')
89
- // .description('watch for changes in your app and allow capgo app or your app to see changes in live')
90
- // .action(watchApp);
91
-
92
- app
93
- .command('set [appId]')
94
- .alias('s')
95
- .description('Set an app in Capgo Cloud')
96
- .action(setApp)
97
- .option('-n, --name <name>', 'app name')
98
- .option('-i, --icon <icon>', 'app icon path')
99
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
100
- .option('-r, --retention <retention>', 'retention period of app bundle in days')
101
-
102
- const bundle = program
103
- .command('bundle')
104
- .description('Manage bundle')
105
-
106
- bundle
107
- .command('upload [appId]')
108
- .alias('u')
109
- .description('Upload a new bundle in Capgo Cloud')
110
- .action(uploadCommand)
111
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
112
- .option('-p, --path <path>', 'path of the folder to upload')
113
- .option('-c, --channel <channel>', 'channel to link to')
114
- .option('-e, --external <url>', 'link to external url intead of upload to Capgo Cloud')
115
- .option('--iv-session-key <key>', 'Set the iv and session key for bundle url external')
116
- .option('--s3-region <region>', 'Region for your AWS S3 bucket')
117
- .option('--s3-apikey <apikey>', 'apikey for your AWS S3 account')
118
- .option('--s3-apisecret <apisecret>', 'api secret for your AWS S3 account')
119
- .option('--s3-bucket-name <bucketName>', 'Name for your AWS S3 bucket')
120
- .option('--key <key>', 'custom path for public signing key')
121
- .option('--key-data <keyData>', 'base64 public signing key')
122
- .option('--bundle-url', 'prints bundle url into stdout')
123
- .option('--no-key', 'ignore signing key and send clear update')
124
- .option('--no-code-check', 'Ignore checking if notifyAppReady() is called in soure code and index present in root folder')
125
- .option('--display-iv-session', 'Show in the console the iv and session key used to encrypt the update')
126
- .option('-b, --bundle <bundle>', 'bundle version number of the bundle to upload')
127
- .option(
128
- '--min-update-version <minUpdateVersion>',
129
- 'Minimal version required to update to this version. Used only if the disable auto update is set to metadata in channel',
130
- )
131
- .option('--auto-min-update-version', 'Set the min update version based on native packages')
132
- .option('--ignore-metadata-check', 'Ignores the metadata (node_modules) check when uploading')
133
-
134
- bundle
135
- .command('compatibility [appId]')
136
- .action(checkCompatibilityCommand)
137
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
138
- .option('-c, --channel <channel>', 'channel to check the compatibility with')
139
- .option('--text', 'output text instead of emojis')
140
-
141
- bundle
142
- .command('delete [bundleId] [appId]')
143
- .alias('d')
144
- .description('Delete a bundle in Capgo Cloud')
145
- .action(deleteBundle)
146
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
147
-
148
- bundle
149
- .command('list [appId]')
150
- .alias('l')
151
- .description('List bundle in Capgo Cloud')
152
- .action(listBundle)
153
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
154
-
155
- // TODO: Fix this command!
156
- // bundle
157
- // .command('unlink [appId]')
158
- // .description('Unlink a bundle in Capgo Cloud')
159
- // .action(listBundle)
160
- // .option('-a, --apikey <apikey>', 'apikey to link to your account')
161
- // .option('-b, --bundle <bundle>', 'bundle version number of the bundle to unlink')
162
-
163
- bundle
164
- .command('cleanup [appId]')
165
- .alias('c')
166
- .action(cleanupBundle)
167
- .description('Cleanup bundle in Capgo Cloud')
168
- .option('-b, --bundle <bundle>', 'bundle version number of the app to delete')
169
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
170
- .option('-k, --keep <keep>', 'number of version to keep')
171
- .option('-f, --force', 'force removal')
172
-
173
- bundle
174
- .command('decrypt [zipPath] [sessionKey]')
175
- .description('Decrypt a signed zip bundle')
176
- .action(decryptZip)
177
- .option('--key <key>', 'custom path for public signing key')
178
- .option('--key-data <keyData>', 'base64 public signing key')
179
-
180
- bundle
181
- .command('encrypt [zipPath]')
182
- .description('Encrypt a zip bundle')
183
- .action(encryptZip)
184
- .option('--key <key>', 'custom path for private signing key')
185
- .option('--key-data <keyData>', 'base64 private signing key')
186
-
187
- bundle
188
- .command('zip [appId]')
189
- .description('Zip a bundle')
190
- .action(zipBundle)
191
- .option('-p, --path <path>', 'path of the folder to upload')
192
- .option('-b, --bundle <bundle>', 'bundle version number to name the zip file')
193
- .option('-n, --name <name>', 'name of the zip file')
194
- .option('-j, --json', 'output in JSON')
195
- .option('--no-code-check', 'Ignore checking if notifyAppReady() is called in soure code and index present in root folder')
196
-
197
- const channel = program
198
- .command('channel')
199
- .description('Manage channel')
200
-
201
- channel
202
- .command('add [channelId] [appId]')
203
- .alias('a')
204
- .description('Create channel')
205
- .action(addChannelCommand)
206
- .option('-d, --default', 'set the channel as default')
207
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
208
-
209
- channel
210
- .command('delete [channelId] [appId]')
211
- .alias('d')
212
- .description('Delete channel')
213
- .action(deleteChannel)
214
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
215
-
216
- channel
217
- .command('list [appId]')
218
- .alias('l')
219
- .description('List channel')
220
- .action(listChannels)
221
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
222
-
223
- channel
224
- .command('currentBundle [channel] [appId]')
225
- .description('Get current bundle for specific channel in Capgo Cloud')
226
- .action(currentBundle)
227
- .option('-c, --channel <channel>', 'channel to get the current bundle from')
228
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
229
- .option('--quiet', 'only print the bundle version')
230
-
231
- channel
232
- .command('set [channelId] [appId]')
233
- .alias('s')
234
- .description('Set channel')
235
- .action(setChannel)
236
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
237
- .option('-b, --bundle <bundle>', 'bundle version number of the file to set')
238
- .option('-s, --state <state>', 'set the state of the channel, default or normal')
239
- .option('--latest', 'get the latest version key in the package.json to set it to the channel')
240
- .option('--downgrade', 'Allow to downgrade to version under native one')
241
- .option('--no-downgrade', 'Disable downgrade to version under native one')
242
- .option('--upgrade', 'Allow to upgrade to version above native one')
243
- .option('--no-upgrade', 'Disable upgrade to version above native one')
244
- .option('--ios', 'Allow sending update to ios devices')
245
- .option('--no-ios', 'Disable sending update to ios devices')
246
- .option('--android', 'Allow sending update to android devices')
247
- .option('--no-android', 'Disable sending update to android devices')
248
- .option('--self-assign', 'Allow to device to self assign to this channel')
249
- .option('--no-self-assign', 'Disable devices to self assign to this channel')
250
- .option('--disable-auto-update <disableAutoUpdate>', 'Disable auto update strategy for this channel.The possible options are: major, minor, metadata, patch, none')
251
-
252
- const key = program
253
- .command('key')
254
- .description('Manage key')
255
-
256
- key
257
- .command('save')
258
- .description('Save base64 signing key in capacitor config, useful for CI')
259
- .action(saveKeyCommand)
260
- .option('-f, --force', 'force generate a new one')
261
- .option('--key', 'key path to save in capacitor config')
262
- .option('--key-data <keyData>', 'key data to save in capacitor config')
263
-
264
- key
265
- .command('create')
266
- .description('Create a new signing key')
267
- .action(createKeyCommand)
268
- .option('-f, --force', 'force generate a new one')
269
-
270
- program
271
- .command('upload [appId]')
272
- .alias('u')
273
- .description('(Deprecated) Upload a new bundle to Capgo Cloud')
274
- .action(uploadDeprecatedCommand)
275
- .option('-a, --apikey <apikey>', 'apikey to link to your account')
276
- .option('-p, --path <path>', 'path of the folder to upload')
277
- .option('-c, --channel <channel>', 'channel to link to')
278
- .option('-e, --external <url>', 'link to external url intead of upload to Capgo Cloud')
279
- .option('--key <key>', 'custom path for public signing key')
280
- .option('--key-data <keyData>', 'base64 public signing key')
281
- .option('--bundle-url', 'prints bundle url into stdout')
282
- .option('--no-key', 'ignore signing key and send clear update')
283
- .option('--display-iv-session', 'Show in the console the iv and session key used to encrypt the update')
284
- .option('-b, --bundle <bundle>', 'bundle version number of the file to upload')
285
- .option(
286
- '--min-update-version <minUpdateVersion>',
287
- 'Minimal version required to update to this version. Used only if the disable auto update is set to metadata in channel',
288
- )
289
-
290
- program.parseAsync()
package/src/init.ts DELETED
@@ -1,301 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'node:fs'
2
- import type { ExecSyncOptions } from 'node:child_process'
3
- import { execSync, spawnSync } from 'node:child_process'
4
- import process from 'node:process'
5
- import { findPackageManagerType } from '@capgo/find-package-manager'
6
- import * as p from '@clack/prompts'
7
- import type { SupabaseClient } from '@supabase/supabase-js'
8
- import type LogSnag from 'logsnag'
9
- import semver from 'semver'
10
- import type { Database } from './types/supabase.types'
11
- import { markSnag, waitLog } from './app/debug'
12
- import { createKey } from './key'
13
- import { addChannel } from './channel/add'
14
- import { uploadBundle } from './bundle/upload'
15
- import { login } from './login'
16
- import { addApp } from './app/add'
17
- import { checkLatest } from './api/update'
18
- import type { Options } from './api/app'
19
- import { convertAppName, createSupabaseClient, findMainFile, findSavedKey, getConfig, useLogSnag, verifyUser } from './utils'
20
-
21
- interface SuperOptions extends Options {
22
- local: boolean
23
- }
24
- const importInject = 'import { CapacitorUpdater } from \'@capgo/capacitor-updater\''
25
- const codeInject = 'CapacitorUpdater.notifyAppReady()'
26
- // create regex to find line who start by 'import ' and end by ' from '
27
- const regexImport = /import.*from.*/g
28
- const defaultChannel = 'production'
29
- const execOption = { stdio: 'pipe' }
30
-
31
- async function cancelCommand(command: boolean | symbol, userId: string, snag: LogSnag) {
32
- if (p.isCancel(command)) {
33
- await markSnag('onboarding-v2', userId, snag, 'canceled', '🤷')
34
- process.exit()
35
- }
36
- }
37
-
38
- async function markStep(userId: string, snag: LogSnag, step: number | string) {
39
- return markSnag('onboarding-v2', userId, snag, `onboarding-step-${step}`)
40
- }
41
-
42
- async function step2(userId: string, snag: LogSnag, appId: string, options: SuperOptions) {
43
- const doAdd = await p.confirm({ message: `Add ${appId} in Capgo?` })
44
- await cancelCommand(doAdd, userId, snag)
45
- if (doAdd) {
46
- const s = p.spinner()
47
- s.start(`Running: npx @capgo/cli@latest app add ${appId}`)
48
- const addRes = await addApp(appId, options, false)
49
- if (!addRes)
50
- s.stop(`App already add ✅`)
51
- else
52
- s.stop(`App add Done ✅`)
53
- }
54
- else {
55
- p.log.info(`Run yourself "npx @capgo/cli@latest app add ${appId}"`)
56
- }
57
- await markStep(userId, snag, 2)
58
- }
59
-
60
- async function step3(userId: string, snag: LogSnag, apikey: string, appId: string) {
61
- const doChannel = await p.confirm({ message: `Create default channel ${defaultChannel} for ${appId} in Capgo?` })
62
- await cancelCommand(doChannel, userId, snag)
63
- if (doChannel) {
64
- const s = p.spinner()
65
- // create production channel public
66
- s.start(`Running: npx @capgo/cli@latest channel add ${defaultChannel} ${appId} --default`)
67
- const addChannelRes = await addChannel(defaultChannel, appId, {
68
- default: true,
69
- apikey,
70
- }, false)
71
- if (!addChannelRes)
72
- s.stop(`Channel already added ✅`)
73
- else
74
- s.stop(`Channel add Done ✅`)
75
- }
76
- else {
77
- p.log.info(`Run yourself "npx @capgo/cli@latest channel add ${defaultChannel} ${appId} --default"`)
78
- }
79
- await markStep(userId, snag, 3)
80
- }
81
-
82
- const urlMigrateV5 = 'https://capacitorjs.com/docs/updating/5-0'
83
- async function step4(userId: string, snag: LogSnag, apikey: string, appId: string) {
84
- const doInstall = await p.confirm({ message: `Automatic Install "@capgo/capacitor-updater" dependency in ${appId}?` })
85
- await cancelCommand(doInstall, userId, snag)
86
- if (doInstall) {
87
- const s = p.spinner()
88
- s.start(`Checking if @capgo/capacitor-updater is installed`)
89
- const pack = JSON.parse(readFileSync('package.json').toString())
90
- let coreVersion = pack.dependencies['@capacitor/core'] || pack.devDependencies['@capacitor/core']
91
- coreVersion = coreVersion?.replace('^', '').replace('~', '')
92
- if (!coreVersion) {
93
- s.stop(`Cannot find @capacitor/core in package.json, please run \`capgo init\` in a capacitor project`)
94
- process.exit()
95
- }
96
- else if (semver.lt(coreVersion, '5.0.0')) {
97
- s.stop(`@capacitor/core version is ${coreVersion}, please update to Capacitor v5 first: ${urlMigrateV5}`)
98
- process.exit()
99
- }
100
- const pm = findPackageManagerType()
101
- if (pm === 'unknown') {
102
- s.stop(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm or yarn`)
103
- process.exit()
104
- }
105
- // // use pm to install capgo
106
- // // run command pm install @capgo/capacitor-updater@latest
107
- const installCmd = pm === 'yarn' ? 'add' : 'install'
108
- // check if capgo is already installed in package.json
109
- if (pack.dependencies['@capgo/capacitor-updater']) {
110
- s.stop(`Capgo already installed ✅`)
111
- }
112
- else {
113
- await execSync(`${pm} ${installCmd} @capgo/capacitor-updater@latest`, execOption as ExecSyncOptions)
114
- s.stop(`Install Done ✅`)
115
- }
116
- }
117
- else {
118
- p.log.info(`Run yourself "npm i @capgo/capacitor-updater@latest"`)
119
- }
120
- await markStep(userId, snag, 4)
121
- }
122
-
123
- async function step5(userId: string, snag: LogSnag, apikey: string, appId: string) {
124
- const doAddCode = await p.confirm({ message: `Automatic Add "${codeInject}" code and import in ${appId}?` })
125
- await cancelCommand(doAddCode, userId, snag)
126
- if (doAddCode) {
127
- const s = p.spinner()
128
- s.start(`Adding @capacitor-updater to your main file`)
129
- const mainFilePath = await findMainFile()
130
- if (!mainFilePath) {
131
- s.stop('No main.ts, main.js, index.ts or index.js file found, You need to add @capgo/capacitor-updater manually')
132
- process.exit()
133
- }
134
- // open main file and inject codeInject
135
- const mainFile = readFileSync(mainFilePath)
136
- // find the last import line in the file and inject codeInject after it
137
- const mainFileContent = mainFile.toString()
138
- const matches = mainFileContent.match(regexImport)
139
- const last = matches?.pop()
140
- if (!last) {
141
- s.stop(`Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/`)
142
- process.exit()
143
- }
144
-
145
- if (mainFileContent.includes(codeInject)) {
146
- s.stop(`Code already added to ${mainFilePath} ✅`)
147
- }
148
- else {
149
- const newMainFileContent = mainFileContent.replace(last, `${last}\n${importInject};\n\n${codeInject};\n`)
150
- writeFileSync(mainFilePath, newMainFileContent)
151
- s.stop(`Code added to ${mainFilePath} ✅`)
152
- }
153
- await markStep(userId, snag, 5)
154
- }
155
- else {
156
- p.log.info(`Add to your main file the following code:\n\n${importInject};\n\n${codeInject};\n`)
157
- }
158
- }
159
-
160
- async function step6(userId: string, snag: LogSnag, apikey: string, appId: string) {
161
- const doEncrypt = await p.confirm({ message: `Automatic configure end-to-end encryption in ${appId} updates?` })
162
- await cancelCommand(doEncrypt, userId, snag)
163
- if (doEncrypt) {
164
- const s = p.spinner()
165
- s.start(`Running: npx @capgo/cli@latest key create`)
166
- const keyRes = await createKey({}, false)
167
- if (!keyRes) {
168
- s.stop(`Cannot create key ❌`)
169
- process.exit(1)
170
- }
171
- else {
172
- s.stop(`key created 🔑`)
173
- }
174
- markSnag('onboarding-v2', userId, snag, 'Use encryption')
175
- }
176
- await markStep(userId, snag, 6)
177
- }
178
-
179
- async function step7(userId: string, snag: LogSnag, apikey: string, appId: string) {
180
- const doBuild = await p.confirm({ message: `Automatic build ${appId} with "npm run build" ?` })
181
- await cancelCommand(doBuild, userId, snag)
182
- if (doBuild) {
183
- const s = p.spinner()
184
- s.start(`Running: npm run build && npx cap sync`)
185
- const pack = JSON.parse(readFileSync('package.json').toString())
186
- // check in script build exist
187
- if (!pack.scripts?.build) {
188
- s.stop(`Cannot find build script in package.json, please add it and run \`capgo init\` again`)
189
- process.exit()
190
- }
191
- execSync(`npm run build && npx cap sync`, execOption as ExecSyncOptions)
192
- s.stop(`Build & Sync Done ✅`)
193
- }
194
- else {
195
- p.log.info(`Build yourself with command: npm run build && npx cap sync`)
196
- }
197
- await markStep(userId, snag, 7)
198
- }
199
-
200
- async function step8(userId: string, snag: LogSnag, apikey: string, appId: string) {
201
- const doBundle = await p.confirm({ message: `Automatic upload ${appId} bundle to Capgo?` })
202
- await cancelCommand(doBundle, userId, snag)
203
- if (doBundle) {
204
- const s = p.spinner()
205
- s.start(`Running: npx @capgo/cli@latest bundle upload`)
206
- const uploadRes = await uploadBundle(appId, {
207
- channel: defaultChannel,
208
- apikey,
209
- }, false)
210
- if (!uploadRes) {
211
- s.stop(`Upload failed ❌`)
212
- process.exit()
213
- }
214
- else {
215
- s.stop(`Upload Done ✅`)
216
- }
217
- }
218
- else {
219
- p.log.info(`Upload yourself with command: npx @capgo/cli@latest bundle upload`)
220
- }
221
- await markStep(userId, snag, 8)
222
- }
223
-
224
- async function step9(userId: string, snag: LogSnag) {
225
- const doRun = await p.confirm({ message: `Run in device now ?` })
226
- await cancelCommand(doRun, userId, snag)
227
- if (doRun) {
228
- const plaformType = await p.select({
229
- message: 'Pick a platform to run your app',
230
- options: [
231
- { value: 'ios', label: 'IOS' },
232
- { value: 'android', label: 'Android' },
233
- ],
234
- })
235
- if (p.isCancel(plaformType))
236
- process.exit()
237
-
238
- const platform = plaformType as 'ios' | 'android'
239
- const s = p.spinner()
240
- s.start(`Running: npx cap run ${platform}`)
241
- await spawnSync('npx', ['cap', 'run', platform], { stdio: 'inherit' })
242
- s.stop(`Started Done ✅`)
243
- }
244
- else {
245
- p.log.info(`Run yourself with command: npx cap run <ios|android>`)
246
- }
247
- await markStep(userId, snag, 9)
248
- }
249
-
250
- async function step10(userId: string, snag: LogSnag, supabase: SupabaseClient<Database>, appId: string) {
251
- const doRun = await p.confirm({ message: `Automatic check if update working in device ?` })
252
- await cancelCommand(doRun, userId, snag)
253
- if (doRun) {
254
- p.log.info(`Wait logs sent to Capgo from ${appId} device, Put the app in background and open it again.`)
255
- p.log.info('Waiting...')
256
- await waitLog('onboarding-v2', supabase, appId, snag, userId)
257
- }
258
- else {
259
- const appIdUrl = convertAppName(appId)
260
- p.log.info(`Check logs in https://web.capgo.app/app/p/${appIdUrl}/logs to see if update works.`)
261
- }
262
- await markStep(userId, snag, 10)
263
- }
264
-
265
- export async function initApp(apikey: string, appId: string, options: SuperOptions) {
266
- p.intro(`Capgo onboarding 🛫`)
267
- await checkLatest()
268
- const snag = useLogSnag()
269
- const config = await getConfig()
270
- appId = appId || config?.app?.appId
271
- apikey = apikey || findSavedKey()
272
-
273
- const log = p.spinner()
274
- log.start('Running: npx @capgo/cli@latest login ***')
275
- const loginRes = await login(apikey, options, false)
276
- if (!loginRes)
277
- log.stop('Login already done ✅')
278
- else
279
- log.stop('Login Done ✅')
280
-
281
- const supabase = await createSupabaseClient(apikey)
282
- const userId = await verifyUser(supabase, apikey, ['upload', 'all', 'read', 'write'])
283
- await markStep(userId, snag, 1)
284
-
285
- await step2(userId, snag, appId, options)
286
- await step3(userId, snag, apikey, appId)
287
- await step4(userId, snag, apikey, appId)
288
- await step5(userId, snag, apikey, appId)
289
- await step6(userId, snag, apikey, appId)
290
- await step7(userId, snag, apikey, appId)
291
- await step8(userId, snag, apikey, appId)
292
- await step9(userId, snag)
293
- await step10(userId, snag, supabase, appId)
294
-
295
- await markStep(userId, snag, 0)
296
- p.log.info(`Welcome onboard ✈️!`)
297
- p.log.info(`Your Capgo update system is setup`)
298
- p.log.info(`Next time use \`npx @capgo/cli@latest bundle upload\` to only upload your bundle`)
299
- p.outro(`Bye 👋`)
300
- process.exit()
301
- }