@@ -81,14 +81,18 @@ module.exports = function(grunt) {
81
81
logger : logger ,
82
82
fontBaseName : options . font || 'icons' ,
83
83
destCss : options . destCss || params . destCss || params . dest ,
84
+ destScss : options . destScss || params . destScss || params . destCss || params . dest ,
85
+ destSass : options . destSass || params . destSass || params . destCss || params . dest ,
86
+ destLess : options . destLess || params . destLess || params . destCss || params . dest ,
87
+ destStyl : options . destStyl || params . destStyl || params . destCss || params . dest ,
84
88
dest : options . dest || params . dest ,
85
89
relativeFontPath : options . relativeFontPath ,
86
90
addHashes : options . hashes !== false ,
87
91
addLigatures : options . ligatures === true ,
88
92
template : options . template ,
89
93
syntax : options . syntax || 'bem' ,
90
94
templateOptions : options . templateOptions || { } ,
91
- stylesheet : options . stylesheet || path . extname ( options . template ) . replace ( / ^ \. / , '' ) || 'css' ,
95
+ stylesheets : options . stylesheets || [ options . stylesheet || path . extname ( options . template ) . replace ( / ^ \. / , '' ) || 'css' ] ,
92
96
htmlDemo : options . htmlDemo !== false ,
93
97
htmlDemoTemplate : options . htmlDemoTemplate ,
94
98
htmlDemoFilename : options . htmlDemoFilename ,
@@ -117,6 +121,13 @@ module.exports = function(grunt) {
117
121
118
122
o = _ . extend ( o , {
119
123
fontName : o . fontBaseName ,
124
+ destCssPaths : {
125
+ css : o . destCss ,
126
+ scss : o . destScss ,
127
+ sass : o . destSass ,
128
+ less : o . destLess ,
129
+ styl : o . destStyl
130
+ } ,
120
131
relativeFontPath : o . relativeFontPath || path . relative ( o . destCss , o . dest ) ,
121
132
destHtml : options . destHtml || o . destCss ,
122
133
fontfaceStyles : has ( o . styles , 'font' ) ,
@@ -160,7 +171,9 @@ module.exports = function(grunt) {
160
171
}
161
172
else {
162
173
generatedFiles . push ( getDemoFilePath ( ) ) ;
163
- generatedFiles . push ( getCssFilePath ( ) ) ;
174
+ o . stylesheets . forEach ( function ( stylesheet ) {
175
+ generatedFiles . push ( getCssFilePath ( stylesheet ) ) ;
176
+ } ) ;
164
177
165
178
regenerationNeeded = _ . some ( generatedFiles , function ( filename ) {
166
179
if ( ! filename ) return false ;
@@ -185,7 +198,7 @@ module.exports = function(grunt) {
185
198
cleanOutputDir ,
186
199
generateFont ,
187
200
generateWoff2Font ,
188
- generateStylesheet ,
201
+ generateStylesheets ,
189
202
generateDemoHtml ,
190
203
generateCustomOutputs ,
191
204
printDone
@@ -237,7 +250,9 @@ module.exports = function(grunt) {
237
250
* @param {Function } done
238
251
*/
239
252
function createOutputDirs ( done ) {
240
- mkdirp . sync ( o . destCss ) ;
253
+ o . stylesheets . forEach ( function ( stylesheet ) {
254
+ mkdirp . sync ( option ( o . destCssPaths , stylesheet ) ) ;
255
+ } ) ;
241
256
mkdirp . sync ( o . dest ) ;
242
257
done ( ) ;
243
258
}
@@ -248,7 +263,7 @@ module.exports = function(grunt) {
248
263
* @param {Function } done
249
264
*/
250
265
function cleanOutputDir ( done ) {
251
- var htmlDemoFileMask = path . join ( o . destCss , o . fontBaseName + '*.{' + o . stylesheet + ' ,html}') ;
266
+ var htmlDemoFileMask = path . join ( o . destCss , o . fontBaseName + '*.{css ,html}' ) ;
252
267
var files = glob . sync ( htmlDemoFileMask ) . concat ( wf . generatedFontFiles ( o ) ) ;
253
268
async . forEach ( files , function ( file , next ) {
254
269
fs . unlink ( file , next ) ;
@@ -310,7 +325,28 @@ module.exports = function(grunt) {
310
325
*
311
326
* @param {Function } done
312
327
*/
313
- function generateStylesheet ( done ) {
328
+ function generateStylesheets ( done ) {
329
+ // Convert codepoints to array of strings
330
+ var codepoints = [ ] ;
331
+ _ . each ( o . glyphs , function ( name ) {
332
+ codepoints . push ( o . codepoints [ name ] . toString ( 16 ) ) ;
333
+ } ) ;
334
+ o . codepoints = codepoints ;
335
+
336
+ // Prepage glyph names to use as CSS classes
337
+ o . glyphs = _ . map ( o . glyphs , classnameize ) ;
338
+
339
+ o . stylesheets . forEach ( generateStylesheet ) ;
340
+
341
+ done ( ) ;
342
+ }
343
+
344
+ /**
345
+ * Generate CSS
346
+ *
347
+ * @param {String } stylesheet type: css, scss, ...
348
+ */
349
+ function generateStylesheet ( stylesheet ) {
314
350
o . relativeFontPath = normalizePath ( o . relativeFontPath ) ;
315
351
316
352
// Generate font URLs to use in @font -face
@@ -324,24 +360,14 @@ module.exports = function(grunt) {
324
360
} ) ;
325
361
} ) ;
326
362
327
- // Convert them to strings that could be used in CSS
328
- var fontSrcSeparator = option ( wf . fontSrcSeparators , o . stylesheet ) ;
363
+ // Convert urls to strings that could be used in CSS
364
+ var fontSrcSeparator = option ( wf . fontSrcSeparators , stylesheet ) ;
329
365
fontSrcs . forEach ( function ( font , idx ) {
330
366
// o.fontSrc1, o.fontSrc2
331
367
o [ 'fontSrc' + ( idx + 1 ) ] = font . join ( fontSrcSeparator ) ;
332
368
} ) ;
333
369
o . fontRawSrcs = fontSrcs ;
334
370
335
- // Convert codepoints to array of strings
336
- var codepoints = [ ] ;
337
- _ . each ( o . glyphs , function ( name ) {
338
- codepoints . push ( o . codepoints [ name ] . toString ( 16 ) ) ;
339
- } ) ;
340
- o . codepoints = codepoints ;
341
-
342
- // Prepage glyph names to use as CSS classes
343
- o . glyphs = _ . map ( o . glyphs , classnameize ) ;
344
-
345
371
// Read JSON file corresponding to CSS template
346
372
var templateJson = readTemplate ( o . template , o . syntax , '.json' , true ) ;
347
373
if ( templateJson ) o = _ . extend ( o , JSON . parse ( templateJson . template ) ) ;
@@ -353,20 +379,19 @@ module.exports = function(grunt) {
353
379
var ext = path . extname ( o . template ) || '.css' ; // Use extension of o.template file if given, or default to .css
354
380
o . cssTemplate = readTemplate ( o . template , o . syntax , ext ) ;
355
381
var cssContext = _ . extend ( o , {
356
- iconsStyles : true
382
+ iconsStyles : true ,
383
+ stylesheet : stylesheet
357
384
} ) ;
358
385
359
386
var css = renderTemplate ( o . cssTemplate , cssContext ) ;
360
387
361
388
// Fix CSS preprocessors comments: single line comments will be removed after compilation
362
- if ( has ( [ 'sass' , 'scss' , 'less' , 'styl' ] , o . stylesheet ) ) {
389
+ if ( has ( [ 'sass' , 'scss' , 'less' , 'styl' ] , stylesheet ) ) {
363
390
css = css . replace ( / \/ \* * ( .* ?) * \* \/ / g, '// $1' ) ;
364
391
}
365
392
366
393
// Save file
367
- fs . writeFileSync ( getCssFilePath ( ) , css ) ;
368
-
369
- done ( ) ;
394
+ fs . writeFileSync ( getCssFilePath ( stylesheet ) , css ) ;
370
395
}
371
396
372
397
/**
@@ -747,11 +772,12 @@ module.exports = function(grunt) {
747
772
/**
748
773
* Return path of CSS file.
749
774
*
775
+ * @param {String } stylesheet (css, scss, ...)
750
776
* @return {String }
751
777
*/
752
- function getCssFilePath ( ) {
753
- var cssFilePrefix = option ( wf . cssFilePrefixes , o . stylesheet ) ;
754
- return path . join ( o . destCss , cssFilePrefix + o . fontBaseName + '.' + o . stylesheet ) ;
778
+ function getCssFilePath ( stylesheet ) {
779
+ var cssFilePrefix = option ( wf . cssFilePrefixes , stylesheet ) ;
780
+ return path . join ( option ( o . destCssPaths , stylesheet ) , cssFilePrefix + o . fontBaseName + '.' + stylesheet ) ;
755
781
}
756
782
757
783
/**
0 commit comments