forked from amsul/pickadate.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
312 lines (259 loc) · 11 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*!
* This Gruntfile is used to build the project files.
*/
/*jshint
asi: true
*/
/*global
module: true
*/
module.exports = function( grunt ) {
// Read the package manifest.
var packageJSON = grunt.file.readJSON( 'package.json' )
// Add the “curly” template delimiters.
grunt.template.addDelimiters( 'curly', '{%', '%}' )
// Load the NPM tasks.
grunt.loadNpmTasks( 'grunt-contrib-concat' )
grunt.loadNpmTasks( 'grunt-contrib-watch' )
grunt.loadNpmTasks( 'grunt-contrib-jshint' )
grunt.loadNpmTasks( 'grunt-contrib-qunit' )
grunt.loadNpmTasks( 'grunt-contrib-copy' )
grunt.loadNpmTasks( 'grunt-contrib-less' )
grunt.loadNpmTasks( 'grunt-contrib-clean' )
grunt.loadNpmTasks( 'grunt-contrib-cssmin' )
grunt.loadNpmTasks( 'grunt-contrib-uglify' )
// Setup the initial configurations.
grunt.initConfig({
// Add the package data.
pkg: packageJSON,
// Set up the directories.
dirs: {
tests: 'tests',
src: {
raw: '_raw',
demos: '_raw/demo',
pickers: '_raw/lib',
themes: '_raw/lib/themes',
translations: '_raw/lib/translations'
},
dest: {
demos: 'demo',
pickers: 'lib',
themes: 'lib/themes',
translations: 'lib/translations'
},
min: {
pickers: 'lib/compressed',
themes: 'lib/compressed/themes',
translations: 'lib/compressed/translations'
}
},
// Clean the destination files and directories.
clean: {
demos: [ '<%= dirs.dest.demos %>', '*.htm' ],
pickers: [ '<%= dirs.dest.pickers %>/*.js' ],
themes: [ '<%= dirs.dest.themes %>' ],
translations: [ '<%= dirs.dest.translations %>' ],
pkg: [ '<%= dirs.dest.pickers %>', '<%= pkg.name %>.jquery.json', '*.md' ]
},
// Generate static HTML templates.
htmlify: {
demos: {
expand: true,
cwd: '<%= dirs.src.raw %>',
src: [ '/!(base|hero)*.htm' ],
dest: '',
base: '/base.htm'
}
},
// Copy over files to destination directions.
copy: {
demos: {
expand: true,
cwd: '<%= dirs.src.demos %>',
src: [ 'styles/.css', 'images/*.{png,ico}' ],
dest: '<%= dirs.dest.demos %>'
},
translations: {
expand: true,
cwd: '<%= dirs.src.translations %>',
src: [ '*' ],
dest: '<%= dirs.dest.translations %>'
},
pkg: {
options: {
processContent: function( content ) {
return grunt.template.process( content, { delimiters: 'curly' } )
}
},
files: [
{ '<%= pkg.name %>.jquery.json': 'package.json' },
{ 'bower.json': 'package.json' },
{ 'README.md': '<%= dirs.src.raw %>/README.md' },
{ 'LICENSE.md': '<%= dirs.src.raw %>/LICENSE.md' },
{ 'CHANGELOG.md': '<%= dirs.src.raw %>/CHANGELOG.md' },
{ 'CONTRIBUTING.md': '<%= dirs.src.raw %>/CONTRIBUTING.md' }
]
}
},
// Compile LESS into CSS.
less: {
options: {
style: 'expanded'
},
demos: {
files: {
'<%= dirs.dest.demos %>/styles/main.css': '<%= dirs.src.demos %>/styles/base.less'
}
},
themes: {
files: {
'<%= dirs.dest.themes %>/default.css': [ '<%= dirs.src.themes %>/base.less', '<%= dirs.src.themes %>/default.less' ],
'<%= dirs.dest.themes %>/classic.css': [ '<%= dirs.src.themes %>/base.less', '<%= dirs.src.themes %>/classic.less' ],
'<%= dirs.dest.themes %>/default.date.css': [ '<%= dirs.src.themes %>/base.date.less', '<%= dirs.src.themes %>/default.date.less' ],
'<%= dirs.dest.themes %>/default.time.css': [ '<%= dirs.src.themes %>/base.time.less', '<%= dirs.src.themes %>/default.time.less' ],
'<%= dirs.dest.themes %>/classic.date.css': [ '<%= dirs.src.themes %>/base.date.less', '<%= dirs.src.themes %>/classic.date.less' ],
'<%= dirs.dest.themes %>/classic.time.css': [ '<%= dirs.src.themes %>/base.time.less', '<%= dirs.src.themes %>/classic.time.less' ],
'<%= dirs.dest.themes %>/rtl.css': [ '<%= dirs.src.themes %>/rtl.less' ]
}
}
},
// Concatenate the files and add the banner.
concat: {
options: {
process: function( content ) {
return grunt.template.process( content, { delimiters: 'curly' } )
}
},
demos: {
files: { '<%= dirs.dest.demos %>/scripts/main.js': '<%= dirs.src.demos %>/scripts/*.js' }
},
pickers: {
expand: true,
cwd: '<%= dirs.src.pickers %>',
src: [ '*.js' ],
dest: '<%= dirs.dest.pickers %>'
}
},
// Lint the files.
jshint: {
gruntfile: 'Gruntfile.js',
demos: [ '<%= dirs.src.demos %>/scripts/base.js' ],
pickers: [
'<%= dirs.tests %>/units/*.js',
'<%= dirs.dest.pickers %>/**/*.js',
// Ignore the legacy and minified files.
'!<%= dirs.dest.pickers %>/legacy.js',
'!<%= dirs.dest.pickers %>/compressed/**/*.js'
]
},
// Minify all the things!
uglify: {
options: {
preserveComments: 'some'
},
pickers: {
files: [
{
expand : true,
cwd : '<%= dirs.dest.pickers %>',
src : [ '**/*.js', '!compressed/**/*.js' ],
dest : '<%= dirs.dest.pickers %>/compressed'
}
]
}
},
cssmin: {
pickers: {
expand: true,
cwd: '<%= dirs.dest.pickers %>',
src: [ '**/*.css', '!compressed/**/*.css' ],
dest: '<%= dirs.dest.pickers %>/compressed'
}
},
// Unit test the files.
qunit: {
pickers: [ '<%= dirs.tests %>/units/all.htm' ]
},
// Watch the project files.
watch: {
gruntfile: {
files: [ 'Gruntfile.js' ],
tasks: [ 'jshint:gruntfile', 'default' ]
},
quick: {
files: [
'<%= dirs.src.raw %>/*.htm',
'<%= dirs.src.raw %>/*.md',
'<%= dirs.src.demos %>/styles/*.less', '<%= dirs.src.demos %>/scripts/*.js',
'<%= dirs.src.pickers %>/**/*.js', '<%= dirs.src.pickers %>/themes/*.css',
'<%= dirs.src.themes %>/*.less',
'<%= dirs.src.translations %>/*.js'
],
tasks: [ 'quick' ]
},
demos: {
files: [
'<%= dirs.src.raw %>/*.htm',
'<%= dirs.src.demos %>/styles/*.less', '<%= dirs.src.demos %>/scripts/*.js'
],
tasks: [ 'demo' ]
},
pickers: {
files: [
'<%= dirs.src.pickers %>/**/*.js', '<%= dirs.src.pickers %>/themes/*.css',
'<%= dirs.src.themes %>/*.less',
'<%= dirs.src.translations %>/*.js'
],
tasks: [ 'picker' ]
}
},
// Any extra data needed in rendering static files.
meta: {
// The sanitized github repo url.
gitrepo_url: packageJSON.repository.url.replace( /.git$/, '' ),
// Get the min & gzip size of a text file.
fileSize: function( content ) {
return {
min: content.length || 0,
gzip: content ? require( 'zlib-browserify' ).gzipSync( content ).length : 0
}
}
}
}) //grunt.initConfig
// Register the tasks.
// * `htmlify` and `copy:pkg` should come after `uglify` because some package files measure `.min` file sizes.
grunt.registerTask( 'default', [ 'clean', 'concat', 'copy:demos', 'copy:translations', 'less', 'jshint', 'qunit', 'uglify', 'cssmin', 'htmlify', 'copy:pkg' ] )
grunt.registerTask( 'quick', [ 'concat', 'copy:demos', 'copy:translations', 'less', 'uglify', 'cssmin', 'htmlify', 'copy:pkg' ] )
grunt.registerTask( 'picker', [ 'clean:pickers', 'concat:pickers', 'copy:translations', 'less:themes', 'jshint:pickers', 'qunit:pickers', 'uglify:pickers', 'cssmin:pickers' ] )
grunt.registerTask( 'demo', [ 'clean:demos', 'concat:demos', 'copy:demos', 'less:demos', 'jshint:demos', 'htmlify:demos' ] )
grunt.registerTask( 'travis', [ 'jshint:pickers', 'qunit:pickers' ] )
// Create and register the task to build out the static HTML files.
grunt.registerMultiTask( 'htmlify', 'Recursively build static HTML files', function() {
var task = this,
options = task.options(),
// Process the base file using the source file content.
processFile = function( fileSource ) {
var processedContent = '',
fileNameMatch = fileSource.match( /([\w-]+)(\.htm)$/ )
// Recursively process the base template using the file source content.
grunt.verbose.writeln( 'Processing ' + fileSource )
processedContent = grunt.template.process( grunt.file.read( task.data.cwd + task.data.base ), {
delimiters: 'curly',
data: {
pkg: packageJSON,
page: fileSource.match( /[\w-]+(?=\.htm$)/ )[ 0 ],
content: grunt.file.read( fileSource ),
meta: grunt.config.data.meta,
dirs: grunt.config.data.dirs
}
})
// Write the destination file by cleaning the file name.
grunt.log.writeln( 'Writing ' + fileSource.cyan )
grunt.file.write( task.data.dest + fileSource.match( /[\w-]+\.htm$/ )[ 0 ], processedContent )
}
// Map through the task directory and process the HTML files.
grunt.log.writeln( 'Expanding ' + task.data.cwd.cyan )
grunt.file.expand( task.data.cwd + task.data.src ).map( processFile )
})
} //module.exports