11'use strict' ;
22
33var path = require ( 'path' ) ;
4- var fs = require ( 'fs' ) ;
54var browserify = require ( 'browserify' ) ;
6- var derequire = require ( 'derequire' ) ; // This is a silly thing to type
5+ var derequire = require ( 'derequire' ) ;
76
87var bannerTemplate = '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */' ;
98
109module . 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