-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
41 lines (35 loc) · 1.08 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
const less = require("less");
const loopWhile = require("deasync").loopWhile;
module.exports = (css, settings) => {
const cssWithPlaceholders = css
.replace(
/\:\s*%%styled-jsx-placeholder-(\d+)%%/g,
(_, id) => `: styled-jsx-placeholder-${id}()`
)
.replace(
/%%styled-jsx-placeholder-(\d+)%%/g,
(_, id) => `/*%%styled-jsx-placeholder-${id}%%*/`
);
let wait = true;
let preprocessed = "";
function resolved(result) {
preprocessed = result;
wait = false;
}
less.render(cssWithPlaceholders, settings).then(function(output) {
resolved(output.css);
}).catch(function(error) {
resolved("");
console.log(error);
});
loopWhile(() => wait);
return preprocessed
.replace(
/\:\s*styled-jsx-placeholder-(\d+)\(\)/g,
(_, id) => `: %%styled-jsx-placeholder-${id}%%`
)
.replace(
/\/\*%%styled-jsx-placeholder-(\d+)%%\*\//g,
(_, id) => `%%styled-jsx-placeholder-${id}%%`
);
};