Skip to content

Commit 86115a3

Browse files
committed
build: Angular2App is now a class, and accepts options for css compilers.
1 parent e201fc5 commit 86115a3

File tree

5 files changed

+357
-340
lines changed

5 files changed

+357
-340
lines changed

lib/broccoli/angular-broccoli-compass.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class CompassPlugin extends Plugin {
3333
}
3434

3535
compile(fileName, inputPath, outputPath) {
36-
let sassOptions = {
37-
file: path.normalize(fileName),
38-
includePaths: this.inputPaths,
36+
let sassOptions = Object.assign(this.options, {
3937
data: '@import "compass"; .transition { @include transition(all); }',
38+
file: fileName,
39+
includePaths: [inputPath].concat(this.options.inputPaths || []),
4040
importer: compass
41-
};
41+
});
4242

4343
let result = sass.renderSync(sassOptions);
4444
let filePath = fileName.replace(inputPath, outputPath).replace(/\.s[ac]ss$/, '.css');
@@ -47,13 +47,13 @@ class CompassPlugin extends Plugin {
4747
}
4848
}
4949

50-
exports.makeBroccoliTree = (sourceDir) => {
50+
exports.makeBroccoliTree = (sourceDir, options) => {
5151
if (sass && compass) {
5252
let compassSrcTree = new Funnel(sourceDir, {
5353
include: ['**/*.scss', '**/*.sass'],
5454
allowEmpty: true
5555
});
5656

57-
return new CompassPlugin([compassSrcTree]);
57+
return new CompassPlugin([compassSrcTree], options);
5858
}
5959
};

lib/broccoli/angular-broccoli-less.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ class LESSPlugin extends Plugin {
3434
compile(fileName, inputPath, outputPath) {
3535
let content = fs.readFileSync(fileName, 'utf8');
3636

37-
return less.render(content)
37+
return less.render(content, this.options)
3838
.then(output => {
3939
let filePath = fileName.replace(inputPath, outputPath).replace(/\.less$/, '.css');
4040
fse.outputFileSync(filePath, output.css, 'utf8');
4141
});
4242
}
4343
}
4444

45-
exports.makeBroccoliTree = (sourceDir) => {
45+
exports.makeBroccoliTree = (sourceDir, options) => {
4646
if (less) {
4747
let lessSrcTree = new Funnel(sourceDir, {
4848
include: ['**/*.less'],
4949
allowEmpty: true
5050
});
5151

52-
return new LESSPlugin([lessSrcTree]);
52+
return new LESSPlugin([lessSrcTree], options);
5353
}
5454
};

lib/broccoli/angular-broccoli-sass.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const requireOrNull = require('./require-or-null');
55
const Plugin = require('broccoli-caching-writer');
66
const fse = require('fs-extra');
7-
const path = require('path');
87
const Funnel = require('broccoli-funnel');
98

109
let sass = requireOrNull('node-sass');
@@ -24,26 +23,32 @@ class SASSPlugin extends Plugin {
2423
}
2524

2625
build() {
27-
this.listEntries().forEach(e => {
28-
let fileName = path.resolve(e.basePath, e.relativePath);
26+
this.listFiles().forEach(fileName => {
2927
this.compile(fileName, this.inputPaths[0], this.outputPath);
3028
});
3129
}
3230

3331
compile(fileName, inputPath, outputPath) {
34-
let sassOptions = {
35-
file: path.normalize(fileName),
36-
includePaths: this.inputPaths
37-
};
32+
const outSourceName = fileName.replace(inputPath, outputPath);
33+
const outFileName = outSourceName.replace(/\.s[ac]ss$/, '.css');
3834

39-
let result = sass.renderSync(sassOptions);
40-
let filePath = fileName.replace(inputPath, outputPath).replace(/\.s[ac]ss$/, '.css');
35+
// We overwrite file, outFile and include the file path for the includePath.
36+
// We also make sure the options don't include a data field.
37+
const sassOptions = Object.assign(this.options, {
38+
data: null,
39+
file: fileName,
40+
outFile: outFileName,
41+
includePaths: [inputPath].concat(this.options.includePaths || [])
42+
});
4143

42-
fse.outputFileSync(filePath, result.css, 'utf8');
44+
const result = sass.renderSync(sassOptions);
45+
fse.outputFileSync(outFileName, result.css, 'utf-8');
4346
}
4447
}
4548

46-
exports.makeBroccoliTree = (sourceDir) => {
49+
exports.makeBroccoliTree = (sourceDir, options) => {
50+
options = options || {};
51+
4752
// include sass support only if compass-importer is not installed
4853
let compass = requireOrNull('compass-importer');
4954
if (!compass) {
@@ -56,6 +61,6 @@ exports.makeBroccoliTree = (sourceDir) => {
5661
allowEmpty: true
5762
});
5863

59-
return new SASSPlugin([sassSrcTree]);
64+
return new SASSPlugin([sassSrcTree], options);
6065
}
6166
};

lib/broccoli/angular-broccoli-stylus.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,24 @@ class StylusPlugin extends Plugin {
3434
compile(fileName, inputPath, outputPath) {
3535
let content = fs.readFileSync(fileName, 'utf8');
3636

37-
return stylus.render(content, { filename: path.basename(fileName) }, function(err, css) {
37+
const options = Object.assign(this.options, {
38+
filename: path.basename(fileName)
39+
});
40+
41+
return stylus.render(content, options, function(err, css) {
3842
let filePath = fileName.replace(inputPath, outputPath).replace(/\.styl$/, '.css');
3943
fse.outputFileSync(filePath, css, 'utf8');
4044
});
4145
}
4246
}
4347

44-
exports.makeBroccoliTree = (sourceDir) => {
48+
exports.makeBroccoliTree = (sourceDir, options) => {
4549
if (stylus) {
4650
let stylusSrcTree = new Funnel(sourceDir, {
4751
include: ['**/*.styl'],
4852
allowEmpty: true
4953
});
5054

51-
return new StylusPlugin([stylusSrcTree]);
55+
return new StylusPlugin([stylusSrcTree], options);
5256
}
5357
};

0 commit comments

Comments
 (0)