-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
57 lines (43 loc) · 1.66 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
var through = require('through2');
var path = require('path');
var gutil = require('gulp-util');
var Finder = require('fs-finder');
var PluginError = gutil.PluginError;
var customizeBootstrap = require('./customizeBootstrap');
const PLUGIN_NAME = 'gulp-customize-bootstrap';
module.exports = function(overrides) {
if (typeof overrides === 'undefined') {
throw new PluginError(PLUGIN_NAME, 'You must specify your stylesheet overrides. Check out the Github page usage instructions – https://github.com/wildbit/gulp-customize-bootstrap');
}
function bufferFile(file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
if (file.isBuffer()) {
var overrideFiles = Finder.in(path.dirname(overrides)).findFiles(path.basename(overrides));
// Clean up path
overrideFiles.forEach(function(item, index) {
// If scss remove partial underscore and extension
if (path.extname(file.path) === '.scss') {
overrideFiles[index] = path.basename(item).replace('.scss', '').substr(1);
} else {
overrideFiles[index] = path.basename(item);
}
if (index === (overrideFiles.length-1)) {
var newContent = customizeBootstrap.create({
srcPath: path.relative(file.cwd,file.base),
srcContent: file.contents.toString(),
overrideFiles: overrideFiles,
overridePath: path.dirname(overrides)
});
file.contents = new Buffer(newContent);
cb(null, file);
}
});
}
}
return through.obj(bufferFile);
};