forked from csstools/postcss-custom-selectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (23 loc) · 1.06 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
import postcss from 'postcss';
import getCustomSelectors from './lib/custom-selectors-from-root';
import transformRules from './lib/transform-rules';
import importCustomSelectorsFromSources from './lib/import-from';
import exportCustomSelectorsToDestinations from './lib/export-to';
export default postcss.plugin('postcss-custom-selectors', opts => {
// whether to preserve custom selectors and rules using them
const preserve = Boolean(Object(opts).preserve);
// sources to import custom selectors from
const importFrom = [].concat(Object(opts).importFrom || []);
// destinations to export custom selectors to
const exportTo = [].concat(Object(opts).exportTo || []);
// promise any custom selectors are imported
const customSelectorsPromise = importCustomSelectorsFromSources(importFrom);
return async root => {
const customProperties = Object.assign(
await customSelectorsPromise,
getCustomSelectors(root, { preserve })
);
await exportCustomSelectorsToDestinations(customProperties, exportTo);
transformRules(root, customProperties, { preserve });
};
});