twbs--bootstrap/grunt/bs-raw-files-generator.js

34 lines
995 B
JavaScript
Raw Normal View History

/* jshint node: true */
/* global btoa: true */
2014-01-21 00:00:52 +00: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)
*/
var btoa = require('btoa')
var fs = require('fs')
function getFiles(type) {
var files = {}
fs.readdirSync(type)
.filter(function (path) {
return type == 'fonts' ? true : new RegExp('\\.' + type + '$').test(path)
})
.forEach(function (path) {
var fullPath = type + '/' + path
return files[path] = (type == 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'))
})
return 'var __' + type + ' = ' + JSON.stringify(files) + '\n'
}
2014-01-14 21:25:27 +00:00
module.exports = function generateRawFilesJs(banner) {
if (!banner) {
banner = ''
}
var files = banner + getFiles('js') + getFiles('less') + getFiles('fonts')
fs.writeFileSync('docs/assets/js/raw-files.min.js', files)
}