This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
css.js
116 lines (94 loc) · 3.46 KB
/
css.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
var requirejs = require( 'requirejs' ),
path = require( 'path' ),
fs = require( 'fs' ),
sqwish = require ( 'sqwish' ),
util = require( 'util' );
module.exports = function( grunt ) {
var config = grunt.config.get( 'global' ),
regularFile = path.join( config.dirs.output, config.names.root ),
structureFile = path.join( config.dirs.output, config.names.structure ),
themeFile = path.join( config.dirs.output, config.names.theme ),
helpers = config.helpers;
grunt.config.set( 'css', {
theme: process.env.THEME || 'default',
require: {
all: {
cssIn: 'css/themes/default/jquery.mobile.css',
optimizeCss: 'standard.keepComments.keepLines',
baseUrl: '.',
out: regularFile + '.compiled.css'
},
structure: {
cssIn: 'css/structure/jquery.mobile.structure.css',
out: structureFile + '.compiled.css'
}
}
});
grunt.registerTask( 'css_without_deps', 'compile and minify the css', function() {
var done = this.async(),
theme = grunt.config.get( 'css' ).theme,
require = grunt.config.get( 'css' ).require;
helpers.asyncConfig(function( config ) {
// pull the includes together using require js
requirejs.optimize( require.all );
// dump the versioned header into the normal css file
grunt.file.write( regularFile + '.css', config.ver.header );
// add the compiled css to the normal css file
helpers.appendFrom( regularFile + '.css', require.all.out );
helpers.minify({
output: regularFile + '.min.css',
input: regularFile + '.css',
header: config.ver.min,
minCallback: function( unminified ) {
return sqwish.minify( unminified, false );
}
});
// pull the includes together using require js
requirejs.optimize( require.structure );
// dump the versioned header into the structure css file
grunt.file.write( structureFile + '.css', config.ver.header );
// add the compiled css to the normal css file
helpers.appendFrom( structureFile + '.css', require.all.out );
// add the min header into the minified file
grunt.file.write( structureFile + '.min.css', config.ver.min );
// minify the structure css
helpers.minify({
output: structureFile + '.min.css',
input: structureFile + '.css',
header: config.ver.min,
minCallback: function( unminified ) {
return sqwish.minify( unminified, false );
}
});
// dump the versioned header into the theme css file
grunt.file.write( themeFile + '.css', config.ver.header );
// dump the theme css into the theme css file
helpers.appendFrom( themeFile + '.css', 'css/themes/default/jquery.mobile.theme.css' );
// minify the theme css
helpers.minify({
output: themeFile + '.min.css',
input: themeFile + '.css',
header: config.ver.min,
minCallback: function( unminified ) {
return sqwish.minify( unminified, false );
}
});
// remove the requirejs compile output
fs.unlink( require.all.out );
fs.unlink( require.structure.out );
// copy images directory
var imagesPath = path.join( config.dirs.output, 'images' ), fileCount = 0;
grunt.file.mkdir( imagesPath );
grunt.file.recurse( path.join('css', 'themes', theme, 'images'), function( full, root, sub, filename ) {
fileCount++;
var is = fs.createReadStream( full );
var os = fs.createWriteStream( path.join(imagesPath, filename) );
util.pump(is, os, function() {
fileCount--;
if( fileCount == 0 ) { done(); }
});
});
});
});
grunt.registerTask( 'css', 'init css_without_deps' );
};