Skip to content

Instantly share code, notes, and snippets.

@ucin
Last active August 29, 2015 14:04
Show Gist options
  • Save ucin/557b3f1114376aeb8796 to your computer and use it in GitHub Desktop.
Save ucin/557b3f1114376aeb8796 to your computer and use it in GitHub Desktop.
Grunt.js file for development environment,
'use strict';
module.exports = function (grunt) {
var env = grunt.option('env') || 'dev';
var testFile = grunt.option('file') || 'test/**/*.js';
var banner = '/*\n<%= pkg.name %> <%= pkg.version %>';
banner += '- <%= pkg.description %>\n<%= pkg.repository.url %>\n';
banner += 'Built on <%= grunt.template.today("yyyy-mm-dd") %>\n*/\n';
var globalConfig = {};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
globalConfig: globalConfig,
env: {
options: {
},
dev: {
NODE_ENV: 'development'
},
prod: {
NODE_ENV: 'production'
}
},
watch: {
options: {
spawn: true,
},
files: ['gruntfile.js', 'app/**/*.js', 'app/config.js', 'test/**/*.js'],
tasks: ['jshint', 'mochaTest']
},
jshint: {
options: {
force: true,
reporter: require('jshint-stylish'),
jshintrc: '.jshintrc'
},
files: {
src: ['gruntfile.js', 'app/**/*.js', 'app/config.js', 'test/**/*.js']
}
},
nodemon: {
prod: {
options: {
file: 'bin/cabin',
args: ['new', 'testsite'],
nodeArgs: ['--debug', '--debug-brk']
}
}
},
mochaTest: {
test: {
options: {
reporter: 'spec',
ignoreLeaks: false,
clearRequireCache: true,
colors: true
},
src: [testFile]
},
},
shell: {
debugtest: {
options: {
stdout: true
},
command: 'mocha --debug-brk --recursive'
},
debugtestdev: {
options: {
stdout: true
},
command: 'NODE_ENV=dev node --debug-brk $(which grunt) test'
}
},
'node-inspector': {
default: {}
},
concurrent: {
test: ['shell:debugtest', 'node-inspector'],
testdev: ['node-inspector', 'shell:debugtestdev'],
options: {
logConcurrentOutput: true
}
}
});
grunt.registerTask('spec', 'Runs a task on a specified file', function (fileName) {
globalConfig.file = fileName;
grunt.task.run('simplemocha:spec');
});
grunt.registerTask('debug', ['concurrent:test']);
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('default', ['watch']);
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment