@ucm-kit/cli 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,8 +10,8 @@ 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.15 init
14
- npx --yes @ucm-kit/cli@0.1.15 check --report ci-report.md
13
+ npx --yes @ucm-kit/cli@0.1.17 init
14
+ npx --yes @ucm-kit/cli@0.1.17 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,16 +36,32 @@ 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:
39
+ `ucm init` takes three options:
40
40
 
41
41
  | Option | Effect |
42
42
  |---|---|
43
43
  | `--components <dir>` | The folder the contracts are stored under |
44
- | `--tokens <file>` | The path of the DTCG token file |
44
+ | `--tokens <dir>` | The folder that holds `tokens.json` |
45
+ | `--implementation <pattern>` | Where a contract's implementation lives |
45
46
 
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.
47
+ The first two take a folder, because a folder is what a repository arranges.
48
+ `--tokens` appends the file name before writing it, so the `tokens` field of
49
+ `ucm.config.json` stays a file path: the readers treat it as one, and turning it
50
+ into a folder would silently point every configuration already written at
51
+ `tokens.json/tokens.json`.
52
+
53
+ `--implementation` takes a pattern, not a folder. It must contain `{id}`;
54
+ without it every contract would resolve to the same file. A repository that does
55
+ not write React states its own extension here, rather than carrying a `.tsx`
56
+ that was wrong the day it was installed:
57
+
58
+ ```sh
59
+ npx --yes @ucm-kit/cli@0.1.17 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
60
+ ```
61
+
62
+ All three act only on a first install: `ucm init` never overwrites an existing
63
+ configuration, and says so when options were passed to a repository that already
64
+ has one.
49
65
 
50
66
  `ucm check` takes two options:
51
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
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",
package/src/init.mjs CHANGED
@@ -13,20 +13,36 @@
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
15
  *
16
- * **`--components` et `--tokens` décident de l'endroit une seule fois.** Le
16
+ * **`--components`, `--tokens` et `--implementation` décident une seule fois.** Le
17
17
  * `ucm.config.json` écrit ici est la seule autorité sur l'endroit où les
18
18
  * exports atterrissent : le plugin Figma le lit, et `ucm check` le lit. Un
19
19
  * repository qui range ailleurs que sous `components/` le dit donc à
20
20
  * l'installation, au lieu de le corriger après un premier export déposé où
21
- * personne ne le cherche.
21
+ * personne ne le cherche. Un repository qui n'écrit pas de React dit de même
22
+ * comment nommer ses fichiers d'implémentation, au lieu de porter un `.tsx`
23
+ * faux dès le jour de son installation.
22
24
  */
23
25
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
24
26
  import { dirname, join } from "node:path";
25
27
 
26
- import { CONFIGURATION_PAR_DEFAUT, NOM_CONFIGURATION } from "@ucm-kit/core/format";
28
+ import {
29
+ CONFIGURATION_PAR_DEFAUT,
30
+ MOTIF_IMPLEMENTATION_PAR_DEFAUT,
31
+ NOM_CONFIGURATION,
32
+ } from "@ucm-kit/core/format";
27
33
 
28
- /** Les deux options d'`init`, et la clé de configuration que chacune décide. */
29
- const OPTIONS_DE_CHEMIN = { "--components": "components", "--tokens": "tokens" };
34
+ /** Les options qui reçoivent un dossier, et la clé que chacune décide. */
35
+ const OPTIONS_DE_DOSSIER = { "--components": "components", "--tokens": "tokens" };
36
+
37
+ /**
38
+ * Le nom du fichier de tokens, lu dans le défaut du kit plutôt que réécrit ici.
39
+ *
40
+ * Les deux options attendent un dossier, parce que c'est ce qu'un repository
41
+ * range. Le champ `tokens` de la configuration, lui, reste un chemin de
42
+ * fichier : le kit le lit ainsi, et changer sa nature ferait pointer toute
43
+ * configuration déjà écrite vers `tokens.json/tokens.json`, sans un mot.
44
+ */
45
+ const NOM_FICHIER_TOKENS = CONFIGURATION_PAR_DEFAUT.tokens.split("/").pop();
30
46
 
