Permalink
Browse files

Merge pull request #1 from svnlto/master

AMD/Node.js Build - Consistent Formatting etc.
  • Loading branch information...
2 parents 4599504 + 52f0d20 commit 5d8717b1bbc0f8923759fad139c0d3a295993b26 @efeminella committed May 18, 2012
Showing with 1,252 additions and 36,611 deletions.
  1. +3 −0 .gitignore
  2. +62 −68 README.md
  3. +0 −1 backbone-eventbroker-min.js
  4. +98 −30 build/build.js
  5. +0 −332 build/node_modules/.bin/uglifyjs
  6. +0 −4 build/node_modules/uglify-js/.npmignore
  7. +0 −981 build/node_modules/uglify-js/README.html
  8. +0 −578 build/node_modules/uglify-js/README.org
  9. +0 −332 build/node_modules/uglify-js/bin/uglifyjs
  10. +0 −75 build/node_modules/uglify-js/docstyle.css
  11. +0 −2,599 build/node_modules/uglify-js/lib/consolidator.js
  12. +0 −75 build/node_modules/uglify-js/lib/object-ast.js
  13. +0 −1,346 build/node_modules/uglify-js/lib/parse-js.js
  14. +0 −2,011 build/node_modules/uglify-js/lib/process.js
  15. +0 −73 build/node_modules/uglify-js/lib/squeeze-more.js
  16. +0 −24 build/node_modules/uglify-js/package.json
  17. +0 −24 build/node_modules/uglify-js/package.json~
  18. +0 −28 build/node_modules/uglify-js/test/beautify.js
  19. +0 −403 build/node_modules/uglify-js/test/testparser.js
  20. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/array1.js
  21. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/array2.js
  22. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/array3.js
  23. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/array4.js
  24. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/assignment.js
  25. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/concatstring.js
  26. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/const.js
  27. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js
  28. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/forstatement.js
  29. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/if.js
  30. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js
  31. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js
  32. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue10.js
  33. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue11.js
  34. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue13.js
  35. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue14.js
  36. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue16.js
  37. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue17.js
  38. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue20.js
  39. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue21.js
  40. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue25.js
  41. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue27.js
  42. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue278.js
  43. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue28.js
  44. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue29.js
  45. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue30.js
  46. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue34.js
  47. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue4.js
  48. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue48.js
  49. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue50.js
  50. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue53.js
  51. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js
  52. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue68.js
  53. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue69.js
  54. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/issue9.js
  55. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/mangle.js
  56. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/null_string.js
  57. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js
  58. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/var.js
  59. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/whitespace.js
  60. +0 −1 build/node_modules/uglify-js/test/unit/compress/expected/with.js
  61. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/array1.js
  62. +0 −4 build/node_modules/uglify-js/test/unit/compress/test/array2.js
  63. +0 −4 build/node_modules/uglify-js/test/unit/compress/test/array3.js
  64. +0 −6 build/node_modules/uglify-js/test/unit/compress/test/array4.js
  65. +0 −20 build/node_modules/uglify-js/test/unit/compress/test/assignment.js
  66. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/concatstring.js
  67. +0 −5 build/node_modules/uglify-js/test/unit/compress/test/const.js
  68. +0 −4 build/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js
  69. +0 −10 build/node_modules/uglify-js/test/unit/compress/test/forstatement.js
  70. +0 −6 build/node_modules/uglify-js/test/unit/compress/test/if.js
  71. +0 −9 build/node_modules/uglify-js/test/unit/compress/test/ifreturn.js
  72. +0 −16 build/node_modules/uglify-js/test/unit/compress/test/ifreturn2.js
  73. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue10.js
  74. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue11.js
  75. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue13.js
  76. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue14.js
  77. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue16.js
  78. +0 −4 build/node_modules/uglify-js/test/unit/compress/test/issue17.js
  79. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue20.js
  80. +0 −6 build/node_modules/uglify-js/test/unit/compress/test/issue21.js
  81. +0 −7 build/node_modules/uglify-js/test/unit/compress/test/issue25.js
  82. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue27.js
  83. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue278.js
  84. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue28.js
  85. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue29.js
  86. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue30.js
  87. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue34.js
  88. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue4.js
  89. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue48.js
  90. +0 −9 build/node_modules/uglify-js/test/unit/compress/test/issue50.js
  91. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue53.js
  92. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/issue54.1.js
  93. +0 −5 build/node_modules/uglify-js/test/unit/compress/test/issue68.js
  94. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/issue69.js
  95. +0 −4 build/node_modules/uglify-js/test/unit/compress/test/issue9.js
  96. +0 −5 build/node_modules/uglify-js/test/unit/compress/test/mangle.js
  97. +0 −1 build/node_modules/uglify-js/test/unit/compress/test/null_string.js
  98. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/strict-equals.js
  99. +0 −3 build/node_modules/uglify-js/test/unit/compress/test/var.js
  100. +0 −21 build/node_modules/uglify-js/test/unit/compress/test/whitespace.js
  101. +0 −2 build/node_modules/uglify-js/test/unit/compress/test/with.js
  102. +0 −55 build/node_modules/uglify-js/test/unit/scripts.js
  103. +0 −13 build/node_modules/uglify-js/tmp/269.js
  104. +0 −22,315 build/node_modules/uglify-js/tmp/app.js
  105. +0 −15 build/node_modules/uglify-js/tmp/embed-tokens.js
  106. +0 −26 build/node_modules/uglify-js/tmp/goto.js
  107. +0 −8 build/node_modules/uglify-js/tmp/goto2.js
  108. +0 −33 build/node_modules/uglify-js/tmp/hoist.js
  109. +0 −97 build/node_modules/uglify-js/tmp/instrument.js
  110. +0 −138 build/node_modules/uglify-js/tmp/instrument2.js
  111. +0 −8 build/node_modules/uglify-js/tmp/liftvars.js
  112. +0 −30 build/node_modules/uglify-js/tmp/test.js
  113. +0 −3,930 build/node_modules/uglify-js/tmp/uglify-hangs.js
  114. +0 −166 build/node_modules/uglify-js/tmp/uglify-hangs2.js
  115. +0 −18 build/node_modules/uglify-js/uglify-js.js
  116. +28 −0 build/templates/backbone-eventbroker.amd.js
  117. +30 −0 build/templates/backbone-eventbroker.js
  118. +241 −0 dist/backbone-eventbroker.amd.js
  119. +1 −0 dist/backbone-eventbroker.amd.min.js
  120. +243 −0 dist/backbone-eventbroker.js
  121. +1 −0 dist/backbone-eventbroker.min.js
  122. +94 −87 examples/basic/index.html
  123. +9 −0 package.json
  124. +205 −210 spec/backbone-eventbroker-spec.js
  125. +24 −24 spec/spec-runner.html
  126. +213 −224 src/backbone-eventbroker.js
