2014-01-21 01:00:52 +01:00
|
|
|
/*!
|
|
|
|
* Bootstrap Grunt task for generating raw-files.min.js for the Customizer
|
2018-09-18 21:27:46 +02:00
|
|
|
* https://getbootstrap.com/
|
2018-09-18 22:04:25 +02:00
|
|
|
* Copyright 2014-2018 Twitter, Inc.
|
2014-01-21 01:00:52 +01:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
|
|
*/
|
2014-03-07 17:59:43 +01:00
|
|
|
|
2014-02-08 21:59:17 +01:00
|
|
|
'use strict';
|
2015-04-26 12:53:45 +02:00
|
|
|
|
2014-02-08 21:59:17 +01:00
|
|
|
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 = {};
|
2015-04-26 12:53:45 +02:00
|
|
|
var recursive = type === 'less';
|
|
|
|
var globExpr = recursive ? '/**/*' : '/*';
|
2014-03-12 22:01:09 +01:00
|
|
|
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(/^[^/]+\//, '');
|
2015-04-26 12:53:45 +02:00
|
|
|
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-03-12 22:01:09 +01:00
|
|
|
var dirs = ['js', 'less', 'fonts'];
|
|
|
|
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);
|
2015-04-26 12:53:45 +02:00
|
|
|
} catch (err) {
|
2014-02-13 08:37:37 +01:00
|
|
|
grunt.fail.warn(err);
|
|
|
|
}
|
|
|
|
grunt.log.writeln('File ' + rawFilesJs.cyan + ' created.');
|
2014-02-08 21:59:17 +01:00
|
|
|
};
|