🐛(tokens) fix generators

When customized tokens have multiple entries like theme and components,
each variable definition needs to end with a ;.
This commit is contained in:
Romain Le Cellier
2023-08-09 14:49:45 +02:00
parent 53bccd111b
commit 7de28bcf9b
9 changed files with 22 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@openfun/cunningham-tokens": patch
---
Fix bug on sass token generation

View File

@@ -24,7 +24,7 @@ describe("JsGenerator", () => {
await run(["", "", "-g", "js"]);
expect(fs.existsSync(tokensFile)).toEqual(true);
expect(fs.readFileSync(tokensFile).toString()).toMatchInlineSnapshot(`
"export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000","ternary-900":"#022858","ogre-odor-is-orange-indeed":"#FD5240"},"font":{"sizes":{"m":"1rem"},"weights":{"medium":400},"families":{"base":"Roboto"}},"spacings":{"s":"1rem"},"transitions":{"ease":"linear"},"input":{"border-color":"#022858"}}};
"export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000","ternary-900":"#022858","ogre-odor-is-orange-indeed":"#FD5240"},"font":{"sizes":{"m":"1rem"},"weights":{"medium":400},"families":{"base":"Roboto"}},"spacings":{"s":"1rem"},"transitions":{"ease":"linear"},"input":{"border-color":"#022858"}},"components":{"button":{"font-family":"Times New Roman"}}};
"
`);
});

View File

@@ -52,7 +52,12 @@ describe("SassGenerator", () => {
'input': (
'border-color': #022858
)
) !default
) !default;
$components: (
'button': (
'font-family': Times New Roman
)
) !default;
"
`);
});

View File

@@ -44,5 +44,5 @@ function JSONToSassMap(json: Object, isDefault = true) {
.replace(/{/g, "(")
.replace(/}/g, ")")
.replace(/"/g, "")
.concat(isDefault ? " !default" : "");
.concat(isDefault ? " !default;" : "");
}

View File

@@ -24,7 +24,7 @@ describe("TsGenerator", () => {
await run(["", "", "-g", "ts"]);
expect(fs.existsSync(tokensFile)).toEqual(true);
expect(fs.readFileSync(tokensFile).toString()).toMatchInlineSnapshot(`
"export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000","ternary-900":"#022858","ogre-odor-is-orange-indeed":"#FD5240"},"font":{"sizes":{"m":"1rem"},"weights":{"medium":400},"families":{"base":"Roboto"}},"spacings":{"s":"1rem"},"transitions":{"ease":"linear"},"input":{"border-color":"#022858"}}};
"export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000","ternary-900":"#022858","ogre-odor-is-orange-indeed":"#FD5240"},"font":{"sizes":{"m":"1rem"},"weights":{"medium":400},"families":{"base":"Roboto"}},"spacings":{"s":"1rem"},"transitions":{"ease":"linear"},"input":{"border-color":"#022858"}},"components":{"button":{"font-family":"Times New Roman"}}};
"
`);
});

View File

@@ -27,4 +27,9 @@ module.exports = {
"border-color": "ref(theme.colors.ternary-900)",
},
},
components: {
button: {
"font-family": "Times New Roman",
},
},
};

View File

@@ -9,4 +9,5 @@
--c--theme--spacings--s: 1rem;
--c--theme--transitions--ease: linear;
--c--theme--input--border-color: var(--c--theme--colors--ternary-900);
--c--components--button--font-family: Times New Roman;
}

View File

@@ -9,4 +9,5 @@
--c--theme--spacings--s: 1rem;
--c--theme--transitions--ease: linear;
--c--theme--input--border-color: var(--c--theme--colors--ternary-900);
--c--components--button--font-family: Times New Roman;
}

View File

@@ -9,6 +9,7 @@
--c--theme--spacings--s: 1rem;
--c--theme--transitions--ease: linear;
--c--theme--input--border-color: var(--c--theme--colors--ternary-900);
--c--components--button--font-family: Times New Roman;
} .clr-primary { color: var(--c--theme--colors--primary); }
.clr-secondary { color: var(--c--theme--colors--secondary); }
.clr-ternary-900 { color: var(--c--theme--colors--ternary-900); }