Skip to content

Commit de3c89b

Browse files
committed
feat(build): broccoli compass plugin
1 parent 33833b8 commit de3c89b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

lib/broccoli/broccoli-compass.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* jshint node: true, esversion: 6 */
2+
'use strict';
3+
4+
try {
5+
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
6+
require('module').Module._initPaths();
7+
require.resolve('node-sass');
8+
require.resolve('compass-importer');
9+
10+
const Plugin = require('broccoli-caching-writer');
11+
const fs = require('fs');
12+
const fse = require('fs-extra');
13+
const path = require('path');
14+
const sass = require('node-sass');
15+
const compass = require('compass-importer');
16+
17+
class CompassPlugin extends Plugin {
18+
constructor(inputNodes, options) {
19+
super(inputNodes, {});
20+
21+
options = options || {};
22+
Plugin.call(this, inputNodes, {
23+
cacheInclude: [/(.*?).scss$/, /(.*?).sass$/]
24+
});
25+
this.options = options;
26+
this.fileRegistry = [];
27+
}
28+
29+
build() {
30+
let entries = this.listEntries();
31+
let rootFileNames = entries.map(e => {
32+
return path.resolve(e.basePath, e.relativePath);
33+
});
34+
35+
rootFileNames.forEach(fileName => {
36+
this.compile(fileName, this.inputPaths[0], this.outputPath);
37+
});
38+
}
39+
40+
compile(fileName, inputPath, outputPath) {
41+
let sassOptions = {
42+
file: path.join(fileName),
43+
includePaths: this.inputPaths,
44+
data: '@import "compass"; .transition { @include transition(all); }',
45+
importer: compass
46+
};
47+
48+
let result = sass.renderSync(sassOptions);
49+
let filePath = fileName.replace(inputPath, outputPath)
50+
.replace(/\.scss$/, '.css')
51+
.replace(/\.sass$/, '.css');
52+
53+
fse.outputFileSync(filePath, result.css, 'utf8');
54+
}
55+
}
56+
57+
module.exports = CompassPlugin;
58+
}
59+
catch (e) {
60+
module.exports = null;
61+
}

0 commit comments

Comments
 (0)