-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
32 lines (26 loc) · 934 Bytes
/
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
var HEADING = '@import "~react-toolbox/lib/_colors"; \n $theme-building: true;';
var DEFAULT_NAME = 'theme.scss';
var path = require('path');
var fs = require('fs');
module.exports = function (source) {
if (this.cacheable) this.cacheable();
var callback = this.async();
var options = this.options.toolbox || {};
var fromBuild = options.fromBuild || true;
var themeName = options.theme || DEFAULT_NAME;
var themePath = path.resolve(themeName);
var themeExists = fs.existsSync(themePath);
if (!themeExists) {
// if themePath is not readable, fall back to default theme name
themePath = path.resolve(DEFAULT_NAME);
}
var heading = HEADING;
if (!fromBuild) {
heading = heading.replace('/lib', '');
}
this.addDependency(themePath);
fs.readFile(themePath, "utf-8", function(err, theme) {
if(err) return callback(err);
callback(null, heading + '\n' + theme + '\n' + source);
});
};