forked from adopted-ember-addons/ember-cli-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (78 loc) · 2.78 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var SassCompiler = require('broccoli-sass-source-maps');
var path = require('path');
var checker = require('ember-cli-version-checker');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var merge = require('merge');
var fs = require('fs');
function SASSPlugin(optionsFn) {
this.name = 'ember-cli-sass';
this.optionsFn = optionsFn;
this.ext = ['scss', 'sass'];
}
SASSPlugin.prototype.toTree = function(tree, inputPath, outputPath, inputOptions) {
var options = merge({}, this.optionsFn(), inputOptions);
var inputTrees;
if (options.onlyIncluded) {
inputTrees = [new Funnel('app/styles', {
srcDir: '/',
destDir: 'app/styles',
annotation: 'Funnel (styles)'
})];
}
else {
inputTrees = [tree];
}
if (options.includePaths) {
inputTrees = inputTrees.concat(options.includePaths);
}
var ext = options.extension || 'scss';
var paths = options.outputPaths;
var trees = Object.keys(paths).map(function(file) {
var input = path.join(inputPath, file + '.' + ext);
var output = paths[file];
return new SassCompiler(inputTrees, input, output, options);
});
return mergeTrees(trees);
};
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.app && this.app.options && this.app.options.sassOptions) || {};
var envConfig = this.project.config(env).sassOptions;
if (envConfig) {
console.warn("Deprecation warning: sassOptions should be moved to your ember-cli-build");
merge(options, envConfig);
}
if ((options.sourceMap === undefined) && (env == 'development')) {
options.sourceMap = true;
}
if (options.sourceMap || options.sourceMapEmbed) {
// we need to embed the sourcesContent in the source map until libsass has better support for broccoli-sass
options.sourceMapContents = true;
}
options.outputFile = options.outputFile || this.project.name() + '.css';
options.sourceMapRoot = path.join(this.project.root, 'app/styles');
return options;
},
setupPreprocessorRegistry: function(type, registry) {
registry.add('css', new SASSPlugin(this.sassOptions.bind(this)));
// prevent conflict with broccoli-sass if it's installed
if (registry.remove) registry.remove('css', 'broccoli-sass');
},
included: function included(app) {
this._super.included.apply(this, arguments);
// see: https://github.com/ember-cli/ember-cli/issues/3718
if (typeof app.import !== 'function' && app.app) {
app = app.app;
}
this.app = app;
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
}
};