Skip to content

Commit

Permalink
fixup! Feat(variables-scss): Formatting color tokens #DS-1461
Browse files Browse the repository at this point in the history
  • Loading branch information
curdaj committed Sep 9, 2024
1 parent 590c5ea commit b072820
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion exporters/variables-scss/generated/exporter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
`):c+=`${be.repeat(i)}${T}
`;return c=ht(c),c=_t(c),c},Ge=(u,i)=>Object.entries(i).reduce((c,[n,T])=>(typeof T=="object"&&T!==null&&typeof c[n]=="object"?c[n]=Ge(c[n],T):c[n]=T,c),{...u});function Ye(u){return Object.entries(u).map(([i,c])=>{if(typeof c=="object"&&c!==null){const n=Ye(c);return`${i}: (
${n}
),
),
`}return`${i}: ${c},
`}).join("").slice(0,-1)}const kt=u=>`/* This file was generated by Supernova, don't change manually */
${u}`,Ct=(u,i,c)=>u.filter(n=>{var T,m;return n.tokenType===i&&((m=(T=n.origin)==null?void 0:T.name)==null?void 0:m.includes(c))}),It=(u,i,c,n,T,m,g,r)=>{let t="",o={};n.forEach(a=>{T.forEach(y=>{const l=Ct(u,a,y);t+=St(l,i,c,y,g,r),t+=`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ $grid-spacing-desktop: 32px !default;

$grid-columns: 12 !default;

$grid-spacings: (
spacing-desktop: $grid-spacing-desktop,
) !default;

$grids: (
spacing: (
desktop: $grid-spacing-desktop,
),
columns: $grid-columns,
) !default;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('contentGenerator', () => {
const groupNames = ['Grid', 'String'];
const withCssObject = true;
const hasParentPrefix = true;
const sortByNumValue = false;

const fileContent = generateFileContent(
tokens,
Expand All @@ -28,6 +29,7 @@ describe('contentGenerator', () => {
groupNames,
withCssObject,
hasParentPrefix,
sortByNumValue,
);

expect(fileContent).toStrictEqual({ content: mockedExpectedResult });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Token, TokenGroup } from '@supernovaio/sdk-exporters';
import { generateCssObjectFromTokens, generateObjectContent } from '../cssObjectGenerator';
import { generateCssObjectFromTokens, getNonNumericPart } from '../cssObjectGenerator';
import { exampleMockedGroups, exampleMockedTokens } from '../../formatters/__fixtures__/mockedExampleTokens';

const mappedTokens: Map<string, Token> = new Map([]);
Expand All @@ -15,21 +15,19 @@ describe('cssObjectGenerator', () => {
true,
);

expect(css).toBe(
'$grid-spacings: (\ndesktop: $grid-spacing-desktop,\n) !default;\n\n$grids: (\ncolumns: $grid-columns,\n) !default;\n\n',
);
expect(css).toStrictEqual({
$grids: { columns: '$grid-columns', spacing: { desktop: '$grid-spacing-desktop' } },
});
});
});

describe('generateObjectContent', () => {
it('should generate object content', () => {
const objectContent = generateObjectContent(
[exampleMockedTokens.get('dimensionRef') as Token],
tokenGroups,
true,
);
describe('getNonNumericPart', () => {
it('should return special case for radius-full', () => {
expect(getNonNumericPart('radius-full')).toBe('full');
});

expect(objectContent).toBe('desktop: $grid-spacing-desktop,\n');
it('should return lowercase token name for other cases', () => {
expect(getNonNumericPart('Grid')).toBe('grid');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const specialCases: { [key: string]: string } = {
'radius-full': 'full',
};

const getNonNumericPart = (tokenName: string): string => {
export const getNonNumericPart = (tokenName: string): string => {
if (specialCases[tokenName]) {
return specialCases[tokenName];
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/variables-scss/src/helpers/cssObjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function convertToScss(obj: CssObjectType): string {
if (typeof value === 'object' && value !== null) {
const nestedScss = convertToScss(value as CssObjectType);

return `${key}: (\n${nestedScss}\n), \n`;
return `${key}: (\n${nestedScss}\n),\n`;
}

return `${key}: ${value},\n`;
Expand Down

0 comments on commit b072820

Please sign in to comment.