@ucm-kit/cli 0.1.16 → 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 +16 -6
- package/package.json +1 -1
- package/src/init.mjs +38 -14
- package/src/ucm.mjs +6 -4
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.
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
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,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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
53
63
|
configuration, and says so when options were passed to a repository that already
|
|
54
64
|
has one.
|
|
55
65
|
|
package/package.json
CHANGED
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 `--
|
|
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 {
|
|
28
|
+
import {
|
|
29
|
+
CONFIGURATION_PAR_DEFAUT,
|
|
30
|
+
MOTIF_IMPLEMENTATION_PAR_DEFAUT,
|
|
31
|
+
NOM_CONFIGURATION,
|
|
32
|
+
} from "@ucm-kit/core/format";
|
|
27
33
|
|
|
28
|
-
/** Les
|
|
29
|
-
const
|
|
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
|
-
*
|
|
60
|
-
* avant de l'écrire
|
|
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 =
|
|
75
|
-
if (!cle
|
|
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
|
|
83
|
-
if (!
|
|
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
|
|
96
|
+
erreur: `${argument} attend ${attendu} au repository, sans « .. » : ${valeur} n'en est pas un.`,
|
|
86
97
|
};
|
|
87
98
|
}
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
45
|
-
--tokens
|
|
46
|
-
|
|
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>]
|