cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [2/2] git commit: [CB-4002] Dont fire hooks or recurse into directories that begin with a dot.
Date Tue, 02 Jul 2013 22:42:32 GMT
[CB-4002] Dont fire hooks or recurse into directories that begin with a dot.


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

Branch: refs/heads/master2
Commit: cbbc7b6a708a7bb692b14cd4c78a1d3ae76b0839
Parents: 20447ea
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Jul 2 15:42:24 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Jul 2 15:42:24 2013 -0700

----------------------------------------------------------------------
 spec/hooker.spec.js | 98 ++++++++++++++++++++++++------------------------
 src/hooker.js       |  4 +-
 2 files changed, 52 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cbbc7b6a/spec/hooker.spec.js
----------------------------------------------------------------------
diff --git a/spec/hooker.spec.js b/spec/hooker.spec.js
index a85fc88..4711b17 100644
--- a/spec/hooker.spec.js
+++ b/spec/hooker.spec.js
@@ -107,61 +107,61 @@ describe('hooker', function() {
         });
 
         describe('success', function() {
-            it('should execute all scripts in order and fire callback', function(done) {
-                var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build');
-                shell.mkdir('-p', hook);
-                this.after(function() { shell.rm('-rf', tempDir); });
-                if (platform.match(/(win32|win64)/)) {
-                    shell.cp(path.join(hooks, 'test', '0.bat'), hook);
-                    shell.cp(path.join(hooks, 'test', '1.bat'), hook);
-                } else {
-                    shell.cp(path.join(hooks, 'test', '0.sh'), hook);
-                    shell.cp(path.join(hooks, 'test', '1.sh'), hook);
-                }
-                fs.readdirSync(hook).forEach(function(script) {
-                    fs.chmodSync(path.join(hook, script), '754');
-                });
-                var returnValue;
-                var s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
-                    cb(0, '');
-                });
-                h.fire('before_build', function(err) {
-                    expect(err).not.toBeDefined();
+            describe('project-level hooks', function() {
+                var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build'),
+                    s;
+                beforeEach(function() {
+                    shell.mkdir('-p', hook);
                     if (platform.match(/(win32|win64)/)) {
-                        expect(s.calls[0].args[0]).toMatch(/0.bat/);
-                        expect(s.calls[1].args[0]).toMatch(/1.bat/);
+                        shell.cp(path.join(hooks, 'test', '0.bat'), hook);
+                        shell.cp(path.join(hooks, 'test', '1.bat'), hook);
                     } else {
-                        expect(s.calls[0].args[0]).toMatch(/0.sh/);
-                        expect(s.calls[1].args[0]).toMatch(/1.sh/);
+                        shell.cp(path.join(hooks, 'test', '0.sh'), hook);
+                        shell.cp(path.join(hooks, 'test', '1.sh'), hook);
                     }
-                    done();
+                    fs.readdirSync(hook).forEach(function(script) {
+                        fs.chmodSync(path.join(hook, script), '754');
+                    });
+                    s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                        cb(0, '');
+                    });
                 });
-            });
-            it('should pass the project root folder as parameter into the project-level hooks',
function(done) {
-                var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build');
-                shell.mkdir('-p', hook);
-                this.after(function() { shell.rm('-rf', tempDir); });
-                if (platform.match(/(win32|win64)/)) {
-                    shell.cp(path.join(hooks, 'test', '0.bat'), hook);
-                } else {
-                    shell.cp(path.join(hooks, 'test', '0.sh'), hook);
-                }
-                fs.readdirSync(hook).forEach(function(script) {
-                    fs.chmodSync(path.join(hook, script), '754');
+                afterEach(function() {
+                    shell.rm('-rf', tempDir);
                 });
-                var s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
-                    cb(0, '');
+                it('should execute all scripts in order and fire callback', function(done)
{
+                    h.fire('before_build', function(err) {
+                        expect(err).not.toBeDefined();
+                        if (platform.match(/(win32|win64)/)) {
+                            expect(s.calls[0].args[0]).toMatch(/0.bat/);
+                            expect(s.calls[1].args[0]).toMatch(/1.bat/);
+                        } else {
+                            expect(s.calls[0].args[0]).toMatch(/0.sh/);
+                            expect(s.calls[1].args[0]).toMatch(/1.sh/);
+                        }
+                        done();
+                    });
                 });
-                h.fire('before_build', function(err) {
-                    expect(err).not.toBeDefined();
-                    var param_str;
-                    if (platform.match(/(win32|win64)/)) {
-                        param_str = '0.bat "'+tempDir+'"';
-                    } else { 
-                        param_str = '0.sh "'+tempDir+'"'; 
-                    }
-                    expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
-                    done();
+                it('should pass the project root folder as parameter into the project-level
hooks', function(done) {
+                    h.fire('before_build', function(err) {
+                        expect(err).not.toBeDefined();
+                        var param_str;
+                        if (platform.match(/(win32|win64)/)) {
+                            param_str = '0.bat "'+tempDir+'"';
+                        } else { 
+                            param_str = '0.sh "'+tempDir+'"'; 
+                        }
+                        expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
+                        done();
+                    });
+                });
+                it('should skip any files starting with a dot on the scripts', function(done)
{
+                    shell.cp(path.join(hooks, 'test', '0.bat'), path.join(hook, '.swp.file'));
+                    h.fire('before_build', function(err) {
+                        expect(err).not.toBeDefined();
+                        expect(s).not.toHaveBeenCalledWith(path.join(tempDir, '.cordova',
'hooks', 'before_build', '.swp.file') + ' "' + tempDir + '"', jasmine.any(Object), jasmine.any(Function));
+                        done();
+                    });
                 });
             });
             describe('module-level hooks', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cbbc7b6a/src/hooker.js
----------------------------------------------------------------------
diff --git a/src/hooker.js b/src/hooker.js
index b5e39d4..eb27f50 100644
--- a/src/hooker.js
+++ b/src/hooker.js
@@ -57,7 +57,9 @@ module.exports.prototype = {
             if (!(fs.existsSync(dir))) {
                 callback(); // hooks directory got axed post-create; ignore.
             } else {
-                var scripts = fs.readdirSync(dir);
+                var scripts = fs.readdirSync(dir).filter(function(s) {
+                    return s[0] != '.';
+                });
                 execute_scripts_serially(scripts, self.root, dir, function(err) {
                     if (err) {
                         callback(err);


Mime
View raw message