forked from kpdecker/jsdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
168 lines (151 loc) · 3.97 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* eslint-env node */
/* eslint-disable no-process-env, camelcase */
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/'
}]
}
},
webpack: {
options: {
context: 'lib/',
output: {
path: 'dist/',
library: 'JsDiff',
libraryTarget: 'umd'
}
},
dist: {
entry: './index.js',
output: {
filename: 'diff.js'
}
}
},
mochaTest: {
test: {
options: {
require: ['babel-core/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
},
sauce: {
singleRun: true,
browsers: ['sl_chrome', 'sl_firefox', 'sl_safari', 'sl_ie_11', 'sl_ie_9']
}
},
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/'}
]
},
components: {
files: [
{expand: true, cwd: 'components/', src: ['**'], dest: 'dist/components'},
{expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/components'}
]
}
},
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', 'webpack']);
this.registerTask('test', ['build', 'mochaTest', 'karma:unit']);
this.registerTask('cover', ['mocha_istanbul:coverage', 'istanbul_check_coverage']);
this.registerTask('release', ['clean', 'test', 'uglify', 'copy:dist', 'copy:components']);
// 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-webpack');
grunt.task.loadTasks('tasks');
grunt.registerTask('travis',
!process.env.KARMA && process.env.SAUCE_USERNAME
? ['clean', 'build', 'karma:unit', 'karma:sauce', 'cover']
: ['clean', 'build', 'cover']);
grunt.registerTask('dev', ['clean', 'watch']);
grunt.registerTask('default', ['clean', 'build', 'cover']);
};