Skip to content

Commit

Permalink
fix(cli): match platform version with cli version on add command (#2724)
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd authored Apr 8, 2020
1 parent c2e0358 commit 6172932
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
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

0 comments on commit 6172932

Please sign in to comment.