@ucm-kit/cli 0.1.16 → 0.1.18

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.16 init
14
- npx --yes @ucm-kit/cli@0.1.16 check --report ci-report.md
13
+ npx --yes @ucm-kit/cli@0.1.18 init
14
+ npx --yes @ucm-kit/cli@0.1.18 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,20 +36,30 @@ 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
44
  | `--tokens <dir>` | The folder that holds `tokens.json` |
45
+ | `--implementation <pattern>` | Where a contract's implementation lives |
45
46
 
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
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
48
49
  `ucm.config.json` stays a file path: the readers treat it as one, and turning it
49
50
  into a folder would silently point every configuration already written at
50
51
  `tokens.json/tokens.json`.
51
52
 
52
- Both act only on a first install: `ucm init` never overwrites an existing
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.18 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
53
63
  configuration, and says so when options were passed to a repository that already
54
64
  has one.
55
65
 
@@ -105,8 +115,8 @@ file that exists but is malformed is refused on both sides.
105
115
  ```
106
116
 
107
117
  `implementation` is a pattern with two tokens, `{dir}` for the contract's folder
108
- and `{id}` for its identifier. The default shown here is a default, not an
109
- assumption: replace it with your own.
118
+ and `{id}` for its identifier. Replace it with the pattern your repository
119
+ uses.
110
120
 
111
121
  No version number goes in this file. Which contract versions can be read belongs
112
122
  to the installed package, and repeating it here would create a second authority
@@ -129,7 +139,7 @@ fix it.**
129
139
  | Composition: every nested component has its own contract, the lists agree, no cycles | Blocks |
130
140
  | Typography tokens have the expected type | Blocks |
131
141
  | Every `{token.path}` cited exists in the token file | Warns |
132
- | The code exposes the props the contract declares | Warns |
142
+ | The code exposes the props the contract declares, with a stack adapter installed | Warns |
133
143
 
134
144
  A gap with the code needs a developer, so it warns and lets the merge through. A
135
145
  token removed from the design system does too: tokens are the source of truth,
@@ -140,7 +150,7 @@ is an allowed state, not an error.
140
150
 
141
151
  **So is a repository with no contract at all.** Right after `ucm init` nothing
142
152
  has been exported: there is no token file, and usually no contract folder. From
143
- `0.1.9` on, `ucm check` returns 0 there and reports what to do next. The number
153
+ `0.1.10` on, `ucm check` returns 0 there and reports what to do next. The number
144
154
  of contracts decides: with one or more, a missing token file blocks the merge
145
155
  again, because those contracts cite tokens nobody can resolve.
146
156
 
@@ -150,8 +160,8 @@ when an orchestrator passes it in through `UCM_ECHECS_DE_TESTS`.
150
160
 
151
161
  ## Optional stack adapters
152
162
 
153
- The six checks above read contracts and tokens only, so they work whatever the
154
- repository is written in. Comparing a contract to real code needs to read that
163
+ The first five checks above read contracts and tokens only, so they work
164
+ whatever the repository is written in. Comparing a contract to real code needs to read that
155
165
  code, which is a stack adapter's job.
156
166
 
157
167
  `ucm check` discovers an adapter installed **by the repository**, resolving from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
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.18"
30
+ "@ucm-kit/core": "0.1.19"
31
31
  }
32
32
  }
package/src/init.mjs CHANGED
@@ -13,20 +13,26 @@
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" };
30
36
 
31
37
  /**
32
38
  * Le nom du fichier de tokens, lu dans le défaut du kit plutôt que réécrit ici.
@@ -56,8 +62,9 @@ function cheminAcceptable(valeur) {
56
62
  /**
57
63
  * Lit les arguments d'`ucm init`.
58
64
  *
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.
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.
61
68
  *
62
69
  * Même forme que `lireArguments` de `check.mjs`, y compris le refus d'une
63
70
  * valeur qui commence par `--` : sans lui, `--components --tokens x` prendrait
@@ -71,22 +78,39 @@ export function lireArgumentsInit(arguments_) {
71
78
 
72
79
  for (let i = 0; i < arguments_.length; i += 1) {
73
80
  const argument = arguments_[i];
74
- const cle = OPTIONS_DE_CHEMIN[argument];
75
- 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
+ }
76
85
 
77
86
  const valeur = arguments_[i + 1];
78
87
  if (valeur === undefined || valeur.startsWith("--")) {
79
88
  return { erreur: `${argument} attend une valeur.` };
80
89
  }
90
+ i += 1;
81
91
 
82
- const dossier = cheminAcceptable(valeur);
83
- if (!dossier) {
92
+ const resolu = cheminAcceptable(valeur);
93
+ if (!resolu) {
94
+ const attendu = cle ? "un dossier relatif" : "un motif relatif";
84
95
  return {
85
- erreur: `${argument} attend un dossier relatif au repository, sans « .. » : ${valeur} n'en est pas un.`,
96
+ erreur: `${argument} attend ${attendu} au repository, sans « .. » : ${valeur} n'en est pas un.`,
86
97
  };
87
98
  }
88
- chemins[cle] = cle === "tokens" ? `${dossier}/${NOM_FICHIER_TOKENS}` : dossier;
89
- 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;
90
114
  }
91
115
 
92
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 <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
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>]