From 44ec162d5424b0362c8271b3286842e51776edbd Mon Sep 17 00:00:00 2001 From: Martijn Walraven Date: Wed, 2 Sep 2015 16:30:12 +0200 Subject: [PATCH] Remove Cordova project directory when it contains outdated platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although we remove the Cordova project directory when upgrading to Meteor 1.2, this only happens once per project, and the .meteor/local/cordova-build directory is usually ignored, and thus preserved per machine. This means we can’t avoid checking for outdated platforms on every run to make sure we remove the directory when needed. --- tools/cordova/project.js | 45 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/cordova/project.js b/tools/cordova/project.js index 196a05492b..626649824a 100644 --- a/tools/cordova/project.js +++ b/tools/cordova/project.js @@ -3,6 +3,7 @@ import util from 'util'; import path from 'path'; import assert from 'assert'; import chalk from 'chalk'; +import semver from 'semver'; import isopackets from '../tool-env/isopackets.js' import files from '../fs/files.js'; @@ -59,6 +60,33 @@ yet supported.`); createIfNeeded() { buildmessage.assertInJob(); + // Check if we have an existing Cordova project directory with outdated + // platforms. In that case, we remove the whole directory to avoid issues. + if (files.exists(this.projectRoot)) { + const platformVersions = this.listInstalledPlatformVersions(); + + // XXX Decide whether to update these if we update cordova-lib. + // If we can guarantee there are no issues going forward, we may want to + // use updatePlatforms instead of removing the whole directory. + const minPlatformVersions = { + 'android': '4.1.0', + 'ios': '3.9.0' + } + + const outdated = _.some(minPlatformVersions, (minVersion, platform) => { + const version = platformVersions[platform]; + return version && semver.lt(version, minVersion); + }); + + if (outdated) { + Console.debug(`Removing Cordova project directory to avoid issues with +outdated platforms`); + // Remove Cordova project directory to start afresh + // and avoid a broken project + files.rm_recursive(this.projectRoot); + } + } + if (!files.exists(this.projectRoot)) { // We create a temporary directory with a generated config.xml // to use as a template for creating the Cordova project @@ -172,7 +200,7 @@ ${displayNameForPlatform(platform)} with options ${options}`, cwd: this.projectRoot, stdio: Console.verbose ? 'inherit' : 'pipe', waitForClose: false }) - ); + ), null, null; } // Platforms @@ -262,6 +290,21 @@ the status of individual requirements."); return cordova_util.listPlatforms(files.convertToOSPath(this.projectRoot)); } + listInstalledPlatformVersions() { + let platformVersions = {}; + this.runCommands(`listing platform versions in Cordova project`, async () => { + for (let platform of this.listInstalledPlatforms()) { + const command = files.convertToOSPath(files.pathJoin( + this.projectRoot, 'platforms', platform, 'cordova', 'version')); + const platformVersion = await execFileSync(command, { + env: this.defaultEnvWithPathsAdded(), + cwd: this.projectRoot}) + platformVersions[platform] = platformVersion; + } + }, null, null); + return platformVersions; + } + updatePlatforms(platforms = this.listInstalledPlatforms()) { this.runCommands(`updating Cordova project for platforms \ ${displayNamesForPlatforms(platforms)}`, async () => {