grunt

CoffeeScriptでモジュールを作る際のGruntfile.coffee

More than 5 years have passed since last update.

毎回使うパターンだったので書いておく。

ファイル結合 + mochaによるテスト

$ npm install grunt grunt-contrib grunt-simple-mocha --save-dev

Gruntfile.coffee

module.exports = (grunt) ->

grunt.loadNpmTasks 'grunt-contrib'
grunt.loadNpmTasks 'grunt-simple-mocha'

grunt.initConfig
connect:
server:
options:
port: 8888
base: '.'

watch:
coffee:
files: "src/**/*.coffee",
tasks: ["coffee"]

coffee_with_test:
files: ["src/**/*.coffee", 'test/**/*_test.coffee'],
tasks: ["coffee:compile", 'simplemocha']

coffee:
compile:
files:
'dist/all.js': [
"src/**/*.coffee"
]

simplemocha:
options:
globals: ['should']
timeout: 3000
ignoreLeaks: false
ui: 'bdd'
reporter: 'spec'
compilers: 'coffee:coffee-script'
all:
src: 'test/**/*.coffee'

grunt.registerTask "run", ["coffee","connect", "watch:coffee"]
grunt.registerTask "run_with_test", ["coffee","connect", "watch:coffee_with_test"]