View
@@ -0,0 +1,3 @@
+.DS_Store
+*.swp
+node_modules/
View
130 README.md
@@ -7,11 +7,11 @@ The `EventBroker` can be used directly to publish and subscribe to events of int
``` javascript
var Users = Backbone.Collection.extend{{
initialize: function(){
- // subscribe to an event ...
- Backbone.EventBroker.on('users:add', this.add, this);
+ // subscribe to an event ...
+ Backbone.EventBroker.on('users:add', this.add, this);
},
add: function(user) {
- console.log(user.id);
+ console.log(user.id);
}
};
@@ -21,13 +21,13 @@ var UserEditor = Backbone.View.extend({
this.$userId = this.$('#userId');
},
add: function() {
- // publish an event ...
- var user = new User({id: this.$userId().val()});
- Backbone.EventBroker.trigger('users:add', user);
+ // publish an event ...
+ var user = new User({id: this.$userId().val()});
+ Backbone.EventBroker.trigger('users:add', user);
}
};
// ...
-```
+```
### Creating namespaced EventBrokers
The `EventBroker` API can be used to create and retrieve any number of specific namespaced `EventBrokers`. A namespaced `EventBroker` ensures that all events are published and subscribed against a specific namespace.
@@ -38,30 +38,30 @@ Namespaced `EventBrokers` are retrieved via `Backbone.EventBroker.get([namespace
var Users = Backbone.Collection.extend{{
// use the 'users' broker
usersBroker: Backbone.EventBroker.get('users'),
-
+
initialize: function(broker){
- this.usersBroker.on('add', this.add, this);
+ this.usersBroker.on('add', this.add, this);
},
add: function(user) {
- console.log(user.id);
+ console.log(user.id);
}
};
var UserEditor = Backbone.View.extend({
el: '#editor',
// use the 'users' broker
usersBroker: Backbone.EventBroker.get('users'),
-
+
// also use the 'roles' broker
rolesBroker : Backbone.EventBroker.get('roles'),
-
+
initialize: function(broker){
- this.$userId = this.$('#userId');
+ this.$userId = this.$('#userId');
},
add: function() {
- // publish an event
- var user = new User({id: this.$userId().val()});
- this.usersBroker.trigger('add', user);
+ // publish an event
+ var user = new User({id: this.$userId().val()});
+ this.usersBroker.trigger('add', user);
}
};
```
@@ -72,32 +72,32 @@ Since namespaced `EventBrokers` ensure events are only piped thru the `EventBrok
var Users = Backbone.Collection.extend{{
// use the 'users' broker
userBroker: Backbone.EventBroker.get('users'),
-
+
initialize: function(broker){
- // prefix the namespace if desired
- this.userBroker.on('users:add', this.add, this);
+ // prefix the namespace if desired
+ this.userBroker.on('users:add', this.add, this);
},
add: function(user) {
- console.log(user.id);
+ console.log(user.id);
}
};
var UserEditor = Backbone.View.extend({
el: '#editor',
// use the 'users' broker
usersBroker: Backbone.EventBroker.get('users'),
-
+
// also use the unique 'roles' broker
rolesBroker: Backbone.EventBroker.get('roles'),
-
+
initialize: function(broker){
- this.$userId = this.$('#userId');
+ this.$userId = this.$('#userId');
},
add: function() {
- // publish an event
- var user = new User({id: this.$userId().val()});
- // prefix the namespace if desired
- this.usersBroker.trigger('users:add', user);
+ // publish an event
+ var user = new User({id: this.$userId().val()});
+ // prefix the namespace if desired
+ this.usersBroker.trigger('users:add', user);
}
};
```
@@ -107,17 +107,15 @@ Modules can register events of interest with an `EventBroker` via the default '[
``` javascript
// Register event/callbacks based on a hash and associated context
-var Users = Backbone.Collection.extend(
-{
- initialize: function()
- {
- Backbone.EventBroker.register({
- 'user:select' : 'select',
- 'user:deselect' : 'deselect',
- 'user:edit' : 'edit',
- 'user:update' : 'update',
- 'user:remove' : 'remove'
- }, this );
+var Users = Backbone.Collection.extend({
+ initialize: function() {
+ Backbone.EventBroker.register({
+ 'user:select' : 'select',
+ 'user:deselect' : 'deselect',
+ 'user:edit' : 'edit',
+ 'user:update' : 'update',
+ 'user:remove' : 'remove'
+ }, this );
},
select: function() { ... },
deselect: function() { ... },
@@ -131,20 +129,18 @@ Alternately, Modules can simply define an "interests" property containing partic
``` javascript
// Register event/callbacks based on a hash and associated context
-var Users = Backbone.Collection.extend(
-{
+var Users = Backbone.Collection.extend({
// defines events of interest and their corresponding callbacks
this.interests: {
- 'user:select' : 'select',
- 'user:deselect' : 'deselect',
- 'user:edit' : 'edit',
- 'user:update' : 'update',
- 'user:remove' : 'remove'
+ 'user:select' : 'select',
+ 'user:deselect' : 'deselect',
+ 'user:edit' : 'edit',
+ 'user:update' : 'update',
+ 'user:remove' : 'remove'
},
- initialize: function()
- {
- // register this object with the EventBroker
- Backbone.EventBroker.register( this );
+ initialize: function() {
+ // register this object with the EventBroker
+ Backbone.EventBroker.register( this );
},
select: function() { ... },
deselect: function() { ... },
@@ -158,28 +154,26 @@ Modules can use different namespaced `EventBrokers` for different things...
``` javascript
// Register event/callbacks with different EventBrokers...
-var CartView = Backbone.View.extend(
-{
+var CartView = Backbone.View.extend({
// Reference the 'items' EventBroker...
itemsBroker: Backbone.EventBroker.get('items'),
-
+
// Reference the 'inventory' EventBroker...
- inventoryBroker: Backbone.EventBroker.get('inventory'),
-
- initialize: function()
- {
- // register events/callbacks with 'items' EventBroker...
- this.itemsBroker.register({
- 'add' : 'add',
- 'update' : 'update',
- 'remove' : 'remove'
- }, this );
- // register events/callbacks with 'inventory' EventBroker...
- this.inventoryBroker.register({
- 'select' : 'select',
- 'deselect' : 'deselect',
- 'edit' : 'edit'
- }, this );
+ inventoryBroker: Backbone.EventBroker.get('inventory'),
+
+ initialize: function() {
+ // register events/callbacks with 'items' EventBroker...
+ this.itemsBroker.register({
+ 'add' : 'add',
+ 'update' : 'update',
+ 'remove' : 'remove'
+ }, this );
+ // register events/callbacks with 'inventory' EventBroker...
+ this.inventoryBroker.register({
+ 'select' : 'select',
+ 'deselect' : 'deselect',
+ 'edit' : 'edit'
+ }, this );
},
add: function() { ... },
update: function() { ... },

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,34 +1,102 @@
+/**
+ * Builds the distribution files from /src
+ *
+ * Includes code from Miller Medeiros, http://blog.millermedeiros.com/node-js-as-a-build-script/
+ */
-var parser = require( 'uglify-js' ).parser,
- uglify = require( 'uglify-js' ).uglify,
- fs = require( 'fs' ),
- src = '../src/backbone-eventbroker.js',
- built = '../backbone-eventbroker-min.js';
-
-var _build = function()
-{
- console.log( 'Loading ' + src );
-
- fs.readFile( src, 'utf8', function ( error, data ) {
- if ( error ) {
- return console.log( 'Error' + error );
- }
- _write( _minify( data ) );
- });
-};
+// DEPENDENCIES
+var fs = require('fs'),
+ util = require('util'),
+ _ = require('underscore'),
+ uglifyJS = require('uglify-js');
-var _minify = function( source ) {
- var ast = uglify.ast_squeeze( uglify.ast_mangle( parser.parse( source ) ) );
- return uglify.gen_code( ast );
-};
+// CONFIG
+var outputDir = __dirname + '/../dist',
+ srcDir = __dirname + '/../src',
+ templateDir = __dirname + '/templates',
+ eol = '\n',
+ fileEncoding = 'utf-8',
+ packageJSON = JSON.parse(fs.readFileSync(__dirname + '/../package.json', fileEncoding));
+
+// SETTINGS
+// Use mustache template tags
+_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
+
+
+// TASKS
+/**
+ * Build the output by concatenating files and optionally wrapping them in a template
+ *
+ * @param {String[]} fileList File paths, relative to current directory
+ * @param {String} outputPath Relative path to output file
+ * @param {Object} [options]
+ *
+ * @param {String} [options.template] Template for adding headers/footers etc. Content will inserted in place of a {{body}} tag
+ * @param {Object} [options.data] Date to populate template tags (in {{tag}} format)
+ */
+function build(fileList, outputPath, options) {
+ var out = fileList.map(function(filePath) {
+ filePath = filePath;
+
+ return fs.readFileSync(filePath, fileEncoding);
+ });
+
+ var content = out.join(eol);
+
+ if (options && options.template) {
+ var data = _.extend(options.data, {
+ body: content
+ });
+
+ var templateString = fs.readFileSync(options.template, fileEncoding);
+
+ content = _.template(templateString, data);
+ }
+
+ fs.writeFileSync(outputPath, content);
-var _write = function( min )
-{
- fs.writeFile( built, min, function( error ) {
- if ( error ) {
- return console.log( 'Error' + error );
- }
- console.log( 'Minified ' + built + '\nDone' );
- });
+ console.log('READY: ' + outputPath);
+}
+
+/**
+ * Minify files using UglifyJS
+ * @param {String} srcPath Relative path to source file
+ * @param {outputPath} outputPath Relative path to output file
+ */
+function uglify(srcPath, outputPath) {
+ var parse = uglifyJS.parser.parse,
+ uglify = uglifyJS.uglify;
+
+ var output = parse(fs.readFileSync(srcPath, fileEncoding));
+
+ output = uglify.ast_mangle(output);
+ output = uglify.ast_squeeze(output);
+
+ fs.writeFileSync(outputPath, uglify.gen_code(output), fileEncoding);
+
+ console.log('READY: ' + outputPath);
+}
+
+// RUN
+var fileList = [
+ srcDir + '/backbone-eventbroker.js'
+];
+
+var templateData = {
+ version: packageJSON.version
};
-_build();
+
+//Main file
+build(fileList, outputDir + '/backbone-eventbroker.js', {
+ template: templateDir + '/backbone-eventbroker.js',
+ data: templateData
+});
+uglify(outputDir + '/backbone-eventbroker.js', outputDir + '/backbone-eventbroker.min.js');
+
+
+//File for AMD (requireJS)
+build(fileList, outputDir + '/backbone-eventbroker.amd.js', {
+ template: templateDir + '/backbone-eventbroker.amd.js',
+ data: templateData
+});
+uglify(outputDir + '/backbone-eventbroker.amd.js', outputDir + '/backbone-eventbroker.amd.min.js');
Oops, something went wrong.

0 comments on commit 5d8717b

Please sign in to comment.