1

I want to write my Gruntfile.js with livescript.

I've done Gruntfile.js and Gruntfile.coffee which both work out of the box

Gruntfile.ls should work... right?

I've seen a few Gruntfile.ls online or does it need to be compiles (other than a .coffee version)?

Livescript

(Error when calling $ grunt)

A valid Gruntfile could not be found. Please see the getting started guide for
more information on how to configure grunt: http://gruntjs.com/getting-started
Fatal error: Unable to find Gruntfile.

Gruntfile.ls

#global module:false

module.exports = (grunt) ->

  # Project configuration.
  grunt.init-config {}=

    meta:
      version: \0.0.1

    livescript:
      src:
        files:
          "build/js/main.js": "src/scripts/main.ls"

    watch:
     livescript:
        files: <[src/scripts/**/*.ls]>
        tasks: <[livescript]>
        options: {+livereload}

  # load tasks
  grunt.loadNpmTasks \grunt-livescript
  grunt.loadNpmTasks \grunt-contrib-watch

  # register tasks
  grunt.registerTask \default, <[livescript]>

compiled:

(works when calling $ grunt)

Gruntfile.js

module.exports = function(grunt){
  grunt.initConfig({
    meta: {
      version: '0.0.1'
    },
    livescript: {
      src: {
        files: {
          "build/js/main.js": "src/scripts/main.ls"
        }
      }
    },
    watch: {
      livescript: {
        files: ['src/scripts/**/*.ls'],
        tasks: ['livescript'],
        options: {
          livereload: true
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-livescript');
  grunt.loadNpmTasks('grunt-contrib-watch');
  return grunt.registerTask('default', ['livescript']);
};
  • AFAIK only JavaScript and CoffeeScript are supported by Grunt, but writing a `Gruntfile.js` that compiles your `Gruntfile.ls` and then runs it with the same arguments should do the job. – jgillich Apr 03 '14 at 21:40
  • That's what I figured... since that is documented by grunt. Was just wondering why there are projects that use a livescript Gruntfile e.g.https://github.com/mndvns/polygon/blob/master/Gruntfile.ls BTW. I cloned that repo and of course it throws the same error. Just couldn't find a file in that repo that compiles the `Gruntfile.ls` to `JavaScript` –  Apr 03 '14 at 21:48
  • 1
    They might be doing it manually, at least the `.gitignore` indicates that they are in fact compiling it and not running it directly. – jgillich Apr 03 '14 at 21:56
  • So basically I would need to run `livescript -c Gruntfile.ls && grunt` ... hm ?? does it make me happy? not really.. *sigh* well at least it works –  Apr 03 '14 at 21:57
  • ah.. nice... I missed the .gitignore file. thx –  Apr 03 '14 at 21:57
  • Well for now I made an alias in my `.bash_profile` --> `alias gruntls='livescript -c Gruntfile.ls && grunt' ` thx for the help –  Apr 03 '14 at 22:02

2 Answers2

2

Use this as your Gruntfile.js:

require('LiveScript');

module.exports = function (grunt) {
    require('./Gruntfile.ls')(grunt);
}

Requires the LiveScript package from npm.

jgillich
  • 71,459
  • 6
  • 57
  • 85
0

I prefer to keep main Gruntfile in js, and tasks in ls.

Example setup:

require("LiveScript")
module.exports = function(grunt){
  require('load-grunt-tasks')(grunt) // autoload npmtasks from package.json
  require('load-grunt-config')(grunt) // lets you keep each task in separate file
}

Actually, I use my own fork of load-grunt-config located on https://github.com/wolfflow/load-grunt-config/tree/beta/0.8.0

if you'd like to try it, simply add following string to your package.json file:

"load-grunt-config": "git://github.com/wolfflow/load-grunt-config.git#beta/0.8.0"

and then run npm install.

Daniel K
  • 91
  • 1
  • 6
  • Actually, Gruntfile.js can be event shorter: `require("LiveScript");module.exports = require('load-grunt-config')` (load-grunt-config already includes load-grunt-tasks) – Daniel K Aug 21 '14 at 04:37