Skip to content

Commit

Permalink
remove custom kebab case transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz committed Jan 9, 2025
1 parent e38883c commit a86cc80
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 68 deletions.
19 changes: 10 additions & 9 deletions packages/cli/src/tokens/build/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { Config as StyleDictionaryConfig, TransformedToken } from 'style-di
import { outputReferencesFilter } from 'style-dictionary/utils';

import { DEFAULT_COLOR, buildOptions } from '../build.js';
import { isColorCategoryToken, pathStartsWithOneOf, typeEquals } from '../utils.js';
import { isColorCategoryToken, isDigit, pathStartsWithOneOf, typeEquals } from '../utils.js';
import { formats } from './formats/css.js';
import { jsTokens } from './formats/js-tokens.js';
import { nameKebab, resolveMath, sizeRem, typographyName, unitless } from './transformers.js';
import { resolveMath, sizeRem, typographyName, unitless } from './transformers.js';
import type {
ColorCategories,
GetSdConfigOptions,
Expand All @@ -29,7 +29,6 @@ export const basePxFontSize = 16;
const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];

StyleDictionary.registerTransform(sizeRem);
StyleDictionary.registerTransform(nameKebab);
StyleDictionary.registerTransform(typographyName);
StyleDictionary.registerTransform(resolveMath);
StyleDictionary.registerTransform(unitless);
Expand All @@ -40,7 +39,7 @@ for (const format of Object.values(formats)) {
}

const dsTransformers = [
nameKebab.name,
'name/kebab',
resolveMath.name,
'ts/size/px',
sizeRem.name,
Expand Down Expand Up @@ -198,8 +197,9 @@ const semanticVariables: GetStyleDictionaryConfig = ({ theme }, { outPath }) =>
options: {
fileHeader,
outputReferences: (token, options) => {
const include = pathStartsWithOneOf(['border-radius', 'size'], token);
return include && outputReferencesFilter(token, options);
const include = pathStartsWithOneOf(['border-radius'], token);
const isWantedSize = pathStartsWithOneOf(['size'], token) && isDigit(token.path[1]);
return (include || isWantedSize) && outputReferencesFilter(token, options);
},
},
},
Expand Down Expand Up @@ -240,8 +240,9 @@ const typescriptTokens: GetStyleDictionaryConfig = ({ 'color-scheme': colorSchem
options: {
fileHeader,
outputReferences: (token, options) => {
const include = pathStartsWithOneOf(['border-radius', 'size'], token);
return include && outputReferencesFilter(token, options);
const include = pathStartsWithOneOf(['border-radius'], token);
const isWantedSize = pathStartsWithOneOf(['size'], token) && isDigit(token.path[1]);
return (include || isWantedSize) && outputReferencesFilter(token, options);
},
},
},
Expand Down Expand Up @@ -269,7 +270,7 @@ const typographyVariables: GetStyleDictionaryConfig = ({ theme, typography }, {
buildPath: `${outPath}/${theme}/`,
basePxFontSize,
transforms: [
nameKebab.name,
'name/kebab',
'ts/size/px',
sizeRem.name,
'ts/size/lineheight',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/tokens/build/formats/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createPropertyFormatter, fileHeader } from 'style-dictionary/utils';
import {
getValue,
isColorCategoryToken,
isDigit,
isGlobalColorToken,
isSemanticToken,
pathStartsWithOneOf,
Expand Down Expand Up @@ -140,7 +141,6 @@ const colorCategory: Format = {
},
};

const isDigit = (s: string) => /^\d+$/.test(s);
const isNumericBorderRadiusToken = (t: TransformedToken) => t.path[0] === 'border-radius' && isDigit(t.path[1]);

const isUwantedTokens = R.anyPass([isNumericBorderRadiusToken]);
Expand Down
12 changes: 0 additions & 12 deletions packages/cli/src/tokens/build/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as R from 'ramda';
import type { Transform } from 'style-dictionary/types';

import { getValue, pathStartsWithOneOf, typeEquals } from '../utils.js';
import { noCase } from './utils/noCase.js';

const isPx = R.test(/\b\d+px\b/g);

Expand Down Expand Up @@ -34,17 +33,6 @@ export const sizeRem: Transform = {
},
};

export const nameKebab: Transform = {
name: 'name/cti/hierarchical-kebab',
type: 'name',
transform: (token, options) => {
return noCase([options?.prefix].concat(token.path).join('-'), {
delimiter: '-',
stripRegexp: /[^A-Z0-9_]+/gi,
});
},
};

export const typographyName: Transform = {
name: 'name/typography',
type: 'name',
Expand Down
46 changes: 0 additions & 46 deletions packages/cli/src/tokens/build/utils/noCase.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/cli/src/tokens/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ export const copyFile = async (src: string, dest: string, dry?: boolean) => {

return await fs.copyFile(src, dest);
};

export const isDigit = (s: string) => /^\d+$/.test(s);

0 comments on commit a86cc80

Please sign in to comment.