This repository was archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathcssbuild.js
63 lines (55 loc) · 1.43 KB
/
cssbuild.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
module.exports = function( grunt ) {
var requirejs = require( "requirejs" ),
async = grunt.util.async;
requirejs.define( "node/print", [], function() {
return function print( msg ) {
if ( msg.substring( 0, 5 ) === "Error" ) {
grunt.log.errorlns( msg );
grunt.fail.warn( "RequireJS failed." );
} else {
grunt.log.oklns( msg );
}
};
} );
function expandFiles( files ) {
return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" );
}
grunt.registerMultiTask( "cssbuild", "Resolve CSS @imports and concat files", function() {
var done = this.async(),
_ = grunt.util._,
options = _.clone( this.options( {
banner: ""
} ) ),
banner = options.banner;
delete options.banner;
async.forEach( this.files,
function( file, callback ) {
var src = grunt.template.process( file.orig.src[ 0 ] ),
dest = file.dest;
grunt.log.debug( "Building '" + src + "' -> '" + dest + "'" );
async.series( [
function( next ) {
// Pull the includes together using require js
requirejs.optimize(
_.extend( {
cssIn: src,
out: dest
}, options
), function( response ) {
next();
} );
},
function( next ) {
var contents = grunt.file.read( dest );
if ( banner ) {
contents = banner + contents;
}
grunt.file.write( dest, contents );
grunt.log.writeln( "File '" + dest + "' written." );
next();
}
], callback );
}, done
);
} );
};