|
| 1 | +module.exports = (grunt) -> |
| 2 | + |
| 3 | + # Project configuration. |
| 4 | + grunt.initConfig |
| 5 | + pkg: grunt.file.readJSON "package.json" |
| 6 | + coffeelint: |
| 7 | + app: [ |
| 8 | + "*.coffee" |
| 9 | + "accessories/**/*.coffee" |
| 10 | + "test/**/*.coffee" |
| 11 | + ] |
| 12 | + options: |
| 13 | + no_trailing_whitespace: |
| 14 | + level: "ignore" |
| 15 | + max_line_length: |
| 16 | + value: 100 |
| 17 | + indentation: |
| 18 | + value: 2 |
| 19 | + level: "error" |
| 20 | + no_unnecessary_fat_arrows: |
| 21 | + level: 'ignore' |
| 22 | + |
| 23 | + mochaTest: |
| 24 | + test: |
| 25 | + options: |
| 26 | + reporter: "spec" |
| 27 | + require: ['coffee-errors'] #needed for right line numbers in errors |
| 28 | + src: ["test/*"] |
| 29 | + # blanket is used to record coverage |
| 30 | + testBlanket: |
| 31 | + options: |
| 32 | + reporter: "dot" |
| 33 | + src: ["test/*"] |
| 34 | + coverage: |
| 35 | + options: |
| 36 | + reporter: "html-cov" |
| 37 | + quiet: true |
| 38 | + captureFile: "coverage.html" |
| 39 | + src: ["test/*"] |
| 40 | + |
| 41 | + grunt.loadNpmTasks "grunt-coffeelint" |
| 42 | + grunt.loadNpmTasks "grunt-mocha-test" |
| 43 | + |
| 44 | + grunt.registerTask "blanket", => |
| 45 | + blanket = require "blanket" |
| 46 | + |
| 47 | + blanket( |
| 48 | + pattern: (file) -> |
| 49 | + if file.match "pimatic-hap/accessories" then return true |
| 50 | + #if file.match "pimatic/node_modules" then return false |
| 51 | + withoutPrefix = file.replace(/.*\/node_modules\/pimatic/, "") |
| 52 | + return (not withoutPrefix.match 'node_modules') and (not withoutPrefix.match "/test/") |
| 53 | + loader: "./node-loaders/coffee-script" |
| 54 | + ) |
| 55 | + |
| 56 | + grunt.registerTask "clean-coverage", => |
| 57 | + fs = require "fs" |
| 58 | + path = require "path" |
| 59 | + |
| 60 | + replaceAll = (find, replace, str) => |
| 61 | + escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") |
| 62 | + str.replace(new RegExp(escapeRegExp(find), 'g'), replace) |
| 63 | + |
| 64 | + file = "#{__dirname}/coverage.html" |
| 65 | + html = fs.readFileSync(file).toString() |
| 66 | + html = replaceAll path.dirname(__dirname), "", html |
| 67 | + fs.writeFileSync file, html |
| 68 | + |
| 69 | + # Default task(s). |
| 70 | + grunt.registerTask "default", ["coffeelint", "mochaTest:test"] |
| 71 | + grunt.registerTask "test", ["coffeelint", "mochaTest:test"] |
| 72 | + grunt.registerTask "coverage", |
| 73 | + ["blanket", "mochaTest:testBlanket", "mochaTest:coverage", "clean-coverage"] |
0 commit comments