From 27db65b748c29a2a1e4e03fc5ff05ff638f14b92 Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Thu, 23 Apr 2015 10:55:30 +0300 Subject: [PATCH] CB-8898 Introduces `cordova requirements` command --- doc/requirements.txt | 7 ++++++ src/cli.js | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 doc/requirements.txt diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 000000000..4c18726f6 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,7 @@ +Synopsis + + cordova-cli requirements [PLATFORM ...] + +Checks and print out all the requirements for platforms specified (or all platforms added +to project if none specified). If all requirements for each platform are met exits with code 0 +otherwise exits with non-zero code. diff --git a/src/cli.js b/src/cli.js index 8f6f87a52..c96c4e365 100644 --- a/src/cli.js +++ b/src/cli.js @@ -241,6 +241,60 @@ function cli(inputArgs) { } cordova.raw[cmd].call(null, opts).done(); + } else if (cmd === 'requirements') { + // All options without dashes are assumed to be platform names + opts.platforms = undashed.slice(1); + var badPlatforms = _.difference(opts.platforms, known_platforms); + if( !_.isEmpty(badPlatforms) ) { + msg = 'Unknown platforms: ' + badPlatforms.join(', '); + throw new CordovaError(msg); + } + + // CB-6976 Windows Universal Apps. Allow mixing windows and windows8 aliases + opts.platforms = opts.platforms.map(function(platform) { + // allow using old windows8 alias for new unified windows platform + if (platform == 'windows8' && fs.existsSync('platforms/windows')) { + return 'windows'; + } + // allow using new windows alias for old windows8 platform + if (platform == 'windows' && + !fs.existsSync('platforms/windows') && + fs.existsSync('platforms/windows8')) { + return 'windows8'; + } + return platform; + }); + + cordova.raw[cmd].call(null, opts.platforms) + .then(function (platformChecks) { + + var someChecksFailed = Object.keys(platformChecks).map(function (platformName) { + events.emit('log', '\nRequirements check results for ' + platformName + ':'); + var platformCheck = platformChecks[platformName]; + if (platformCheck instanceof CordovaError) { + events.emit('warn', 'Check failed for ' + platformName + ' due to ' + platformCheck); + return true; + } + + var someChecksFailed = false; + platformCheck.forEach(function (checkItem) { + var checkSummary = checkItem.name + ': ' + + (checkItem.installed ? 'installed ' : 'not installed ') + + (checkItem.metadata.version || ''); + events.emit('log', checkSummary); + if (!checkItem.installed) { + someChecksFailed = true; + events.emit('warn', checkItem.metadata.reason); + } + }); + + return someChecksFailed; + }).some(function (isCheckFailedForPlatform) { + return isCheckFailedForPlatform; + }); + + if (someChecksFailed) throw new CordovaError('Some of requirements check failed'); + }).done(); } else if (cmd == 'serve') { var port = undashed[1]; cordova.raw.serve(port).done();