-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
50 lines (45 loc) · 1.71 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
var path = require('path');
var postcss = require('postcss');
var analyzer = require('./lib/analyzer');
var newParams = require('./lib/params');
var template = require('./lib/template');
var fileWriter = require('./lib/fileWriter');
var markdownParser = require('./lib/markdown');
var syntaxHighlighter = require('./lib/syntaxHighlight');
var colorPalette = require('./lib/colorPalette');
module.exports = postcss.plugin('postcss-style-guide', function (opts) {
opts = opts || {};
analyzer.setModules(syntaxHighlighter, markdownParser);
var func = function (root, result) {
var resultOpts = result.opts || {};
try {
var params = newParams(root, opts, resultOpts);
} catch (err) {
throw err;
}
var maps = analyzer.analyze(root, opts);
var palette = colorPalette.parse(root.toString());
var promise = syntaxHighlighter.execute({
src: params.src,
tmplStyle: params.style,
stylePath: require.resolve('highlight.js/styles/github.css')
}).then(function (styles) {
var html = template.rendering(maps, styles, {
project: params.project,
showCode: params.showCode,
tmpl: params.template,
colorPalette: palette
});
fileWriter.write(params.dest, html);
if (!opts.silent) {
console.log('Successfully created style guide at ' + path.relative(process.cwd(), params.dest) + '!');
}
return root;
}).catch(function (err) {
console.error('generate err:', err);
return root;
});
return promise;
};
return func;
});