@digdir/designsystemet 0.1.0-alpha.3 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/bin/designsystemet.js +1 -1
- package/dist/build/src/migrations/beta-to-v1.js +64 -6
- package/dist/build/src/migrations/codemods/jsx/run.js +19 -0
- package/dist/build/src/migrations/index.js +3 -1
- package/dist/build/src/migrations/react-beta-to-v1.js +2 -0
- package/dist/build/src/test/jsx-test.js +1 -1
- package/dist/build/src/tokens/actions.js +13 -0
- package/dist/build/src/tokens/build.js +84 -38
- package/dist/build/src/tokens/formats/groupedTokens.js +28 -0
- package/dist/build/src/tokens/{formatters.js → formats/scopedReferenceVariables.js} +2 -30
- package/dist/build/src/tokens/formats/typographyClasses.js +31 -0
- package/dist/build/src/tokens/transformers.js +7 -6
- package/dist/build/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/migrations/beta-to-v1.d.ts.map +1 -1
- package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/jsx/run.d.ts +7 -0
- package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +1 -0
- package/dist/types/src/migrations/index.d.ts +2 -1
- package/dist/types/src/migrations/index.d.ts.map +1 -1
- package/dist/types/src/migrations/react-beta-to-v1.d.ts +3 -0
- package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +1 -0
- package/dist/types/src/test/jsx-test.d.ts.map +1 -1
- package/dist/types/src/tokens/actions.d.ts +3 -0
- package/dist/types/src/tokens/actions.d.ts.map +1 -0
- package/dist/types/src/tokens/build.d.ts.map +1 -1
- package/dist/types/src/tokens/formats/groupedTokens.d.ts +6 -0
- package/dist/types/src/tokens/formats/groupedTokens.d.ts.map +1 -0
- package/dist/types/src/tokens/{formatters.d.ts → formats/scopedReferenceVariables.d.ts} +1 -5
- package/dist/types/src/tokens/formats/scopedReferenceVariables.d.ts.map +1 -0
- package/dist/types/src/tokens/formats/typographyClasses.d.ts +6 -0
- package/dist/types/src/tokens/formats/typographyClasses.d.ts.map +1 -0
- package/dist/types/src/tokens/transformers.d.ts.map +1 -1
- package/package.json +10 -11
- package/dist/types/src/codemods/css/plugins.d.ts.map +0 -1
- package/dist/types/src/codemods/css/run.d.ts.map +0 -1
- package/dist/types/src/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/types/src/tokens/formatters.d.ts.map +0 -1
- /package/dist/build/src/{codemods → migrations/codemods}/css/plugins.js +0 -0
- /package/dist/build/src/{codemods → migrations/codemods}/css/run.js +0 -0
- /package/dist/build/src/{codemods → migrations/codemods}/jsx/classname-prefix.js +0 -0
- /package/dist/types/src/{codemods → migrations/codemods}/css/plugins.d.ts +0 -0
- /package/dist/types/src/{codemods → migrations/codemods}/css/run.d.ts +0 -0
- /package/dist/types/src/{codemods → migrations/codemods}/jsx/classname-prefix.d.ts +0 -0
|
@@ -24,7 +24,7 @@ program
|
|
|
24
24
|
.description('run a Designsystemet migration')
|
|
25
25
|
.addArgument(new Argument('[migration]', 'Available migrations').choices(Object.keys(migrations)))
|
|
26
26
|
.option('-l --list', 'List available migrations')
|
|
27
|
-
.option('-g --glob <glob>', 'Glob for files upon which to apply the migration', './**/*.css')
|
|
27
|
+
.option('-g --glob <glob>', 'Glob for files upon which to apply the migration', './**/*.(tsx|css)')
|
|
28
28
|
.action((migrationKey, opts) => {
|
|
29
29
|
const { glob, list } = opts;
|
|
30
30
|
if (list) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { cssClassRename, cssVarRename } from '
|
|
2
|
-
import { runCssCodemod } from '
|
|
1
|
+
import { cssClassRename, cssVarRename } from './codemods/css/plugins.js';
|
|
2
|
+
import { runCssCodemod } from './codemods/css/run.js';
|
|
3
3
|
export default (glob) => runCssCodemod({
|
|
4
4
|
globPattern: glob,
|
|
5
5
|
plugins: [
|
|
@@ -227,9 +227,8 @@ export default (glob) => runCssCodemod({
|
|
|
227
227
|
'--fds-base_spacing': '[delete]',
|
|
228
228
|
'--fds-base_sizing': '[delete]',
|
|
229
229
|
'--fds-border_width-default': '--ds-border-width-default',
|
|
230
|
-
'--fds-border_width-active': '--ds-border-width-
|
|
231
|
-
'--fds-
|
|
232
|
-
'--fds-border_width-tab_focus': '--ds-border-width-tab_focus', // Skulle denne fjernes?
|
|
230
|
+
'--fds-border_width-active': '--ds-border-width-highlight',
|
|
231
|
+
'--fds-border_width-tab_focus': '--ds-border-width-highlight',
|
|
233
232
|
'--fds-shadow-xsmall': '--ds-shadow-xs',
|
|
234
233
|
'--fds-shadow-small': '--ds-shadow-sm',
|
|
235
234
|
'--fds-shadow-medium': '--ds-shadow-md',
|
|
@@ -275,7 +274,66 @@ export default (glob) => runCssCodemod({
|
|
|
275
274
|
'--fds-sizing-22': '--ds-sizing-22',
|
|
276
275
|
'--fds-sizing-26': '--ds-sizing-26',
|
|
277
276
|
'--fds-sizing-30': '--ds-sizing-30',
|
|
278
|
-
'--fds-opacity-disabled': '--ds-opacity
|
|
277
|
+
'--fds-opacity-disabled': '--ds-disabled-opacity',
|
|
278
|
+
'--fds-colors-blue-100': '--ds-global-blue-1',
|
|
279
|
+
'--fds-colors-blue-200': '--ds-global-blue-2',
|
|
280
|
+
'--fds-colors-blue-700': '--ds-global-blue-7',
|
|
281
|
+
'--fds-colors-blue-800': '--ds-global-blue-8',
|
|
282
|
+
'--fds-colors-blue-900': '--ds-global-blue-9',
|
|
283
|
+
'--fds-colors-grey-100': '--ds-color-neutral-1',
|
|
284
|
+
'--fds-colors-grey-200': '--ds-color-neutral-2',
|
|
285
|
+
'--fds-colors-grey-400': '--ds-color-neutral-4',
|
|
286
|
+
'--fds-colors-grey-600': '--ds-color-neutral-6',
|
|
287
|
+
'--fds-colors-grey-700': '--ds-color-neutral-7',
|
|
288
|
+
'--fds-colors-grey-800': '--ds-color-neutral-8',
|
|
289
|
+
'--fds-colors-green-200': '--ds-global-green-2',
|
|
290
|
+
'--fds-colors-green-300': '--ds-global-green-3',
|
|
291
|
+
'--fds-colors-green-700': '--ds-global-green-7',
|
|
292
|
+
'--fds-colors-green-800': '--ds-global-green-8',
|
|
293
|
+
'--fds-colors-green-900': '--ds-global-green-9',
|
|
294
|
+
'--fds-colors-yellow-100': '--ds-global-yellow-1',
|
|
295
|
+
'--fds-colors-yellow-200': '--ds-global-yellow-2',
|
|
296
|
+
'--fds-colors-yellow-300': '--ds-global-yellow-3',
|
|
297
|
+
'--fds-colors-yellow-500': '--ds-global-yellow-5',
|
|
298
|
+
'--fds-colors-blue-400': '--ds-global-blue-4',
|
|
299
|
+
'--fds-colors-grey-300': '--ds-global-grey-3',
|
|
300
|
+
'--fds-colors-orange-600': '--ds-global-orange-6',
|
|
301
|
+
'--fds-colors-orange-700': '--ds-global-orange-7',
|
|
302
|
+
'--fds-colors-orange-800': '--ds-global-orange-8',
|
|
303
|
+
'--fds-colors-red-800': '--ds-global-red-8',
|
|
304
|
+
'--fds-colors-purple-700': '--ds-global-purple-7',
|
|
305
|
+
'--fds-colors-red-100': '--ds-global-red-1',
|
|
306
|
+
'--fds-colors-red-200': '--ds-global-red-2',
|
|
307
|
+
'--fds-colors-red-500': '--ds-global-red-5',
|
|
308
|
+
'--fds-colors-red-600': '--ds-global-red-6',
|
|
309
|
+
'--fds-colors-red-700': '--ds-global-red-7',
|
|
310
|
+
'--fds-brand-alt1-100': '--ds-color-brand1-1',
|
|
311
|
+
'--fds-brand-alt1-200': '--ds-color-brand1-2',
|
|
312
|
+
'--fds-brand-alt1-300': '--ds-color-brand1-3',
|
|
313
|
+
'--fds-brand-alt1-400': '--ds-color-brand1-4',
|
|
314
|
+
'--fds-brand-alt1-500': '--ds-color-brand1-5',
|
|
315
|
+
'--fds-brand-alt1-600': '--ds-color-brand1-6',
|
|
316
|
+
'--fds-brand-alt1-700': '--ds-color-brand1-7',
|
|
317
|
+
'--fds-brand-alt1-800': '--ds-color-brand1-8',
|
|
318
|
+
'--fds-brand-alt1-900': '--ds-color-brand1-9',
|
|
319
|
+
'--fds-brand-alt2-100': '--ds-color-brand2-1',
|
|
320
|
+
'--fds-brand-alt2-200': '--ds-color-brand2-2',
|
|
321
|
+
'--fds-brand-alt2-300': '--ds-color-brand2-3',
|
|
322
|
+
'--fds-brand-alt2-400': '--ds-color-brand2-4',
|
|
323
|
+
'--fds-brand-alt2-500': '--ds-color-brand2-5',
|
|
324
|
+
'--fds-brand-alt2-600': '--ds-color-brand2-6',
|
|
325
|
+
'--fds-brand-alt2-700': '--ds-color-brand2-7',
|
|
326
|
+
'--fds-brand-alt2-800': '--ds-color-brand2-8',
|
|
327
|
+
'--fds-brand-alt2-900': '--ds-color-brand2-9',
|
|
328
|
+
'--fds-brand-alt3-100': '--ds-color-brand3-1',
|
|
329
|
+
'--fds-brand-alt3-200': '--ds-color-brand3-2',
|
|
330
|
+
'--fds-brand-alt3-300': '--ds-color-brand3-3',
|
|
331
|
+
'--fds-brand-alt3-400': '--ds-color-brand3-4',
|
|
332
|
+
'--fds-brand-alt3-500': '--ds-color-brand3-5',
|
|
333
|
+
'--fds-brand-alt3-600': '--ds-color-brand3-6',
|
|
334
|
+
'--fds-brand-alt3-700': '--ds-color-brand3-7',
|
|
335
|
+
'--fds-brand-alt3-800': '--ds-color-brand3-8',
|
|
336
|
+
'--fds-brand-alt3-900': '--ds-color-brand3-9',
|
|
279
337
|
}),
|
|
280
338
|
],
|
|
281
339
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import glob from 'fast-glob';
|
|
2
|
+
import { run as jscodeshift } from 'jscodeshift/src/Runner.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
const transformer = `${import.meta.dirname}/classname-prefix.ts`;
|
|
5
|
+
export const runJSXCodemod = async ({ globPattern = './**/*.tsx', dry }) => {
|
|
6
|
+
const options = {
|
|
7
|
+
dry,
|
|
8
|
+
extensions: 'tsx',
|
|
9
|
+
parser: 'tsx',
|
|
10
|
+
};
|
|
11
|
+
const transform = async () => {
|
|
12
|
+
const files = await glob(globPattern, { ignore: ['node_modules/**', 'dist/**'] });
|
|
13
|
+
const result = await jscodeshift(transformer, files, options);
|
|
14
|
+
if (result.ok) {
|
|
15
|
+
console.log(chalk.green('Finished parsing'));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return transform();
|
|
19
|
+
};
|
|
@@ -6,5 +6,5 @@ export default function JsxTest({ className }) {
|
|
|
6
6
|
? 'fds-yes'
|
|
7
7
|
: typeof DEFAULT === 'function'
|
|
8
8
|
? 'fds-no'
|
|
9
|
-
: 'fds-yes', className) }) }), _jsx("div", { className: `fds-${DEFAULT}` })] }));
|
|
9
|
+
: 'fds-yes', className), children: "button" }) }), _jsx("div", { className: `fds-${DEFAULT}` })] }));
|
|
10
10
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import glob from 'fast-glob';
|
|
3
|
+
export const makeEntryFile = {
|
|
4
|
+
name: 'make_entryfile',
|
|
5
|
+
do: async function (dictionary, config) {
|
|
6
|
+
console.log('Creating entry file');
|
|
7
|
+
const { outPath, folderName } = config;
|
|
8
|
+
const files = await glob(`**/*`, { cwd: config.buildPath });
|
|
9
|
+
const content = files.map((file) => `@import url('./${folderName}/${file}');`).join('\n');
|
|
10
|
+
await fs.writeFile(`${outPath}/${folderName}.css`, content);
|
|
11
|
+
},
|
|
12
|
+
undo: async function noOp() { },
|
|
13
|
+
};
|
|
@@ -4,7 +4,10 @@ import { registerTransforms, permutateThemes } from '@tokens-studio/sd-transform
|
|
|
4
4
|
import StyleDictionary from 'style-dictionary';
|
|
5
5
|
import * as R from 'ramda';
|
|
6
6
|
import { nameKebab, typographyShorthand, sizeRem } from './transformers.js';
|
|
7
|
-
import { groupedTokens
|
|
7
|
+
import { groupedTokens } from './formats/groupedTokens.js';
|
|
8
|
+
import { scopedReferenceVariables } from './formats/scopedReferenceVariables.js';
|
|
9
|
+
import { typographyClasses } from './formats/typographyClasses.js';
|
|
10
|
+
import { makeEntryFile } from './actions.js';
|
|
8
11
|
void registerTransforms(StyleDictionary);
|
|
9
12
|
const prefix = 'ds';
|
|
10
13
|
const basePxFontSize = 16;
|
|
@@ -15,6 +18,8 @@ StyleDictionary.registerTransform(nameKebab);
|
|
|
15
18
|
StyleDictionary.registerTransform(typographyShorthand);
|
|
16
19
|
StyleDictionary.registerFormat(groupedTokens);
|
|
17
20
|
StyleDictionary.registerFormat(scopedReferenceVariables);
|
|
21
|
+
StyleDictionary.registerFormat(typographyClasses);
|
|
22
|
+
StyleDictionary.registerAction(makeEntryFile);
|
|
18
23
|
StyleDictionary.registerTransformGroup({
|
|
19
24
|
name: 'fds/css',
|
|
20
25
|
transforms: [
|
|
@@ -30,16 +35,21 @@ StyleDictionary.registerTransformGroup({
|
|
|
30
35
|
],
|
|
31
36
|
});
|
|
32
37
|
const processThemeName = R.pipe(R.replace(`${separator}semantic`, ''), R.toLower, R.split(separator));
|
|
33
|
-
const getCSSConfig = ({ fileName = 'unknown', buildPath = 'unknown' }) => {
|
|
38
|
+
const getCSSConfig = ({ fileName = 'unknown', buildPath = 'unknown', mode = 'light', outPath, folderName, }) => {
|
|
34
39
|
return {
|
|
35
|
-
log: { verbosity: 'verbose' },
|
|
36
40
|
preprocessors: ['tokens-studio'],
|
|
37
41
|
platforms: {
|
|
38
42
|
css: {
|
|
39
|
-
|
|
43
|
+
// custom
|
|
44
|
+
outPath,
|
|
45
|
+
fileName,
|
|
46
|
+
folderName,
|
|
40
47
|
basePxFontSize,
|
|
48
|
+
//
|
|
49
|
+
prefix,
|
|
50
|
+
buildPath: buildPath ?? `${outPath}/${folderName}/`,
|
|
41
51
|
transformGroup: 'fds/css',
|
|
42
|
-
|
|
52
|
+
actions: [makeEntryFile.name],
|
|
43
53
|
files: [
|
|
44
54
|
{
|
|
45
55
|
destination: `${fileName}.css`,
|
|
@@ -47,6 +57,7 @@ const getCSSConfig = ({ fileName = 'unknown', buildPath = 'unknown' }) => {
|
|
|
47
57
|
},
|
|
48
58
|
],
|
|
49
59
|
options: {
|
|
60
|
+
mode,
|
|
50
61
|
fileHeader,
|
|
51
62
|
includeReferences: (token) => {
|
|
52
63
|
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) &&
|
|
@@ -62,7 +73,6 @@ const getCSSConfig = ({ fileName = 'unknown', buildPath = 'unknown' }) => {
|
|
|
62
73
|
};
|
|
63
74
|
const getStorefrontConfig = ({ fileName = 'unknown', buildPath = 'unknown' }) => {
|
|
64
75
|
return {
|
|
65
|
-
log: { verbosity: 'verbose' },
|
|
66
76
|
preprocessors: ['tokens-studio'],
|
|
67
77
|
platforms: {
|
|
68
78
|
storefront: {
|
|
@@ -90,55 +100,91 @@ const getStorefrontConfig = ({ fileName = 'unknown', buildPath = 'unknown' }) =>
|
|
|
90
100
|
},
|
|
91
101
|
};
|
|
92
102
|
};
|
|
103
|
+
const getTypographyConfig = ({ buildPath = 'unknown' }) => {
|
|
104
|
+
return {
|
|
105
|
+
log: { verbosity: 'verbose' },
|
|
106
|
+
preprocessors: ['tokens-studio'],
|
|
107
|
+
platforms: {
|
|
108
|
+
css: {
|
|
109
|
+
prefix,
|
|
110
|
+
buildPath,
|
|
111
|
+
basePxFontSize,
|
|
112
|
+
transforms: [nameKebab.name, 'ts/size/lineheight', 'ts/size/px'],
|
|
113
|
+
files: [
|
|
114
|
+
{
|
|
115
|
+
destination: 'typography.css',
|
|
116
|
+
format: typographyClasses.name,
|
|
117
|
+
filter: (token) => token.type === 'typography',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
options: {
|
|
121
|
+
fileHeader,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
93
127
|
const sd = new StyleDictionary();
|
|
128
|
+
const getConfigs = (getConfig, outPath, tokensDir, themes) => Object.entries(themes)
|
|
129
|
+
.map(([name, tokensets]) => {
|
|
130
|
+
const setsWithPaths = tokensets.map((x) => `${tokensDir}/${x}.json`);
|
|
131
|
+
const [fileName, folderName] = processThemeName(name);
|
|
132
|
+
const paritionPrimitives = /(?!.*global\.json).*primitives.*/;
|
|
133
|
+
const [source, include] = R.partition(R.test(paritionPrimitives), setsWithPaths);
|
|
134
|
+
const config_ = getConfig({
|
|
135
|
+
fileName: fileName,
|
|
136
|
+
outPath,
|
|
137
|
+
folderName,
|
|
138
|
+
buildPath: `${outPath}/${folderName}/`,
|
|
139
|
+
mode: fileName,
|
|
140
|
+
});
|
|
141
|
+
const config = {
|
|
142
|
+
...config_,
|
|
143
|
+
source,
|
|
144
|
+
include,
|
|
145
|
+
};
|
|
146
|
+
// console.log(config);
|
|
147
|
+
return [`${folderName}: ${fileName}`, config];
|
|
148
|
+
})
|
|
149
|
+
.sort();
|
|
94
150
|
export async function run(options) {
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const $themes = JSON.parse(fs.readFileSync(path.resolve(`${
|
|
151
|
+
const tokensDir = options.tokens;
|
|
152
|
+
const storefrontOutDir = path.resolve('../../apps/storefront/tokens');
|
|
153
|
+
const tokensOutDir = path.resolve(options.out);
|
|
154
|
+
const $themes = JSON.parse(fs.readFileSync(path.resolve(`${tokensDir}/$themes.json`), 'utf-8'));
|
|
99
155
|
const themes = permutateThemes($themes, {
|
|
100
156
|
separator,
|
|
101
157
|
});
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
source: source,
|
|
116
|
-
include,
|
|
117
|
-
};
|
|
118
|
-
// console.log(config);
|
|
119
|
-
return [`${folderName}: ${fileName}`, config];
|
|
120
|
-
})
|
|
121
|
-
.sort();
|
|
122
|
-
const tokenConfigs = getConfigs(getCSSConfig, packageTokensOutPath);
|
|
123
|
-
const storefrontConfigs = getConfigs(getStorefrontConfig, storefrontTokensOutPath);
|
|
158
|
+
const tokenConfigs = getConfigs(getCSSConfig, tokensOutDir, tokensDir, themes);
|
|
159
|
+
const storefrontConfigs = getConfigs(getStorefrontConfig, storefrontOutDir, tokensDir, themes);
|
|
160
|
+
const typographyConfigs = getConfigs(getTypographyConfig, tokensOutDir, tokensDir, R.pickBy((val, key) => R.startsWith('light', R.toLower(key)), themes));
|
|
161
|
+
if (typographyConfigs.length > 0) {
|
|
162
|
+
console.log('🍱 Bulding typography classes');
|
|
163
|
+
console.log('➡️ Tokens path: ', tokensDir);
|
|
164
|
+
await Promise.all(typographyConfigs.map(async ([name, config]) => {
|
|
165
|
+
console.log(`👷 Processing ${name}`);
|
|
166
|
+
const typographyClasses = await sd.extend(config);
|
|
167
|
+
return typographyClasses.buildAllPlatforms();
|
|
168
|
+
}));
|
|
169
|
+
console.log('🏁 Finished building Typography classes!');
|
|
170
|
+
}
|
|
124
171
|
if (tokenConfigs.length > 0) {
|
|
125
|
-
console.log('🍱
|
|
126
|
-
console.log('➡️ Tokens path: ',
|
|
127
|
-
console.log('\n🏗️ Start building CSS tokens');
|
|
172
|
+
console.log('🍱 Building CSS variables from tokens');
|
|
173
|
+
console.log('➡️ Tokens path: ', tokensDir);
|
|
128
174
|
await Promise.all(tokenConfigs.map(async ([name, config]) => {
|
|
129
175
|
console.log(`👷 Processing ${name}`);
|
|
130
176
|
const tokensPackageSD = await sd.extend(config);
|
|
131
177
|
return tokensPackageSD.buildAllPlatforms();
|
|
132
178
|
}));
|
|
133
|
-
console.log('🏁 Finished building
|
|
179
|
+
console.log('🏁 Finished building CSS variables!');
|
|
134
180
|
}
|
|
135
181
|
if (storefrontConfigs.length > 0 && options.preview) {
|
|
136
|
-
console.log('\n🏗️
|
|
182
|
+
console.log('\n🏗️ Building storefront js tokens');
|
|
137
183
|
await Promise.all(storefrontConfigs.map(async ([name, config]) => {
|
|
138
184
|
console.log(`👷 Processing ${name}`);
|
|
139
185
|
const storefrontSD = await sd.extend(config);
|
|
140
186
|
return storefrontSD.buildAllPlatforms();
|
|
141
187
|
}));
|
|
142
|
-
console.log('🏁 Finished building storefront tokens
|
|
188
|
+
console.log('🏁 Finished building storefront tokens');
|
|
143
189
|
}
|
|
144
190
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { fileHeader, createPropertyFormatter } from 'style-dictionary/utils';
|
|
3
|
+
const groupByType = R.groupBy((token) => token.type);
|
|
4
|
+
/** Add token name with prefix to list for removal */
|
|
5
|
+
const removeUnwatedTokens = R.filter((token) => !['fds-base_spacing', 'fds-base_sizing'].includes(token.name));
|
|
6
|
+
const toCssVarName = R.pipe(R.split(':'), R.head, R.trim);
|
|
7
|
+
/**
|
|
8
|
+
* Format for displaying tokens in storefront
|
|
9
|
+
*/
|
|
10
|
+
export const groupedTokens = {
|
|
11
|
+
name: 'groupedTokens',
|
|
12
|
+
format: async function ({ dictionary, file }) {
|
|
13
|
+
const format = createPropertyFormatter({
|
|
14
|
+
dictionary,
|
|
15
|
+
format: 'css',
|
|
16
|
+
});
|
|
17
|
+
const formatTokens = R.map((token) => ({
|
|
18
|
+
...token,
|
|
19
|
+
name: toCssVarName(format(token)),
|
|
20
|
+
}));
|
|
21
|
+
const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
22
|
+
const tokens = processTokens(dictionary.allTokens);
|
|
23
|
+
const content = Object.entries(tokens)
|
|
24
|
+
.map(([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, '$1:')} \n`)
|
|
25
|
+
.join('\n');
|
|
26
|
+
return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
1
|
import { fileHeader, createPropertyFormatter, usesReferences, getReferences } from 'style-dictionary/utils';
|
|
3
2
|
/**
|
|
4
3
|
* CSS variables format with option to include source references for matched token through `options.referencesFilter`
|
|
@@ -7,9 +6,8 @@ export const scopedReferenceVariables = {
|
|
|
7
6
|
name: 'css/variables-scoped-references',
|
|
8
7
|
format: async function ({ dictionary, file, options }) {
|
|
9
8
|
const { allTokens, unfilteredTokens } = dictionary;
|
|
10
|
-
const { usesDtcg, outputReferences } = options;
|
|
11
|
-
const
|
|
12
|
-
const selector = mode === 'dark' ? '[data-ds-color-mode="dark"]' : ':root, [data-ds-color-mode="light"]';
|
|
9
|
+
const { usesDtcg, outputReferences, mode } = options;
|
|
10
|
+
const selector = `${mode === 'light' ? ':root, ' : ''}[data-ds-color-mode="${mode}"]`;
|
|
13
11
|
const includeReferences = options.includeReferences;
|
|
14
12
|
let referencedTokens = [];
|
|
15
13
|
const format = createPropertyFormatter({
|
|
@@ -51,29 +49,3 @@ ${tokens.join('\n')}
|
|
|
51
49
|
`);
|
|
52
50
|
},
|
|
53
51
|
};
|
|
54
|
-
const groupByType = R.groupBy((token) => token.type);
|
|
55
|
-
/** Add token name with prefix to list for removal */
|
|
56
|
-
const removeUnwatedTokens = R.filter((token) => !['fds-base_spacing', 'fds-base_sizing'].includes(token.name));
|
|
57
|
-
const toCssVarName = R.pipe(R.split(':'), R.head, R.trim);
|
|
58
|
-
/**
|
|
59
|
-
* Format for displaying tokens in storefront
|
|
60
|
-
*/
|
|
61
|
-
export const groupedTokens = {
|
|
62
|
-
name: 'groupedTokens',
|
|
63
|
-
format: async function ({ dictionary, file }) {
|
|
64
|
-
const format = createPropertyFormatter({
|
|
65
|
-
dictionary,
|
|
66
|
-
format: 'css',
|
|
67
|
-
});
|
|
68
|
-
const formatTokens = R.map((token) => ({
|
|
69
|
-
...token,
|
|
70
|
-
name: toCssVarName(format(token)),
|
|
71
|
-
}));
|
|
72
|
-
const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
73
|
-
const tokens = processTokens(dictionary.allTokens);
|
|
74
|
-
const content = Object.entries(tokens)
|
|
75
|
-
.map(([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, '$1:')} \n`)
|
|
76
|
-
.join('\n');
|
|
77
|
-
return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
|
|
78
|
-
},
|
|
79
|
-
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { fileHeader } from 'style-dictionary/utils';
|
|
3
|
+
// const isTransformedToken = (token: TransformedTokens): token is TransformedToken => token;
|
|
4
|
+
/**
|
|
5
|
+
* Creates CSS classes from typography tokens
|
|
6
|
+
*/
|
|
7
|
+
export const typographyClasses = {
|
|
8
|
+
name: 'typographyClasses',
|
|
9
|
+
format: async function ({ dictionary, file, options, platform }) {
|
|
10
|
+
const { usesDtcg } = options;
|
|
11
|
+
const { basePxFontSize } = platform;
|
|
12
|
+
const classNames = R.map((token) => {
|
|
13
|
+
if (!Array.isArray(token)) {
|
|
14
|
+
const typography = (usesDtcg ? token.$value : token.value);
|
|
15
|
+
const baseFontPx = basePxFontSize || 16;
|
|
16
|
+
const fontSize = `${parseInt(typography.fontSize) / baseFontPx}rem`;
|
|
17
|
+
const className = `
|
|
18
|
+
.${token.name} {
|
|
19
|
+
font-size: ${fontSize};
|
|
20
|
+
line-height: ${typography?.lineHeight};
|
|
21
|
+
font-weight: ${typography?.fontWeight};
|
|
22
|
+
}`;
|
|
23
|
+
return className;
|
|
24
|
+
}
|
|
25
|
+
}, dictionary.allTokens);
|
|
26
|
+
return fileHeader({ file }).then((fileHeaderText) => `${fileHeaderText}
|
|
27
|
+
@layer ds.typography {
|
|
28
|
+
${classNames.join('\n')}
|
|
29
|
+
}\n`);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -3,15 +3,16 @@ export const sizeRem = {
|
|
|
3
3
|
name: 'fds/size/toRem',
|
|
4
4
|
type: 'value',
|
|
5
5
|
transitive: true,
|
|
6
|
-
filter: (token) => ['sizing', 'spacing'].includes(token.type) &&
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
filter: (token) => ['sizing', 'spacing'].includes(token.type) && !token.name.includes('base'),
|
|
7
|
+
transform: (token, config, options) => {
|
|
8
|
+
const { usesDtcg } = options;
|
|
9
|
+
const value = (usesDtcg ? token.$value : token.value);
|
|
9
10
|
const baseFont = config.basePxFontSize || 16;
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
11
|
+
const size = parseInt(value);
|
|
12
|
+
if (size === 0) {
|
|
12
13
|
return '0';
|
|
13
14
|
}
|
|
14
|
-
return `${
|
|
15
|
+
return `${size / baseFont}rem`;
|
|
15
16
|
},
|
|
16
17
|
};
|
|
17
18
|
export const nameKebab = {
|