@x12i/kit-cli 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -9,41 +9,111 @@ npx @x12i/kit-cli doctor
9
9
  | Command | Status |
10
10
  | --- | --- |
11
11
  | `kit init` | Writes `kit.config.json` (`--theme`, `--density`, `--force`). |
12
- | `kit doctor [paths...]` | Finds hard-coded hex colors in CSS, TS, JS, HTML, Vue, Svelte and MDX files. Exits with 1 when it finds any, so it can gate CI. |
12
+ | `kit doctor [paths...]` | Checks CSS, SCSS, TS, JS, HTML, Vue, Svelte and MDX files against the kit's conventions: tokens instead of hard-coded values, restrained motion, logical properties, visible focus. Exits with 1 on an error, or on any finding with `--strict`, so it can gate CI. |
13
+ | `kit design` | Writes a `DESIGN.md` that tells a coding agent what the kit looks like (`--theme`, `--out`, `--force`). |
13
14
  | `kit theme [name]` | Lists the built-in themes and densities. Generating a theme is planned. |
14
15
  | `kit add <component...>` | Stub. The component registry is planned, so it exits with 1 and says so. |
15
16
 
16
17
  Exit codes: `0` success, `1` the command ran and found a problem, `2` bad usage
17
- (unknown command, option, theme or path).
18
+ (unknown command, option, theme, rule or path).
18
19
 
19
20
  ## doctor
20
21
 
21
- `kit doctor` is a minimal scan. It finds `#rgb`, `#rgba`, `#rrggbb` and
22
- `#rrggbbaa` values. It skips `node_modules`, `dist`, `build`, `coverage` and
23
- other build folders, minified files and `.d.ts` files. It does not flag URL
24
- fragments, `href="#anchor"` links or HTML entities.
22
+ ```sh
23
+ kit doctor src # scan a folder
24
+ kit doctor --strict # a warning also fails the run
25
+ kit doctor --json # findings as JSON
26
+ kit doctor --list-rules # every rule, its default severity and what it checks
27
+ ```
28
+
29
+ Each line is `file:line:col match message (severity rule)`, and the run ends
30
+ with a count of errors and warnings. A hard-coded hex color is an **error**, as it
31
+ always was. Every other rule is a **warning** by default, so adding the new rules
32
+ to an existing project does not turn a passing build red.
33
+
34
+ | Group | Rules |
35
+ | --- | --- |
36
+ | Tokens | `hardcoded-color` (error), `hardcoded-color-function`, `hardcoded-font-size`, `hardcoded-font-family`, `hardcoded-spacing`, `hardcoded-radius` |
37
+ | Motion | `hardcoded-duration`, `hardcoded-easing`, `bounce-easing`, `transition-all`, `layout-animation`, `missing-reduced-motion` |
38
+ | Layout and focus | `physical-property`, `outline-none`, `important` |
39
+
40
+ A value that uses a token is fine, and so is a mix such as
41
+ `calc(var(--kit-space-2) * 3)`. The scan reads CSS declarations, `<style>` blocks
42
+ and `style` attributes in markup, template literals, and string values in style
43
+ objects. It skips `node_modules`, `dist`, `build`, `coverage` and other build
44
+ folders, minified files and `.d.ts` files, and it does not flag URL fragments,
45
+ `href="#anchor"` links or HTML entities.
46
+
47
+ Some limits to know about:
48
+
49
+ - `left` and `right` with a percentage (`left: 50%`) are not flagged. Centering and
50
+ anchoring use them with a physical `translate`, and the logical twin would break
51
+ in right to left.
52
+ - `physical-property` is not reported inside a selector that names a side
53
+ (`.panel.left`, `.handle-right`, `[data-side="left"]`, `.text-left`), because
54
+ that code places things on that side on purpose.
55
+ - `missing-reduced-motion` is one finding for the whole scan: it fires when
56
+ something animates and no scanned file handles `prefers-reduced-motion`.
57
+ - It reads text. It does not resolve imports or compute styles, so a value built
58
+ at runtime is not seen.
25
59
 
26
- - Add `kit-ignore` to a line (in a comment) to keep a color on purpose, such as a
27
- brand logo.
28
- - List paths to skip in `kit.config.json`:
60
+ Configure it in `kit.config.json`. A rule is `"off"`, `"warn"` or `"error"`:
29
61
 
30
62
  ```json
31
63
  {
32
64
  "version": 1,
33
65
  "theme": "light",
34
66
  "density": "default",
35
- "doctor": { "ignore": ["legacy", "src/vendor"] }
67
+ "doctor": {
68
+ "ignore": ["legacy", "src/vendor"],
69
+ "rules": {
70
+ "physical-property": "off",
71
+ "hardcoded-spacing": "error"
72
+ }
73
+ }
36
74
  }
37
75
  ```
38
76
 
39
- - `--json` prints the findings as JSON.
77
+ - Add `kit-ignore` to a line (in a comment) to keep a value on purpose, such as a
78
+ brand logo color.
79
+ - `ignore` lists paths to skip, for example generated files.
80
+ - `--json` prints an array of findings. Each has `file`, `line`, `column`,
81
+ `match`, `rule`, `severity` and `message`.
40
82
 
41
- Spacing, font sizes and `rgb()` or `hsl()` colors are not scanned yet.
83
+ The text output has more on each line than it used to. Parse `--json`, not the
84
+ text.
85
+
86
+ ## design
87
+
88
+ `kit design` writes the kit's `DESIGN.md` into your project, so a coding agent
89
+ that reads it builds with the kit's colors, type, spacing and motion instead of
90
+ inventing its own. It follows the [DESIGN.md format](https://github.com/google-labs-code/design.md)
91
+ and is generated from the same tokens as the CSS, so it cannot drift from them.
92
+
93
+ ```sh
94
+ kit design # writes ./DESIGN.md, using the theme in kit.config.json
95
+ kit design --theme dark
96
+ kit design --out docs/DESIGN.md
97
+ kit design --out - # print instead of writing
98
+ ```
99
+
100
+ It will not overwrite a file that exists unless you pass `--force`. The file ends
101
+ by telling the agent to run `kit doctor` before it finishes, which is what catches
102
+ the values an agent hard-codes anyway.
42
103
 
43
104
  ## API
44
105
 
45
106
  ```ts
46
- import { scanForHardcodedColors } from "@x12i/kit-cli";
107
+ import { scanForHardcodedColors, scanProject, RULES } from "@x12i/kit-cli";
47
108
 
48
- const findings = await scanForHardcodedColors(process.cwd(), ["src"]);
109
+ // The original scan: hex colors only.
110
+ const colors = await scanForHardcodedColors(process.cwd(), ["src"]);
111
+
112
+ // Every rule. Pass `rules` to change severities and `ignore` to skip paths.
113
+ const findings = await scanProject(process.cwd(), ["src"], {
114
+ rules: { "physical-property": "off" },
115
+ });
49
116
  ```
117
+
118
+ The same text is available from code as `createDesignMd({ theme })` in
119
+ `@x12i/tokens/design-md`.