|
| 1 | +require 'cake-gulp' |
| 2 | +path = require 'path' |
| 3 | + |
| 4 | +browserify = require 'browserify' |
| 5 | +watchify = require 'watchify' |
| 6 | + |
| 7 | +cjsx = require 'coffee-reactify' |
| 8 | +uglify = require 'uglifyify' |
| 9 | + |
| 10 | +jquery = "#{path.dirname require.resolve 'jquery/dist/jquery'}" |
| 11 | +semantic = "#{path.dirname require.resolve 'semantic-ui/dist/semantic'}" |
| 12 | + |
| 13 | +option '-w', '--watch', 'Watchify files.' |
| 14 | + |
| 15 | +task 'build:clean', 'Delete all auto-generated files.', (options, callback) -> |
| 16 | + del ["#{__dirname}/dist/**/*"], (error, files) -> |
| 17 | + if error |
| 18 | + throw error |
| 19 | + log "[#{green 'Deleted'}]\n#{files.map(fancypath).join '\n'}" |
| 20 | + callback() |
| 21 | + |
| 22 | +task 'build:files', 'Copies static files.', ['build:clean'], (options, callback) -> |
| 23 | + files = [ |
| 24 | + "#{__dirname}/src/**/*.html" |
| 25 | + "#{__dirname}/src/**/*.png" |
| 26 | + "#{__dirname}/src/**/*.min.*" |
| 27 | + "#{jquery}/**/jquery.min.*" |
| 28 | + "#{semantic}/**/semantic.min.*" |
| 29 | + "#{semantic}/**/icons.*" |
| 30 | + ] |
| 31 | + # if options.watch |
| 32 | + # watch files, 'build:files' |
| 33 | + src files |
| 34 | + .pipe dest "#{__dirname}/dist" |
| 35 | + |
| 36 | +task 'build', 'Browserify all the things!', ['build:files'], (options, callback) -> |
| 37 | + config = |
| 38 | + entry: './src/bundle.cjsx' |
| 39 | + path: "#{__dirname}/dist" |
| 40 | + debug: options.watch |
| 41 | + if options.watch |
| 42 | + for own key of watchify.args |
| 43 | + unless key of options |
| 44 | + config[key] = watchify.args[key] |
| 45 | + for own key of options |
| 46 | + config[key] = options[key] |
| 47 | + bundler = if options.watch then watchify browserify config else browserify config |
| 48 | + |
| 49 | + bundler.transform [cjsx, extension: 'cjsx'] |
| 50 | + unless options.watch |
| 51 | + bundler.transform [uglify, global: yes] |
| 52 | + bundler.require require.resolve(config.entry), entry: yes |
| 53 | + |
| 54 | + rebuild = (files) -> |
| 55 | + if Array.isArray files |
| 56 | + files = files |
| 57 | + .map fancypath |
| 58 | + .join '\n' |
| 59 | + log "[#{green if options.watch then 'Watchify!' else 'Browserify!'}]\n#{files or '...'}" |
| 60 | + bundler |
| 61 | + .bundle() |
| 62 | + .on 'error', log.bind 'Browserify Error: ' |
| 63 | + .pipe source config.entry |
| 64 | + .pipe rename 'bundle.min.js' |
| 65 | + .pipe dest config.path |
| 66 | + |
| 67 | + bundler |
| 68 | + .on 'update', rebuild |
| 69 | + .on 'log', log |
| 70 | + |
| 71 | + rebuild() |
0 commit comments