Skip to content
This repository was archived by the owner on Dec 11, 2021. It is now read-only.

Commit 01f27af

Browse files
committed
Build: Cleanup gruntfile
1 parent 6148e53 commit 01f27af

File tree

9 files changed

+234
-220
lines changed

9 files changed

+234
-220
lines changed

Gruntfile.js

+101-218
Original file line numberDiff line numberDiff line change
@@ -1,242 +1,125 @@
11
module.exports = function( grunt ) {
2+
require( "load-grunt-tasks" )( grunt );
23

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+
]
9018
},
91-
cleanup: [ "style", "fill", "id" ]
92-
},
93-
files: {
94-
"icons/icons.svg": [ "icons/svg-min/*.svg" ]
19+
src: "*.css"
9520
}
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" ],
13427
options: {
135-
spawn: false
28+
jshintrc: ".jshintrc"
13629
}
13730
},
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+
} ]
14344
}
144-
}
145-
},
146-
perfjankie: {
147-
options: {
148-
suite: "perfSlides - Performance Analysis"
14945
},
150-
"comparison": {
46+
// Minifies SVGs
47+
svgmin: {
15148
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+
}
16955
]
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+
} ]
17065
}
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+
},
18567

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" ]
19885
}
199-
]
200-
},
201-
perf: {},
202-
dev: {
203-
options: {
204-
keepalive: true
20586
}
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+
}
218102
}
219103
}
220-
}
221-
});
222-
grunt.loadNpmTasks( "perfjankie" );
223-
grunt.registerTask( "update-authors", function() {
224-
var getAuthors = require( "grunt-git-authors" ),
225-
done = this.async();
104+
};
226105

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;
232110

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 );
237114
});
238-
});
239115

116+
return object;
117+
}
118+
119+
grunt.util._.extend( config, loadConfig( "./tasks/options/" ) );
120+
121+
grunt.initConfig( config );
122+
grunt.loadNpmTasks( "perfjankie" );
240123
grunt.registerTask( "default", [ "jshint", "jscs" ] );
241124
grunt.registerTask( "build", [ "sass", "autoprefixer" ] );
242125
grunt.registerTask( "perf", [ "start-selenium-server", "connect:perf", "perfjankie" ] );

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,20 @@
4646
"chromedriver": "2.13.0",
4747
"commitplease": "2.0.0",
4848
"ejs-template": "0.1.0",
49+
"glob": "4.4.2",
4950
"grunt": "0.4.5",
5051
"grunt-autoprefixer": "^2.1.0",
5152
"grunt-contrib-jshint": "0.10.0",
5253
"grunt-contrib-connect": "0.9.0",
5354
"grunt-contrib-watch": "^0.6.1",
5455
"grunt-git-authors": "2.0.0",
56+
"grunt-html": "1.6.0",
5557
"grunt-jscs": "0.6.2",
5658
"grunt-sass": "^0.17.0",
5759
"grunt-selenium-server": "0.1.2",
5860
"grunt-svgmin": "^2.0.0",
5961
"grunt-svgstore": "^0.5.0",
60-
"grunt-html": "1.6.0",
62+
"load-grunt-tasks": "3.1.0",
6163
"perfjankie": "1.1.1"
6264
},
6365
"keywords": []

performance/frameworks/jquery-ui-1-12.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
2-
css: [ "https://cdn.rawgit.com/arschmitz/5a0c0b61d0240c096db5/raw/0d1d52e3c0e732e0f22cecda2f56def937152db2/jquery-ui-1-12.min.css" ],
2+
css: [ "https://cdn.rawgit.com/arschmitz/5a0c0b61d0240c096db5/raw/" +
3+
"0d1d52e3c0e732e0f22cecda2f56def937152db2/jquery-ui-1-12.min.css" ],
34
button: {
45
generator: function( options ) {
56
var icon,

tasks/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)