Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions src/init/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { addAppInternal } from '../app/add'
import { markSnag, waitLog } from '../app/debug'
import { canUseFilePicker, openPackageJsonPicker } from '../build/onboarding/file-picker'
import { getPlatformDirFromCapacitorConfig } from '../build/platform-paths'
import { uploadBundleInternal } from '../bundle/upload'
import { addChannelInternal } from '../channel/add'
import { writeConfigUpdater } from '../config'
Expand Down Expand Up @@ -1371,9 +1372,15 @@
const pm = getPMAndCommand()
let pkgVersion = '1.0.0'
let delta = false
const doInstall = await pConfirm({ message: `Automatic Install "@capgo/capacitor-updater" dependency in ${appId}?` })
await cancelCommand(doInstall, orgId, apikey)
if (doInstall) {
const installChoice = await pSelect({
message: `Install @capgo/capacitor-updater in your project?`,
options: [
{ value: 'yes', label: '✅ Yes, install it' },
{ value: 'no', label: '❌ No, I\'ll do it manually' },
],
})
await cancelCommand(installChoice, orgId, apikey)
if (installChoice === 'yes') {
while (true) {
const s = pSpinner()
let versionToInstall = 'latest'
Expand Down Expand Up @@ -1462,10 +1469,16 @@
}

async function addCodeStep(orgId: string, apikey: string, appId: string) {
const doAddCode = await pConfirm({ message: `Automatic Add "${codeInject}" code and import in ${appId}?` })
await cancelCommand(doAddCode, orgId, apikey)
const addCodeChoice = await pSelect({
message: `Add the Capacitor Updater import to your main file?`,
options: [
{ value: 'yes', label: '✅ Yes, add it' },
{ value: 'no', label: '❌ No, I\'ll do it manually' },
],
})
await cancelCommand(addCodeChoice, orgId, apikey)

if (doAddCode) {
if (addCodeChoice === 'yes') {
const s = pSpinner()
s.start(`Adding @capacitor-updater to your main file`)

Expand Down Expand Up @@ -2305,6 +2318,46 @@
localSupaAnon: options.supaAnon,
})
}
// Warn if this doesn't look like a Capacitor project
const hasCapacitorConfig = capacitorConfigFiles.some(file => existsSync(join(cwd(), file)))
if (!hasCapacitorConfig) {

Check warning on line 2323 in src/init/command.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=Cap-go_capgo-cli&issues=AZ0eQ-RjJ_uSqP-KJgfs&open=AZ0eQ-RjJ_uSqP-KJgfs&pullRequest=570
pLog.warn('⚠️ No capacitor.config.* found in the current directory.')
pLog.info(' Capgo requires a Capacitor project. Make sure you run this from your project root.')
pLog.info(' Learn more: https://capacitorjs.com/docs/getting-started')
const continueAnyway = await pSelect({
message: 'Continue anyway?',
options: [
{ value: 'yes', label: '✅ Yes, continue' },
{ value: 'no', label: '❌ No, exit' },
],
})
if (pIsCancel(continueAnyway) || continueAnyway === 'no') {
pOutro('Bye 👋')
exit()
}
}
else {
const iosDir = getPlatformDirFromCapacitorConfig(extConfig?.config, 'ios')
const androidDir = getPlatformDirFromCapacitorConfig(extConfig?.config, 'android')
const hasIos = existsSync(join(cwd(), iosDir))
const hasAndroid = existsSync(join(cwd(), androidDir))
if (!hasIos && !hasAndroid) {
pLog.warn('⚠️ No native platform directories found (ios/ or android/).')
pLog.info(' Run "npx cap add ios" or "npx cap add android" to add a platform.')
const continueWithout = await pSelect({
message: 'Continue without native platforms? Later steps may not work.',
options: [
{ value: 'yes', label: '✅ Yes, continue anyway' },
{ value: 'no', label: '❌ No, I\'ll add a platform first' },
],
})
if (pIsCancel(continueWithout) || continueWithout === 'no') {
pOutro('Bye 👋\n💡 Run "npx cap add ios" or "npx cap add android", then try again.')
exit()
}
}
}

const localConfig = await getLocalConfig()
appId = getAppId(appId, extConfig?.config)
options.apikey = apikeyCommand
Expand Down
Loading