Skip to content

Commit

Permalink
chore(tokens): ♻️ New token export
Browse files Browse the repository at this point in the history
Creating a separate stack on #1849 for new tokens export
  • Loading branch information
mimarz committed May 15, 2024
1 parent 354d979 commit 6346bf7
Show file tree
Hide file tree
Showing 25 changed files with 95,210 additions and 11,074 deletions.
12,768 changes: 10,285 additions & 2,483 deletions apps/storefront/tokens/altinn.ts

Large diffs are not rendered by default.

12,632 changes: 10,193 additions & 2,439 deletions apps/storefront/tokens/brreg.ts

Large diffs are not rendered by default.

12,756 changes: 10,282 additions & 2,474 deletions apps/storefront/tokens/digdir.ts

Large diffs are not rendered by default.

12,669 changes: 12,669 additions & 0 deletions apps/storefront/tokens/theme1.ts

Large diffs are not rendered by default.

12,669 changes: 12,669 additions & 0 deletions apps/storefront/tokens/theme2.ts

Large diffs are not rendered by default.

12,669 changes: 12,669 additions & 0 deletions apps/storefront/tokens/theme3.ts

Large diffs are not rendered by default.

12,669 changes: 12,669 additions & 0 deletions apps/storefront/tokens/theme4.ts

Large diffs are not rendered by default.

