@capgo/cli 4.12.12 → 4.12.14-beta.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/src/init.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
2
- import path from 'node:path'
3
2
  import type { ExecSyncOptions } from 'node:child_process'
4
3
  import { execSync, spawnSync } from 'node:child_process'
5
- import process from 'node:process'
4
+ import { exit } from 'node:process'
5
+ import { join } from 'node:path'
6
6
  import * as p from '@clack/prompts'
7
7
  import type LogSnag from 'logsnag'
8
8
  import semver from 'semver'
@@ -16,7 +16,7 @@ import { addAppInternal } from './app/add'
16
16
  import { checkLatest } from './api/update'
17
17
  import type { Options } from './api/app'
18
18
  import type { Organization } from './utils'
19
- import { convertAppName, createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findSavedKey, getConfig, getOrganization, getPMAndCommand, useLogSnag, verifyUser } from './utils'
19
+ import { convertAppName, createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findSavedKey, getConfig, getOrganization, getPMAndCommand, readPackageJson, useLogSnag, verifyUser } from './utils'
20
20
 
21
21
  interface SuperOptions extends Options {
22
22
  local: boolean
@@ -88,7 +88,7 @@ function cleanupStepsDone() {
88
88
  async function cancelCommand(command: boolean | symbol, orgId: string, snag: LogSnag) {
89
89
  if (p.isCancel(command)) {
90
90
  await markSnag('onboarding-v2', orgId, snag, 'canceled', '🤷')
91
- process.exit()
91
+ exit()
92
92
  }
93
93
  }
94
94
 
@@ -148,20 +148,20 @@ async function step4(orgId: string, snag: LogSnag, apikey: string, appId: string
148
148
  const s = p.spinner()
149
149
  s.start(`Checking if @capgo/capacitor-updater is installed`)
150
150
  let versionToInstall = 'latest'
151
- const pack = JSON.parse(readFileSync('package.json').toString())
151
+ const pack = await readPackageJson()
152
152
  let coreVersion = pack.dependencies['@capacitor/core'] || pack.devDependencies['@capacitor/core']
153
153
  coreVersion = coreVersion?.replace('^', '').replace('~', '')
154
154
  if (!coreVersion) {
155
155
  s.stop('Error')
156
156
  p.log.warn(`Cannot find @capacitor/core in package.json, please run \`capgo init\` in a capacitor project`)
157
157
  p.outro(`Bye 👋`)
158
- process.exit()
158
+ exit()
159
159
  }
160
160
  else if (semver.lt(coreVersion, '5.0.0')) {
161
161
  s.stop('Error')
162
162
  p.log.warn(`@capacitor/core version is ${coreVersion}, please update to Capacitor v5 first: ${urlMigrateV5}`)
163
163
  p.outro(`Bye 👋`)
164
- process.exit()
164
+ exit()
165
165
  }
166
166
  else if (semver.lt(coreVersion, '6.0.0')) {
167
167
  s.stop(`@capacitor/core version is ${coreVersion}, please update to Capacitor v6: ${urlMigrateV6} to access the best features of Capgo`)
@@ -171,7 +171,7 @@ async function step4(orgId: string, snag: LogSnag, apikey: string, appId: string
171
171
  s.stop('Error')
172
172
  p.log.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm, bun or yarn`)
173
173
  p.outro(`Bye 👋`)
174
- process.exit()
174
+ exit()
175
175
  }
176
176
  // // use pm to install capgo
177
177
  // // run command pm install @capgo/capacitor-updater@latest
@@ -201,16 +201,16 @@ async function step5(orgId: string, snag: LogSnag, apikey: string, appId: string
201
201
  const projectType = await findProjectType()
202
202
  if (projectType === 'nuxtjs-js' || projectType === 'nuxtjs-ts') {
203
203
  // Nuxt.js specific logic
204
- const nuxtDir = path.join('plugins')
204
+ const nuxtDir = join('plugins')
205
205
  if (!existsSync(nuxtDir)) {
206
206
  mkdirSync(nuxtDir, { recursive: true })
207
207
  }
208
208
  let nuxtFilePath
209
209
  if (projectType === 'nuxtjs-ts') {
210
- nuxtFilePath = path.join(nuxtDir, 'capacitorUpdater.client.ts')
210
+ nuxtFilePath = join(nuxtDir, 'capacitorUpdater.client.ts')
211
211
  }
212
212
  else {
213
- nuxtFilePath = path.join(nuxtDir, 'capacitorUpdater.client.js')
213
+ nuxtFilePath = join(nuxtDir, 'capacitorUpdater.client.js')
214
214
  }
215
215
  const nuxtFileContent = `
216
216
  import { CapacitorUpdater } from '@capgo/capacitor-updater'
@@ -257,7 +257,7 @@ async function step5(orgId: string, snag: LogSnag, apikey: string, appId: string
257
257
  p.log.warn(`Cannot find the latest version of ${projectType}, you might need to upgrade to the latest version of ${projectType}`)
258
258
  }
259
259
  p.outro(`Bye 👋`)
260
- process.exit()
260
+ exit()
261
261
  }
262
262
 
263
263
  // Open main file and inject codeInject
@@ -270,7 +270,7 @@ async function step5(orgId: string, snag: LogSnag, apikey: string, appId: string
270
270
  s.stop('Error')
271
271
  p.log.warn(`Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/`)
272
272
  p.outro(`Bye 👋`)
273
- process.exit()
273
+ exit()
274
274
  }
275
275
 
276
276
  if (mainFileContent.includes(codeInject)) {
@@ -302,7 +302,7 @@ async function step6(orgId: string, snag: LogSnag, apikey: string, appId: string
302
302
  s.stop('Error')
303
303
  p.log.warn(`Cannot create key ❌`)
304
304
  p.outro(`Bye 👋`)
305
- process.exit(1)
305
+ exit(1)
306
306
  }
307
307
  else {
308
308
  s.stop(`key created 🔑`)
@@ -321,13 +321,13 @@ async function step7(orgId: string, snag: LogSnag, apikey: string, appId: string
321
321
  const projectType = await findProjectType()
322
322
  const buildCommand = await findBuildCommandForProjectType(projectType)
323
323
  s.start(`Running: ${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`)
324
- const pack = JSON.parse(readFileSync('package.json').toString())
324
+ const pack = await readPackageJson()
325
325
  // check in script build exist
326
326
  if (!pack.scripts[buildCommand]) {
327
327
  s.stop('Error')
328
328
  p.log.warn(`Cannot find ${buildCommand} script in package.json, please add it and run \`capgo init\` again`)
329
329
  p.outro(`Bye 👋`)
330
- process.exit()
330
+ exit()
331
331
  }
332
332
  execSync(`${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`, execOption as ExecSyncOptions)
333
333
  s.stop(`Build & Sync Done ✅`)
@@ -353,7 +353,7 @@ async function step8(orgId: string, snag: LogSnag, apikey: string, appId: string
353
353
  s.stop('Error')
354
354
  p.log.warn(`Upload failed ❌`)
355
355
  p.outro(`Bye 👋`)
356
- process.exit()
356
+ exit()
357
357
  }
358
358
  else {
359
359
  s.stop(`Upload Done ✅`)
@@ -379,7 +379,7 @@ async function step9(orgId: string, snag: LogSnag) {
379
379
  })
380
380
  if (p.isCancel(plaformType)) {
381
381
  p.outro(`Bye 👋`)
382
- process.exit()
382
+ exit()
383
383
  }
384
384
 
385
385
  const platform = plaformType as 'ios' | 'android'
@@ -413,8 +413,8 @@ export async function initApp(apikeyCommand: string, appId: string, options: Sup
413
413
  p.intro(`Capgo onboarding 🛫`)
414
414
  await checkLatest()
415
415
  const snag = useLogSnag()
416
- const config = await getConfig()
417
- appId = appId || config?.app?.appId
416
+ const extConfig = await getConfig()
417
+ appId = appId || extConfig?.config?.appId
418
418
  const apikey = apikeyCommand || findSavedKey()
419
419
 
420
420
  const log = p.spinner()
@@ -483,7 +483,7 @@ export async function initApp(apikeyCommand: string, appId: string, options: Sup
483
483
  catch (e) {
484
484
  console.error(e)
485
485
  p.log.error(`Error during onboarding, please try again later`)
486
- process.exit(1)
486
+ exit(1)
487
487
  }
488
488
 
489
489
  p.log.info(`Welcome onboard ✈️!`)
@@ -491,5 +491,5 @@ export async function initApp(apikeyCommand: string, appId: string, options: Sup
491
491
  p.log.info(`Next time use \`${pm.runner} @capgo/cli@latest bundle upload\` to only upload your bundle`)
492
492
  p.log.info(`If you have any issue try to use the debug command \`${pm.runner} @capgo/cli@latest app debug\``)
493
493
  p.outro(`Bye 👋`)
494
- process.exit()
494
+ exit()
495
495
  }
package/src/key.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs'
2
2
  import { program } from 'commander'
3
- import { writeConfig } from '@capacitor/cli/dist/config'
4
- import * as p from '@clack/prompts'
3
+ import { intro, log, outro } from '@clack/prompts'
4
+ import { writeConfig } from './config'
5
5
  import { createRSA } from './api/crypto'
6
6
  import { baseKey, baseKeyPub, getConfig } from './utils'
7
7
  import { checkLatest } from './api/update'
@@ -14,12 +14,11 @@ interface Options {
14
14
  force?: boolean
15
15
  }
16
16
 
17
- export async function saveKey(options: saveOptions, log = true) {
18
- if (log)
19
- p.intro(`Save keys 🔑`)
17
+ export async function saveKey(options: saveOptions, logg = true) {
18
+ if (logg)
19
+ intro(`Save keys 🔑`)
20
20
 
21
- const config = await getConfig()
22
- const { extConfig } = config.app
21
+ const extConfig = await getConfig()
23
22
 
24
23
  const keyPath = options.key || baseKey
25
24
  // check if publicKey exist
@@ -27,8 +26,8 @@ export async function saveKey(options: saveOptions, log = true) {
27
26
  let privateKey = options.keyData || ''
28
27
 
29
28
  if (!existsSync(keyPath) && !privateKey) {
30
- if (log) {
31
- p.log.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
29
+ if (logg) {
30
+ log.error(`Cannot find public key ${keyPath} or as keyData option or in ${extConfig.path}`)
32
31
  program.error('')
33
32
  }
34
33
  else {
@@ -41,43 +40,43 @@ export async function saveKey(options: saveOptions, log = true) {
41
40
  privateKey = keyFile.toString()
42
41
  }
43
42
 
44
- if (extConfig) {
45
- if (!extConfig.plugins) {
46
- extConfig.plugins = {
43
+ if (extConfig?.config) {
44
+ if (!extConfig.config.plugins) {
45
+ extConfig.config.plugins = {
47
46
  extConfig: {},
48
47
  CapacitorUpdater: {},
49
48
  }
50
49
  }
51
- if (!extConfig.plugins.CapacitorUpdater)
52
- extConfig.plugins.CapacitorUpdater = {}
50
+ if (!extConfig.config.plugins.CapacitorUpdater)
51
+ extConfig.config.plugins.CapacitorUpdater = {}
53
52
 
54
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
53
+ extConfig.config.plugins.CapacitorUpdater.privateKey = privateKey
55
54
  // console.log('extConfig', extConfig)
56
- writeConfig(extConfig, config.app.extConfigFilePath)
55
+ await writeConfig(extConfig)
57
56
  }
58
57
  if (log) {
59
- p.log.success(`private key saved into ${config.app.extConfigFilePath} file in local directory`)
60
- p.log.success(`your app will decode the zip archive with this key`)
58
+ log.success(`private key saved into ${extConfig.path} file in local directory`)
59
+ log.success(`your app will decode the zip archive with this key`)
61
60
  }
62
61
  return true
63
62
  }
64
63
  export async function saveKeyCommand(options: saveOptions) {
65
- p.intro(`Save keys 🔑`)
64
+ intro(`Save keys 🔑`)
66
65
  await checkLatest()
67
66
  await saveKey(options)
68
67
  }
69
68
 
70
- export async function createKey(options: Options, log = true) {
69
+ export async function createKey(options: Options, logg = true) {
71
70
  // write in file .capgo the apikey in home directory
72
- if (log)
73
- p.intro(`Create keys 🔑`)
71
+ if (logg)
72
+ intro(`Create keys 🔑`)
74
73
 
75
74
  const { publicKey, privateKey } = createRSA()
76
75
 
77
76
  // check if baseName already exist
78
77
  if (existsSync(baseKeyPub) && !options.force) {
79
- p.log.error('Public Key already exists, use --force to overwrite')
80
- if (log) {
78
+ log.error('Public Key already exists, use --force to overwrite')
79
+ if (logg) {
81
80
  program.error('')
82
81
  }
83
82
  else {
@@ -86,8 +85,8 @@ export async function createKey(options: Options, log = true) {
86
85
  }
87
86
  writeFileSync(baseKeyPub, publicKey)
88
87
  if (existsSync(baseKey) && !options.force) {
89
- p.log.error('Private Key already exists, use --force to overwrite')
90
- if (log) {
88
+ log.error('Private Key already exists, use --force to overwrite')
89
+ if (logg) {
91
90
  program.error('')
92
91
  }
93
92
  else {
@@ -96,36 +95,36 @@ export async function createKey(options: Options, log = true) {
96
95
  }
97
96
  writeFileSync(baseKey, privateKey)
98
97
 
99
- const config = await getConfig()
100
- const { extConfig } = config.app
101
- if (extConfig) {
102
- if (!extConfig.plugins) {
103
- extConfig.plugins = {
98
+ const extConfig = await getConfig()
99
+ if (extConfig?.config) {
100
+ if (!extConfig.config.plugins) {
101
+ extConfig.config.plugins = {
104
102
  extConfig: {},
105
103
  CapacitorUpdater: {},
106
104
  }
107
105
  }
108
106
 
109
- if (!extConfig.plugins.CapacitorUpdater) {
110
- extConfig.plugins.CapacitorUpdater = {}
107
+ if (!extConfig.config.plugins.CapacitorUpdater) {
108
+ extConfig.config.plugins.CapacitorUpdater = {}
111
109
  }
112
110
 
113
- extConfig.plugins.CapacitorUpdater.privateKey = privateKey
111
+ const flattenPrivateKey = privateKey.replace(/\\n/g, '\\n')
112
+ extConfig.config.plugins.CapacitorUpdater.privateKey = flattenPrivateKey
114
113
  // console.log('extConfig', extConfig)
115
- writeConfig(extConfig, config.app.extConfigFilePath)
114
+ writeConfig(extConfig)
116
115
  }
117
116
 
118
- if (log) {
119
- p.log.success('Your RSA key has been generated')
120
- p.log.success(`Public key saved in ${baseKeyPub}`)
121
- p.log.success('This key will be use to encrypt your bundle before sending it to Capgo')
122
- p.log.success('Keep it safe')
123
- p.log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
124
- p.log.success(`Private key saved in ${config.app.extConfigFilePath}`)
125
- p.log.success('Your app will be the only one having it')
126
- p.log.success('Only your users can decrypt your update')
127
- p.log.success('Only you can send them an update')
128
- p.outro(`Done ✅`)
117
+ if (logg) {
118
+ log.success('Your RSA key has been generated')
119
+ log.success(`Public key saved in ${baseKeyPub}`)
120
+ log.success('This key will be use to encrypt your bundle before sending it to Capgo')
121
+ log.success('Keep it safe')
122
+ log.success('Than make it unreadable by Capgo and unmodifiable by anyone')
123
+ log.success(`Private key saved in ${extConfig.path}`)
124
+ log.success('Your app will be the only one having it')
125
+ log.success('Only your users can decrypt your update')
126
+ log.success('Only you can send them an update')
127
+ outro(`Done ✅`)
129
128
  }
130
129
  return true
131
130
  }
package/src/login.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { appendFileSync, existsSync, writeFileSync } from 'node:fs'
2
2
  import { homedir } from 'node:os'
3
- import process from 'node:process'
3
+ import { exit } from 'node:process'
4
4
  import { program } from 'commander'
5
- import * as p from '@clack/prompts'
5
+ import { intro, log, outro } from '@clack/prompts'
6
6
  import { createSupabaseClient, useLogSnag, verifyUser } from './utils'
7
7
  import { checkLatest } from './api/update'
8
8
 
@@ -16,11 +16,11 @@ export async function doLoginExists() {
16
16
 
17
17
  export async function login(apikey: string, options: Options, shouldExit = true) {
18
18
  if (shouldExit)
19
- p.intro(`Login to Capgo`)
19
+ intro(`Login to Capgo`)
20
20
 
21
21
  if (!apikey) {
22
22
  if (shouldExit) {
23
- p.log.error('Missing API key, you need to provide a API key to upload your bundle')
23
+ log.error('Missing API key, you need to provide a API key to upload your bundle')
24
24
  program.error('')
25
25
  }
26
26
  return false
@@ -33,7 +33,7 @@ export async function login(apikey: string, options: Options, shouldExit = true)
33
33
 
34
34
  if (local) {
35
35
  if (!existsSync('.git')) {
36
- p.log.error('To use local you should be in a git repository')
36
+ log.error('To use local you should be in a git repository')
37
37
  program.error('')
38
38
  }
39
39
  writeFileSync('.capgo', `${apikey}\n`)
@@ -52,15 +52,15 @@ export async function login(apikey: string, options: Options, shouldExit = true)
52
52
  user_id: userId,
53
53
  notify: false,
54
54
  }).catch()
55
- p.log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
55
+ log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`)
56
56
  }
57
57
  catch (e) {
58
- p.log.error(`Error while saving login`)
59
- process.exit(1)
58
+ log.error(`Error while saving login`)
59
+ exit(1)
60
60
  }
61
61
  if (shouldExit) {
62
- p.outro('Done ✅')
63
- process.exit()
62
+ outro('Done ✅')
63
+ exit()
64
64
  }
65
65
  return true
66
66
  }
@@ -1,11 +1,11 @@
1
- import * as p from '@clack/prompts'
1
+ import { intro, outro } from '@clack/prompts'
2
2
  import { createSupabaseClient, findSavedKey, verifyUser } from '../utils'
3
3
  import type { Options } from '../api/app'
4
4
 
5
5
  export async function getUserId(options: Options) {
6
- p.intro(`Getting user id`)
6
+ intro(`Getting user id`)
7
7
  options.apikey = options.apikey || findSavedKey()
8
8
  const supabase = await createSupabaseClient(options.apikey)
9
9
  const userId = await verifyUser(supabase, options.apikey, ['read'])
10
- p.outro(`Done ✅: ${userId}`)
10
+ outro(`Done ✅: ${userId}`)
11
11
  }