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