forked from adopted-ember-addons/ember-cli-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (50 loc) · 1.9 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
var SassCompiler = require('broccoli-sass');
var path = require('path');
var checker = require('ember-cli-version-checker');
function SASSPlugin(options) {
this.name = 'ember-cli-sass';
options = options || {};
options.inputFile = options.inputFile || 'app.scss';
options.outputFile = options.outputFile || 'app.css';
if (options.sourceMap) {
options.sourceComments = 'map';
options.sourceMap = true;
}
this.options = options;
}
SASSPlugin.prototype.toTree = function(tree, inputPath, outputPath) {
var trees = [tree];
if (this.options.includePaths) trees = trees.concat(this.options.includePaths);
inputPath = path.join(inputPath, this.options.inputFile);
outputPath = path.join(outputPath, this.options.outputFile);
return new SassCompiler(trees, inputPath, outputPath, this.options);
};
module.exports = {
name: 'Ember CLI SASS',
shouldSetupRegistryInIncluded: function() {
return !checker.isAbove(this, '0.2.0');
},
sassOptions: function () {
var env = process.env.EMBER_ENV;
var options = (this.shouldSetupRegistryInIncluded() ?
this.project.config(env).sassOptions :
this.app.options.sassOptions) || {};
if ((options.sourceMap === undefined) && (env == 'development')) {
options.sourceMap = true;
}
options.outputFile = options.outputFile || this.project.name() + '.css';
return options;
},
setupPreprocessorRegistry: function(type, registry) {
registry.add('css', new SASSPlugin(this.sassOptions()));
// prevent conflict with broccoli-sass if it's installed
if (registry.remove) registry.remove('css', 'broccoli-sass');
},
included: function included(app) {
this.app = app; // used to provide back-compat for ember-cli < 0.2.0 in sassOptions()
this._super.included.apply(this, arguments);
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
}
};