Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 6a93b3e

Browse files
committed
feat(css): broccoli stylus plugin
1 parent 5f7336b commit 6a93b3e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* jshint node: true, esversion: 6 */
2+
'use strict';
3+
4+
try {
5+
let stylus;
6+
7+
if (process.platform === 'win32') {
8+
require.resolve(`${process.env.PWD}/node_modules/stylus`);
9+
stylus = require(`${process.env.PWD}/node_modules/stylus`);
10+
} else {
11+
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
12+
require('module').Module._initPaths();
13+
require.resolve('stylus');
14+
stylus = require('stylus');
15+
}
16+
17+
const Plugin = require('broccoli-caching-writer');
18+
const fs = require('fs');
19+
const fse = require('fs-extra');
20+
const path = require('path');
21+
const Funnel = require('broccoli-funnel');
22+
23+
class StylusPlugin extends Plugin {
24+
constructor(inputNodes, options) {
25+
super(inputNodes, {});
26+
27+
options = options || {};
28+
Plugin.call(this, inputNodes, {
29+
cacheInclude: [/(.*?).styl$/]
30+
});
31+
this.options = options;
32+
this.fileRegistry = [];
33+
}
34+
35+
build() {
36+
let entries = this.listEntries();
37+
let rootFileNames = entries.map(e => {
38+
return path.resolve(e.basePath, e.relativePath);
39+
});
40+
41+
return Promise.all(rootFileNames.map(fileName => {
42+
return this.compile(fileName, this.inputPaths[0], this.outputPath);
43+
}));
44+
}
45+
46+
compile(fileName, inputPath, outputPath) {
47+
let content = fs.readFileSync(fileName, 'utf8');
48+
49+
return stylus.render(content, { filename: path.basename(fileName) }, function(err, css) {
50+
let filePath = fileName.replace(inputPath, outputPath).replace(/\.styl$/, '.css');
51+
fse.outputFileSync(filePath, css, 'utf8');
52+
});
53+
}
54+
}
55+
56+
exports.makeBroccoliTree = (sourceDir) => {
57+
let stylusSrcTree = new Funnel(sourceDir, {
58+
include: ['**/*.styl'],
59+
allowEmpty: true
60+
});
61+
62+
return new StylusPlugin([stylusSrcTree]);
63+
};
64+
} catch (e) {
65+
exports.makeBroccoliTree = () => {
66+
return null;
67+
};
68+
}

0 commit comments

Comments
 (0)