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
|
/*global config:true, task:true*/
function stripDirectory(file) {
return file.replace(/.+\/(.+)$/, '$1');
}
function createBanner(files) {
// strip folders
var fileNames = files && files.map(stripDirectory);
return '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= template.today("isoDate") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Includes: ' + (files ? fileNames.join(', ') : '<%= stripDirectory(task.current.data.src[1]) %>') + '\n' +
'* Copyright (c) <%= template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */';
}
// allow access from banner template
global.stripDirectory = stripDirectory;
var coreFiles = 'jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.effects.core.js'.split(', ');
var uiFiles = coreFiles.map(function(file) {
return 'ui/' + file;
}).concat(file.expand('ui/*.js').filter(function(file) {
return coreFiles.indexOf(file.substring(3)) === -1;
}));
var minify = {
'dist/ui/minified/jquery-ui.min.js': ['<banner:meta.bannerAll>', 'dist/ui/jquery-ui.js'],
'dist/ui/minified/i18n/jquery-ui-i18n.min.js': ['<banner:meta.bannerI18n>', 'dist/ui/i18n/jquery-ui-i18n.js']
};
function minFile(file) {
minify['dist/' + file.replace(/\.js$/, '.min.js').replace(/ui\//, 'ui/minified/')] = ['<banner>', file];
}
uiFiles.forEach(minFile);
var allI18nFiles = file.expand('ui/i18n/*.js');
allI18nFiles.forEach(minFile);
// TODO move core to the front, theme to the end, exclude all and base
var cssFiles = file.expand('themes/base/*.css');
config.init({
pkg: '<json:package.json>',
meta: {
banner: createBanner(),
bannerAll: createBanner(uiFiles),
bannerI18n: createBanner(allI18nFiles),
bannerCSS: createBanner(cssFiles)
},
concat: {
'dist/ui/jquery-ui.js': uiFiles,
'dist/ui/i18n/jquery-ui-i18n.js': 'ui/i18n/*.js'
},
min: minify,
css_min: {
dist: {
src: ['<banner:meta.bannerCSS>'].concat(cssFiles),
dest: 'dist/themes/base/minified/jquery-ui.min.css'
}
},
zip: {
dist: {
src: [
'dist/**/*.js',
'README.md',
'grunt.js',
'package.json',
'ui/**/*',
'demos/**/*',
'themes/**/*',
'external/**/*',
'tests/**/*'
],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip'
}
},
qunit: {
files: file.expand('tests/unit/**/*.html').filter(function(file) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// except for all|index|test, try to include more as we go
return !(/(all|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated)\.html/).test(file);
})
},
lint: {
// TODO extend this to tests
files: ['ui/*']
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
}
});
task.registerBasicTask('zip', 'Create a zip file for release', function(data) {
var files = file.expand(data.src);
log.writeln("Creating zip file " + data.dest);
var fs = require('fs');
var AdmZip = require('adm-zip');
var zip = new AdmZip();
files.forEach(function(file) {
log.verbose.writeln('Zipping ' + file);
// rewrite file names from dist folder (created by build), drop the /dist part
zip.addFile(file.replace(/^dist/, ''), fs.readFileSync(file));
});
zip.writeZip(data.dest);
log.writeln("Wrote " + files.length + " files to " + data.dest);
});
task.registerBasicTask( 'css_min', 'Minify CSS files with Sqwish.', function( data ) {
var files = file.expand( data.src );
// Get banner, if specified. It would be nice if UglifyJS supported ignoring
// all comments matching a certain pattern, like /*!...*/, but it doesn't.
var banner = task.directive(files[0], function() { return null; });
if (banner === null) {
banner = '';
} else {
files.shift();
}
var max = task.helper( 'concat', files );
// Concat banner + minified source.
var min = banner + require('sqwish').minify( max, false );
file.write( data.dest, min );
if ( task.hadErrors() ) {
return false;
}
log.writeln( 'File "' + data.dest + '" created.' );
task.helper( 'min_max_info', min, max );
});
task.registerTask('default', 'lint qunit');
task.registerTask('release', 'concat min zip');
|