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-01-08 07:15:48 +01:00
|
|
|
|
|
|
|
function getFiles(type) {
|
2014-02-08 21:59:17 +01:00
|
|
|
var files = {};
|
2014-01-08 07:15:48 +01:00
|
|
|
fs.readdirSync(type)
|
|
|
|
.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
|
|
|
})
|
|
|
|
.forEach(function (path) {
|
2014-02-08 21:59:17 +01:00
|
|
|
var fullPath = type + '/' + path;
|
|
|
|
files[path] = (type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'));
|
|
|
|
});
|
|
|
|
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-02-08 21:59:17 +01:00
|
|
|
var files = banner + getFiles('js') + getFiles('less') + getFiles('fonts');
|
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
|
|
|
};
|