Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): do not error if webDir is missing when adding platforms #4215

Merged
merged 6 commits into from
Feb 18, 2021
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
45 changes: 23 additions & 22 deletions cli/src/tasks/add.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathExists } from '@ionic/utils-fs';
import { prettyPath } from '@ionic/utils-terminal';

import { addAndroid } from '../android/add';
Expand All @@ -12,7 +13,6 @@ import {
check,
checkAppConfig,
checkPackage,
checkWebDir,
resolvePlatform,
runPlatformHook,
runTask,
Expand All @@ -30,7 +30,7 @@ import {
checkIOSPackage,
checkCocoaPods,
} from '../ios/common';
import { logger } from '../log';
import { logger, logSuccess, output } from '../log';

import { sync } from './sync';

Expand Down Expand Up @@ -89,24 +89,22 @@ export async function addCommand(
() => checkAppConfig(config),
...addChecks(config, platformName),
]);
await check([() => checkWebDir(config)]);
await doAdd(config, platformName);
await editPlatforms(config, platformName);

if (shouldSync(config, platformName)) {
await sync(config, platformName, false);
if (await pathExists(config.app.webDirAbs)) {
sync(config, platformName, false);
} else {
logger.warn(
`${c.success(c.strong('sync'))} could not run--missing ${c.strong(
config.app.webDir,
)} directory.`,
);
}
}

if (
platformName === config.ios.name ||
platformName === config.android.name
) {
logger.info(
`Run ${c.input(`npx cap open ${platformName}`)} to launch ${
platformName === config.ios.name ? 'Xcode' : 'Android Studio'
}`,
);
}
printNextSteps(platformName);
} catch (e) {
if (!isFatal(e)) {
fatal(e.stack ?? e);
Expand All @@ -117,10 +115,16 @@ export async function addCommand(
}
}

export function addChecks(
config: Config,
platformName: string,
): CheckFunction[] {
function printNextSteps(platformName: string) {
logSuccess(`${c.strong(platformName)} platform added!`);
output.write(
`Follow the Developer Workflow guide to get building:\n${c.strong(
`https://capacitorjs.com/docs/v3/basics/workflow`,
)}\n`,
);
}

function addChecks(config: Config, platformName: string): CheckFunction[] {
if (platformName === config.ios.name) {
return [() => checkIOSPackage(config), () => checkCocoaPods(config)];
} else if (platformName === config.android.name) {
Expand All @@ -132,10 +136,7 @@ export function addChecks(
}
}

export async function doAdd(
config: Config,
platformName: string,
): Promise<void> {
async function doAdd(config: Config, platformName: string): Promise<void> {
await runTask(c.success(c.strong('add')), async () => {
if (platformName === config.ios.name) {
await addIOS(config);
Expand Down