2014-01-21 01:00:52 +01:00
|
|
|
/*!
|
|
|
|
* Bootstrap Grunt task for generating raw-files.min.js for the Customizer
|
|
|
|
* http://getbootstrap.com
|
|
|
|
* Copyright 2014 Twitter, Inc.
|
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
|
|
*/
|
2014-03-07 17:59:43 +01:00
|
|
|
|
|
|
|
/* global btoa: true */
|
|
|
|
|
2014-02-08 21:59:17 +01:00
|
|
|
'use strict';
|
|
|
|
var fs = require('fs');
|
2014-02-13 08:37:37 +01:00
|
|
|
var btoa = require('btoa');
|
2014-03-12 22:01:09 +01:00
|
|
|
var glob = require('glob');
|
2014-01-08 07:15:48 +01:00
|
|
|
|
|
|
|
function getFiles(type) {
|
2014-02-08 21:59:17 +01:00
|
|
|
var files = {};
|
2014-03-12 22:01:09 +01:00
|
|
|
var recursive = (type === 'less');
|
|
|
|
var globExpr = (recursive ? '/**/*' : '/*');
|
|
|
|
glob.sync(type + globExpr)
|
2014-01-08 07:15:48 +01:00
|
|
|
.filter(function (path) {
|
2014-02-08 21:59:17 +01:00
|
|
|
return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
|
2014-01-08 07:15:48 +01:00
|
|
|
})
|
2014-03-12 22:01:09 +01:00
|
|
|
.forEach(function (fullPath) {
|
|
|
|
var relativePath = fullPath.replace(/^[^/]+\//, '');
|
|
|
|
files[relativePath] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
2014-02-08 21:59:17 +01:00
|
|
|
});
|
|
|
|
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
|
2014-01-08 07:15:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 11:33:42 +01:00
|
|
|
module.exports = function generateRawFilesJs(grunt, banner) {
|
2014-01-14 22:25:27 +01:00
|
|
|
if (!banner) {
|
2014-02-08 21:59:17 +01:00
|
|
|
banner = '';
|
2014-01-14 22:25:27 +01:00
|
|
|
}
|
2014-12-01 06:01:50 +01:00
|
|
|
var dirs = ['js', 'less'];
|
2014-03-12 22:01:09 +01:00
|
|
|
var files = banner + dirs.map(getFiles).reduce(function (combined, file) {
|
|
|
|
return combined + file;
|
|
|
|
}, '');
|
2014-02-13 08:37:37 +01:00
|
|
|
var rawFilesJs = 'docs/assets/js/raw-files.min.js';
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(rawFilesJs, files);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
grunt.fail.warn(err);
|
|
|
|
}
|
|
|
|
grunt.log.writeln('File ' + rawFilesJs.cyan + ' created.');
|
2014-02-08 21:59:17 +01:00
|
|
|
};
|