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';
|
'use strict';
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var btoa = require('btoa');
|
var btoa = require('btoa');
|
||||||
|
var glob = require('glob');
|
||||||
|
|
||||||
function getFiles(type) {
|
function getFiles(type) {
|
||||||
var files = {};
|
var files = {};
|
||||||
fs.readdirSync(type)
|
var recursive = (type === 'less');
|
||||||
|
var globExpr = (recursive ? '/**/*' : '/*');
|
||||||
|
glob.sync(type + globExpr)
|
||||||
.filter(function (path) {
|
.filter(function (path) {
|
||||||
return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
|
return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
|
||||||
})
|
})
|
||||||
.forEach(function (path) {
|
.forEach(function (fullPath) {
|
||||||
var fullPath = type + '/' + path;
|
var relativePath = fullPath.replace(/^[^/]+\//, '');
|
||||||
files[path] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
files[relativePath] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
||||||
});
|
});
|
||||||
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
|
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
|
||||||
}
|
}
|
||||||
|
@ -28,7 +31,10 @@ module.exports = function generateRawFilesJs(grunt, banner) {
|
||||||
if (!banner) {
|
if (!banner) {
|
||||||
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';
|
var rawFilesJs = 'docs/assets/js/raw-files.min.js';
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(rawFilesJs, files);
|
fs.writeFileSync(rawFilesJs, files);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"btoa": "~1.1.1",
|
"btoa": "~1.1.1",
|
||||||
"canonical-json": "~0.0.4",
|
"canonical-json": "~0.0.4",
|
||||||
|
"glob": "^3.2.9",
|
||||||
"grunt": "~0.4.4",
|
"grunt": "~0.4.4",
|
||||||
"grunt-autoprefixer": "~0.7.2",
|
"grunt-autoprefixer": "~0.7.2",
|
||||||
"grunt-banner": "~0.2.2",
|
"grunt-banner": "~0.2.2",
|
||||||
|
|
Loading…
Reference in a new issue