@ucm-kit/cli 0.1.40 → 0.1.42
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 +241 -233
- package/package.json +2 -2
- package/src/init.mjs +13 -4
- package/src/ucm.mjs +5 -0
package/README.md
CHANGED
|
@@ -7,71 +7,199 @@ A **UCM contract** is a JSON file describing a UI component exactly as it exists
|
|
|
7
7
|
in Figma: its variants, its structure, its design tokens, its usage rules. It is
|
|
8
8
|
written by the [UCM Contract
|
|
9
9
|
Exporter](https://github.com/Vassili-g/UCM-Exporter) Figma plugin and committed
|
|
10
|
-
next to the component's code. This command reads those files and
|
|
11
|
-
they
|
|
10
|
+
next to the component's code. This command reads those files and reports
|
|
11
|
+
whether they are valid, whether their references resolve, and whether the code
|
|
12
|
+
matches them.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
Requires Node 20 or later. At the root of the repository:
|
|
12
17
|
|
|
13
18
|
```sh
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
15
|
-
npx --yes @ucm-kit/cli@0.1.40 check --report ci-report.md
|
|
19
|
+
npx --yes @ucm-kit/cli@0.1.42 init
|
|
16
20
|
```
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
1. Commit and push the files `init` wrote.
|
|
23
|
+
2. Make the check block merges: see [GitHub](#github) or [GitLab](#gitlab).
|
|
24
|
+
3. Give the repository URL to the designer, who enters it in the Figma plugin
|
|
25
|
+
with an access token.
|
|
26
|
+
|
|
27
|
+
To run the check locally:
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
```sh
|
|
30
|
+
npx --yes @ucm-kit/cli@0.1.42 check --report ci-report.md
|
|
31
|
+
```
|
|
23
32
|
|
|
24
|
-
`
|
|
25
|
-
|
|
26
|
-
only requirement is Node, and in CI `setup-node` provides it.
|
|
33
|
+
`--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
|
|
34
|
+
a range lets npx install a build this project has not tested.
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
**The repository does not have to be a Node project.** The workflow `ucm init`
|
|
37
|
+
writes needs no `package.json`, so an iOS or Android repository, or a plain
|
|
38
|
+
folder of contracts, can have its exports checked. When a `package-lock.json`
|
|
39
|
+
exists, the workflow runs `npm ci` first, so `ucm check` finds a stack adapter
|
|
40
|
+
the repository installed.
|
|
31
41
|
|
|
32
42
|
## Commands
|
|
33
43
|
|
|
34
44
|
| Command | What it does |
|
|
35
45
|
|---|---|
|
|
36
|
-
| `ucm init` | Installs what the repository is missing, never overwriting a file that already exists |
|
|
37
|
-
| `ucm check` | Checks every contract and renders the report |
|
|
46
|
+
| [`ucm init`](#ucm-init) | Installs what the repository is missing, never overwriting a file that already exists |
|
|
47
|
+
| [`ucm check`](#ucm-check) | Checks every contract and renders the report |
|
|
38
48
|
| `ucm icons` | Lists the icons the contracts ask this repository to draw |
|
|
39
|
-
| `ucm tokens css --out <file>` | Writes the CSS stylesheet of the tokens and their modes |
|
|
40
|
-
| `ucm aides [<aide>]` | Lists the implementation guides, or prints one |
|
|
41
|
-
| `ucm guide <contract>` | Prints what an agent reads before implementing that contract |
|
|
42
|
-
| `ucm rapport-gitlab` | Posts the report as a note on a GitLab merge request |
|
|
43
|
-
| `ucm --help` | Prints
|
|
49
|
+
| [`ucm tokens css --out <file>`](#the-token-stylesheet) | Writes the CSS stylesheet of the tokens and their modes |
|
|
50
|
+
| [`ucm aides [<aide>]`](#implementation-guides) | Lists the implementation guides, or prints one |
|
|
51
|
+
| [`ucm guide <contract>`](#the-guide-of-a-contract) | Prints what an agent reads before implementing that contract |
|
|
52
|
+
| [`ucm rapport-gitlab`](#gitlab) | Posts the report as a note on a GitLab merge request |
|
|
53
|
+
| `ucm --help` | Prints every command and option |
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
Every command exits with the same codes:
|
|
46
56
|
|
|
47
|
-
|
|
|
57
|
+
| Code | Meaning |
|
|
48
58
|
|---|---|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
|
|
61
|
-
`--implementation`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
| `0` | The command did what it was asked |
|
|
60
|
+
| `1` | Checks failed |
|
|
61
|
+
| `2` | The invocation or the configuration is at fault |
|
|
62
|
+
|
|
63
|
+
A faulty invocation never exits with `1`, so it cannot pass for failed checks.
|
|
64
|
+
|
|
65
|
+
## `ucm init`
|
|
66
|
+
|
|
67
|
+
| Option | Default | Effect |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `--components <dir>` | `components` | The folder the contracts are stored under |
|
|
70
|
+
| `--tokens <dir>` | the repository root | The folder that holds `tokens.json` |
|
|
71
|
+
| `--implementation <pattern>` | `{dir}/{id}.tsx` | The file that implements a contract: `{dir}` is the contract's folder, `{id}` its identifier |
|
|
72
|
+
| `--forge github\|gitlab` | detected, see below | The forge whose CI is written |
|
|
73
|
+
| `--sans-agents` | off | Writes neither the agent relays, nor `.ucm/conventions.md`, nor the templates |
|
|
74
|
+
|
|
75
|
+
`--tokens` takes a folder, and `ucm.config.json` stores the file path
|
|
76
|
+
`<dir>/tokens.json`. `--implementation` must contain `{id}`; without it, every
|
|
77
|
+
contract would resolve to the same file. A repository that does not write React
|
|
78
|
+
states its own extension:
|
|
65
79
|
|
|
66
80
|
```sh
|
|
67
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
81
|
+
npx --yes @ucm-kit/cli@0.1.42 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
|
|
68
82
|
```
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
The three path options act only on a first install. `ucm init` never overwrites
|
|
85
|
+
an existing `ucm.config.json`, and says so when options were passed. To change
|
|
86
|
+
a path later, edit that file.
|
|
87
|
+
|
|
88
|
+
Without `--forge`, the host of the `origin` remote decides, then the presence of
|
|
89
|
+
`.gitlab-ci.yml`, and GitHub otherwise. The command names the forge and the
|
|
90
|
+
signal it followed.
|
|
91
|
+
|
|
92
|
+
### What it writes
|
|
93
|
+
|
|
94
|
+
Five control files, then what an agent needs, unless `--sans-agents` is passed.
|
|
95
|
+
The command explains each file as it writes it. An existing file is kept as it
|
|
96
|
+
is, and the command names what it left alone.
|
|
97
|
+
|
|
98
|
+
| File | Why |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `ucm.config.json` | Where the contracts, the tokens and the implementations live |
|
|
101
|
+
| `.gitattributes` | Keeps contracts and tokens in LF, so a re-export from a Windows machine does not produce a whole-file diff |
|
|
102
|
+
| `.vscode/settings.json` | Binds `*.contract.json` to the JSON Schema of the installed package, so the editor validates as you read |
|
|
103
|
+
| `.gitignore` | Keeps `ci-report.md` out of the repository; it is regenerated on every run |
|
|
104
|
+
| `.github/workflows/ucm.yml` | Runs the check on every pull request and posts the report as a comment. On GitLab, `.gitlab/ucm.gitlab-ci.yml` and `.gitlab-ci.yml` replace it |
|
|
105
|
+
| `.agents/skills/ucm-implementer/SKILL.md`, `.claude/skills/ucm-implementer/SKILL.md` | Two identical relays: an agent loads one before writing a component, and runs `ucm guide` at the pinned version |
|
|
106
|
+
| `.ucm/conventions.md` | The repository's stack and writings, with its instructions in a comment |
|
|
107
|
+
| `.ucm/gabarits/` | The templates of the installed stack adapter, when it publishes some |
|
|
108
|
+
|
|
109
|
+
The workflow is yours once written, and `ucm init` never rewrites it.
|
|
110
|
+
|
|
111
|
+
The command then prints the lines it does not write, each with its file:
|
|
112
|
+
`@ucm-kit/cli` in `devDependencies`, `ucm tokens css` at the head of the `dev`
|
|
113
|
+
and `build` scripts, the import of the generated stylesheet, and the optional
|
|
114
|
+
`modes` section when `tokens.json` declares axes. A line already present is not
|
|
115
|
+
printed. An installed adapter that fails to load is reported, and the rest is
|
|
116
|
+
installed.
|
|
117
|
+
|
|
118
|
+
### `ucm.config.json`
|
|
119
|
+
|
|
120
|
+
**This file is the only authority on where an export lands.** The Figma plugin
|
|
121
|
+
reads it before publishing, and `ucm check` reads it before looking for
|
|
122
|
+
contracts. Without the file, the defaults below apply on both sides. A file that
|
|
123
|
+
exists but is malformed is refused on both sides.
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"components": "components",
|
|
128
|
+
"tokens": "tokens.json",
|
|
129
|
+
"implementation": "{dir}/{id}.tsx"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Each path is relative to the repository root and written with `/`. A path that
|
|
134
|
+
starts with `/` or a drive letter, contains `\`, or has an empty, `.` or `..`
|
|
135
|
+
segment is refused: the plugin would write outside the repository with the
|
|
136
|
+
designer's token, and the check would read outside it.
|
|
137
|
+
|
|
138
|
+
The file holds no version number. The installed package decides which contract
|
|
139
|
+
versions it reads.
|
|
140
|
+
|
|
141
|
+
### GitHub
|
|
142
|
+
|
|
143
|
+
The workflow runs on every pull request and on every push to `main`. If the
|
|
144
|
+
default branch has another name, change it in `.github/workflows/ucm.yml`.
|
|
145
|
+
|
|
146
|
+
Its `contrats` job runs the check with read-only permissions. Its `commentaire`
|
|
147
|
+
job runs no code from the repository: it receives the report as an artifact
|
|
148
|
+
and posts it, replacing its previous comment.
|
|
149
|
+
|
|
150
|
+
A red check blocks a merge only when the base branch requires the `contrats`
|
|
151
|
+
status check, in a branch protection rule or a ruleset. GitHub offers these on
|
|
152
|
+
public repositories and on paid plans. Without that setting, the report
|
|
153
|
+
announces a blocked merge that is not blocked.
|
|
73
154
|
|
|
74
|
-
|
|
155
|
+
### GitLab
|
|
156
|
+
|
|
157
|
+
`init --forge gitlab` writes `.gitlab/ucm.gitlab-ci.yml`, two jobs with no
|
|
158
|
+
global key, so the project's other jobs keep their rules. `ucm` runs the check
|
|
159
|
+
in merge request pipelines and on the default branch; `ucm-rapport` posts the
|
|
160
|
+
note in merge request pipelines. Both take the default `test` stage. A new
|
|
161
|
+
`.gitlab-ci.yml` includes the file; an existing one is left alone, and the
|
|
162
|
+
command prints the `include` line to add. It also prints three settings it
|
|
163
|
+
cannot make:
|
|
164
|
+
|
|
165
|
+
- create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
|
|
166
|
+
holding an `api` token of an account with the Reporter role on this project
|
|
167
|
+
only: a service account's personal token, or a project access token where
|
|
168
|
+
the GitLab plan offers one. Export branches are not protected, so a
|
|
169
|
+
protected variable would be empty there. Every pipeline of every branch reads
|
|
170
|
+
an unprotected variable, and any user who can push a branch can print it: the
|
|
171
|
+
Reporter role limits that token to reading and commenting;
|
|
172
|
+
- tick "Pipelines must succeed" in the merge request settings. Without it, a red
|
|
173
|
+
report does not block the merge it says is blocked;
|
|
174
|
+
- keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
|
|
175
|
+
pipeline whose job names a missing stage.
|
|
176
|
+
|
|
177
|
+
`ucm` unsets `UCM_GITLAB_TOKEN` before `npm ci`, so install scripts do not
|
|
178
|
+
inherit it on executors that set variables in the job script. `ucm-rapport`
|
|
179
|
+
runs no code from the repository: it clones nothing, receives `ci-report.md`
|
|
180
|
+
as an artifact, disables install scripts, and runs `npx` from an empty
|
|
181
|
+
directory. It writes a minimal report when the check stopped before writing
|
|
182
|
+
one, then posts the report:
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
npx --yes @ucm-kit/cli@0.1.42 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Option | Effect |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `--projet <id>` | The GitLab project, by identifier or path |
|
|
191
|
+
| `--merge-request <iid>` | The merge request number within that project |
|
|
192
|
+
| `--fichier <path>` | The report written by `ucm check --report` |
|
|
193
|
+
| `--api <url>` | The GitLab API; `https://gitlab.com/api/v4` by default |
|
|
194
|
+
|
|
195
|
+
The command reads the token from `UCM_GITLAB_TOKEN` and never prints it. It
|
|
196
|
+
replaces the note that the token's account wrote with the `<!-- ucm-rapport -->`
|
|
197
|
+
marker, and creates one otherwise. Without the variable it says so and exits
|
|
198
|
+
with `0`: the report stays in the job artifacts. A refused token exits with `1`
|
|
199
|
+
and names the fix. The job allows failure, so a refused token leaves the
|
|
200
|
+
pipeline the colour of the check.
|
|
201
|
+
|
|
202
|
+
## `ucm check`
|
|
75
203
|
|
|
76
204
|
| Option | Effect |
|
|
77
205
|
|---|---|
|
|
@@ -82,15 +210,57 @@ The report stops before 65,536 characters, the size of a GitHub comment, and
|
|
|
82
210
|
says so in its last line. The verdict opens the report and is never cut; the
|
|
83
211
|
terminal output keeps every detail.
|
|
84
212
|
|
|
85
|
-
###
|
|
213
|
+
### What the report says
|
|
86
214
|
|
|
87
|
-
|
|
215
|
+
The report is written for the **designer** who validates the export. Every
|
|
216
|
+
reason a merge is refused appears in it, so the designer never opens a CI log.
|
|
217
|
+
|
|
218
|
+
Six checks run on each contract. **A check blocks when the file on disk cannot
|
|
219
|
+
be read as it stands**, and warns when the read succeeds and the gap points at
|
|
220
|
+
the code or at the token file.
|
|
221
|
+
|
|
222
|
+
| Check | Verdict |
|
|
88
223
|
|---|---|
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
224
|
+
| The contract is readable and complete | Blocks |
|
|
225
|
+
| This repository can read that contract version | Blocks |
|
|
226
|
+
| Composition: every nested component has its own contract, the lists agree, no cycles | Blocks |
|
|
227
|
+
| Typography tokens have the expected type | Blocks |
|
|
228
|
+
| Every `{token.path}` cited exists in the token file | Warns, but a missing or unreadable token file blocks |
|
|
229
|
+
| The code exposes the props the contract declares, with a stack adapter installed | Warns |
|
|
92
230
|
|
|
93
|
-
|
|
231
|
+
The direction of a version gap names who fixes it. A contract that is too old
|
|
232
|
+
is re-exported by the designer. A contract that is too new needs this package
|
|
233
|
+
upgraded by a developer.
|
|
234
|
+
|
|
235
|
+
Before any contract, the check reads the format version at the root of the
|
|
236
|
+
token file. A version newer than this package reads blocks the merge, and a
|
|
237
|
+
developer upgrades the UCM packages. A mark that is not a version blocks too,
|
|
238
|
+
and the designer runs the token export again. Both apply even in a repository
|
|
239
|
+
with no contract yet.
|
|
240
|
+
|
|
241
|
+
A gap with the code warns: a developer closes it, and the merge goes through. A
|
|
242
|
+
token removed from the design system warns too, so an older contract does not
|
|
243
|
+
hold back the tokens. A contract may land before the code that implements it.
|
|
244
|
+
|
|
245
|
+
A repository with no contract passes. Right after `ucm init`, `ucm check`
|
|
246
|
+
returns `0` and reports the next step. From the first contract on, a missing
|
|
247
|
+
token file blocks the merge.
|
|
248
|
+
|
|
249
|
+
The report also relays the warnings the export wrote into the contract, and the
|
|
250
|
+
verdict of the repository's own tests when an orchestrator passes it in through
|
|
251
|
+
the `UCM_ECHECS_DE_TESTS` environment variable, a JSON object with `echoue` and
|
|
252
|
+
`echecs`.
|
|
253
|
+
|
|
254
|
+
### Optional stack adapters
|
|
255
|
+
|
|
256
|
+
The first five checks read contracts and tokens only, whatever the repository
|
|
257
|
+
is written in. Comparing a contract to real code needs a stack adapter.
|
|
258
|
+
|
|
259
|
+
`ucm check` discovers an adapter installed **by the repository**, resolving from
|
|
260
|
+
the checked root rather than from the npx cache. Install
|
|
261
|
+
[`@ucm-kit/adapter-typescript`](https://www.npmjs.com/package/@ucm-kit/adapter-typescript)
|
|
262
|
+
for prop and composition parity in TypeScript projects. Without an adapter, the
|
|
263
|
+
report says the implementation was not read, and never that it is conformant.
|
|
94
264
|
|
|
95
265
|
## The token stylesheet
|
|
96
266
|
|
|
@@ -103,10 +273,16 @@ names and writes one custom property per token. Each property is named by
|
|
|
103
273
|
npx --no-install ucm tokens css --out src/generated/tokens.css
|
|
104
274
|
```
|
|
105
275
|
|
|
106
|
-
|
|
276
|
+
`--no-install` runs the version pinned in `devDependencies`. Run the command
|
|
277
|
+
before `dev` and `build`, in place of any other generator of the same
|
|
107
278
|
stylesheet, and import the generated file once, from the application's CSS
|
|
108
279
|
entry point.
|
|
109
280
|
|
|
281
|
+
| Option | Effect |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `--out <file>` | The stylesheet to write. Required |
|
|
284
|
+
| `--sans-modes` | Writes the default value of every token, for a token file exported before axes were declared |
|
|
285
|
+
|
|
110
286
|
**Modes are attributes.** Each axis of `tokens.json`, one per Figma collection
|
|
111
287
|
with several modes, is selected by an HTML attribute on any element: its
|
|
112
288
|
subtree takes that mode, and removing the attribute gives back the mode
|
|
@@ -121,7 +297,7 @@ the command prints it. A repository names another one in `ucm.config.json`:
|
|
|
121
297
|
```
|
|
122
298
|
|
|
123
299
|
Two axes with the same set of modes may share an attribute. A component reads
|
|
124
|
-
tokens and never declares
|
|
300
|
+
tokens and never declares an attribute, so any ancestor can switch its mode.
|
|
125
301
|
|
|
126
302
|
A collection that Figma extended collections override, an experimental reading,
|
|
127
303
|
adds the axis `<axis>-extensions`: its attribute takes `base` for the collection
|
|
@@ -136,11 +312,11 @@ correct stylesheet: an alias to a missing token, two token paths that give the
|
|
|
136
312
|
same property, two extension names that give the same CSS name, an alias cycle
|
|
137
313
|
that a context can reach, an alias whose type changes in a mode or an extension,
|
|
138
314
|
or modes the export did not attach to an axis. A key of `modes` that names no
|
|
139
|
-
axis of the token file exits with `2`. The previous
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
315
|
+
axis of the token file exits with `2`. The previous stylesheet stays in place. A
|
|
316
|
+
token file exported before axes were declared is refused with that reason, and
|
|
317
|
+
`--sans-modes` applies until the tokens are exported again. Without a token
|
|
318
|
+
file, the command writes an empty stylesheet when no contract cites a token, and
|
|
319
|
+
refuses otherwise.
|
|
144
320
|
|
|
145
321
|
## Implementation guides
|
|
146
322
|
|
|
@@ -177,15 +353,17 @@ guide. `ecritures-par-defaut: non` on the first line prints meanings only, for a
|
|
|
177
353
|
repository that writes no CSS.
|
|
178
354
|
|
|
179
355
|
`ucm aides <aide> --personnaliser [<path>]` appends that guide's section, with
|
|
180
|
-
its default writing to edit, to the
|
|
181
|
-
section, and the command refuses it. The marker records the
|
|
182
|
-
fingerprint of the copied writing: when the default writing
|
|
183
|
-
and `ucm guide` name the section to read again, and a
|
|
184
|
-
fingerprint is named as well. An existing section is never
|
|
356
|
+
its default writing to edit, to the conventions file closest to `<path>`.
|
|
357
|
+
`composant` has no section, and the command refuses it. The marker records the
|
|
358
|
+
version and a fingerprint of the copied writing: when the default writing
|
|
359
|
+
changes, `ucm aides` and `ucm guide` name the section to read again, and a
|
|
360
|
+
marker without a fingerprint is named as well. An existing section is never
|
|
361
|
+
overwritten.
|
|
185
362
|
|
|
186
363
|
## The guide of a contract
|
|
187
364
|
|
|
188
|
-
`ucm guide <contract> [--out <file>]` prints, in one Markdown document
|
|
365
|
+
`ucm guide <contract> [--out <file>]` prints, in one Markdown document, or
|
|
366
|
+
writes to `<file>`:
|
|
189
367
|
|
|
190
368
|
1. what to read again first: conventions anomalies, copied sections whose
|
|
191
369
|
default writing changed, and `@ucm-kit/cli` pins that differ between the two
|
|
@@ -207,176 +385,6 @@ The command exits with `1` when the composition graph or the token file is
|
|
|
207
385
|
inconsistent, and with `2` for an invocation, a configuration or a contract it
|
|
208
386
|
cannot read, a contract version outside its reading window included.
|
|
209
387
|
|
|
210
|
-
## What `ucm init` writes
|
|
211
|
-
|
|
212
|
-
Five control files, then what an agent needs, unless `--sans-agents` is passed.
|
|
213
|
-
The command explains each one as it writes it. An existing file is kept as it
|
|
214
|
-
is, and the command names what it left alone.
|
|
215
|
-
|
|
216
|
-
| File | Why |
|
|
217
|
-
|---|---|
|
|
218
|
-
| `ucm.config.json` | Where the contracts, the tokens and the implementations live |
|
|
219
|
-
| `.gitattributes` | Keeps contracts and tokens in LF, so a re-export from a Windows machine does not produce a whole-file diff |
|
|
220
|
-
| `.vscode/settings.json` | Binds `*.contract.json` to the JSON Schema of the installed package, so the editor validates as you read |
|
|
221
|
-
| `.gitignore` | Keeps `ci-report.md` out of the repository; it is regenerated on every run and describes only that run |
|
|
222
|
-
| `.github/workflows/ucm.yml` | Runs the check on every pull request and posts the report as a comment, from a second job |
|
|
223
|
-
| `.agents/skills/ucm-implementer/SKILL.md`, `.claude/skills/ucm-implementer/SKILL.md` | Two identical relays: an agent loads one before writing a component, and runs `ucm guide` at the pinned version |
|
|
224
|
-
| `.ucm/conventions.md` | The repository's stack and writings, with its instructions in a comment |
|
|
225
|
-
| `.ucm/gabarits/` | The templates of the installed stack adapter, when it publishes some |
|
|
226
|
-
|
|
227
|
-
The workflow is yours once written. It will never be overwritten. On GitLab,
|
|
228
|
-
`.gitlab/ucm.gitlab-ci.yml` and `.gitlab-ci.yml` replace the GitHub workflow.
|
|
229
|
-
|
|
230
|
-
An installed adapter that fails to load is reported, and the rest is
|
|
231
|
-
installed. The command then prints the lines it does not write, each with its
|
|
232
|
-
file: `@ucm-kit/cli` in `devDependencies`, `ucm tokens css` at the head of the
|
|
233
|
-
`dev` and `build` scripts, the import of the generated stylesheet, and the
|
|
234
|
-
optional `modes` section when `tokens.json` declares axes. A line already present
|
|
235
|
-
is not printed.
|
|
236
|
-
|
|
237
|
-
### `ucm.config.json`
|
|
238
|
-
|
|
239
|
-
Three paths. **This file is the only authority on where an export lands.** The
|
|
240
|
-
Figma plugin reads it before publishing, and `ucm check` reads it before looking
|
|
241
|
-
for contracts. A repository that arranges things differently says so here, once,
|
|
242
|
-
and both sides follow.
|
|
243
|
-
|
|
244
|
-
Its absence is the nominal case: the defaults below apply. A repository with a
|
|
245
|
-
single `components/` folder works without writing a line. A file that exists but
|
|
246
|
-
is malformed is refused on both sides.
|
|
247
|
-
|
|
248
|
-
```json
|
|
249
|
-
{
|
|
250
|
-
"components": "components",
|
|
251
|
-
"tokens": "tokens.json",
|
|
252
|
-
"implementation": "{dir}/{id}.tsx"
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
`implementation` is a pattern with two tokens, `{dir}` for the contract's folder
|
|
257
|
-
and `{id}` for its identifier. Replace it with the pattern your repository uses.
|
|
258
|
-
|
|
259
|
-
Each of the three paths is relative to the repository root and written with
|
|
260
|
-
`/`. A path that starts with `/` or a drive letter, contains `\`, or has an
|
|
261
|
-
empty, `.` or `..` segment is refused on both sides: the plugin would write
|
|
262
|
-
outside the repository with the designer's token, and the check would read
|
|
263
|
-
outside it.
|
|
264
|
-
|
|
265
|
-
No version number goes in this file. Which contract versions can be read belongs
|
|
266
|
-
to the installed package, and repeating it here would create a second authority
|
|
267
|
-
that drifts on the first update.
|
|
268
|
-
|
|
269
|
-
## What the report says
|
|
270
|
-
|
|
271
|
-
The report is written for the **designer** who validates the export. It requires
|
|
272
|
-
no CI log. Every reason a pull request is refused appears in it.
|
|
273
|
-
|
|
274
|
-
Six checks run on each contract. Four block a merge, two only warn: **a check
|
|
275
|
-
blocks when the file on disk cannot be read as it stands**, and warns when the
|
|
276
|
-
read succeeds and the gap points at the code or at the token file.
|
|
277
|
-
|
|
278
|
-
The direction of the gap names who fixes it. The CI never reads who opened the
|
|
279
|
-
pull request. A contract that is too old is re-exported; a contract that is too
|
|
280
|
-
new needs this package upgraded, which no re-export replaces.
|
|
281
|
-
[`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) names both
|
|
282
|
-
directions.
|
|
283
|
-
|
|
284
|
-
| Check | Verdict |
|
|
285
|
-
|---|---|
|
|
286
|
-
| The contract is readable and complete | Blocks |
|
|
287
|
-
| This repository can read that contract version | Blocks |
|
|
288
|
-
| Composition: every nested component has its own contract, the lists agree, no cycles | Blocks |
|
|
289
|
-
| Typography tokens have the expected type | Blocks |
|
|
290
|
-
| Every `{token.path}` cited exists in the token file | Warns, but a missing or unreadable token file blocks |
|
|
291
|
-
| The code exposes the props the contract declares, with a stack adapter installed | Warns |
|
|
292
|
-
|
|
293
|
-
Before any contract, the check reads the format version at the root of the
|
|
294
|
-
token file. A version newer than this package reads, or a mark that is not a
|
|
295
|
-
version, blocks the merge, even in a repository with no contract yet. A
|
|
296
|
-
developer upgrades the UCM packages for the first case, and the designer runs
|
|
297
|
-
the token export again for the second.
|
|
298
|
-
[`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) lists the four
|
|
299
|
-
states.
|
|
300
|
-
|
|
301
|
-
A gap with the code needs a developer, so it warns and lets the merge through. A
|
|
302
|
-
token removed from the design system does too: tokens are the source of truth,
|
|
303
|
-
so an older contract does not hold back their evolution. A token file that is
|
|
304
|
-
absent or unreadable is another matter: no reference can be resolved at all, so
|
|
305
|
-
the check gives up rather than reporting every path as missing.
|
|
306
|
-
|
|
307
|
-
A contract may land before the code that implements it. A missing implementation
|
|
308
|
-
is an allowed stage of the work.
|
|
309
|
-
|
|
310
|
-
**So is a repository with no contract at all.** Right after `ucm init` nothing
|
|
311
|
-
has been exported: there is no token file, and usually no contract folder. From
|
|
312
|
-
`0.1.10` on, `ucm check` returns 0 there and reports what to do next. The number
|
|
313
|
-
of contracts decides: with one or more, a missing token file blocks the merge
|
|
314
|
-
again, because those contracts cite tokens that cannot be resolved.
|
|
315
|
-
|
|
316
|
-
The report also relays two things it does not measure itself: the warnings the
|
|
317
|
-
export wrote into the contract, and the verdict of the repository's own tests
|
|
318
|
-
when an orchestrator passes it in through `UCM_ECHECS_DE_TESTS`.
|
|
319
|
-
|
|
320
|
-
## GitLab
|
|
321
|
-
|
|
322
|
-
`ucm init` writes the CI of one forge. `--forge` decides; without it, the host
|
|
323
|
-
of the `origin` remote does, then the presence of `.gitlab-ci.yml`, and GitHub
|
|
324
|
-
otherwise. The command names the forge and the signal it followed.
|
|
325
|
-
|
|
326
|
-
For GitLab it writes `.gitlab/ucm.gitlab-ci.yml`, two jobs with no global key,
|
|
327
|
-
so the project's other jobs keep their rules. `ucm` runs the check in merge
|
|
328
|
-
request pipelines and on the default branch; `ucm-rapport` posts the note in
|
|
329
|
-
merge request pipelines. Both take the default `test` stage. A new
|
|
330
|
-
`.gitlab-ci.yml` includes the file; an existing one is left alone, and the
|
|
331
|
-
command prints the `include` line to add. It also prints three settings it
|
|
332
|
-
cannot make:
|
|
333
|
-
|
|
334
|
-
- create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
|
|
335
|
-
holding an `api` token of an account with the Reporter role on this project
|
|
336
|
-
only: a service account's personal token, or a project access token where
|
|
337
|
-
the GitLab plan offers one. Export branches are not protected, so a
|
|
338
|
-
protected variable would be empty there. Every pipeline of every branch reads
|
|
339
|
-
an unprotected variable, and whoever pushes a branch can print it: the
|
|
340
|
-
Reporter role limits that token to reading and commenting;
|
|
341
|
-
- tick "Pipelines must succeed" in the merge request settings. Without it, a red
|
|
342
|
-
report does not block the merge it says is blocked;
|
|
343
|
-
- keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
|
|
344
|
-
pipeline whose job names a missing stage.
|
|
345
|
-
|
|
346
|
-
`ucm` unsets `UCM_GITLAB_TOKEN` before `npm ci`, so install scripts do not
|
|
347
|
-
inherit it on executors that set variables in the job script. `ucm-rapport`
|
|
348
|
-
runs no code from the repository: it clones nothing, receives `ci-report.md`
|
|
349
|
-
as an artifact, disables install scripts, and runs `npx` from an empty
|
|
350
|
-
directory. It writes a minimal report when the check stopped before writing
|
|
351
|
-
one, then posts the report:
|
|
352
|
-
|
|
353
|
-
```sh
|
|
354
|
-
npx --yes @ucm-kit/cli@0.1.40 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
The job allows failure: a refused token leaves the pipeline the colour of the
|
|
358
|
-
check, and the report stays in the artifacts.
|
|
359
|
-
|
|
360
|
-
The command reads the token from `UCM_GITLAB_TOKEN` and never prints it. It
|
|
361
|
-
replaces the note that the token's account wrote with the `<!-- ucm-rapport -->`
|
|
362
|
-
marker, across every page of notes, and creates one otherwise. Without the
|
|
363
|
-
variable it says so and exits with `0`: the report stays in the job artifacts.
|
|
364
|
-
A refused token exits with `1` and names the fix. `--api` defaults to
|
|
365
|
-
`https://gitlab.com/api/v4`.
|
|
366
|
-
|
|
367
|
-
## Optional stack adapters
|
|
368
|
-
|
|
369
|
-
The first five checks above read contracts and tokens only, so they work
|
|
370
|
-
whatever the repository is written in. Comparing a contract to real code needs
|
|
371
|
-
to read that code, which is a stack adapter's job.
|
|
372
|
-
|
|
373
|
-
`ucm check` discovers an adapter installed **by the repository**, resolving from
|
|
374
|
-
the checked root rather than from the npx cache. Install
|
|
375
|
-
[`@ucm-kit/adapter-typescript`](https://www.npmjs.com/package/@ucm-kit/adapter-typescript)
|
|
376
|
-
to add static prop and composition parity for TypeScript projects. Without an
|
|
377
|
-
adapter, the report says the implementation was not read, and never that it is
|
|
378
|
-
conformant.
|
|
379
|
-
|
|
380
388
|
## Status
|
|
381
389
|
|
|
382
390
|
**0.x, the public surface is not frozen.** Pin an exact version.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.42",
|
|
4
4
|
"description": "La ligne de commande UCM : initialiser un repository, lister ce qu'il doit couvrir.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test": "node scripts/run-tests.cjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ucm-kit/core": "0.1.
|
|
32
|
+
"@ucm-kit/core": "0.1.37"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"yaml": "^2.9.1"
|
package/src/init.mjs
CHANGED
|
@@ -630,7 +630,7 @@ function lignesGitlab(racine) {
|
|
|
630
630
|
const lignes = [
|
|
631
631
|
{
|
|
632
632
|
fichier: "Settings > CI/CD > Variables",
|
|
633
|
-
ligne: "créez `UCM_GITLAB_TOKEN`, masquée et non protégée
|
|
633
|
+
ligne: "créez `UCM_GITLAB_TOKEN`, masquée et non protégée. Sa valeur : un jeton de scope api d'un compte de service membre de ce seul projet, au rôle Reporter, ou un jeton d'accès de projet au rôle Reporter si l'offre le permet. Sans cette variable, le rapport n'est pas publié sur la merge request. Non protégée, parce que les branches d'export ne le sont pas ; tout pipeline d'une branche la lit, et le rôle Reporter borne ce qu'on en tire à lire et commenter.",
|
|
634
634
|
},
|
|
635
635
|
{
|
|
636
636
|
fichier: "Settings > Merge requests",
|
|
@@ -792,8 +792,9 @@ export function rendreInit({
|
|
|
792
792
|
: "Aucun fichier à écrire : ce repository est déjà installé.",
|
|
793
793
|
);
|
|
794
794
|
if (forge) {
|
|
795
|
-
lignes.push(
|
|
796
|
-
|
|
795
|
+
lignes.push("");
|
|
796
|
+
lignes.push(`CI écrite pour ${forge.nom === "gitlab" ? "GitLab" : "GitHub"}, d'après ${forge.signal}.`);
|
|
797
|
+
lignes.push("L'option `--forge github` ou `--forge gitlab` en choisit une autre.");
|
|
797
798
|
}
|
|
798
799
|
|
|
799
800
|
if (optionsIgnorees) {
|
|
@@ -823,7 +824,15 @@ export function rendreInit({
|
|
|
823
824
|
if (restantes.length > 0) {
|
|
824
825
|
lignes.push("");
|
|
825
826
|
lignes.push("Reste à ajouter à la main :");
|
|
826
|
-
|
|
827
|
+
// L'endroit en tête, puis une phrase par ligne : le geste d'abord, ses
|
|
828
|
+
// raisons ensuite, sans qu'un paragraphe replié par le terminal les mêle.
|
|
829
|
+
for (const { fichier, ligne } of restantes) {
|
|
830
|
+
lignes.push("");
|
|
831
|
+
lignes.push(`- ${fichier}`);
|
|
832
|
+
for (const phrase of ligne.split(/(?<=\.) (?=\p{Lu})/u)) {
|
|
833
|
+
lignes.push(` ${phrase[0].toUpperCase()}${phrase.slice(1)}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
827
836
|
}
|
|
828
837
|
return lignes.join("\n");
|
|
829
838
|
}
|
package/src/ucm.mjs
CHANGED
|
@@ -192,6 +192,11 @@ function executerCommande(arguments_, {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
if (commande === "icons") {
|
|
195
|
+
if (arguments_.length > 1) {
|
|
196
|
+
const alerter = sorties.alerter ?? console.error;
|
|
197
|
+
alerter(`Argument inconnu : ${arguments_[1]}\n\nucm icons`);
|
|
198
|
+
return 2;
|
|
199
|
+
}
|
|
195
200
|
const { configuration, erreur } = lireConfiguration(racine);
|
|
196
201
|
if (erreur) {
|
|
197
202
|
// La configuration est refusée ici comme ailleurs : retomber sur les
|