mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
use glob instead of fs.readdirSync since /less now has subdirs
This commit is contained in:
parent
44d32ed776
commit
24c5a453b2
2 changed files with 12 additions and 5 deletions
|
@ -10,16 +10,19 @@
|
|||
'use strict';
|
||||
var fs = require('fs');
|
||||
var btoa = require('btoa');
|
||||
var glob = require('glob');
|
||||
|
||||
function getFiles(type) {
|
||||
var files = {};
|
||||
fs.readdirSync(type)
|
||||
var recursive = (type === 'less');
|
||||
var globExpr = (recursive ? '/**/*' : '/*');
|
||||
glob.sync(type + globExpr)
|
||||
.filter(function (path) {
|
||||
return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
|
||||
})
|
||||
.forEach(function (path) {
|
||||
var fullPath = type + '/' + path;
|
||||
files[path] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
||||
.forEach(function (fullPath) {
|
||||
var relativePath = fullPath.replace(/^[^/]+\//, '');
|
||||
files[relativePath] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
||||
});
|
||||
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
|
||||
}
|
||||
|
@ -28,7 +31,10 @@ module.exports = function generateRawFilesJs(grunt, banner) {
|
|||
if (!banner) {
|
||||
banner = '';
|
||||
}
|
||||
var files = banner + getFiles('js') + getFiles('less') + getFiles('fonts');
|
||||
var dirs = ['js', 'less', 'fonts'];
|
||||
var files = banner + dirs.map(getFiles).reduce(function (combined, file) {
|
||||
return combined + file;
|
||||
}, '');
|
||||
var rawFilesJs = 'docs/assets/js/raw-files.min.js';
|
||||
try {
|
||||
fs.writeFileSync(rawFilesJs, files);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"devDependencies": {
|
||||
"btoa": "~1.1.1",
|
||||
"canonical-json": "~0.0.4",
|
||||
"glob": "^3.2.9",
|
||||
"grunt": "~0.4.4",
|
||||
"grunt-autoprefixer": "~0.7.2",
|
||||
"grunt-banner": "~0.2.2",
|
||||
|
|
Loading…
Reference in a new issue