Git Product home page Git Product logo

gulp-coffee's Introduction

Build Status

Information

Packagegulp-coffee
Description Compiles CoffeeScript
Node Version >= 6

Usage

var coffee = require('gulp-coffee');

gulp.task('coffee', function() {
  gulp.src('./src/*.coffee')
    .pipe(coffee({bare: true}))
    .pipe(gulp.dest('./public/'));
});

Options

  • coffee (optional): A reference to a custom CoffeeScript version/fork (eg. coffee: require('my-name/coffeescript'))

Additionally, the options object supports all options that are supported by the standard CoffeeScript compiler.

Source maps

gulp 3.x

gulp-coffee can be used in tandem with gulp-sourcemaps to generate source maps for the coffee to javascript transition. You will need to initialize gulp-sourcemaps prior to running the gulp-coffee compiler and write the source maps after.

var sourcemaps = require('gulp-sourcemaps');

gulp.src('./src/*.coffee')
  .pipe(sourcemaps.init())
  .pipe(coffee())
  .pipe(sourcemaps.write())
  .pipe(gulp.dest('./dest/js'));

// will write the source maps inline in the compiled javascript files

By default, gulp-sourcemaps writes the source maps inline in the compiled javascript files. To write them to a separate file, specify a relative file path in the sourcemaps.write() function.

var sourcemaps = require('gulp-sourcemaps');

gulp.src('./src/*.coffee')
  .pipe(sourcemaps.init())
  .pipe(coffee({ bare: true }))
  .pipe(sourcemaps.write('./maps'))
  .pipe(gulp.dest('./dest/js'));

// will write the source maps to ./dest/js/maps

gulp 4.x

In gulp 4, sourcemaps are built-in by default.

gulp.src('./src/*.coffee', { sourcemaps: true })
  .pipe(coffee({ bare: true }))
  .pipe(gulp.dest('./dest/js'));

LICENSE

(MIT License)

Copyright (c) 2015 Fractal [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gulp-coffee's People

Contributors

adamloving avatar alubbe avatar bcherny avatar brandonson avatar dashed avatar demurgos avatar felixrabe avatar floridoo avatar funkytek avatar hackerone avatar jackjennings avatar joaumg avatar kcreate avatar kevva avatar leny avatar lettertwo avatar mattparlane avatar pdehaan avatar shinnn avatar stephenlacy avatar svsool avatar thedancingcode avatar typicode avatar yocontra avatar zakuni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-coffee's Issues

generate question

sometimes it only generate a part of my coffee code ,but there is no error,i dont konw why

SyntaxError

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 ...

Support Source Maps

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!

How to use "require"

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?

gulp-coffee won't compile after an error occured(and handled) when used with gulp-watch

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.

Remove lock files

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.

seems to exit the process when a compile error happens.

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

How not to strip empty lines?

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?

Error handler being ignored

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.

wrong extensions for `coffee.md` files

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

Needs new release to remove merge vulnerability

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!

Formatting errors with gulp-util

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...

Strange bug with bare option

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!

Bump node version

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?

remove gulp-util using the following API replacements

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

support for --eval option?

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})

Move only files to dest, without the src directories.

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?

End event

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.

Join compiled JS and sourcemaps

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.

Update Node versions tested in CI

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.

Converts variables with @$ to _at_$

I have some AngularJS modules written in coffeescript. They suddenly stopped working with error message like "at$stateProvider" not found. I compare the compiled javascript between gulp-coffee 2.2.0 and 2.2.1 and see that wherever I refer to a variable or parameter with @$, it gets converted to at$.

Errors stops gulp.watch even though they were already handled

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.

Support the --join option

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

supporting IcedCoffeeScript and Coco

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. :-)

"prettyErrorMessage" kills gulp process

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)

Is gulp-coffee broken

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

do sourcemaps still work?

I'm copy/pasting the example from the readme, and am not getting sourcemaps in my output directory. Any hints to debug?

Be able to configure Source Map Directory

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/'));
});

Expose path information on failure

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.

What's the canonical way to do partial rebuilds?

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.

Maps

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.