12,658 changes: 10,257 additions & 2,401 deletions apps/storefront/tokens/tilsynet.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion design-tokens/$themes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1387,4 +1387,4 @@
"colors.brand3.contrast-2": "1996d517bbcfa74cc3110ce915465d9356390c88"
}
}
]
]
10 changes: 9 additions & 1 deletion design-tokens/core/modes/dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@
"value": "#f6fafd",
"type": "color"
},
"contrast-2": {
"value": "#ddeaf6",
"type": "color"
},
"contrast-1": {
"value": "#f6fafd",
"type": "color"
},
"contrast-2": {
"value": "#ddeaf6",
"type": "color"
Expand Down Expand Up @@ -1561,4 +1569,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion design-tokens/themes/theme1.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"designsystemet": "esno ./bin/designsystemet.ts",
"build": "yarn clean && yarn designsystemet tokens -t ../../design-tokens -b Digdir Tilsynet Altinn Brreg",
"build": "yarn clean && yarn designsystemet tokens -t ../../design-tokens -b theme1 theme2 theme3 theme4",
"prepublish": "tsc",
"clean": "yarn workspace @digdir/designsystemet-theme clean",
"css-light-dark-codemod": "esno ./bin/designsystemet.ts migrate tokens-rename-light-dark"
Expand Down
88 changes: 57 additions & 31 deletions packages/cli/src/tokens/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import path from 'path';
import fs from 'fs';

import { registerTransforms } from '@tokens-studio/sd-transforms';
import {
registerTransforms,
permutateThemes,
} from '@tokens-studio/sd-transforms';
import type { ThemeObject } from '@tokens-studio/types';
import StyleDictionary from 'style-dictionary';
import type { Config, TransformedToken } from 'style-dictionary/types';

Expand Down Expand Up @@ -42,17 +47,17 @@ StyleDictionary.registerTransformGroup({

const baseConfig = (brand: Brand, tokensPath: string): Partial<Config> => {
return {
log: { verbosity: 'silent' },
log: { verbosity: 'verbose' },
include: [
`${tokensPath}/Brand/${brand}.json`,
`${tokensPath}/Base/Semantic.json`,
`${tokensPath}/themes/${brand}.json`,
`${tokensPath}/semantic/**/*.json`,
],
source: [`${tokensPath}/Base/Core.json`],
source: [`${tokensPath}/core/**/*.json`],
};
};

const excludeSource = (token: TransformedToken) => {
if (token.filePath.includes('Core.json')) return false;
if (token.filePath.includes('core/**/*.json')) return false;

if (token.path[0] === 'viewport' && ['color'].includes(token.type as string))
return false;
Expand All @@ -63,29 +68,30 @@ const excludeSource = (token: TransformedToken) => {
const getCSSTokensConfig = (
brand: Brand,
targetFolder = '',
tokensPath: string,
tokensets: string[],
): Config => {
const destinationPath = `${targetFolder}/${brand.toLowerCase()}`;
const destinationPath = `${targetFolder}/${brand.toLowerCase()}/`;

return {
...baseConfig(brand, tokensPath),
log: { verbosity: 'verbose' },
source: tokensets,
platforms: {
css: {
prefix,
basePxFontSize,
transformGroup: 'fds/css',
buildPath: destinationPath,
files: [
{
destination: `${destinationPath}/tokens.css`,
destination: `tokens.css`,
format: scopedReferenceVariables.name,
filter: excludeSource,
},
],
options: {
fileHeader,
includeReferences: (token: TransformedToken) =>
['color'].includes(token.type as string) &&
!(token.value as string).startsWith('rgba'),
['color'].includes(token.type as string),
},
},
},
Expand Down Expand Up @@ -129,11 +135,29 @@ type Options = {
};

export async function run(options: Options): Promise<void> {
const brands = options.brands;
const tokensPath = options.tokens;

const $themes = JSON.parse(
fs.readFileSync(path.resolve(`${tokensPath}/$themes.json`), 'utf-8'),
) as ThemeObject[];

const storefrontTokensPath = path.resolve('../../apps/storefront/tokens');
const themes = permutateThemes($themes, {
separator: '_',
}) as Record<string, string[]>;

const brands = Object.entries(themes).map(([name]) => name);

// const storefrontTokensPath = path.resolve('../../apps/storefront/tokens');
const packageTokensPath = path.resolve('../../packages/theme/brand');
const tokensPath = options.tokens;

const configs = Object.entries(themes).map(([name, tokensets]) => {
const updatedSets = tokensets.map((x) =>
path.resolve(`${tokensPath}/${x}.json`),
);

console.log({ name, updatedSets });
return getCSSTokensConfig(name, packageTokensPath, updatedSets);
});

if (brands.length > 0) {
console.log('🍱 Staring token builder');
Expand All @@ -142,31 +166,33 @@ export async function run(options: Options): Promise<void> {

console.log('\n🏗️ Start building CSS tokens');
await Promise.all(
brands.map(async (brand) => {
console.log(`👷 Processing ${brand}`);
configs.map(async (config) => {
console.log(
`👷 Processing ${config?.platforms?.css?.files?.[0]?.destination}`,
);

console.log('config:', config);

const sd = new StyleDictionary();
const tokensPackageSD = await sd.extend(
getCSSTokensConfig(brand, packageTokensPath, tokensPath),
);
const tokensPackageSD = await sd.extend(config);

return tokensPackageSD.buildAllPlatforms();
}),
);
console.log('🏁 Finished building package tokens!');

console.log('\n🏗️ Started building storefront tokens…');
await Promise.all(
brands.map(async (brand) => {
console.log(`👷 Processing ${brand}`);
// console.log('\n🏗️ Started building storefront tokens…');
// await Promise.all(
// brands.map(async (brand) => {
// console.log(`👷 Processing ${brand}`);

const storefrontSD = new StyleDictionary(
getStorefrontConfig(brand, storefrontTokensPath, tokensPath),
);
// const storefrontSD = new StyleDictionary(
// getStorefrontConfig(brand, storefrontTokensPath, tokensPath),
// );

return storefrontSD.buildAllPlatforms();
}),
);
console.log('🏁 Finished building storefront tokens!');
// return storefrontSD.buildAllPlatforms();
// }),
// );
// console.log('🏁 Finished building storefront tokens!');
}
}
Loading

0 comments on commit 6346bf7

Please sign in to comment.