|
1 | 1 | module.exports = function( grunt ) {
|
| 2 | +require( "load-grunt-tasks" )( grunt ); |
2 | 3 |
|
3 |
| -grunt.loadNpmTasks( "grunt-contrib-jshint" ); |
4 |
| -grunt.loadNpmTasks( "grunt-contrib-connect" ); |
5 |
| -grunt.loadNpmTasks( "grunt-selenium-server" ); |
6 |
| -grunt.loadNpmTasks( "grunt-html" ); |
7 |
| -grunt.loadNpmTasks( "grunt-jscs" ); |
8 |
| -grunt.loadNpmTasks( "grunt-svgmin" ); |
9 |
| -grunt.loadNpmTasks( "grunt-svgstore" ); |
10 |
| -grunt.loadNpmTasks( "grunt-sass" ); |
11 |
| -grunt.loadNpmTasks( "grunt-autoprefixer" ); |
12 |
| -grunt.loadNpmTasks( "grunt-contrib-watch" ); |
13 |
| - |
14 |
| -var target, |
15 |
| - template = require( "ejs-template" ), |
16 |
| - urlParser = require( "url" ), |
17 |
| - componentGenerator = require( "./performance/component.js" ), |
18 |
| - seleniumChildProcesses = {}; |
19 |
| - |
20 |
| -// This saves the process so we can attempt to kill it later in the case of a failure |
21 |
| -grunt.event.on( "selenium.start", function( target, process ) { |
22 |
| - grunt.log.ok( "Saw process for target: " + target ); |
23 |
| - seleniumChildProcesses[ target ] = process; |
24 |
| -}); |
25 |
| - |
26 |
| -// This trys to gracefully handle failures and kill the selenium server but its not 100% |
27 |
| -// if this does is not successfull the task will not run again until this has been killed |
28 |
| -grunt.util.hooker.hook( grunt.fail, function() { |
29 |
| - |
30 |
| - // Clean up selenium if we left it running after a failure. |
31 |
| - grunt.log.writeln( "Attempting to clean up running selenium server." ); |
32 |
| - for ( target in seleniumChildProcesses ) { |
33 |
| - grunt.log.ok( "Killing selenium target: " + target ); |
34 |
| - try { |
35 |
| - seleniumChildProcesses[ target ].kill( "SIGTERM" ); |
36 |
| - } |
37 |
| - catch ( e ) { |
38 |
| - |
39 |
| - // This is only if the kill command fails |
40 |
| - grunt.log.warn( "Unable to stop selenium target: " + target ); |
41 |
| - } |
42 |
| - } |
43 |
| -}); |
44 |
| - |
45 |
| -grunt.initConfig({ |
46 |
| - jshint: { |
47 |
| - files: [ "*.js", "performance/*.js", "performance/frameworks/*.js" ], |
48 |
| - options: { |
49 |
| - jshintrc: ".jshintrc" |
50 |
| - } |
51 |
| - }, |
52 |
| - jscs: { |
53 |
| - all: [ "*.js", "performance/*.js", "performance/frameworks/*.js" ] |
54 |
| - }, |
55 |
| - |
56 |
| - // Minifies SVGs |
57 |
| - svgmin: { |
58 |
| - options: { |
59 |
| - plugins: [ |
60 |
| - { |
61 |
| - removeViewBox: false |
62 |
| - }, { |
63 |
| - removeUselessStrokeAndFill: false |
64 |
| - } |
65 |
| - ] |
66 |
| - }, |
67 |
| - dist: { |
68 |
| - files: [ { |
69 |
| - expand: true, |
70 |
| - cwd: "icons/svg-source", |
71 |
| - src: [ "*.svg" ], |
72 |
| - dest: "icons/svg-min/", |
73 |
| - ext: ".svg" |
74 |
| - } ] |
75 |
| - } |
76 |
| - }, |
77 |
| - |
78 |
| - // Combines SVGs into single file |
79 |
| - svgstore: { |
80 |
| - defaults: { |
81 |
| - options: { |
82 |
| - |
83 |
| - // This will prefix each ID |
84 |
| - prefix: "icon-", |
85 |
| - |
86 |
| - // Adds attributes to the resulting SVG |
87 |
| - svg: { |
88 |
| - viewBox: "0 0 24 24", |
89 |
| - xmlns: "http://www.w3.org/2000/svg" |
| 4 | +var config = { |
| 5 | + autoprefixer: { |
| 6 | + dist: { |
| 7 | + options: { |
| 8 | + map: true, |
| 9 | + browsers: [ |
| 10 | + "> 1%", |
| 11 | + "last 2 versions", |
| 12 | + "safari >= 5.1", |
| 13 | + "ios >= 6.1", |
| 14 | + "android 2.3", |
| 15 | + "android >= 4", |
| 16 | + "ie >= 8" |
| 17 | + ] |
90 | 18 | },
|
91 |
| - cleanup: [ "style", "fill", "id" ] |
92 |
| - }, |
93 |
| - files: { |
94 |
| - "icons/icons.svg": [ "icons/svg-min/*.svg" ] |
| 19 | + src: "*.css" |
95 | 20 | }
|
96 |
| - } |
97 |
| - }, |
98 |
| - sass: { |
99 |
| - dist: { |
100 |
| - options: { |
101 |
| - sourceMap: true, |
102 |
| - outputStyle: "compressed" |
103 |
| - }, |
104 |
| - files: [ { |
105 |
| - expand: true, |
106 |
| - cwd: "scss", |
107 |
| - src: [ "*.scss" ], |
108 |
| - dest: "", |
109 |
| - ext: ".css" |
110 |
| - } ] |
111 |
| - } |
112 |
| - }, |
113 |
| - autoprefixer: { |
114 |
| - dist: { |
115 |
| - options: { |
116 |
| - map: true, |
117 |
| - browsers: [ |
118 |
| - "> 1%", |
119 |
| - "last 2 versions", |
120 |
| - "safari >= 5.1", |
121 |
| - "ios >= 6.1", |
122 |
| - "android 2.3", |
123 |
| - "android >= 4", |
124 |
| - "ie >= 8" |
125 |
| - ] |
126 |
| - }, |
127 |
| - src: "*.css" |
128 |
| - } |
129 |
| - }, |
130 |
| - watch: { |
131 |
| - sass: { |
132 |
| - files: [ "scss/**/*.scss" ], |
133 |
| - tasks: [ "build" ], |
| 21 | + }, |
| 22 | + jscs: { |
| 23 | + all: [ "*.js", "performance/*.js", "performance/frameworks/*.js" ] |
| 24 | + }, |
| 25 | + jshint: { |
| 26 | + files: [ "*.js", "performance/*.js", "performance/frameworks/*.js" ], |
134 | 27 | options: {
|
135 |
| - spawn: false |
| 28 | + jshintrc: ".jshintrc" |
136 | 29 | }
|
137 | 30 | },
|
138 |
| - svg: { |
139 |
| - files: [ "svg-source/**/*.svg" ], |
140 |
| - tasks: [ "svgmin", "svgstore" ], |
141 |
| - options: { |
142 |
| - spawn: false |
| 31 | + sass: { |
| 32 | + dist: { |
| 33 | + options: { |
| 34 | + sourceMap: true, |
| 35 | + outputStyle: "compressed" |
| 36 | + }, |
| 37 | + files: [ { |
| 38 | + expand: true, |
| 39 | + cwd: "scss", |
| 40 | + src: [ "*.scss" ], |
| 41 | + dest: "", |
| 42 | + ext: ".css" |
| 43 | + } ] |
143 | 44 | }
|
144 |
| - } |
145 |
| - }, |
146 |
| - perfjankie: { |
147 |
| - options: { |
148 |
| - suite: "perfSlides - Performance Analysis" |
149 | 45 | },
|
150 |
| - "comparison": { |
| 46 | + // Minifies SVGs |
| 47 | + svgmin: { |
151 | 48 | options: {
|
152 |
| - repeat: 2, |
153 |
| - selenium: "http://localhost:4444/wd/hub", |
154 |
| - browsers: "chrome", |
155 |
| - couch: { |
156 |
| - server: "http://localhost:5984", |
157 |
| - database: "css-performance", |
158 |
| - updateSite: true |
159 |
| - }, |
160 |
| - urls: [ |
161 |
| - "http://localhost:4200/framework/foundation/component/button/count/1000/" + |
162 |
| - "foundation:button", |
163 |
| - "http://localhost:4200/framework/jquery-mobile/component/button/count/1000/" + |
164 |
| - "jquery-mobile:button", |
165 |
| - "http://localhost:4200/framework/jquery-ui/component/button/count/1000/" + |
166 |
| - "jquery-ui:button", |
167 |
| - "http://localhost:4200/framework/bootstrap/component/button/count/1000/" + |
168 |
| - "bootstrap:button" |
| 49 | + plugins: [ |
| 50 | + { |
| 51 | + removeViewBox: false |
| 52 | + }, { |
| 53 | + removeUselessStrokeAndFill: false |
| 54 | + } |
169 | 55 | ]
|
| 56 | + }, |
| 57 | + dist: { |
| 58 | + files: [ { |
| 59 | + expand: true, |
| 60 | + cwd: "icons/svg-source", |
| 61 | + src: [ "*.svg" ], |
| 62 | + dest: "icons/svg-min/", |
| 63 | + ext: ".svg" |
| 64 | + } ] |
170 | 65 | }
|
171 |
| - } |
172 |
| - }, |
173 |
| - connect: { |
174 |
| - options: { |
175 |
| - port: 4200, |
176 |
| - base: ".", |
177 |
| - middleware: [ |
178 |
| - template.middleware({ basedir: __dirname }), |
179 |
| - function( req, res ) { |
180 |
| - var data, i, |
181 |
| - url = urlParser.parse( req.url, true ), |
182 |
| - query = {}, |
183 |
| - parts = url.pathname.split( "/" ), |
184 |
| - file = req.url.replace( /^\//, "" ).split( "?" )[ 0 ]; |
| 66 | + }, |
185 | 67 |
|
186 |
| - for ( i = 1; i < parts.length; i += 2 ) { |
187 |
| - query[ parts[ i ] ] = parts[ i + 1 ]; |
188 |
| - } |
189 |
| - if ( file.split( "." ).length <= 1 ) { |
190 |
| - data = componentGenerator.generate( |
191 |
| - query.framework, |
192 |
| - query.component, |
193 |
| - query.count |
194 |
| - ); |
195 |
| - file = "performance/component.html"; |
196 |
| - } |
197 |
| - res.endTemplate( file, data ); |
| 68 | + // Combines SVGs into single file |
| 69 | + svgstore: { |
| 70 | + defaults: { |
| 71 | + options: { |
| 72 | + |
| 73 | + // This will prefix each ID |
| 74 | + prefix: "icon-", |
| 75 | + |
| 76 | + // Adds attributes to the resulting SVG |
| 77 | + svg: { |
| 78 | + viewBox: "0 0 24 24", |
| 79 | + xmlns: "http://www.w3.org/2000/svg" |
| 80 | + }, |
| 81 | + cleanup: [ "style", "fill", "id" ] |
| 82 | + }, |
| 83 | + files: { |
| 84 | + "icons/icons.svg": [ "icons/svg-min/*.svg" ] |
198 | 85 | }
|
199 |
| - ] |
200 |
| - }, |
201 |
| - perf: {}, |
202 |
| - dev: { |
203 |
| - options: { |
204 |
| - keepalive: true |
205 | 86 | }
|
206 |
| - } |
207 |
| - }, |
208 |
| - "start-selenium-server": { |
209 |
| - dev: { |
210 |
| - options: { |
211 |
| - downloadUrl: "https://selenium-release.storage.googleapis.com/2.40/" + |
212 |
| - "selenium-server-standalone-2.40.0.jar", |
213 |
| - downloadLocation: "external/selenium", |
214 |
| - serverOptions: { |
215 |
| - "Dwebdriver.chrome.driver=node_modules/chromedriver/bin/chromedriver": "" |
216 |
| - }, |
217 |
| - systemProperties: {} |
| 87 | + }, |
| 88 | + watch: { |
| 89 | + sass: { |
| 90 | + files: [ "scss/**/*.scss" ], |
| 91 | + tasks: [ "build" ], |
| 92 | + options: { |
| 93 | + spawn: false |
| 94 | + } |
| 95 | + }, |
| 96 | + svg: { |
| 97 | + files: [ "svg-source/**/*.svg" ], |
| 98 | + tasks: [ "svgmin", "svgstore" ], |
| 99 | + options: { |
| 100 | + spawn: false |
| 101 | + } |
218 | 102 | }
|
219 | 103 | }
|
220 |
| - } |
221 |
| -}); |
222 |
| -grunt.loadNpmTasks( "perfjankie" ); |
223 |
| -grunt.registerTask( "update-authors", function() { |
224 |
| - var getAuthors = require( "grunt-git-authors" ), |
225 |
| - done = this.async(); |
| 104 | + }; |
226 | 105 |
|
227 |
| - getAuthors( {}, function( error, authors ) { |
228 |
| - if ( error ) { |
229 |
| - grunt.log.error( error ); |
230 |
| - return done( error ); |
231 |
| - } |
| 106 | +function loadConfig(path) { |
| 107 | + var glob = require( "glob" ), |
| 108 | + object = {}, |
| 109 | + key; |
232 | 110 |
|
233 |
| - grunt.file.write( "AUTHORS.txt", |
234 |
| - "Authors ordered by first contribution\n\n" + |
235 |
| - authors.join( "\n" ) + "\n" ); |
236 |
| - done(); |
| 111 | + glob.sync( "*", { cwd: path } ).forEach( function( option ) { |
| 112 | + key = option.replace( /\.js$/, "" ); |
| 113 | + object[ key ] = require( path + option ); |
237 | 114 | });
|
238 |
| -}); |
239 | 115 |
|
| 116 | + return object; |
| 117 | +} |
| 118 | + |
| 119 | +grunt.util._.extend( config, loadConfig( "./tasks/options/" ) ); |
| 120 | + |
| 121 | +grunt.initConfig( config ); |
| 122 | +grunt.loadNpmTasks( "perfjankie" ); |
240 | 123 | grunt.registerTask( "default", [ "jshint", "jscs" ] );
|
241 | 124 | grunt.registerTask( "build", [ "sass", "autoprefixer" ] );
|
242 | 125 | grunt.registerTask( "perf", [ "start-selenium-server", "connect:perf", "perfjankie" ] );
|
|
0 commit comments