Created
February 13, 2016 00:58
-
-
Save guemidiborhane/47473524116c31edc0a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Elixir = require('laravel-elixir') | |
config = Elixir.config | |
browserify = require('browserify') | |
gulp = require('gulp') | |
source = require('vinyl-source-stream') | |
path = require('path') | |
coffeeify = require('coffeeify') | |
### | |
# This task run the given coffee files through browserify | |
# using the coffeeify transformation | |
### | |
Elixir.extend 'coffeeify', (src, output, options) -> | |
new (Elixir.Task)('coffeeify', -> | |
make = (file) -> | |
outputFile = path.basename(file).replace('.coffee', '.js') | |
browserify(file, extensions: [ '.coffee' ]).transform(coffeeify).bundle().on('error', (e) -> | |
(new (Elixir.Notification)).error e, 'CoffeeScript Compilation Failed!' | |
@emit 'end' | |
return | |
).pipe(source(outputFile)).pipe(gulp.dest(config.get('public.js.outputFolder'))).pipe new (Elixir.Notification)('CoffeeScript Compiled!') | |
source | |
paths = prepGulpPaths(src, output) | |
files = paths.src.path | |
# To handle array of files | |
if files.constructor != Array | |
files = [ files ] | |
files.map make | |
).watch config.get('assets.js.coffee.folder') + '/**/*.coffee' | |
return | |
###* | |
# Prep the Gulp src and output paths. | |
# | |
# @param {string|array} src | |
# @param {string|null} output | |
# @return {object} | |
### | |
prepGulpPaths = (src, output) -> | |
(new (Elixir.GulpPaths)).src(src, config.get('assets.js.coffee.folder')).output output or config.get('public.js.outputFolder'), 'app.js' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment