This repository was archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgruntfile.js
185 lines (176 loc) · 4.72 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
/*
This is the grunt file used to build the project.
Credit where credit is due:
A lot of the concepts around removing the AMD implementation and
building the final library were inspired by the excellent
Modernizer project (https://github.com/Modernizr/Modernizr).
*/
/*jshint node: true */
/*global module */
module.exports = function(grunt)
{
'use strict';
// Project configuration.
grunt.config.init(
{
pkg: grunt.file.readJSON('package.json'),
banner:
{
compact: '/*! <%= pkg.name %> <%= pkg.version %> (Custom Build) | <%= pkg.license %> */',
full:
'/*!\n' +
' * <%= pkg.name %> v<%= pkg.version %>\n' +
' * Copyright (c) <%= _.pluck(pkg.contributors, "name").join(", ") %>\n' +
' * <%= pkg.license %> License\n */' +
' \n' +
'/*\n' +
' * Selectioner is a general purpose jQuery-based enhancement for HTML select boxes.\n' +
' * It was written with extensibility in mind, and comes with various pre-built\n' +
' * flavours, such as multi-selects and combo-boxes.\n */'
},
jshint:
{
// See http://www.jshint.com/docs/options/ for option details.
options:
{
scripturl: true
},
all: ['gruntfile.js', 'source/*/*.js']
},
requirejs:
{
compile:
{
options:
{
dir: 'build',
appDir: 'source',
baseUrl: '.',
optimize: 'none',
optimizeCss: 'none',
removeCombined: true,
paths:
{
},
modules :
[{
'name' : 'selectioner',
'include':
[
'extensions/single-select',
'extensions/multi-select',
'extensions/date-select',
'extensions/combo-select',
'extensions/auto-complete'
],
'create': true
}],
fileExclusionRegExp: /^(.git|node_modules)$/,
wrap:
{
start: '<%= banner.full %>' + '\n;(function(window, document, $){ \n\'use strict\';',
end: '})(this, document, jQuery);'
},
onBuildWrite:
function (id, path, contents)
{
// Remove AMD for use without require.js
if ((/(define)\s*\([^\{]+\{/).test(contents))
{
contents = contents.replace(/(define)\s*\([^\{]+\{/, '');
contents = contents.replace(/\s*\}\s*\);\s*?$/,'');
}
else if ((/require\([^\{]*?\{/).test(contents))
{
contents = contents.replace(/require[^\{]+\{/, '');
contents = contents.replace(/\s*\}\s*\);\s*?$/,'');
}
return contents;
}
}
}
},
stripdefine:
{
build:
[
'build/selectioner.js'
]
},
less:
{
options:
{
paths: ['source/styles']
},
src:
{
expand: true,
cwd: 'source/styles',
src: ['*.less', '!mixins.less'],
ext: '.css',
dest: 'build/styles'
}
},
uglify:
{
options:
{
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
report: 'gzip',
sourceMap: 'build/<%= pkg.name.toLowerCase() %>.min.map'
},
build:
{
src: 'build/<%= pkg.name.toLowerCase() %>.js',
dest: 'build/<%= pkg.name.toLowerCase() %>.min.js'
}
},
cssmin:
{
options:
{
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */',
report: 'gzip'
},
minify:
{
expand: true,
cwd: 'build/styles',
src: ['*.css', '!*.min.css'],
ext: '.min.css',
dest: 'build/styles'
}
}
});
grunt.registerMultiTask(
'stripdefine',
'Strip the define call from built file',
function()
{
this.filesSrc.forEach(
function(filepath)
{
// Remove define(...) from the built file, and
// replace it with an actual AMD definition.
var amdJs =
'\n\n\tif (typeof define === \'function\' && define.amd)' +
'\n\t{' +
'\n\t\tdefine(\'selectioner\', [], function () { return Selectioner; });' +
'\n\t}\n';
grunt.file.write(
filepath,
grunt.file
.read(filepath)
.replace(/\s*define\(.*\);/g, amdJs));
});
});
// Load the required grunt plug-ins
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
// Default task(s).
grunt.registerTask('default', ['jshint', 'requirejs', 'stripdefine', 'less', 'uglify', 'cssmin']);
};