Skip to content

Commit

Permalink
Created an EuiTokensObject definition in eui.d.ts to declare existant…
Browse files Browse the repository at this point in the history
… i18n tokens
  • Loading branch information
chandlerprall committed Jun 29, 2021
1 parent 949189f commit a377c03
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/dtsgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const generator = dtsGenerator({
// 1. strip any `/// <reference` lines from the generated eui.d.ts
// 2. replace any import("src/...") declarations to import("@elastic/eui/src/...")
// 3. replace any import("./...") declarations to import("@elastic/eui/src/...)
// 4. generate & add EuiTokenObject
generator.then(() => {
const defsFilePath = path.resolve(baseDir, 'eui.d.ts');

Expand Down Expand Up @@ -144,5 +145,30 @@ generator.then(() => {
);
}
) // end 3.
.replace(/$/, `\n\n${buildEuiTokensObject()}`) // 4.
);
});

/** For step 4 **/
// i18ntokens.json is generated as the first step in the build and can be relied upon here
function buildEuiTokensObject() {
// reduce over the tokens list as a few of the tokens are used multiple times and must be
// filtered down to a list
const i18ndefs = require('../i18ntokens.json').reduce(
({ definitions, tokens }, def) => {
if (tokens.has(def.token)) {
tokens.add(def.token);
definitions.push(def);
}
return definitions;
},
{ definitions: [], tokens: new Set() }
);
return `
declare module '@elastic/eui' {
export type EuiTokensObject = {
${i18ndefs.map(({ token }) => `"${token}": any;`).join('\n')}
}
}
`;
}

0 comments on commit a377c03

Please sign in to comment.