Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(exporter-tokens): Sort typography tokens and remove unused param… #1780

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exporters/tokens/exporter.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Spirit Tokens Exporter allows you to export a tokens from Supernova",
"author": "Spirit Design System Team <[email protected]>",
"organization": "Alma Career",
"version": "1.0.1",
"version": "1.1.0",
"usesBrands": true,
"usesThemes": true,
"executable": "/generated/exporter.cjs",
Expand Down
74 changes: 37 additions & 37 deletions exporters/tokens/generated/exporter.cjs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion exporters/tokens/src/config/fileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const nonThemedFilesData: FileData[] = [
{
fileName: 'typography',
tokenTypes: [TokenType.typography],
hasParentPrefix: false,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ describe('mixinGenerator', () => {
const dataProvider = [
{
tokens: exampleColorsTokens,
groupName: '',
hasParentPrefix: false,
hasTokenPrefix: true,
description: 'should generate mixin from tokens',
expectedStyles: `${SCSS_INDENTATION}--spirit-color-active: #{$active};\n${SCSS_INDENTATION}--spirit-color-primary: #{$primary};`,
},
{
tokens: exampleColorsTokens,
groupName: '',
hasParentPrefix: false,
hasTokenPrefix: false,
description: 'should generate mixin with parent prefix and no token prefix',
Expand All @@ -30,15 +28,14 @@ describe('mixinGenerator', () => {

it.each(dataProvider)(
'should correctly generate mixin for $description',
({ tokens, expectedStyles, groupName, hasParentPrefix, hasTokenPrefix }) => {
({ tokens, expectedStyles, hasParentPrefix, hasTokenPrefix }) => {
const prefixTokens = Array.from(examplePrefixToken.values());
const tokenPrefix = hasTokenPrefix ? findTokenPrefix(prefixTokens) : '';

const styles = generateMixinFromTokens(
Array.from(tokens.values()),
tokenGroups,
tokenPrefix,
groupName,
hasParentPrefix,
false,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ describe('stylesGenerator', () => {
const dataProvider = [
{
tokens: exampleDimensionAndStringTokens,
groupName: 'Grid',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: true,
Expand All @@ -168,7 +167,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleDimensionAndStringTokens,
groupName: 'Grid',
hasJsOutput: true,
hasMixin: false,
hasParentPrefix: true,
Expand All @@ -178,7 +176,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleColorsTokens,
groupName: '',
hasJsOutput: false,
hasMixin: true,
hasParentPrefix: false,
Expand All @@ -188,7 +185,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleColorsTokens,
groupName: '',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: false,
Expand All @@ -198,7 +194,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleColorsTokens,
groupName: '',
hasJsOutput: true,
hasMixin: true,
hasParentPrefix: false,
Expand All @@ -208,7 +203,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleShadowTokens,
groupName: '',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: false,
Expand All @@ -218,7 +212,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleShadowTokens,
groupName: '',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: false,
Expand All @@ -228,7 +221,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleGradientTokens,
groupName: '',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: false,
Expand All @@ -239,7 +231,6 @@ describe('stylesGenerator', () => {
},
{
tokens: exampleGradientTokens,
groupName: '',
hasJsOutput: false,
hasMixin: false,
hasParentPrefix: false,
Expand All @@ -252,15 +243,14 @@ describe('stylesGenerator', () => {

it.each(dataProvider)(
'$description',
({ tokens, groupName, hasJsOutput, hasMixin, hasParentPrefix, hasTokenPrefix, expectedStyles }) => {
({ tokens, hasJsOutput, hasMixin, hasParentPrefix, hasTokenPrefix, expectedStyles }) => {
const prefixTokens = Array.from(examplePrefixToken.values());
const tokenPrefix = hasTokenPrefix ? findTokenPrefix(prefixTokens) : '';
const styles = generateStylesFromTokens(
Array.from(tokens.values()),
mappedTokens,
tokenGroups,
tokenPrefix,
groupName,
hasMixin,
hasParentPrefix,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
typographyGroupReducer,
} from '../stylesObjectGenerator';

const mappedTokens: Map<string, Token> = new Map([]);
const tokenGroups: Array<TokenGroup> = exampleGroups;

describe('stylesObjectGenerator', () => {
Expand Down Expand Up @@ -109,13 +108,7 @@ describe('stylesObjectGenerator', () => {
];

it.each(dataProvider)('$description', ({ tokens, expectedStyles, hasJsOutput }) => {
const styles = generateStylesObjectFromTokens(
Array.from(tokens.values()),
mappedTokens,
tokenGroups,
true,
hasJsOutput,
);
const styles = generateStylesObjectFromTokens(Array.from(tokens.values()), tokenGroups, true, hasJsOutput, false);

expect(styles).toStrictEqual(expectedStyles);
});
Expand Down
10 changes: 4 additions & 6 deletions exporters/tokens/src/generators/contentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export const generateFileContent = (
let stylesObject: StylesObjectType = {};
let styledMixin = '';
const {
excludeGroupNames = null,
groupNames = [''],
hasParentPrefix = true,
sortByNumValue = false,
hasMixin = false,
hasParentPrefix = true,
hasStylesObject = true,
sortByNumValue = false,
tokenTypes,
excludeGroupNames = null,
} = fileData;

// Iterate over token types and groups to filter tokens
Expand All @@ -114,7 +114,6 @@ export const generateFileContent = (
mappedTokens,
tokenGroups,
tokenPrefix,
group,
hasMixin,
hasParentPrefix,
sortByNumValue,
Expand All @@ -129,7 +128,6 @@ export const generateFileContent = (
filteredTokens,
tokenGroups,
tokenPrefix,
group,
hasParentPrefix,
sortByNumValue,
);
Expand All @@ -138,10 +136,10 @@ export const generateFileContent = (
// Generate css object and merge it with the existing one
const groupStylesObject = generateStylesObjectFromTokens(
filteredTokens,
mappedTokens,
tokenGroups,
hasParentPrefix,
hasJsOutput,
sortByNumValue,
);
stylesObject = deepMergeObjects(stylesObject, groupStylesObject);
});
Expand Down
2 changes: 1 addition & 1 deletion exporters/tokens/src/generators/fileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const generateOutputFilesByThemes = async (
// Generate root themes file
const rootThemesFileContent = generateThemesRootFile(themes);
const rootTsThemesFileContent = generateThemesRootFile(themes, true);
const rootScssThemesFile = `@forward 'color-tokens';\n`;
const rootScssThemesFile = "@forward 'color-tokens';\n";
const colorTokensFile = generateFiles(
filteredColorCollections,
mappedTokens,
Expand Down
3 changes: 1 addition & 2 deletions exporters/tokens/src/generators/mixinGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ export const generateMixinFromTokens = (
tokens: Token[],
tokenGroups: Array<TokenGroup>,
tokenPrefix: string,
group: string,
hasParentPrefix: boolean,
sortByNumValue: boolean,
): string => {
const sortedTokens = sortTokens(tokens, tokenGroups, hasParentPrefix, group, sortByNumValue);
const sortedTokens = sortTokens(tokens, tokenGroups, hasParentPrefix, sortByNumValue);
const variables = sortedTokens
.map((token) => {
const name = tokenVariableName(token, tokenGroups, hasParentPrefix);
Expand Down
3 changes: 1 addition & 2 deletions exporters/tokens/src/generators/stylesGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ export const generateStylesFromTokens = (
mappedTokens: Map<string, Token>,
tokenGroups: Array<TokenGroup>,
tokenPrefix: string,
group: string,
hasMixin: boolean,
hasParentPrefix: boolean,
sortByNumValue: boolean,
hasJsOutput: boolean = false,
): string => {
const sortedTokens = sortTokens(tokens, tokenGroups, hasParentPrefix, group, sortByNumValue);
const sortedTokens = sortTokens(tokens, tokenGroups, hasParentPrefix, sortByNumValue);

const cssTokens = sortedTokens.map((token) => ({
css: tokenToStyleByType(token, mappedTokens, tokenGroups, tokenPrefix, hasMixin, hasParentPrefix, hasJsOutput),
Expand Down
7 changes: 4 additions & 3 deletions exporters/tokens/src/generators/stylesObjectGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Token, TokenGroup, TokenType, TypographyToken } from '@supernovaio/sdk-exporters';
import { formatTypographyName, getBreakpoint, getTokenAlias, normalizeFirstNamePart } from '../helpers/objectHelper';
import { tokenVariableName, typographyValue } from '../helpers/tokenHelper';
import { sortTokens, tokenVariableName, typographyValue } from '../helpers/tokenHelper';
import { toCamelCase } from '../helpers/stringHelper';
import { COLOR_JS_SUFFIX, COLOR_KEY, COLOR_SCSS_SUFFIX, TYPOGRAPHY_KEY } from '../constants';

Expand Down Expand Up @@ -115,12 +115,13 @@ export const createGlobalTypographyObject = (typographyKeys: Array<string>) => {
// TODO: refactor this function to not use cssObject reference
export const generateStylesObjectFromTokens = (
tokens: Array<Token>,
mappedTokens: Map<string, Token>,
tokenGroups: Array<TokenGroup>,
hasParentPrefix: boolean,
hasJsOutput: boolean,
sortByNumValue: boolean,
): StylesObjectType => {
const stylesObject = tokens.reduce((stylesObjectAccumulator, token) => {
const sortedTokens = sortTokens(tokens, tokenGroups, hasParentPrefix, sortByNumValue);
const stylesObject = sortedTokens.reduce((stylesObjectAccumulator, token) => {
const currentObject = createStylesObjectStructureFromTokenNameParts(
token,
tokenGroups,
Expand Down
1 change: 0 additions & 1 deletion exporters/tokens/src/helpers/tokenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const sortTokens = (
tokens: Token[],
tokenGroups: Array<TokenGroup>,
hasParentPrefix: boolean,
group: string,
sortByNumValue: boolean,
) => {
const sortedTokens = tokens.sort((a, b) => {
Expand Down