(config: Config, selectedPlatformName: string)
| 28 | import { sync } from './sync'; |
| 29 | |
| 30 | export async function addCommand(config: Config, selectedPlatformName: string): Promise<void> { |
| 31 | if (selectedPlatformName && !(await isValidPlatform(selectedPlatformName))) { |
| 32 | const platformDir = resolvePlatform(config, selectedPlatformName); |
| 33 | if (platformDir) { |
| 34 | await runPlatformHook(config, selectedPlatformName, platformDir, 'capacitor:add'); |
| 35 | } else { |
| 36 | let msg = `Platform ${c.input(selectedPlatformName)} not found.`; |
| 37 | |
| 38 | if (await isValidCommunityPlatform(selectedPlatformName)) { |
| 39 | msg += `\nTry installing ${c.strong( |
| 40 | `@capacitor-community/${selectedPlatformName}`, |
| 41 | )} and adding the platform again.`; |
| 42 | } |
| 43 | |
| 44 | if (await isValidEnterprisePlatform(selectedPlatformName)) { |
| 45 | msg += |
| 46 | `\nThis is an enterprise platform and @ionic-enterprise/capacitor-${selectedPlatformName} is not installed.\n` + |
| 47 | `To learn how to use this platform, visit https://ionic.io/docs/${selectedPlatformName}`; |
| 48 | } |
| 49 | |
| 50 | logger.error(msg); |
| 51 | } |
| 52 | } else { |
| 53 | const knownPlatforms = await getKnownPlatforms(); |
| 54 | const platformName = await promptForPlatform( |
| 55 | knownPlatforms, |
| 56 | `Please choose a platform to add:`, |
| 57 | selectedPlatformName, |
| 58 | ); |
| 59 | |
| 60 | if (platformName === config.web.name) { |
| 61 | webWarning(); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | const existingPlatformDir = await getProjectPlatformDirectory(config, platformName); |
| 66 | |
| 67 | if (existingPlatformDir) { |
| 68 | fatal( |
| 69 | `${c.input(platformName)} platform already exists.\n` + |
| 70 | `To re-add this platform, first remove ${c.strong( |
| 71 | prettyPath(existingPlatformDir), |
| 72 | )}, then run this command again.\n` + |
| 73 | `${c.strong('WARNING')}: Your native project will be completely removed.`, |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | try { |
| 78 | await check([() => checkPackage(), () => checkAppConfig(config), ...(await getAddChecks(config, platformName))]); |
| 79 | await doAdd(config, platformName); |
| 80 | await editPlatforms(config, platformName); |
| 81 | |
| 82 | if (await pathExists(config.app.webDirAbs)) { |
| 83 | await sync(config, platformName, false, false); |
| 84 | if (platformName === config.android.name) { |
| 85 | await runTask('Syncing Gradle', async () => { |
| 86 | return createLocalProperties(config.android.platformDirAbs); |
| 87 | }); |
no test coverage detected