Permalink
Browse files

Updated browserify task after p5 update to be sure this lib can stand…

…alone
  • Loading branch information...
1 parent 2f4019e commit eb6d2d4a4cc49fee31146dd77eb5cbfee9846fd9 @sarahgp committed Aug 19, 2015
Showing with 99 additions and 55 deletions.
  1. +9 −18 Gruntfile.js
  2. +52 −0 build/tasks/browserify.js
  3. +1 −1 doc/index.html
  4. +1 −1 doc/led.js.html
  5. +1 −1 doc/module-Server-Side%20Events_%20LED.html
  6. +32 −32 lib/p5bots.js
  7. +1 −1 lib/p5bots.min.js
  8. +2 −1 package.json
View
@@ -50,7 +50,10 @@ module.exports = function(grunt) {
reporter: require('jscs-stylish').path
},
build: {
- src: ['Gruntfile.js']
+ src: [
+ 'Gruntfile.js',
+ 'build/**/*.js'
+ ]
},
source: {
src: [
@@ -70,7 +73,10 @@ module.exports = function(grunt) {
options: {
jshintrc: '.jshintrc'
},
- src: ['Gruntfile.js']
+ src: [
+ 'Gruntfile.js',
+ 'build/**/*.js'
+ ]
},
source: {
options: {
@@ -142,21 +148,6 @@ module.exports = function(grunt) {
}
},
- // Build p5bots client source into a single, UMD-wrapped file
- browserify: {
- p5: {
- options: {
- transform: ['brfs'],
- browserifyOptions: {
- standalone: 'p5bots'
- },
- banner: '/*! p5bots.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */'
- },
- src: 'src/client/app.js',
- dest: 'lib/p5bots.js'
- }
- },
-
// This minifies the javascript into a single file and adds a banner to the
// front of the file.
uglify: {
@@ -201,7 +192,7 @@ module.exports = function(grunt) {
});
// Load the external libraries used.
- grunt.loadNpmTasks('grunt-browserify');
+ grunt.loadTasks('build/tasks');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jsdoc');
@@ -0,0 +1,52 @@
+'use strict';
+
+var path = require('path');
+var browserify = require('browserify');
+var derequire = require('derequire');
+
+var bannerTemplate = '/*! p5bots.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */';
+
+module.exports = function(grunt) {
+
+ var srcFilePath = require.resolve('../../src/client/app.js');
+
+ // This file will not exist until it has been built
+ var libFilePath = path.resolve('lib/p5bots.js');
+
+ grunt.registerTask('browserify', 'Compile the p5bots.js source with Browserify', function() {
+ // Reading and writing files is asynchronous
+ var done = this.async();
+
+ // Render the banner for the top of the file
+ var banner = grunt.template.process(bannerTemplate);
+
+ // Invoke Browserify programatically to bundle the code
+ var bundle = browserify(srcFilePath, {
+ standalone: 'p5js'
+ })
+ .transform('brfs')
+ .bundle();
+
+ // Start the generated output with the banner comment,
+ var code = banner + '\n';
+
+ // Then read the bundle into memory so we can run it through derequire
+ bundle.on('data', function(data) {
+ code += data;
+ }).on('end', function() {
+
+ // "code" is complete: create the distributable UMD build by running
+ // the bundle through derequire, then write the bundle to disk.
+ // (Derequire changes the bundle's internal "require" function to
+ // something that will not interfere with this module being used
+ // within a separate browserify bundle.)
+ grunt.file.write(libFilePath, derequire(code));
+
+ // Print a success message
+ grunt.log.writeln('>>'.green + ' Bundle ' + 'lib/p5bots.js'.cyan + ' created.');
+
+ // Complete the task
+ done();
+ });
+ });
+};
View
@@ -64,7 +64,7 @@ <h1 class="page-title">Home</h1>
<br class="clear">
<footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 21:35:27 GMT-0400 (EDT)
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 22:00:02 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
View
@@ -112,7 +112,7 @@ <h1 class="page-title">Source: led.js</h1>
<br class="clear">
<footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 21:35:27 GMT-0400 (EDT)
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 22:00:02 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
@@ -386,7 +386,7 @@ <h4 class="name" id=".fade"><span class="type-signature">(static) </span>fade<sp
<br class="clear">
<footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 21:35:27 GMT-0400 (EDT)
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 22:00:02 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
View
@@ -1,9 +1,9 @@
/*! p5bots.js v0.0.2 August 18, 2015 */
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.p5bots = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.p5js = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
'use strict';
-var utils = require('./lib/socket_utils.js');
-var special = require('./lib/special_methods_index.js');
+var utils = _dereq_('./lib/socket_utils.js');
+var special = _dereq_('./lib/special_methods_index.js');
var modeError = "Please check mode. Value should be 'analog', 'digital', 'pwm', or servo"; // jshint ignore:line
@@ -113,8 +113,8 @@ p5.serial = special.serial;
-},{"./lib/socket_utils.js":9,"./lib/special_methods_index.js":10}],2:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./lib/socket_utils.js":9,"./lib/special_methods_index.js":10}],2:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function button (pin) {
@@ -156,8 +156,8 @@ function button (pin) {
module.exports = button;
-},{"./socket_utils.js":9}],3:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],3:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function led(pin) {
utils.dispatch(utils.pinInit(pin.pin, pin.mode, pin.direction));
@@ -236,8 +236,8 @@ function led(pin) {
module.exports = led;
-},{"./socket_utils.js":9}],4:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],4:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function motor(pin) {
utils.dispatch(utils.pinInit(pin.pin, pin.mode, pin.direction));
@@ -268,8 +268,8 @@ function motor(pin) {
}
module.exports = motor;
-},{"./socket_utils.js":9}],5:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],5:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function piezo(pin) {
utils.dispatch(utils.pinInit(pin.pin, pin.mode, pin.direction));
@@ -323,8 +323,8 @@ function piezo(pin) {
}
module.exports = piezo;
-},{"./socket_utils.js":9}],6:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],6:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function rgb(pin) {
// Unpack pin object & initialize pins
@@ -485,8 +485,8 @@ function rgb(pin) {
module.exports = rgb;
-},{"./socket_utils.js":9}],7:[function(require,module,exports){
-var utils = require('./socket_utils.js'),
+},{"./socket_utils.js":9}],7:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js'),
socket = utils.socket,
serialObj = {};
@@ -532,8 +532,8 @@ var serial = function() {
};
module.exports = serial;
-},{"./socket_utils.js":9}],8:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],8:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function servo(pin) {
utils.dispatch(utils.pinInit(pin.pin, pin.mode, pin.direction));
@@ -584,7 +584,7 @@ function servo(pin) {
}
module.exports = servo;
-},{"./socket_utils.js":9}],9:[function(require,module,exports){
+},{"./socket_utils.js":9}],9:[function(_dereq_,module,exports){
var socket = io.connect('http://localhost:8000/sensors');
socket.on('error', function(err){
console.log(err);
@@ -704,32 +704,32 @@ var utils = {
};
module.exports = utils;
-},{}],10:[function(require,module,exports){
+},{}],10:[function(_dereq_,module,exports){
var special = {
- button: require('./button.js'),
+ button: _dereq_('./button.js'),
- led: require('./led.js'),
+ led: _dereq_('./led.js'),
- motor: require('./motor.js'),
+ motor: _dereq_('./motor.js'),
- piezo: require('./piezo.js'),
+ piezo: _dereq_('./piezo.js'),
- rgbled: require('./rgb.js'),
+ rgbled: _dereq_('./rgb.js'),
- serial: require('./serial.js'),
+ serial: _dereq_('./serial.js'),
- servo: require('./servo.js'),
+ servo: _dereq_('./servo.js'),
- temp: require('./temp.js'),
+ temp: _dereq_('./temp.js'),
- vres: require('./variable_resistor.js')
+ vres: _dereq_('./variable_resistor.js')
};
module.exports = special;
-},{"./button.js":2,"./led.js":3,"./motor.js":4,"./piezo.js":5,"./rgb.js":6,"./serial.js":7,"./servo.js":8,"./temp.js":11,"./variable_resistor.js":12}],11:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./button.js":2,"./led.js":3,"./motor.js":4,"./piezo.js":5,"./rgb.js":6,"./serial.js":7,"./servo.js":8,"./temp.js":11,"./variable_resistor.js":12}],11:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function temp(pin) {
// Unpack pin object, pluck data & reassign pin num to pin.pin for generation
@@ -753,8 +753,8 @@ function temp(pin) {
}
module.exports = temp;
-},{"./socket_utils.js":9}],12:[function(require,module,exports){
-var utils = require('./socket_utils.js');
+},{"./socket_utils.js":9}],12:[function(_dereq_,module,exports){
+var utils = _dereq_('./socket_utils.js');
function vres(pin) {
Oops, something went wrong.

0 comments on commit eb6d2d4

Please sign in to comment.