You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bs-raw-files-generator.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*!
  2. * Bootstrap Grunt task for generating raw-files.min.js for the Customizer
  3. * http://getbootstrap.com
  4. * Copyright 2014-2015 Twitter, Inc.
  5. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  6. */
  7. 'use strict';
  8. var fs = require('fs');
  9. var btoa = require('btoa');
  10. var glob = require('glob');
  11. function getFiles(type) {
  12. var files = {};
  13. var recursive = type === 'less';
  14. var globExpr = recursive ? '/**/*' : '/*';
  15. glob.sync(type + globExpr)
  16. .filter(function (path) {
  17. return type === 'fonts' ? true : new RegExp('\\.' + type + '$').test(path);
  18. })
  19. .forEach(function (fullPath) {
  20. var relativePath = fullPath.replace(/^[^/]+\//, '');
  21. files[relativePath] = type === 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8');
  22. });
  23. return 'var __' + type + ' = ' + JSON.stringify(files) + '\n';
  24. }
  25. module.exports = function generateRawFilesJs(grunt, banner) {
  26. if (!banner) {
  27. banner = '';
  28. }
  29. var dirs = ['js', 'less', 'fonts'];
  30. var files = banner + dirs.map(getFiles).reduce(function (combined, file) {
  31. return combined + file;
  32. }, '');
  33. var rawFilesJs = 'docs/assets/js/raw-files.min.js';
  34. try {
  35. fs.writeFileSync(rawFilesJs, files);
  36. } catch (err) {
  37. grunt.fail.warn(err);
  38. }
  39. grunt.log.writeln('File ' + rawFilesJs.cyan + ' created.');
  40. };