forked from angular-ui/ui-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
112 lines (105 loc) · 3.82 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var testacular = require('testacular');
/*global module:false*/
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
// Project configuration.
grunt.initConfig({
builddir: 'build',
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '/**\n' + ' * <%= pkg.description %>\n' +
' * @version v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @license MIT License, http://www.opensource.org/licenses/MIT\n' + ' */',
prefix: '(function (window, angular, undefined) {',
suffix: '})(window, window.angular);'
},
clean: [ '<%= builddir %>' ],
concat: {
build: {
src: [
'<banner:meta.banner>',
'<banner:meta.prefix>',
'src/common.js',
'src/templateFactory.js',
'src/urlMatcherFactory.js',
'src/urlRouter.js',
'src/state.js',
'src/viewDirective.js',
'src/compat.js',
'<banner:meta.suffix>'
],
dest: '<%= builddir %>/<%= pkg.name %>.js'
}
},
uglify: {
build: {
files: {
'<%= builddir %>/<%= pkg.name %>.min.js': ['<banner:meta.banner>', '<%= concat.build.dest %>']
}
}
},
jshint: {
all: ['Gruntfile.js', 'src/*.js', '<%= builddir %>/<%= pkg.name %>.js'],
options: {
eqnull: true
}
},
watch: {
files: ['src/*.js', 'test/**/*.js'],
tasks: ['build', 'test']
},
connect: {
server: {}
}
});
grunt.registerTask('default', ['build', 'jshint', 'test']);
grunt.registerTask('build', 'Perform a normal build', ['concat', 'uglify']);
grunt.registerTask('dist', 'Perform a clean build and generate documentation', ['clean', 'build', 'jsdoc']);
grunt.registerTask('dev', 'Run dev server and watch for changes', ['build', 'connect', 'watch']);
grunt.registerTask('test-server', 'Start testacular server', function () {
//Mark the task as async but never call done, so the server stays up
var done = this.async();
testacular.server.start({ configFile: 'test/test-config.js'});
});
grunt.registerTask('test', 'Run tests (make sure test-server task is run first)', function () {
var done = this.async();
grunt.util.spawn({
cmd: process.platform === 'win32' ? 'testacular.cmd' : 'testacular',
args: process.env.TRAVIS ? ['start', 'test/test-config.js', '--single-run', '--no-auto-watch', '--reporter=dots', '--browsers=Firefox'] : ['run']
}, function (error, result, code) {
if (error) {
grunt.warn("Make sure the testacular server is online: run `grunt test-server`.\n" +
"Also make sure you have a browser open to http://localhost:8080/.\n" +
error.stdout + error.stderr);
//the testacular runner somehow modifies the files if it errors(??).
//this causes grunt's watch task to re-fire itself constantly,
//unless we wait for a sec
setTimeout(done, 1000);
} else {
grunt.log.write(result.stdout);
done();
}
});
});
grunt.registerTask('jsdoc', 'Generate documentation', function () {
var done = this.async();
grunt.util.spawn({
cmd: 'node_modules/jsdoc/jsdoc',
args: [ '-c', 'jsdoc-conf.json', '-d', grunt.config('builddir') + '/doc', 'src' ]
}, function (error, result, code) {
if (error) {
grunt.log.write(error.stderr + '\n');
grunt.warn("jsdoc generation failed");
} else {
grunt.log.write(result.stderr + result.stdout);
}
done();
});
});
};