-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-parsing.js
More file actions
42 lines (35 loc) · 1003 Bytes
/
process-parsing.js
File metadata and controls
42 lines (35 loc) · 1003 Bytes
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
import postcss from 'postcss'
import postcssrc from 'postcss-load-config'
import safeParse from 'postcss-safe-parser'
import defaultConfig from './default-config'
let config
let processor
/**
* 1. Initiate config, options and processor variables in module scope,
* if they are not initiated yet
*
* 2. Process parsing with initiated options
*
* @param {String} rawStyles
* @param {Object} processOptions
* @returns {Object} JSS Object
*/
const processParsing = async (rawStyles, processOptions = {}) => {
const { config: customConfig } = processOptions
if (!config && customConfig) {
config = customConfig
} else if (!config) {
try {
config = await postcssrc()
} catch (e) {
config = defaultConfig
}
}
const { plugins = [], options = {} } = config
const finalOptions = { parser: safeParse, ...options }
if (!processor) {
processor = postcss(plugins)
}
return processor.process(rawStyles, finalOptions)
}
export default processParsing