1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | console.warn(`
|
10 | **** WARNING: Ring UI extract-css-vars.js is deprecated since 2.0 in favor of "importFrom" option of postcss-preset-env ****
|
11 | **** Consider using the following way of including variables: ****
|
12 | 'postcss-preset-env': {
|
13 | importFrom: require.resolve('@jetbrains/ring-ui/components/global/variables.css'),
|
14 | features: {
|
15 | 'postcss-custom-properties': {
|
16 | preserve: true
|
17 | }
|
18 | }
|
19 | }
|
20 | **** More details: https://github.com/postcss/postcss-custom-properties#importfrom, https://github.com/csstools/postcss-preset-env#importfrom ***
|
21 | `);
|
22 |
|
23 | const fs = require('fs');
|
24 |
|
25 | const postcss = require('postcss');
|
26 |
|
27 | const customPropertyMatch = /^--([_a-zA-Z]+[_a-zA-Z0-9-]*)$/;
|
28 |
|
29 | function isCustomProperty(node) {
|
30 | return node.type === 'decl' && customPropertyMatch.test(node.prop);
|
31 | }
|
32 |
|
33 | const ExtractVariablesPlugin = postcss.
|
34 | plugin('postcss-export-ring-variables', () => {
|
35 | const variables = {};
|
36 |
|
37 | return (root, result) => {
|
38 | root.walk(node => {
|
39 | if (isCustomProperty(node)) {
|
40 | const [, property] = node.prop.match(customPropertyMatch);
|
41 |
|
42 | variables[`--${property}`] = node.value;
|
43 | }
|
44 | });
|
45 |
|
46 | result.parsedVariables = variables;
|
47 | };
|
48 | });
|
49 |
|
50 | const variablesSource = fs.
|
51 | readFileSync(require.resolve('./components/global/variables.css'));
|
52 |
|
53 | const res = ExtractVariablesPlugin.
|
54 | process(variablesSource.toString(), {}, {}).sync();
|
55 |
|
56 | module.exports = res.parsedVariables;
|