Skip to content

Commit ce344be

Browse files
committed
Address PR comments in custom browserify task
1 parent 7a4d8c7 commit ce344be

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Gruntfile.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ module.exports = function(grunt) {
5858
reporter: require('jscs-stylish').path
5959
},
6060
build: {
61-
src: ['Gruntfile.js']
61+
src: [
62+
'Gruntfile.js',
63+
'build/**/*.js'
64+
]
6265
},
6366
source: {
6467
src: [
@@ -77,7 +80,10 @@ module.exports = function(grunt) {
7780
options: {
7881
jshintrc: '.jshintrc'
7982
},
80-
src: ['Gruntfile.js']
83+
src: [
84+
'Gruntfile.js',
85+
'build/**/*.js'
86+
]
8187
},
8288
source: {
8389
options: {

build/tasks/browserify.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'use strict';
22

33
var path = require('path');
4-
var fs = require('fs');
54
var browserify = require('browserify');
6-
var derequire = require('derequire'); // This is a silly thing to type
5+
var derequire = require('derequire');
76

87
var bannerTemplate = '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */';
98

109
module.exports = function(grunt) {
1110

12-
var libFilePath = path.join(process.cwd(), 'lib/p5.js');
13-
var srcFilePath = path.join(process.cwd(), 'src/app.js');
11+
var srcFilePath = require.resolve('../../src/app.js');
12+
13+
// This file will not exist until it has been built
14+
var libFilePath = path.resolve('lib/p5.js');
1415

1516
grunt.registerTask('browserify', 'Compile the p5.js source with Browserify', function() {
1617
// Reading and writing files is asynchronous
@@ -33,12 +34,19 @@ module.exports = function(grunt) {
3334
bundle.on('data', function(data) {
3435
code += data;
3536
}).on('end', function() {
37+
3638
// "code" is complete: create the distributable UMD build by running
3739
// the bundle through derequire, then write the bundle to disk.
3840
// (Derequire changes the bundle's internal "require" function to
3941
// something that will not interfere with this module being used
4042
// within a separate browserify bundle.)
41-
fs.writeFile(libFilePath, derequire(code), done);
43+
grunt.file.write(libFilePath, derequire(code));
44+
45+
// Print a success message
46+
grunt.log.writeln('>>'.green + ' Bundle ' + 'lib/p5.js'.cyan + ' created.');
47+
48+
// Complete the task
49+
done();
4250
});
4351
});
4452
};

0 commit comments

Comments
 (0)