31
47
  /**
32
48
  * Un chemin acceptable dans la configuration : relatif, en `/`, sans segment
@@ -46,6 +62,10 @@ function cheminAcceptable(valeur) {
46
62
  /**
47
63
  * Lit les arguments d'`ucm init`.
48
64
  *
65
+ * `--components` et `--tokens` attendent un dossier ; `--tokens` y ajoute le nom
66
+ * du fichier avant de l'écrire, la configuration gardant un chemin de fichier.
67
+ * `--implementation` reçoit un motif, et non un dossier.
68
+ *
49
69
  * Même forme que `lireArguments` de `check.mjs`, y compris le refus d'une
50
70
  * valeur qui commence par `--` : sans lui, `--components --tokens x` prendrait
51
71
  * « --tokens » pour un dossier et écrirait une configuration que personne n'a
@@ -58,22 +78,39 @@ export function lireArgumentsInit(arguments_) {
58
78
 
59
79
  for (let i = 0; i < arguments_.length; i += 1) {
60
80
  const argument = arguments_[i];
61
- const cle = OPTIONS_DE_CHEMIN[argument];
62
- if (!cle) return { erreur: `Argument inconnu : ${argument}` };
81
+ const cle = OPTIONS_DE_DOSSIER[argument];
82
+ if (!cle && argument !== "--implementation") {
83
+ return { erreur: `Argument inconnu : ${argument}` };
84
+ }
63
85
 
64
86
  const valeur = arguments_[i + 1];
65
87
  if (valeur === undefined || valeur.startsWith("--")) {
66
88
  return { erreur: `${argument} attend une valeur.` };
67
89
  }
90
+ i += 1;
68
91
 
69
- const chemin = cheminAcceptable(valeur);
70
- if (!chemin) {
92
+ const resolu = cheminAcceptable(valeur);
93
+ if (!resolu) {
94
+ const attendu = cle ? "un dossier relatif" : "un motif relatif";
71
95
  return {
72
- erreur: `${argument} attend un chemin relatif au repository, sans « .. » : ${valeur} n'en est pas un.`,
96
+ erreur: `${argument} attend ${attendu} au repository, sans « .. » : ${valeur} n'en est pas un.`,
73
97
  };
74
98
  }
75
- chemins[cle] = chemin;
76
- i += 1;
99
+
100
+ if (!cle) {
101
+ // Sans `{id}`, tous les contrats désigneraient le même fichier, et le
102
+ // rapport dirait « implémentation absente » pour tous sauf un.
103
+ if (!resolu.includes("{id}")) {
104
+ return {
105
+ erreur: `--implementation attend un motif contenant {id}, par exemple `
106
+ + `"${MOTIF_IMPLEMENTATION_PAR_DEFAUT}" : ${valeur} n'en est pas un.`,
107
+ };
108
+ }
109
+ chemins.implementation = resolu;
110
+ continue;
111
+ }
112
+
113
+ chemins[cle] = cle === "tokens" ? `${resolu}/${NOM_FICHIER_TOKENS}` : resolu;
77
114
  }
78
115
 
79
116
  return { chemins };
package/src/ucm.mjs CHANGED
@@ -40,10 +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
43
+ ucm init [--components <dossier>] [--tokens <dossier>] [--implementation <motif>]
44
+ --components dossier sous lequel les contrats sont rangés
45
+ --tokens dossier qui reçoit tokens.json
46
+ --implementation où vit l'implémentation d'un contrat, {dir} et {id}
47
+ pour son dossier et son identifiant
48
+ Les trois n'agissent qu'à la première installation : ucm init n'écrase
47
49
  jamais un ucm.config.json existant.
48
50
 
49
51
  ucm check [--base <sha>] [--report <chemin>]
@@ -71,7 +73,7 @@ export function executer(arguments_, {
71
73
  const { chemins, erreur } = lireArgumentsInit(arguments_.slice(1));
72
74
  if (erreur) {
73
75
  const alerter = sorties.alerter ?? console.error;
74
- alerter(`${erreur}\n\nucm init [--components <dossier>] [--tokens <fichier>]`);
76
+ alerter(`${erreur}\n\nucm init [--components <dossier>] [--tokens <dossier>]`);
75
77
  return 2;
76
78
  }
77
79
  ecrire(rendreInit(init(racine, { chemins })));