🐛(tokens) fix scss generator
scss maps expect keys between quotes like: $map = ( 'key': value, )
This commit is contained in:
5
.changeset/nasty-donuts-run.md
Normal file
5
.changeset/nasty-donuts-run.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@openfun/cunningham-tokens": minor
|
||||
---
|
||||
|
||||
Fix SassGenerator
|
||||
@@ -26,26 +26,26 @@ describe("SassGenerator", () => {
|
||||
expect(fs.existsSync(sassFile)).toEqual(true);
|
||||
expect(fs.readFileSync(sassFile).toString()).toMatchInlineSnapshot(`
|
||||
"$colors: (
|
||||
primary: #055FD2,
|
||||
secondary: #DA0000,
|
||||
ternary: (
|
||||
900: #022858
|
||||
'primary': #055FD2,
|
||||
'secondary': #DA0000,
|
||||
'ternary': (
|
||||
'900': #022858
|
||||
)
|
||||
);
|
||||
$fontFamilies: (
|
||||
base: Roboto
|
||||
'base': Roboto
|
||||
);
|
||||
$fontSizes: (
|
||||
m: 1rem
|
||||
'm': 1rem
|
||||
);
|
||||
$fontWeights: (
|
||||
medium: 400
|
||||
'medium': 400
|
||||
);
|
||||
$spacings: (
|
||||
s: 1rem
|
||||
's': 1rem
|
||||
);
|
||||
$transitions: (
|
||||
ease: linear
|
||||
'ease': linear
|
||||
);
|
||||
"
|
||||
`);
|
||||
|
||||
@@ -55,7 +55,19 @@ const generateTransitionsSassMap = (tokens: Tokens) => {
|
||||
};
|
||||
|
||||
function JSONToSassMap(json: Object) {
|
||||
return JSON.stringify(json, null, 2)
|
||||
function deepQuoteObjectKeys(object: Object) {
|
||||
return Object.entries(object).reduce(
|
||||
(acc, [key, value]): Record<string, any> => ({
|
||||
...acc,
|
||||
[`'${key}'`]:
|
||||
typeof value === "object" ? deepQuoteObjectKeys(value) : value,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
}
|
||||
const jsonWithQuotedKeys = deepQuoteObjectKeys(json);
|
||||
|
||||
return JSON.stringify(jsonWithQuotedKeys, null, 2)
|
||||
.replace(/{/g, "(")
|
||||
.replace(/}/g, ")")
|
||||
.replace(/"/g, "");
|
||||
|
||||
Reference in New Issue
Block a user