@digdir/designsystemet 0.0.0-deps-tsdown-20260421103939
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/LICENSE +7 -0
- package/README.md +115 -0
- package/configs/test-tokens.config.json +82 -0
- package/dist/bin/config.d.ts +12 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +58 -0
- package/dist/bin/designsystemet.d.ts +3 -0
- package/dist/bin/designsystemet.d.ts.map +1 -0
- package/dist/bin/designsystemet.js +156 -0
- package/dist/bin/options.d.ts +21 -0
- package/dist/bin/options.d.ts.map +1 -0
- package/dist/bin/options.js +23 -0
- package/dist/config.schema.json +209 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
- package/dist/package.js +5 -0
- package/dist/src/colors/colorMetadata.d.ts +56 -0
- package/dist/src/colors/colorMetadata.d.ts.map +1 -0
- package/dist/src/colors/colorMetadata.js +259 -0
- package/dist/src/colors/index.d.ts +5 -0
- package/dist/src/colors/index.d.ts.map +1 -0
- package/dist/src/colors/index.js +5 -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 +111 -0
- package/dist/src/colors/types.d.ts +69 -0
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/src/colors/types.js +24 -0
- package/dist/src/colors/utils.d.ts +128 -0
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +244 -0
- package/dist/src/config.d.ts +181 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +118 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/migrations/beta-to-v1.d.ts +3 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +340 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts +6 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.js +35 -0
- package/dist/src/migrations/codemods/css/run.d.ts +8 -0
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.js +23 -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 +46 -0
- package/dist/src/migrations/index.d.ts +6 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/index.js +9 -0
- package/dist/src/scripts/createJsonSchema.d.ts +2 -0
- package/dist/src/scripts/createJsonSchema.d.ts.map +1 -0
- package/dist/src/scripts/update-preview-tokens.d.ts +3 -0
- package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -0
- package/dist/src/tokens/build.d.ts +4 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +41 -0
- package/dist/src/tokens/create/files.d.ts +11 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/files.js +44 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +10 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.js +19 -0
- package/dist/src/tokens/create/generators/$themes.d.ts +27 -0
- package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$themes.js +158 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +5 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.js +71 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts +3 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.js +142 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts +4 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.js +147 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts +4 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.js +216 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.d.ts +8 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.js +26 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts +5 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.js +46 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts +3 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.js +381 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts +3 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.js +112 -0
- package/dist/src/tokens/create.d.ts +21 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +47 -0
- package/dist/src/tokens/format.d.ts +15 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +41 -0
- package/dist/src/tokens/generate-config.d.ts +10 -0
- package/dist/src/tokens/generate-config.d.ts.map +1 -0
- package/dist/src/tokens/generate-config.js +178 -0
- package/dist/src/tokens/index.d.ts +4 -0
- package/dist/src/tokens/index.d.ts.map +1 -0
- package/dist/src/tokens/index.js +3 -0
- package/dist/src/tokens/process/configs/color.d.ts +12 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +51 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +47 -0
- package/dist/src/tokens/process/configs/shared.d.ts +10 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +19 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts +3 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.js +28 -0
- package/dist/src/tokens/process/configs/size.d.ts +3 -0
- package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size.js +34 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.js +49 -0
- package/dist/src/tokens/process/configs/typography.d.ts +3 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +64 -0
- package/dist/src/tokens/process/configs.d.ts +20 -0
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +90 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +63 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +29 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size-mode.js +50 -0
- package/dist/src/tokens/process/formats/css/size.d.ts +21 -0
- package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size.js +93 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/type-scale.js +55 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +29 -0
- package/dist/src/tokens/process/formats/css.d.ts +11 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css.js +18 -0
- package/dist/src/tokens/process/output/declarations.d.ts +5 -0
- package/dist/src/tokens/process/output/declarations.d.ts.map +1 -0
- package/dist/src/tokens/process/output/declarations.js +38 -0
- package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +45 -0
- package/dist/src/tokens/process/output/theme.d.ts +27 -0
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/output/theme.js +83 -0
- package/dist/src/tokens/process/platform.d.ts +106 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +168 -0
- package/dist/src/tokens/process/transformers.d.ts +6 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/process/transformers.js +54 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +36 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +114 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts +5 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.js +9 -0
- package/dist/src/tokens/types.d.ts +74 -0
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/src/tokens/types.js +7 -0
- package/dist/src/tokens/utils.d.ts +63 -0
- package/dist/src/tokens/utils.d.ts.map +1 -0
- package/dist/src/tokens/utils.js +121 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils/filesystem.d.ts +40 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +115 -0
- package/package.json +87 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ThemeObject } from '@tokens-studio/types';
|
|
2
|
+
import type { ThemeDimension, ThemePermutation } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Find the theme permutations that are relevant for the given theme dimensions.
|
|
5
|
+
*
|
|
6
|
+
* Technically, for the given dimensions all permutations are included, while for other
|
|
7
|
+
* dimensions the first permutation is used.
|
|
8
|
+
*
|
|
9
|
+
* @param processed$themes Theme objects from $themes.json (Tokens Studio)
|
|
10
|
+
* @param dimensions Which theme dimensions to return permutations for.
|
|
11
|
+
* 'theme' (e.g. altinn/digdir/uutilsynet) is always implicitly included.
|
|
12
|
+
* @returns the relevant theme permutations
|
|
13
|
+
*/
|
|
14
|
+
export declare const getMultidimensionalThemes: (processed$themes: ProcessedThemeObject[], dimensions: ThemeDimension[]) => PermutatedTheme[];
|
|
15
|
+
export type PermutatedTheme = {
|
|
16
|
+
name: string;
|
|
17
|
+
selectedTokenSets: string[];
|
|
18
|
+
permutation: ThemePermutation;
|
|
19
|
+
};
|
|
20
|
+
declare const processed: unique symbol;
|
|
21
|
+
/**
|
|
22
|
+
* A Tokens Studio {@link ThemeObject} which has been processed for easier use in code
|
|
23
|
+
*/
|
|
24
|
+
export type ProcessedThemeObject = ThemeObject & {
|
|
25
|
+
[processed]: true;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Normalise theme names and theme group names for easier use in code
|
|
29
|
+
* @param theme A theme object from $themes.json
|
|
30
|
+
* @returns Processed theme object
|
|
31
|
+
*/
|
|
32
|
+
export declare function processThemeObject(theme: ThemeObject | ProcessedThemeObject): ProcessedThemeObject;
|
|
33
|
+
export type GroupedThemes = Record<keyof ThemePermutation, ProcessedThemeObject[]>;
|
|
34
|
+
export declare const getCustomColors: (processed$themes: ProcessedThemeObject[], colorGroups: (string | RegExp)[]) => string[];
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=getMultidimensionalThemes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMultidimensionalThemes.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/utils/getMultidimensionalThemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GAAI,kBAAkB,oBAAoB,EAAE,EAAE,YAAY,cAAc,EAAE,sBAe/G,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,SAAS,EAAE,OAAO,MAAsD,CAAC;AAC/E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAMvE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,oBAAoB,GAAG,oBAAoB,CAUlG;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,gBAAgB,EAAE,oBAAoB,EAAE,CAAC,CAAC;AA8FnF,eAAO,MAAM,eAAe,GAAI,kBAAkB,oBAAoB,EAAE,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,aASnF,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { TokenSetStatus } from "../../../../node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js";
|
|
2
|
+
import "../../../../node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js";
|
|
3
|
+
import { kebabCase } from "./kebab-case.js";
|
|
4
|
+
import { buildOptions } from "../platform.js";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import * as R from "ramda";
|
|
7
|
+
//#region src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
8
|
+
/**
|
|
9
|
+
* Find the theme permutations that are relevant for the given theme dimensions.
|
|
10
|
+
*
|
|
11
|
+
* Technically, for the given dimensions all permutations are included, while for other
|
|
12
|
+
* dimensions the first permutation is used.
|
|
13
|
+
*
|
|
14
|
+
* @param processed$themes Theme objects from $themes.json (Tokens Studio)
|
|
15
|
+
* @param dimensions Which theme dimensions to return permutations for.
|
|
16
|
+
* 'theme' (e.g. altinn/digdir/uutilsynet) is always implicitly included.
|
|
17
|
+
* @returns the relevant theme permutations
|
|
18
|
+
*/
|
|
19
|
+
const getMultidimensionalThemes = (processed$themes, dimensions) => {
|
|
20
|
+
const verboseLogging = buildOptions?.verbose;
|
|
21
|
+
const grouped$themes = groupThemes(processed$themes);
|
|
22
|
+
const permutations = permutateThemes(grouped$themes);
|
|
23
|
+
const ALL_DEPENDENT_ON = ["theme"];
|
|
24
|
+
const nonDependentKeys = R.keys(grouped$themes).filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
|
|
25
|
+
if (verboseLogging) {
|
|
26
|
+
console.log(pc.cyan(`🔎 Finding theme permutations for ${dimensions}`));
|
|
27
|
+
console.log(pc.cyan(` (ignoring permutations for ${nonDependentKeys})`));
|
|
28
|
+
}
|
|
29
|
+
return permutations.filter((val) => {
|
|
30
|
+
return nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name).every((x) => x);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const processed = Symbol("Type brand for ProcessedThemeObject");
|
|
34
|
+
function isProcessed(theme) {
|
|
35
|
+
return Boolean(theme[processed]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Normalise theme names and theme group names for easier use in code
|
|
39
|
+
* @param theme A theme object from $themes.json
|
|
40
|
+
* @returns Processed theme object
|
|
41
|
+
*/
|
|
42
|
+
function processThemeObject(theme) {
|
|
43
|
+
if (isProcessed(theme)) return theme;
|
|
44
|
+
const result = {
|
|
45
|
+
...theme,
|
|
46
|
+
[processed]: true
|
|
47
|
+
};
|
|
48
|
+
if (result.group) result.group = kebabCase(result.group);
|
|
49
|
+
result.name = kebabCase(result.name);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function groupThemes(themes) {
|
|
53
|
+
const groups = {};
|
|
54
|
+
for (const theme of themes) if (theme.group) {
|
|
55
|
+
const groupKey = theme.group;
|
|
56
|
+
groups[groupKey] = [...groups[groupKey] ?? [], theme];
|
|
57
|
+
} else throw new Error(`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`);
|
|
58
|
+
return groups;
|
|
59
|
+
}
|
|
60
|
+
const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
|
|
61
|
+
function permutateThemes(groups) {
|
|
62
|
+
const separator = "_";
|
|
63
|
+
return cartesian(Object.values(groups)).map((perm) => {
|
|
64
|
+
const permutatedTheme = perm.reduce((acc, theme) => {
|
|
65
|
+
const { group, name, selectedTokenSets } = theme;
|
|
66
|
+
let updatedPermutation = acc.permutation;
|
|
67
|
+
if (group) {
|
|
68
|
+
const groupProp = R.lensProp(group);
|
|
69
|
+
updatedPermutation = R.set(groupProp, name, updatedPermutation);
|
|
70
|
+
}
|
|
71
|
+
const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
|
|
72
|
+
const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|
|
73
|
+
return {
|
|
74
|
+
permutation: updatedPermutation,
|
|
75
|
+
name: updatedName,
|
|
76
|
+
selectedTokenSets: sets
|
|
77
|
+
};
|
|
78
|
+
}, {
|
|
79
|
+
name: "",
|
|
80
|
+
selectedTokenSets: [],
|
|
81
|
+
permutation: {
|
|
82
|
+
"color-scheme": "unknown",
|
|
83
|
+
"main-color": "unknown",
|
|
84
|
+
"support-color": "unknown",
|
|
85
|
+
theme: "unknown",
|
|
86
|
+
semantic: "unknown",
|
|
87
|
+
size: "unknown",
|
|
88
|
+
typography: "unknown"
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (hasUnknownProps(permutatedTheme)) throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
|
|
92
|
+
const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
|
|
93
|
+
return {
|
|
94
|
+
...permutatedTheme,
|
|
95
|
+
selectedTokenSets: Array.from(uniqueTokenSets)
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function filterTokenSets(tokensets) {
|
|
100
|
+
return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
|
|
101
|
+
if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) return -1;
|
|
102
|
+
if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) return 1;
|
|
103
|
+
return 0;
|
|
104
|
+
}).map((entry) => entry[0]);
|
|
105
|
+
}
|
|
106
|
+
function cartesian(a) {
|
|
107
|
+
return a.reduce((a, b) => a.flatMap((d) => b.map((e) => [d, e].flat())));
|
|
108
|
+
}
|
|
109
|
+
const getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
|
|
110
|
+
if (!x.group) return false;
|
|
111
|
+
return colorGroups.includes(x.group);
|
|
112
|
+
}).map((x) => x.name);
|
|
113
|
+
//#endregion
|
|
114
|
+
export { getCustomColors, getMultidimensionalThemes, processThemeObject };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kebab-case.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/utils/kebab-case.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK7C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/tokens/process/utils/kebab-case.ts
|
|
2
|
+
/**
|
|
3
|
+
* Function to convert a string to kebab-case.
|
|
4
|
+
*/
|
|
5
|
+
function kebabCase(str) {
|
|
6
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { kebabCase };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Config as SDConfig } from 'style-dictionary/types';
|
|
2
|
+
import type { ConfigSchemaTheme } from '../config.js';
|
|
3
|
+
import type { GetStyleDictionaryConfig } from './process/configs/shared.js';
|
|
4
|
+
export type Token = {
|
|
5
|
+
$value: string | Record<string, string>[];
|
|
6
|
+
$type: string;
|
|
7
|
+
} | {
|
|
8
|
+
$type: 'boxShadow';
|
|
9
|
+
$value: Record<'x' | 'y' | 'blur' | 'spread' | 'color', string>[];
|
|
10
|
+
} | {
|
|
11
|
+
$type: 'typography';
|
|
12
|
+
$value: Record<'fontFamily' | 'fontWeight' | 'lineHeight' | 'fontSize' | 'letterSpacing', string>;
|
|
13
|
+
};
|
|
14
|
+
export type TokenSet = {
|
|
15
|
+
[key: string]: Token | TokenSet;
|
|
16
|
+
};
|
|
17
|
+
export type TokenSets = Map<string, TokenSet>;
|
|
18
|
+
export type Colors = Theme['colors'];
|
|
19
|
+
export type Typography = Theme['typography'];
|
|
20
|
+
export type Theme = {
|
|
21
|
+
name: string;
|
|
22
|
+
} & Required<Omit<ConfigSchemaTheme, 'overrides'>> & Pick<ConfigSchemaTheme, 'overrides'>;
|
|
23
|
+
export declare const colorCategories: {
|
|
24
|
+
readonly main: "main";
|
|
25
|
+
readonly support: "support";
|
|
26
|
+
};
|
|
27
|
+
export type ColorCategories = keyof typeof colorCategories;
|
|
28
|
+
export type BuiltInColors = 'neutral' | 'success' | 'warning' | 'danger' | 'info';
|
|
29
|
+
export type SizeModes = 'small' | 'medium' | 'large';
|
|
30
|
+
/**
|
|
31
|
+
* A multi-dimensional theme is a concrete permutation of the possible theme dimensions
|
|
32
|
+
*/
|
|
33
|
+
export type ThemePermutation = {
|
|
34
|
+
'color-scheme': string;
|
|
35
|
+
'main-color': string;
|
|
36
|
+
'support-color'?: string;
|
|
37
|
+
semantic: string;
|
|
38
|
+
size: string;
|
|
39
|
+
theme: string;
|
|
40
|
+
typography: string;
|
|
41
|
+
};
|
|
42
|
+
export type ThemeDimension = keyof ThemePermutation;
|
|
43
|
+
export type GetSDConfigOptions = {
|
|
44
|
+
tokensDir?: string;
|
|
45
|
+
dry?: boolean;
|
|
46
|
+
tokenSets?: TokenSets;
|
|
47
|
+
};
|
|
48
|
+
export type BuildConfig = {
|
|
49
|
+
/** Optional name of the build config - only used in the console output */
|
|
50
|
+
name?: string;
|
|
51
|
+
/** Style Dictionary configuration creator */
|
|
52
|
+
getConfig: GetStyleDictionaryConfig;
|
|
53
|
+
/** Which theme dimensions to include. `theme` (e.g. digdir/altinn) is always included. */
|
|
54
|
+
dimensions: ThemeDimension[];
|
|
55
|
+
/** Whether the build config is enabled. @default () => true */
|
|
56
|
+
enabled?: () => boolean;
|
|
57
|
+
/** Custom log message. */
|
|
58
|
+
log?: (config: SDConfigForThemePermutation) => string;
|
|
59
|
+
};
|
|
60
|
+
export type SDConfigForThemePermutation = {
|
|
61
|
+
permutation: ThemePermutation;
|
|
62
|
+
config: SDConfig;
|
|
63
|
+
};
|
|
64
|
+
/** This type is taken from Style Dictionary `formatPlatform`.
|
|
65
|
+
* Metadata for a file output */
|
|
66
|
+
export type OutputFile = {
|
|
67
|
+
output: string;
|
|
68
|
+
destination: string;
|
|
69
|
+
};
|
|
70
|
+
export type DesignsystemetObject = {
|
|
71
|
+
name: string;
|
|
72
|
+
version: string;
|
|
73
|
+
};
|
|
74
|
+
//# 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,MAAM,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,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
|
2
|
+
import type { DesignToken, TransformedToken } from 'style-dictionary/types';
|
|
3
|
+
import { type ColorCategories, type TokenSet } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
6
|
+
* @param token Transformed token
|
|
7
|
+
* @returns type
|
|
8
|
+
*/
|
|
9
|
+
export declare const getType: (token: TransformedToken) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
12
|
+
*
|
|
13
|
+
* Use generic (`<T>`) to define return value type
|
|
14
|
+
* @param token Transformed or Design token
|
|
15
|
+
* @returns value
|
|
16
|
+
*/
|
|
17
|
+
export declare const getValue: <T>(token: TransformedToken | DesignToken) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Check if token type matches provided type
|
|
20
|
+
* This function is curried
|
|
21
|
+
* @param types Type or array of types to check against
|
|
22
|
+
* @param token Transformed token
|
|
23
|
+
* @returns boolean
|
|
24
|
+
*/
|
|
25
|
+
export declare const typeEquals: (types: string[] | string, token: TransformedToken) => boolean;
|
|
26
|
+
export declare const pathStartsWithOneOf: ((paths: (string | string[])[], token: TransformedToken) => boolean) & ((paths: (string | string[])[]) => (token: TransformedToken) => boolean);
|
|
27
|
+
export declare function isSemanticToken(token: TransformedToken): boolean;
|
|
28
|
+
export declare function isSemanticColorToken(token: TransformedToken, color: string): boolean;
|
|
29
|
+
export declare function isGlobalColorToken(token: TransformedToken): boolean;
|
|
30
|
+
export declare function isColorCategoryToken(token: TransformedToken, category?: ColorCategories): boolean;
|
|
31
|
+
export declare const isDigit: (s: string) => boolean;
|
|
32
|
+
/** Copied from Style Dictionary and added types
|
|
33
|
+
@see https://github.com/amzn/style-dictionary/blob/31c29df0382a61b085f6392dc3225c5009fbffc5/lib/utils/combineJSON.js#L33 */
|
|
34
|
+
export declare function traverseObj(obj: Tokens | TokenSet, fn: (obj: TokenSet | Tokens | DesignToken, key: keyof Tokens | string, slice: Tokens | DesignToken | string) => void): import("style-dictionary/types").DesignTokens | TokenSet;
|
|
35
|
+
/**
|
|
36
|
+
* In the given tokens array, inline and remove tokens that match the predicate
|
|
37
|
+
*
|
|
38
|
+
* Example: In pseudo-code, given the predicate `(token) => token.path === ['size', '1']` and the following tokens
|
|
39
|
+
* ```js
|
|
40
|
+
* [
|
|
41
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
42
|
+
* { path: ['size', '1'], original: { $value: '{size.base} * 2' } },
|
|
43
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.1}, 12px)' } }
|
|
44
|
+
* ]
|
|
45
|
+
* ```
|
|
46
|
+
* would return
|
|
47
|
+
* ```js
|
|
48
|
+
* [
|
|
49
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
50
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.base} * 2, 12px)' } }
|
|
51
|
+
* ]
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param shouldInline - predicate to determine if token should be inlined
|
|
55
|
+
* @param tokens - array of tokens to transform
|
|
56
|
+
* @returns copy of `tokens` without those that matched the predicate,
|
|
57
|
+
* where references to the matching tokens have been inlined
|
|
58
|
+
*/
|
|
59
|
+
export declare function inlineTokens(shouldInline: (t: TransformedToken) => boolean, tokens: TransformedToken[]): TransformedToken[];
|
|
60
|
+
export declare function shortSizeName(size: string): string;
|
|
61
|
+
export declare const sizeComparator: (size: string) => number;
|
|
62
|
+
export declare function orderBySize(sizes: string[]): string[];
|
|
63
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tokens/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,O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AAE,MAAM,GAAG,WAAW,GAAG,MAAM,KAAK,IAAI,4DAYrH;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,sBAetG;AAUD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,MAG7C,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAErD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { colorCategories } from "./types.js";
|
|
2
|
+
import * as R from "ramda";
|
|
3
|
+
//#region src/tokens/utils.ts
|
|
4
|
+
const mapToLowerCase = R.map(R.toLower);
|
|
5
|
+
const hasAnyTruth = R.any(R.equals(true));
|
|
6
|
+
/**
|
|
7
|
+
* Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
8
|
+
* @param token Transformed token
|
|
9
|
+
* @returns type
|
|
10
|
+
*/
|
|
11
|
+
const getType = (token) => (token.$type ?? token.type) || "";
|
|
12
|
+
/**
|
|
13
|
+
* Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
14
|
+
*
|
|
15
|
+
* Use generic (`<T>`) to define return value type
|
|
16
|
+
* @param token Transformed or Design token
|
|
17
|
+
* @returns value
|
|
18
|
+
*/
|
|
19
|
+
const getValue = (token) => token.$value ?? token.value;
|
|
20
|
+
/**
|
|
21
|
+
* Check if token type matches provided type
|
|
22
|
+
* This function is curried
|
|
23
|
+
* @param types Type or array of types to check against
|
|
24
|
+
* @param token Transformed token
|
|
25
|
+
* @returns boolean
|
|
26
|
+
*/
|
|
27
|
+
const typeEquals = R.curry((types, token) => {
|
|
28
|
+
if (R.isNil(token)) return false;
|
|
29
|
+
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
30
|
+
});
|
|
31
|
+
const pathStartsWithOneOf = R.curry((paths, token) => {
|
|
32
|
+
if (R.isNil(token)) return false;
|
|
33
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
34
|
+
return hasAnyTruth(R.map((pathOrString) => {
|
|
35
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
36
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
37
|
+
}, paths));
|
|
38
|
+
});
|
|
39
|
+
function isSemanticToken(token) {
|
|
40
|
+
return token.filePath.includes("semantic/");
|
|
41
|
+
}
|
|
42
|
+
function isSemanticColorToken(token, color) {
|
|
43
|
+
return token.filePath.includes("semantic/") && R.startsWith(["color", color], token.path);
|
|
44
|
+
}
|
|
45
|
+
function isGlobalColorToken(token) {
|
|
46
|
+
return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
|
|
47
|
+
}
|
|
48
|
+
function isColorCategoryToken(token, category) {
|
|
49
|
+
if (!category) return Object.keys(colorCategories).some((colorCategory) => isColorCategoryToken(token, colorCategory));
|
|
50
|
+
return R.startsWith(["color", category], token.path);
|
|
51
|
+
}
|
|
52
|
+
const isDigit = (s) => /^\d+$/.test(s);
|
|
53
|
+
/** Copied from Style Dictionary and added types
|
|
54
|
+
@see https://github.com/amzn/style-dictionary/blob/31c29df0382a61b085f6392dc3225c5009fbffc5/lib/utils/combineJSON.js#L33 */
|
|
55
|
+
function traverseObj(obj, fn) {
|
|
56
|
+
for (const key in obj) {
|
|
57
|
+
const prop = obj[key];
|
|
58
|
+
if (prop != null) {
|
|
59
|
+
fn.apply(null, [
|
|
60
|
+
obj,
|
|
61
|
+
key,
|
|
62
|
+
prop
|
|
63
|
+
]);
|
|
64
|
+
if (typeof prop === "object") traverseObj(prop, fn);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* In the given tokens array, inline and remove tokens that match the predicate
|
|
71
|
+
*
|
|
72
|
+
* Example: In pseudo-code, given the predicate `(token) => token.path === ['size', '1']` and the following tokens
|
|
73
|
+
* ```js
|
|
74
|
+
* [
|
|
75
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
76
|
+
* { path: ['size', '1'], original: { $value: '{size.base} * 2' } },
|
|
77
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.1}, 12px)' } }
|
|
78
|
+
* ]
|
|
79
|
+
* ```
|
|
80
|
+
* would return
|
|
81
|
+
* ```js
|
|
82
|
+
* [
|
|
83
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
84
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.base} * 2, 12px)' } }
|
|
85
|
+
* ]
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param shouldInline - predicate to determine if token should be inlined
|
|
89
|
+
* @param tokens - array of tokens to transform
|
|
90
|
+
* @returns copy of `tokens` without those that matched the predicate,
|
|
91
|
+
* where references to the matching tokens have been inlined
|
|
92
|
+
*/
|
|
93
|
+
function inlineTokens(shouldInline, tokens) {
|
|
94
|
+
const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
|
|
95
|
+
return otherTokens.map((token) => {
|
|
96
|
+
let transformed = getValue(token.original);
|
|
97
|
+
for (const ref of inlineableTokens) {
|
|
98
|
+
const refName = ref.path.join(".");
|
|
99
|
+
if (typeof transformed === "string") transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
|
|
100
|
+
}
|
|
101
|
+
return R.set(R.lensPath(["original", "$value"]), transformed, token);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const sizeMap = {
|
|
105
|
+
xsmall: "xs",
|
|
106
|
+
small: "sm",
|
|
107
|
+
medium: "md",
|
|
108
|
+
large: "lg",
|
|
109
|
+
xlarge: "xl"
|
|
110
|
+
};
|
|
111
|
+
function shortSizeName(size) {
|
|
112
|
+
return sizeMap[size] ?? size;
|
|
113
|
+
}
|
|
114
|
+
const sizeComparator = (size) => {
|
|
115
|
+
return Object.entries(sizeMap).findIndex(([key, val]) => key === size || val === size) ?? 0;
|
|
116
|
+
};
|
|
117
|
+
function orderBySize(sizes) {
|
|
118
|
+
return R.sortBy(sizeComparator, sizes);
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { getType, getValue, inlineTokens, isColorCategoryToken, isDigit, isGlobalColorToken, isSemanticColorToken, isSemanticToken, orderBySize, pathStartsWithOneOf, shortSizeName, sizeComparator, traverseObj, typeEquals };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CopyOptions, PathLike } from 'node:fs';
|
|
2
|
+
import type { OutputFile } from '../tokens/types.js';
|
|
3
|
+
declare class FileSystem {
|
|
4
|
+
private isInitialized;
|
|
5
|
+
private dry;
|
|
6
|
+
private verbose;
|
|
7
|
+
/** Default working directory is where the process was started */
|
|
8
|
+
workingDir: string;
|
|
9
|
+
outDir: string;
|
|
10
|
+
/** Initialize the file system */
|
|
11
|
+
init({ dry, outdir, verbose }: {
|
|
12
|
+
dry?: boolean;
|
|
13
|
+
outdir?: string;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a directory if it does not already exist.
|
|
18
|
+
*
|
|
19
|
+
* @param dir - The path of the directory to create.
|
|
20
|
+
*
|
|
21
|
+
* @returns A promise that resolves when the operation is complete.
|
|
22
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
23
|
+
*/
|
|
24
|
+
mkdir: (dir: PathLike) => Promise<string | void>;
|
|
25
|
+
writeFile: (path: PathLike, data: string) => Promise<void>;
|
|
26
|
+
cp: (src: string, dest: string, filter?: CopyOptions["filter"]) => Promise<void>;
|
|
27
|
+
copyFile: (src: PathLike, dest: PathLike) => Promise<void>;
|
|
28
|
+
cleanDir: (dir: string) => Promise<void>;
|
|
29
|
+
readFile: (path: PathLike, allowFileNotFound?: boolean) => Promise<string>;
|
|
30
|
+
readdir: (path: PathLike) => Promise<string[]>;
|
|
31
|
+
writeFiles: (files: OutputFile[], outDir: string, log?: boolean) => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An abstraction of Node's file system API and helper functions for Designsystemet CLI interaction with the file system.
|
|
35
|
+
*
|
|
36
|
+
* Allows dry-running destructive operations, logging and store relevant file system state.
|
|
37
|
+
*/
|
|
38
|
+
export declare const dsfs: FileSystem;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../../src/utils/filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,cAAM,UAAU;IACd,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,iEAAiE;IACjE,UAAU,SAAiB;IAC3B,MAAM,SAAmB;IAEzB,iCAAiC;IACjC,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;IAwBpF;;;;;;;OAOG;IACH,KAAK,GAAU,KAAK,QAAQ,4BAgB1B;IAEF,SAAS,GAAU,MAAM,QAAQ,EAAE,MAAM,MAAM,mBAW7C;IAEF,EAAE,GAAU,KAAK,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,WAAW,CAAC,QAAQ,CAAC,mBAOnE;IAEF,QAAQ,GAAU,KAAK,QAAQ,EAAE,MAAM,QAAQ,mBAO7C;IAEF,QAAQ,GAAU,KAAK,MAAM,mBAS3B;IAEF,QAAQ,GAAU,MAAM,QAAQ,EAAE,oBAAoB,OAAO,qBAa3D;IACF,OAAO,GAAU,MAAM,QAAQ,uBAa7B;IACF,UAAU,GAAU,OAAO,UAAU,EAAE,EAAE,QAAQ,MAAM,EAAE,MAAM,OAAO,mBAcpE;CACH;AAED;;;;GAIG;AACH,eAAO,MAAM,IAAI,YAAmB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utils/filesystem.ts
|
|
5
|
+
var FileSystem = class {
|
|
6
|
+
isInitialized = false;
|
|
7
|
+
dry = false;
|
|
8
|
+
verbose = false;
|
|
9
|
+
/** Default working directory is where the process was started */
|
|
10
|
+
workingDir = process.cwd();
|
|
11
|
+
outDir = this.workingDir;
|
|
12
|
+
/** Initialize the file system */
|
|
13
|
+
init({ dry, outdir, verbose }) {
|
|
14
|
+
if (this.isInitialized) {
|
|
15
|
+
console.warn(pc.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (dry) console.log(pc.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
19
|
+
this.dry = dry ?? false;
|
|
20
|
+
this.verbose = verbose ?? false;
|
|
21
|
+
this.outDir = outdir ? path.isAbsolute(outdir) ? outdir : path.join(this.workingDir, outdir) : this.workingDir;
|
|
22
|
+
if (this.verbose) console.log(`FileSystem initialized with workingDir: ${pc.green(this.workingDir)}, outDir: ${pc.green(this.outDir)}`);
|
|
23
|
+
this.isInitialized = true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a directory if it does not already exist.
|
|
27
|
+
*
|
|
28
|
+
* @param dir - The path of the directory to create.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves when the operation is complete.
|
|
31
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
32
|
+
*/
|
|
33
|
+
mkdir = async (dir) => {
|
|
34
|
+
if (this.dry) {
|
|
35
|
+
console.log(`${pc.blue("mkdir")} ${dir}`);
|
|
36
|
+
return Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
if (await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false)) return Promise.resolve();
|
|
39
|
+
return fs.mkdir(dir, { recursive: true });
|
|
40
|
+
};
|
|
41
|
+
writeFile = async (path, data) => {
|
|
42
|
+
if (this.dry) {
|
|
43
|
+
console.log(`${pc.blue("writeFile")} ${path}`);
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
return fs.writeFile(path, data, { encoding: "utf-8" }).catch((error) => {
|
|
47
|
+
console.error(pc.red(`Error writing file: ${path}`));
|
|
48
|
+
console.error(pc.red(error));
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
cp = async (src, dest, filter) => {
|
|
53
|
+
if (this.dry) {
|
|
54
|
+
console.log(`${pc.blue("cp")} ${src} ${dest}`);
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
return fs.cp(src, dest, {
|
|
58
|
+
recursive: true,
|
|
59
|
+
filter
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
copyFile = async (src, dest) => {
|
|
63
|
+
if (this.dry) {
|
|
64
|
+
console.log(`${pc.blue("copyFile")} ${src} to ${dest}`);
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
return fs.copyFile(src, dest);
|
|
68
|
+
};
|
|
69
|
+
cleanDir = async (dir) => {
|
|
70
|
+
if (this.dry) {
|
|
71
|
+
console.log(`${pc.blue("cleanDir")} ${dir}`);
|
|
72
|
+
return Promise.resolve();
|
|
73
|
+
}
|
|
74
|
+
console.log(`\n🔥 Cleaning dir ${pc.red(`${dir.trim()}`)} `);
|
|
75
|
+
return fs.rm(dir, {
|
|
76
|
+
recursive: true,
|
|
77
|
+
force: true
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
readFile = async (path, allowFileNotFound) => {
|
|
81
|
+
if (this.dry) console.log(`${pc.blue("readFile")} ${path}`);
|
|
82
|
+
try {
|
|
83
|
+
return await fs.readFile(path, "utf-8");
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (allowFileNotFound && error.code === "ENOENT") return "";
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
readdir = async (path) => {
|
|
90
|
+
if (this.dry) console.log(`${pc.blue("readdir")} ${path}`);
|
|
91
|
+
try {
|
|
92
|
+
return await fs.readdir(path);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error.code === "ENOENT") return [];
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
writeFiles = async (files, outDir, log) => {
|
|
99
|
+
for (const { destination: filename, output } of files) if (filename) {
|
|
100
|
+
const filePath = path.join(outDir, filename);
|
|
101
|
+
const fileDir = path.dirname(filePath);
|
|
102
|
+
if (log) console.log(filename);
|
|
103
|
+
await this.mkdir(fileDir);
|
|
104
|
+
await this.writeFile(filePath, output);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* An abstraction of Node's file system API and helper functions for Designsystemet CLI interaction with the file system.
|
|
110
|
+
*
|
|
111
|
+
* Allows dry-running destructive operations, logging and store relevant file system state.
|
|
112
|
+
*/
|
|
113
|
+
const dsfs = new FileSystem();
|
|
114
|
+
//#endregion
|
|
115
|
+
export { dsfs };
|