You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/12/18 22:44:38 UTC

[GitHub] brodybits closed pull request #478: Use cross-spawn & shelljs instead of child-process

brodybits closed pull request #478: Use cross-spawn & shelljs instead of child-process
URL: https://github.com/apache/cordova-ios/pull/478
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js
index 42bccbfe2..4f28a262b 100644
--- a/bin/templates/scripts/cordova/lib/build.js
+++ b/bin/templates/scripts/cordova/lib/build.js
@@ -20,7 +20,7 @@
 var Q = require('q');
 var path = require('path');
 var shell = require('shelljs');
-var spawn = require('./spawn');
+var superspawn = require('cordova-common').superspawn;
 var fs = require('fs');
 var plist = require('plist');
 var util = require('util');
@@ -168,11 +168,10 @@ module.exports.run = function (buildOpts) {
             var buildOutputDir = path.join(projectPath, 'build', (buildOpts.device ? 'device' : 'emulator'));
 
             // remove the build/device folder before building
-            return spawn('rm', [ '-rf', buildOutputDir ], projectPath)
-                .then(function () {
-                    var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning);
-                    return spawn('xcodebuild', xcodebuildArgs, projectPath);
-                });
+            shell.rm('-rf', buildOutputDir);
+
+            var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning);
+            return superspawn.spawn('xcodebuild', xcodebuildArgs, { cwd: projectPath });
 
         }).then(function () {
             if (!buildOpts.device || buildOpts.noSign) {
@@ -225,7 +224,7 @@ module.exports.run = function (buildOpts) {
 
             function packageArchive () {
                 var xcodearchiveArgs = getXcodeArchiveArgs(projectName, projectPath, buildOutputDir, exportOptionsPath, buildOpts.automaticProvisioning);
-                return spawn('xcodebuild', xcodearchiveArgs, projectPath);
+                return superspawn.spawn('xcodebuild', xcodearchiveArgs, { cwd: projectPath });
             }
 
             return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8')
diff --git a/bin/templates/scripts/cordova/lib/clean.js b/bin/templates/scripts/cordova/lib/clean.js
index 20e8ac66e..3e4d4140e 100644
--- a/bin/templates/scripts/cordova/lib/clean.js
+++ b/bin/templates/scripts/cordova/lib/clean.js
@@ -20,7 +20,7 @@
 var Q = require('q');
 var path = require('path');
 var shell = require('shelljs');
-var spawn = require('./spawn');
+var superspawn = require('cordova-common').superspawn;
 
 var projectPath = path.join(__dirname, '..', '..');
 
@@ -33,9 +33,9 @@ module.exports.run = function () {
         return Q.reject('No Xcode project found in ' + projectPath);
     }
 
-    return spawn('xcodebuild', ['-project', projectName, '-configuration', 'Debug', '-alltargets', 'clean'], projectPath)
+    return superspawn.spawn('xcodebuild', ['-project', projectName, '-configuration', 'Debug', '-alltargets', 'clean'], { cwd: projectPath })
         .then(function () {
-            return spawn('xcodebuild', ['-project', projectName, '-configuration', 'Release', '-alltargets', 'clean'], projectPath);
+            return superspawn.spawn('xcodebuild', ['-project', projectName, '-configuration', 'Release', '-alltargets', 'clean'], { cwd: projectPath });
         }).then(function () {
             return shell.rm('-rf', path.join(projectPath, 'build'));
         });
diff --git a/bin/templates/scripts/cordova/lib/run.js b/bin/templates/scripts/cordova/lib/run.js
index 40344a37f..8b8477759 100644
--- a/bin/templates/scripts/cordova/lib/run.js
+++ b/bin/templates/scripts/cordova/lib/run.js
@@ -21,7 +21,8 @@ var Q = require('q');
 var path = require('path');
 var cp = require('child_process');
 var build = require('./build');
-var spawn = require('./spawn');
+var shell = require('shelljs');
+var superspawn = require('cordova-common').superspawn;
 var check_reqs = require('./check_reqs');
 
 var events = require('cordova-common').events;
@@ -78,7 +79,7 @@ module.exports.run = function (runOptions) {
                         var ipafile = path.join(buildOutputDir, projectName + '.ipa');
 
                         // unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder
-                        return spawn('unzip', [ '-o', '-qq', ipafile ], buildOutputDir);
+                        return superspawn.spawn('unzip', [ '-o', '-qq', ipafile ], { cwd: buildOutputDir });
                     })
                     .then(function () {
                         // Uncompress IPA (zip file)
@@ -87,15 +88,13 @@ module.exports.run = function (runOptions) {
                         var payloadFolder = path.join(buildOutputDir, 'Payload');
 
                         // delete the existing platform/ios/build/device/appname.app
-                        return spawn('rm', [ '-rf', appFile ], buildOutputDir)
-                            .then(function () {
-                                // move the platform/ios/build/device/Payload/appname.app to parent
-                                return spawn('mv', [ '-f', appFileInflated, buildOutputDir ], buildOutputDir);
-                            })
-                            .then(function () {
-                                // delete the platform/ios/build/device/Payload folder
-                                return spawn('rm', [ '-rf', payloadFolder ], buildOutputDir);
-                            });
+                        shell.rm('-rf', appFile);
+                        // move the platform/ios/build/device/Payload/appname.app to parent
+                        shell.mv('-f', appFileInflated, buildOutputDir);
+                        // delete the platform/ios/build/device/Payload folder
+                        shell.rm('-rf', payloadFolder);
+
+                        return null;
                     })
                     .then(function () {
                         appPath = path.join(projectPath, 'build', 'device', projectName + '.app');
@@ -149,7 +148,7 @@ function filterSupportedArgs (args) {
  * @return {Promise} Fullfilled when any device is connected, rejected otherwise
  */
 function checkDeviceConnected () {
-    return spawn('ios-deploy', ['-c', '-t', '1']);
+    return superspawn.spawn('ios-deploy', ['-c', '-t', '1']);
 }
 
 /**
@@ -161,9 +160,9 @@ function checkDeviceConnected () {
 function deployToDevice (appPath, target, extraArgs) {
     // Deploying to device...
     if (target) {
-        return spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs));
+        return superspawn.spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs));
     } else {
-        return spawn('ios-deploy', ['--justlaunch', '--no-wifi', '-d', '-b', appPath].concat(extraArgs));
+        return superspawn.spawn('ios-deploy', ['--justlaunch', '--no-wifi', '-d', '-b', appPath].concat(extraArgs));
     }
 }
 
diff --git a/bin/templates/scripts/cordova/lib/spawn.js b/bin/templates/scripts/cordova/lib/spawn.js
index b5a568524..a6c29307f 100644
--- a/bin/templates/scripts/cordova/lib/spawn.js
+++ b/bin/templates/scripts/cordova/lib/spawn.js
@@ -27,6 +27,7 @@ var proc = require('child_process');
  * @param  {String} opt_cwd       Working directory for command
  * @param  {String} opt_verbosity Verbosity level for command stdout output, "verbose" by default
  * @return {Promise}              Promise either fullfilled or rejected with error code
+ * @deprecated Use `require('cordova-common').superspawn` instead.
  */
 module.exports = function (cmd, args, opt_cwd) {
     var d = Q.defer();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org