forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
230 lines (212 loc) · 5.48 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
module.exports = function( grunt ) {
"use strict";
var
// files
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.ui.effect.js"
],
uiFiles = coreFiles.map(function( file ) {
return "ui/" + file;
}).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
return coreFiles.indexOf( file.substring( 3 ) ) === -1;
}) ),
allI18nFiles = expandFiles( "ui/i18n/*.js" ),
cssFiles = [
"core",
"accordion",
"autocomplete",
"button",
"datepicker",
"dialog",
"menu",
"progressbar",
"resizable",
"selectable",
"selectmenu",
"slider",
"spinner",
"tabs",
"tooltip",
"theme"
].map(function( component ) {
return "themes/base/jquery.ui." + component + ".css";
}),
// minified files
minify = {
options: {
preserveComments: false
},
main: {
options: {
banner: createBanner( uiFiles )
},
files: {
"dist/jquery-ui.min.js": "dist/jquery-ui.js"
}
},
i18n: {
options: {
banner: createBanner( allI18nFiles )
},
files: {
"dist/i18n/jquery-ui-i18n.min.js": "dist/i18n/jquery-ui-i18n.js"
}
}
},
compareFiles = {
all: [
"dist/jquery-ui.js",
"dist/jquery-ui.min.js"
]
};
function mapMinFile( file ) {
return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
}
function expandFiles( files ) {
return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" ).map(function( values ) {
return values[ 0 ];
});
}
uiFiles.concat( allI18nFiles ).forEach(function( file ) {
minify[ file ] = {
options: {
banner: createBanner()
},
files: {}
};
minify[ file ].files[ mapMinFile( file ) ] = file;
});
uiFiles.forEach(function( file ) {
// TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
compareFiles[ file ] = [ file, mapMinFile( file ) ];
});
// grunt plugins
grunt.loadNpmTasks( "grunt-contrib-jshint" );
grunt.loadNpmTasks( "grunt-contrib-uglify" );
grunt.loadNpmTasks( "grunt-contrib-concat" );
grunt.loadNpmTasks( "grunt-contrib-qunit" );
grunt.loadNpmTasks( "grunt-contrib-csslint" );
grunt.loadNpmTasks( "grunt-jscs-checker" );
grunt.loadNpmTasks( "grunt-html" );
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-git-authors" );
grunt.loadNpmTasks( "grunt-esformatter" );
// local testswarm and build tasks
grunt.loadTasks( "build/tasks" );
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 %> - " +
"<%= grunt.template.today('isoDate') %>\n" +
"<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
(files ? "* Includes: " + fileNames.join(", ") + "\n" : "") +
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
}
grunt.initConfig({
pkg: grunt.file.readJSON( "package.json" ),
files: {
dist: "<%= pkg.name %>-<%= pkg.version %>"
},
compare_size: compareFiles,
concat: {
ui: {
options: {
banner: createBanner( uiFiles ),
stripBanners: {
block: true
}
},
src: uiFiles,
dest: "dist/jquery-ui.js"
},
i18n: {
options: {
banner: createBanner( allI18nFiles )
},
src: allI18nFiles,
dest: "dist/i18n/jquery-ui-i18n.js"
},
css: {
options: {
banner: createBanner( cssFiles ),
stripBanners: {
block: true
}
},
src: cssFiles,
dest: "dist/jquery-ui.css"
}
},
jscs: {
// datepicker, sortable, resizable and draggable are getting rewritten, ignore until that's done
ui: [ "ui/jquery.ui.*.js", "!ui/jquery.ui.datepicker.js", "!ui/jquery.ui.sortable.js", "!ui/jquery.ui.resizable.js", "!ui/jquery.ui.draggable.js" ],
// TODO enable this once we have a tool that can help with fixing formatting of existing files
// tests: "tests/unit/**/*.js",
grunt: "Gruntfile.js"
},
uglify: minify,
htmllint: {
// ignore files that contain invalid html, used only for ajax content testing
all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core.*\.html)/.test( file );
})
},
qunit: {
files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
return !( /(all|index|test|dialog|tooltip)\.html$/ ).test( file );
})
},
jshint: {
options: {
jshintrc: true
},
all: [
"ui/*.js",
"Gruntfile.js",
"build/**/*.js",
"tests/unit/**/*.js"
]
},
csslint: {
base_theme: {
src: "themes/base/*.css",
options: {
csslintrc: ".csslintrc"
}
}
},
esformatter: {
options: {
preset: "jquery"
},
ui: "ui/*.js",
tests: "tests/unit/**/*.js",
build: {
options: {
skipHashbang: true
},
src: "build/**/*.js"
},
grunt: "Gruntfile.js"
}
});
grunt.registerTask( "default", [ "lint", "test" ]);
grunt.registerTask( "lint", [ "asciilint", "jshint", "jscs", "csslint", "htmllint" ]);
grunt.registerTask( "test", [ "qunit" ]);
grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ]);
grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ]);
};