-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
284 lines (267 loc) · 8.58 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
module.exports = function (grunt)
{
'use strict';
// Load all Grunt tasks.
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Set up paths.
paths: {
src: {
sass: 'scss/',
fonts: 'fonts/',
images: 'img/',
js: 'js/',
templates: 'templates/'
},
dest: {
css: 'themes/hive-framework-<%= pkg.version %>/assets/css/',
fonts: 'themes/hive-framework-<%= pkg.version %>/assets/fonts/',
images: 'themes/hive-framework-<%= pkg.version %>/assets/img/',
js: 'themes/hive-framework-<%= pkg.version %>/assets/js/',
templates: 'themes/hive-framework-<%= pkg.version %>/'
}
},
// Bundle up the JavaScript.
browserify: {
development: {
src: [
'<%= paths.src.js %>app.js'
],
dest: '<%= paths.dest.js %>app.js',
options: {
browserifyOptions: {
debug: false
},
transform: [[
'babelify', {
'presets': ['@babel/preset-env']
}
]]
}
}
},
// Clean theme directory to start afresh.
clean: [
'themes/*'
],
// Run some tasks in parallel to speed up the build process.
concurrent: {
dist: [
'browserify',
'copy',
'jshint',
'replace'
]
},
copy: {
// Copy fonts.
fonts: {
files: [
{
expand: true,
cwd: '<%= paths.src.fonts %>',
src: '**',
dest: '<%= paths.dest.fonts %>'
}
]
},
// Copy Textpattern templates.
html: {
files: [
{
expand: true,
cwd: '<%= paths.src.templates %>',
src: ['**', '!manifest.json'],
dest: '<%= paths.dest.templates %>'
}
]
},
// Copy fonts.
img: {
files: [
{
expand: true,
cwd: '<%= paths.src.images %>',
src: '**',
dest: '<%= paths.dest.images %>'
}
]
},
// Copy Leaflet (open-source interactive maps) files.
leaflet: {
files: [
{
'<%= paths.dest.js %>map.js': ['node_modules/leaflet/dist/leaflet.js'],
'<%= paths.dest.css %>map.css': ['node_modules/leaflet/dist/leaflet.css']
}
]
}
},
// Check code quality of Gruntfile.js and site-specific JavaScript using JSHint.
jshint: {
options: {
bitwise: true,
browser: true,
curly: true,
eqeqeq: true,
esversion: 6,
forin: true,
globals: {
$: true,
console: true,
jQuery: true,
Zepto: true,
define: true,
module: true,
require: true,
autosize: true,
Prism: true
},
latedef: true,
noarg: true,
nonew: true,
strict: true,
undef: true,
unused: true
},
files: [
'Gruntfile.js',
'<%= paths.src.js %>*.js'
]
},
// Add vendor prefixed styles and other post-processing transformations.
postcss: {
options: {
processors: [
require('autoprefixer'),
require('cssnano')
]
},
dist: {
src: '<%= paths.dest.css %>*.css'
}
},
// Purge unused CSS from production.
purgecss: {
my_target: {
options: {
content: [
'<%= paths.dest.templates %>**/*.txp',
'<%= paths.dest.js %>**/*.js'
],
safelist: {
standard: [
'caps',
'comments_error',
'cpreview',
'error_message',
'footnote',
'list--no-bullets',
'success',
'error',
'alert-block success',
'alert-block error'
],
greedy: [
/input$/,
/textarea$/,
/disabled$/
]
}
},
files: {
'<%= paths.dest.css %>screen.css': ['<%= paths.dest.css %>screen.css']
}
}
},
// Generate version number automatically in theme manifest.json file.
replace: {
theme: {
options: {
patterns: [
{
match: 'version',
replacement: '<%= pkg.version %>'
}
]
},
files: [
{'<%= paths.dest.templates %>manifest.json': '<%= paths.src.templates %>manifest.json'}
]
}
},
// Sass configuration.
sass: {
options: {
implementation: require('sass'),
outputStyle: 'expanded', // outputStyle = expanded, nested, compact or compressed.
sourceMap: false
},
dist: {
files: [
{'<%= paths.dest.css %>screen.css': '<%= paths.src.sass %>screen.scss'},
{'<%= paths.dest.css %>print.css': '<%= paths.src.sass %>print.scss'}
]
}
},
// Validate CSS files via stylelint.
stylelint: {
options: {
configFile: '.stylelintrc.yml'
},
src: ['<%= paths.src.sass %>**/*.{css,scss}']
},
// Minify `app.js`.
terser: {
options: {
ecma: 2015,
compress: {
booleans_as_integers: true,
drop_console: true
},
format: {
comments: false
}
},
dist: {
files: [
{
'<%= paths.dest.js %>app.js': ['<%= paths.dest.js %>app.js']
}
]
}
},
// Directories watched and tasks performed by invoking `grunt watch`.
watch: {
sass: {
files: '<%= paths.src.sass %>**/*.scss',
tasks: 'css'
},
js: {
files: '<%= paths.src.js %>**',
tasks: [
'jshint',
'browserify',
'terser'
]
},
html: {
files: [
'<%= paths.src.templates %>**'
],
tasks: [
'copy:html',
'replace'
]
}
}
});
// Register tasks.
grunt.registerTask('build', ['clean', 'concurrent', 'terser', 'css']);
grunt.registerTask('build-production', ['clean', 'concurrent', 'terser', 'css-production']);
grunt.registerTask('css', ['stylelint', 'sass', 'postcss']);
grunt.registerTask('css-production', ['stylelint', 'sass', 'purgecss', 'postcss']);
grunt.registerTask('default', ['watch']);
grunt.registerTask('html', ['copy:html', 'copy:img']);
};