forked from amsul/pickadate.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
275 lines (226 loc) · 9.01 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
/*!
* This Gruntfile is used to build the project files.
*/
/*jshint
node: 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-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-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',
lib: {
src: 'lib',
min: 'lib/compressed'
},
themes: {
src: 'lib/themes-source',
dest: 'lib/themes',
min: 'lib/compressed/themes'
},
translations: {
src: 'lib/translations',
min: 'lib/compressed/translations'
},
docs: {
src: '_docs',
dest: '.'
},
demo: {
images: 'demo/images',
scripts: 'demo/scripts',
styles: {
src: 'demo/styles/less',
dest: 'demo/styles/css'
}
},
},
// Generate static HTML templates.
htmlify: {
docs: {
expand: true,
cwd: '<%= dirs.docs.src %>',
src: [ '/!(base|hero)*.htm' ],
dest: '',
base: '/base.htm'
}
},
// Copy over files to destination directions.
copy: {
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.docs.src %>/README.md' },
{ 'LICENSE.md': '<%= dirs.docs.src %>/LICENSE.md' },
{ 'CHANGELOG.md': '<%= dirs.docs.src %>/CHANGELOG.md' },
{ 'CONTRIBUTING.md': '<%= dirs.docs.src %>/CONTRIBUTING.md' }
]
}
},
// Compile LESS into CSS.
less: {
options: {
style: 'expanded'
},
demo: {
files: {
'<%= dirs.demo.styles.dest %>/main.css': '<%= dirs.demo.styles.src %>/base.less'
}
},
themes: {
files: {
'<%= dirs.themes.dest %>/default.css': [ '<%= dirs.themes.src %>/base.less', '<%= dirs.themes.src %>/default.less' ],
'<%= dirs.themes.dest %>/classic.css': [ '<%= dirs.themes.src %>/base.less', '<%= dirs.themes.src %>/classic.less' ],
'<%= dirs.themes.dest %>/default.date.css': [ '<%= dirs.themes.src %>/base.date.less', '<%= dirs.themes.src %>/default.date.less' ],
'<%= dirs.themes.dest %>/default.time.css': [ '<%= dirs.themes.src %>/base.time.less', '<%= dirs.themes.src %>/default.time.less' ],
'<%= dirs.themes.dest %>/classic.date.css': [ '<%= dirs.themes.src %>/base.date.less', '<%= dirs.themes.src %>/classic.date.less' ],
'<%= dirs.themes.dest %>/classic.time.css': [ '<%= dirs.themes.src %>/base.time.less', '<%= dirs.themes.src %>/classic.time.less' ],
'<%= dirs.themes.dest %>/rtl.css': [ '<%= dirs.themes.src %>/rtl.less' ]
}
}
},
// Lint the files.
jshint: {
options: {
jshintrc: true
},
gruntfile: 'Gruntfile.js',
demo: [ '<%= dirs.demo.scripts %>/demo.js' ],
lib: [
'<%= dirs.tests %>/units/*.js',
'<%= dirs.lib.src %>/**/*.js',
// Ignore the legacy and minified files.
'!<%= dirs.lib.src %>/legacy.js',
'!<%= dirs.lib.src %>/compressed/**/*.js'
]
},
// Minify all the things!
uglify: {
options: {
preserveComments: 'some'
},
lib: {
files: [
{
expand : true,
cwd : '<%= dirs.lib.src %>',
src : [ '**/*.js', '!compressed/**/*.js' ],
dest : '<%= dirs.lib.min %>'
}
]
}
},
cssmin: {
lib: {
expand: true,
cwd: '<%= dirs.themes.dest %>',
src: [ '**/*.css', '!compressed/**/*.css' ],
dest: '<%= dirs.themes.min %>'
}
},
// Unit test the files.
qunit: {
lib: [ '<%= dirs.tests %>/units/all.htm' ]
},
// Watch the project files.
watch: {
quick: {
files: [
'<%= dirs.docs.src %>/**/*.htm',
'<%= dirs.docs.src %>/**/*.md',
'<%= dirs.demo.src %>/styles/**/*.less',
'<%= dirs.themes.src %>/**/*.less'
],
tasks: [ 'quick' ]
},
demo: {
files: [
'<%= dirs.demo.styles.src %>/**/*.less'
],
tasks: [ 'demo' ]
},
docs: {
files: [
'<%= dirs.docs.src %>/**/*.htm',
'<%= dirs.docs.src %>/**/*.md'
],
tasks: [ 'docs' ]
},
themes: {
files: [
'<%= dirs.themes.src %>/**/*.less'
],
tasks: [ 'themes' ]
}
},
// 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', [ 'less', 'jshint', 'qunit', 'uglify', 'cssmin', 'htmlify', 'copy:pkg' ] )
grunt.registerTask( 'quick', [ 'less', 'uglify', 'cssmin', 'htmlify', 'copy:pkg' ] )
grunt.registerTask( 'themes', [ 'less:themes' ] )
grunt.registerTask( 'demo', [ 'less:demo', 'jshint:demo' ] )
grunt.registerTask( 'docs', [ 'copy:pkg', 'htmlify:docs' ] )
grunt.registerTask( 'travis', [ 'jshint:lib', 'qunit:lib' ] )
// 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