forked from TablePress/TablePress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
214 lines (198 loc) · 4.38 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* TablePress Grunt configuration
*
* Performs syntax checks and minifies CSS and JS files.
* To run, use "npm install" and "grunt build" in the main plugin folder.
* Running just "grunt" will run the "watch" task, which will automatically
* lint and minify all changed CSS or JS files.
*/
/* jshint node: true */
module.exports = function( grunt ) {
var autoprefixer = require( 'autoprefixer' );
// Load tasks
require( 'matchdep' ).filterDev( 'grunt-*' ).forEach( grunt.loadNpmTasks );
// Task configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
// Syntax validation of JavaScript files
jsvalidate: {
options: {
globals: {},
esprimaOptions: {},
verbose: false
},
all: {
src: [
'**/*.js',
'!node_modules/**/*.js'
]
},
changed: {
src: []
}
},
// JavaScript coding style validation
jshint: {
options: '<%= pkg.jshintConfig %>',
all: {
src: [
'<%= jsvalidate.all.src %>',
'!**/*.min.js'
]
},
changed: {
src: []
}
},
// JavaScript minification
uglify: {
options: {
ASCIIOnly: true,
screwIE8: false
},
all: {
expand: true,
ext: '.min.js',
extDot: 'last',
src: [
'<%= jshint.all.src %>',
'!Gruntfile.js'
]
},
changed: {
expand: true,
ext: '.min.js',
extDot: 'last',
src: []
}
},
// Validation of JSON files
jsonlint: {
all: {
src: [
'**/*.json',
'!node_modules/**/*.json'
]
},
changed: {
src: []
}
},
// CSS vendor autoprefixing
postcss: {
options: {
processors: [
autoprefixer( {
browsers: [
'Android >= 2.1',
'Chrome >= 21',
'Edge >= 12',
'Explorer >= 7',
'Firefox >= 17',
'Opera >= 12.1',
'Safari >= 6.0'
],
cascade: false
} )
]
},
all: {
src: [
'<%= csslint.all.src %>'
]
},
changed: {
src: []
}
},
// CSS syntax validation
csslint: {
options: {
'important': false,
'ids': false,
'regex-selectors': false,
'unqualified-attributes': false,
'outline-none': false,
'box-model': false,
'display-property-grouping': false,
'adjoining-classes': false,
'empty-rules': false,
'overqualified-elements': false,
'known-properties': false,
'compatible-vendor-prefixes': false,
'order-alphabetical': false,
'universal-selector': false,
'bulletproof-font-face': false,
'box-sizing': false
},
all: {
src: [
'**/*.css',
'!**/*.min.css',
'!node_modules/**/*.css'
]
},
changed: {
src: []
}
},
// CSS minification
cssmin: {
options: {
removeEmpty: true
},
all: {
expand: true,
ext: '.min.css',
extDot: 'last',
src: [
'<%= csslint.all.src %>'
]
},
changed: {
expand: true,
ext: '.min.css',
extDot: 'last',
src: []
}
},
// Watch files for changes
watch: {
options: {
event: [ 'changed' ],
spawn: false
},
js: {
files: '<%= jshint.all.src %>',
tasks: [ 'jshint:changed', 'uglify:changed', 'jsvalidate:changed' ]
},
json: {
files: '<%= jsonlint.all.src %>',
tasks: [ 'jsonlint:changed' ]
},
css: {
files: '<%= csslint.all.src %>',
tasks: [ 'postcss:changed', 'csslint:changed', 'cssmin:changed' ]
}
}
} );
// Register "build" task
grunt.registerTask( 'build:js', [ 'jshint:all', 'jsonlint:all', 'uglify:all', 'jsvalidate:all' ] );
grunt.registerTask( 'build:css', [ 'postcss:all', 'csslint:all', 'cssmin:all' ] );
grunt.registerTask( 'build', [ 'build:js', 'build:css' ] );
// Make "watch" the default task
grunt.registerTask( 'default', [ 'watch' ] );
// Add a listener to the "watch" task
//
// On "watch", automatically updates the "changed" target for the task configurations,
// so that only the changed files are touched by the task.
grunt.event.on( 'watch', function( action, filepath /*, target */ ) {
grunt.config( [ 'jsvalidate', 'changed', 'src' ], filepath );
grunt.config( [ 'jshint', 'changed', 'src' ], filepath );
grunt.config( [ 'uglify', 'changed', 'src' ], filepath );
grunt.config( [ 'jsonlint', 'changed', 'src' ], filepath );
grunt.config( [ 'postcss', 'changed', 'src' ], filepath );
grunt.config( [ 'csslint', 'changed', 'src' ], filepath );
grunt.config( [ 'cssmin', 'changed', 'src' ], filepath );
} );
};