Skip to content

Commit

Permalink
feat(cli): generate per-category classnames
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadsammy committed Dec 12, 2021
1 parent 0ed9ba0 commit 805396f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/cli/core/FileContentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class FileContentGenerator {
'\n\n' +
this.regularClassnamesTypesTemplate() +
'\n\n' +
this.pseudoClassnamesTypesTemplate() +
'\n\n' +
this.utilityFunctionsTemplate() +
'\n\n' +
this.mainExportStatementsTemplate()
Expand Down Expand Up @@ -80,6 +82,45 @@ export class FileContentGenerator {
return generatedClassnamesTemplate + '\n\n' + allclassnamesExportTemplate;
};

private pseudoClassnamesTypesTemplate = (): string => {
let template = '';

for (const [keyOfCategory, value] of Object.entries(this._generatedClassNames)) {
const categoryObject = this._generatedClassNames[keyOfCategory as keyof TAllClassnames];

if (categoryObject !== undefined) {
const allClassnamesInCategory: string[] = Object.keys(value)
.map(k => {
return categoryObject[k as keyof typeof categoryObject];
})
.flat();

const pseudoClassnamesOfCategory = this._configParser.getVariants().flatMap(variant => {
return allClassnamesInCategory.map(classname => {
return (
variant +
this._configParser.getSeparator() +
this._configParser.getPrefix() +
classname
);
});
});

template =
template +
this.generateTypesTemplate(
`T${keyOfCategory}PseudoClassnames`,
pseudoClassnamesOfCategory,
undefined,
true,
) +
'\n\n';
}
}

return template;
};

private utilityFunctionsTemplate = (): string => {
return Object.keys(this._generatedClassNames)
.map(categoryGroupName => {
Expand Down

0 comments on commit 805396f

Please sign in to comment.