@ucm-kit/cli 0.1.13 → 0.1.16
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 +28 -5
- package/package.json +2 -2
- package/src/init.mjs +130 -12
- package/src/ucm.mjs +14 -2
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ exported them.
|
|
|
5
5
|
|
|
6
6
|
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
|
-
written by the [
|
|
8
|
+
written by the [UCM Contract Exporter](https://github.com/Vassili-g/UCM-Exporter)
|
|
9
9
|
Figma plugin and committed next to the component's code. This command reads
|
|
10
10
|
those files and says whether they still hold together.
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
13
|
+
npx --yes @ucm-kit/cli@0.1.16 init
|
|
14
|
+
npx --yes @ucm-kit/cli@0.1.16 check --report ci-report.md
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Pin an exact version, without `^`. A range would let npx pick a build nobody
|
|
@@ -36,6 +36,23 @@ that any optional stack adapter the repository installed becomes visible to
|
|
|
36
36
|
| `ucm icons` | Lists the icons the contracts ask this repository to draw |
|
|
37
37
|
| `ucm --help` | Prints the above |
|
|
38
38
|
|
|
39
|
+
`ucm init` takes two options:
|
|
40
|
+
|
|
41
|
+
| Option | Effect |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `--components <dir>` | The folder the contracts are stored under |
|
|
44
|
+
| `--tokens <dir>` | The folder that holds `tokens.json` |
|
|
45
|
+
|
|
46
|
+
Both take a folder, because a folder is what a repository arranges. `--tokens`
|
|
47
|
+
appends the file name before writing it, so the `tokens` field of
|
|
48
|
+
`ucm.config.json` stays a file path: the readers treat it as one, and turning it
|
|
49
|
+
into a folder would silently point every configuration already written at
|
|
50
|
+
`tokens.json/tokens.json`.
|
|
51
|
+
|
|
52
|
+
Both act only on a first install: `ucm init` never overwrites an existing
|
|
53
|
+
configuration, and says so when options were passed to a repository that already
|
|
54
|
+
has one.
|
|
55
|
+
|
|
39
56
|
`ucm check` takes two options:
|
|
40
57
|
|
|
41
58
|
| Option | Effect |
|
|
@@ -70,8 +87,14 @@ The workflow is yours once written. It will never be overwritten.
|
|
|
70
87
|
|
|
71
88
|
### `ucm.config.json`
|
|
72
89
|
|
|
73
|
-
Three paths, and nothing else.
|
|
74
|
-
|
|
90
|
+
Three paths, and nothing else. **This file is the only authority on where an
|
|
91
|
+
export lands.** The Figma plugin reads it before publishing, and `ucm check`
|
|
92
|
+
reads it before looking for contracts. A repository that arranges things
|
|
93
|
+
differently says so here, once, and both sides follow.
|
|
94
|
+
|
|
95
|
+
Its absence is the nominal case, not an error: the defaults below apply, and a
|
|
96
|
+
repository with a single `components/` folder works without writing a line. A
|
|
97
|
+
file that exists but is malformed is refused on both sides.
|
|
75
98
|
|
|
76
99
|
```json
|
|
77
100
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
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",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"test": "node scripts/run-tests.cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ucm-kit/core": "0.1.
|
|
30
|
+
"@ucm-kit/core": "0.1.18"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/init.mjs
CHANGED
|
@@ -12,12 +12,86 @@
|
|
|
12
12
|
* **Elle n'écrit aucun numéro de version**, nulle part : ni dans la
|
|
13
13
|
* configuration (voir `configuration.mjs` du kit), ni dans le workflow, qui
|
|
14
14
|
* épingle le paquet et laisse le paquet dire ce qu'il lit.
|
|
15
|
+
*
|
|
16
|
+
* **`--components` et `--tokens` décident de l'endroit une seule fois.** Le
|
|
17
|
+
* `ucm.config.json` écrit ici est la seule autorité sur l'endroit où les
|
|
18
|
+
* exports atterrissent : le plugin Figma le lit, et `ucm check` le lit. Un
|
|
19
|
+
* repository qui range ailleurs que sous `components/` le dit donc à
|
|
20
|
+
* l'installation, au lieu de le corriger après un premier export déposé où
|
|
21
|
+
* personne ne le cherche.
|
|
15
22
|
*/
|
|
16
23
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
24
|
import { dirname, join } from "node:path";
|
|
18
25
|
|
|
19
26
|
import { CONFIGURATION_PAR_DEFAUT, NOM_CONFIGURATION } from "@ucm-kit/core/format";
|
|
20
27
|
|
|
28
|
+
/** Les deux options d'`init`, et la clé de configuration que chacune décide. */
|
|
29
|
+
const OPTIONS_DE_CHEMIN = { "--components": "components", "--tokens": "tokens" };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Le nom du fichier de tokens, lu dans le défaut du kit plutôt que réécrit ici.
|
|
33
|
+
*
|
|
34
|
+
* Les deux options attendent un dossier, parce que c'est ce qu'un repository
|
|
35
|
+
* range. Le champ `tokens` de la configuration, lui, reste un chemin de
|
|
36
|
+
* fichier : le kit le lit ainsi, et changer sa nature ferait pointer toute
|
|
37
|
+
* configuration déjà écrite vers `tokens.json/tokens.json`, sans un mot.
|
|
38
|
+
*/
|
|
39
|
+
const NOM_FICHIER_TOKENS = CONFIGURATION_PAR_DEFAUT.tokens.split("/").pop();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Un chemin acceptable dans la configuration : relatif, en `/`, sans segment
|
|
43
|
+
* qui remonte. La garde est ici et pas dans la grammaire du kit : celle-ci
|
|
44
|
+
* décrit ce qu'un `ucm.config.json` déjà écrit a le droit de contenir, et la
|
|
45
|
+
* durcir changerait le format. Ce qu'une commande accepte de taper au clavier
|
|
46
|
+
* est une autre question, et c'est celle-là qui se pose ici.
|
|
47
|
+
*/
|
|
48
|
+
function cheminAcceptable(valeur) {
|
|
49
|
+
const normalise = valeur.trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
50
|
+
if (!normalise) return null;
|
|
51
|
+
const segments = normalise.split("/");
|
|
52
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) return null;
|
|
53
|
+
return segments.join("/");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Lit les arguments d'`ucm init`.
|
|
58
|
+
*
|
|
59
|
+
* Les deux options attendent un dossier. `--tokens` y ajoute le nom du fichier
|
|
60
|
+
* avant de l'écrire dans la configuration, qui garde un chemin de fichier.
|
|
61
|
+
*
|
|
62
|
+
* Même forme que `lireArguments` de `check.mjs`, y compris le refus d'une
|
|
63
|
+
* valeur qui commence par `--` : sans lui, `--components --tokens x` prendrait
|
|
64
|
+
* « --tokens » pour un dossier et écrirait une configuration que personne n'a
|
|
65
|
+
* demandée. Un argument inconnu est refusé au lieu d'être ignoré, faute de quoi
|
|
66
|
+
* `ucm init --composants src` sortirait en 0 sans avoir rien fait de ce qui
|
|
67
|
+
* était demandé.
|
|
68
|
+
*/
|
|
69
|
+
export function lireArgumentsInit(arguments_) {
|
|
70
|
+
const chemins = {};
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < arguments_.length; i += 1) {
|
|
73
|
+
const argument = arguments_[i];
|
|
74
|
+
const cle = OPTIONS_DE_CHEMIN[argument];
|
|
75
|
+
if (!cle) return { erreur: `Argument inconnu : ${argument}` };
|
|
76
|
+
|
|
77
|
+
const valeur = arguments_[i + 1];
|
|
78
|
+
if (valeur === undefined || valeur.startsWith("--")) {
|
|
79
|
+
return { erreur: `${argument} attend une valeur.` };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const dossier = cheminAcceptable(valeur);
|
|
83
|
+
if (!dossier) {
|
|
84
|
+
return {
|
|
85
|
+
erreur: `${argument} attend un dossier relatif au repository, sans « .. » : ${valeur} n'en est pas un.`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
chemins[cle] = cle === "tokens" ? `${dossier}/${NOM_FICHIER_TOKENS}` : dossier;
|
|
89
|
+
i += 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { chemins };
|
|
93
|
+
}
|
|
94
|
+
|
|
21
95
|
/** La version de `@ucm-kit/cli`, lue dans son propre `package.json`. */
|
|
22
96
|
function versionDuPaquet() {
|
|
23
97
|
const chemin = new URL("../package.json", import.meta.url);
|
|
@@ -41,7 +115,7 @@ function versionDuPaquet() {
|
|
|
41
115
|
* présents, le rappel se tait : trois lignes réclamées pour rien sont trois
|
|
42
116
|
* lignes qu'on apprend à sauter.
|
|
43
117
|
*/
|
|
44
|
-
function fichiers(version) {
|
|
118
|
+
function fichiers(version, chemins) {
|
|
45
119
|
return [
|
|
46
120
|
{
|
|
47
121
|
chemin: NOM_CONFIGURATION,
|
|
@@ -49,7 +123,7 @@ function fichiers(version) {
|
|
|
49
123
|
// Pas de `$schema` : aucun schéma de configuration n'est publié
|
|
50
124
|
// aujourd'hui, et pointer vers une URL qui rend 404 apprendrait à
|
|
51
125
|
// l'éditeur — et à qui lit le fichier — à ignorer cette ligne.
|
|
52
|
-
{ ...CONFIGURATION_PAR_DEFAUT },
|
|
126
|
+
{ ...CONFIGURATION_PAR_DEFAUT, ...chemins },
|
|
53
127
|
null,
|
|
54
128
|
2,
|
|
55
129
|
)}\n`,
|
|
@@ -92,14 +166,14 @@ function fichiers(version) {
|
|
|
92
166
|
{
|
|
93
167
|
chemin: ".gitignore",
|
|
94
168
|
contenu: [
|
|
95
|
-
"# Le rapport
|
|
96
|
-
"#
|
|
97
|
-
"#
|
|
169
|
+
"# Le rapport de `ucm check --report`, réécrit à chaque exécution.",
|
|
170
|
+
"# Commité, il montrerait le verdict d'un contrôle passé, pas celui du",
|
|
171
|
+
"# code en cours.",
|
|
98
172
|
"ci-report.md",
|
|
99
173
|
"",
|
|
100
174
|
].join("\n"),
|
|
101
175
|
marqueurs: ["ci-report.md"],
|
|
102
|
-
rappel: "ajoutez-y `ci-report.md
|
|
176
|
+
rappel: "ajoutez-y `ci-report.md`. `ucm check --report` le réécrit à chaque exécution ; commité, il montrerait le verdict d'un contrôle passé, pas celui du code en cours.",
|
|
103
177
|
},
|
|
104
178
|
{
|
|
105
179
|
chemin: ".github/workflows/ucm.yml",
|
|
@@ -226,12 +300,12 @@ function workflow(version) {
|
|
|
226
300
|
* mi-chemin laisserait un repo à moitié installé, état que rien ne sait
|
|
227
301
|
* diagnostiquer ensuite.
|
|
228
302
|
*/
|
|
229
|
-
export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
303
|
+
export function init(racine, { ecrire = writeFileSync, chemins = {} } = {}) {
|
|
230
304
|
const version = versionDuPaquet();
|
|
231
305
|
const aEcrire = [];
|
|
232
306
|
const deja = [];
|
|
233
307
|
|
|
234
|
-
for (const fichier of fichiers(version)) {
|
|
308
|
+
for (const fichier of fichiers(version, chemins)) {
|
|
235
309
|
const cible = join(racine, fichier.chemin);
|
|
236
310
|
if (existsSync(cible)) deja.push({ ...fichier, cible });
|
|
237
311
|
else aEcrire.push({ ...fichier, cible });
|
|
@@ -242,6 +316,7 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
242
316
|
ecrire(fichier.cible, fichier.contenu, "utf8");
|
|
243
317
|
}
|
|
244
318
|
|
|
319
|
+
const optionsDemandees = Object.keys(chemins).length > 0;
|
|
245
320
|
return {
|
|
246
321
|
ecrits: aEcrire.map((f) => f.chemin),
|
|
247
322
|
conserves: deja.map((f) => f.chemin),
|
|
@@ -249,6 +324,24 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
249
324
|
chemin: f.chemin,
|
|
250
325
|
rappel: f.rappel,
|
|
251
326
|
})),
|
|
327
|
+
/*
|
|
328
|
+
* Des chemins demandés à une commande qui n'écrase rien, sur un repository
|
|
329
|
+
* qui a déjà sa configuration. Le silence se lirait comme « c'est fait »,
|
|
330
|
+
* et le premier export irait ailleurs que là où on croit l'avoir envoyé.
|
|
331
|
+
* Ce n'est pas un `rappel` : les trois rappels nomment une ligne à ajouter
|
|
332
|
+
* à un fichier partagé, et les mélanger ferait de la liste entière quelque
|
|
333
|
+
* chose qu'on apprend à sauter.
|
|
334
|
+
*/
|
|
335
|
+
optionsIgnorees: optionsDemandees && deja.some((f) => f.chemin === NOM_CONFIGURATION),
|
|
336
|
+
/*
|
|
337
|
+
* Les chemins écrits, et `null` quand la configuration a été conservée :
|
|
338
|
+
* ce sont alors ceux du fichier déjà là, qu'`init` n'a pas lu. Les
|
|
339
|
+
* afficher quand même reviendrait à annoncer un endroit sur la foi d'un
|
|
340
|
+
* défaut, devant un fichier qui dit peut-être autre chose.
|
|
341
|
+
*/
|
|
342
|
+
chemins: aEcrire.some((f) => f.chemin === NOM_CONFIGURATION)
|
|
343
|
+
? { ...CONFIGURATION_PAR_DEFAUT, ...chemins }
|
|
344
|
+
: null,
|
|
252
345
|
version,
|
|
253
346
|
};
|
|
254
347
|
}
|
|
@@ -260,6 +353,10 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
260
353
|
* silence sur la seule chose que cette commande ne sait pas installer.
|
|
261
354
|
*/
|
|
262
355
|
function porteLaRegle(fichier) {
|
|
356
|
+
// Un fichier sans marqueur n'a rien à reconnaître. Sans cette ligne, la
|
|
357
|
+
// réponse serait juste par accident : `undefined.every` lève, et c'est le
|
|
358
|
+
// `catch` écrit pour un fichier illisible qui rendrait `false`.
|
|
359
|
+
if (!fichier.marqueurs) return false;
|
|
263
360
|
try {
|
|
264
361
|
const contenu = readFileSync(fichier.cible, "utf8");
|
|
265
362
|
return fichier.marqueurs.every((marqueur) => contenu.includes(marqueur));
|
|
@@ -275,19 +372,40 @@ function porteLaRegle(fichier) {
|
|
|
275
372
|
* quel » ne suffit pas à la remplacer : cette mention se lit comme « rien à
|
|
276
373
|
* faire », alors que la moitié de l'installation manque précisément là.
|
|
277
374
|
*/
|
|
278
|
-
export function rendreInit({
|
|
375
|
+
export function rendreInit({
|
|
376
|
+
ecrits,
|
|
377
|
+
conserves,
|
|
378
|
+
rappels = [],
|
|
379
|
+
optionsIgnorees = false,
|
|
380
|
+
chemins = null,
|
|
381
|
+
version,
|
|
382
|
+
}) {
|
|
279
383
|
const lignes = [];
|
|
280
384
|
for (const chemin of ecrits) lignes.push(`✓ ${chemin}`);
|
|
281
385
|
for (const chemin of conserves) lignes.push(`· ${chemin} existait déjà, laissé tel quel`);
|
|
282
386
|
lignes.push("");
|
|
387
|
+
// L'endroit vient de la configuration écrite, jamais d'une convention
|
|
388
|
+
// recopiée ici : les deux dériveraient dès qu'un drapeau en décide autrement.
|
|
389
|
+
const ou = chemins
|
|
390
|
+
? `Placez vos contrats sous \`${chemins.components}/\`, vos tokens dans `
|
|
391
|
+
+ `\`${chemins.tokens}\`, puis lancez \`ucm check\`.`
|
|
392
|
+
: `Les chemins restent ceux que ce repository déclare dans son ${NOM_CONFIGURATION}. `
|
|
393
|
+
+ "Lancez `ucm check`.";
|
|
283
394
|
lignes.push(
|
|
284
395
|
ecrits.length === 0
|
|
285
396
|
? "Rien à faire : ce repository est déjà installé."
|
|
286
|
-
: `Installé avec @ucm-kit/cli ${version}.\n
|
|
287
|
-
+ "Placez vos contrats sous `components/`, vos tokens dans `tokens.json`, "
|
|
288
|
-
+ "puis lancez `ucm check`.",
|
|
397
|
+
: `Installé avec @ucm-kit/cli ${version}.\n${ou}`,
|
|
289
398
|
);
|
|
290
399
|
|
|
400
|
+
if (optionsIgnorees) {
|
|
401
|
+
lignes.push("");
|
|
402
|
+
lignes.push(
|
|
403
|
+
`· \`${NOM_CONFIGURATION}\` existait déjà : les chemins passés en option n'ont pas été `
|
|
404
|
+
+ "écrits. Ce fichier décide seul de l'endroit où les exports atterrissent ; modifiez-le "
|
|
405
|
+
+ "à la main pour en changer.",
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
291
409
|
for (const { chemin, rappel } of rappels) {
|
|
292
410
|
lignes.push("");
|
|
293
411
|
lignes.push(`· \`${chemin}\` existait déjà : ${rappel}`);
|
package/src/ucm.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { lireConfiguration } from "@ucm-kit/core/lecteurs";
|
|
|
13
13
|
import { chargerAdaptateur, NOM_ADAPTATEUR_TYPESCRIPT } from "./adaptateur.mjs";
|
|
14
14
|
import { check } from "./check.mjs";
|
|
15
15
|
import { iconesDuRepository, rendreIcones } from "./icons.mjs";
|
|
16
|
-
import { init, rendreInit } from "./init.mjs";
|
|
16
|
+
import { init, lireArgumentsInit, rendreInit } from "./init.mjs";
|
|
17
17
|
|
|
18
18
|
/** Le verdict de tests qu'un orchestrateur de stack peut transmettre au CLI. */
|
|
19
19
|
function echecsDeTestsDepuis(env) {
|
|
@@ -40,6 +40,12 @@ const AIDE = `ucm — la ligne de commande UCM
|
|
|
40
40
|
ucm icons liste les icônes que les contrats réclament
|
|
41
41
|
ucm --help affiche cette aide
|
|
42
42
|
|
|
43
|
+
ucm init [--components <dossier>] [--tokens <dossier>]
|
|
44
|
+
--components dossier sous lequel les contrats sont rangés
|
|
45
|
+
--tokens dossier qui reçoit tokens.json
|
|
46
|
+
Les deux n'agissent qu'à la première installation : ucm init n'écrase
|
|
47
|
+
jamais un ucm.config.json existant.
|
|
48
|
+
|
|
43
49
|
ucm check [--base <sha>] [--report <chemin>]
|
|
44
50
|
--base limite les états informatifs aux contrats modifiés depuis ce sha
|
|
45
51
|
--report écrit le rapport markdown à ce chemin, en plus du terminal
|
|
@@ -62,7 +68,13 @@ export function executer(arguments_, {
|
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
if (commande === "init") {
|
|
65
|
-
|
|
71
|
+
const { chemins, erreur } = lireArgumentsInit(arguments_.slice(1));
|
|
72
|
+
if (erreur) {
|
|
73
|
+
const alerter = sorties.alerter ?? console.error;
|
|
74
|
+
alerter(`${erreur}\n\nucm init [--components <dossier>] [--tokens <dossier>]`);
|
|
75
|
+
return 2;
|
|
76
|
+
}
|
|
77
|
+
ecrire(rendreInit(init(racine, { chemins })));
|
|
66
78
|
return 0;
|
|
67
79
|
}
|
|
68
80
|
|