summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/cordova/lib/versions.js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/versions.js')
-rw-r--r--[-rwxr-xr-x]StoneIsland/platforms/ios/cordova/lib/versions.js173
1 files changed, 49 insertions, 124 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/versions.js b/StoneIsland/platforms/ios/cordova/lib/versions.js
index c6a41b83..f8914785 100755..100644
--- a/StoneIsland/platforms/ios/cordova/lib/versions.js
+++ b/StoneIsland/platforms/ios/cordova/lib/versions.js
@@ -1,5 +1,3 @@
-#!/usr/bin/env node
-
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -19,76 +17,43 @@
under the License.
*/
-var child_process = require('child_process');
-var Q = require('q');
+const {
+ CordovaError,
+ superspawn: { spawn }
+} = require('cordova-common');
+const semver = require('semver');
-exports.get_apple_ios_version = function () {
- var d = Q.defer();
- child_process.exec('xcodebuild -showsdks', function (error, stdout, stderr) {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
+function fetchSdkVersionByType (sdkType) {
+ return spawn('xcodebuild', ['-showsdks'])
+ .then(output => {
+ const regexSdk = new RegExp(`^${sdkType} \\d`);
- return d.promise.then(function (output) {
- var regex = /[0-9]*\.[0-9]*/;
- var versions = [];
- var regexIOS = /^iOS \d+/;
- output = output.split('\n');
- for (var i = 0; i < output.length; i++) {
- if (output[i].trim().match(regexIOS)) {
- versions[versions.length] = parseFloat(output[i].match(regex)[0]);
- }
- }
- versions.sort();
- console.log(versions[0]);
- return Q();
- }, function (stderr) {
- return Q.reject(stderr);
- });
-};
+ const versions = output.split('\n')
+ .filter(line => line.trim().match(regexSdk))
+ .map(line => line.match(/\d+\.\d+/)[0])
+ .sort(exports.compareVersions);
-exports.get_apple_osx_version = function () {
- var d = Q.defer();
- child_process.exec('xcodebuild -showsdks', function (error, stdout, stderr) {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
+ console.log(versions[0]);
+ });
+}
- return d.promise.then(function (output) {
- var regex = /[0-9]*\.[0-9]*/;
- var versions = [];
- var regexOSX = /^OS X \d+/;
- output = output.split('\n');
- for (var i = 0; i < output.length; i++) {
- if (output[i].trim().match(regexOSX)) {
- versions[versions.length] = parseFloat(output[i].match(regex)[0]);
- }
- }
- versions.sort();
- console.log(versions[0]);
- return Q();
- }, function (stderr) {
- return Q.reject(stderr);
- });
+exports.get_apple_ios_version = () => {
+ return fetchSdkVersionByType('iOS');
};
-exports.get_apple_xcode_version = function () {
- var d = Q.defer();
- child_process.exec('xcodebuild -version', function (error, stdout, stderr) {
- var versionMatch = /Xcode (.*)/.exec(stdout);
- if (error || !versionMatch) {
- d.reject(stderr);
- } else {
- d.resolve(versionMatch[1]);
- }
- });
- return d.promise;
+exports.get_apple_osx_version = () => {
+ return fetchSdkVersionByType('macOS');
+};
+
+exports.get_apple_xcode_version = () => {
+ return spawn('xcodebuild', ['-version'])
+ .then(output => {
+ const versionMatch = /Xcode (.*)/.exec(output);
+
+ if (!versionMatch) return Promise.reject(output);
+
+ return versionMatch[1];
+ });
};
/**
@@ -96,16 +61,8 @@ exports.get_apple_xcode_version = function () {
* @return {Promise} Promise that either resolved with ios-deploy version
* or rejected in case of error
*/
-exports.get_ios_deploy_version = function () {
- var d = Q.defer();
- child_process.exec('ios-deploy --version', function (error, stdout, stderr) {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
- return d.promise;
+exports.get_ios_deploy_version = () => {
+ return spawn('ios-deploy', ['--version']);
};
/**
@@ -113,16 +70,8 @@ exports.get_ios_deploy_version = function () {
* @return {Promise} Promise that either resolved with pod version
* or rejected in case of error
*/
-exports.get_cocoapods_version = function () {
- var d = Q.defer();
- child_process.exec('pod --version', function (error, stdout, stderr) {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
- return d.promise;
+exports.get_cocoapods_version = () => {
+ return spawn('pod', ['--version']);
};
/**
@@ -130,16 +79,8 @@ exports.get_cocoapods_version = function () {
* @return {Promise} Promise that either resolved with ios-sim version
* or rejected in case of error
*/
-exports.get_ios_sim_version = function () {
- var d = Q.defer();
- child_process.exec('ios-sim --version', function (error, stdout, stderr) {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
- return d.promise;
+exports.get_ios_sim_version = () => {
+ return spawn('ios-sim', ['--version']);
};
/**
@@ -148,47 +89,31 @@ exports.get_ios_sim_version = function () {
* @return {Promise} Promise that either resolved with tool version
* or rejected in case of error
*/
-exports.get_tool_version = function (toolName) {
+exports.get_tool_version = toolName => {
switch (toolName) {
case 'xcodebuild': return exports.get_apple_xcode_version();
case 'ios-sim': return exports.get_ios_sim_version();
case 'ios-deploy': return exports.get_ios_deploy_version();
case 'pod': return exports.get_cocoapods_version();
- default: return Q.reject(toolName + ' is not valid tool name. Valid names are: \'xcodebuild\', \'ios-sim\', \'ios-deploy\', and \'pod\'');
+ default: return Promise.reject(new CordovaError(`${toolName} is not valid tool name. Valid names are: 'xcodebuild', 'ios-sim', 'ios-deploy', and 'pod'`));
}
};
/**
- * Compares two semver-notated version strings. Returns number
- * that indicates equality of provided version strings.
+ * Compares two version strings that can be coerced to semver.
+ *
* @param {String} version1 Version to compare
* @param {String} version2 Another version to compare
* @return {Number} Negative number if first version is lower than the second,
* positive otherwise and 0 if versions are equal.
*/
-exports.compareVersions = function (version1, version2) {
- function parseVer (version) {
- return version.split('.').map(function (value) {
- // try to convert version segment to Number
- var parsed = Number(value);
- // Number constructor is strict enough and will return NaN
- // if conversion fails. In this case we won't be able to compare versions properly
- if (isNaN(parsed)) {
- throw 'Version should contain only numbers and dots';
- }
- return parsed;
- });
- }
- var parsedVer1 = parseVer(version1);
- var parsedVer2 = parseVer(version2);
+exports.compareVersions = (...args) => {
+ const coerceToSemverIfInvalid = v => {
+ const semverVersion = semver.parse(v) || semver.coerce(v);
+ if (!semverVersion) throw new TypeError(`Invalid Version: ${v}`);
+ return semverVersion;
+ };
- // Compare corresponding segments of each version
- for (var i = 0; i < Math.max(parsedVer1.length, parsedVer2.length); i++) {
- // if segment is not specified, assume that it is 0
- // E.g. 3.1 is equal to 3.1.0
- var ret = (parsedVer1[i] || 0) - (parsedVer2[i] || 0);
- // if segments are not equal, we're finished
- if (ret !== 0) return ret;
- }
- return 0;
+ const semverVersions = args.map(coerceToSemverIfInvalid);
+ return semver.compare(...semverVersions);
};