Search code examples
gruntjslivescript

how to use a Gruntfile.ls (livescript Grunt)


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

Solution

  • Use this as your Gruntfile.js:

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

    Requires the LiveScript package from npm.