@design-token-kit/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -20
- package/bin/index.mjs +14 -35
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@ It provides commands to:
|
|
|
7
7
|
- validate design tokens
|
|
8
8
|
- convert between DTCG JSON, HRDT YAML, and CSS
|
|
9
9
|
- generate HTML showcase pages
|
|
10
|
-
- run round-trip read/write checks
|
|
11
10
|
|
|
12
11
|
Node.js 18 or newer is required.
|
|
13
12
|
|
|
@@ -32,6 +31,13 @@ Install as a local dependency:
|
|
|
32
31
|
npm install @design-token-kit/cli
|
|
33
32
|
```
|
|
34
33
|
|
|
34
|
+
Show CLI version:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
dtokens -v
|
|
38
|
+
dtokens --version
|
|
39
|
+
```
|
|
40
|
+
|
|
35
41
|
## Commands
|
|
36
42
|
|
|
37
43
|
### `validate`
|
|
@@ -41,7 +47,6 @@ Validate one or more DTCG JSON or HRDT YAML token files.
|
|
|
41
47
|
```bash
|
|
42
48
|
dtokens validate tokens.json
|
|
43
49
|
dtokens validate tokens.yaml
|
|
44
|
-
dtokens validate light.json dark.yaml
|
|
45
50
|
```
|
|
46
51
|
|
|
47
52
|
### `convert`
|
|
@@ -55,9 +60,7 @@ Defaults:
|
|
|
55
60
|
|
|
56
61
|
```bash
|
|
57
62
|
dtokens convert tokens.json
|
|
58
|
-
dtokens convert tokens.
|
|
59
|
-
dtokens convert tokens.yaml --inform hrdt --outform css
|
|
60
|
-
dtokens convert tokens.yaml --inform hrdt --outform dtcg
|
|
63
|
+
dtokens convert tokens.yaml --inform hrdt --outform css --out ./dist/tokens.css
|
|
61
64
|
dtokens convert tokens.json --outform hrdt
|
|
62
65
|
```
|
|
63
66
|
|
|
@@ -72,21 +75,7 @@ Options:
|
|
|
72
75
|
Generate an HTML showcase from token files or CSS.
|
|
73
76
|
|
|
74
77
|
```bash
|
|
75
|
-
dtokens showcase tokens.
|
|
76
|
-
dtokens showcase tokens.css --out showcase.html
|
|
77
|
-
dtokens showcase tokens.json --out showcase.html
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### `test`
|
|
81
|
-
|
|
82
|
-
Load a token file, build the internal model, and print it back in the same or
|
|
83
|
-
requested format.
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
dtokens test tokens.json
|
|
87
|
-
dtokens test tokens.yaml
|
|
88
|
-
dtokens test tokens.yaml --outform hrdt
|
|
89
|
-
dtokens test tokens.json --outform dtcg
|
|
78
|
+
dtokens showcase tokens.yaml --out ./dist/showcase.html
|
|
90
79
|
```
|
|
91
80
|
|
|
92
81
|
## Supported Formats
|
package/bin/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command4 } from "commander";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
6
|
+
import path2 from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
5
8
|
|
|
6
9
|
// src/commands/validate.ts
|
|
7
10
|
import { Command } from "commander";
|
|
@@ -21,7 +24,7 @@ function printIssues(issues) {
|
|
|
21
24
|
function hasErrors(issues) {
|
|
22
25
|
return issues.some((i) => i.severity === "error");
|
|
23
26
|
}
|
|
24
|
-
var validateCommand = new Command("validate").description("Validate DTCG JSON or HRDT YAML token files.").argument("<
|
|
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) => {
|
|
25
28
|
try {
|
|
26
29
|
const validator = new DtcgTokenValidator();
|
|
27
30
|
const issues = await validator.validate(sources);
|
|
@@ -49,21 +52,12 @@ import {
|
|
|
49
52
|
HrdtTokenReader,
|
|
50
53
|
HrdtTokenWriter
|
|
51
54
|
} from "@design-token-kit/core";
|
|
52
|
-
function detectDocumentFormat(file) {
|
|
53
|
-
return /\.(ya?ml)$/i.test(file) ? "hrdt" /* HRDT */ : "dtcg" /* DTCG */;
|
|
54
|
-
}
|
|
55
55
|
function getReader(format) {
|
|
56
56
|
return readers[toDocumentFormat(format)];
|
|
57
57
|
}
|
|
58
58
|
function getWriter(format) {
|
|
59
59
|
return writers[toOutputFormat(format)];
|
|
60
60
|
}
|
|
61
|
-
function getRoundTripWriter(format, file) {
|
|
62
|
-
return writers[toDocumentFormat(format, detectDocumentFormat(file))];
|
|
63
|
-
}
|
|
64
|
-
function getDetectedReader(file) {
|
|
65
|
-
return readers[detectDocumentFormat(file)];
|
|
66
|
-
}
|
|
67
61
|
var readers = {
|
|
68
62
|
["dtcg" /* DTCG */]: {
|
|
69
63
|
read: (content) => new DtcgJsonReader().parse(content)
|
|
@@ -95,7 +89,7 @@ function toOutputFormat(format, fallback = "css" /* CSS */) {
|
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
// src/commands/convert.ts
|
|
98
|
-
var convertCommand = new Command2("convert").description("Convert
|
|
92
|
+
var convertCommand = new Command2("convert").description("Convert a token file to DTCG JSON, HRDT YAML, or CSS.").argument("<file>", "Path to a token JSON or HRDT file").option("-i, --inform <format>", "Input format override: dtcg, hrdt").option("-f, --outform <format>", "Output format: dtcg, hrdt, css (default: css)").option("-o, --out <file>", "Output file").action(async (file, options) => {
|
|
99
93
|
try {
|
|
100
94
|
const reader = getReader(options.inform);
|
|
101
95
|
const content = await new Source(file).getContent();
|
|
@@ -161,35 +155,20 @@ var showcaseCommand = new Command3("showcase").description("Create HTML showcase
|
|
|
161
155
|
}
|
|
162
156
|
});
|
|
163
157
|
|
|
164
|
-
// src/commands/test.ts
|
|
165
|
-
import { Command as Command4 } from "commander";
|
|
166
|
-
import { Source as Source3 } from "@design-token-kit/core";
|
|
167
|
-
var testCommand = new Command4("test").description("Load a DTCG JSON or HRDT YAML file, build the model, and print it back (round-trip check).").argument("<file>", "Path to a DTCG JSON or HRDT file").option("-f, --outform <format>", "Output format: dtcg, hrdt (default: same as input)").action(async (file, options) => {
|
|
168
|
-
try {
|
|
169
|
-
const reader = getDetectedReader(file);
|
|
170
|
-
const writer = getRoundTripWriter(options.outform, file);
|
|
171
|
-
const content = await new Source3(file).getContent();
|
|
172
|
-
const doc = reader.read(content);
|
|
173
|
-
process.stdout.write(writer.write(doc));
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error(`Error: ${error.message}`);
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
158
|
// src/index.ts
|
|
181
|
-
var
|
|
159
|
+
var packageJsonPath = path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "../package.json");
|
|
160
|
+
var packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
161
|
+
var versionArgs = /* @__PURE__ */ new Set(["-v", "--version"]);
|
|
162
|
+
if (process.argv.length === 3 && versionArgs.has(process.argv[2])) {
|
|
163
|
+
console.log(packageJson.version);
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
var program = new Command4().name("dtokens").description("CLI for DTCG JSON and HRDT YAML: validate, convert, showcase.").helpCommand(false).option("-v, --version", "display version").addCommand(validateCommand).addCommand(convertCommand).addCommand(showcaseCommand).addHelpText("after", ({ command }) => command.name() === "dtokens" ? `
|
|
182
167
|
Examples:
|
|
183
|
-
$ dtokens test tokens.json
|
|
184
168
|
$ dtokens validate tokens.json
|
|
185
169
|
$ dtokens validate tokens.yaml
|
|
186
|
-
$ dtokens validate tokens.json tokens.dark.yaml --engine ajv
|
|
187
170
|
$ dtokens convert tokens.yaml --inform hrdt --outform css --out ./dist/tokens.css
|
|
188
|
-
$ dtokens convert tokens.yaml --outform dtcg
|
|
189
171
|
$ dtokens convert tokens.json --outform hrdt
|
|
190
|
-
$ dtokens showcase tokens.yaml
|
|
191
|
-
$ dtokens showcase tokens.css
|
|
192
|
-
$ dtokens showcase tokens.yaml --out out.html
|
|
193
172
|
$ dtokens showcase tokens.yaml --out ./dist/showcase.html
|
|
194
173
|
` : "");
|
|
195
174
|
program.parseAsync(process.argv).catch((error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design-token-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "CLI for Design Token Kit: validate, convert, showcase.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-tokens",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist": "node ../scripts/stage-package.mjs cli"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@design-token-kit/core": "0.1.
|
|
44
|
+
"@design-token-kit/core": "0.1.2",
|
|
45
45
|
"commander": "14.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|