You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/01/28 03:54:48 UTC

[2/2] git commit: CB-5913 Fail more gracefully on Windows when symlinks fail.

CB-5913 Fail more gracefully on Windows when symlinks fail.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/1f430644
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/1f430644
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/1f430644

Branch: refs/heads/master
Commit: 1f430644cb2df0a4b71ebf67a6e4c1ddc5341696
Parents: 23d0a4d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Jan 27 21:51:22 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jan 27 21:54:38 2014 -0500

----------------------------------------------------------------------
 spec/create.spec.js | 10 +++++-----
 src/create.js       | 48 ++++++++++++++++++++++++++++++++----------------
 2 files changed, 37 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1f430644/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 31efb47..a0eb0e7 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -62,17 +62,17 @@ describe('create command', function () {
     describe('success', function() {
         it('should create top-level directory structure appropriate for a cordova-cli project', function(done) {
             cordova.raw.create(tempDir).then(function() {
-                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'platforms'));
-                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'merges'));
-                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'plugins'));
-                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'www'));
+                expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'platforms'));
+                expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'merges'));
+                expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'plugins'));
+                expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'www'));
                 done();
             });
         });
         it('should create hooks directory', function(done) {
             var hooks_dir = path.join(tempDir, 'hooks');
             cordova.raw.create(tempDir).then(function() {
-                expect(mkdir).toHaveBeenCalledWith('-p', hooks_dir);
+                expect(mkdir).toHaveBeenCalledWith(hooks_dir);
                 expect(cp).toHaveBeenCalledWith(
                     path.resolve(__dirname, '..', 'templates', 'hooks-README.md'),
                     jasmine.any(String)

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1f430644/src/create.js
----------------------------------------------------------------------
diff --git a/src/create.js b/src/create.js
index 2ee3c45..75b2621 100644
--- a/src/create.js
+++ b/src/create.js
@@ -79,16 +79,7 @@ module.exports = function create (dir, id, name, cfg) {
         return Q.reject(new CordovaError('Path already exists and is not empty: ' + dir));
     }
 
-    // Create basic project structure.
-    shell.mkdir('-p', path.join(dir, 'platforms'));
-    shell.mkdir('-p', path.join(dir, 'merges'));
-    shell.mkdir('-p', path.join(dir, 'plugins'));
-    shell.mkdir('-p', path.join(dir, 'hooks'));
-
-    // Add hooks README.md
-    shell.cp(path.join(__dirname, '..', 'templates', 'hooks-README.md'), path.join(dir, 'hooks', 'README.md'));
-
-    // Write out .cordova/config.json file if necessary.
+    // Read / Write .cordova/config.json file if necessary.
     var config_json = config(dir, cfg);
 
     var p;
@@ -104,18 +95,18 @@ module.exports = function create (dir, id, name, cfg) {
             events.emit('verbose', 'Symlinking custom www assets into "' + www_dir + '"');
         } else {
             p = lazy_load.custom(config_json.lib.www.uri, www_id, 'www', www_version)
-            .then(function(dir) {
+            .then(function(d) {
                 events.emit('verbose', 'Copying custom www assets into "' + www_dir + '"');
-                return dir;
+                return d;
             });
         }
     } else {
         // Nope, so use stock cordova-hello-world-app one.
         events.emit('verbose', 'Using stock cordova hello-world application.');
         p = lazy_load.cordova('www')
-        .then(function(dir) {
+        .then(function(d) {
             events.emit('verbose', 'Copying stock Cordova www assets into "' + www_dir + '"');
-            return dir;
+            return d;
         });
     }
 
@@ -124,12 +115,37 @@ module.exports = function create (dir, id, name, cfg) {
         while (fs.existsSync(path.join(www_lib, 'www'))) {
             www_lib = path.join(www_lib, 'www');
         }
+
+        var dirAlreadyExisted = fs.existsSync(dir);
+        if (!dirAlreadyExisted) {
+            shell.mkdir(dir);
+        }
         if (symlink) {
-            fs.symlinkSync(www_lib, www_dir, 'dir');
+            try {
+                fs.symlinkSync(www_lib, www_dir, 'dir');
+            } catch (e) {
+                if (!dirAlreadyExisted) {
+                    fs.rmdirSync(dir);
+                }
+                if (process.platform.slice(0, 3) == 'win' && e.code == 'EPERM')  {
+                    throw new CordovaError('Symlinks on Windows require Administrator privileges');
+                }
+                throw e;
+            }
         } else {
-            shell.mkdir('-p', www_dir);
+            shell.mkdir(www_dir);
             shell.cp('-rf', path.join(www_lib, '*'), www_dir);
         }
+
+        // Create basic project structure.
+        shell.mkdir(path.join(dir, 'platforms'));
+        shell.mkdir(path.join(dir, 'merges'));
+        shell.mkdir(path.join(dir, 'plugins'));
+        shell.mkdir(path.join(dir, 'hooks'));
+
+        // Add hooks README.md
+        shell.cp(path.join(__dirname, '..', 'templates', 'hooks-README.md'), path.join(dir, 'hooks', 'README.md'));
+
         var configPath = util.projectConfig(dir);
         // Add template config.xml for apps that are missing it
         if (!fs.existsSync(configPath)) {