-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
42 lines (39 loc) · 906 Bytes
/
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
const fs = require( 'fs' );
module.exports = (opts = {}) => {
let colorJson = opts.defaults || {};
let colors = opts.colors || [
'--blue',
'--indigo',
'--purple',
'--pink',
'--red',
'--orange',
'--yellow',
'--green',
'--teal',
'--cyan',
'--white',
'--gray',
'--gray-dark'
];
let output = opts.output || 'inc/editor-color-palette.json';
return {
postcssPlugin: 'postcss-understrap-palette-generator',
prepare (result) {
return {
Declaration (decl) {
if (colors.indexOf(decl.prop) > -1) {
colorJson[decl.prop] = decl.value;
}
},
OnceExit () {
if (!(Object.keys(colorJson).length === 0)){
fs.writeFile(output, JSON.stringify(colorJson), function(){});
}
return colorJson;
}
}
}
}
}
module.exports.postcss = true