forked from vitalets/x-editable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
330 lines (297 loc) · 10.6 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
function getFiles() {
//directories
var
lib = 'src/',
forms = lib+'editable-form/',
inputs = lib+'inputs/',
containers = lib+'containers/';
//config for different cores of lib
var config = {
bootstrap: {
form: [forms+'editable-form-bootstrap.js'],
container: [containers+'editable-popover.js'],
inputs: [
inputs+'date/bootstrap-datepicker/js/bootstrap-datepicker.js',
inputs+'date/date.js',
inputs+'date/datefield.js',
inputs+'datetime/datetime.js',
inputs+'datetime/datetimefield.js',
//don't build datetime lib, should be included manually
//inputs+'datetime/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js',
inputs+'typeahead.js'
],
css: [
inputs+'date/bootstrap-datepicker/css/datepicker.css'
//don't build datetime lib, should be included manually
//inputs+'datetime/bootstrap-datetimepicker/css/datetimepicker.css'
]
},
bootstrap3: {
filePrefix: 'bootstrap', //to have bootstrap-editable.js instead of bootstrap3-editable
form: [forms+'editable-form-bootstrap3.js'],
container: [containers+'editable-popover3.js'],
inputs: [
inputs+'date/bootstrap-datepicker/js/bootstrap-datepicker.js',
inputs+'date/date.js',
inputs+'date/datefield.js',
inputs+'datetime/datetime.js',
inputs+'datetime/datetimefield.js'
//don't build datetime lib, should be included manually
//inputs+'datetime/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js',
//no typeahead in bs3
//inputs+'typeahead.js'
],
css: [
inputs+'date/bootstrap-datepicker/css/datepicker.css'
//don't build datetime lib, should be included manually
//inputs+'datetime/bootstrap-datetimepicker/css/datetimepicker.css'
]
},
jqueryui: {
form: [forms+'editable-form-jqueryui.js'],
container: [containers+'editable-tooltip.js'],
inputs: [
inputs+'dateui/dateui.js',
inputs+'dateui/dateuifield.js'
],
css: []
},
jquery: {
form: [],
container: [containers+'editable-poshytip.js'],
inputs: [
inputs+'dateui/dateui.js',
inputs+'dateui/dateuifield.js'
],
css: []
}
};
//common js files
var js = [
forms+'editable-form.js',
forms+'editable-form-utils.js',
containers+'editable-container.js',
containers+'editable-inline.js',
lib+'element/editable-element.js',
inputs+'abstract.js',
inputs+'list.js',
inputs+'text.js',
inputs+'textarea.js',
inputs+'select.js',
inputs+'checklist.js',
inputs+'html5types.js',
inputs+'select2/select2.js',
inputs+'combodate/lib/combodate.js',
inputs+'combodate/combodate.js'
];
//common css files
var css = [
forms+'editable-form.css',
containers+'editable-container.css',
lib+'element/editable-element.css'
];
//create 'concat' and 'uglify' tasks
var task, folder, dest, concat_files = {}, min_files = {};
for(var k in config) {
folder = '<%= dist %>/'+k+'-editable/';
var prefix = config[k].filePrefix || k;
//js
task = k+'_js';
dest = folder+'js/'+prefix+'-editable'+ (k === 'jquery' ? '-poshytip' : '');
concat_files[task] = {
src: js.concat(config[k].form).concat(config[k].container).concat(config[k].inputs),
dest: dest+'.js'
};
min_files[task] = {
src: ['<%= concat.'+task+'.dest %>'],
dest: dest + '.min.js'
};
//css
concat_files[k+'_css'] = {
src: css.concat(config[k].css),
dest: folder+'css/'+prefix+'-editable.css'
};
}
return {concat_files: concat_files, min_files: min_files};
}
/*global module:false*/
module.exports = function(grunt) {
grunt.util.linefeed = '\n';
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
//grunt.loadNpmTasks('grunt-contrib-requirejs');
//version of jquery-ui datepicker to be copied into dist
//note: if change here => don't forget to change in gh-pages demo-plain.hbs !!!
var dp_ui_ver = '1.10.3';
//module for testing
var module = '';
// module = '&module=combodate';
// module = '&module=textarea';
//module = '&module=select';
//module = '&module=text';
//test on several jquery versions
var qunit_testover = [];
['bs3', 'bootstrap', 'jqueryui', 'plain'].forEach(function(f){
['popup', 'inline'].forEach(function(c){
['1.7.2', '1.8.3', '1.9.1', '1.10.2', '2.0.3'].forEach(function(jqver) {
qunit_testover.push('http://localhost:8000/test/index.html?f='+f+'&c='+c+'&jquery='+jqver+module);
});
});
});
//get js and css for different builds
var files = getFiles();
var banner = '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> \n' +
'* <%= pkg.description %>\n' +
'* <%= pkg.homepage %>\n' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n';
files.concat_files.options = {banner: banner};
files.min_files.options = {banner: banner};
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
dist: 'dist',
clean: ['<%= dist %>'],
concat: files.concat_files,
uglify: files.min_files,
qunit: {
bootstrap2: {
options: {
urls: [
'http://localhost:8000/test/index.html?f=bootstrap&c=popup'+module,
'http://localhost:8000/test/index.html?f=bootstrap&c=inline'+module
]
}
},
bootstrap3: {
options: {
puppeteer: {
headless: true
},
urls: [
'http://localhost:8000/test/bs3.html?popup',
'http://localhost:8000/test/bs3.html?inline',
// 'http://localhost:8000/test/index.html?f=bs3&c=popup'+module,
// 'http://localhost:8000/test/index.html?f=bs3&c=inline'+module
]
}
},
jqueryui: {
options: {
urls:[
'http://localhost:8000/test/index.html?f=jqueryui&c=popup'+module,
'http://localhost:8000/test/index.html?f=jqueryui&c=inline'+module
]
}
},
plain: {
options: {
urls:[
'http://localhost:8000/test/index.html?f=plain&c=popup'+module,
'http://localhost:8000/test/index.html?f=plain&c=inline'+module
]
}
},
//test all builds under several versions of jquery
testover: {
options: {
urls:qunit_testover
}
},
},
connect: {
server: {
options: {
port: 8000,
base: '.'
}
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
evil: false,
globals: {
jQuery: true
},
},
js: [ 'Gruntfile.js',
'src/editable-form/*.js',
'src/containers/*.js',
'src/element/*.js',
'src/inputs/*.js',
'src/inputs/date/*.js',
'src/inputs/dateui/*.js',
'src/inputs/datetime/*.js',
'src/inputs/combodate/*.js',
'src/inputs/select2/*.js',
'src/inputs-ext/address/*.js',
'src/inputs-ext/wysihtml5/*.js'
]
},
copy: {
dist: {
files: [
//image
{expand: true, flatten: true, dest: '<%= dist %>/bootstrap3-editable/img/', src: 'src/img/*'},
{expand: true, flatten: true, dest: '<%= dist %>/bootstrap-editable/img/', src: 'src/img/*'},
{expand: true, flatten: true, dest: '<%= dist %>/jqueryui-editable/img/', src: 'src/img/*'},
{expand: true, flatten: true, dest: '<%= dist %>/jquery-editable/img/', src: 'src/img/*'},
//licences
{expand: true, flatten: true, dest: '<%= dist %>/', src: ['LICENSE-MIT', 'README.md', 'CHANGELOG.txt']}
]
},
inputs_ext: {
expand: true,
cwd: 'src/inputs-ext',
src: '**',
dest:'<%= dist %>/inputs-ext/'
},
ui_datepicker: {
//copy jquery ui datepicker to jquery-editable build
expand: true,
cwd: 'src/inputs/dateui/jquery-ui-datepicker',
src: [
'js/jquery-ui-'+dp_ui_ver+'.*.js',
'css/redmond/jquery-ui-'+dp_ui_ver+'.*.css',
'css/redmond/images/**'
],
dest:'<%= dist %>/jquery-editable/jquery-ui-datepicker/'
}
}
});
//test task
grunt.registerTask('test', ['jshint', 'connect', 'qunit:bootstrap2']);
grunt.registerTask('test3', ['jshint', 'connect', 'qunit:bootstrap3']);
grunt.registerTask('testall', [
'jshint',
'connect',
'qunit:bootstrap2',
'qunit:bootstrap3',
'qunit:jqueryui',
'qunit:plain'
]);
grunt.registerTask('testover', ['jshint', 'connect', 'qunit:testover']);
// Default task.
grunt.registerTask('default', ['clean', 'jshint', 'concat', 'uglify', 'copy']);
// alive server
grunt.registerTask('server', 'connect:server:keepalive');
// build
grunt.registerTask('build', ['clean', 'jshint', 'concat', 'uglify', 'copy']);
//to run particular task use ":", e.g. copy:libs
};