forked from drewcovi/ember-cli-stylus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (47 loc) · 1.63 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
58
var StylusCompiler = require('broccoli-stylus-single');
var checker = require('ember-cli-version-checker');
function StylusPlugin(optionsFn) {
this.name = 'ember-cli-stylus';
this.ext = 'styl';
this.optionsFn = optionsFn;
};
StylusPlugin.prototype.toTree = function(tree, inputPath, outputPath) {
var trees = [tree];
var options = this.optionsFn();
if (options.includePaths) trees = trees.concat(options.includePaths);
inputPath += '/' + options.inputFile;
outputPath += '/' + options.outputFile;
return new StylusCompiler(trees, inputPath, outputPath, options);
};
module.exports = {
name: 'Ember CLI Stylus',
stylusOptions: function() {
var options = (this.app && this.app.options && this.app.options.stylusOptions) || {};
if (options.sourceMap) {
options.sourceComments = 'map';
options.sourceMap = options.outputFile + '.map';
}
if ((options.sourceMap === undefined) && (this.app.env == 'development')) {
options.sourcemap = {
inline: true
};
options.cache = false;
}
options.inputFile = options.inputFile || 'app.styl';
options.outputFile = options.outputFile || this.project.name() + '.css';
return options;
},
shouldSetupRegistryInIncluded: function() {
return !checker.isAbove(this, '0.2.0');
},
setupPreprocessorRegistry: function(type, registry) {
registry.add('css', new StylusPlugin(this.stylusOptions.bind(this)));
},
included: function(app) {
this._super.included.apply(this, arguments);
this.app = app;
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
};
}
};