gulp-community / gulp-coffee Goto Github PK
View Code? Open in Web Editor NEWCoffeescript plugin for gulp
License: MIT License
Coffeescript plugin for gulp
License: MIT License
I have a "watch" task that watches my coffee files:
coffee = require('gulp-coffee')
util = require('gulp-util')
gulp.task 'coffee', ->
gulp.src([
'assets/js/src/*.coffee'
])
.pipe(coffee(bare: true).on('error', util.log))
.pipe(concat('app.js', newLine: '/*---*/\n'))
.pipe(gulp.dest('assets/js'))
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest('assets/js'))
gulp.task 'watch', ->
gulp.watch 'src/*.coffee', -> gulp.run 'coffee'
even though I have .on('error'), I still get this error and my gulp process dies:
D:\mydirectory\node_modules\gulp-coffee\lib\formatError.js:4
var msg = helpers.prettyErrorMessage(err, file.path, String(file.contents),
^
TypeError: Object #<Object> has no method 'prettyErrorMessage'
at module.exports (D:\mydirectory\node_modules\gulp-coffee\lib\formatError.js:4:21)
at Stream.modifyFile (D:\mydirectory\node_modules\gulp-coffee\index.js:27:22)
at Stream.stream.write (D:\mydirectory\node_modules\gulp-coffee\node_modules\event-stream\node_modules\through\index.js:26:11)
at Stream.ondata (stream.js:51:26)
at Stream.EventEmitter.emit (events.js:95:17)
at queueData (D:\mydirectory\node_modules\gulp\node_modules\vinyl-fs\node_modules\map-stream\index.js:43:21)
at next (D:\mydirectory\node_modules\gulp\node_modules\vinyl-fs\node_modules\map-stream\index.js:71:7)
at D:\mydirectory\node_modules\gulp\node_modules\vinyl-fs\node_modules\map-stream\index.js:85:7
at D:\mydirectory\node_modules\gulp\node_modules\vinyl-fs\lib\src\bufferFile.js:8:5
at fs.js:266:14
at D:\mydirectory\node_modules\gulp-imagemin\node_modules\graceful-fs\graceful-fs.js:103:5
at D:\mydirectory\node_modules\gulp\node_modules\vinyl-fs\node_modules\graceful-fs\graceful-fs.js:103:5
at Object.oncomplete (fs.js:107:15)
Now on gulp-community.
sometimes it only generate a part of my coffee code ,but there is no error,i dont konw why
Please include configuration examples to README.md
I'm pretty sure bumping Node up a couple versions would allow this plugin to grow and do a lot more. Besides, many people even require Node ~0.10.x, this can probably go up to 0.6, no?
The error you are emitting when coffee fails compiling does not have any syntax error information just the message so its hard to debug and find out where and which file the error occurred .
this.emit('error', new Error(err));
Right now i'm doing
this.emit('error', err);
and handling it like this,
console.log("file: "+err.filename)
console.log("line: "+err.location.first_line)
console.log(err.message)
Although i think this reporting should be inbuilt ...
Any plans on supporting ES6? Similarly to this fork..
Im trying to find a way to concatenate a set of Coffeescript files into a single JS files, while still having sourcemaps available.
I first tried gulp-concat but that raises a problem where the sourcemap is referring to a js file which doesn't exist.
I noticed that the Coffeescript compiler has something to join files, the --join
flag.
Tried to apply that but haven't succeed.
Any suggestion on how can I achieve this?
Just to recapitulate, the goal is to compile multiple '.coffee' files into a single '.js' file, while having the sourcemap also merged but still referencing the original coffee files.
I believe this is something already solved in the [https://npmjs.org/package/grunt-contrib-coffee](Grunt task), wonder if it could happen also here.
I'm copy/pasting the example from the readme, and am not getting sourcemaps in my output directory. Any hints to debug?
Hi.
I'm trying to use gulp-watch to compile coffeescript amongst other things (less, browserify, jade, etc).
When I enable the error log handler below, when a coffeescript compile error occurs, it is printed.
The problem is that when I do consecutive writes, I will not get a second compile. Why is this?
gulp.task 'watch1', ->
gulpWatch {
glob: [ 'src/**/*' ]
emitOnGlob: false
}, (sourceStream) ->
destinationStream = gulp.dest 'build'
filterCoffee = gulpFilter [ "**/*.coffee", "**/*.litcoffee" ]
compileCoffee = gulpCoffee bare: true
#compileCoffee.on 'error', (error) ->
# log error
sourceStream
.pipe filterCoffee
.pipe compileCoffee
.pipe destinationStream
I have a directory of files, which I am compiling 1-to-1:
in:
src/
|_ foo/
|_ foo.coffee
|_ bar.coffee
out:
dist/
|_ foo/
|_ foo.js
|_ bar.js
What's the right way to watch and do partial rebuilds when a file changes (ie. only recompile the changed file)? An example would be nice.
I notice that your latest commits removed the unneeded "merge" library. Many of us who use gulp-coffee
just got a security alert email (or a jillion of them) saying that we depend upon an insecure merge library through gulp-coffee
. We can't fix the problem until those commits go into npm. Can you do a point release please, or whatever you think is appropriate? Thank you!
I have a source dir like this:
src/
----/coffee/some1.coffee
----/coffee/some2.coffee
----/coffee/some3.coffee
that I want to end up like this:
dest/
------/some1.js
------/some2.js
------/some3.js
but it keeps ending up like this:
dest/
-----/coffee/some1.js
-----/coffee/some2.js
-----/coffee/some3.js
Is there a way to avoid bringing the nested directories over to the dest dir?
Right now, if you pass sourceMap: true
as an option, it outputs empty files and no source maps. Would be really awesome if this feature could be supported!
Is there a way to use the --eval (not to be confused with eval()) command line option? The readme says normal coffeescript cli options are available, but I coudn't get this one to trigger.
I'm compiling a js file which uses a local path /
for staging, and a global path example.com
for production. Would be extremely helpful to pass in a variable into my gulpfile to use one or the other based on where the gulpfile lives.
var env = require('./env'); // This is where my dev environment string lives
var path = 'http://example.com/'
...
if (env = 'dev') path = '/'
...
.pipe(coffee({bare: true, eval: 'path = ' + path})
Great to see the recent changes to includes
... any plans for CoffeeScript 2 support here?
Hi,
I'm trying to use the coffeescript function "require".
Ex. require('lib/setup');
but at the final file I just get an error about require not being definied.
What is the right way of doing it?
This is super weird, and I'm not totally sure it's gulp-coffee's fault, but hear me out on this one.
Gulp task, compiles coffeescript. I add in the { bare: true }
option, assuming all will go well since I'm compiling node anyway. When they come out, the coffeescript extension __extends
is not getting compiled at the top of files that use classes (this is breaking and causes all files with classes to immediately throw an error).
Get rid of the bare option and it's back, albeit with an extra useless function wrapper now. Looks like a bug in coffeescript to me, really. Make sure locally installed coffeescript is the same version as the one required by gulp-coffee (1.6.3, yep, but you guys should be using 1.x.x
in your package.json, because semver), compile the file manually with the bare option. __extends
is defined in the files, and no function wrapper, everything works perfectly. Wat?
So I checked the source and it looks like you guys are just compiling through coffee-script
, as usual, but I figured I'd at least log this here because compiling with coffee manually didn't break anything, but the compilation through gulp caused breakage.
Any thoughts or help on this appreciated!
You should test against 0.8 instead, maybe?
Currently the *.js.map
files are generated as siblings to the *.coffee
files.
A convenient sourceMapDir
option would make this configurable.
For example:
var coffee = require('gulp-coffee');
gulp.task('coffee', function () {
gulp.src('./src/*.coffee')
.pipe(coffee({sourceMapDir: 'maps/'}))
.pipe(gulp.dest('./public/'));
});
Coffeescript is up to version 1.10
this module is still on 1.9
See the example:
https://github.com/kuchumovn/gulp-coffee-sourcemaps
coffee:
gulp.task 'coffee_build', ->
gulp
.src 'build/coffee/*.coffee'
.pipe coffee bare: true
.pipe gulp.dest "build/js/"
native:
gulp.task('coffee_build', function() {
return gulp.src('build/coffee/*.coffee').pipe(coffee({
bare: true
})).pipe(gulp.dest("build/js/"));
});
Hi,
coffeescript
Dropped support for old Node versions (pre Node 6 it seems) but CI
for this package is running on Node 0.10
, 0.11
and 4
so it always fail.
It would also be nice to update the engines.node
field in the package.json
.
coffee-script should be a peer dependency, so that users can decide what version of coffee-script they want for themselves.
I would like to write an error handler that writes a small JS file when gulp-coffee fails. For example if a.coffee
has a syntax error, I want to create a.js
with:
throw new Error('Error compiling a.coffee: <syntaxerror.stack>');
For this, my gulp task needs access to the name of the JS file that gulp-coffee was trying to create.
My gulpfile:
var gulp = require('gulp');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var coffee = require('gulp-coffee');
gulp.task('watch', function () {
var src = ...;
var dest = ...;
return gulp.src(src)
.pipe(watch(src).on(change, gutil.log))
.pipe(coffee().on('error', gutil.log))
.pipe(gulp.dest(dest));
});
I used gulp watch
, and wrote a coffee file which was then compiled. Then I made a syntax error in that coffee file, so gulp logged an error. Gulp still logged file changes when I fixed that syntax error & saved, however coffee file was not compiled again.
input:
console.log 1
console.log 2
coffeescript compiler output:
(function() {
console.log(1);
console.log(2);
}).call(this);
expected output:
(function() {
console.log(1);
console.log(2);
}).call(this);
How not to strip empty lines?
coffeeStream = coffee().on('error', (error) ->
{filename} = error
extension = path.extname(error.filename)
dirname = path.dirname(filename)
basename = path.basename(error.filename, '.coffee')
target = path.join(dirname, "#{basename}.js")
)
gulp.task("coffee", () ->
return gulp.src(dedupeGlobs(paths.coffee))
.pipe(sourcemaps.init())
.pipe(ngClassify(ngClassifyOptions))
.pipe(coffeeStream)
.pipe(ngAnnotate())
.pipe(sourcemaps.write())
.pipe(gulp.dest(COMPILE_PATH))
I have a syntax error in one of the files being loaded into the task.
The following prints to the console:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: [stdin]:1:1: error: unexpected &
&*^%$^#&*()_
I've tried adding gulp-plumber, but all it did was prevent gulp from exiting.
When compiling .coffee.md
files with default options,
gulp-util
only recognizes .md
as the extension, thus the resulting output files are named xyz.coffee.js
I'm having trouble getting nicely formatted errors. Following the example, I have the following:
// Compile coffee into temp folder, unconcatenated and uniminified.
gulp.task('scripts', function (done) {
return gulp.src(appSrc.scripts)
.pipe(plumber())
.pipe(coffee({bare: false}).on('error', util.log))
.pipe(ngAnnotate())
.pipe(gulp.dest(compileDest.scripts))
.pipe(size())
;
});
But I get output that looks like this:
[10:53:53] { [SyntaxError: unexpected newline]
location:
{ first_line: 849,
first_column: 51,
last_line: 849,
last_column: 51 },
toString: [Function],
code: '\n# Not a good thing\nhandleError = (debug, task) -> (error) ->\n debug.error \'Error\', error\n alert "An error occured while performing #{ task }"\n\nangular.module \'hummingbirdControllers\', [\'hummingbirdConstants\', \'ngAnimate\']\n\n.controller \'LoginCtrl\' [CODE REDACTED...]',
filename: '/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/app/scripts/controllers.coffee',
name: 'SyntaxError',
message: 'unexpected newline',
stack: '/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/app/scripts/controllers.coffee:850:52: error: unexpected newline\n "#{ invitationsRoute }/:invitationId": [\'GET\']\u001b[1;31m\u001b[0m\n\u001b[1;31m ^\u001b[0m',
showStack: false,
showProperties: true,
plugin: 'gulp-coffee' }
How can I get this to be formatted and readable? I've updated gutil, gulp and gulp-coffee to the newest versions...
Hi,
I see that your library is using lock files but I believe that you should avoid it.
Lock files are great to get reproducible builds for applications (top level packages) but should be avoided in libraries (non top level packages) because it prevents CI to automatically get the latest version of the dependencies: devs have to update it manually. This is a problem because lock files are not used for library consumers. It means that consumers are always the first to be affected by breakage in transitive dependencies while it would be better to catch it in your own CI.
gutil.File => https://www.npmjs.com/package/vinyl
gutil.replaceExtension => The .extname property on Vinyl objects or https://www.npmjs.com/package/replace-ext
gutil.colors => https://www.npmjs.com/package/ansi-colors
gutil.date => https://www.npmjs.com/package/date-format
gutil.log => https://www.npmjs.com/package/fancy-log
gutil.template => https://www.npmjs.com/package/lodash.template
gutil.env => https://www.npmjs.com/package/minimist
gutil.beep => https://www.npmjs.com/package/beeper
gutil.noop => https://www.npmjs.com/package/through2
gutil.isStream => Use the .isStream() method on Vinyl objects
gutil.isBuffer => Use the .isBuffer() method on Vinyl objects
gutil.isNull => Use the .isNull() method on Vinyl objects
gutil.linefeed => Use the string '\n' in your code
gutil.combine => https://www.npmjs.com/package/multipipe
gutil.buffer => https://www.npmjs.com/package/list-stream
gutil.PluginError => https://www.npmjs.com/package/plugin-error
Please release new version of gulp-coffee with included coffee-script 1.10.0 dependency.
I have a fairly large codebase and I would like to launch livereload when all the coffeescript files have been compiled. Right now, it's a race when I use the change event. Would love an end event that I could bind to.
This was touched on in #14, but here is the problem:
coffee(join:true) is not the same as coffee() + concat()
The latter will have extra cruft because each input file will be wrapped with the function safety wrapper.
Here's the code that doesn't work:
gulp.task 'concat', ->
gulp.src myFilesInOrder, baseDir: myBaseDir
.pipe coffee
join: true
.on 'error', gutil.log
.pipe gulp.dest myDestFile
This was just a one-liner to scratch an immediate itch, but I guess a proper solution from someone with more free time would involve somehow handling the conditional dependencies of ICS/Coco in the package.json or eliminating coffee-script
from that file. I figure that opening this issue (even if it's immediately closed) will probably be helpful to someone.
Coffee->Coco:
disruptek/gulp-coco@37448a120e4bf32d7996fdf4b7ef3032654222bd
Coffee->Iced
disruptek/gulp-coco@44b6273ea2c04c30c857b1f77b40912b6a614d82
Thank you for gulp-coffee. :-)
My gulpfile in coffee:
gulp = require 'gulp'
coffee = require 'gulp-coffee'
gutil = require 'gulp-util'
connect = require 'gulp-connect'
gulp.task 'coffee', ->
gulp.src ['index.coffee', '!gulpfile.coffee']
.pipe coffee( bare: true ).on('error', gutil.log)
.pipe gulp.dest '.'
.pipe connect.reload()
gulp.task 'watch', ->
gulp.watch ['index.coffee', '!gulpfile.coffee'], ['coffee']
gulp.task "connect", connect.server(
root: __dirname
port: 3000
livereload: true
)
gulp.task 'default', ['coffee', 'connect', 'watch']
When error occurred, gulp.watch
still stops. when new files changes, nothing happens.
Then i tried to switch to gulp-watch
plugin, problem still there.
So I'm wondering if the problem belong to gulp-coffee
itself.
If there something wrong with my gulpfile, I'm sorry to bother you. I'm not sure where the problem is.
Hey
How can I include another files inside my coffee script? And have gulp to process that?
How to generate maps?
map: true does not work. A review of the source code seems to indicate that this flag is not passed through. Am I missing something?
I just installed the latest verison...I am getting a blank .js file...what is happening.
gulp = require 'gulp'
coffee = require 'gulp-coffee'
gutil = require 'gulp-util'
gulp.task 'default', ->
gulp.src('./routes/index.coffee')
.pipe coffee({sourceMap:true}).on('error',gutil.log)
.pipe gulp.dest('./routes/')
gulp
would blank out index.js
I have some AngularJS modules written in coffeescript. They suddenly stopped working with error message like "at
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.