raphinesse commented on a change in pull request #763: refactor: replace
superspawn & child_process with execa
URL: https://github.com/apache/cordova-ios/pull/763#discussion_r364461513
##########
File path: bin/templates/scripts/cordova/lib/versions.js
##########
@@ -19,73 +19,55 @@
under the License.
*/
-const child_process = require('child_process');
const Q = require('q');
+const execa = require('execa');
const semver = require('semver');
-exports.get_apple_ios_version = () => {
- const d = Q.defer();
- child_process.exec('xcodebuild -showsdks', (error, stdout, stderr) => {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
-
- return d.promise.then(output => {
- const regex = /[0-9]*\.[0-9]*/;
- const versions = [];
- const regexIOS = /^iOS \d+/;
- output = output.split('\n');
- for (let i = 0; i < output.length; i++) {
- if (output[i].trim().match(regexIOS)) {
- versions[versions.length] =
parseFloat(output[i].match(regex)[0]);
+function fetchSdkVersionByType (sdkType) {
+ return execa('xcodebuild', ['-showsdks'])
+ .then(
+ ({ stdout }) => stdout,
+ ({ stderr }) => stderr
+ )
+ .then(output => {
+ output = output.split('\n');
+
+ const versions = [];
+ const regexSdk = new RegExp(`^${sdkType} \\d`);
+
+ for (const line of output) {
+ const matched = line.trim();
+
+ if (matched.match(regexSdk)) {
+
versions.push(parseFloat(matched.match(/[0-9]*\.[0-9]*/)[0]));
+ }
}
- }
- versions.sort();
- console.log(versions[0]);
- return Q();
- }, stderr => Q.reject(stderr));
+
+ versions.sort();
+ console.log(versions[0]);
+ });
+}
+
+exports.get_apple_ios_version = () => {
+ return fetchSdkVersionByType('iOS');
};
exports.get_apple_osx_version = () => {
- const d = Q.defer();
- child_process.exec('xcodebuild -showsdks', (error, stdout, stderr) => {
- if (error) {
- d.reject(stderr);
- } else {
- d.resolve(stdout);
- }
- });
-
- return d.promise.then(output => {
- const regex = /[0-9]*\.[0-9]*/;
- const versions = [];
- const regexOSX = /^macOS \d+/;
- output = output.split('\n');
- for (let 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();
- }, stderr => Q.reject(stderr));
+ return fetchSdkVersionByType('macOS');
};
exports.get_apple_xcode_version = () => {
- const d = Q.defer();
- child_process.exec('xcodebuild -version', (error, stdout, stderr) => {
- const versionMatch = /Xcode (.*)/.exec(stdout);
- if (error || !versionMatch) {
- d.reject(stderr);
- } else {
- d.resolve(versionMatch[1]);
- }
- });
- return d.promise;
+ return execa('xcodebuild', ['-version'])
+ .then(
+ ({ stdout }) => {
+ const versionMatch = /Xcode (.*)/.exec(stdout);
+
+ if (!versionMatch) Promise.reject(new Error('Missing
version'));
Review comment:
The equivalent of the old code would be:
```suggestion
if (!versionMatch) return Promise.reject(stderr);
```
Any reason to change the behavior here? Your code seems to be missing a
`return` as well
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]