-
Notifications
You must be signed in to change notification settings - Fork 3
/
customizeBootstrap.js
45 lines (35 loc) · 1.3 KB
/
customizeBootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var path = require('path');
var _ = require('lodash');
module.exports = {
create: function(config) {
// TODO: validate config
// config = {
// srcPath: '', // The path of the source manifest
// srcContent: '', // Content of the source manifest
// overrideFiles: [], // Array of override includes
// overridePath: '' // Path of override files
// }
var existingManifest = this.parseExistingManifest(config.srcContent);
return this.processNewManifest(existingManifest, config);
},
parseExistingManifest: function(content) {
var pattern = /@import "([\w\.-]+)";/g;
var manifest = [];
var match;
// Match and store import statements
while ((match = pattern.exec(content)) !== null) {
manifest.push(match[1]);
}
// return manifest;
return manifest;
},
processNewManifest: function(content, config) {
var overridePrefix = path.relative(config.srcPath, config.overridePath);
// Iterate through manifest files
return content.map(function(filename) {
// Check if overrides matches manifest file
var prefix = _.includes(config.overrideFiles, filename) ? overridePrefix : './';
return '@import "' + path.join(prefix, filename) + '";';
}).join('\n');
}
};