@digdir/designsystemet 0.1.0-next.31 → 0.100.51-next.52
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/README.md +16 -0
- package/dist/bin/config.d.ts +162 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +56 -0
- package/dist/{types/bin → bin}/designsystemet.d.ts.map +1 -1
- package/dist/bin/designsystemet.js +159 -31
- package/dist/bin/options.d.ts +16 -0
- package/dist/bin/options.d.ts.map +1 -0
- package/dist/bin/options.js +12 -0
- package/dist/config.schema.json +81 -0
- package/dist/src/colors/colorMetadata.d.ts +53 -0
- package/dist/src/colors/colorMetadata.d.ts.map +1 -0
- package/dist/src/colors/colorMetadata.js +211 -0
- package/dist/{types/src → src}/colors/index.d.ts +1 -0
- package/dist/src/colors/index.d.ts.map +1 -0
- package/dist/src/colors/index.js +1 -0
- package/dist/src/colors/theme.d.ts +30 -0
- package/dist/src/colors/theme.d.ts.map +1 -0
- package/dist/src/colors/theme.js +52 -233
- package/dist/src/colors/types.d.ts +63 -0
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/{types/src → src}/colors/utils.d.ts +39 -56
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +59 -187
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +45 -45
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.js +7 -8
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.js +9 -1
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
- package/dist/src/migrations/codemods/jsx/run.d.ts.map +1 -0
- package/dist/src/migrations/color-rename-next49.d.ts +3 -0
- package/dist/src/migrations/color-rename-next49.d.ts.map +1 -0
- package/dist/src/migrations/color-rename-next49.js +38 -0
- package/dist/{types/src → src}/migrations/index.d.ts +1 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/index.js +3 -1
- package/dist/src/migrations/react-beta-to-v1.d.ts.map +1 -0
- package/dist/src/scripts/copy-internal-tokens.d.ts +2 -0
- package/dist/src/scripts/copy-internal-tokens.d.ts.map +1 -0
- package/dist/src/scripts/copy-internal-tokens.js +28 -0
- package/dist/src/scripts/createJsonSchema.d.ts +2 -0
- package/dist/src/scripts/createJsonSchema.d.ts.map +1 -0
- package/dist/src/scripts/createJsonSchema.js +15 -0
- package/dist/src/tokens/build/builtin-colors.css +87 -0
- package/dist/src/tokens/build/configs.d.ts +21 -0
- package/dist/src/tokens/build/configs.d.ts.map +1 -0
- package/dist/src/tokens/build/configs.js +136 -95
- package/dist/src/tokens/build/formats/css.d.ts +53 -0
- package/dist/src/tokens/build/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/build/formats/css.js +140 -111
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -0
- package/dist/src/tokens/build/formats/js-tokens.js +22 -9
- package/dist/src/tokens/build/transformers.d.ts +6 -0
- package/dist/src/tokens/build/transformers.d.ts.map +1 -0
- package/dist/src/tokens/build/transformers.js +27 -18
- package/dist/src/tokens/build/types.d.ts +45 -0
- package/dist/src/tokens/build/types.d.ts.map +1 -0
- package/dist/src/tokens/build/types.js +7 -0
- package/dist/{types/src → src}/tokens/build/utils/entryfile.d.ts +1 -0
- package/dist/src/tokens/build/utils/entryfile.d.ts.map +1 -0
- package/dist/src/tokens/build/utils/entryfile.js +42 -6
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts +35 -0
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +112 -0
- package/dist/src/tokens/build.d.ts +20 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +131 -0
- package/dist/src/tokens/create.d.ts +18 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +99 -0
- package/dist/src/{init/template/default-files/design-tokens → tokens/design-tokens/default}/primitives/globals.json +2 -20
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/global.json +96 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/large.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/medium.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/small.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/large.json +96 -0
- package/dist/src/{init/template/default-files/design-tokens/primitives/size/default.json → tokens/design-tokens/default/primitives/modes/typography/size/medium.json} +9 -88
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/small.json +96 -0
- package/dist/src/{init/template/default-files/design-tokens → tokens/design-tokens/default}/semantic/style.json +126 -312
- package/dist/src/tokens/design-tokens/template/$metadata.json +25 -0
- package/dist/src/tokens/design-tokens/template/$themes.json +1498 -0
- package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +278 -0
- package/dist/src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json +66 -0
- package/dist/src/tokens/design-tokens/template/semantic/semantic-color-template.json +66 -0
- package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +57 -0
- package/dist/src/tokens/design-tokens/template/themes/theme-color-template.json +66 -0
- package/dist/src/tokens/index.d.ts +3 -0
- package/dist/src/tokens/index.d.ts.map +1 -0
- package/dist/src/tokens/index.js +2 -1
- package/dist/src/tokens/template.d.ts +2 -0
- package/dist/src/tokens/template.d.ts.map +1 -0
- package/dist/src/tokens/template.js +98 -0
- package/dist/src/tokens/types.d.ts +46 -0
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/src/tokens/types.js +0 -0
- package/dist/src/tokens/utils.d.ts +34 -0
- package/dist/src/tokens/utils.d.ts.map +1 -0
- package/dist/src/tokens/utils.js +85 -0
- package/dist/src/tokens/write/generate$metadata.d.ts +9 -0
- package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -0
- package/dist/src/tokens/write/generate$metadata.js +28 -0
- package/dist/src/tokens/write/generate$themes.d.ts +12 -0
- package/dist/src/tokens/write/generate$themes.d.ts.map +1 -0
- package/dist/src/tokens/write/generate$themes.js +161 -0
- package/dist/src/tokens/write.d.ts +12 -0
- package/dist/src/tokens/write.d.ts.map +1 -0
- package/dist/src/tokens/write.js +176 -0
- package/package.json +43 -31
- package/dist/src/init/createTokensPackage.js +0 -273
- package/dist/src/init/generateMetadataJson.js +0 -24
- package/dist/src/init/generateThemesJson.js +0 -103
- package/dist/src/init/index.js +0 -10
- package/dist/src/init/nextStepsMarkdown.js +0 -92
- package/dist/src/init/template/default-files/README.md +0 -10
- package/dist/src/init/template/default-files/design-tokens/Figma/components.json +0 -22
- package/dist/src/init/template/default-files/design-tokens/README.md +0 -3
- package/dist/src/init/template/default-files/design-tokens/semantic/color.json +0 -572
- package/dist/src/init/template/default-files/design-tokens/themes/theme.json +0 -334
- package/dist/src/init/template/prettier.config.js +0 -5
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/global.json +0 -376
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/theme-template.json +0 -314
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/global.json +0 -376
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/theme-template.json +0 -314
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/global.json +0 -376
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/theme-template.json +0 -314
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/primary/theme-template.json +0 -30
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/secondary/theme-template.json +0 -30
- package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +0 -334
- package/dist/src/init/template/template-files/package.json +0 -24
- package/dist/src/init/utils.js +0 -15
- package/dist/src/tokens/build/actions.js +0 -33
- package/dist/src/tokens/build/index.js +0 -85
- package/dist/src/tokens/build/utils/noCase.js +0 -24
- package/dist/src/tokens/build/utils/permutateThemes.js +0 -64
- package/dist/src/tokens/build/utils/utils.js +0 -25
- package/dist/src/tokens/create/README.md +0 -3
- package/dist/src/tokens/create/index.js +0 -150
- package/dist/types/src/colors/index.d.ts.map +0 -1
- package/dist/types/src/colors/theme.d.ts +0 -85
- package/dist/types/src/colors/theme.d.ts.map +0 -1
- package/dist/types/src/colors/types.d.ts +0 -17
- package/dist/types/src/colors/types.d.ts.map +0 -1
- package/dist/types/src/colors/utils.d.ts.map +0 -1
- package/dist/types/src/init/createTokensPackage.d.ts +0 -5
- package/dist/types/src/init/createTokensPackage.d.ts.map +0 -1
- package/dist/types/src/init/generateMetadataJson.d.ts +0 -6
- package/dist/types/src/init/generateMetadataJson.d.ts.map +0 -1
- package/dist/types/src/init/generateThemesJson.d.ts +0 -3
- package/dist/types/src/init/generateThemesJson.d.ts.map +0 -1
- package/dist/types/src/init/index.d.ts +0 -3
- package/dist/types/src/init/index.d.ts.map +0 -1
- package/dist/types/src/init/nextStepsMarkdown.d.ts +0 -3
- package/dist/types/src/init/nextStepsMarkdown.d.ts.map +0 -1
- package/dist/types/src/init/template/prettier.config.d.mts +0 -9
- package/dist/types/src/init/template/prettier.config.d.mts.map +0 -1
- package/dist/types/src/init/utils.d.ts +0 -4
- package/dist/types/src/init/utils.d.ts.map +0 -1
- package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/types/src/migrations/index.d.ts.map +0 -1
- package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/tokens/build/actions.d.ts +0 -6
- package/dist/types/src/tokens/build/actions.d.ts.map +0 -1
- package/dist/types/src/tokens/build/configs.d.ts +0 -31
- package/dist/types/src/tokens/build/configs.d.ts.map +0 -1
- package/dist/types/src/tokens/build/formats/css.d.ts +0 -5
- package/dist/types/src/tokens/build/formats/css.d.ts.map +0 -1
- package/dist/types/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
- package/dist/types/src/tokens/build/index.d.ts +0 -11
- package/dist/types/src/tokens/build/index.d.ts.map +0 -1
- package/dist/types/src/tokens/build/transformers.d.ts +0 -5
- package/dist/types/src/tokens/build/transformers.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/noCase.d.ts +0 -11
- package/dist/types/src/tokens/build/utils/noCase.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/permutateThemes.d.ts +0 -17
- package/dist/types/src/tokens/build/utils/permutateThemes.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/utils.d.ts +0 -25
- package/dist/types/src/tokens/build/utils/utils.d.ts.map +0 -1
- package/dist/types/src/tokens/create/index.d.ts +0 -64
- package/dist/types/src/tokens/create/index.d.ts.map +0 -1
- package/dist/types/src/tokens/index.d.ts +0 -2
- package/dist/types/src/tokens/index.d.ts.map +0 -1
- /package/dist/{types/bin → bin}/designsystemet.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/beta-to-v1.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/css/plugins.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/css/run.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/jsx/classname-prefix.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/jsx/run.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/react-beta-to-v1.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/build/formats/js-tokens.d.ts +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CssColor } from '../colors/types.js';
|
|
2
|
+
export type Token = {
|
|
3
|
+
$value: string;
|
|
4
|
+
$type: string;
|
|
5
|
+
};
|
|
6
|
+
export type Tokens1ary = Record<string, Token>;
|
|
7
|
+
export type Tokens2ary = Record<string, Tokens1ary>;
|
|
8
|
+
export type Tokens3ary = Record<string, Record<string, Tokens1ary>>;
|
|
9
|
+
export type TokensSet = Tokens1ary | Tokens2ary | Tokens3ary;
|
|
10
|
+
export type ColorModeTokens = {
|
|
11
|
+
global: TokensSet;
|
|
12
|
+
[key: string]: TokensSet;
|
|
13
|
+
};
|
|
14
|
+
export type TypographyTokens = TokensSet;
|
|
15
|
+
export type Tokens = {
|
|
16
|
+
colors: {
|
|
17
|
+
light: ColorModeTokens;
|
|
18
|
+
dark: ColorModeTokens;
|
|
19
|
+
contrast?: ColorModeTokens;
|
|
20
|
+
};
|
|
21
|
+
typography: {
|
|
22
|
+
primary: TokensSet;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type Colors = {
|
|
26
|
+
main: Record<string, CssColor>;
|
|
27
|
+
support: Record<string, CssColor>;
|
|
28
|
+
neutral: CssColor;
|
|
29
|
+
};
|
|
30
|
+
export type Typography = {
|
|
31
|
+
fontFamily?: string;
|
|
32
|
+
};
|
|
33
|
+
export type TypographyModes = 'primary' | 'secondary';
|
|
34
|
+
export type File = {
|
|
35
|
+
data: string;
|
|
36
|
+
path: string;
|
|
37
|
+
filePath: string;
|
|
38
|
+
};
|
|
39
|
+
export type Collection = string | 'global';
|
|
40
|
+
export type Theme = {
|
|
41
|
+
name: string;
|
|
42
|
+
colors: Colors;
|
|
43
|
+
typography: Typography;
|
|
44
|
+
borderRadius: number;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAGzC,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE;QACN,KAAK,EAAE,eAAe,CAAC;QACvB,IAAI,EAAE,eAAe,CAAC;QACtB,QAAQ,CAAC,EAAE,eAAe,CAAC;KAC5B,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,SAAS,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtD,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE3C,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DesignToken, TransformedToken } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
4
|
+
* @param token Transformed token
|
|
5
|
+
* @returns type
|
|
6
|
+
*/
|
|
7
|
+
export declare const getType: (token: TransformedToken) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
10
|
+
*
|
|
11
|
+
* Use generic (`<T>`) to define return value type
|
|
12
|
+
* @param token Transformed or Design token
|
|
13
|
+
* @returns value
|
|
14
|
+
*/
|
|
15
|
+
export declare const getValue: <T>(token: TransformedToken | DesignToken) => T;
|
|
16
|
+
/**
|
|
17
|
+
* Check if token type matches provided type
|
|
18
|
+
* This function is curried
|
|
19
|
+
* @param types Type or array of types to check against
|
|
20
|
+
* @param token Transformed token
|
|
21
|
+
* @returns boolean
|
|
22
|
+
*/
|
|
23
|
+
export declare const typeEquals: import("ts-toolbelt/out/Function/Curry.js").Curry<(types: string[] | string, token: TransformedToken) => boolean>;
|
|
24
|
+
export declare const pathStartsWithOneOf: import("ts-toolbelt/out/Function/Curry.js").Curry<(paths: string[], token: TransformedToken) => boolean>;
|
|
25
|
+
export declare function isSemanticToken(token: TransformedToken): boolean;
|
|
26
|
+
export declare function isGlobalColorToken(token: TransformedToken): boolean;
|
|
27
|
+
export declare function isColorCategoryToken(token: TransformedToken, category?: 'main' | 'support'): boolean;
|
|
28
|
+
export declare const mkdir: (dir: string, dry?: boolean) => Promise<string | void>;
|
|
29
|
+
export declare const writeFile: (path: string, data: string, dry?: boolean) => Promise<void>;
|
|
30
|
+
export declare const cp: (src: string, dest: string, dry?: boolean) => Promise<void>;
|
|
31
|
+
export declare const copyFile: (src: string, dest: string, dry?: boolean) => Promise<void>;
|
|
32
|
+
export declare const isDigit: (s: string) => boolean;
|
|
33
|
+
export declare const cleanDir: (dir: string, dry?: boolean) => Promise<void>;
|
|
34
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tokens/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,OAAO,UAAW,gBAAgB,WAAkD,CAAC;AAElG;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,gBAAgB,GAAG,WAAW,KAAG,CAAuC,CAAC;AAE5G;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,4DAAmB,MAAM,EAAE,GAAG,MAAM,SAAS,gBAAgB,aAMlF,CAAC;AAEH,eAAO,MAAM,mBAAmB,4DAAmB,MAAM,EAAE,SAAS,gBAAgB,aASlF,CAAC;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAEnE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAKpG;AAED,eAAO,MAAM,KAAK,QAAe,MAAM,QAAQ,OAAO,2BAOrD,CAAC;AAEF,eAAO,MAAM,SAAS,SAAgB,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOxE,CAAC;AAEF,eAAO,MAAM,EAAE,QAAe,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOhE,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAe,MAAM,QAAQ,MAAM,QAAQ,OAAO,kBAOtE,CAAC;AAEF,eAAO,MAAM,OAAO,MAAO,MAAM,YAAoB,CAAC;AAEtD,eAAO,MAAM,QAAQ,QAAe,MAAM,QAAQ,OAAO,kBASxD,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import * as R from "ramda";
|
|
4
|
+
const mapToLowerCase = R.map(R.toLower);
|
|
5
|
+
const hasAnyTruth = R.any(R.equals(true));
|
|
6
|
+
const getType = (token) => (token.$type ?? token.type) || "";
|
|
7
|
+
const getValue = (token) => token.$value ?? token.value;
|
|
8
|
+
const typeEquals = R.curry((types, token) => {
|
|
9
|
+
if (R.isNil(token)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
13
|
+
});
|
|
14
|
+
const pathStartsWithOneOf = R.curry((paths, token) => {
|
|
15
|
+
if (R.isNil(token)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
19
|
+
const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
|
|
20
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
21
|
+
});
|
|
22
|
+
function isSemanticToken(token) {
|
|
23
|
+
return token.filePath.includes("semantic/");
|
|
24
|
+
}
|
|
25
|
+
function isGlobalColorToken(token) {
|
|
26
|
+
return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
|
|
27
|
+
}
|
|
28
|
+
function isColorCategoryToken(token, category) {
|
|
29
|
+
if (!category) {
|
|
30
|
+
return ["main", "support"].some((c) => isColorCategoryToken(token, c));
|
|
31
|
+
}
|
|
32
|
+
return R.startsWith(["color", category], token.path);
|
|
33
|
+
}
|
|
34
|
+
const mkdir = async (dir, dry) => {
|
|
35
|
+
if (dry) {
|
|
36
|
+
console.log(`${chalk.blue("mkdir")} ${dir}`);
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
return await fs.mkdir(dir, { recursive: true });
|
|
40
|
+
};
|
|
41
|
+
const writeFile = async (path, data, dry) => {
|
|
42
|
+
if (dry) {
|
|
43
|
+
console.log(`${chalk.blue("writeFile")} ${path}`);
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
return await fs.writeFile(path, data, { encoding: "utf-8" });
|
|
47
|
+
};
|
|
48
|
+
const cp = async (src, dest, dry) => {
|
|
49
|
+
if (dry) {
|
|
50
|
+
console.log(`${chalk.blue("cp")} ${src} ${dest}`);
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
return await fs.cp(src, dest, { recursive: true });
|
|
54
|
+
};
|
|
55
|
+
const copyFile = async (src, dest, dry) => {
|
|
56
|
+
if (dry) {
|
|
57
|
+
console.log(`${chalk.blue("copyFile")} ${src} to ${dest}`);
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
return await fs.copyFile(src, dest);
|
|
61
|
+
};
|
|
62
|
+
const isDigit = (s) => /^\d+$/.test(s);
|
|
63
|
+
const cleanDir = async (dir, dry) => {
|
|
64
|
+
if (dry) {
|
|
65
|
+
console.log(`${chalk.blue("cleanDir")} ${dir}`);
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
console.log(`${chalk.red(`Cleaning outputDir: ${dir.trim()}`)} `);
|
|
69
|
+
return await fs.rm(dir, { recursive: true, force: true });
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
cleanDir,
|
|
73
|
+
copyFile,
|
|
74
|
+
cp,
|
|
75
|
+
getType,
|
|
76
|
+
getValue,
|
|
77
|
+
isColorCategoryToken,
|
|
78
|
+
isDigit,
|
|
79
|
+
isGlobalColorToken,
|
|
80
|
+
isSemanticToken,
|
|
81
|
+
mkdir,
|
|
82
|
+
pathStartsWithOneOf,
|
|
83
|
+
typeEquals,
|
|
84
|
+
writeFile
|
|
85
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ColorScheme } from '../../colors/types.js';
|
|
2
|
+
import type { Colors } from '../types.js';
|
|
3
|
+
type ColorSchemes = Array<ColorScheme>;
|
|
4
|
+
type Metadata = {
|
|
5
|
+
tokenSetOrder: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function generateMetadataJson(schemes: ColorSchemes, themes: string[], colors: Colors): Metadata;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=generate$metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate$metadata.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,QAAQ,GAAG;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAwBtG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function generateMetadataJson(schemes, themes, colors) {
|
|
2
|
+
return {
|
|
3
|
+
tokenSetOrder: [
|
|
4
|
+
"primitives/globals",
|
|
5
|
+
"primitives/modes/size/small",
|
|
6
|
+
"primitives/modes/size/medium",
|
|
7
|
+
"primitives/modes/size/large",
|
|
8
|
+
"primitives/modes/size/global",
|
|
9
|
+
"primitives/modes/typography/size/small",
|
|
10
|
+
"primitives/modes/typography/size/medium",
|
|
11
|
+
"primitives/modes/typography/size/large",
|
|
12
|
+
...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
|
|
13
|
+
...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
|
|
14
|
+
...schemes.flatMap((scheme) => [
|
|
15
|
+
`primitives/modes/color-scheme/${scheme}/global`,
|
|
16
|
+
...themes.map((theme) => `primitives/modes/color-scheme/${scheme}/${theme}`)
|
|
17
|
+
]),
|
|
18
|
+
...themes.map((theme) => `themes/${theme}`),
|
|
19
|
+
"semantic/color",
|
|
20
|
+
...Object.entries(colors.main).map(([color]) => `semantic/modes/main-color/${color}`),
|
|
21
|
+
...Object.entries(colors.support).map(([color]) => `semantic/modes/support-color/${color}`),
|
|
22
|
+
"semantic/style"
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
generateMetadataJson
|
|
28
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ThemeObject } from '@tokens-studio/types';
|
|
2
|
+
import type { ColorScheme } from '../../colors/types.js';
|
|
3
|
+
import type { Colors } from '../types.js';
|
|
4
|
+
type ColorSchemes = Array<ColorScheme>;
|
|
5
|
+
type ThemeObject_ = ThemeObject & {
|
|
6
|
+
$figmaCollectionId?: string;
|
|
7
|
+
$figmaModeId?: string;
|
|
8
|
+
$figmaVariableReferences?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
export declare function generateThemesJson(colorSchemes: ColorSchemes, themes: string[], colors: Colors): ThemeObject_[];
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=generate$themes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate$themes.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$themes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,YAAY,GAAG,WAAW,GAAG;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnD,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAU/G"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { TokenSetStatus } from "@tokens-studio/types";
|
|
3
|
+
const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
4
|
+
const createHash = (text) => crypto.hash("sha1", text);
|
|
5
|
+
function generateThemesJson(colorSchemes, themes, colors) {
|
|
6
|
+
return [
|
|
7
|
+
...generateSizeGroup(),
|
|
8
|
+
...generateThemesGroup(themes),
|
|
9
|
+
...generateTypographyGroup(themes),
|
|
10
|
+
...generateColorSchemesGroup(colorSchemes, themes),
|
|
11
|
+
generateSemanticGroup(),
|
|
12
|
+
...generateColorGroup("main", colors),
|
|
13
|
+
...generateColorGroup("support", colors)
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
function generateSizeGroup() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
id: "8b2c8cc86611a34b135cb22948666779361fd729",
|
|
20
|
+
name: "medium",
|
|
21
|
+
$figmaStyleReferences: {},
|
|
22
|
+
selectedTokenSets: {
|
|
23
|
+
"primitives/modes/size/medium": TokenSetStatus.SOURCE,
|
|
24
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
25
|
+
"primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
|
|
26
|
+
},
|
|
27
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
28
|
+
$figmaModeId: "41630:1",
|
|
29
|
+
group: "Size"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
|
|
33
|
+
name: "large",
|
|
34
|
+
$figmaStyleReferences: {},
|
|
35
|
+
selectedTokenSets: {
|
|
36
|
+
"primitives/modes/size/large": TokenSetStatus.SOURCE,
|
|
37
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
38
|
+
"primitives/modes/typography/size/large": TokenSetStatus.ENABLED
|
|
39
|
+
},
|
|
40
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
41
|
+
$figmaModeId: "41630:2",
|
|
42
|
+
group: "Size"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "fb11567729c298ca37c9da4e3a27716a23480824",
|
|
46
|
+
name: "small",
|
|
47
|
+
$figmaStyleReferences: {},
|
|
48
|
+
selectedTokenSets: {
|
|
49
|
+
"primitives/modes/size/small": TokenSetStatus.SOURCE,
|
|
50
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
51
|
+
"primitives/modes/typography/size/small": TokenSetStatus.ENABLED
|
|
52
|
+
},
|
|
53
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
54
|
+
$figmaModeId: "41630:3",
|
|
55
|
+
group: "Size"
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
const colorSchemeDefaults = {
|
|
60
|
+
light: {
|
|
61
|
+
name: "Light",
|
|
62
|
+
selectedTokenSets: {},
|
|
63
|
+
id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
|
|
64
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
65
|
+
$figmaModeId: "34811:0"
|
|
66
|
+
},
|
|
67
|
+
dark: {
|
|
68
|
+
name: "Dark",
|
|
69
|
+
selectedTokenSets: {},
|
|
70
|
+
id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
|
|
71
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
72
|
+
$figmaModeId: "34811:1"
|
|
73
|
+
},
|
|
74
|
+
contrast: {
|
|
75
|
+
name: "Contrast",
|
|
76
|
+
selectedTokenSets: {},
|
|
77
|
+
id: "9ebd8aed52afbffc17e2666e8b4653a53498b123",
|
|
78
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
79
|
+
$figmaModeId: "34811:2"
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function generateColorSchemesGroup(colorSchemes, themes) {
|
|
83
|
+
return colorSchemes.map(
|
|
84
|
+
(scheme) => ({
|
|
85
|
+
...colorSchemeDefaults[scheme],
|
|
86
|
+
selectedTokenSets: Object.fromEntries([
|
|
87
|
+
[`primitives/modes/color-scheme/${scheme}/global`, TokenSetStatus.ENABLED],
|
|
88
|
+
...themes.map((theme) => [`primitives/modes/color-scheme/${scheme}/${theme}`, TokenSetStatus.ENABLED])
|
|
89
|
+
]),
|
|
90
|
+
group: "Color scheme"
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
function generateThemesGroup(themes) {
|
|
95
|
+
return themes.map(
|
|
96
|
+
(theme, index) => ({
|
|
97
|
+
id: createHash(theme),
|
|
98
|
+
$figmaCollectionId: "VariableCollectionId:36528:61712",
|
|
99
|
+
$figmaModeId: `40960:${index + 6}`,
|
|
100
|
+
// Start on 6 in Token Studio and Community file for some reason
|
|
101
|
+
name: theme,
|
|
102
|
+
selectedTokenSets: {
|
|
103
|
+
[`themes/${theme}`]: TokenSetStatus.ENABLED
|
|
104
|
+
},
|
|
105
|
+
group: "Theme"
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function generateSemanticGroup() {
|
|
110
|
+
return {
|
|
111
|
+
id: "541629445ef90ad5363f9e88f52a1ccb617e6f84",
|
|
112
|
+
name: "Semantic",
|
|
113
|
+
selectedTokenSets: {
|
|
114
|
+
"semantic/style": TokenSetStatus.ENABLED,
|
|
115
|
+
"semantic/color": TokenSetStatus.ENABLED,
|
|
116
|
+
"primitives/globals": TokenSetStatus.SOURCE
|
|
117
|
+
},
|
|
118
|
+
$figmaCollectionId: "VariableCollectionId:34811:5976",
|
|
119
|
+
$figmaModeId: "34811:5",
|
|
120
|
+
group: "Semantic"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function generateColorGroup(group, colors) {
|
|
124
|
+
return Object.entries(colors[group]).map(
|
|
125
|
+
([color]) => ({
|
|
126
|
+
id: createHash(`${group}-${color}`),
|
|
127
|
+
name: color,
|
|
128
|
+
selectedTokenSets: {
|
|
129
|
+
[`semantic/modes/${group}-color/${color}`]: TokenSetStatus.ENABLED
|
|
130
|
+
},
|
|
131
|
+
group: `${capitalize(group)} color`
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function generateTypographyGroup(themes) {
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
id: "368d753fcac4455f289500eaa42e70dc0a03522f",
|
|
139
|
+
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
140
|
+
$figmaModeId: "36248:2",
|
|
141
|
+
name: "Primary",
|
|
142
|
+
selectedTokenSets: Object.fromEntries(
|
|
143
|
+
themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
|
|
144
|
+
),
|
|
145
|
+
group: "Typography"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
|
|
149
|
+
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
150
|
+
$figmaModeId: "36248:3",
|
|
151
|
+
name: "Secondary",
|
|
152
|
+
selectedTokenSets: Object.fromEntries(
|
|
153
|
+
themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
|
|
154
|
+
),
|
|
155
|
+
group: "Typography"
|
|
156
|
+
}
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
generateThemesJson
|
|
161
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Theme, Tokens } from './types.js';
|
|
2
|
+
export declare const stringify: (data: unknown) => string;
|
|
3
|
+
type WriteTokensOptions = {
|
|
4
|
+
outDir: string;
|
|
5
|
+
tokens: Tokens;
|
|
6
|
+
theme: Theme;
|
|
7
|
+
/** Dry run, no files will be written */
|
|
8
|
+
dry?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const writeTokens: (options: WriteTokensOptions) => Promise<void>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBA4K5D,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import semanticColorBaseFile from "./design-tokens/template/semantic/color-base-file.json" with { type: "json" };
|
|
6
|
+
import customColorTemplate from "./design-tokens/template/semantic/modes/category-color/category-color-template.json" with { type: "json" };
|
|
7
|
+
import semanticColorTemplate from "./design-tokens/template/semantic/semantic-color-template.json" with { type: "json" };
|
|
8
|
+
import themeBaseFile from "./design-tokens/template/themes/theme-base-file.json" with { type: "json" };
|
|
9
|
+
import themeColorTemplate from "./design-tokens/template/themes/theme-color-template.json" with { type: "json" };
|
|
10
|
+
import { cp, mkdir, writeFile } from "./utils.js";
|
|
11
|
+
import { generateMetadataJson } from "./write/generate$metadata.js";
|
|
12
|
+
import { generateThemesJson } from "./write/generate$themes.js";
|
|
13
|
+
const DIRNAME = import.meta.dirname || __dirname;
|
|
14
|
+
const DEFAULT_FILES_PATH = path.join(DIRNAME, "./design-tokens/default");
|
|
15
|
+
const TEMPLATE_FILES_PATH = path.join(DIRNAME, "./design-tokens/template/");
|
|
16
|
+
const stringify = (data) => JSON.stringify(data, null, 2);
|
|
17
|
+
const generateColorSchemeFile = (scheme, name, tokens, outPath) => {
|
|
18
|
+
const path2 = `${outPath}/primitives/modes/color-scheme/${scheme}`;
|
|
19
|
+
return {
|
|
20
|
+
data: stringify(tokens),
|
|
21
|
+
path: path2,
|
|
22
|
+
filePath: `${path2}/${name}.json`
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const generateTypographyFile = (folder, name, tokens, outPath) => {
|
|
26
|
+
const path2 = `${outPath}/primitives/modes/typography/${folder}`;
|
|
27
|
+
return {
|
|
28
|
+
data: stringify(tokens),
|
|
29
|
+
path: path2,
|
|
30
|
+
filePath: `${path2}/${name}.json`
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const writeTokens = async (options) => {
|
|
34
|
+
const {
|
|
35
|
+
outDir,
|
|
36
|
+
tokens,
|
|
37
|
+
theme: { name: themeName, colors, borderRadius },
|
|
38
|
+
dry
|
|
39
|
+
} = options;
|
|
40
|
+
const targetDir = path.resolve(process.cwd(), String(outDir));
|
|
41
|
+
const $themesPath = path.join(targetDir, "$themes.json");
|
|
42
|
+
const $metadataPath = path.join(targetDir, "$metadata.json");
|
|
43
|
+
let themes = [themeName];
|
|
44
|
+
await mkdir(targetDir, dry);
|
|
45
|
+
try {
|
|
46
|
+
const $themes = await fs.readFile($themesPath, "utf-8");
|
|
47
|
+
const themeObjects = JSON.parse($themes) || [];
|
|
48
|
+
themes = R.pipe(
|
|
49
|
+
R.filter((obj) => R.toLower(obj.group || "") === "theme"),
|
|
50
|
+
R.map(R.prop("name")),
|
|
51
|
+
R.append(themeName),
|
|
52
|
+
R.uniq
|
|
53
|
+
)(themeObjects);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
}
|
|
56
|
+
console.log(`Themes: ${chalk.blue(themes.join(", "))}`);
|
|
57
|
+
const $theme = generateThemesJson(["dark", "light"], themes, colors);
|
|
58
|
+
const $metadata = generateMetadataJson(["dark", "light"], themes, colors);
|
|
59
|
+
await writeFile($themesPath, stringify($theme), dry);
|
|
60
|
+
await writeFile($metadataPath, stringify($metadata), dry);
|
|
61
|
+
await cp(DEFAULT_FILES_PATH, targetDir, dry);
|
|
62
|
+
const mainColorNames = Object.keys(colors.main);
|
|
63
|
+
const supportColorNames = Object.keys(colors.support);
|
|
64
|
+
const customColors = [...mainColorNames, "neutral", ...supportColorNames];
|
|
65
|
+
const defaultAccentColor = mainColorNames[0];
|
|
66
|
+
for (const [colorCategory, colorNames] of [
|
|
67
|
+
["main", mainColorNames],
|
|
68
|
+
["support", supportColorNames]
|
|
69
|
+
]) {
|
|
70
|
+
const colorCategoryPath = path.join(targetDir, "semantic", "modes", `${colorCategory}-color`);
|
|
71
|
+
await mkdir(colorCategoryPath, dry);
|
|
72
|
+
for (const colorName of colorNames) {
|
|
73
|
+
const customColorFile = {
|
|
74
|
+
color: {
|
|
75
|
+
[colorCategory]: customColorTemplate
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
await writeFile(
|
|
79
|
+
path.join(colorCategoryPath, `${colorName}.json`),
|
|
80
|
+
JSON.stringify(
|
|
81
|
+
customColorFile,
|
|
82
|
+
(key, value) => {
|
|
83
|
+
if (key === "$value") {
|
|
84
|
+
return value.replace("<color>", colorName);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
},
|
|
88
|
+
2
|
|
89
|
+
),
|
|
90
|
+
dry
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const semanticColorTokens = customColors.map(
|
|
95
|
+
(colorName) => [
|
|
96
|
+
colorName,
|
|
97
|
+
R.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), semanticColorTemplate)
|
|
98
|
+
]
|
|
99
|
+
);
|
|
100
|
+
const semanticColors = {
|
|
101
|
+
color: {
|
|
102
|
+
...Object.fromEntries(semanticColorTokens),
|
|
103
|
+
...semanticColorBaseFile.color
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
await writeFile(
|
|
107
|
+
path.join(targetDir, `semantic/color.json`),
|
|
108
|
+
JSON.stringify(
|
|
109
|
+
semanticColors,
|
|
110
|
+
(key, value) => {
|
|
111
|
+
if (key === "$value") {
|
|
112
|
+
return value.replace("<accent-color>", defaultAccentColor);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
},
|
|
116
|
+
2
|
|
117
|
+
),
|
|
118
|
+
dry
|
|
119
|
+
);
|
|
120
|
+
await mkdir(path.join(targetDir, "themes"), dry);
|
|
121
|
+
const themeColorTokens = Object.fromEntries(
|
|
122
|
+
customColors.map(
|
|
123
|
+
(colorName) => [
|
|
124
|
+
colorName,
|
|
125
|
+
R.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), themeColorTemplate)
|
|
126
|
+
]
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
const { color: themeBaseFileColor, ...remainingThemeFile } = themeBaseFile;
|
|
130
|
+
const themeFile = {
|
|
131
|
+
color: {
|
|
132
|
+
...themeColorTokens,
|
|
133
|
+
...themeBaseFileColor
|
|
134
|
+
},
|
|
135
|
+
...remainingThemeFile
|
|
136
|
+
};
|
|
137
|
+
const baseBorderRadius = R.lensPath(["border-radius", "base", "$value"]);
|
|
138
|
+
const updatedThemeFile = R.set(baseBorderRadius, String(borderRadius), themeFile);
|
|
139
|
+
await writeFile(
|
|
140
|
+
path.join(targetDir, `themes/${themeName}.json`),
|
|
141
|
+
JSON.stringify(
|
|
142
|
+
updatedThemeFile,
|
|
143
|
+
(key, value) => {
|
|
144
|
+
if (key === "$value") {
|
|
145
|
+
return value.replace("<theme>", themeName);
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
},
|
|
149
|
+
2
|
|
150
|
+
),
|
|
151
|
+
dry
|
|
152
|
+
);
|
|
153
|
+
const files = [
|
|
154
|
+
generateColorSchemeFile("light", themeName, tokens.colors.light[themeName], targetDir),
|
|
155
|
+
generateColorSchemeFile("light", "global", tokens.colors.light.global, targetDir),
|
|
156
|
+
generateColorSchemeFile("dark", themeName, tokens.colors.dark[themeName], targetDir),
|
|
157
|
+
generateColorSchemeFile("dark", "global", tokens.colors.dark.global, targetDir),
|
|
158
|
+
// generateColorSchemeFile('contrast', themeName, tokens.colors.contrast[themeName], targetDir),
|
|
159
|
+
// generateColorSchemeFile('contrast', 'global', tokens.colors.contrast.global, targetDir),
|
|
160
|
+
generateTypographyFile("primary", themeName, tokens.typography.primary, targetDir),
|
|
161
|
+
generateTypographyFile("secondary", themeName, tokens.typography.primary, targetDir)
|
|
162
|
+
];
|
|
163
|
+
for (const file of files) {
|
|
164
|
+
const dirPath = path.resolve(file.path);
|
|
165
|
+
const filePath = path.resolve(file.filePath);
|
|
166
|
+
await mkdir(dirPath, dry);
|
|
167
|
+
await writeFile(filePath, file.data, dry);
|
|
168
|
+
}
|
|
169
|
+
console.log(
|
|
170
|
+
`Finished creating Designsystem design tokens in ${chalk.green(outDir)} for theme ${chalk.blue(themeName)}`
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
export {
|
|
174
|
+
stringify,
|
|
175
|
+
writeTokens
|
|
176
|
+
};
|