You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/10/04 09:41:40 UTC
[5/7] git commit: before and after build hooks
before and after build hooks
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/cb2e1f3c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/cb2e1f3c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/cb2e1f3c
Branch: refs/heads/cordova-client
Commit: cb2e1f3c187ddfc8dd46cbaa6e5bb362fa976eaa
Parents: d49d263
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Oct 3 21:16:51 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Oct 3 21:16:51 2012 -0700
----------------------------------------------------------------------
spec/build.spec.js | 33 +++++++++++++++++++++++++++++----
src/build.js | 14 ++++++++++++++
2 files changed, 43 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/cb2e1f3c/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index b36861e..5533b3c 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -7,6 +7,7 @@ var cordova = require('../cordova'),
android_parser = require('../src/metadata/android_parser'),
ios_parser = require('../src/metadata/ios_parser'),
blackberry_parser = require('../src/metadata/blackberry_parser'),
+ hooker = require('../src/hooker'),
fixtures = path.join(__dirname, 'fixtures'),
hooks = path.join(fixtures, 'hooks'),
tempDir = path.join(__dirname, '..', 'temp');
@@ -239,17 +240,41 @@ describe('build command', function() {
});
describe('hooks', function() {
+ var s;
beforeEach(function() {
cordova.create(tempDir);
process.chdir(tempDir);
- cordova.platform('add', 'android');
+ s = spyOn(hooker.prototype, 'fire').andReturn(true);
});
-
afterEach(function() {
process.chdir(cwd);
+ shell.rm('-rf', tempDir);
+ });
+
+ describe('when platforms are added', function() {
+ beforeEach(function() {
+ cordova.platform('add', 'android');
+ spyOn(shell, 'exec').andReturn({code:0});
+ });
+
+ it('should fire before hooks through the hooker module', function() {
+ cordova.build();
+ expect(s).toHaveBeenCalledWith('before_build');
+ });
+ it('should fire after hooks through the hooker module', function() {
+ cordova.build();
+ expect(s).toHaveBeenCalledWith('after_build');
+ });
});
- it('should delegate before hooks to the hooker module');
- it('should delegate after hooks to the hooker module');
+ describe('with no platforms added', function() {
+ it('should not fire the hooker', function() {
+ spyOn(shell, 'exec').andReturn({code:0});
+ expect(function() {
+ cordova.build();
+ }).toThrow();
+ expect(s).not.toHaveBeenCalled();
+ });
+ });
});
});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/cb2e1f3c/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index 1af02ec..239582e 100644
--- a/src/build.js
+++ b/src/build.js
@@ -8,6 +8,7 @@ var cordova_util = require('./util'),
android_parser= require('./metadata/android_parser'),
blackberry_parser= require('./metadata/blackberry_parser'),
ios_parser = require('./metadata/ios_parser'),
+ hooker = require('./hooker'),
n = require('ncallbacks'),
prompt = require('prompt'),
util = require('util');
@@ -53,6 +54,16 @@ module.exports = function build (platforms, callback) {
if (platforms.length === 0) throw 'No platforms added to this project. Please use `cordova platform add <platform>`.';
+ var hooks = new hooker(projectRoot);
+ if (!(hooks.fire('before_build'))) {
+ throw 'before_build hooks exited with non-zero code. Aborting build.';
+ }
+ var fire_after_hooks = function() {
+ if (!(hooks.fire('after_build'))) {
+ throw 'after_build hooks exited with non-zero code. Aborting.';
+ }
+ };
+
var end = n(platforms.length, function() {
if (callback) callback();
});
@@ -69,6 +80,7 @@ module.exports = function build (platforms, callback) {
// Update the related platform project from the config
parser.update_project(cfg);
shell_out_to_debug(projectRoot, 'android');
+ fire_after_hooks();
end();
break;
case 'blackberry-10':
@@ -79,6 +91,7 @@ module.exports = function build (platforms, callback) {
parser.update_project(cfg, function() {
// Shell it
shell_out_to_debug(projectRoot, 'blackberry-10');
+ fire_after_hooks();
end();
});
break;
@@ -89,6 +102,7 @@ module.exports = function build (platforms, callback) {
// Update the related platform project from the config
parser.update_project(cfg, function() {
shell_out_to_debug(projectRoot, 'ios');
+ fire_after_hooks();
end();
});
break;