@design-token-kit/cli 0.2.0 → 0.3.0

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.
Files changed (4) hide show
  1. package/LICENSE +159 -159
  2. package/README.md +85 -85
  3. package/bin/index.mjs +74 -59
  4. package/package.json +6 -4
package/LICENSE CHANGED
@@ -1,159 +1,159 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction, and
10
- distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
- owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all other entities
16
- that control, are controlled by, or are under common control with that entity.
17
- For the purposes of this definition, "control" means (i) the power, direct or
18
- indirect, to cause the direction or management of such entity, whether by
19
- contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
- outstanding shares, or (iii) beneficial ownership of such entity.
21
-
22
- "You" (or "Your") shall mean an individual or Legal Entity exercising
23
- permissions granted by this License.
24
-
25
- "Source" form shall mean the preferred form for making modifications, including
26
- but not limited to software source code, documentation source, and configuration
27
- files.
28
-
29
- "Object" form shall mean any form resulting from mechanical transformation or
30
- translation of a Source form, including but not limited to compiled object code,
31
- generated documentation, and conversions to other media types.
32
-
33
- "Work" shall mean the work of authorship, whether in Source or Object form, made
34
- available under the License, as indicated by a copyright notice that is included
35
- in or attached to the work (an example is provided in the Appendix below).
36
-
37
- "Derivative Works" shall mean any work, whether in Source or Object form, that
38
- is based on (or derived from) the Work and for which the editorial revisions,
39
- annotations, elaborations, or other modifications represent, as a whole, an
40
- original work of authorship. For the purposes of this License, Derivative Works
41
- shall not include works that remain separable from, or merely link (or bind by
42
- name) to the interfaces of, the Work and Derivative Works thereof.
43
-
44
- "Contribution" shall mean any work of authorship, including the original version
45
- of the Work and any modifications or additions to that Work or Derivative Works
46
- thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
- by the copyright owner or by an individual or Legal Entity authorized to submit
48
- on behalf of the copyright owner. For the purposes of this definition,
49
- "submitted" means any form of electronic, verbal, or written communication sent
50
- to the Licensor or its representatives, including but not limited to
51
- communication on electronic mailing lists, source code control systems, and
52
- issue tracking systems that are managed by, or on behalf of, the Licensor for
53
- the purpose of discussing and improving the Work, but excluding communication
54
- that is conspicuously marked or otherwise designated in writing by the copyright
55
- owner as "Not a Contribution."
56
-
57
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
- of whom a Contribution has been received by Licensor and subsequently
59
- incorporated within the Work.
60
-
61
- 2. Grant of Copyright License. Subject to the terms and conditions of this
62
- License, each Contributor hereby grants to You a perpetual, worldwide,
63
- non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
- reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
- sublicense, and distribute the Work and such Derivative Works in Source or
66
- Object form.
67
-
68
- 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
- each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
- no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
- license to make, have made, use, offer to sell, sell, import, and otherwise
72
- transfer the Work, where such license applies only to those patent claims
73
- licensable by such Contributor that are necessarily infringed by their
74
- Contribution(s) alone or by combination of their Contribution(s) with the Work
75
- to which such Contribution(s) was submitted. If You institute patent litigation
76
- against any entity (including a cross-claim or counterclaim in a lawsuit)
77
- alleging that the Work or a Contribution incorporated within the Work
78
- constitutes direct or contributory patent infringement, then any patent licenses
79
- granted to You under this License for that Work shall terminate as of the date
80
- such litigation is filed.
81
-
82
- 4. Redistribution. You may reproduce and distribute copies of the Work or
83
- Derivative Works thereof in any medium, with or without modifications, and in
84
- Source or Object form, provided that You meet the following conditions:
85
-
86
- (a) You must give any other recipients of the Work or Derivative Works a copy of
87
- this License; and
88
-
89
- (b) You must cause any modified files to carry prominent notices stating that
90
- You changed the files; and
91
-
92
- (c) You must retain, in the Source form of any Derivative Works that You
93
- distribute, all copyright, patent, trademark, and attribution notices from the
94
- Source form of the Work, excluding those notices that do not pertain to any part
95
- of the Derivative Works; and
96
-
97
- (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
- any Derivative Works that You distribute must include a readable copy of the
99
- attribution notices contained within such NOTICE file, excluding those notices
100
- that do not pertain to any part of the Derivative Works, in at least one of the
101
- following places: within a NOTICE text file distributed as part of the
102
- Derivative Works; within the Source form or documentation, if provided along
103
- with the Derivative Works; or, within a display generated by the Derivative
104
- Works, if and wherever such third-party notices normally appear. The contents of
105
- the NOTICE file are for informational purposes only and do not modify the
106
- License. You may add Your own attribution notices within Derivative Works that
107
- You distribute, alongside or as an addendum to the NOTICE text from the Work,
108
- provided that such additional attribution notices cannot be construed as
109
- modifying the License.
110
-
111
- You may add Your own copyright statement to Your modifications and may provide
112
- additional or different license terms and conditions for use, reproduction, or
113
- distribution of Your modifications, or for any such Derivative Works as a whole,
114
- provided Your use, reproduction, and distribution of the Work otherwise complies
115
- with the conditions stated in this License.
116
-
117
- 5. Submission of Contributions. Unless You explicitly state otherwise, any
118
- Contribution intentionally submitted for inclusion in the Work by You to the
119
- Licensor shall be under the terms and conditions of this License, without any
120
- additional terms or conditions. Notwithstanding the above, nothing herein shall
121
- supersede or modify the terms of any separate license agreement you may have
122
- executed with Licensor regarding such Contributions.
123
-
124
- 6. Trademarks. This License does not grant permission to use the trade names,
125
- trademarks, service marks, or product names of the Licensor, except as required
126
- for reasonable and customary use in describing the origin of the Work and
127
- reproducing the content of the NOTICE file.
128
-
129
- 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
130
- writing, Licensor provides the Work (and each Contributor provides its
131
- Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
132
- KIND, either express or implied, including, without limitation, any warranties
133
- or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
134
- PARTICULAR PURPOSE. You are solely responsible for determining the
135
- appropriateness of using or redistributing the Work and assume any risks
136
- associated with Your exercise of permissions under this License.
137
-
138
- 8. Limitation of Liability. In no event and under no legal theory, whether in
139
- contract, tort (including negligence), or otherwise, unless required by
140
- applicable law (such as deliberate and grossly negligent acts) or agreed to in
141
- writing, shall any Contributor be liable to You for damages, including any
142
- direct, indirect, special, incidental, or consequential damages of any character
143
- arising as a result of this License or out of the use or inability to use the
144
- Work (including but not limited to damages for loss of goodwill, work stoppage,
145
- computer failure or malfunction, or any and all other commercial damages or
146
- losses), even if such Contributor has been advised of the possibility of such
147
- damages.
148
-
149
- 9. Accepting Warranty or Additional Liability. While redistributing the Work or
150
- Derivative Works thereof, You may choose to offer, and charge a fee for,
151
- acceptance of support, warranty, indemnity, or other liability obligations
152
- and/or rights consistent with this License. However, in accepting such
153
- obligations, You may act only on Your own behalf and on Your sole responsibility,
154
- not on behalf of any other Contributor, and only if You agree to indemnify,
155
- defend, and hold each Contributor harmless for any liability incurred by, or
156
- claims asserted against, such Contributor by reason of your accepting any such
157
- warranty or additional liability.
158
-
159
- END OF TERMS AND CONDITIONS
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
+ license to make, have made, use, offer to sell, sell, import, and otherwise
72
+ transfer the Work, where such license applies only to those patent claims
73
+ licensable by such Contributor that are necessarily infringed by their
74
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
75
+ to which such Contribution(s) was submitted. If You institute patent litigation
76
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
77
+ alleging that the Work or a Contribution incorporated within the Work
78
+ constitutes direct or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate as of the date
80
+ such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
83
+ Derivative Works thereof in any medium, with or without modifications, and in
84
+ Source or Object form, provided that You meet the following conditions:
85
+
86
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
87
+ this License; and
88
+
89
+ (b) You must cause any modified files to carry prominent notices stating that
90
+ You changed the files; and
91
+
92
+ (c) You must retain, in the Source form of any Derivative Works that You
93
+ distribute, all copyright, patent, trademark, and attribution notices from the
94
+ Source form of the Work, excluding those notices that do not pertain to any part
95
+ of the Derivative Works; and
96
+
97
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
+ any Derivative Works that You distribute must include a readable copy of the
99
+ attribution notices contained within such NOTICE file, excluding those notices
100
+ that do not pertain to any part of the Derivative Works, in at least one of the
101
+ following places: within a NOTICE text file distributed as part of the
102
+ Derivative Works; within the Source form or documentation, if provided along
103
+ with the Derivative Works; or, within a display generated by the Derivative
104
+ Works, if and wherever such third-party notices normally appear. The contents of
105
+ the NOTICE file are for informational purposes only and do not modify the
106
+ License. You may add Your own attribution notices within Derivative Works that
107
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
108
+ provided that such additional attribution notices cannot be construed as
109
+ modifying the License.
110
+
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
118
+ Contribution intentionally submitted for inclusion in the Work by You to the
119
+ Licensor shall be under the terms and conditions of this License, without any
120
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
121
+ supersede or modify the terms of any separate license agreement you may have
122
+ executed with Licensor regarding such Contributions.
123
+
124
+ 6. Trademarks. This License does not grant permission to use the trade names,
125
+ trademarks, service marks, or product names of the Licensor, except as required
126
+ for reasonable and customary use in describing the origin of the Work and
127
+ reproducing the content of the NOTICE file.
128
+
129
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
130
+ writing, Licensor provides the Work (and each Contributor provides its
131
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
132
+ KIND, either express or implied, including, without limitation, any warranties
133
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
134
+ PARTICULAR PURPOSE. You are solely responsible for determining the
135
+ appropriateness of using or redistributing the Work and assume any risks
136
+ associated with Your exercise of permissions under this License.
137
+
138
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
139
+ contract, tort (including negligence), or otherwise, unless required by
140
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
141
+ writing, shall any Contributor be liable to You for damages, including any
142
+ direct, indirect, special, incidental, or consequential damages of any character
143
+ arising as a result of this License or out of the use or inability to use the
144
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
145
+ computer failure or malfunction, or any and all other commercial damages or
146
+ losses), even if such Contributor has been advised of the possibility of such
147
+ damages.
148
+
149
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
150
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
151
+ acceptance of support, warranty, indemnity, or other liability obligations
152
+ and/or rights consistent with this License. However, in accepting such
153
+ obligations, You may act only on Your own behalf and on Your sole responsibility,
154
+ not on behalf of any other Contributor, and only if You agree to indemnify,
155
+ defend, and hold each Contributor harmless for any liability incurred by, or
156
+ claims asserted against, such Contributor by reason of your accepting any such
157
+ warranty or additional liability.
158
+
159
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,85 +1,85 @@
1
- # @design-token-kit/cli
2
-
3
- Command line interface for Design Token Kit.
4
-
5
- It provides commands to:
6
-
7
- - validate design tokens
8
- - convert between DTCG JSON, HRDT YAML, and CSS
9
- - generate HTML showcase pages
10
-
11
- Node.js 18 or newer is required.
12
-
13
- ## Install
14
-
15
- Run without installation:
16
-
17
- ```bash
18
- npx @design-token-kit/cli validate tokens.json
19
- ```
20
-
21
- Install globally:
22
-
23
- ```bash
24
- npm install -g @design-token-kit/cli
25
- dtokens validate tokens.json
26
- ```
27
-
28
- Install as a local dependency:
29
-
30
- ```bash
31
- npm install @design-token-kit/cli
32
- ```
33
-
34
- Show CLI version:
35
-
36
- ```bash
37
- dtokens -v
38
- dtokens --version
39
- ```
40
-
41
- ## Commands
42
-
43
- ### `validate`
44
-
45
- Validate one or more DTCG JSON or HRDT YAML token files.
46
-
47
- ```bash
48
- dtokens validate tokens.json
49
- dtokens validate tokens.yaml
50
- ```
51
-
52
- ### `convert`
53
-
54
- Convert a token file to DTCG JSON, HRDT YAML, or CSS.
55
-
56
- Defaults:
57
-
58
- - `--inform` defaults to `dtcg`
59
- - `--outform` defaults to `css`
60
-
61
- ```bash
62
- dtokens convert tokens.json
63
- dtokens convert tokens.yaml --inform hrdt --outform css --out ./dist/tokens.css
64
- dtokens convert tokens.json --outform hrdt
65
- ```
66
-
67
- Options:
68
-
69
- - `--inform <format>`: input format override, `dtcg` or `hrdt`
70
- - `--outform <format>`: output format, `dtcg`, `hrdt`, or `css`
71
- - `--out <file>`: write output to a file instead of stdout
72
-
73
- ### `showcase`
74
-
75
- Generate an HTML showcase from token files or CSS.
76
-
77
- ```bash
78
- dtokens showcase tokens.yaml --out ./dist/showcase.html
79
- ```
80
-
81
- ## Supported Formats
82
-
83
- - `dtcg` - Design Tokens Community Group JSON format
84
- - `hrdt` - Human-Readable Design Tokens YAML format
85
- - `css` - CSS custom properties output
1
+ # @design-token-kit/cli
2
+
3
+ Command line interface for Design Token Kit.
4
+
5
+ It provides commands to:
6
+
7
+ - validate design tokens
8
+ - convert between DTCG JSON, HRDT YAML, and CSS
9
+ - generate HTML showcase pages
10
+
11
+ Node.js 18 or newer is required.
12
+
13
+ ## Install
14
+
15
+ Run without installation:
16
+
17
+ ```bash
18
+ npx @design-token-kit/cli validate tokens.json
19
+ ```
20
+
21
+ Install globally:
22
+
23
+ ```bash
24
+ npm install -g @design-token-kit/cli
25
+ dtokens validate tokens.json
26
+ ```
27
+
28
+ Install as a local dependency:
29
+
30
+ ```bash
31
+ npm install @design-token-kit/cli
32
+ ```
33
+
34
+ Show CLI version:
35
+
36
+ ```bash
37
+ dtokens -v
38
+ dtokens --version
39
+ ```
40
+
41
+ ## Commands
42
+
43
+ ### `validate`
44
+
45
+ Validate one or more DTCG JSON or HRDT YAML token files.
46
+
47
+ ```bash
48
+ dtokens validate tokens.json
49
+ dtokens validate tokens.yaml
50
+ ```
51
+
52
+ ### `convert`
53
+
54
+ Convert a token file to DTCG JSON, HRDT YAML, or CSS.
55
+
56
+ Defaults:
57
+
58
+ - `--inform` defaults to `dtcg`
59
+ - `--outform` defaults to `css`
60
+
61
+ ```bash
62
+ dtokens convert tokens.json
63
+ dtokens convert tokens.yaml --inform hrdt --outform css --out ./dist/tokens.css
64
+ dtokens convert tokens.json --outform hrdt
65
+ ```
66
+
67
+ Options:
68
+
69
+ - `--inform <format>`: input format override, `dtcg` or `hrdt`
70
+ - `--outform <format>`: output format, `dtcg`, `hrdt`, or `css`
71
+ - `--out <file>`: write output to a file instead of stdout
72
+
73
+ ### `showcase`
74
+
75
+ Generate an HTML showcase from token files or CSS.
76
+
77
+ ```bash
78
+ dtokens showcase tokens.yaml --out ./dist/showcase.html
79
+ ```
80
+
81
+ ## Supported Formats
82
+
83
+ - `dtcg` - Design Tokens Community Group JSON format
84
+ - `hrdt` - Human-Readable Design Tokens YAML format
85
+ - `css` - CSS custom properties output
package/bin/index.mjs CHANGED
@@ -11,9 +11,26 @@ import { Command } from "commander";
11
11
  import {
12
12
  DtcgTokenValidator
13
13
  } from "@design-token-kit/core";
14
+ var EXIT_VALIDATION_ERROR = 2;
15
+ var EXIT_FAILURE = 1;
16
+ var validateCommand = new Command("validate").description("Validate DTCG JSON or HRDT YAML token files.").argument("[files...]", "Paths to DTCG JSON or HRDT YAML token files (reads from stdin when omitted)").addHelpText("after", "\nExit status:\n 0 success\n 1 unexpected error\n 2 validation errors found").action(async (sources) => {
17
+ try {
18
+ const validator = new DtcgTokenValidator();
19
+ const issues = await validator.validate(sources.length > 0 ? sources : ["-"]);
20
+ printIssues(issues);
21
+ if (hasErrors(issues)) {
22
+ process.exit(EXIT_VALIDATION_ERROR);
23
+ }
24
+ console.log("Validation passed.");
25
+ } catch (error) {
26
+ console.error("Validation error:", error.message);
27
+ process.exit(EXIT_FAILURE);
28
+ }
29
+ });
14
30
  function formatIssue(issue) {
31
+ const source = issue.sourcePath === "-" ? "stdin" : issue.sourcePath;
15
32
  const location = issue.line === void 0 ? "" : issue.column === void 0 ? `:${issue.line}` : `:${issue.line}:${issue.column}`;
16
- return `[${issue.name}] ${issue.severity}: ${issue.sourcePath}${location} - ${issue.message}`;
33
+ return `[${issue.name}] ${issue.severity}: ${source}${location} - ${issue.message}`;
17
34
  }
18
35
  function printIssues(issues) {
19
36
  for (const issue of issues) {
@@ -24,24 +41,10 @@ function printIssues(issues) {
24
41
  function hasErrors(issues) {
25
42
  return issues.some((i) => i.severity === "error");
26
43
  }
27
- var validateCommand = new Command("validate").description("Validate DTCG JSON or HRDT YAML token files.").argument("<files...>", "Paths to DTCG JSON or HRDT YAML token files").action(async (sources) => {
28
- try {
29
- const validator = new DtcgTokenValidator();
30
- const issues = await validator.validate(sources);
31
- printIssues(issues);
32
- if (hasErrors(issues)) {
33
- process.exit(2);
34
- }
35
- console.log("Validation passed.");
36
- } catch (error) {
37
- console.error("Validation error:", error.message);
38
- process.exit(1);
39
- }
40
- });
41
44
 
42
45
  // src/commands/convert.ts
43
46
  import { Command as Command2 } from "commander";
44
- import { Source } from "@design-token-kit/core";
47
+ import { DtcgListLoader, DtcgTokenCssConverter as DtcgTokenCssConverter2 } from "@design-token-kit/core";
45
48
  import { writeFile } from "fs/promises";
46
49
 
47
50
  // src/commands/formats.ts
@@ -52,20 +55,9 @@ import {
52
55
  HrdtTokenReader,
53
56
  HrdtTokenWriter
54
57
  } from "@design-token-kit/core";
55
- function getReader(format) {
56
- return readers[toDocumentFormat(format)];
57
- }
58
58
  function getWriter(format) {
59
59
  return writers[toOutputFormat(format)];
60
60
  }
61
- var readers = {
62
- ["dtcg" /* DTCG */]: {
63
- read: (content) => new DtcgJsonReader().parse(content)
64
- },
65
- ["hrdt" /* HRDT */]: {
66
- read: (content) => new HrdtTokenReader().parse(content)
67
- }
68
- };
69
61
  var writers = {
70
62
  ["dtcg" /* DTCG */]: {
71
63
  write: (doc) => new DtcgJsonWriter().write(doc)
@@ -89,23 +81,39 @@ function toOutputFormat(format, fallback = "css" /* CSS */) {
89
81
  }
90
82
 
91
83
  // src/commands/convert.ts
92
- var convertCommand = new Command2("convert").description("Convert a token file to DTCG JSON, HRDT YAML, or CSS.").argument("<file>", "Path to a token file").option("-i, --inform [format]", "Input format: dtcg, hrdt (default: auto-detect)").option("-f, --outform [format]", "Output format: dtcg, hrdt, css (default: css)").option("-o, --out [file]", "Output file (default: stdout)").action(async (file, options) => {
84
+ var EXIT_FAILURE2 = 1;
85
+ var convertCommand = new Command2("convert").description("Convert a token file to DTCG JSON, HRDT YAML, or CSS.").argument("[files...]", "Paths to token files (reads from stdin when omitted or '-')").option("-i, --inform [format]", "Input format: dtcg, hrdt (force all files to this format)").option("-f, --outform [format]", "Output format: dtcg, hrdt, css (default: css)").option("-o, --out [file]", "Output file (default: stdout)").addHelpText("after", "\nExit status:\n 0 success\n 1 conversion failed").action(async (files, options) => {
93
86
  try {
94
- const reader = getReader(options.inform);
95
- const content = await new Source(file).getContent();
96
- const doc = reader.read(content);
97
- const writer = getWriter(options.outform);
98
- const output = writer.write(doc);
99
- if (options.out) {
100
- await writeFile(options.out, output);
101
- } else {
102
- process.stdout.write(output);
103
- }
87
+ const outform = options.outform ?? "css" /* CSS */;
88
+ const forcedFormat = options.inform !== void 0 ? toDocumentFormat(options.inform) : void 0;
89
+ const list = await loadSources(files, forcedFormat);
90
+ const output = convertList(list, outform);
91
+ await writeOutput(output, options.out);
104
92
  } catch (error) {
105
93
  console.error("Conversion failed:", error.message);
106
- process.exit(1);
94
+ process.exit(EXIT_FAILURE2);
107
95
  }
108
96
  });
97
+ async function loadSources(files, forcedFormat) {
98
+ const sources = files.length > 0 ? files : ["-"];
99
+ return new DtcgListLoader().load(sources, forcedFormat);
100
+ }
101
+ function convertList(list, outform) {
102
+ if (outform === "css" /* CSS */) {
103
+ return new DtcgTokenCssConverter2().convertList(list);
104
+ }
105
+ if (list.themes.size > 0) {
106
+ throw new Error(`Multiple files are only supported with --outform css, got ${outform}`);
107
+ }
108
+ return getWriter(outform).write(list.base);
109
+ }
110
+ async function writeOutput(output, out) {
111
+ if (out) {
112
+ await writeFile(out, output);
113
+ } else {
114
+ process.stdout.write(output);
115
+ }
116
+ }
109
117
 
110
118
  // src/commands/showcase.ts
111
119
  import { Command as Command3 } from "commander";
@@ -113,7 +121,29 @@ import { writeFile as writeFile2 } from "fs/promises";
113
121
  import { spawn } from "child_process";
114
122
  import path from "path";
115
123
  import { tmpdir } from "os";
116
- import { Source as Source2, createTokenHtmlShowcase } from "@design-token-kit/core";
124
+ import { Source, createTokenHtmlShowcase } from "@design-token-kit/core";
125
+ var EXIT_FAILURE3 = 1;
126
+ var showcaseCommand = new Command3("showcase").description("Create HTML showcase from DTCG JSON, HRDT YAML, or CSS.").argument("[files...]", "Paths to token JSON, HRDT, or CSS files (reads from stdin when omitted)").option("-o, --out <file>", "Output HTML file name or path").option("--open", "Open the generated HTML in browser (only with --out)").addHelpText("after", "\nExit status:\n 0 success\n 1 showcase failed").action(async (files, options) => {
127
+ try {
128
+ const showcase = createTokenHtmlShowcase();
129
+ const sources = (files.length > 0 ? files : ["-"]).map((f) => new Source(f));
130
+ const filePaths = await Promise.all(sources.map((s) => s.getFile()));
131
+ const html = await showcase.showcase(filePaths);
132
+ if (options.out) {
133
+ const targetFile = resolveOutputPath(options.out);
134
+ await writeFile2(targetFile, html);
135
+ console.log(`Saved HTML to: ${targetFile}`);
136
+ if (options.open) {
137
+ openFile(targetFile);
138
+ }
139
+ } else {
140
+ process.stdout.write(html);
141
+ }
142
+ } catch (error) {
143
+ console.error("Showcase failed:", error.message);
144
+ process.exit(EXIT_FAILURE3);
145
+ }
146
+ });
117
147
  function resolveOutputPath(output) {
118
148
  if (path.isAbsolute(output)) {
119
149
  return output;
@@ -135,25 +165,6 @@ function openFile(filePath) {
135
165
  }
136
166
  spawn("xdg-open", [filePath], { stdio: "ignore", detached: true });
137
167
  }
138
- var showcaseCommand = new Command3("showcase").description("Create HTML showcase from DTCG JSON, HRDT YAML, or CSS.").argument("<files...>", "Paths to token JSON, HRDT, or CSS files").option("-o, --out <file>", "Output HTML file name or path").action(async (files, options) => {
139
- try {
140
- const showcase = createTokenHtmlShowcase();
141
- const sources = files.map((f) => new Source2(f));
142
- const filePaths = await Promise.all(sources.map((s) => s.getFile()));
143
- const html = await showcase.showcase(filePaths);
144
- if (options.out) {
145
- const targetFile = resolveOutputPath(options.out);
146
- await writeFile2(targetFile, html);
147
- console.log(`Saved HTML to: ${targetFile}`);
148
- openFile(targetFile);
149
- } else {
150
- process.stdout.write(html);
151
- }
152
- } catch (error) {
153
- console.error("Showcase failed:", error.message);
154
- process.exit(1);
155
- }
156
- });
157
168
 
158
169
  // src/index.ts
159
170
  var packageJsonPath = path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "../package.json");
@@ -164,9 +175,13 @@ var program = new Command4().name("dtokens").description("CLI for DTCG JSON and
164
175
  Examples:
165
176
  $ dtokens validate tokens.json
166
177
  $ dtokens validate tokens.yaml
178
+ $ dtokens validate tokens.yaml tokens.dark.yaml
179
+ $ dtokens validate - tokens.dark.yaml < tokens.yaml
167
180
  $ dtokens convert tokens.yaml --inform hrdt --outform css --out ./dist/tokens.css
168
181
  $ dtokens convert tokens.json --outform hrdt
182
+ $ dtokens convert --outform css < tokens.yaml
169
183
  $ dtokens showcase tokens.yaml --out ./dist/showcase.html
184
+ $ dtokens showcase - < tokens.yaml
170
185
  ` : "");
171
186
  program.parseAsync(process.argv).catch((error) => {
172
187
  console.error(error instanceof Error ? error.message : error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-token-kit/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for Design Token Kit: validate, convert, showcase.",
5
5
  "keywords": [
6
6
  "design-tokens",
@@ -38,15 +38,17 @@
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsc --noEmit && tsup",
41
- "dist": "node ../scripts/stage-package.mjs cli"
41
+ "dist": "node ../scripts/stage-package.mjs cli",
42
+ "test": "vitest run"
42
43
  },
43
44
  "dependencies": {
44
- "@design-token-kit/core": "0.2.0",
45
+ "@design-token-kit/core": "0.3.0",
45
46
  "commander": "14.0.1"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/node": "24.10.1",
49
50
  "tsup": "8.5.1",
50
- "typescript": "5.9.3"
51
+ "typescript": "5.9.3",
52
+ "vitest": "^4.1.7"
51
53
  }
52
54
  }