@ucm-kit/cli 0.1.33 → 0.1.36
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 +48 -12
- package/package.json +1 -1
- package/src/aides.mjs +1 -1
- package/src/contrats.mjs +17 -0
- package/src/guide.mjs +475 -0
- package/src/icons.mjs +2 -2
- package/src/init.mjs +179 -11
- package/src/tokens-css.mjs +3 -2
- package/src/ucm.mjs +23 -5
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ next to the component's code. This command reads those files and says whether
|
|
|
11
11
|
they still hold together.
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
15
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
14
|
+
npx --yes @ucm-kit/cli@0.1.36 init
|
|
15
|
+
npx --yes @ucm-kit/cli@0.1.36 check --report ci-report.md
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Pin an exact version, without `^`. A range would let npx install a build this
|
|
@@ -38,15 +38,17 @@ check`.
|
|
|
38
38
|
| `ucm icons` | Lists the icons the contracts ask this repository to draw |
|
|
39
39
|
| `ucm tokens css --out <file>` | Writes the CSS stylesheet of the tokens and their modes |
|
|
40
40
|
| `ucm aides [<aide>]` | Lists the implementation guides, or prints one |
|
|
41
|
+
| `ucm guide <contract>` | Prints what an agent reads before implementing that contract |
|
|
41
42
|
| `ucm --help` | Prints the above |
|
|
42
43
|
|
|
43
|
-
`ucm init` takes
|
|
44
|
+
`ucm init` takes four options:
|
|
44
45
|
|
|
45
46
|
| Option | Effect |
|
|
46
47
|
|---|---|
|
|
47
48
|
| `--components <dir>` | The folder the contracts are stored under |
|
|
48
49
|
| `--tokens <dir>` | The folder that holds `tokens.json` |
|
|
49
50
|
| `--implementation <pattern>` | Where a contract's implementation lives |
|
|
51
|
+
| `--sans-agents` | Writes neither the agent relays, nor `.ucm/conventions.md`, nor the templates |
|
|
50
52
|
|
|
51
53
|
The first two take a folder, because a folder is what a repository arranges.
|
|
52
54
|
`--tokens` appends the file name before writing it, so the `tokens` field of
|
|
@@ -60,7 +62,7 @@ not write React states its own extension here, rather than carrying a `.tsx`
|
|
|
60
62
|
that was wrong the day it was installed:
|
|
61
63
|
|
|
62
64
|
```sh
|
|
63
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
65
|
+
npx --yes @ucm-kit/cli@0.1.36 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
|
|
64
66
|
```
|
|
65
67
|
|
|
66
68
|
All three act only on a first install: `ucm init` never overwrites an existing
|
|
@@ -164,22 +166,46 @@ writing. `ucm aides` reports an unknown title, a duplicate section, a
|
|
|
164
166
|
a path applies, searching up to the folder that holds `ucm.config.json`, never
|
|
165
167
|
above the repository.
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
`
|
|
169
|
-
|
|
170
|
-
The current commands read neither.
|
|
169
|
+
A `Contrôle :` line adds its commands, between backticks, to the proof of the
|
|
170
|
+
guide. `ecritures-par-defaut: non` on the first line prints meanings only, for a
|
|
171
|
+
repository that writes no CSS.
|
|
171
172
|
|
|
172
173
|
`ucm aides <aide> --personnaliser [<path>]` appends that guide's section, with
|
|
173
174
|
its default writing to edit, to the closest conventions file. `composant` has no
|
|
174
175
|
section, and the command refuses it. The marker records the version and a
|
|
175
176
|
fingerprint of the copied writing: when the default writing changes, `ucm aides`
|
|
176
|
-
|
|
177
|
-
well. An existing section is never overwritten.
|
|
177
|
+
and `ucm guide` name the section to read again, and a marker without a
|
|
178
|
+
fingerprint is named as well. An existing section is never overwritten.
|
|
179
|
+
|
|
180
|
+
## The guide of a contract
|
|
181
|
+
|
|
182
|
+
`ucm guide <contract> [--out <file>]` prints, in one Markdown document:
|
|
183
|
+
|
|
184
|
+
1. what to read again first: conventions anomalies, copied sections whose
|
|
185
|
+
default writing changed, and `@ucm-kit/cli` pins that differ between the two
|
|
186
|
+
relays, the workflow and `package.json`;
|
|
187
|
+
2. the procedure, `procedure.md`;
|
|
188
|
+
3. the text before the first section of the closest conventions file;
|
|
189
|
+
4. the contract: its meta, props, structure, states, intent, rendering, variants
|
|
190
|
+
with their view reference, each view and catalog entry once, the icons, text
|
|
191
|
+
styles and binding definitions in use, and the props and samples of each
|
|
192
|
+
dependency;
|
|
193
|
+
5. each guide the contract's characteristics use, with the repository's section
|
|
194
|
+
or the default writing, and the proof;
|
|
195
|
+
6. the anchors the conventions leave open, as questions for a developer;
|
|
196
|
+
7. the mode axes that reach the contract, their attributes, and the contexts to
|
|
197
|
+
check;
|
|
198
|
+
8. the icons the contract asks for, then the size of each part.
|
|
199
|
+
|
|
200
|
+
The command exits with `1` when the composition graph or the token file is
|
|
201
|
+
inconsistent, and with `2` for an invocation, a configuration or a contract it
|
|
202
|
+
cannot read, a contract version outside its reading window included.
|
|
178
203
|
|
|
179
204
|
## What `ucm init` writes
|
|
180
205
|
|
|
181
|
-
Five files
|
|
182
|
-
|
|
206
|
+
Five control files, then what an agent needs, unless `--sans-agents` is passed.
|
|
207
|
+
The command explains each one as it writes it. An existing file is kept as it
|
|
208
|
+
is, and the command names what it left alone.
|
|
183
209
|
|
|
184
210
|
| File | Why |
|
|
185
211
|
|---|---|
|
|
@@ -188,9 +214,19 @@ kept as it is, and the command names what it left alone.
|
|
|
188
214
|
| `.vscode/settings.json` | Binds `*.contract.json` to the JSON Schema of the installed package, so the editor validates as you read |
|
|
189
215
|
| `.gitignore` | Keeps `ci-report.md` out of the repository; it is regenerated on every run and describes only that run |
|
|
190
216
|
| `.github/workflows/ucm.yml` | Runs the check on every pull request and posts the report as a comment |
|
|
217
|
+
| `.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 |
|
|
218
|
+
| `.ucm/conventions.md` | The repository's stack and writings, with its instructions in a comment |
|
|
219
|
+
| `.ucm/gabarits/` | The templates of the installed stack adapter, when it publishes some |
|
|
191
220
|
|
|
192
221
|
The workflow is yours once written. It will never be overwritten.
|
|
193
222
|
|
|
223
|
+
An installed adapter that fails to load is reported, and the rest is
|
|
224
|
+
installed. The command then prints the lines it does not write, each with its
|
|
225
|
+
file: `@ucm-kit/cli` in `devDependencies`, `ucm tokens css` at the head of the
|
|
226
|
+
`dev` and `build` scripts, the import of the generated stylesheet, and the
|
|
227
|
+
optional `modes` section when `tokens.json` declares axes. A line already present
|
|
228
|
+
is not printed.
|
|
229
|
+
|
|
194
230
|
### `ucm.config.json`
|
|
195
231
|
|
|
196
232
|
Three paths. **This file is the only authority on where an export lands.** The
|
package/package.json
CHANGED
package/src/aides.mjs
CHANGED
|
@@ -76,7 +76,7 @@ function conventionsDepuis(depart, racine, catalogue) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** Les anomalies et les sections à relire, à imprimer avant tout le reste. */
|
|
79
|
-
function avertissements(conventions, chemin, racine, catalogue) {
|
|
79
|
+
export function avertissements(conventions, chemin, racine, catalogue) {
|
|
80
80
|
if (!conventions) return [];
|
|
81
81
|
const ou = relative(racine, chemin).split("\\").join("/");
|
|
82
82
|
return [
|
package/src/contrats.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Les contrats d'un repository, lus par les commandes qui les parcourent. */
|
|
2
|
+
import { trouverContrats } from "@ucm-kit/core/lecteurs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Les chemins des contrats sous `dossier`, et `[]` quand ce dossier n'existe
|
|
6
|
+
* pas : un repository neuf n'a pas de dossier de contrats avant son premier
|
|
7
|
+
* export, et `npm run dev` y lance déjà `ucm tokens css`. Toute autre erreur
|
|
8
|
+
* remonte, une panne ne valant pas zéro contrat.
|
|
9
|
+
*/
|
|
10
|
+
export function contratsDuDossier(dossier) {
|
|
11
|
+
try {
|
|
12
|
+
return trouverContrats(dossier);
|
|
13
|
+
} catch (erreur) {
|
|
14
|
+
if (erreur?.code === "ENOENT") return [];
|
|
15
|
+
throw erreur;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/guide.mjs
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ucm guide <contrat>` : ce qu'un agent lit avant d'implémenter un contrat, en
|
|
3
|
+
* une seule commande.
|
|
4
|
+
*
|
|
5
|
+
* La sortie est un Markdown, dans cet ordre : ce qui est à relire avant de
|
|
6
|
+
* commencer, la procédure, le texte de tête des conventions, l'extraction du
|
|
7
|
+
* contrat, les aides que ses caractéristiques emploient, les ancrages que les
|
|
8
|
+
* conventions ne tranchent pas, les modes, les icônes, puis la taille de chaque
|
|
9
|
+
* partie. Une vue ou une entrée de catalogue s'imprime une fois, sous son renvoi.
|
|
10
|
+
*
|
|
11
|
+
* Codes : 0 guide rendu, 1 graphe de composition ou fichier de tokens
|
|
12
|
+
* incohérent, 2 invocation, configuration ou contrat illisible.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
16
|
+
|
|
17
|
+
import { NOM_CONFIGURATION, etatDuFormatDeTokens } from "@ucm-kit/core/format";
|
|
18
|
+
import {
|
|
19
|
+
CARACTERISTIQUES,
|
|
20
|
+
axesDeTokens,
|
|
21
|
+
axesDuContrat,
|
|
22
|
+
caracteristiquesDuContrat,
|
|
23
|
+
compositionsExactesDuVariant,
|
|
24
|
+
conesDesAxes,
|
|
25
|
+
contextesDeVerification,
|
|
26
|
+
contextesDesAxes,
|
|
27
|
+
lireConfiguration,
|
|
28
|
+
messagesDExport,
|
|
29
|
+
validerGrapheDesContrats,
|
|
30
|
+
verdictDeVersion,
|
|
31
|
+
vueExacteDuVariant,
|
|
32
|
+
} from "@ucm-kit/core/lecteurs";
|
|
33
|
+
|
|
34
|
+
import { avertissements, catalogueDesAides } from "./aides.mjs";
|
|
35
|
+
import { contratsDuDossier } from "./contrats.mjs";
|
|
36
|
+
import { conventionsLesPlusProches, lireConventions } from "./conventions.mjs";
|
|
37
|
+
import { attributsDesAxes } from "./tokens-css.mjs";
|
|
38
|
+
|
|
39
|
+
export const USAGE_GUIDE = "ucm guide <contrat> [--out <fichier>]";
|
|
40
|
+
|
|
41
|
+
const PROCEDURE = new URL("../procedure.md", import.meta.url);
|
|
42
|
+
|
|
43
|
+
/** Les catalogues de second niveau, par partie de vue. */
|
|
44
|
+
const CATALOGUES = {
|
|
45
|
+
structure: "viewStructures",
|
|
46
|
+
typography: "viewTypographies",
|
|
47
|
+
composes: "viewComposes",
|
|
48
|
+
icons: "viewIcons",
|
|
49
|
+
paintPlacements: "viewPaintPlacements",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const estObjet = (valeur) => Boolean(valeur) && typeof valeur === "object" && !Array.isArray(valeur);
|
|
53
|
+
const enSlash = (chemin) => chemin.split("\\").join("/");
|
|
54
|
+
const lireJson = (chemin) => JSON.parse(readFileSync(chemin, "utf8").replace(/^\uFEFF/, ""));
|
|
55
|
+
|
|
56
|
+
/** Lit les arguments de `ucm guide`, sans lever. */
|
|
57
|
+
export function lireArgumentsGuide(arguments_) {
|
|
58
|
+
const options = { contrat: null, out: null };
|
|
59
|
+
for (let i = 0; i < arguments_.length; i += 1) {
|
|
60
|
+
const argument = arguments_[i];
|
|
61
|
+
if (argument === "--out") {
|
|
62
|
+
const valeur = arguments_[i + 1];
|
|
63
|
+
if (valeur === undefined || valeur.startsWith("--")) return { erreur: "--out attend un chemin de fichier." };
|
|
64
|
+
options.out = valeur;
|
|
65
|
+
i += 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (argument.startsWith("--") || options.contrat !== null) return { erreur: `Argument inconnu : ${argument}` };
|
|
69
|
+
options.contrat = argument;
|
|
70
|
+
}
|
|
71
|
+
if (options.contrat === null) return { erreur: "ucm guide attend le chemin d'un contrat." };
|
|
72
|
+
return { options };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Une ligne par entrée : la clé, puis sa valeur en JSON compact. */
|
|
76
|
+
function lignesJson(valeur) {
|
|
77
|
+
if (!estObjet(valeur)) return [JSON.stringify(valeur)];
|
|
78
|
+
return Object.entries(valeur).map(([cle, entree]) => `${JSON.stringify(cle)}: ${JSON.stringify(entree)}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function blocJson(titre, valeur) {
|
|
82
|
+
if (valeur === undefined) return [];
|
|
83
|
+
return [`### ${titre}`, "", "```json", ...lignesJson(valeur), "```", ""];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Les clés de définition que des liaisons citent, à n'importe quelle profondeur. */
|
|
87
|
+
function definitionsCitees(valeur, trouvees = new Set()) {
|
|
88
|
+
if (Array.isArray(valeur)) for (const entree of valeur) definitionsCitees(entree, trouvees);
|
|
89
|
+
else if (estObjet(valeur)) {
|
|
90
|
+
if (typeof valeur.definition === "string") trouvees.add(valeur.definition);
|
|
91
|
+
for (const entree of Object.values(valeur)) definitionsCitees(entree, trouvees);
|
|
92
|
+
}
|
|
93
|
+
return trouvees;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Les entrées d'un dictionnaire dont la clé est citée, dans l'ordre du contrat. */
|
|
97
|
+
function entreesCitees(dictionnaire, cles) {
|
|
98
|
+
if (!estObjet(dictionnaire)) return undefined;
|
|
99
|
+
const choisies = Object.entries(dictionnaire).filter(([cle]) => cles.has(cle));
|
|
100
|
+
return choisies.length === 0 ? undefined : Object.fromEntries(choisies);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Les noms des dépendances qu'au moins un variant compose, dans l'ordre de première apparition. */
|
|
104
|
+
function dependancesDuContrat(contrat) {
|
|
105
|
+
const noms = [];
|
|
106
|
+
for (const variant of Array.isArray(contrat.variants) ? contrat.variants : []) {
|
|
107
|
+
for (const { component } of compositionsExactesDuVariant(contrat, variant)) {
|
|
108
|
+
if (typeof component === "string" && !noms.includes(component)) noms.push(component);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return noms;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Les icônes que les vues des variants placent. */
|
|
115
|
+
function iconesUtilisees(contrat) {
|
|
116
|
+
const cles = new Set();
|
|
117
|
+
for (const variant of Array.isArray(contrat.variants) ? contrat.variants : []) {
|
|
118
|
+
const icones = vueExacteDuVariant(contrat, variant)?.icons;
|
|
119
|
+
for (const cle of Object.keys(estObjet(icones) ? icones : {})) cles.add(cle);
|
|
120
|
+
}
|
|
121
|
+
return cles;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* L'extraction du contrat. Les variants gardent leur renvoi de vue, chaque vue
|
|
126
|
+
* citée s'imprime une fois, puis chaque entrée de catalogue qu'une vue cite.
|
|
127
|
+
* Les identités Figma d'un variant, `nodeId` et `figmaName`, ne sont pas
|
|
128
|
+
* imprimées : elles tracent la maquette et ne décrivent aucun rendu.
|
|
129
|
+
*/
|
|
130
|
+
function extraction(contrat, contratsParNom) {
|
|
131
|
+
const variants = (Array.isArray(contrat.variants) ? contrat.variants : []).map((variant) => {
|
|
132
|
+
if (!estObjet(variant)) return variant;
|
|
133
|
+
const { nodeId, figmaName, ...rendu } = variant;
|
|
134
|
+
return rendu;
|
|
135
|
+
});
|
|
136
|
+
const vuesCitees = new Set(variants.map((variant) => variant?.view).filter((vue) => typeof vue === "string"));
|
|
137
|
+
const vues = entreesCitees(contrat.variantViews, vuesCitees);
|
|
138
|
+
|
|
139
|
+
const citees = Object.fromEntries(Object.keys(CATALOGUES).map((partie) => [partie, new Set()]));
|
|
140
|
+
if (typeof contrat.structure?.view === "string") citees.structure.add(contrat.structure.view);
|
|
141
|
+
for (const vue of Object.values(vues ?? {})) {
|
|
142
|
+
for (const partie of Object.keys(CATALOGUES)) {
|
|
143
|
+
if (typeof vue?.[partie] === "string") citees[partie].add(vue[partie]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const styles = new Set();
|
|
148
|
+
for (const variant of Array.isArray(contrat.variants) ? contrat.variants : []) {
|
|
149
|
+
const usages = vueExacteDuVariant(contrat, variant)?.typography;
|
|
150
|
+
for (const usage of Array.isArray(usages) ? usages : []) if (typeof usage?.style === "string") styles.add(usage.style);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const lignes = [
|
|
154
|
+
"## Contrat",
|
|
155
|
+
"",
|
|
156
|
+
`Version ${contrat.meta?.contractVersion}, couverture portable ${contrat.meta?.coverage?.portable ?? "non déclarée"}.`,
|
|
157
|
+
"",
|
|
158
|
+
];
|
|
159
|
+
const diagnostics = messagesDExport(contrat);
|
|
160
|
+
if (diagnostics.length > 0) {
|
|
161
|
+
lignes.push("Ce que l'export n'a pas su décrire, à rapporter au développeur :", "", ...diagnostics.map((message) => `- ${message}`), "");
|
|
162
|
+
}
|
|
163
|
+
lignes.push(
|
|
164
|
+
...blocJson("props", contrat.props),
|
|
165
|
+
...blocJson("structure", contrat.structure),
|
|
166
|
+
...blocJson("stateModel", contrat.stateModel),
|
|
167
|
+
...blocJson("intent", contrat.intent),
|
|
168
|
+
...blocJson("rendering", contrat.rendering),
|
|
169
|
+
"### variants",
|
|
170
|
+
"",
|
|
171
|
+
"```json",
|
|
172
|
+
...variants.map((variant) => JSON.stringify(variant)),
|
|
173
|
+
"```",
|
|
174
|
+
"",
|
|
175
|
+
...blocJson("variantViews", vues),
|
|
176
|
+
);
|
|
177
|
+
for (const [partie, catalogue] of Object.entries(CATALOGUES)) {
|
|
178
|
+
lignes.push(...blocJson(catalogue, entreesCitees(contrat[catalogue], citees[partie])));
|
|
179
|
+
}
|
|
180
|
+
lignes.push(
|
|
181
|
+
...blocJson("icons", entreesCitees(contrat.icons, iconesUtilisees(contrat))),
|
|
182
|
+
...blocJson("textStyles", entreesCitees(contrat.textStyles, styles)),
|
|
183
|
+
...blocJson("propertyBindingDefinitions", entreesCitees(contrat.propertyBindingDefinitions, definitionsCitees(contrat.variants))),
|
|
184
|
+
...blocJson("samples", contrat.samples),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
for (const nom of dependancesDuContrat(contrat)) {
|
|
188
|
+
const dependance = contratsParNom.get(nom);
|
|
189
|
+
lignes.push(`### Dépendance ${nom}`, "");
|
|
190
|
+
if (!estObjet(dependance)) {
|
|
191
|
+
lignes.push("Contrat introuvable ou ambigu dans ce repository.", "");
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
lignes.push("```json", ...lignesJson({ props: dependance.props, samples: dependance.samples }), "```", "");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
lignes.push(
|
|
198
|
+
"### Ce que le contrat ne dit pas",
|
|
199
|
+
"",
|
|
200
|
+
"- Le comportement, l'accessibilité et les événements relèvent des conventions et de la relecture.",
|
|
201
|
+
"- Ce guide ne prouve pas qu'un sens a été appliqué : la preuve de chaque aide le vérifie.",
|
|
202
|
+
"",
|
|
203
|
+
);
|
|
204
|
+
return lignes.join("\n");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Le rang d'une aide : celui de sa caractéristique, `composant` en tête des aides de tout contrat. */
|
|
208
|
+
function rangDAide(aide) {
|
|
209
|
+
const rang = CARACTERISTIQUES.findIndex(({ id }) => id === aide.quand);
|
|
210
|
+
return [rang, aide.nom === "composant" ? 0 : 1, aide.nom];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function comparerAides(gauche, droite) {
|
|
214
|
+
const [a, b] = [rangDAide(gauche), rangDAide(droite)];
|
|
215
|
+
return a[0] - b[0] || a[1] - b[1] || a[2].localeCompare(b[2]);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Les aides employées, rendues ; et les ancrages que les conventions ne tranchent pas. */
|
|
219
|
+
function aidesDuContrat(caracteristiques, catalogue, conventions) {
|
|
220
|
+
const employees = [...catalogue.values()].filter((aide) => caracteristiques.includes(aide.quand)).sort(comparerAides);
|
|
221
|
+
const rendues = [];
|
|
222
|
+
const nonTranches = [];
|
|
223
|
+
const ecrituresParDefaut = conventions?.ecrituresParDefaut ?? true;
|
|
224
|
+
|
|
225
|
+
for (const aide of employees) {
|
|
226
|
+
const section = conventions?.sections.get(aide.nom);
|
|
227
|
+
if (aide.ancrage && !(section && section.texte !== "")) {
|
|
228
|
+
nonTranches.push(`- **${aide.nom}** : ${aide.sens.replace(/\s*\n\s*/g, " ")}`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const parties = [`### ${aide.nom}`, "", "**Sens.**", "", aide.sens, ""];
|
|
232
|
+
if (aide.ancrage) parties.push("**Réponse du repository.**", "", section.texte, "");
|
|
233
|
+
else if (aide.nom === "composant" && conventions?.tete) parties.push("**Écriture.** Le texte de tête des conventions, plus haut.", "");
|
|
234
|
+
else if (section) parties.push("**Écriture du repository.**", "", section.texte, "");
|
|
235
|
+
else if (ecrituresParDefaut) parties.push("**Écriture par défaut.**", "", aide.ecriture, "");
|
|
236
|
+
|
|
237
|
+
const controles = [...(section?.controles ?? []), ...(aide.nom === "composant" ? conventions?.controles ?? [] : [])];
|
|
238
|
+
parties.push("**Preuve.**", "", aide.preuve, "");
|
|
239
|
+
if (controles.length > 0) parties.push(`Contrôles du repository : ${controles.map((commande) => `\`${commande}\``).join(", ")}.`, "");
|
|
240
|
+
rendues.push(parties.join("\n"));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
aides: ["## Aides", "", ...rendues].join("\n"),
|
|
245
|
+
nonTranches: nonTranches.length === 0 ? "" : ["## Non tranché : demander au développeur", "", ...nonTranches, ""].join("\n"),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Le numéro de `@ucm-kit/cli` qu'un fichier épingle, ou `null`. */
|
|
250
|
+
function pinDans(texte) {
|
|
251
|
+
return /@ucm-kit\/cli@(\d+\.\d+\.\d+[^\s`"']*)/.exec(texte)?.[1] ?? null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Les pins de `@ucm-kit/cli` du repository, comparés entre eux : les deux
|
|
256
|
+
* relais, le workflow et `package.json`. Rend une ligne par fichier quand deux
|
|
257
|
+
* numéros diffèrent, sinon rien.
|
|
258
|
+
*/
|
|
259
|
+
export function pinsEnDesaccord(racine) {
|
|
260
|
+
const trouves = [];
|
|
261
|
+
for (const chemin of [
|
|
262
|
+
".agents/skills/ucm-implementer/SKILL.md",
|
|
263
|
+
".claude/skills/ucm-implementer/SKILL.md",
|
|
264
|
+
".github/workflows/ucm.yml",
|
|
265
|
+
]) {
|
|
266
|
+
const complet = join(racine, chemin);
|
|
267
|
+
if (!existsSync(complet)) continue;
|
|
268
|
+
const version = pinDans(readFileSync(complet, "utf8"));
|
|
269
|
+
if (version !== null) trouves.push({ chemin, version });
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const manifeste = lireJson(join(racine, "package.json"));
|
|
273
|
+
const version = manifeste.devDependencies?.["@ucm-kit/cli"] ?? manifeste.dependencies?.["@ucm-kit/cli"];
|
|
274
|
+
// Une archive, un lien ou un espace de travail ne portent pas de numéro à comparer.
|
|
275
|
+
if (typeof version === "string" && !/^[a-z][a-z+]*:/i.test(version)) trouves.push({ chemin: "package.json", version });
|
|
276
|
+
} catch {
|
|
277
|
+
// Un repository sans package.json lisible n'épingle rien là.
|
|
278
|
+
}
|
|
279
|
+
if (new Set(trouves.map(({ version }) => version)).size < 2) return [];
|
|
280
|
+
return [
|
|
281
|
+
"⚠ Les pins de @ucm-kit/cli diffèrent : alignez-les sur une seule version.",
|
|
282
|
+
...trouves.map(({ chemin, version }) => ` ${chemin} : ${version}`),
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Les modes qui touchent le contrat : un refus quand le fichier de tokens est
|
|
288
|
+
* incohérent, sinon le texte de la section.
|
|
289
|
+
*/
|
|
290
|
+
function modesDuContrat(contrat, contratsParNom, racine, configuration) {
|
|
291
|
+
const source = resolve(racine, configuration.tokens);
|
|
292
|
+
if (!existsSync(source)) return { texte: `## Modes\n\nAucun fichier de tokens à ${configuration.tokens} : aucun axe ne se lit.\n`, cones: undefined };
|
|
293
|
+
|
|
294
|
+
let document;
|
|
295
|
+
try {
|
|
296
|
+
document = lireJson(source);
|
|
297
|
+
} catch {
|
|
298
|
+
return { refus: `${configuration.tokens} est illisible : ce n'est pas du JSON valide.` };
|
|
299
|
+
}
|
|
300
|
+
const format = etatDuFormatDeTokens(document);
|
|
301
|
+
if (format.etat === "future" || format.etat === "invalide") {
|
|
302
|
+
return { refus: `${configuration.tokens} porte une version du format de tokens que cette commande ne lit pas.` };
|
|
303
|
+
}
|
|
304
|
+
const { etat, axes, constats } = axesDeTokens(document);
|
|
305
|
+
if (etat === "incoherent") {
|
|
306
|
+
return { refus: [`${configuration.tokens} déclare des modes incohérents :`, ...constats.map(({ message }) => ` ${message}`)].join("\n") };
|
|
307
|
+
}
|
|
308
|
+
if (etat === "anterieur" || etat === "axe-ecarte") {
|
|
309
|
+
return {
|
|
310
|
+
texte: `## Modes\n\n${configuration.tokens} porte des modes sans axe déclaré : les contextes de ce contrat ne se déterminent pas. Un designer doit réexporter les tokens depuis Figma.\n`,
|
|
311
|
+
cones: undefined,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const cones = conesDesAxes(document, axes);
|
|
316
|
+
const generes = contextesDesAxes(document, axes);
|
|
317
|
+
const { attributs, erreurs, notes } = attributsDesAxes(generes, configuration.modes ?? {});
|
|
318
|
+
if (erreurs.length > 0) return { erreurConfiguration: erreurs.join("\n") };
|
|
319
|
+
|
|
320
|
+
const touches = axesDuContrat(contrat, contratsParNom, cones);
|
|
321
|
+
const touchants = generes.filter(({ nom }) => touches.axes.includes(nom));
|
|
322
|
+
if (touchants.length === 0) return { texte: "## Modes\n\nAucun axe de modes ne touche ce contrat.\n", cones };
|
|
323
|
+
|
|
324
|
+
const axeParNom = new Map(generes.map((axe) => [axe.nom, axe]));
|
|
325
|
+
const selecteur = (contexte) => {
|
|
326
|
+
const entrees = Object.entries(contexte);
|
|
327
|
+
if (entrees.length === 0) return "le contexte par défaut";
|
|
328
|
+
return entrees.map(([nom, mode]) => `\`${attributs.get(nom)}="${mode}"\``).join(" et ");
|
|
329
|
+
};
|
|
330
|
+
const lignes = [
|
|
331
|
+
"## Modes",
|
|
332
|
+
"",
|
|
333
|
+
"Chaque axe se pose par un attribut, sur n'importe quel élément. Le composant ne lit pas le mode et ne déclare aucune variable de token.",
|
|
334
|
+
"",
|
|
335
|
+
...touchants.map((axe) => `- \`${axe.nom}\` : attribut \`${attributs.get(axe.nom)}\`, modes ${axe.modes.map((mode) => (mode === axe.defaut ? `${mode} (défaut)` : mode)).join(", ")}`),
|
|
336
|
+
...notes.map((note) => `- ${note}`),
|
|
337
|
+
"",
|
|
338
|
+
"Contextes à vérifier :",
|
|
339
|
+
"",
|
|
340
|
+
...contextesDeVerification(touchants, touches.croisements.filter((couple) => couple.every((nom) => axeParNom.has(nom))))
|
|
341
|
+
.map((contexte) => `- ${selecteur(contexte)}`),
|
|
342
|
+
"",
|
|
343
|
+
];
|
|
344
|
+
return { texte: lignes.join("\n"), cones };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Lit les contrats du repository ; le contrat visé est toujours du lot. */
|
|
348
|
+
function documentsDuRepository(racine, configuration, cible) {
|
|
349
|
+
const chemins = contratsDuDossier(join(racine, configuration.components)).map((chemin) => resolve(chemin));
|
|
350
|
+
if (!chemins.includes(cible)) chemins.push(cible);
|
|
351
|
+
const documents = [];
|
|
352
|
+
for (const chemin of chemins) {
|
|
353
|
+
try {
|
|
354
|
+
documents.push({ chemin, contrat: lireJson(chemin) });
|
|
355
|
+
} catch {
|
|
356
|
+
// Un contrat voisin illisible relève d'`ucm check`.
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return documents;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function indexParNom(documents) {
|
|
363
|
+
const parNom = new Map();
|
|
364
|
+
for (const { contrat } of documents) {
|
|
365
|
+
if (typeof contrat?.name !== "string") continue;
|
|
366
|
+
const deja = parNom.get(contrat.name);
|
|
367
|
+
parNom.set(contrat.name, deja === undefined ? contrat : [...[deja].flat(), contrat]);
|
|
368
|
+
}
|
|
369
|
+
return parNom;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* La commande `ucm guide`, et son code de sortie. `ecrire` reçoit le guide, ou
|
|
374
|
+
* le compte rendu de son écriture avec `--out` ; `alerter` reçoit les refus.
|
|
375
|
+
*/
|
|
376
|
+
export function guide(arguments_, {
|
|
377
|
+
racine = process.cwd(),
|
|
378
|
+
ecrire = console.log,
|
|
379
|
+
alerter = console.error,
|
|
380
|
+
ecrireFichier = writeFileSync,
|
|
381
|
+
catalogue = catalogueDesAides(),
|
|
382
|
+
} = {}) {
|
|
383
|
+
const { options, erreur } = lireArgumentsGuide(arguments_);
|
|
384
|
+
if (erreur) {
|
|
385
|
+
alerter(`${erreur}\n\n${USAGE_GUIDE}`);
|
|
386
|
+
return 2;
|
|
387
|
+
}
|
|
388
|
+
const { configuration, erreur: erreurConfiguration } = lireConfiguration(racine);
|
|
389
|
+
if (erreurConfiguration) {
|
|
390
|
+
alerter(erreurConfiguration);
|
|
391
|
+
return 2;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const cible = resolve(racine, options.contrat);
|
|
395
|
+
let contrat;
|
|
396
|
+
try {
|
|
397
|
+
contrat = lireJson(cible);
|
|
398
|
+
} catch {
|
|
399
|
+
alerter(`${options.contrat} est introuvable ou n'est pas du JSON valide.`);
|
|
400
|
+
return 2;
|
|
401
|
+
}
|
|
402
|
+
if (!estObjet(contrat)) {
|
|
403
|
+
alerter(`${options.contrat} n'est pas un contrat : sa racine n'est pas un objet.`);
|
|
404
|
+
return 2;
|
|
405
|
+
}
|
|
406
|
+
const verdict = verdictDeVersion(contrat.meta?.contractVersion);
|
|
407
|
+
if (verdict !== "ok") {
|
|
408
|
+
alerter(verdict === "recent"
|
|
409
|
+
? `${options.contrat} est en version ${contrat.meta?.contractVersion}, que cette CLI ne lit pas encore. Un développeur doit mettre à jour @ucm-kit/cli.`
|
|
410
|
+
: `${options.contrat} est en version ${contrat.meta?.contractVersion}, que cette CLI ne lit plus. Un designer doit réexporter le composant depuis Figma.`);
|
|
411
|
+
return 2;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const documents = documentsDuRepository(racine, configuration, cible);
|
|
415
|
+
const fautes = validerGrapheDesContrats(documents).get(cible) ?? [];
|
|
416
|
+
if (fautes.length > 0) {
|
|
417
|
+
alerter([`${options.contrat} ne forme pas un graphe de composition cohérent :`, ...fautes.map((faute) => ` ${faute}`)].join("\n"));
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
420
|
+
const contratsParNom = indexParNom(documents);
|
|
421
|
+
|
|
422
|
+
const modes = modesDuContrat(contrat, contratsParNom, racine, configuration);
|
|
423
|
+
if (modes.erreurConfiguration) {
|
|
424
|
+
alerter(modes.erreurConfiguration);
|
|
425
|
+
return 2;
|
|
426
|
+
}
|
|
427
|
+
if (modes.refus) {
|
|
428
|
+
alerter(modes.refus);
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const cheminConventions = conventionsLesPlusProches(dirname(cible), racine);
|
|
433
|
+
const conventions = cheminConventions === null ? null : lireConventions(readFileSync(cheminConventions, "utf8"), catalogue);
|
|
434
|
+
const caracteristiques = caracteristiquesDuContrat(contrat, contratsParNom, modes.cones);
|
|
435
|
+
const { aides, nonTranches } = aidesDuContrat(caracteristiques, catalogue, conventions);
|
|
436
|
+
|
|
437
|
+
const aRelire = [...avertissements(conventions, cheminConventions, racine, catalogue), ...pinsEnDesaccord(racine)];
|
|
438
|
+
const icones = entreesCitees(contrat.icons, iconesUtilisees(contrat));
|
|
439
|
+
const parties = [
|
|
440
|
+
["à relire", aRelire.length === 0 ? "" : ["## À relire avant de commencer", "", ...aRelire, ""].join("\n")],
|
|
441
|
+
["procédure", `${readFileSync(PROCEDURE, "utf8").replace(/\r\n/g, "\n").replace(/^(#+) /gm, "#$1 ").trim()}\n`],
|
|
442
|
+
["conventions", conventions?.tete
|
|
443
|
+
? `## Conventions du repository\n\n${conventions.tete}\n`
|
|
444
|
+
: `## Conventions du repository\n\nAucun texte de tête dans ${cheminConventions === null ? ".ucm/conventions.md, absent" : enSlash(relative(racine, cheminConventions))}.\n`],
|
|
445
|
+
["contrat", extraction(contrat, contratsParNom)],
|
|
446
|
+
["aides", aides],
|
|
447
|
+
["non tranché", nonTranches],
|
|
448
|
+
["modes", modes.texte],
|
|
449
|
+
["icônes", icones === undefined ? "" : ["## Icônes réclamées", "", ...Object.values(icones).map((icone) => `- ${icone?.figmaName}`), ""].join("\n")],
|
|
450
|
+
].filter(([, texte]) => texte !== "");
|
|
451
|
+
|
|
452
|
+
const taille = [
|
|
453
|
+
"## Taille de ce guide",
|
|
454
|
+
"",
|
|
455
|
+
"| Partie | Octets |",
|
|
456
|
+
"|---|---|",
|
|
457
|
+
...parties.map(([nom, texte]) => `| ${nom} | ${Buffer.byteLength(texte, "utf8")} |`),
|
|
458
|
+
"",
|
|
459
|
+
].join("\n");
|
|
460
|
+
const sortie = [`# Guide d'implémentation : ${contrat.name}`, "", ...parties.map(([, texte]) => texte), taille].join("\n");
|
|
461
|
+
|
|
462
|
+
if (options.out === null) {
|
|
463
|
+
ecrire(sortie);
|
|
464
|
+
return 0;
|
|
465
|
+
}
|
|
466
|
+
const destination = resolve(racine, options.out);
|
|
467
|
+
if (destination === cible || destination === resolve(racine, NOM_CONFIGURATION)) {
|
|
468
|
+
alerter(`--out désigne ${options.out}, que la commande lit : choisissez un fichier à part.`);
|
|
469
|
+
return 2;
|
|
470
|
+
}
|
|
471
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
472
|
+
ecrireFichier(destination, sortie, "utf8");
|
|
473
|
+
ecrire(`${options.out} : ${Buffer.byteLength(sortie, "utf8")} octets.`);
|
|
474
|
+
return 0;
|
|
475
|
+
}
|
package/src/icons.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { join, relative } from "node:path";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { contratsDuDossier } from "./contrats.mjs";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Les icônes réclamées par les contrats d'un repository.
|
|
@@ -17,7 +17,7 @@ import { trouverContrats } from "@ucm-kit/core/lecteurs";
|
|
|
17
17
|
export function iconesDuRepository(racine, dossierComponents) {
|
|
18
18
|
const parNom = new Map();
|
|
19
19
|
|
|
20
|
-
for (const chemin of
|
|
20
|
+
for (const chemin of contratsDuDossier(join(racine, dossierComponents))) {
|
|
21
21
|
let contrat;
|
|
22
22
|
try {
|
|
23
23
|
contrat = JSON.parse(readFileSync(chemin, "utf8").replace(/^/, ""));
|
package/src/init.mjs
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
* workflow que quelqu'un a adapté serait la seule faute irréversible que cette
|
|
10
10
|
* commande puisse commettre.
|
|
11
11
|
*
|
|
12
|
-
* **Elle n'écrit
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* **Elle n'écrit aucune version du format**, nulle part : la configuration
|
|
13
|
+
* n'en porte aucune (voir `configuration.mjs` du kit), et le paquet installé
|
|
14
|
+
* dit ce qu'il lit. Le seul numéro écrit est le pin de la CLI, dans le workflow
|
|
15
|
+
* et dans les deux relais d'agent.
|
|
15
16
|
*
|
|
16
17
|
* **`--components`, `--tokens` et `--implementation` décident une seule fois.** Le
|
|
17
18
|
* `ucm.config.json` écrit ici est la seule autorité sur l'endroit où les
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
* comment nommer ses fichiers d'implémentation, au lieu de porter un `.tsx`
|
|
23
24
|
* faux dès le jour de son installation.
|
|
24
25
|
*/
|
|
25
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
26
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
26
27
|
import { dirname, join } from "node:path";
|
|
27
28
|
|
|
28
29
|
import {
|
|
@@ -30,6 +31,10 @@ import {
|
|
|
30
31
|
MOTIF_IMPLEMENTATION_PAR_DEFAUT,
|
|
31
32
|
NOM_CONFIGURATION,
|
|
32
33
|
} from "@ucm-kit/core/format";
|
|
34
|
+
import { lireConfiguration } from "@ucm-kit/core/lecteurs";
|
|
35
|
+
|
|
36
|
+
import { NOM_ADAPTATEUR_TYPESCRIPT } from "./adaptateur.mjs";
|
|
37
|
+
import { CHEMIN_CONVENTIONS } from "./conventions.mjs";
|
|
33
38
|
|
|
34
39
|
/** Les options qui reçoivent un dossier, et la clé que chacune décide. */
|
|
35
40
|
const OPTIONS_DE_DOSSIER = { "--components": "components", "--tokens": "tokens" };
|
|
@@ -75,9 +80,14 @@ function cheminAcceptable(valeur) {
|
|
|
75
80
|
*/
|
|
76
81
|
export function lireArgumentsInit(arguments_) {
|
|
77
82
|
const chemins = {};
|
|
83
|
+
let sansAgents = false;
|
|
78
84
|
|
|
79
85
|
for (let i = 0; i < arguments_.length; i += 1) {
|
|
80
86
|
const argument = arguments_[i];
|
|
87
|
+
if (argument === "--sans-agents") {
|
|
88
|
+
sansAgents = true;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
81
91
|
const cle = OPTIONS_DE_DOSSIER[argument];
|
|
82
92
|
if (!cle && argument !== "--implementation") {
|
|
83
93
|
return { erreur: `Argument inconnu : ${argument}` };
|
|
@@ -113,7 +123,7 @@ export function lireArgumentsInit(arguments_) {
|
|
|
113
123
|
chemins[cle] = cle === "tokens" ? `${resolu}/${NOM_FICHIER_TOKENS}` : resolu;
|
|
114
124
|
}
|
|
115
125
|
|
|
116
|
-
return { chemins };
|
|
126
|
+
return { chemins, sansAgents };
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
/** La version de `@ucm-kit/cli`, lue dans son propre `package.json`. */
|
|
@@ -139,7 +149,7 @@ function versionDuPaquet() {
|
|
|
139
149
|
* présents, le rappel se tait : trois lignes réclamées pour rien sont trois
|
|
140
150
|
* lignes qu'on apprend à sauter.
|
|
141
151
|
*/
|
|
142
|
-
function fichiers(version, chemins) {
|
|
152
|
+
function fichiers(version, chemins, { agents = true, gabarits = [] } = {}) {
|
|
143
153
|
return [
|
|
144
154
|
{
|
|
145
155
|
chemin: NOM_CONFIGURATION,
|
|
@@ -203,9 +213,125 @@ function fichiers(version, chemins) {
|
|
|
203
213
|
chemin: ".github/workflows/ucm.yml",
|
|
204
214
|
contenu: workflow(version),
|
|
205
215
|
},
|
|
216
|
+
...(agents
|
|
217
|
+
? [
|
|
218
|
+
{ chemin: ".agents/skills/ucm-implementer/SKILL.md", contenu: relais(version) },
|
|
219
|
+
{ chemin: ".claude/skills/ucm-implementer/SKILL.md", contenu: relais(version) },
|
|
220
|
+
{ chemin: CHEMIN_CONVENTIONS.split("\\").join("/"), contenu: CONVENTIONS },
|
|
221
|
+
...gabarits,
|
|
222
|
+
]
|
|
223
|
+
: []),
|
|
206
224
|
];
|
|
207
225
|
}
|
|
208
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Le relais qu'un agent découvre dans `.agents/skills` ou `.claude/skills`. Il
|
|
229
|
+
* épingle la CLI et renvoie à `ucm guide`, qui imprime la procédure et les
|
|
230
|
+
* aides du contrat : le relais ne recopie aucune règle.
|
|
231
|
+
*/
|
|
232
|
+
function relais(version) {
|
|
233
|
+
return [
|
|
234
|
+
"---",
|
|
235
|
+
"name: ucm-implementer",
|
|
236
|
+
"description: Implémenter ou modifier un composant décrit par un fichier *.contract.json. Charger avant d'écrire le code du composant.",
|
|
237
|
+
"---",
|
|
238
|
+
"",
|
|
239
|
+
`Lancer \`npx --yes @ucm-kit/cli@${version} guide <chemin du contrat>\`, puis suivre sa sortie.`,
|
|
240
|
+
"",
|
|
241
|
+
].join("\n");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Le fichier de conventions : sa marche à suivre et son exemple, en commentaire que la lecture retire. */
|
|
245
|
+
const CONVENTIONS = [
|
|
246
|
+
"<!-- ucm : marche à suivre, retirée à la lecture.",
|
|
247
|
+
"",
|
|
248
|
+
"Le texte avant la première section décrit la stack, l'architecture et le",
|
|
249
|
+
"gabarit ou le composant de référence du repository.",
|
|
250
|
+
"",
|
|
251
|
+
"Une section « ## <aide> » remplace l'écriture par défaut de cette aide, ou",
|
|
252
|
+
"répond à un ancrage. `ucm aides` liste les aides ; `ucm aides <aide>",
|
|
253
|
+
"--personnaliser` ajoute la section, à éditer.",
|
|
254
|
+
"",
|
|
255
|
+
"Une ligne « Contrôle : `commande` » ajoute la commande à la preuve de l'aide.",
|
|
256
|
+
"",
|
|
257
|
+
"« ecritures-par-defaut: non » en première ligne retire les écritures par",
|
|
258
|
+
"défaut, pour un repository qui n'écrit pas de CSS.",
|
|
259
|
+
"",
|
|
260
|
+
"Exemple :",
|
|
261
|
+
"",
|
|
262
|
+
"Stack : React 19 et CSS Modules. Un composant par dossier, tests à côté.",
|
|
263
|
+
"Gabarit : `.ucm/gabarits/composant.tsx`.",
|
|
264
|
+
"",
|
|
265
|
+
"## contour-ring",
|
|
266
|
+
"",
|
|
267
|
+
"Classe `ring` de `src/styles/contours.module.css`.",
|
|
268
|
+
"",
|
|
269
|
+
"Contrôle : `npm run lint:css`",
|
|
270
|
+
"-->",
|
|
271
|
+
"",
|
|
272
|
+
].join("\n");
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Les gabarits qu'un adaptateur publie, à copier dans `.ucm/gabarits/`. Rend
|
|
276
|
+
* `erreur` quand le dossier annoncé ne se lit pas.
|
|
277
|
+
*/
|
|
278
|
+
function gabaritsDe(adaptateur) {
|
|
279
|
+
const dossier = adaptateur?.cheminGabarits;
|
|
280
|
+
if (typeof dossier !== "string") return { gabarits: [], erreur: null };
|
|
281
|
+
try {
|
|
282
|
+
const gabarits = readdirSync(dossier, { withFileTypes: true })
|
|
283
|
+
.filter((entree) => entree.isFile())
|
|
284
|
+
.map(({ name }) => ({ chemin: `.ucm/gabarits/${name}`, contenu: readFileSync(join(dossier, name), "utf8") }));
|
|
285
|
+
return { gabarits, erreur: null };
|
|
286
|
+
} catch (erreur) {
|
|
287
|
+
return { gabarits: [], erreur: `ses gabarits ne se lisent pas (${erreur?.code ?? erreur?.message ?? erreur})` };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Les lignes qu'`init` n'écrit pas, parce qu'elles vivent dans un fichier que
|
|
293
|
+
* le repository possède, chacune avec son fichier. Une ligne déjà présente ne
|
|
294
|
+
* se réclame pas.
|
|
295
|
+
*/
|
|
296
|
+
function lignesRestantes(racine, version, configuration) {
|
|
297
|
+
const lignes = [];
|
|
298
|
+
let manifeste = null;
|
|
299
|
+
try {
|
|
300
|
+
manifeste = JSON.parse(readFileSync(join(racine, "package.json"), "utf8"));
|
|
301
|
+
} catch {
|
|
302
|
+
// Un repository sans package.json lisible ne génère pas la feuille des tokens par npm.
|
|
303
|
+
}
|
|
304
|
+
if (manifeste !== null) {
|
|
305
|
+
const epingle = manifeste.devDependencies?.["@ucm-kit/cli"] ?? manifeste.dependencies?.["@ucm-kit/cli"];
|
|
306
|
+
// Une archive, un lien ou un espace de travail installent la CLI sans numéro à comparer.
|
|
307
|
+
if (epingle === undefined || (epingle !== version && !/^[a-z][a-z+]*:/i.test(epingle))) {
|
|
308
|
+
lignes.push({ fichier: "package.json", ligne: `ajoutez \`"@ucm-kit/cli": "${version}"\` aux devDependencies.` });
|
|
309
|
+
}
|
|
310
|
+
const scripts = Object.values(manifeste.scripts ?? {}).join("\n");
|
|
311
|
+
if (!scripts.includes("ucm tokens css")) {
|
|
312
|
+
lignes.push({
|
|
313
|
+
fichier: "package.json",
|
|
314
|
+
ligne: "lancez `ucm tokens css --out src/generated/tokens.css` en tête des scripts dev et build, à la place de tout autre générateur de la même feuille.",
|
|
315
|
+
});
|
|
316
|
+
lignes.push({ fichier: "l'entrée CSS de l'application", ligne: "importez la feuille générée, `src/generated/tokens.css`." });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (configuration && configuration.modes === undefined) {
|
|
320
|
+
try {
|
|
321
|
+
const axes = JSON.parse(readFileSync(join(racine, configuration.tokens), "utf8"))?.$extensions?.["com.ucm.axes"];
|
|
322
|
+
if (axes && typeof axes === "object" && Object.keys(axes).length > 0) {
|
|
323
|
+
lignes.push({
|
|
324
|
+
fichier: NOM_CONFIGURATION,
|
|
325
|
+
ligne: "la section modes, facultative, nomme l'attribut HTML de chaque axe ; sans elle, un axe prend `data-` suivi de son nom.",
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
} catch {
|
|
329
|
+
// Sans fichier de tokens lisible, aucun axe ne se lit.
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return lignes;
|
|
333
|
+
}
|
|
334
|
+
|
|
209
335
|
/**
|
|
210
336
|
* Le workflow de contrôle, écrit pour un repository quelconque.
|
|
211
337
|
*
|
|
@@ -324,12 +450,19 @@ function workflow(version) {
|
|
|
324
450
|
* mi-chemin laisserait un repo à moitié installé, état que rien ne sait
|
|
325
451
|
* diagnostiquer ensuite.
|
|
326
452
|
*/
|
|
327
|
-
export function init(racine, {
|
|
453
|
+
export function init(racine, {
|
|
454
|
+
ecrire = writeFileSync,
|
|
455
|
+
chemins = {},
|
|
456
|
+
sansAgents = false,
|
|
457
|
+
adaptateur = null,
|
|
458
|
+
erreurAdaptateur = null,
|
|
459
|
+
} = {}) {
|
|
328
460
|
const version = versionDuPaquet();
|
|
329
461
|
const aEcrire = [];
|
|
330
462
|
const deja = [];
|
|
463
|
+
const { gabarits, erreur: erreurGabarits } = sansAgents ? { gabarits: [], erreur: null } : gabaritsDe(adaptateur);
|
|
331
464
|
|
|
332
|
-
for (const fichier of fichiers(version, chemins)) {
|
|
465
|
+
for (const fichier of fichiers(version, chemins, { agents: !sansAgents, gabarits })) {
|
|
333
466
|
const cible = join(racine, fichier.chemin);
|
|
334
467
|
if (existsSync(cible)) deja.push({ ...fichier, cible });
|
|
335
468
|
else aEcrire.push({ ...fichier, cible });
|
|
@@ -367,6 +500,19 @@ export function init(racine, { ecrire = writeFileSync, chemins = {} } = {}) {
|
|
|
367
500
|
? { ...CONFIGURATION_PAR_DEFAUT, ...chemins }
|
|
368
501
|
: null,
|
|
369
502
|
version,
|
|
503
|
+
agents: !sansAgents,
|
|
504
|
+
// `absent` quand aucun adaptateur n'est installé, le message quand il n'a pas pu servir.
|
|
505
|
+
adaptateur: erreurAdaptateur
|
|
506
|
+
? { erreur: erreurAdaptateur?.message ?? String(erreurAdaptateur) }
|
|
507
|
+
: erreurGabarits ? { erreur: erreurGabarits } : adaptateur ? "trouve" : "absent",
|
|
508
|
+
nodeJs: existsSync(join(racine, "package.json")),
|
|
509
|
+
lignes: lignesRestantes(
|
|
510
|
+
racine,
|
|
511
|
+
version,
|
|
512
|
+
aEcrire.some((f) => f.chemin === NOM_CONFIGURATION)
|
|
513
|
+
? { ...CONFIGURATION_PAR_DEFAUT, ...chemins }
|
|
514
|
+
: lireConfiguration(racine).configuration,
|
|
515
|
+
),
|
|
370
516
|
};
|
|
371
517
|
}
|
|
372
518
|
|
|
@@ -403,6 +549,10 @@ export function rendreInit({
|
|
|
403
549
|
optionsIgnorees = false,
|
|
404
550
|
chemins = null,
|
|
405
551
|
version,
|
|
552
|
+
agents = false,
|
|
553
|
+
adaptateur = "absent",
|
|
554
|
+
nodeJs = false,
|
|
555
|
+
lignes: restantes = [],
|
|
406
556
|
}) {
|
|
407
557
|
const lignes = [];
|
|
408
558
|
for (const chemin of ecrits) lignes.push(`✓ ${chemin}`);
|
|
@@ -416,9 +566,11 @@ export function rendreInit({
|
|
|
416
566
|
: `Les chemins restent ceux que ce repository déclare dans son ${NOM_CONFIGURATION}. `
|
|
417
567
|
+ "Lancez `ucm check`.";
|
|
418
568
|
lignes.push(
|
|
419
|
-
ecrits.length
|
|
420
|
-
?
|
|
421
|
-
:
|
|
569
|
+
ecrits.length > 0
|
|
570
|
+
? `Installé avec @ucm-kit/cli ${version}.\n${ou}`
|
|
571
|
+
: restantes.length === 0
|
|
572
|
+
? "Rien à faire : ce repository est déjà installé."
|
|
573
|
+
: "Aucun fichier à écrire : ce repository est déjà installé.",
|
|
422
574
|
);
|
|
423
575
|
|
|
424
576
|
if (optionsIgnorees) {
|
|
@@ -434,5 +586,21 @@ export function rendreInit({
|
|
|
434
586
|
lignes.push("");
|
|
435
587
|
lignes.push(`· \`${chemin}\` existait déjà : ${rappel}`);
|
|
436
588
|
}
|
|
589
|
+
|
|
590
|
+
if (typeof adaptateur === "object" && adaptateur !== null) {
|
|
591
|
+
lignes.push("");
|
|
592
|
+
lignes.push(`· ${NOM_ADAPTATEUR_TYPESCRIPT} est installé mais n'a pas servi : ${adaptateur.erreur}. `
|
|
593
|
+
+ "Les gabarits n'ont pas été copiés ; le reste de l'installation est fait.");
|
|
594
|
+
} else if (agents && nodeJs && adaptateur === "absent") {
|
|
595
|
+
lignes.push("");
|
|
596
|
+
lignes.push(`· Relancez \`ucm init\` après avoir installé ${NOM_ADAPTATEUR_TYPESCRIPT} pour recevoir le gabarit `
|
|
597
|
+
+ "dans `.ucm/gabarits/`.");
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (restantes.length > 0) {
|
|
601
|
+
lignes.push("");
|
|
602
|
+
lignes.push("Reste à ajouter à la main :");
|
|
603
|
+
for (const { fichier, ligne } of restantes) lignes.push(`- ${fichier} : ${ligne}`);
|
|
604
|
+
}
|
|
437
605
|
return lignes.join("\n");
|
|
438
606
|
}
|
package/src/tokens-css.mjs
CHANGED
|
@@ -31,9 +31,10 @@ import {
|
|
|
31
31
|
indexerTokensDtcg,
|
|
32
32
|
lireConfiguration,
|
|
33
33
|
sansEchantillon,
|
|
34
|
-
trouverContrats,
|
|
35
34
|
} from "@ucm-kit/core/lecteurs";
|
|
36
35
|
|
|
36
|
+
import { contratsDuDossier } from "./contrats.mjs";
|
|
37
|
+
|
|
37
38
|
export const USAGE_TOKENS = "ucm tokens css --out <fichier> [--sans-modes]";
|
|
38
39
|
|
|
39
40
|
const possede = (objet, cle) => Object.prototype.hasOwnProperty.call(objet, cle);
|
|
@@ -443,7 +444,7 @@ export function lireArgumentsTokens(arguments_) {
|
|
|
443
444
|
/** Les contrats du repository qui citent au moins une référence de token. */
|
|
444
445
|
function contratsQuiCitentDesTokens(racine, dossierComponents) {
|
|
445
446
|
const cites = [];
|
|
446
|
-
for (const chemin of
|
|
447
|
+
for (const chemin of contratsDuDossier(join(racine, dossierComponents))) {
|
|
447
448
|
try {
|
|
448
449
|
const contrat = JSON.parse(readFileSync(chemin, "utf8").replace(/^\uFEFF/, ""));
|
|
449
450
|
if (collecterReferences(sansEchantillon(contrat)).size > 0) cites.push(relative(racine, chemin).split("\\").join("/"));
|
package/src/ucm.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { lireConfiguration } from "@ucm-kit/core/lecteurs";
|
|
|
13
13
|
import { chargerAdaptateur, NOM_ADAPTATEUR_TYPESCRIPT } from "./adaptateur.mjs";
|
|
14
14
|
import { aides } from "./aides.mjs";
|
|
15
15
|
import { check } from "./check.mjs";
|
|
16
|
+
import { guide } from "./guide.mjs";
|
|
16
17
|
import { iconesDuRepository, rendreIcones } from "./icons.mjs";
|
|
17
18
|
import { init, lireArgumentsInit, rendreInit } from "./init.mjs";
|
|
18
19
|
import { tokensCss } from "./tokens-css.mjs";
|
|
@@ -42,13 +43,16 @@ const AIDE = `ucm — la ligne de commande UCM
|
|
|
42
43
|
ucm icons liste les icônes que les contrats réclament
|
|
43
44
|
ucm tokens css écrit la feuille CSS des tokens et de leurs modes
|
|
44
45
|
ucm aides liste les aides à l'implémentation et leur origine
|
|
46
|
+
ucm guide imprime ce qu'un agent lit avant d'implémenter un contrat
|
|
45
47
|
ucm --help affiche cette aide
|
|
46
48
|
|
|
47
|
-
ucm init [--components <dossier>] [--tokens <dossier>] [--implementation <motif>]
|
|
49
|
+
ucm init [--components <dossier>] [--tokens <dossier>] [--implementation <motif>] [--sans-agents]
|
|
48
50
|
--components dossier sous lequel les contrats sont rangés
|
|
49
51
|
--tokens dossier qui reçoit tokens.json
|
|
50
52
|
--implementation où vit l'implémentation d'un contrat, {dir} et {id}
|
|
51
53
|
pour son dossier et son identifiant
|
|
54
|
+
--sans-agents n'écrit ni les relais d'agent, ni .ucm/conventions.md,
|
|
55
|
+
ni les gabarits
|
|
52
56
|
Les trois n'agissent qu'à la première installation : ucm init n'écrase
|
|
53
57
|
jamais un ucm.config.json existant.
|
|
54
58
|
|
|
@@ -67,6 +71,10 @@ const AIDE = `ucm — la ligne de commande UCM
|
|
|
67
71
|
--personnaliser ajoute la section de l'aide au .ucm/conventions.md le
|
|
68
72
|
plus proche du chemin, à éditer, sans rien écraser
|
|
69
73
|
|
|
74
|
+
ucm guide <contrat> [--out <fichier>]
|
|
75
|
+
<contrat> le fichier .contract.json à implémenter
|
|
76
|
+
--out écrit le guide dans ce fichier plutôt que dans le terminal
|
|
77
|
+
|
|
70
78
|
Codes de sortie : 0 tout est passé, 1 des contrôles ont échoué, 2 l'invocation
|
|
71
79
|
ou la configuration est fautive.`;
|
|
72
80
|
|
|
@@ -85,14 +93,20 @@ export function executer(arguments_, {
|
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
if (commande === "init") {
|
|
88
|
-
const { chemins, erreur } = lireArgumentsInit(arguments_.slice(1));
|
|
96
|
+
const { chemins, sansAgents, erreur } = lireArgumentsInit(arguments_.slice(1));
|
|
89
97
|
if (erreur) {
|
|
90
98
|
const alerter = sorties.alerter ?? console.error;
|
|
91
|
-
alerter(`${erreur}\n\nucm init [--components <dossier>] [--tokens <dossier>]`);
|
|
99
|
+
alerter(`${erreur}\n\nucm init [--components <dossier>] [--tokens <dossier>] [--implementation <motif>] [--sans-agents]`);
|
|
92
100
|
return 2;
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
// Un adaptateur qui ne se charge pas prive le repository de ses gabarits,
|
|
103
|
+
// pas du reste de l'installation : `init` reçoit l'erreur et la rapporte.
|
|
104
|
+
return chargerAdaptateur(racine)
|
|
105
|
+
.then((adaptateur) => ({ adaptateur }), (erreurAdaptateur) => ({ erreurAdaptateur }))
|
|
106
|
+
.then((chargement) => {
|
|
107
|
+
ecrire(rendreInit(init(racine, { chemins, sansAgents, ...chargement })));
|
|
108
|
+
return 0;
|
|
109
|
+
});
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
if (commande === "check") {
|
|
@@ -136,6 +150,10 @@ export function executer(arguments_, {
|
|
|
136
150
|
return aides(arguments_.slice(1), { racine, ecrire, alerter: sorties.alerter ?? console.error });
|
|
137
151
|
}
|
|
138
152
|
|
|
153
|
+
if (commande === "guide") {
|
|
154
|
+
return guide(arguments_.slice(1), { racine, ecrire, alerter: sorties.alerter ?? console.error });
|
|
155
|
+
}
|
|
156
|
+
|
|
139
157
|
if (commande === "icons") {
|
|
140
158
|
const { configuration, erreur } = lireConfiguration(racine);
|
|
141
159
|
if (erreur) {
|