10
10
'use strict' ;
11
11
var fs = require ( 'fs' ) ;
12
12
var btoa = require ( 'btoa' ) ;
13
+ var glob = require ( 'glob' ) ;
13
14
14
15
function getFiles ( type ) {
15
16
var files = { } ;
16
- fs . readdirSync ( type )
17
+ var recursive = ( type === 'less' ) ;
18
+ var globExpr = ( recursive ? '/**/*' : '/*' ) ;
19
+ glob . sync ( type + globExpr )
17
20
. filter ( function ( path ) {
18
21
return type === 'fonts' ? true : new RegExp ( '\\.' + type + '$' ) . test ( path ) ;
19
22
} )
20
- . forEach ( function ( path ) {
21
- var fullPath = type + '/' + path ;
22
- files [ path ] = ( type === 'fonts' ? btoa ( fs . readFileSync ( fullPath ) ) : fs . readFileSync ( fullPath , 'utf8' ) ) ;
23
+ . forEach ( function ( fullPath ) {
24
+ var relativePath = fullPath . replace ( / ^ [ ^ / ] + \/ / , '' ) ;
25
+ files [ relativePath ] = ( type === 'fonts' ? btoa ( fs . readFileSync ( fullPath ) ) : fs . readFileSync ( fullPath , 'utf8' ) ) ;
23
26
} ) ;
24
27
return 'var __' + type + ' = ' + JSON . stringify ( files ) + '\n' ;
25
28
}
@@ -28,7 +31,10 @@ module.exports = function generateRawFilesJs(grunt, banner) {
28
31
if ( ! banner ) {
29
32
banner = '' ;
30
33
}
31
- var files = banner + getFiles ( 'js' ) + getFiles ( 'less' ) + getFiles ( 'fonts' ) ;
34
+ var dirs = [ 'js' , 'less' , 'fonts' ] ;
35
+ var files = banner + dirs . map ( getFiles ) . reduce ( function ( combined , file ) {
36
+ return combined + file ;
37
+ } , '' ) ;
32
38
var rawFilesJs = 'docs/assets/js/raw-files.min.js' ;
33
39
try {
34
40
fs . writeFileSync ( rawFilesJs , files ) ;
0 commit comments