cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject git commit: CB-5765 Identify root project folder using www and config.xml instead of .cordova
Date Fri, 10 Jan 2014 21:00:46 GMT
Updated Branches:
  refs/heads/master 0f193ecfe -> 0eeaa000d


CB-5765 Identify root project folder using www and config.xml instead of .cordova

It's now possible that .cordova will not exist.


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

Branch: refs/heads/master
Commit: 0eeaa000db7fdfd576cf63607f09ea6f16d3d3a9
Parents: 0f193ec
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Jan 10 16:00:12 2014 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jan 10 16:00:12 2014 -0500

----------------------------------------------------------------------
 spec/util.spec.js | 21 +++++++++++++++++----
 src/util.js       | 38 ++++++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0eeaa000/spec/util.spec.js
----------------------------------------------------------------------
diff --git a/spec/util.spec.js b/spec/util.spec.js
index 495894c..cb24f53 100644
--- a/spec/util.spec.js
+++ b/spec/util.spec.js
@@ -53,7 +53,7 @@ describe('util module', function() {
                 shell.rm('-rf', somedir);
             });
             shell.mkdir('-p', anotherdir);
-            shell.mkdir(path.join(somedir, '.cordova'));
+            shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
             expect(util.isCordova(somedir)).toEqual(somedir);
         });
         it('should ignore PWD when its undefined', function() {
@@ -64,7 +64,8 @@ describe('util module', function() {
                 shell.rm('-rf', somedir);
             });
             shell.mkdir('-p', anotherdir);
-            shell.mkdir(path.join(somedir, '.cordova'));
+            shell.mkdir('-p', path.join(somedir, 'www'));
+            shell.mkdir('-p', path.join(somedir, 'config.xml'));
             process.chdir(anotherdir);
             expect(util.isCordova()).toEqual(somedir);
         });
@@ -75,7 +76,7 @@ describe('util module', function() {
                 shell.rm('-rf', somedir);
             });
             shell.mkdir('-p', anotherdir);
-            shell.mkdir(path.join(somedir, '.cordova'));
+            shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
             process.env['PWD'] = anotherdir;
             process.chdir(path.sep);
             expect(util.isCordova()).toEqual(somedir);
@@ -87,11 +88,23 @@ describe('util module', function() {
                 shell.rm('-rf', somedir);
             });
             shell.mkdir('-p', anotherdir);
-            shell.mkdir(path.join(somedir, '.cordova'));
+            shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
             process.env['PWD'] = path.sep;
             process.chdir(anotherdir);
             expect(util.isCordova()).toEqual(somedir);
         });
+        it('should ignore platform www/config.xml', function() {
+            var somedir = path.join(home,'somedir');
+            var anotherdir = path.join(somedir, 'anotherdir');
+            this.after(function() {
+                shell.rm('-rf', somedir);
+            });
+            shell.mkdir('-p', anotherdir);
+            shell.mkdir('-p', path.join(anotherdir, 'www', 'config.xml'));
+            shell.mkdir('-p', path.join(somedir, 'www'));
+            shell.mkdir('-p', path.join(somedir, 'config.xml'));
+            expect(util.isCordova(anotherdir)).toEqual(somedir);
+        });
     });
     describe('deleteSvnFolders method', function() {
         afterEach(function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0eeaa000/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 2ae9184..278172a 100644
--- a/src/util.js
+++ b/src/util.js
@@ -26,6 +26,20 @@ var global_config_path = path.join(HOME, '.cordova');
 var lib_path = path.join(global_config_path, 'lib');
 shell.mkdir('-p', lib_path);
 
+function isRootDir(dir) {
+    if (fs.existsSync(path.join(dir, 'www'))) {
+        // For sure is.
+        if (fs.existsSync(path.join(dir, 'config.xml'))) {
+            return 2;
+        }
+        // Might be (or may be under platforms/).
+        if (fs.existsSync(path.join(dir, 'www', 'config.xml'))) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
 exports = module.exports = {
     globalConfig:global_config_path,
     libDirectory:lib_path,
@@ -42,21 +56,21 @@ exports = module.exports = {
             }
             return this.isCordova(cwd);
         }
+        var bestReturnValueSoFar = false;
         for (var i = 0; i < 1000; ++i) {
-            // The .cordova within the HOME directory doesnt count.
-            if (dir == HOME) {
-                return false;
-            }
-            if (fs.existsSync(path.join(dir, '.cordova'))) {
+            var result = isRootDir(dir);
+            if (result === 2) {
                 return dir;
-            } else {
-                var parentDir = path.normalize(path.join(dir, '..'));
-                // Detect fs root.
-                if (parentDir == dir) {
-                    return false;
-                }
-                dir = parentDir;
             }
+            if (result === 1) {
+                bestReturnValueSoFar = dir;
+            }
+            var parentDir = path.normalize(path.join(dir, '..'));
+            // Detect fs root.
+            if (parentDir == dir) {
+                return bestReturnValueSoFar;
+            }
+            dir = parentDir;
         }
         console.error('Hit an unhandled case in util.isCordova');
         return false;


Mime
View raw message