Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(cli): match platform version with cli version on add command #2724

Merged
merged 4 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions cli/src/android/add.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from '../config';
import { TaskInfoProvider, copyTemplate, installDeps, resolveNode, runCommand, runTask } from '../common';
import { TaskInfoProvider, copyTemplate, getCLIVersion, installDeps, resolveNode, runCommand, runTask } from '../common';
import { existsAsync, writeFileAsync } from '../util/fs';
import { homedir } from 'os';
import { join } from 'path';
Expand All @@ -11,7 +11,8 @@ export async function addAndroid(config: Config) {
info('Skipping: already installed');
return;
}
return installDeps(config.app.rootDir, ['@capacitor/android'], config);
const cliVersion = await getCLIVersion(config);
return installDeps(config.app.rootDir, [`@capacitor/android@${cliVersion}`], config);
});
await runTask(`Adding native android project in: ${config.android.platformDir}`, async () => {
return copyTemplate(config.android.assets.templateDir, config.android.platformDir);
Expand Down
26 changes: 21 additions & 5 deletions cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,39 @@ export async function printNextSteps(config: Config, appDir: string) {
log(`Follow the Developer Workflow guide to get building:\n${chalk.bold(`https://capacitor.ionicframework.com/docs/basics/workflow`)}\n`);
}

export async function checkPlatformVersions(config: Config, platform: string) {
export async function getCoreVersion(config: Config): Promise<string> {
const corePackagePath = resolveNode(config, '@capacitor/core', 'package.json');
if (!corePackagePath) {
logFatal('Unable to find node_modules/@capacitor/core/package.json. Are you sure',
'@capacitor/core is installed? This file is currently required for Capacitor to function.');
}

return (await readJSON(corePackagePath)).version;
}

export async function getCLIVersion(config: Config): Promise<string> {
const cliPackagePath = resolveNode(config, '@capacitor/cli', 'package.json');
if (!cliPackagePath) {
logFatal('Unable to find node_modules/@capacitor/cli/package.json. Are you sure',
'@capacitor/cli is installed? This file is currently required for Capacitor to function.');
return;
}

return (await readJSON(cliPackagePath)).version;
}

export async function getPlatformVersion(config: Config, platform: string): Promise<string> {
const platformPackagePath = resolveNode(config, `@capacitor/${platform}`, 'package.json');
if (!platformPackagePath) {
logFatal(`Unable to find node_modules/@capacitor/${platform}/package.json. Are you sure`,
`@capacitor/${platform} is installed? This file is currently required for Capacitor to function.`);
return;
}

const cliVersion = (await readJSON(cliPackagePath)).version;
const platformVersion = (await readJSON(platformPackagePath)).version;
return (await readJSON(platformPackagePath)).version;
}

export async function checkPlatformVersions(config: Config, platform: string) {
const cliVersion = await getCLIVersion(config);
const platformVersion = await getPlatformVersion(config, platform);

if (semver.gt(cliVersion, platformVersion)) {
log('\n');
Expand Down
6 changes: 3 additions & 3 deletions cli/src/ios/add.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { checkCocoaPods } from './common';
import { CheckFunction, TaskInfoProvider, copyTemplate, installDeps, resolveNode, runTask } from '../common';
import { CheckFunction, TaskInfoProvider, copyTemplate, getCLIVersion, installDeps, resolveNode, runTask } from '../common';
import { Config } from '../config';

export const addIOSChecks: CheckFunction[] = [checkCocoaPods];
Expand All @@ -10,8 +10,8 @@ export async function addIOS(config: Config) {
info('Skipping: already installed');
return;
}

return installDeps(config.app.rootDir, ['@capacitor/ios'], config);
const cliVersion = await getCLIVersion(config);
return installDeps(config.app.rootDir, [`@capacitor/ios@${cliVersion}`], config);
});
await runTask(`Adding native xcode project in: ${config.ios.platformDir}`, () => {
return copyTemplate(config.ios.assets.templateDir, config.ios.platformDir);
Expand Down