-
Notifications
You must be signed in to change notification settings - Fork 504
/
Gruntfile.js
144 lines (127 loc) · 3.26 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-env node */
/* eslint-disable no-process-env, camelcase */
const pkg = require('./package.json');
const babel = require('rollup-plugin-babel');
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
options: {
},
files: [
'src/**/*.js',
'test/**/*.js'
]
},
clean: ['lib', 'dist'],
babel: {
cjs: {
files: [{
cwd: 'src/',
expand: true,
src: '**/*.js',
dest: 'lib/'
}]
}
},
exec: {
rollup: {
command: 'rollup -c'
}
},
mochaTest: {
test: {
options: {
require: ['@babel/register'],
reporter: 'dot'
},
src: ['test/**/*.js']
}
},
mocha_istanbul: {
coverage: {
src: 'test/**/*.js'
}
},
istanbul_check_coverage: {
'default': {
options: {
coverageFolder: 'coverage*', // will check both coverage folders and merge the coverage results
check: {
statements: 100,
functions: 100,
branches: 100,
lines: 100
}
}
}
},
karma: {
options: {
configFile: 'karma.conf.js',
autoWatch: false
},
unit: {
singleRun: true
},
},
uglify: {
options: {
mangle: true,
compress: true,
preserveComments: 'some'
},
dist: {
files: [{
cwd: 'dist/',
expand: true,
src: ['*.js', '!*.min.js'],
dest: 'dist/',
rename: function(dest, src) {
return dest + src.replace(/\.js$/, '.min.js');
}
}]
}
},
copy: {
dist: {
options: {
processContent: function(content) {
return grunt.template.process('/*!\n\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n@license\n*/\n')
+ content;
}
},
files: [
{expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/'}
]
}
},
watch: {
scripts: {
options: {
atBegin: true
},
files: ['src/**/*.js', 'test/**/*.js'],
tasks: ['build', 'mochaTest', 'cover']
}
}
});
// Build a new version of the library
this.registerTask('build', 'Builds a distributable version of the current project', ['eslint', 'babel', 'exec:rollup']);
this.registerTask('test', ['build', 'mochaTest', 'karma:unit']);
this.registerTask('cover', ['mocha_istanbul:coverage', 'istanbul_check_coverage']);
this.registerTask('release', ['clean', 'test', 'uglify', 'copy:dist']);
// Load tasks from npm
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('dev', ['clean', 'watch']);
grunt.registerTask('default', ['clean', 'build', 'cover']);
};