[CB-4036] - fixed up how plugin install handles the dev flag for repos as well as cleaned up some errors
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/0414fe4a Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/0414fe4a Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/0414fe4a Branch: refs/heads/master Commit: 0414fe4a332dc38b4ea632e43c90bb1bb36a4f29 Parents: c06a07e Author: Tim Kim <[email protected]> Authored: Thu Aug 15 17:13:03 2013 -0700 Committer: Tim Kim <[email protected]> Committed: Mon Aug 26 16:47:17 2013 -0700 ---------------------------------------------------------------------- spec/plugins/EnginePlugin/plugin.xml | 1 + src/install.js | 58 +++++++++++++++++++------------ src/util/default-engines.js | 14 ++++---- 3 files changed, 44 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/0414fe4a/spec/plugins/EnginePlugin/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/plugins/EnginePlugin/plugin.xml b/spec/plugins/EnginePlugin/plugin.xml index 169e8d1..72bf190 100644 --- a/spec/plugins/EnginePlugin/plugin.xml +++ b/spec/plugins/EnginePlugin/plugin.xml @@ -26,6 +26,7 @@ <engines> <engine name="cordova" version=">=2.3.0" platform="*" /> <engine name="cordova-plugman" version=">=0.10.0" platform="*" /> + <engine name="cordova-android" version=">=3.1.0" platform="*" /> </engines> </plugin> http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/0414fe4a/src/install.js ---------------------------------------------------------------------- diff --git a/src/install.js b/src/install.js index 4e88b80..59334dc 100644 --- a/src/install.js +++ b/src/install.js @@ -66,8 +66,8 @@ function possiblyFetch(actions, platform, project_dir, id, plugins_dir, options, } function checkMinimumReq(engines, callback) { - engines.forEach(function(engine){ - if(engine.currentVersion == 'dev' || semver.satisfies(engine.currentVersion, engine.minVersion || engine.currentVersion == null)){ + engines.forEach(function(engine){ + if(semver.satisfies(engine.currentVersion, engine.minVersion || engine.currentVersion == null)){ // engine ok! }else{ var err = new Error('Plugin doesn\'t support this project\'s '+engine.name+' version. '+engine.name+': ' + engine.currentVersion + ', failed version requirement: ' + engine.minVersion); @@ -77,12 +77,19 @@ function checkMinimumReq(engines, callback) { }); } -function cleanVersionRC(version){ +function cleanVersionOutput(version, platform){ var out = version.trim(); var rc_index = out.indexOf('rc'); + var dev_index = out.indexOf('dev'); if (rc_index > -1) { out = out.substr(0, rc_index) + '-' + out.substr(rc_index); - } + } + + // strip out the -dev and put a warning about using the dev branch + if (dev_index > -1) { + out = out.substr(0, dev_index-1); + require('../plugman').emit('log', 'Cordova-'+platform+' has been detected as using a development branch. Attemping to install as Cordova-'+platform+' '+out); + } return out; } @@ -96,13 +103,13 @@ function callEngineScripts(engines) { fs.chmodSync(engine.scriptTarget, '755'); engineScript = shell.exec(engine.scriptTarget, {silent: true}); if (engineScript.code === 0) { - engineScriptVersion = cleanVersionRC(engineScript.output) + engineScriptVersion = cleanVersionOutput(engineScript.output, engine.platform) }else{ engineScriptVersion = null; require('../plugman').emit('log', 'Cordova project '+ engine.scriptTarget +' script failed (has a '+ engine.scriptTarget +' script, but something went wrong executing it), continuing anyways.'); } - }else if(engine.minVersion){ - engineScriptVersion = cleanVersionRC(engine.minVersion) + }else if(engine.currentVersion){ + engineScriptVersion = cleanVersionOutput(engine.currentVersion, engine.platform) }else{ engineScriptVersion = null; require('../plugman').emit('log', 'Cordova project '+ engine.scriptTarget +' not detected (lacks a '+ engine.scriptTarget +' script), continuing.'); @@ -119,22 +126,37 @@ function getEngines(pluginElement, platform, project_dir){ var defaultEngines = require('./util/default-engines'); var uncheckedEngines = []; var tempEngine; - // load in all known defaults and compare + var cordovaEngineIndex; + var cordovaPlatformEngineIndex; + + var theName; + // load in known defaults and update when necessary engines.forEach(function(engine){ - // this may need some changes - what to do for default platforms - why need to specify platforms? if(engine.attrib["platform"] === platform || engine.attrib["platform"] === '*'){ - if(defaultEngines[engine.attrib["name"]]){ - defaultEngines[engine.attrib["name"]].minVersion = defaultEngines[engine.attrib["name"]].minVersion ? defaultEngines[engine.attrib["name"]].minVersion : engine.attrib["version"]; - defaultEngines[engine.attrib["name"]].scriptTarget = defaultEngines[engine.attrib["name"]].scriptTarget ? path.join(project_dir, defaultEngines[engine.attrib["name"]].scriptTarget) : null; - uncheckedEngines.push(defaultEngines[engine.attrib["name"]]); + theName = engine.attrib["name"]; + if(defaultEngines[theName]){ + defaultEngines[theName].minVersion = defaultEngines[theName].minVersion ? defaultEngines[theName].minVersion : engine.attrib["version"]; + defaultEngines[theName].currentVersion = defaultEngines[theName].currentVersion ? defaultEngines[theName].currentVersion : null; + defaultEngines[theName].scriptTarget = defaultEngines[theName].scriptTarget ? path.join(project_dir, defaultEngines[theName].scriptTarget) : null; + defaultEngines[theName].name = theName; + + // set the indices so we can pop the cordova engine when needed + if(theName==='cordova') cordovaEngineIndex = uncheckedEngines.length; + if(theName==='cordova-'+platform) cordovaPlatformEngineIndex = uncheckedEngines.length; + + uncheckedEngines.push(defaultEngines[theName]); + }else{ // check for other engines tempEngine = {}; - tempEngine[engine.attrib["name"]] = { 'platform': engine.attrib["platform"], 'scriptTarget':path.join(project_dir,engine.attrib["scriptTarget"]), 'minVersion' : engine.attrib["version"]}; + tempEngine[theName] = { 'platform': engine.attrib["platform"], 'scriptTarget':path.join(project_dir,engine.attrib["scriptTarget"]), 'minVersion' : engine.attrib["version"]}; uncheckedEngines.push(tempEngine); } } }); + + // make sure we check for platform req's and not just cordova reqs + if(cordovaEngineIndex && cordovaPlatformEngineIndex) uncheckedEngines.pop(cordovaEngineIndex); return uncheckedEngines; } @@ -167,14 +189,6 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt if (callback) callback(); return; } - - //var versionPath = path.join(project_dir, 'cordova', 'version'); - // windows8, wp7, wp8 all use a .bat file - /* - if (platform === "windows8" || platform === "wp7" || platform === "wp8") { - versionPath += ".bat"; - } - */ var theEngines = getEngines(plugin_et, platform, project_dir); theEngines = callEngineScripts(theEngines); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/0414fe4a/src/util/default-engines.js ---------------------------------------------------------------------- diff --git a/src/util/default-engines.js b/src/util/default-engines.js index e1a26d1..b041951 100644 --- a/src/util/default-engines.js +++ b/src/util/default-engines.js @@ -9,19 +9,19 @@ module.exports = { { 'platform':'*', 'scriptTarget': path.join('cordova','version') }, // no location needed for plugman as this should be the calling process 'cordova-plugman': - { 'platform':'*', 'minVersion': process.version }, + { 'platform':'*', 'currentVersion': process.version }, 'cordova-android': - { 'platform':'android', 'scriptTarget': '' }, + { 'platform':'android', 'scriptTarget': path.join('cordova','version') }, 'cordova-ios': - { 'platform':'ios', 'scriptTarget': '' }, + { 'platform':'ios', 'scriptTarget': path.join('cordova','version') }, 'cordova-blackberry10': - { 'platform':'blackberry10', 'scriptTarget': '' }, + { 'platform':'blackberry10', 'scriptTarget': path.join('cordova','version') }, 'cordova-wp7': - { 'platform':'wp7', 'scriptTarget': '' }, + { 'platform':'wp7', 'scriptTarget': path.join('cordova','version') }, 'cordova-wp8': - { 'platform':'wp8', 'scriptTarget': '' }, + { 'platform':'wp8', 'scriptTarget': path.join('cordova','version') }, 'cordova-windows8': - { 'platform':'windows8', 'scriptTarget': '' }, + { 'platform':'windows8', 'scriptTarget': path.join('cordova','version') }, // ideally these sdk versions will be known via a script // that calls the sdk's version command - the idea would be that
