MCPcopy
hub / github.com/ionic-team/capacitor / addCommand

Function addCommand

cli/src/tasks/add.ts:30–102  ·  view source on GitHub ↗
(config: Config, selectedPlatformName: string)

Source from the content-addressed store, hash-verified

28import { sync } from './sync';
29
30export 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 });

Callers 1

runProgramFunction · 0.85

Calls 15

isValidPlatformFunction · 0.90
resolvePlatformFunction · 0.90
runPlatformHookFunction · 0.90
isValidCommunityPlatformFunction · 0.90
getKnownPlatformsFunction · 0.90
promptForPlatformFunction · 0.90
fatalFunction · 0.90
checkFunction · 0.90
checkPackageFunction · 0.90
checkAppConfigFunction · 0.90

Tested by

no test coverage detected