@ucm-kit/cli 0.1.32 → 0.1.33
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 +3 -3
- package/package.json +2 -2
- package/src/tokens-css.mjs +49 -12
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ next to the component's code. This command reads those files and says whether
|
|
|
11
11
|
they still hold together.
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
15
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
14
|
+
npx --yes @ucm-kit/cli@0.1.33 init
|
|
15
|
+
npx --yes @ucm-kit/cli@0.1.33 check --report ci-report.md
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Pin an exact version, without `^`. A range would let npx install a build this
|
|
@@ -60,7 +60,7 @@ not write React states its own extension here, rather than carrying a `.tsx`
|
|
|
60
60
|
that was wrong the day it was installed:
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
63
|
+
npx --yes @ucm-kit/cli@0.1.33 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
All three act only on a first install: `ucm init` never overwrites an existing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
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,6 +29,6 @@
|
|
|
29
29
|
"test": "node scripts/run-tests.cjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ucm-kit/core": "0.1.
|
|
32
|
+
"@ucm-kit/core": "0.1.32"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/tokens-css.mjs
CHANGED
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
* Codes : 0 feuille écrite, 1 fichier de tokens refusé, 2 invocation ou
|
|
12
12
|
* configuration fautive. Un refus laisse la feuille précédente en place.
|
|
13
13
|
*/
|
|
14
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
15
15
|
import { dirname, join, relative, resolve } from "node:path";
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
18
|
NOM_CONFIGURATION,
|
|
19
|
+
PREFIXE_DES_INTERMEDIAIRES,
|
|
19
20
|
attributDeMode,
|
|
21
|
+
axeDesExtensions,
|
|
20
22
|
etatDuFormatDeTokens,
|
|
21
23
|
tokenCssVariable,
|
|
22
24
|
} from "@ucm-kit/core/format";
|
|
23
25
|
import {
|
|
24
|
-
axeDesExtensions,
|
|
25
26
|
axesDeTokens,
|
|
26
27
|
cheminDeReference,
|
|
27
28
|
collecterReferences,
|
|
@@ -233,8 +234,8 @@ export function feuilleDesTokens(document, { axes = [], attributs = new Map(), r
|
|
|
233
234
|
const parNom = new Map();
|
|
234
235
|
for (const chemin of index.keys()) {
|
|
235
236
|
const nom = tokenCssVariable(chemin);
|
|
236
|
-
if (nom.startsWith(
|
|
237
|
-
refus.push(`La feuille « ${chemin} » donne la propriété « ${nom} », dont le préfixe
|
|
237
|
+
if (nom.startsWith(PREFIXE_DES_INTERMEDIAIRES)) {
|
|
238
|
+
refus.push(`La feuille « ${chemin} » donne la propriété « ${nom} », dont le préfixe ${PREFIXE_DES_INTERMEDIAIRES} est réservé aux collections étendues.`);
|
|
238
239
|
}
|
|
239
240
|
if (parNom.has(nom)) {
|
|
240
241
|
refus.push(`Les feuilles « ${parNom.get(nom)} » et « ${chemin} » donnent la même propriété CSS « ${nom} ».`);
|
|
@@ -292,7 +293,7 @@ export function feuilleDesTokens(document, { axes = [], attributs = new Map(), r
|
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
const suffixe = nom.slice(2);
|
|
295
|
-
const intermediaire = (extension) =>
|
|
296
|
+
const intermediaire = (extension) => `${PREFIXE_DES_INTERMEDIAIRES}${tokenCssVariable(extension).slice(2)}--${suffixe}`;
|
|
296
297
|
const plusProche = (extension) => {
|
|
297
298
|
for (let courante = extension; courante !== undefined && courante !== "base"; courante = axe.extensions[courante]?.parent) {
|
|
298
299
|
if (possede(surcharges, courante)) return courante;
|
|
@@ -453,12 +454,37 @@ function contratsQuiCitentDesTokens(racine, dossierComponents) {
|
|
|
453
454
|
return cites;
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Vrai quand deux chemins désignent le même fichier existant. La comparaison
|
|
459
|
+
* porte sur l'identité du fichier : sous Windows et macOS, `TOKENS.JSON` et
|
|
460
|
+
* `tokens.json` sont deux chaînes pour un seul fichier.
|
|
461
|
+
*/
|
|
462
|
+
function memeFichier(chemin, autre) {
|
|
463
|
+
if (chemin === autre) return true;
|
|
464
|
+
try {
|
|
465
|
+
const premier = statSync(chemin, { bigint: true });
|
|
466
|
+
const second = statSync(autre, { bigint: true });
|
|
467
|
+
return premier.ino === second.ino && premier.dev === second.dev;
|
|
468
|
+
} catch {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Écrit un fichier terminé à sa place, par remplacement : une écriture interrompue ne laisse pas de demi-feuille.
|
|
475
|
+
* Rend l'erreur du système quand l'écriture échoue, le fichier provisoire retiré.
|
|
476
|
+
*/
|
|
457
477
|
function remplacer(cible, contenu, ecrireFichier) {
|
|
458
|
-
mkdirSync(dirname(cible), { recursive: true });
|
|
459
478
|
const provisoire = `${cible}.${process.pid}.tmp`;
|
|
460
|
-
|
|
461
|
-
|
|
479
|
+
try {
|
|
480
|
+
mkdirSync(dirname(cible), { recursive: true });
|
|
481
|
+
ecrireFichier(provisoire, contenu, "utf8");
|
|
482
|
+
renameSync(provisoire, cible);
|
|
483
|
+
return null;
|
|
484
|
+
} catch (erreur) {
|
|
485
|
+
rmSync(provisoire, { force: true });
|
|
486
|
+
return erreur;
|
|
487
|
+
}
|
|
462
488
|
}
|
|
463
489
|
|
|
464
490
|
/**
|
|
@@ -487,10 +513,19 @@ export function tokensCss(arguments_, {
|
|
|
487
513
|
|
|
488
514
|
const cible = resolve(racine, options.out);
|
|
489
515
|
const source = resolve(racine, configuration.tokens);
|
|
490
|
-
|
|
516
|
+
const lus = [source, resolve(racine, NOM_CONFIGURATION)];
|
|
517
|
+
if (lus.some((lu) => memeFichier(cible, lu)) || cible.toLowerCase().endsWith(".contract.json")) {
|
|
491
518
|
alerter(`--out désigne ${options.out}, que la commande lit : choisissez un fichier .css à part.`);
|
|
492
519
|
return 2;
|
|
493
520
|
}
|
|
521
|
+
if (existsSync(cible) && statSync(cible).isDirectory()) {
|
|
522
|
+
alerter(`--out désigne le dossier ${options.out} : nommez le fichier .css à écrire.`);
|
|
523
|
+
return 2;
|
|
524
|
+
}
|
|
525
|
+
const echecDEcriture = (erreur) => {
|
|
526
|
+
alerter(`${options.out} n'a pas pu être écrit (${erreur.code ?? erreur.message}) : la feuille précédente reste en place.`);
|
|
527
|
+
return 2;
|
|
528
|
+
};
|
|
494
529
|
|
|
495
530
|
const enTete = `/* Généré par ucm tokens css depuis ${configuration.tokens}. Relancer la commande plutôt que modifier ce fichier. */\n`;
|
|
496
531
|
|
|
@@ -501,7 +536,8 @@ export function tokensCss(arguments_, {
|
|
|
501
536
|
+ `des tokens : ${cites.join(", ")}. Exportez les tokens depuis Figma, ou corrigez le chemin tokens de ${NOM_CONFIGURATION}.`);
|
|
502
537
|
return 1;
|
|
503
538
|
}
|
|
504
|
-
remplacer(cible, `${enTete}/* Aucun fichier de tokens, et aucun contrat ne cite de token : cette feuille ne déclare rien. */\n`, ecrireFichier);
|
|
539
|
+
const echec = remplacer(cible, `${enTete}/* Aucun fichier de tokens, et aucun contrat ne cite de token : cette feuille ne déclare rien. */\n`, ecrireFichier);
|
|
540
|
+
if (echec) return echecDEcriture(echec);
|
|
505
541
|
ecrire(`${options.out} : aucun fichier de tokens, feuille vide écrite.`);
|
|
506
542
|
return 0;
|
|
507
543
|
}
|
|
@@ -575,7 +611,8 @@ export function tokensCss(arguments_, {
|
|
|
575
611
|
}
|
|
576
612
|
|
|
577
613
|
const contenu = `${enTete}${css}`;
|
|
578
|
-
remplacer(cible, contenu, ecrireFichier);
|
|
614
|
+
const echec = remplacer(cible, contenu, ecrireFichier);
|
|
615
|
+
if (echec) return echecDEcriture(echec);
|
|
579
616
|
const { regles, declarations, octets } = statistiquesDeFeuille(contenu);
|
|
580
617
|
ecrire(`${options.out} : ${regles} règles, ${declarations} déclarations, ${octets} octets.`);
|
|
581
618
|
for (const note of notesDAttributs) ecrire(note);
|