Skip to content

Commit

Permalink
cleaning up some more sd files
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz committed Jun 6, 2024
1 parent 4589ff9 commit fc9f330
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
17 changes: 11 additions & 6 deletions packages/cli/src/tokens/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},
};
2 changes: 2 additions & 0 deletions packages/cli/src/tokens/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/tokens/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export const tokensConfig: GetConfig = ({ mode = 'light', outPath, theme }) => {
// custom
outPath,
mode,
fileName: mode,
folderName: theme,
theme,
basePxFontSize,
selector,
//
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions packages/cli/src/tokens/formats/css-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ type Typgraphy = {
fontFamily: string;
};

// const isTransformedToken = (token: TransformedTokens): token is TransformedToken => token;

/**
* Creates CSS classes from typography tokens
*/
Expand All @@ -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;
Expand All @@ -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};
Expand All @@ -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`;
},
};
11 changes: 2 additions & 9 deletions packages/cli/src/tokens/formats/css-variables.ts
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand All @@ -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`;
},
};

0 comments on commit fc9f330

Please sign in to comment.