Skip to content

Commit 24c5a45

Browse files
committed
use glob instead of fs.readdirSync since /less now has subdirs
1 parent 44d32ed commit 24c5a45

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

grunt/bs-raw-files-generator.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
'use strict';
1111
var fs = require('fs');
1212
var btoa = require('btoa');
13+
var glob = require('glob');
1314

1415
function getFiles(type) {
1516
var files = {};
16-
fs.readdirSync(type)
17+
var recursive = (type === 'less');
18+
var globExpr = (recursive ? '/**/*' : '/*');
19+
glob.sync(type + globExpr)
1720
.filter(function (path) {
1821
return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
1922
})
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'));
2326
});
2427
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
2528
}
@@ -28,7 +31,10 @@ module.exports = function generateRawFilesJs(grunt, banner) {
2831
if (!banner) {
2932
banner = '';
3033
}
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+
}, '');
3238
var rawFilesJs = 'docs/assets/js/raw-files.min.js';
3339
try {
3440
fs.writeFileSync(rawFilesJs, files);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"devDependencies": {
3333
"btoa": "~1.1.1",
3434
"canonical-json": "~0.0.4",
35+
"glob": "^3.2.9",
3536
"grunt": "~0.4.4",
3637
"grunt-autoprefixer": "~0.7.2",
3738
"grunt-banner": "~0.2.2",

0 commit comments

Comments
 (0)