@digdir/designsystemet 0.0.0-chore-remove-cli-tsx-20260701060359
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 +104 -0
- package/dist/bin/config.d.ts +14 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +58 -0
- package/dist/bin/config.js.map +1 -0
- package/dist/bin/designsystemet.d.ts +1 -0
- package/dist/bin/designsystemet.js +174 -0
- package/dist/bin/designsystemet.js.map +1 -0
- package/dist/bin/options.d.ts +24 -0
- package/dist/bin/options.d.ts.map +1 -0
- package/dist/bin/options.js +25 -0
- package/dist/bin/options.js.map +1 -0
- package/dist/config.schema.json +181 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +15 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +12 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +12 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +55 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +16 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.d.ts +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.d.ts.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +34 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +17 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/ThemeObject.d.ts +16 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/ThemeObject.d.ts.map +1 -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 +7 -0
- package/dist/package.js.map +1 -0
- package/dist/src/automigrate.d.ts +5 -0
- package/dist/src/automigrate.d.ts.map +1 -0
- package/dist/src/automigrate.js +35 -0
- package/dist/src/automigrate.js.map +1 -0
- package/dist/src/colors/colorMetadata.d.ts +60 -0
- package/dist/src/colors/colorMetadata.d.ts.map +1 -0
- package/dist/src/colors/colorMetadata.js +261 -0
- package/dist/src/colors/colorMetadata.js.map +1 -0
- package/dist/src/colors/index.d.ts +5 -0
- package/dist/src/colors/index.js +5 -0
- package/dist/src/colors/theme.d.ts +34 -0
- package/dist/src/colors/theme.d.ts.map +1 -0
- package/dist/src/colors/theme.js +113 -0
- package/dist/src/colors/theme.js.map +1 -0
- package/dist/src/colors/types.d.ts +67 -0
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/src/colors/types.js +26 -0
- package/dist/src/colors/types.js.map +1 -0
- package/dist/src/colors/utils.d.ts +132 -0
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +246 -0
- package/dist/src/colors/utils.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +11 -0
- package/dist/src/migrations/beta-to-v1.d.ts +5 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +342 -0
- package/dist/src/migrations/beta-to-v1.js.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts +9 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.js +37 -0
- package/dist/src/migrations/codemods/css/plugins.js.map +1 -0
- package/dist/src/migrations/codemods/css/run.d.ts +14 -0
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.js +25 -0
- package/dist/src/migrations/codemods/css/run.js.map +1 -0
- package/dist/src/migrations/color-rename-next49.d.ts +5 -0
- package/dist/src/migrations/color-rename-next49.d.ts.map +1 -0
- package/dist/src/migrations/color-rename-next49.js +48 -0
- package/dist/src/migrations/color-rename-next49.js.map +1 -0
- package/dist/src/migrations/flatten-color-categories.d.ts +12 -0
- package/dist/src/migrations/flatten-color-categories.d.ts.map +1 -0
- package/dist/src/migrations/flatten-color-categories.js +58 -0
- package/dist/src/migrations/flatten-color-categories.js.map +1 -0
- package/dist/src/migrations/index.d.ts +17 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/index.js +13 -0
- package/dist/src/migrations/index.js.map +1 -0
- package/dist/src/schemas/helpers.d.ts +42 -0
- package/dist/src/schemas/helpers.d.ts.map +1 -0
- package/dist/src/schemas/helpers.js +96 -0
- package/dist/src/schemas/helpers.js.map +1 -0
- package/dist/src/schemas/v1/schema.d.ts +173 -0
- package/dist/src/schemas/v1/schema.d.ts.map +1 -0
- package/dist/src/schemas/v1/schema.js +65 -0
- package/dist/src/schemas/v1/schema.js.map +1 -0
- package/dist/src/schemas/v1.1/schema.d.ts +165 -0
- package/dist/src/schemas/v1.1/schema.d.ts.map +1 -0
- package/dist/src/schemas/v1.1/schema.js +56 -0
- package/dist/src/schemas/v1.1/schema.js.map +1 -0
- package/dist/src/tokens/build.d.ts +8 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +43 -0
- package/dist/src/tokens/build.js.map +1 -0
- package/dist/src/tokens/create/files.d.ts +19 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/files.js +48 -0
- package/dist/src/tokens/create/files.js.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +8 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +12 -0
- package/dist/src/tokens/create/generators/$designsystemet.js.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +15 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.js +25 -0
- package/dist/src/tokens/create/generators/$metadata.js.map +1 -0
- package/dist/src/tokens/create/generators/$themes.d.ts +28 -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/$themes.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +9 -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/color-scheme.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts +7 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.js +144 -0
- package/dist/src/tokens/create/generators/primitives/globals.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts +8 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.js +149 -0
- package/dist/src/tokens/create/generators/primitives/size.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts +10 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.js +218 -0
- package/dist/src/tokens/create/generators/primitives/typography.js.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts +7 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.js +19 -0
- package/dist/src/tokens/create/generators/semantic/color.js.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts +7 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.js +420 -0
- package/dist/src/tokens/create/generators/semantic/style.js.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts +7 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.js +105 -0
- package/dist/src/tokens/create/generators/themes/theme.js.map +1 -0
- package/dist/src/tokens/create.d.ts +10 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +40 -0
- package/dist/src/tokens/create.js.map +1 -0
- package/dist/src/tokens/format.d.ts +19 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +42 -0
- package/dist/src/tokens/format.js.map +1 -0
- package/dist/src/tokens/generate-config.d.ts +14 -0
- package/dist/src/tokens/generate-config.d.ts.map +1 -0
- package/dist/src/tokens/generate-config.js +154 -0
- package/dist/src/tokens/generate-config.js.map +1 -0
- package/dist/src/tokens/index.d.ts +5 -0
- package/dist/src/tokens/index.js +4 -0
- package/dist/src/tokens/process/configs/color.d.ts +8 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +50 -0
- package/dist/src/tokens/process/configs/color.js.map +1 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +7 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +49 -0
- package/dist/src/tokens/process/configs/semantic.js.map +1 -0
- package/dist/src/tokens/process/configs/shared.d.ts +14 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +21 -0
- package/dist/src/tokens/process/configs/shared.js.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts +7 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.js +30 -0
- package/dist/src/tokens/process/configs/size-mode.js.map +1 -0
- package/dist/src/tokens/process/configs/size.d.ts +7 -0
- package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size.js +36 -0
- package/dist/src/tokens/process/configs/size.js.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts +7 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.js +51 -0
- package/dist/src/tokens/process/configs/type-scale.js.map +1 -0
- package/dist/src/tokens/process/configs/typography.d.ts +7 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +66 -0
- package/dist/src/tokens/process/configs/typography.js.map +1 -0
- package/dist/src/tokens/process/configs.d.ts +18 -0
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +74 -0
- package/dist/src/tokens/process/configs.js.map +1 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +8 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +64 -0
- package/dist/src/tokens/process/formats/css/color.js.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +7 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +31 -0
- package/dist/src/tokens/process/formats/css/semantic.js.map +1 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts +7 -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 +52 -0
- package/dist/src/tokens/process/formats/css/size-mode.js.map +1 -0
- package/dist/src/tokens/process/formats/css/size.d.ts +16 -0
- package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size.js +95 -0
- package/dist/src/tokens/process/formats/css/size.js.map +1 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts +7 -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 +57 -0
- package/dist/src/tokens/process/formats/css/type-scale.js.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +7 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +31 -0
- package/dist/src/tokens/process/formats/css/typography.js.map +1 -0
- package/dist/src/tokens/process/formats/css.d.ts +15 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css.js +20 -0
- package/dist/src/tokens/process/formats/css.js.map +1 -0
- package/dist/src/tokens/process/output/declarations.d.ts +9 -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/declarations.js.map +1 -0
- package/dist/src/tokens/process/output/tailwind.d.ts +7 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +47 -0
- package/dist/src/tokens/process/output/tailwind.js.map +1 -0
- package/dist/src/tokens/process/output/theme.d.ts +31 -0
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/output/theme.js +85 -0
- package/dist/src/tokens/process/output/theme.js.map +1 -0
- package/dist/src/tokens/process/platform.d.ts +69 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +128 -0
- package/dist/src/tokens/process/platform.js.map +1 -0
- package/dist/src/tokens/process/transformers.d.ts +10 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/process/transformers.js +56 -0
- package/dist/src/tokens/process/transformers.js.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +38 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +112 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts +8 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.js +11 -0
- package/dist/src/tokens/process/utils/kebab-case.js.map +1 -0
- package/dist/src/tokens/types.d.ts +71 -0
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/src/tokens/types.js +1 -0
- package/dist/src/tokens/utils.d.ts +62 -0
- package/dist/src/tokens/utils.d.ts.map +1 -0
- package/dist/src/tokens/utils.js +123 -0
- package/dist/src/tokens/utils.js.map +1 -0
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.js +10 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/filesystem.d.ts +47 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +117 -0
- package/dist/src/utils/filesystem.js.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Digitaliseringsdirektoratet (Digdir)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @digdir/designsystemet
|
|
2
|
+
|
|
3
|
+
CLI and tooling for Designsystemet
|
|
4
|
+
|
|
5
|
+
Use `--help` for available commands and options
|
|
6
|
+
|
|
7
|
+
Read the Designsystemet [README](https://github.com/digdir/designsystemet) to get started.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
### Create tokens
|
|
13
|
+
|
|
14
|
+
Use `npx @digdir/designsystemet tokens create <options>` to create design tokens for use with Designsystemet.
|
|
15
|
+
|
|
16
|
+
This allows you to define themes including custom colors, font-family, and border-radius.
|
|
17
|
+
We recommend using the [Designsystemet theme builder](https://theme.designsystemet.no/) for generating a valid config.
|
|
18
|
+
|
|
19
|
+
#### Update tokens
|
|
20
|
+
|
|
21
|
+
Whenever a new version of the CLI is released, or you have done changes, we recommend to update design tokens with the `--clean` option to potentially remove any changes deprecated files or unneeded files.
|
|
22
|
+
|
|
23
|
+
To update design tokens, re-run `npx @digdir/designsystemet tokens create <options> --clean`.
|
|
24
|
+
If a [config file](#using-a-config-file) you can also re-run with `"clean": true`.
|
|
25
|
+
|
|
26
|
+
> ⚠️ **WARNING** ⚠️
|
|
27
|
+
> The design tokens created by this tool are considered an implementation detail, and is subject
|
|
28
|
+
> to change at any time without being considered a breaking change. We **only** support customisations
|
|
29
|
+
> done through the CLI options and config. Direct editing of the design tokens are **not** supported.
|
|
30
|
+
>
|
|
31
|
+
> Since tokens may be added or removed at any time, it is necessary to routinely re-run this
|
|
32
|
+
> command when upgrading the libraries. This will remove any direct edits to the design tokens.
|
|
33
|
+
|
|
34
|
+
### Build CSS from tokens
|
|
35
|
+
|
|
36
|
+
Use `npx @digdir/designsystemet tokens build <options>` to build CSS from design tokens generated in the previous step.
|
|
37
|
+
|
|
38
|
+
> ⚠️ **WARNING** ⚠️
|
|
39
|
+
> The CSS files from created by this tool are considered build artifacts. They should **not** be
|
|
40
|
+
> edited directly. While the CSS will not change unexpectedly, new variables may be added at any
|
|
41
|
+
> time. Therefore, it is necessary to routinely re-run this command when upgrading the libraries.
|
|
42
|
+
> This will remove any direct edits to the CSS.
|
|
43
|
+
|
|
44
|
+
#### Update built CSS
|
|
45
|
+
|
|
46
|
+
Whenever a new version of the CLI is released, or you have done changes, we recommend to build a new set of CSS from design tokens with the `--clean` option to potentially remove any changes deprecated files or unneeded files.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Using a config file
|
|
50
|
+
|
|
51
|
+
> ⚠️ **WARNING** ⚠️
|
|
52
|
+
> The typography feature is experimental. The config schema may change at any time.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
The `tokens create` command supports a config file. It will auto-detect a `designsystemet.config.json` or `designsystemet.config.jsonc` file in the current directory. You can also use the `--config <path>` option to supply a different config name and location.
|
|
56
|
+
|
|
57
|
+
Both `.json` and `.jsonc` files may contain comments and trailing commas (JSONC).
|
|
58
|
+
|
|
59
|
+
The main advantage of using a config file is for automation in scenarios with multiple themes.
|
|
60
|
+
|
|
61
|
+
To get started, use this template for a `designsystemet.config.json` file:
|
|
62
|
+
|
|
63
|
+
```jsonc
|
|
64
|
+
{
|
|
65
|
+
"$schema": "node_modules/@digdir/designsystemet/dist/config.schema.json",
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
In editors which support JSON Schema, the `$schema` will then give you editor hints for the structure of the file.
|
|
70
|
+
|
|
71
|
+
#### Minimal config example
|
|
72
|
+
```jsonc
|
|
73
|
+
{
|
|
74
|
+
"$schema": "./node_modules/@digdir/designsystemet/dist/config.schema.json",
|
|
75
|
+
"outDir": "../path/to/design-tokens",
|
|
76
|
+
"themes": {
|
|
77
|
+
"theme": {
|
|
78
|
+
"colors": {
|
|
79
|
+
"accent": "#1E98F5",
|
|
80
|
+
"neutral": "#1E2B3C",
|
|
81
|
+
},
|
|
82
|
+
"borderRadius": 4
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
To generate new design tokens and CSS files, you would then run.
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
npx @digdir/designsystemet tokens create
|
|
91
|
+
npx @digdir/designsystemet tokens build
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Complex config example
|
|
95
|
+
|
|
96
|
+
Have a look at the `*.config.json` files under the `packages/cli` in the Github repo for more complex examples.
|
|
97
|
+
|
|
98
|
+
#### Create config from existing tokens
|
|
99
|
+
|
|
100
|
+
You can get a minimal config file, meaning without overrides, generated from existing design tokens using the following command:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
npx @digdir/designsystemet generate-config-from-tokens --dir <path to design tokens>
|
|
104
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CreateConfigSchema } from "../src/schemas/v1.1/schema.js";
|
|
2
|
+
import { deprecatedCLIOptions } from "../src/schemas/helpers.js";
|
|
3
|
+
import { Command, OptionValues } from "@commander-js/extra-typings";
|
|
4
|
+
|
|
5
|
+
//#region bin/config.d.ts
|
|
6
|
+
declare function readConfigFile(configFilePath: string, allowFileNotFound?: boolean): Promise<string>;
|
|
7
|
+
declare function parseCreateConfig(configFile: string, options: {
|
|
8
|
+
theme: string;
|
|
9
|
+
cmd: Command<unknown[], OptionValues>;
|
|
10
|
+
configFilePath: string;
|
|
11
|
+
}): Promise<CreateConfigSchema>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { deprecatedCLIOptions, parseCreateConfig, readConfigFile };
|
|
14
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","names":[],"sources":["../../bin/config.ts"],"mappings":";;;;;iBAUsB,cAAA,CAAe,cAAA,UAAwB,iBAAA,aAA2B,OAAO;AAAA,iBAoBzE,iBAAA,CACpB,UAAA,UACA,OAAA;EAAW,KAAA;EAAe,GAAA,EAAK,OAAA,YAAmB,YAAA;EAAe,cAAA;AAAA,IAChE,OAAA,CAAQ,kBAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { deprecatedCLIOptions, parseConfig, validateConfig } from "../src/schemas/helpers.js";
|
|
2
|
+
import { configFileCreateSchema } from "../src/schemas/v1.1/schema.js";
|
|
3
|
+
import { dsfs } from "../src/utils/filesystem.js";
|
|
4
|
+
import { getCliOption, getDefaultCliOption, getSuppliedCliOption } from "./options.js";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import * as R from "ramda";
|
|
7
|
+
//#region bin/config.ts
|
|
8
|
+
async function readConfigFile(configFilePath, allowFileNotFound = true) {
|
|
9
|
+
let configFile;
|
|
10
|
+
try {
|
|
11
|
+
configFile = await dsfs.readFile(configFilePath, allowFileNotFound);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (allowFileNotFound) return "";
|
|
14
|
+
console.error(pc.redBright(`Could not read config file at ${pc.blue(configFilePath)}`));
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
if (configFile) console.log(`Found config file: ${pc.green(configFilePath)}`);
|
|
18
|
+
return configFile;
|
|
19
|
+
}
|
|
20
|
+
async function parseCreateConfig(configFile, options) {
|
|
21
|
+
const { cmd, theme = "theme", configFilePath } = options;
|
|
22
|
+
const configParsed = parseConfig(configFile, configFilePath);
|
|
23
|
+
const themeColors = Object.values(configParsed?.themes ?? {}).map((x) => new Set(R.keys(x.colors)));
|
|
24
|
+
if (!R.all(R.equals(R.__, themeColors[0]), themeColors)) {
|
|
25
|
+
console.error(pc.redBright(`In config, all themes must have the same custom color names, but we found:`));
|
|
26
|
+
const themeNames = R.keys(configParsed.themes ?? {});
|
|
27
|
+
themeColors.forEach((colors, index) => {
|
|
28
|
+
const colorNames = Array.from(colors);
|
|
29
|
+
console.log(` - ${themeNames[index]}: ${colorNames.join(", ")}`);
|
|
30
|
+
});
|
|
31
|
+
console.log();
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
const noUndefined = R.reject(R.isNil);
|
|
35
|
+
const getThemeOptions = (optionGetter) => noUndefined({
|
|
36
|
+
colors: noUndefined({
|
|
37
|
+
...optionGetter(cmd, "mainColors"),
|
|
38
|
+
...optionGetter(cmd, "supportColors"),
|
|
39
|
+
neutral: optionGetter(cmd, "neutralColor")
|
|
40
|
+
}),
|
|
41
|
+
typography: noUndefined({ fontFamily: optionGetter(cmd, "fontFamily") }),
|
|
42
|
+
borderRadius: optionGetter(cmd, "borderRadius"),
|
|
43
|
+
defaultColor: optionGetter(cmd, "defaultColor")
|
|
44
|
+
});
|
|
45
|
+
return validateConfig(configFileCreateSchema, noUndefined({
|
|
46
|
+
outDir: configParsed?.outDir ?? getCliOption(cmd, "outDir"),
|
|
47
|
+
clean: configParsed?.clean ?? getCliOption(cmd, "clean"),
|
|
48
|
+
themes: configParsed?.themes ? R.map((jsonThemeValues) => {
|
|
49
|
+
const defaultThemeValues = getThemeOptions(getDefaultCliOption);
|
|
50
|
+
const cliThemeValues = getThemeOptions(getSuppliedCliOption);
|
|
51
|
+
return R.mergeDeepRight(defaultThemeValues, R.mergeDeepRight(jsonThemeValues, cliThemeValues));
|
|
52
|
+
}, configParsed.themes) : { [theme]: getThemeOptions(getCliOption) }
|
|
53
|
+
}), configFilePath);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { deprecatedCLIOptions, parseCreateConfig, readConfigFile };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../../bin/config.ts"],"sourcesContent":["import type { Command, OptionValues } from '@commander-js/extra-typings';\nimport pc from 'picocolors';\nimport * as R from 'ramda';\nimport { parseConfig, validateConfig } from '../src/schemas/helpers.ts';\nimport { type CreateConfigSchema, configFileCreateSchema } from '../src/schemas/v1.1/schema.ts';\nimport { dsfs } from '../src/utils/filesystem.ts';\nimport { getCliOption, getDefaultCliOption, getSuppliedCliOption, type OptionGetter } from './options.ts';\n\nexport { deprecatedCLIOptions } from '../src/schemas/helpers.ts';\n\nexport async function readConfigFile(configFilePath: string, allowFileNotFound = true): Promise<string> {\n let configFile: string;\n\n try {\n configFile = await dsfs.readFile(configFilePath, allowFileNotFound);\n } catch (err) {\n if (allowFileNotFound) {\n return '';\n }\n console.error(pc.redBright(`Could not read config file at ${pc.blue(configFilePath)}`));\n throw err;\n }\n\n if (configFile) {\n console.log(`Found config file: ${pc.green(configFilePath)}`);\n }\n\n return configFile;\n}\n\nexport async function parseCreateConfig(\n configFile: string,\n options: { theme: string; cmd: Command<unknown[], OptionValues>; configFilePath: string },\n): Promise<CreateConfigSchema> {\n const { cmd, theme = 'theme', configFilePath } = options;\n\n const configParsed: CreateConfigSchema = parseConfig<CreateConfigSchema>(configFile, configFilePath);\n\n /*\n * Check that we're not creating multiple themes with different color names.\n * For the themes' modes to work in Figma and when building css, the color names must be consistent\n */\n const themeColors = Object.values(configParsed?.themes ?? {}).map((x) => new Set(R.keys(x.colors)));\n if (!R.all(R.equals(R.__, themeColors[0]), themeColors)) {\n console.error(pc.redBright(`In config, all themes must have the same custom color names, but we found:`));\n const themeNames = R.keys(configParsed.themes ?? {});\n themeColors.forEach((colors, index) => {\n const colorNames = Array.from(colors);\n console.log(` - ${themeNames[index]}: ${colorNames.join(', ')}`);\n });\n console.log();\n process.exit(1);\n }\n\n /*\n * Create final config from JSON config file and command-line options\n */\n const noUndefined = R.reject(R.isNil);\n\n const getThemeOptions = (optionGetter: OptionGetter) =>\n noUndefined({\n colors: noUndefined({\n ...(optionGetter(cmd, 'mainColors') as Record<string, string>),\n ...(optionGetter(cmd, 'supportColors') as Record<string, string>),\n neutral: optionGetter(cmd, 'neutralColor') as string,\n }),\n typography: noUndefined({\n fontFamily: optionGetter(cmd, 'fontFamily'),\n }),\n borderRadius: optionGetter(cmd, 'borderRadius'),\n defaultColor: optionGetter(cmd, 'defaultColor'),\n });\n\n const unvalidatedConfig = noUndefined({\n outDir: configParsed?.outDir ?? getCliOption(cmd, 'outDir'),\n clean: configParsed?.clean ?? getCliOption(cmd, 'clean'),\n themes: configParsed?.themes\n ? R.map((jsonThemeValues) => {\n // For each theme specified in the JSON config, we resolve the option values in the following order:\n // - default value\n // - config value\n // - CLI value\n // With later values overriding earlier values\n const defaultThemeValues = getThemeOptions(getDefaultCliOption);\n const cliThemeValues = getThemeOptions(getSuppliedCliOption);\n const mergedConfigs = R.mergeDeepRight(defaultThemeValues, R.mergeDeepRight(jsonThemeValues, cliThemeValues));\n return mergedConfigs;\n }, configParsed.themes)\n : // If there are no themes specified in the JSON config, we use both explicit\n // and default theme options from the CLI.\n {\n [theme]: getThemeOptions(getCliOption),\n },\n });\n\n return validateConfig<CreateConfigSchema>(configFileCreateSchema, unvalidatedConfig, configFilePath);\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,eAAe,gBAAwB,oBAAoB,MAAuB;CACtG,IAAI;CAEJ,IAAI;EACF,aAAa,MAAM,KAAK,SAAS,gBAAgB,iBAAiB;CACpE,SAAS,KAAK;EACZ,IAAI,mBACF,OAAO;EAET,QAAQ,MAAM,GAAG,UAAU,iCAAiC,GAAG,KAAK,cAAc,GAAG,CAAC;EACtF,MAAM;CACR;CAEA,IAAI,YACF,QAAQ,IAAI,sBAAsB,GAAG,MAAM,cAAc,GAAG;CAG9D,OAAO;AACT;AAEA,eAAsB,kBACpB,YACA,SAC6B;CAC7B,MAAM,EAAE,KAAK,QAAQ,SAAS,mBAAmB;CAEjD,MAAM,eAAmC,YAAgC,YAAY,cAAc;CAMnG,MAAM,cAAc,OAAO,OAAO,cAAc,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;CAClG,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,GAAG,WAAW,GAAG;EACvD,QAAQ,MAAM,GAAG,UAAU,4EAA4E,CAAC;EACxG,MAAM,aAAa,EAAE,KAAK,aAAa,UAAU,CAAC,CAAC;EACnD,YAAY,SAAS,QAAQ,UAAU;GACrC,MAAM,aAAa,MAAM,KAAK,MAAM;GACpC,QAAQ,IAAI,OAAO,WAAW,OAAO,IAAI,WAAW,KAAK,IAAI,GAAG;EAClE,CAAC;EACD,QAAQ,IAAI;EACZ,QAAQ,KAAK,CAAC;CAChB;CAKA,MAAM,cAAc,EAAE,OAAO,EAAE,KAAK;CAEpC,MAAM,mBAAmB,iBACvB,YAAY;EACV,QAAQ,YAAY;GAClB,GAAI,aAAa,KAAK,YAAY;GAClC,GAAI,aAAa,KAAK,eAAe;GACrC,SAAS,aAAa,KAAK,cAAc;EAC3C,CAAC;EACD,YAAY,YAAY,EACtB,YAAY,aAAa,KAAK,YAAY,EAC5C,CAAC;EACD,cAAc,aAAa,KAAK,cAAc;EAC9C,cAAc,aAAa,KAAK,cAAc;CAChD,CAAC;CAwBH,OAAO,eAAmC,wBAtBhB,YAAY;EACpC,QAAQ,cAAc,UAAU,aAAa,KAAK,QAAQ;EAC1D,OAAO,cAAc,SAAS,aAAa,KAAK,OAAO;EACvD,QAAQ,cAAc,SAClB,EAAE,KAAK,oBAAoB;GAMzB,MAAM,qBAAqB,gBAAgB,mBAAmB;GAC9D,MAAM,iBAAiB,gBAAgB,oBAAoB;GAE3D,OADsB,EAAE,eAAe,oBAAoB,EAAE,eAAe,iBAAiB,cAAc,CACxF;EACrB,GAAG,aAAa,MAAM,IAGtB,GACG,QAAQ,gBAAgB,YAAY,EACvC;CACN,CAEkF,GAAG,cAAc;AACrG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { deprecatedCLIOptions } from "../src/schemas/helpers.js";
|
|
3
|
+
import { convertToHex } from "../src/colors/utils.js";
|
|
4
|
+
import "../src/colors/index.js";
|
|
5
|
+
import { dsfs } from "../src/utils/filesystem.js";
|
|
6
|
+
import { parseCreateConfig, readConfigFile } from "./config.js";
|
|
7
|
+
import migrations_default from "../src/migrations/index.js";
|
|
8
|
+
import { checkAutomigrate } from "../src/automigrate.js";
|
|
9
|
+
import { toColorNames } from "../src/tokens/utils.js";
|
|
10
|
+
import { buildTokens } from "../src/tokens/build.js";
|
|
11
|
+
import { createSystemTokenFiles, tokenSetsToFiles } from "../src/tokens/create/files.js";
|
|
12
|
+
import { createTokens, tokenSetDimensions } from "../src/tokens/create.js";
|
|
13
|
+
import { generateConfigFromTokens } from "../src/tokens/generate-config.js";
|
|
14
|
+
import pc from "picocolors";
|
|
15
|
+
import * as R from "ramda";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { Argument, createCommand, program } from "@commander-js/extra-typings";
|
|
18
|
+
//#region bin/designsystemet.ts
|
|
19
|
+
const figletAscii = `
|
|
20
|
+
_____ _ _ _
|
|
21
|
+
| __ \\ (_) | | | |
|
|
22
|
+
| | | | ___ ___ _ __ _ _ __ ___ _ _ ___| |_ ___ _ __ ___ ___| |_
|
|
23
|
+
| | | |/ _ \\/ __| |/ _\` | '_ \\/ __| | | / __| __/ _ \\ '_ \` _ \\ / _ \\ __|
|
|
24
|
+
| |__| | __/\\__ \\ | (_| | | | \\__ \\ |_| \\__ \\ || __/ | | | | | __/ |_
|
|
25
|
+
|_____/ \\___||___/_|\\__, |_| |_|___/\\__, |___/\\__\\___|_| |_| |_|\\___|\\__|
|
|
26
|
+
__/ | __/ |
|
|
27
|
+
|___/ |___/
|
|
28
|
+
`;
|
|
29
|
+
program.name("designsystemet").description("CLI for working with Designsystemet").showHelpAfterError();
|
|
30
|
+
const DEFAULT_TOKENS_CREATE_DIR = "./design-tokens";
|
|
31
|
+
const DEFAULT_TOKENS_BUILD_DIR = "./design-tokens-build";
|
|
32
|
+
const DEFAULT_FONT = "Inter";
|
|
33
|
+
const DEFAULT_THEME_NAME = "theme";
|
|
34
|
+
const DEFAULT_CONFIG_FILEPATH = "designsystemet.config.json";
|
|
35
|
+
const DEFAULT_CONFIG_FILEPATHS = ["designsystemet.config.json", "designsystemet.config.jsonc"];
|
|
36
|
+
function _makeTokenCommands() {
|
|
37
|
+
const tokenCmd = createCommand("tokens");
|
|
38
|
+
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${pc.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option("-o, --out-dir <string>", `Output directory for built ${pc.blue("design-tokens")}`, DEFAULT_TOKENS_BUILD_DIR).option(`--${deprecatedCLIOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${pc.blue("design-tokens")}`, parseBoolean, false).option("--verbose", "Enable verbose output", false).option("--config <string>", `Path to config file (auto-detects ${DEFAULT_CONFIG_FILEPATHS.map((p) => `"${p}"`).join(" or ")})`).option("--experimental-tailwind", "Generate Tailwind CSS classes for tokens", false).action(async (opts) => {
|
|
39
|
+
console.log(figletAscii);
|
|
40
|
+
const { verbose, clean, dry, experimentalTailwind, tokens } = opts;
|
|
41
|
+
dsfs.init({
|
|
42
|
+
dry,
|
|
43
|
+
outdir: opts.outDir,
|
|
44
|
+
verbose
|
|
45
|
+
});
|
|
46
|
+
const outDir = dsfs.outDir;
|
|
47
|
+
if (clean) await dsfs.cleanDir(outDir);
|
|
48
|
+
const files = await buildTokens({
|
|
49
|
+
tokensDir: tokens,
|
|
50
|
+
verbose,
|
|
51
|
+
tailwind: experimentalTailwind
|
|
52
|
+
});
|
|
53
|
+
console.log(`\n💾 Writing build to ${pc.green(outDir)}`);
|
|
54
|
+
await dsfs.writeFiles(files, outDir, true);
|
|
55
|
+
console.log(`\n✅ Finished building tokens in ${pc.green(outDir)}`);
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
});
|
|
58
|
+
tokenCmd.command("create").description("Create Designsystemet tokens").option("--config <string>", `Path to config file (auto-detects ${DEFAULT_CONFIG_FILEPATHS.map((p) => `"${p}"`).join(" or ")})`).option(`--${deprecatedCLIOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${pc.blue("design-tokens")}`, parseBoolean, false).option("--skip-check", "Skip migration check", false).option("-y, --yes", "Skip user prompts", false).option(`-m, --${deprecatedCLIOptions.theme.colors.main} <name:hex...>`, `Main colors (deprecated, use JSON config file instead)`, parseColorValues).option(`-s, --${deprecatedCLIOptions.theme.colors.support} <name:hex...>`, `Support colors (deprecated, use JSON config file instead)`, parseColorValues).option(`-n, --${deprecatedCLIOptions.theme.colors.neutral} <hex>`, `Neutral hex color (deprecated, use JSON config file instead)`, convertToHex).option(`-o, --${deprecatedCLIOptions.outDir} <string>`, `Output directory for created ${pc.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option(`-f, --${deprecatedCLIOptions.theme.typography.fontFamily} <string>`, `Font family (experimental, deprecated, use JSON config file instead)`, DEFAULT_FONT).option(`-b, --${deprecatedCLIOptions.theme.borderRadius} <number>`, `Unitless base border-radius in px (deprecated, use JSON config file instead)`, (radiusAsString) => Number(radiusAsString), 4).option("--theme <string>", "Theme name (deprecated, use JSON config file instead)", DEFAULT_THEME_NAME).action(async (opts, cmd) => {
|
|
59
|
+
if (opts.mainColors || opts.supportColors || opts.neutralColor || opts.borderRadius && opts.borderRadius !== 4 || opts.theme && opts.theme !== DEFAULT_THEME_NAME || opts.fontFamily && opts.fontFamily !== DEFAULT_FONT) console.warn(pc.yellow(`\n ⚠️ Using CLI options for ${pc.bold(`colors, border radius, theme, or font family is deprecated`)} and will be removed in a future release.
|
|
60
|
+
\n ⚠️ Please use a JSON config file instead.`));
|
|
61
|
+
console.log(figletAscii);
|
|
62
|
+
if (opts.dry) console.log(`Performing dry run, no files will be written`);
|
|
63
|
+
const themeName = opts.theme;
|
|
64
|
+
const { configFile, configFilePath } = await getConfigFile(opts.config);
|
|
65
|
+
const config = await parseCreateConfig((opts.skipCheck ? configFile : await checkAutomigrate(configFile, configFilePath, opts.yes)) || configFile, {
|
|
66
|
+
theme: themeName,
|
|
67
|
+
cmd,
|
|
68
|
+
configFilePath
|
|
69
|
+
});
|
|
70
|
+
const themeNames = Object.keys(config.themes);
|
|
71
|
+
if (themeNames.length > 0) console.log(`Using themes from config file: ${pc.blue(themeNames.join(", "))}`);
|
|
72
|
+
dsfs.init({
|
|
73
|
+
dry: opts.dry,
|
|
74
|
+
outdir: config.outDir
|
|
75
|
+
});
|
|
76
|
+
const outDir = dsfs.outDir;
|
|
77
|
+
const files = [];
|
|
78
|
+
const colorNames = toColorNames(config.themes?.[themeNames[0]]?.colors);
|
|
79
|
+
for (const [name, themeConfig] of Object.entries(config.themes)) {
|
|
80
|
+
const { tokenSets } = await createTokens({
|
|
81
|
+
name,
|
|
82
|
+
...themeConfig
|
|
83
|
+
});
|
|
84
|
+
files.push(...tokenSetsToFiles(tokenSets));
|
|
85
|
+
}
|
|
86
|
+
files.push(...await createSystemTokenFiles({
|
|
87
|
+
tokenSetDimensions,
|
|
88
|
+
themeNames,
|
|
89
|
+
colorNames
|
|
90
|
+
}));
|
|
91
|
+
if (config.clean) await dsfs.cleanDir(outDir);
|
|
92
|
+
await dsfs.mkdir(outDir);
|
|
93
|
+
await dsfs.writeFiles(files, outDir);
|
|
94
|
+
console.log(`\n✅ Finished creating tokens in ${pc.green(outDir)} for themes: ${pc.blue(themeNames.join(", "))}`);
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
});
|
|
97
|
+
return tokenCmd;
|
|
98
|
+
}
|
|
99
|
+
program.addCommand(_makeTokenCommands());
|
|
100
|
+
program.command("generate-config-from-tokens").description("Generate a config file from existing design tokens. Will not include overrides.").option("-d, --dir <string>", "Path to design tokens directory", DEFAULT_TOKENS_CREATE_DIR).option("-o, --out <string>", "Output path for config file", DEFAULT_CONFIG_FILEPATH).option("--dry [boolean]", "Dry run - show config without writing file", parseBoolean, false).action(async (opts) => {
|
|
101
|
+
console.log(figletAscii);
|
|
102
|
+
const { dry } = opts;
|
|
103
|
+
const tokensDir = path.resolve(opts.dir);
|
|
104
|
+
const configFilePath = path.resolve(opts.out);
|
|
105
|
+
dsfs.init({
|
|
106
|
+
dry,
|
|
107
|
+
outdir: path.dirname(configFilePath)
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
const config = await generateConfigFromTokens({
|
|
111
|
+
tokensDir,
|
|
112
|
+
outFile: configFilePath
|
|
113
|
+
});
|
|
114
|
+
if (dry) {
|
|
115
|
+
console.log();
|
|
116
|
+
console.log("Generated config (dry run):");
|
|
117
|
+
console.log(JSON.stringify(config, null, 2));
|
|
118
|
+
}
|
|
119
|
+
if (configFilePath) {
|
|
120
|
+
const configJson = JSON.stringify(config, null, 2);
|
|
121
|
+
await dsfs.writeFile(configFilePath, configJson);
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(`\n✅ Config file written to ${pc.blue(configFilePath)}`);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(pc.redBright("Error generating config:"));
|
|
127
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
program.command("migrate").description("run a Designsystemet migration").addArgument(new Argument("[migration]", "Available migrations").choices(Object.keys(migrations_default))).option("-l --list", "List available migrations").option("-g --glob <glob>", "Glob for files upon which to apply the migration", "./**/*.(tsx|css)").action((migrationKey, opts) => {
|
|
132
|
+
console.log(figletAscii);
|
|
133
|
+
const { glob, list } = opts;
|
|
134
|
+
if (list) for (const key of Object.keys(migrations_default)) console.log(key);
|
|
135
|
+
else if (migrationKey) {
|
|
136
|
+
const migration = migrations_default[migrationKey];
|
|
137
|
+
if (!migration) {
|
|
138
|
+
console.error("Migration not found!");
|
|
139
|
+
throw "Aborting";
|
|
140
|
+
}
|
|
141
|
+
console.log(`Applying migration ${pc.blue(migrationKey)} with glob: ${pc.green(glob)}`);
|
|
142
|
+
migration?.(glob).then(() => console.log(`Migration ${pc.blue(migrationKey)} finished`)).catch((error) => console.log(error));
|
|
143
|
+
} else console.log("Migrate: please specify a migration name or --list");
|
|
144
|
+
});
|
|
145
|
+
await program.parseAsync(process.argv);
|
|
146
|
+
function parseColorValues(value, previous = {}) {
|
|
147
|
+
const [name, hex] = value.split(":");
|
|
148
|
+
previous[name] = convertToHex(hex);
|
|
149
|
+
return previous;
|
|
150
|
+
}
|
|
151
|
+
function parseBoolean(value) {
|
|
152
|
+
return value === "true" || value === true;
|
|
153
|
+
}
|
|
154
|
+
async function getConfigFile(userConfigFilePath) {
|
|
155
|
+
if (!R.isNil(userConfigFilePath)) return {
|
|
156
|
+
configFile: await readConfigFile(userConfigFilePath, DEFAULT_CONFIG_FILEPATHS.includes(userConfigFilePath)),
|
|
157
|
+
configFilePath: userConfigFilePath
|
|
158
|
+
};
|
|
159
|
+
for (const configFilePath of DEFAULT_CONFIG_FILEPATHS) {
|
|
160
|
+
const configFile = await readConfigFile(configFilePath, true);
|
|
161
|
+
if (configFile) return {
|
|
162
|
+
configFile,
|
|
163
|
+
configFilePath
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
configFile: "",
|
|
168
|
+
configFilePath: DEFAULT_CONFIG_FILEPATH
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export {};
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=designsystemet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"designsystemet.js","names":["cliOptions","migrations"],"sources":["../../bin/designsystemet.ts"],"sourcesContent":["#!/usr/bin/env node\nimport path from 'node:path';\nimport { Argument, createCommand, program } from '@commander-js/extra-typings';\nimport pc from 'picocolors';\nimport * as R from 'ramda';\nimport { checkAutomigrate } from '../src/automigrate.ts';\nimport { convertToHex } from '../src/colors/index.ts';\nimport type { CssColor } from '../src/colors/types.ts';\nimport migrations from '../src/migrations/index.ts';\nimport { buildTokens } from '../src/tokens/build.ts';\nimport { createSystemTokenFiles, tokenSetsToFiles } from '../src/tokens/create/files.ts';\nimport { createTokens, tokenSetDimensions } from '../src/tokens/create.ts';\nimport { generateConfigFromTokens } from '../src/tokens/generate-config.ts';\nimport type { OutputFile, Theme } from '../src/tokens/types.ts';\nimport { toColorNames } from '../src/tokens/utils.ts';\nimport { dsfs } from '../src/utils/filesystem.ts';\nimport { deprecatedCLIOptions as cliOptions, parseCreateConfig, readConfigFile } from './config.ts';\n\nconst figletAscii = `\n _____ _ _ _\n| __ \\\\ (_) | | | |\n| | | | ___ ___ _ __ _ _ __ ___ _ _ ___| |_ ___ _ __ ___ ___| |_\n| | | |/ _ \\\\/ __| |/ _\\` | '_ \\\\/ __| | | / __| __/ _ \\\\ '_ \\` _ \\\\ / _ \\\\ __|\n| |__| | __/\\\\__ \\\\ | (_| | | | \\\\__ \\\\ |_| \\\\__ \\\\ || __/ | | | | | __/ |_\n|_____/ \\\\___||___/_|\\\\__, |_| |_|___/\\\\__, |___/\\\\__\\\\___|_| |_| |_|\\\\___|\\\\__|\n __/ | __/ |\n |___/ |___/\n`;\n\nprogram.name('designsystemet').description('CLI for working with Designsystemet').showHelpAfterError();\n\nconst DEFAULT_TOKENS_CREATE_DIR = './design-tokens';\nconst DEFAULT_TOKENS_BUILD_DIR = './design-tokens-build';\nconst DEFAULT_FONT = 'Inter';\nconst DEFAULT_THEME_NAME = 'theme';\nconst DEFAULT_CONFIG_FILEPATH = 'designsystemet.config.json';\n// Default config files to auto-detect when no --config is supplied, in order of precedence.\nconst DEFAULT_CONFIG_FILEPATHS = ['designsystemet.config.json', 'designsystemet.config.jsonc'];\n\nfunction _makeTokenCommands() {\n const tokenCmd = createCommand('tokens');\n\n tokenCmd\n .command('build')\n .description('Build Designsystemet tokens')\n .option('-t, --tokens <string>', `Path to ${pc.blue('design-tokens')}`, DEFAULT_TOKENS_CREATE_DIR)\n .option(\n '-o, --out-dir <string>',\n `Output directory for built ${pc.blue('design-tokens')}`,\n DEFAULT_TOKENS_BUILD_DIR,\n )\n .option(`--${cliOptions.clean} [boolean]`, 'Clean output directory before building tokens', parseBoolean, false)\n .option('--dry [boolean]', `Dry run for built ${pc.blue('design-tokens')}`, parseBoolean, false)\n .option('--verbose', 'Enable verbose output', false)\n .option(\n '--config <string>',\n `Path to config file (auto-detects ${DEFAULT_CONFIG_FILEPATHS.map((p) => `\"${p}\"`).join(' or ')})`,\n )\n .option('--experimental-tailwind', 'Generate Tailwind CSS classes for tokens', false)\n .action(async (opts) => {\n console.log(figletAscii);\n const { verbose, clean, dry, experimentalTailwind, tokens } = opts;\n\n // TODO - add outdir eqivalent to config option when parsing config, so that it can be set in the config file as well. buildDir?\n\n dsfs.init({ dry, outdir: opts.outDir, verbose });\n\n const outDir = dsfs.outDir;\n\n if (clean) {\n await dsfs.cleanDir(outDir);\n }\n\n const files = await buildTokens({\n tokensDir: tokens,\n verbose,\n tailwind: experimentalTailwind,\n });\n\n console.log(`\\n💾 Writing build to ${pc.green(outDir)}`);\n\n await dsfs.writeFiles(files, outDir, true);\n\n console.log(`\\n✅ Finished building tokens in ${pc.green(outDir)}`);\n\n return Promise.resolve();\n });\n\n tokenCmd\n .command('create')\n .description('Create Designsystemet tokens')\n .option(\n '--config <string>',\n `Path to config file (auto-detects ${DEFAULT_CONFIG_FILEPATHS.map((p) => `\"${p}\"`).join(' or ')})`,\n )\n .option(`--${cliOptions.clean} [boolean]`, 'Clean output directory before creating tokens', parseBoolean, false)\n .option('--dry [boolean]', `Dry run for created ${pc.blue('design-tokens')}`, parseBoolean, false)\n .option('--skip-check', 'Skip migration check', false) // TODO -- will be moved to global option in the future, since it applies to all commands, not just create\n .option('-y, --yes', 'Skip user prompts', false) // TODO -- will be moved to global option in the future, since it applies to all commands, not just create\n /** Deprecated options */\n .option(\n `-m, --${cliOptions.theme.colors.main} <name:hex...>`,\n `Main colors (deprecated, use JSON config file instead)`,\n parseColorValues,\n )\n .option(\n `-s, --${cliOptions.theme.colors.support} <name:hex...>`,\n `Support colors (deprecated, use JSON config file instead)`,\n parseColorValues,\n )\n .option(\n `-n, --${cliOptions.theme.colors.neutral} <hex>`,\n `Neutral hex color (deprecated, use JSON config file instead)`,\n convertToHex,\n )\n .option(\n `-o, --${cliOptions.outDir} <string>`,\n `Output directory for created ${pc.blue('design-tokens')}`,\n DEFAULT_TOKENS_CREATE_DIR,\n )\n .option(\n `-f, --${cliOptions.theme.typography.fontFamily} <string>`,\n `Font family (experimental, deprecated, use JSON config file instead)`,\n DEFAULT_FONT,\n )\n .option(\n `-b, --${cliOptions.theme.borderRadius} <number>`,\n `Unitless base border-radius in px (deprecated, use JSON config file instead)`,\n (radiusAsString) => Number(radiusAsString),\n 4,\n )\n .option('--theme <string>', 'Theme name (deprecated, use JSON config file instead)', DEFAULT_THEME_NAME)\n .action(async (opts, cmd) => {\n if (\n opts.mainColors ||\n opts.supportColors ||\n opts.neutralColor ||\n (opts.borderRadius && opts.borderRadius !== 4) ||\n (opts.theme && opts.theme !== DEFAULT_THEME_NAME) ||\n (opts.fontFamily && opts.fontFamily !== DEFAULT_FONT)\n ) {\n console.warn(\n pc.yellow(`\\n ⚠️ Using CLI options for ${pc.bold(`colors, border radius, theme, or font family is deprecated`)} and will be removed in a future release.\n \\n ⚠️ Please use a JSON config file instead.`),\n );\n }\n\n console.log(figletAscii);\n if (opts.dry) {\n console.log(`Performing dry run, no files will be written`);\n }\n const themeName = opts.theme;\n\n const { configFile, configFilePath } = await getConfigFile(opts.config);\n\n const updatedConfigFile = opts.skipCheck\n ? configFile\n : await checkAutomigrate(configFile, configFilePath, opts.yes);\n\n const config = await parseCreateConfig(updatedConfigFile || configFile, {\n theme: themeName,\n cmd,\n configFilePath,\n });\n\n const themeNames = Object.keys(config.themes);\n if (themeNames.length > 0) {\n console.log(`Using themes from config file: ${pc.blue(themeNames.join(', '))}`);\n }\n\n dsfs.init({ dry: opts.dry, outdir: config.outDir });\n\n const outDir = dsfs.outDir;\n\n const files: OutputFile[] = [];\n\n // Pick colors from first theme since we have a constraint they should be the same across themes.\n const colorNames = toColorNames(config.themes?.[themeNames[0]]?.colors);\n\n for (const [name, themeConfig] of Object.entries(config.themes)) {\n const { tokenSets } = await createTokens({ name, ...themeConfig } as Theme);\n files.push(...tokenSetsToFiles(tokenSets));\n }\n\n files.push(\n ...(await createSystemTokenFiles({\n tokenSetDimensions,\n themeNames,\n colorNames,\n })),\n );\n\n if (config.clean) {\n await dsfs.cleanDir(outDir);\n }\n\n await dsfs.mkdir(outDir);\n await dsfs.writeFiles(files, outDir);\n\n console.log(`\\n✅ Finished creating tokens in ${pc.green(outDir)} for themes: ${pc.blue(themeNames.join(', '))}`);\n\n return Promise.resolve();\n });\n\n return tokenCmd;\n}\n\nprogram.addCommand(_makeTokenCommands());\n\nprogram\n .command('generate-config-from-tokens')\n .description('Generate a config file from existing design tokens. Will not include overrides.')\n .option('-d, --dir <string>', 'Path to design tokens directory', DEFAULT_TOKENS_CREATE_DIR)\n .option('-o, --out <string>', 'Output path for config file', DEFAULT_CONFIG_FILEPATH)\n .option('--dry [boolean]', 'Dry run - show config without writing file', parseBoolean, false)\n .action(async (opts) => {\n console.log(figletAscii);\n const { dry } = opts;\n const tokensDir = path.resolve(opts.dir);\n const configFilePath = path.resolve(opts.out);\n\n dsfs.init({ dry, outdir: path.dirname(configFilePath) });\n\n try {\n const config = await generateConfigFromTokens({\n tokensDir,\n outFile: configFilePath,\n });\n\n if (dry) {\n console.log();\n console.log('Generated config (dry run):');\n console.log(JSON.stringify(config, null, 2));\n }\n\n if (configFilePath) {\n const configJson = JSON.stringify(config, null, 2);\n await dsfs.writeFile(configFilePath, configJson);\n console.log();\n console.log(`\\n✅ Config file written to ${pc.blue(configFilePath)}`);\n }\n } catch (error) {\n console.error(pc.redBright('Error generating config:'));\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n }\n });\n\nprogram\n .command('migrate')\n .description('run a Designsystemet migration')\n .addArgument(new Argument('[migration]', 'Available migrations').choices(Object.keys(migrations)))\n .option('-l --list', 'List available migrations')\n .option('-g --glob <glob>', 'Glob for files upon which to apply the migration', './**/*.(tsx|css)')\n .action((migrationKey, opts) => {\n console.log(figletAscii);\n const { glob, list } = opts;\n\n if (list) {\n for (const key of Object.keys(migrations)) {\n console.log(key);\n }\n } else if (migrationKey) {\n const migration = migrations[migrationKey as keyof typeof migrations];\n if (!migration) {\n console.error('Migration not found!');\n throw 'Aborting';\n }\n\n console.log(`Applying migration ${pc.blue(migrationKey)} with glob: ${pc.green(glob)}`);\n migration?.(glob)\n .then(() => console.log(`Migration ${pc.blue(migrationKey)} finished`))\n .catch((error) => console.log(error));\n } else {\n console.log('Migrate: please specify a migration name or --list');\n }\n });\n\nawait program.parseAsync(process.argv);\n\nfunction parseColorValues(value: string, previous: Record<string, CssColor> = {}): Record<string, CssColor> {\n const [name, hex] = value.split(':');\n previous[name] = convertToHex(hex);\n return previous;\n}\n\nfunction parseBoolean(value: string | boolean): boolean {\n return value === 'true' || value === true;\n}\n\nasync function getConfigFile(userConfigFilePath: string | undefined) {\n if (!R.isNil(userConfigFilePath)) {\n // A config path was supplied explicitly. It's allowed to not exist only if it's one of the defaults.\n const allowFileNotFound = DEFAULT_CONFIG_FILEPATHS.includes(userConfigFilePath);\n const configFile = await readConfigFile(userConfigFilePath, allowFileNotFound);\n\n return { configFile, configFilePath: userConfigFilePath };\n }\n\n // No config path supplied: auto-detect the default config files (.json, then .jsonc).\n for (const configFilePath of DEFAULT_CONFIG_FILEPATHS) {\n const configFile = await readConfigFile(configFilePath, true);\n if (configFile) {\n return { configFile, configFilePath };\n }\n }\n\n // None found - return empty config using the canonical default path for messaging.\n return { configFile: '', configFilePath: DEFAULT_CONFIG_FILEPATH };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,cAAc;;;;;;;;;;AAWpB,QAAQ,KAAK,gBAAgB,CAAC,CAAC,YAAY,qCAAqC,CAAC,CAAC,mBAAmB;AAErG,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;AACjC,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AAQ,IAAI,sBAAsB,GAAG,KAAK,YAAY,EAAE,cAAc,GAAG,MAAM,IAAI,GAAG;EACtF,YAAY,IAAI,CAAC,CACd,WAAW,QAAQ,IAAI,aAAa,GAAG,KAAK,YAAY,EAAE,UAAU,CAAC,CAAC,CACtE,OAAO,UAAU,QAAQ,IAAI,KAAK,CAAC;CACxC,OACE,QAAQ,IAAI,oDAAoD;AAEpE,CAAC;AAEH,MAAM,QAAQ,WAAW,QAAQ,IAAI;AAErC,SAAS,iBAAiB,OAAe,WAAqC,CAAC,GAA6B;CAC1G,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;CACnC,SAAS,QAAQ,aAAa,GAAG;CACjC,OAAO;AACT;AAEA,SAAS,aAAa,OAAkC;CACtD,OAAO,UAAU,UAAU,UAAU;AACvC;AAEA,eAAe,cAAc,oBAAwC;CACnE,IAAI,CAAC,EAAE,MAAM,kBAAkB,GAK7B,OAAO;EAAE,YAAA,MAFgB,eAAe,oBADd,yBAAyB,SAAS,kBACgB,CAAC;EAExD,gBAAgB;CAAmB;CAI1D,KAAK,MAAM,kBAAkB,0BAA0B;EACrD,MAAM,aAAa,MAAM,eAAe,gBAAgB,IAAI;EAC5D,IAAI,YACF,OAAO;GAAE;GAAY;EAAe;CAExC;CAGA,OAAO;EAAE,YAAY;EAAI,gBAAgB;CAAwB;AACnE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Command, OptionValueSource, OptionValues } from "@commander-js/extra-typings";
|
|
2
|
+
|
|
3
|
+
//#region bin/options.d.ts
|
|
4
|
+
declare const getOptionIfMatchingSource: (...sources: OptionValueSource[]) => <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
5
|
+
type OptionGetter = ReturnType<typeof getOptionIfMatchingSource>;
|
|
6
|
+
/**
|
|
7
|
+
* Get an option value if it is explicitly supplied to the CLI command.
|
|
8
|
+
* The difference between this and using the option directly is that we return undefined
|
|
9
|
+
* instead of the default value if the option was not explicitly set.
|
|
10
|
+
*/
|
|
11
|
+
declare const getSuppliedCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get the default value specified for a CLI command option.
|
|
14
|
+
* Mostly useful for getting values which may later be overridden.
|
|
15
|
+
*/
|
|
16
|
+
declare const getDefaultCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Try to get the explicitly supplied CLI option, and fall back to the default value
|
|
19
|
+
* for the option as defined in the {@link Command}
|
|
20
|
+
*/
|
|
21
|
+
declare const getCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { OptionGetter, getCliOption, getDefaultCliOption, getSuppliedCliOption };
|
|
24
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","names":[],"sources":["../../bin/options.ts"],"mappings":";;;cAEM,yBAAA,MACA,OAAA,EAAS,iBAAA,6CACyB,YAAA,kBAA8B,IAAA,EAClE,OAAA,EAAS,OAAA,CAAQ,IAAA,EAAM,IAAA,GACvB,MAAA,EAAQ,CAAA,KAAC,IAAA,CAAA,CAAA;AAAA,KAQD,YAAA,GAAe,UAAU,QAAQ,yBAAA;AAd+C;;;;;AAAA,cAqB/E,oBAAA,wCAjB2B,YAAA,kBAA8B,IAAA,EAAI,OAAA,EAC7D,OAAA,CAAQ,IAAA,EAAM,IAAA,GAAK,MAAA,EACpB,CAAA,KAAC,IAAA,CAAA,CAAA;;;;;cAqBA,mBAAA,wCAvB2B,YAAA,kBAA8B,IAAA,EAAI,OAAA,EAC7D,OAAA,CAAQ,IAAA,EAAM,IAAA,GAAK,MAAA,EACpB,CAAA,KAAC,IAAA,CAAA,CAAA;;;;;cA2BA,YAAA,wCA7B2B,YAAA,kBAA8B,IAAA,EAAI,OAAA,EAC7D,OAAA,CAAQ,IAAA,EAAM,IAAA,GAAK,MAAA,EACpB,CAAA,KAAC,IAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region bin/options.ts
|
|
2
|
+
const getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
3
|
+
const source = command.getOptionValueSource(option);
|
|
4
|
+
if (sources.includes(source)) return command.getOptionValue(option);
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Get an option value if it is explicitly supplied to the CLI command.
|
|
8
|
+
* The difference between this and using the option directly is that we return undefined
|
|
9
|
+
* instead of the default value if the option was not explicitly set.
|
|
10
|
+
*/
|
|
11
|
+
const getSuppliedCliOption = getOptionIfMatchingSource("cli");
|
|
12
|
+
/**
|
|
13
|
+
* Get the default value specified for a CLI command option.
|
|
14
|
+
* Mostly useful for getting values which may later be overridden.
|
|
15
|
+
*/
|
|
16
|
+
const getDefaultCliOption = getOptionIfMatchingSource("default");
|
|
17
|
+
/**
|
|
18
|
+
* Try to get the explicitly supplied CLI option, and fall back to the default value
|
|
19
|
+
* for the option as defined in the {@link Command}
|
|
20
|
+
*/
|
|
21
|
+
const getCliOption = getOptionIfMatchingSource("cli", "default");
|
|
22
|
+
//#endregion
|
|
23
|
+
export { getCliOption, getDefaultCliOption, getSuppliedCliOption };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../bin/options.ts"],"sourcesContent":["import type { Command, OptionValueSource, OptionValues } from '@commander-js/extra-typings';\n\nconst getOptionIfMatchingSource =\n (...sources: OptionValueSource[]) =>\n <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(\n command: Command<Args, Opts>,\n option: K,\n ) => {\n const source = command.getOptionValueSource(option);\n if (sources.includes(source)) {\n return command.getOptionValue(option);\n }\n };\n\nexport type OptionGetter = ReturnType<typeof getOptionIfMatchingSource>;\n\n/**\n * Get an option value if it is explicitly supplied to the CLI command.\n * The difference between this and using the option directly is that we return undefined\n * instead of the default value if the option was not explicitly set.\n */\nexport const getSuppliedCliOption = getOptionIfMatchingSource('cli');\n\n/**\n * Get the default value specified for a CLI command option.\n * Mostly useful for getting values which may later be overridden.\n */\nexport const getDefaultCliOption = getOptionIfMatchingSource('default');\n\n/**\n * Try to get the explicitly supplied CLI option, and fall back to the default value\n * for the option as defined in the {@link Command}\n */\nexport const getCliOption = getOptionIfMatchingSource('cli', 'default');\n"],"mappings":";AAEA,MAAM,6BACH,GAAG,aAEF,SACA,WACG;CACH,MAAM,SAAS,QAAQ,qBAAqB,MAAM;CAClD,IAAI,QAAQ,SAAS,MAAM,GACzB,OAAO,QAAQ,eAAe,MAAM;AAExC;;;;;;AASF,MAAa,uBAAuB,0BAA0B,KAAK;;;;;AAMnE,MAAa,sBAAsB,0BAA0B,SAAS;;;;;AAMtE,MAAa,eAAe,0BAA0B,OAAO,SAAS"}
|