@ucm-kit/cli 0.1.13 → 0.1.15
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 +22 -5
- package/package.json +2 -2
- package/src/init.mjs +117 -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.15 init
|
|
14
|
+
npx --yes @ucm-kit/cli@0.1.15 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,17 @@ 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 <file>` | The path of the DTCG token file |
|
|
45
|
+
|
|
46
|
+
Both write into `ucm.config.json`, and both act only on a first install: `ucm
|
|
47
|
+
init` never overwrites an existing configuration, and says so when options were
|
|
48
|
+
passed to a repository that already has one.
|
|
49
|
+
|
|
39
50
|
`ucm check` takes two options:
|
|
40
51
|
|
|
41
52
|
| Option | Effect |
|
|
@@ -70,8 +81,14 @@ The workflow is yours once written. It will never be overwritten.
|
|
|
70
81
|
|
|
71
82
|
### `ucm.config.json`
|
|
72
83
|
|
|
73
|
-
Three paths, and nothing else.
|
|
74
|
-
|
|
84
|
+
Three paths, and nothing else. **This file is the only authority on where an
|
|
85
|
+
export lands.** The Figma plugin reads it before publishing, and `ucm check`
|
|
86
|
+
reads it before looking for contracts. A repository that arranges things
|
|
87
|
+
differently says so here, once, and both sides follow.
|
|
88
|
+
|
|
89
|
+
Its absence is the nominal case, not an error: the defaults below apply, and a
|
|
90
|
+
repository with a single `components/` folder works without writing a line. A
|
|
91
|
+
file that exists but is malformed is refused on both sides.
|
|
75
92
|
|
|
76
93
|
```json
|
|
77
94
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
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,73 @@
|
|
|
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
|
+
* Un chemin acceptable dans la configuration : relatif, en `/`, sans segment
|
|
33
|
+
* qui remonte. La garde est ici et pas dans la grammaire du kit : celle-ci
|
|
34
|
+
* décrit ce qu'un `ucm.config.json` déjà écrit a le droit de contenir, et la
|
|
35
|
+
* durcir changerait le format. Ce qu'une commande accepte de taper au clavier
|
|
36
|
+
* est une autre question, et c'est celle-là qui se pose ici.
|
|
37
|
+
*/
|
|
38
|
+
function cheminAcceptable(valeur) {
|
|
39
|
+
const normalise = valeur.trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
40
|
+
if (!normalise) return null;
|
|
41
|
+
const segments = normalise.split("/");
|
|
42
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) return null;
|
|
43
|
+
return segments.join("/");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Lit les arguments d'`ucm init`.
|
|
48
|
+
*
|
|
49
|
+
* Même forme que `lireArguments` de `check.mjs`, y compris le refus d'une
|
|
50
|
+
* valeur qui commence par `--` : sans lui, `--components --tokens x` prendrait
|
|
51
|
+
* « --tokens » pour un dossier et écrirait une configuration que personne n'a
|
|
52
|
+
* demandée. Un argument inconnu est refusé au lieu d'être ignoré, faute de quoi
|
|
53
|
+
* `ucm init --composants src` sortirait en 0 sans avoir rien fait de ce qui
|
|
54
|
+
* était demandé.
|
|
55
|
+
*/
|
|
56
|
+
export function lireArgumentsInit(arguments_) {
|
|
57
|
+
const chemins = {};
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < arguments_.length; i += 1) {
|
|
60
|
+
const argument = arguments_[i];
|
|
61
|
+
const cle = OPTIONS_DE_CHEMIN[argument];
|
|
62
|
+
if (!cle) return { erreur: `Argument inconnu : ${argument}` };
|
|
63
|
+
|
|
64
|
+
const valeur = arguments_[i + 1];
|
|
65
|
+
if (valeur === undefined || valeur.startsWith("--")) {
|
|
66
|
+
return { erreur: `${argument} attend une valeur.` };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const chemin = cheminAcceptable(valeur);
|
|
70
|
+
if (!chemin) {
|
|
71
|
+
return {
|
|
72
|
+
erreur: `${argument} attend un chemin relatif au repository, sans « .. » : ${valeur} n'en est pas un.`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
chemins[cle] = chemin;
|
|
76
|
+
i += 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { chemins };
|
|
80
|
+
}
|
|
81
|
+
|
|
21
82
|
/** La version de `@ucm-kit/cli`, lue dans son propre `package.json`. */
|
|
22
83
|
function versionDuPaquet() {
|
|
23
84
|
const chemin = new URL("../package.json", import.meta.url);
|
|
@@ -41,7 +102,7 @@ function versionDuPaquet() {
|
|
|
41
102
|
* présents, le rappel se tait : trois lignes réclamées pour rien sont trois
|
|
42
103
|
* lignes qu'on apprend à sauter.
|
|
43
104
|
*/
|
|
44
|
-
function fichiers(version) {
|
|
105
|
+
function fichiers(version, chemins) {
|
|
45
106
|
return [
|
|
46
107
|
{
|
|
47
108
|
chemin: NOM_CONFIGURATION,
|
|
@@ -49,7 +110,7 @@ function fichiers(version) {
|
|
|
49
110
|
// Pas de `$schema` : aucun schéma de configuration n'est publié
|
|
50
111
|
// aujourd'hui, et pointer vers une URL qui rend 404 apprendrait à
|
|
51
112
|
// l'éditeur — et à qui lit le fichier — à ignorer cette ligne.
|
|
52
|
-
{ ...CONFIGURATION_PAR_DEFAUT },
|
|
113
|
+
{ ...CONFIGURATION_PAR_DEFAUT, ...chemins },
|
|
53
114
|
null,
|
|
54
115
|
2,
|
|
55
116
|
)}\n`,
|
|
@@ -92,14 +153,14 @@ function fichiers(version) {
|
|
|
92
153
|
{
|
|
93
154
|
chemin: ".gitignore",
|
|
94
155
|
contenu: [
|
|
95
|
-
"# Le rapport
|
|
96
|
-
"#
|
|
97
|
-
"#
|
|
156
|
+
"# Le rapport de `ucm check --report`, réécrit à chaque exécution.",
|
|
157
|
+
"# Commité, il montrerait le verdict d'un contrôle passé, pas celui du",
|
|
158
|
+
"# code en cours.",
|
|
98
159
|
"ci-report.md",
|
|
99
160
|
"",
|
|
100
161
|
].join("\n"),
|
|
101
162
|
marqueurs: ["ci-report.md"],
|
|
102
|
-
rappel: "ajoutez-y `ci-report.md
|
|
163
|
+
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
164
|
},
|
|
104
165
|
{
|
|
105
166
|
chemin: ".github/workflows/ucm.yml",
|
|
@@ -226,12 +287,12 @@ function workflow(version) {
|
|
|
226
287
|
* mi-chemin laisserait un repo à moitié installé, état que rien ne sait
|
|
227
288
|
* diagnostiquer ensuite.
|
|
228
289
|
*/
|
|
229
|
-
export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
290
|
+
export function init(racine, { ecrire = writeFileSync, chemins = {} } = {}) {
|
|
230
291
|
const version = versionDuPaquet();
|
|
231
292
|
const aEcrire = [];
|
|
232
293
|
const deja = [];
|
|
233
294
|
|
|
234
|
-
for (const fichier of fichiers(version)) {
|
|
295
|
+
for (const fichier of fichiers(version, chemins)) {
|
|
235
296
|
const cible = join(racine, fichier.chemin);
|
|
236
297
|
if (existsSync(cible)) deja.push({ ...fichier, cible });
|
|
237
298
|
else aEcrire.push({ ...fichier, cible });
|
|
@@ -242,6 +303,7 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
242
303
|
ecrire(fichier.cible, fichier.contenu, "utf8");
|
|
243
304
|
}
|
|
244
305
|
|
|
306
|
+
const optionsDemandees = Object.keys(chemins).length > 0;
|
|
245
307
|
return {
|
|
246
308
|
ecrits: aEcrire.map((f) => f.chemin),
|
|
247
309
|
conserves: deja.map((f) => f.chemin),
|
|
@@ -249,6 +311,24 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
249
311
|
chemin: f.chemin,
|
|
250
312
|
rappel: f.rappel,
|
|
251
313
|
})),
|
|
314
|
+
/*
|
|
315
|
+
* Des chemins demandés à une commande qui n'écrase rien, sur un repository
|
|
316
|
+
* qui a déjà sa configuration. Le silence se lirait comme « c'est fait »,
|
|
317
|
+
* et le premier export irait ailleurs que là où on croit l'avoir envoyé.
|
|
318
|
+
* Ce n'est pas un `rappel` : les trois rappels nomment une ligne à ajouter
|
|
319
|
+
* à un fichier partagé, et les mélanger ferait de la liste entière quelque
|
|
320
|
+
* chose qu'on apprend à sauter.
|
|
321
|
+
*/
|
|
322
|
+
optionsIgnorees: optionsDemandees && deja.some((f) => f.chemin === NOM_CONFIGURATION),
|
|
323
|
+
/*
|
|
324
|
+
* Les chemins écrits, et `null` quand la configuration a été conservée :
|
|
325
|
+
* ce sont alors ceux du fichier déjà là, qu'`init` n'a pas lu. Les
|
|
326
|
+
* afficher quand même reviendrait à annoncer un endroit sur la foi d'un
|
|
327
|
+
* défaut, devant un fichier qui dit peut-être autre chose.
|
|
328
|
+
*/
|
|
329
|
+
chemins: aEcrire.some((f) => f.chemin === NOM_CONFIGURATION)
|
|
330
|
+
? { ...CONFIGURATION_PAR_DEFAUT, ...chemins }
|
|
331
|
+
: null,
|
|
252
332
|
version,
|
|
253
333
|
};
|
|
254
334
|
}
|
|
@@ -260,6 +340,10 @@ export function init(racine, { ecrire = writeFileSync } = {}) {
|
|
|
260
340
|
* silence sur la seule chose que cette commande ne sait pas installer.
|
|
261
341
|
*/
|
|
262
342
|
function porteLaRegle(fichier) {
|
|
343
|
+
// Un fichier sans marqueur n'a rien à reconnaître. Sans cette ligne, la
|
|
344
|
+
// réponse serait juste par accident : `undefined.every` lève, et c'est le
|
|
345
|
+
// `catch` écrit pour un fichier illisible qui rendrait `false`.
|
|
346
|
+
if (!fichier.marqueurs) return false;
|
|
263
347
|
try {
|
|
264
348
|
const contenu = readFileSync(fichier.cible, "utf8");
|
|
265
349
|
return fichier.marqueurs.every((marqueur) => contenu.includes(marqueur));
|
|
@@ -275,19 +359,40 @@ function porteLaRegle(fichier) {
|
|
|
275
359
|
* quel » ne suffit pas à la remplacer : cette mention se lit comme « rien à
|
|
276
360
|
* faire », alors que la moitié de l'installation manque précisément là.
|
|
277
361
|
*/
|
|
278
|
-
export function rendreInit({
|
|
362
|
+
export function rendreInit({
|
|
363
|
+
ecrits,
|
|
364
|
+
conserves,
|
|
365
|
+
rappels = [],
|
|
366
|
+
optionsIgnorees = false,
|
|
367
|
+
chemins = null,
|
|
368
|
+
version,
|
|
369
|
+
}) {
|
|
279
370
|
const lignes = [];
|
|
280
371
|
for (const chemin of ecrits) lignes.push(`✓ ${chemin}`);
|
|
281
372
|
for (const chemin of conserves) lignes.push(`· ${chemin} existait déjà, laissé tel quel`);
|
|
282
373
|
lignes.push("");
|
|
374
|
+
// L'endroit vient de la configuration écrite, jamais d'une convention
|
|
375
|
+
// recopiée ici : les deux dériveraient dès qu'un drapeau en décide autrement.
|
|
376
|
+
const ou = chemins
|
|
377
|
+
? `Placez vos contrats sous \`${chemins.components}/\`, vos tokens dans `
|
|
378
|
+
+ `\`${chemins.tokens}\`, puis lancez \`ucm check\`.`
|
|
379
|
+
: `Les chemins restent ceux que ce repository déclare dans son ${NOM_CONFIGURATION}. `
|
|
380
|
+
+ "Lancez `ucm check`.";
|
|
283
381
|
lignes.push(
|
|
284
382
|
ecrits.length === 0
|
|
285
383
|
? "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`.",
|
|
384
|
+
: `Installé avec @ucm-kit/cli ${version}.\n${ou}`,
|
|
289
385
|
);
|
|
290
386
|
|
|
387
|
+
if (optionsIgnorees) {
|
|
388
|
+
lignes.push("");
|
|
389
|
+
lignes.push(
|
|
390
|
+
`· \`${NOM_CONFIGURATION}\` existait déjà : les chemins passés en option n'ont pas été `
|
|
391
|
+
+ "écrits. Ce fichier décide seul de l'endroit où les exports atterrissent ; modifiez-le "
|
|
392
|
+
+ "à la main pour en changer.",
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
291
396
|
for (const { chemin, rappel } of rappels) {
|
|
292
397
|
lignes.push("");
|
|
293
398
|
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 <fichier>]
|
|
44
|
+
--components dossier sous lequel les contrats sont rangés
|
|
45
|
+
--tokens chemin du fichier de tokens DTCG
|
|
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 <fichier>]`);
|
|
75
|
+
return 2;
|
|
76
|
+
}
|
|
77
|
+
ecrire(rendreInit(init(racine, { chemins })));
|
|
66
78
|
return 0;
|
|
67
79
|
}
|
|
68
80
|
|