forked from gpoitch/ember-cli-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·68 lines (53 loc) · 1.91 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
var LESSCompiler = require('broccoli-less-single');
var path = require('path');
var merge = require('lodash-node/modern/objects/merge');
var mergeTrees = require('broccoli-merge-trees');
var checker = require('ember-cli-version-checker');
function LESSPlugin(optionsFn) {
this.name = 'ember-cli-less';
this.ext = 'less';
this.optionsFn = optionsFn;
}
LESSPlugin.prototype.toTree = function(tree, inputPath, outputPath, inputOptions) {
var options = merge({}, this.optionsFn(), inputOptions);
var ext = this.ext;
var paths = options.outputPaths || {
app: options.registry.app.options.outputPaths.app.css
};
var trees = Object.keys(paths).map(function(file) {
var input = path.join(inputPath, file + '.' + ext);
var output = paths[file];
return new LESSCompiler([tree], input, output, options);
});
return mergeTrees(trees);
};
module.exports = {
name: 'Ember CLI LESS',
project: this.project,
shouldSetupRegistryInIncluded: function() {
return !checker.isAbove(this, '0.2.0');
},
lessOptions: function() {
var env = process.env.EMBER_ENV;
var options = this.project.config(env).lessOptions ||
(this.app && this.app.options.lessOptions) || {};
if ((options.sourceMap === undefined) && (env === 'development')) {
options.sourceMap = true;
}
return options;
},
setupPreprocessorRegistry: function(type, registry) {
registry.add('css', new LESSPlugin(this.lessOptions.bind(this)));
// prevent conflict with broccoli-less-single if it's installed
if (registry.remove) {
registry.remove('css', 'broccoli-less-single');
}
},
included: function(app) {
this.app = app; // used to provide back-compat for ember-cli < 0.2.0 in lessOptions()
this._super.included.apply(this, arguments);
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
}
}