From fc9f330c47dda57657f8d6c5cafccce7ff097241 Mon Sep 17 00:00:00 2001 From: Michael Marszalek Date: Thu, 6 Jun 2024 21:54:44 +0200 Subject: [PATCH] cleaning up some more sd files --- packages/cli/src/tokens/actions.ts | 17 +++++++++++------ packages/cli/src/tokens/build.ts | 2 ++ packages/cli/src/tokens/configs.ts | 5 ++--- packages/cli/src/tokens/formats/css-classes.ts | 13 ++++--------- .../cli/src/tokens/formats/css-variables.ts | 11 ++--------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/tokens/actions.ts b/packages/cli/src/tokens/actions.ts index cc705c977c..3e7c955887 100644 --- a/packages/cli/src/tokens/actions.ts +++ b/packages/cli/src/tokens/actions.ts @@ -6,14 +6,19 @@ import * as R from 'ramda'; export const makeEntryFile: Action = { name: 'make_entryfile', - do: async function (dictionary, config) { - console.log(chalk.green('Creating entry file')); - const { outPath, folderName } = config; - const files = await glob(`**/*`, { cwd: config.buildPath }); + do: async function (dictionary, platform) { + const { outPath, theme } = platform; + + const writePath = `${outPath}/${theme}.css`; + + console.log(chalk.green(`Creating entry file: ${writePath}`)); + + const files = await glob(`**/*`, { cwd: platform.buildPath }); const content = R.reverse(R.sortBy(R.includes('light'), files)) - .map((file) => `@import url('./${folderName}/${file}');`) + .map((file) => `@import url('./${theme}/${file}');`) .join('\n'); - await fs.writeFile(`${outPath}/${folderName}.css`, content); + + await fs.writeFile(writePath, content); }, undo: async function noOp() {}, }; diff --git a/packages/cli/src/tokens/build.ts b/packages/cli/src/tokens/build.ts index f89f23cac9..885548b4c1 100644 --- a/packages/cli/src/tokens/build.ts +++ b/packages/cli/src/tokens/build.ts @@ -16,6 +16,8 @@ type Options = { preview: boolean; }; +// type FormattedCSSPlatform = { css: { output: string; destination: string }[] }; + const sd = new StyleDictionary(); export async function run(options: Options): Promise { diff --git a/packages/cli/src/tokens/configs.ts b/packages/cli/src/tokens/configs.ts index 3fc82b7c67..f53c40e50b 100644 --- a/packages/cli/src/tokens/configs.ts +++ b/packages/cli/src/tokens/configs.ts @@ -71,8 +71,7 @@ export const tokensConfig: GetConfig = ({ mode = 'light', outPath, theme }) => { // custom outPath, mode, - fileName: mode, - folderName: theme, + theme, basePxFontSize, selector, // @@ -176,7 +175,7 @@ export const getConfigs = ( const [mode, theme, semantic, fontSize, typography] = processThemeName(name); - console.log({ mode, theme, semantic, fontSize, typography }); + // console.log({ mode, theme, semantic, fontSize, typography }); const paritionPrimitives = /(?!.*global\.json).*primitives.*/; const [source, include] = R.partition(R.test(paritionPrimitives), setsWithPaths); diff --git a/packages/cli/src/tokens/formats/css-classes.ts b/packages/cli/src/tokens/formats/css-classes.ts index 8ce1f6647b..f91b304d6e 100644 --- a/packages/cli/src/tokens/formats/css-classes.ts +++ b/packages/cli/src/tokens/formats/css-classes.ts @@ -9,8 +9,6 @@ type Typgraphy = { fontFamily: string; }; -// const isTransformedToken = (token: TransformedTokens): token is TransformedToken => token; - /** * Creates CSS classes from typography tokens */ @@ -20,6 +18,8 @@ export const cssClasses: Format = { const { usesDtcg } = options; const { basePxFontSize } = platform; + const header = await fileHeader({ file }); + const classNames = R.map((token) => { if (!Array.isArray(token)) { const typography = (usesDtcg ? token.$value : token.value) as Typgraphy; @@ -28,8 +28,7 @@ export const cssClasses: Format = { const fontSize = `${parseInt(typography.fontSize) / baseFontPx}rem`; const selector = R.replace('-typography', '', token.name); - const className = ` - .${selector} { + const className = `.${selector} { font-size: ${fontSize}; line-height: ${typography?.lineHeight}; font-weight: ${typography?.fontWeight}; @@ -39,10 +38,6 @@ export const cssClasses: Format = { } }, dictionary.allTokens); - return fileHeader({ file }).then( - (fileHeaderText) => `${fileHeaderText}@layer ds.typography { -${classNames.join('\n')} -}\n`, - ); + return header + `@layer ds.typography {\n${classNames.join('\n')}\n}\n`; }, }; diff --git a/packages/cli/src/tokens/formats/css-variables.ts b/packages/cli/src/tokens/formats/css-variables.ts index e72af3c18c..15dd19e6c3 100644 --- a/packages/cli/src/tokens/formats/css-variables.ts +++ b/packages/cli/src/tokens/formats/css-variables.ts @@ -1,9 +1,6 @@ import type { Format } from 'style-dictionary/types'; import { fileHeader, createPropertyFormatter } from 'style-dictionary/utils'; -/** - * CSS variables format with option to include source references for matched token through `options.referencesFilter` - */ export const cssVariables: Format = { name: 'ds/css-variables', format: async function ({ dictionary, file, options, platform }) { @@ -19,12 +16,8 @@ export const cssVariables: Format = { format: 'css', }); - const tokens = allTokens.map(format); + const formattedVariables = allTokens.map(format); - return ` -${header} -${selector} { -${tokens.join('\n')} -}\n`; + return header + `${selector} {\n${formattedVariables.join('\n')}\n}\n`; }, };