Last active
August 29, 2015 14:03
-
-
Save thiagomata/1f6a7c3b47bcb7c16399 to your computer and use it in GitHub Desktop.
A workaround to be able to create the maps files into a separate file of the javascript files from the coffescript files what are into a tree structure.
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
project | |
src | |
coffee | |
foo.coffee | |
component | |
bar.coffee | |
animals | |
dog.coffee | |
cat.coffee | |
public | |
scripts | |
foo.js | |
maps | |
foo.js.map | |
component | |
bar.js | |
maps | |
bar.js.map | |
animals | |
dog.js | |
cat.js | |
maps | |
dog.js.map | |
cat.js.map |
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
var gulp = require('gulp'); | |
var $plugin = require('gulp-load-plugins')({ camelize: true}); | |
var gutil = require('gutil'); | |
var glob = require('glob'); | |
var path = require('path'); | |
/** | |
* Project Paths | |
*/ | |
glob.paths = { | |
publicScript: './public/scripts/', | |
srcCoffee: './src/coffee/' | |
}; | |
/** | |
* Create the javascript and map files from the coffeescripts | |
*/ | |
gulp.task('coffee-map', function( callback ) { | |
// // this what we want to do, but doesn't work as excepted // | |
// gulp.src(glob.paths.srcCoffee + '**/*.coffee') | |
// .pipe($plugin.sourcemaps.init()) | |
// .pipe($plugin.coffee({bare: true}).on('error', gutil.log)) | |
// .pipe($plugin.sourcemaps.write( './maps/')) | |
// .pipe(gulp.dest(glob.paths.publicScript)); | |
/** | |
* @workaround This is a not so easy or fast way to compile the coffee | |
* scripts and create the maps but it was necessary to the current version | |
* @todo use the tradicional way when fixed | |
* @link https://github.com/gulpjs/gulp/issues/356 | |
*/ | |
var coffeeFiles = glob.sync( glob.paths.srcCoffee + '**/*.coffee'); | |
var intCounter = 0; | |
coffeeFiles.forEach(function(fullPathFileName){ | |
var srcDir = path.dirname(fullPathFileName); | |
var srcRelativeDir = srcDir.substr(glob.paths.srcCoffee.length); | |
var destDir = glob.paths.publicScript + srcRelativeDir + "/"; | |
var answer = gulp.src(fullPathFileName) | |
.pipe($plugin.sourcemaps.init()) | |
.pipe($plugin.coffee({bare: true}).on('error', gutil.log)) | |
.pipe($plugin.sourcemaps.write( './maps/')) | |
.pipe(gulp.dest(destDir)); | |
answer.on('end',function(){ | |
intCounter++; | |
if( intCounter >= coffeeFiles.length ) { | |
callback(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment