@ucm-kit/cli 0.4.0 → 0.4.1

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
@@ -16,7 +16,7 @@ matches them.
16
16
  Requires Node 22 or later. At the root of the repository:
17
17
 
18
18
  ```sh
19
- npx --yes @ucm-kit/cli@0.4.0 init
19
+ npx --yes @ucm-kit/cli@0.4.1 init
20
20
  ```
21
21
 
22
22
  1. Commit and push the files `init` wrote.
@@ -27,7 +27,7 @@ npx --yes @ucm-kit/cli@0.4.0 init
27
27
  To run the check locally:
28
28
 
29
29
  ```sh
30
- npx --yes @ucm-kit/cli@0.4.0 check --report ci-report.md
30
+ npx --yes @ucm-kit/cli@0.4.1 check --report ci-report.md
31
31
  ```
32
32
 
33
33
  `--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
@@ -87,7 +87,7 @@ contract would resolve to the same file. A repository that does not write React
87
87
  states its own extension:
88
88
 
89
89
  ```sh
90
- npx --yes @ucm-kit/cli@0.4.0 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
90
+ npx --yes @ucm-kit/cli@0.4.1 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
91
91
  ```
92
92
 
93
93
  The three path options act only on a first install. `ucm init` never overwrites
@@ -159,7 +159,7 @@ job runs no code from the repository: it receives the report as an artifact
159
159
  and posts it with `ucm rapport-github`, replacing its previous comment:
160
160
 
161
161
  ```sh
162
- npx --yes @ucm-kit/cli@0.4.0 rapport-github --depot "$GITHUB_REPOSITORY" --demande "$NUMERO" --fichier ci-report.md
162
+ npx --yes @ucm-kit/cli@0.4.1 rapport-github --depot "$GITHUB_REPOSITORY" --demande "$NUMERO" --fichier ci-report.md
163
163
  ```
164
164
 
165
165
  | Option | Effect |
@@ -222,7 +222,7 @@ directory. It writes a minimal report when the check stopped before writing
222
222
  one, then posts the report:
223
223
 
224
224
  ```sh
225
- npx --yes @ucm-kit/cli@0.4.0 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
225
+ npx --yes @ucm-kit/cli@0.4.1 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
226
226
  ```
227
227
 
228
228
  | Option | Effect |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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",
@@ -29,7 +29,7 @@
29
29
  "test": "node scripts/run-tests.cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@ucm-kit/core": "0.18.0"
32
+ "@ucm-kit/core": "0.18.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "yaml": "^2.9.1"
package/src/init.mjs CHANGED
@@ -217,9 +217,24 @@ function versionDuPaquet() {
217
217
  * présents, le rappel se tait : trois lignes réclamées pour rien sont trois
218
218
  * lignes qu'on apprend à sauter.
219
219
  */
220
+ /**
221
+ * Le motif de `.gitattributes` qui désigne ce seul chemin.
222
+ *
223
+ * Git coupe une ligne aux espaces et lit `*`, `?`, `[` comme un glob : écrit
224
+ * tel quel, `design system/tokens.json` donnerait un attribut invalide, et le
225
+ * fichier resterait sans `eol=lf`. Une espace devient `[[:space:]]`, un signe
226
+ * de glob et un `#` ou `!` de tête sont échappés.
227
+ */
228
+ function motifDeGitattributes(chemin) {
229
+ return chemin
230
+ .replace(/[*?[\]\\]/g, "\\$&")
231
+ .replace(/^[#!"]/, "\\$&")
232
+ .replace(/\s/g, "[[:space:]]");
233
+ }
234
+
220
235
  function fichiers(version, chemins, { agents = true, gabarits = [], forge = "github" } = {}) {
221
236
  // Le fichier de tokens que la configuration écrite désigne, pas un nom recopié.
222
- const cheminDesTokens = { ...CONFIGURATION_PAR_DEFAUT, ...chemins }.tokens;
237
+ const cheminDesTokens = motifDeGitattributes({ ...CONFIGURATION_PAR_DEFAUT, ...chemins }.tokens);
223
238
  return [
224
239
  {
225
240
  chemin: NOM_CONFIGURATION,
@@ -379,13 +394,14 @@ function lignesRestantes(racine, version, configuration) {
379
394
  }
380
395
 
381
396
  /**
382
- * Un repository Node utilise sa CLI installée ; un dossier sans stack Node garde le contrôle portable par npm,
383
- * sur la version que `init` a écrite : un `npx` sans numéro prendrait la dernière publiée, que personne n'a essayée.
397
+ * Le repository qui a installé la CLI (`npm ci` sur un `package-lock.json`) l'exécute ; sans elle, même avec un
398
+ * `package.json` (yarn, pnpm), le contrôle reste portable par npm, sur la version que `init` a écrite :
399
+ * un `npx` sans numéro prendrait la dernière publiée, que personne n'a essayée.
384
400
  */
385
401
  function lancementUcm(marge, version) {
386
402
  return [
387
403
  'ucm() {',
388
- ' if [ -f package.json ]; then',
404
+ ' if [ -f node_modules/@ucm-kit/cli/src/ucm.mjs ]; then',
389
405
  ' node node_modules/@ucm-kit/cli/src/ucm.mjs "$@"',
390
406
  ' else',
391
407
  ` npx --yes @ucm-kit/cli@${version} "$@"`,
@@ -22,6 +22,7 @@ import { readFileSync } from "node:fs";
22
22
  import { resolve } from "node:path";
23
23
 
24
24
  import { MARQUEUR_RAPPORT, rapportPrecedent, rapportSansObjet } from "@ucm-kit/core/lecteurs";
25
+ import { sansBom } from "@ucm-kit/core/format";
25
26
  import { API_GITHUB } from "@ucm-kit/core/protocoles";
26
27
 
27
28
  import { VARIABLE_DU_JETON_GITHUB } from "./fichiers-du-consommateur.mjs";
@@ -114,7 +115,9 @@ export async function rapportGithub(arguments_, {
114
115
 
115
116
  let rapport;
116
117
  try {
117
- rapport = readFileSync(resolve(racine, valeurs.fichier), "utf8");
118
+ // Un BOM repousserait le marqueur sans objet en troisième ligne, et la
119
+ // demande étrangère à UCM recevrait un commentaire.
120
+ rapport = sansBom(readFileSync(resolve(racine, valeurs.fichier), "utf8"));
118
121
  } catch (erreurLecture) {
119
122
  alerter(`Le rapport ${valeurs.fichier} ne se lit pas (${erreurLecture?.code ?? erreurLecture?.message}) : aucun commentaire n'est publié.`);
120
123
  return 1;
@@ -19,6 +19,7 @@ import { readFileSync } from "node:fs";
19
19
  import { resolve } from "node:path";
20
20
 
21
21
  import { MARQUEUR_RAPPORT, MARQUEUR_SANS_OBJET, rapportPrecedent, rapportSansObjet } from "@ucm-kit/core/lecteurs";
22
+ import { sansBom } from "@ucm-kit/core/format";
22
23
  import { API_GITLAB } from "@ucm-kit/core/protocoles";
23
24
 
24
25
  import { VARIABLE_DU_JETON_GITLAB } from "./fichiers-du-consommateur.mjs";
@@ -111,7 +112,9 @@ export async function rapportGitlab(arguments_, {
111
112
 
112
113
  let rapport;
113
114
  try {
114
- rapport = readFileSync(resolve(racine, valeurs.fichier), "utf8");
115
+ // Un BOM repousserait le marqueur sans objet en troisième ligne, et la
116
+ // demande étrangère à UCM recevrait un commentaire.
117
+ rapport = sansBom(readFileSync(resolve(racine, valeurs.fichier), "utf8"));
115
118
  } catch (erreurLecture) {
116
119
  alerter(`Le rapport ${valeurs.fichier} ne se lit pas (${erreurLecture?.code ?? erreurLecture?.message}) : aucune note n'est publiée.`);
117
120
  return 1;
@@ -138,7 +141,7 @@ export async function rapportGitlab(arguments_, {
138
141
  throw new RefusGitlab(null, `La requête vers GitLab n'a pas abouti en voulant ${action}. Relancez le job.`);
139
142
  }
140
143
  if (reponse.status >= 300 && reponse.status < 400) {
141
- throw new RefusGitlab(reponse.status, `GitLab a redirige la requete en voulant ${action}.`);
144
+ throw new RefusGitlab(reponse.status, `GitLab a redirigé la requête en voulant ${action}.`);
142
145
  }
143
146
  if (!reponse.ok) throw new RefusGitlab(reponse.status, gesteDuStatut(reponse.status, action));
144
147
  return reponse;
@@ -34,6 +34,7 @@ import {
34
34
  cyclesActifs,
35
35
  indexerTokensDtcg,
36
36
  lireConfiguration,
37
+ libelleNombre,
37
38
  lireJsonDuDepot,
38
39
  refusDesNomsCss,
39
40
  sansEchantillon,
@@ -688,7 +689,7 @@ export function tokensCss(arguments_, {
688
689
  const echec = remplacer(cible, contenu, ecrireFichier);
689
690
  if (echec) return echecDEcriture(echec);
690
691
  const { regles, declarations, octets } = statistiquesDeFeuille(contenu);
691
- ecrire(`${options.out} : ${regles} règles, ${declarations} déclarations, ${octets} octets.`);
692
+ ecrire(`${options.out} : ${libelleNombre(regles, "règle")}, ${libelleNombre(declarations, "déclaration")}, ${libelleNombre(octets, "octet")}.`);
692
693
  for (const note of notesDAttributs) ecrire(note);
693
694
  if (genereModes) {
694
695
  for (const axe of contextesDesAxes(document, axes)) {
@@ -13,7 +13,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
13
13
  import { relative, resolve } from "node:path";
14
14
 
15
15
  import { isTokenReference, referencesDansUnTexte } from "@ucm-kit/core/format";
16
- import { cheminDeReference, indexerTokensDtcg, lireConfiguration, lireJsonDuDepot, nomsCssDesTokens } from "@ucm-kit/core/lecteurs";
16
+ import { cheminDeReference, indexerTokensDtcg, libelleNombre, lireConfiguration, lireJsonDuDepot, nomsCssDesTokens } from "@ucm-kit/core/lecteurs";
17
17
 
18
18
  import { catalogueDesAides } from "./aides.mjs";
19
19
  import { conventionsLesPlusProches, lireConventions } from "./conventions.mjs";
@@ -22,6 +22,8 @@ export const USAGE_REFERENCES = "ucm tokens references [--verifier] <fichiers…
22
22
 
23
23
  const SECTION_DU_REPOSITORY = "resolution-token";
24
24
 
25
+ const remplacees = (nombre) => `${libelleNombre(nombre, "référence")} ${nombre === 1 ? "remplacée" : "remplacées"}`;
26
+
25
27
  /** Lit les arguments de la commande, sans lever. */
26
28
  export function lireArgumentsReferences(arguments_) {
27
29
  const options = { verifier: false, fichiers: [] };
@@ -205,11 +207,11 @@ export function tokensReferences(arguments_, {
205
207
  } else if (resultat.texte !== original) {
206
208
  ecrireFichier(fichier, resultat.texte, "utf8");
207
209
  remplaceesAuTotal += resultat.remplacees.length;
208
- ecrire(`${nom} : ${resultat.remplacees.length} référence(s) remplacée(s).`);
210
+ ecrire(`${nom} : ${remplacees(resultat.remplacees.length)}.`);
209
211
  }
210
212
  }
211
213
 
212
214
  if (aSignaler > 0) return 1;
213
- ecrire(remplaceesAuTotal === 0 ? "Aucune référence à remplacer." : `${remplaceesAuTotal} référence(s) remplacée(s).`);
215
+ ecrire(remplaceesAuTotal === 0 ? "Aucune référence à remplacer." : `${remplacees(remplaceesAuTotal)}.`);
214
216
  return 0;
215
217
  }