forked from drewcovi/ember-cli-stylus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (56 loc) · 1.95 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
59
60
61
62
63
64
65
66
67
68
69
70
var StylusCompiler = require('broccoli-stylus-single');
var path = require('path');
var VersionChecker = require('ember-cli-version-checker');
var mergeTrees = require('broccoli-merge-trees');
function StylusPlugin(optionsFn) {
this.name = 'ember-cli-stylus';
this.ext = 'styl';
this.optionsFn = optionsFn;
};
StylusPlugin.prototype.toTree = function(tree, inputPath, outputPath, inputOptions) {
var trees = [tree];
var options = Object.assign({}, this.optionsFn(), inputOptions);
if (options.includePaths) {
trees = trees.concat(options.includePaths);
}
var paths = options.outputPaths;
var trees = Object.keys(paths).map(function(file) {
var input = path.join(inputPath, file + '.styl');
var output = paths[file];
return new StylusCompiler(trees, input, output, options);
});
return mergeTrees(trees);
};
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() {
var checker = new VersionChecker(this);
return !checker.for('ember-cli').isAbove('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);
};
}
};