(react) add tokens.ts files handling

These files will be used to define the custom design tokens per components.
They are automatically aggregated by the packages/react/cunningham.ts file,
this is why handling typescript config file was important.
This commit is contained in:
Nathan Vasse
2023-01-04 15:52:24 +01:00
committed by NathanVss
parent 67dd0048d0
commit be1c9d000b
19 changed files with 147 additions and 29 deletions

View File

@@ -0,0 +1,33 @@
import child_process from "child_process";
import path from "path";
/**
* Run the NPM script 'build-theme' in order to generate the tokens files ( cunningham-token.ts|css ).
* ( The purpose is mainly to generate the tokens files and then verify in tests that custom tokens defined in
* tokens.ts files are correctly taken into account. )
*/
export const buildTheme = (debug?: boolean) => {
const child = child_process.exec(
"cd " + path.join(__dirname, "..", "..") + " && yarn build-theme"
);
return new Promise<void>((resolve) => {
child.stdout?.on("data", (data) => {
// eslint-disable-next-line no-console
if (debug) console.log("stdout: " + data);
});
child.stderr?.on("data", (data) => {
// eslint-disable-next-line no-console
if (debug) console.log("stderr: " + data);
});
child.on("close", (code) => {
// eslint-disable-next-line no-console
if (debug) console.log("closing code: " + code);
resolve();
});
});
};
export const loadTokens = async () => {
const module = await import("../cunningham-tokens");
return module.tokens;
};