@ucm-kit/cli 0.1.42 → 0.1.45
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 +13 -7
- package/package.json +2 -2
- package/src/check.mjs +2 -2
- package/src/init.mjs +42 -6
- package/src/rapport-gitlab.mjs +25 -4
- package/src/tokens-css.mjs +6 -1
- package/src/ucm.mjs +14 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ matches them.
|
|
|
16
16
|
Requires Node 20 or later. At the root of the repository:
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
19
|
+
npx --yes @ucm-kit/cli@0.1.45 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.1.42 init
|
|
|
27
27
|
To run the check locally:
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
30
|
+
npx --yes @ucm-kit/cli@0.1.45 check --report ci-report.md
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
`--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
|
|
@@ -78,7 +78,7 @@ contract would resolve to the same file. A repository that does not write React
|
|
|
78
78
|
states its own extension:
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
81
|
+
npx --yes @ucm-kit/cli@0.1.45 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
The three path options act only on a first install. `ucm init` never overwrites
|
|
@@ -159,7 +159,7 @@ global key, so the project's other jobs keep their rules. `ucm` runs the check
|
|
|
159
159
|
in merge request pipelines and on the default branch; `ucm-rapport` posts the
|
|
160
160
|
note in merge request pipelines. Both take the default `test` stage. A new
|
|
161
161
|
`.gitlab-ci.yml` includes the file; an existing one is left alone, and the
|
|
162
|
-
command prints the `include` line to add. It also prints
|
|
162
|
+
command prints the `include` line to add. It also prints the settings it
|
|
163
163
|
cannot make:
|
|
164
164
|
|
|
165
165
|
- create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
|
|
@@ -172,8 +172,14 @@ cannot make:
|
|
|
172
172
|
- tick "Pipelines must succeed" in the merge request settings. Without it, a red
|
|
173
173
|
report does not block the merge it says is blocked;
|
|
174
174
|
- keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
|
|
175
|
-
pipeline whose job names a missing stage
|
|
176
|
-
|
|
175
|
+
pipeline whose job names a missing stage;
|
|
176
|
+
- put `- if: $CI_PIPELINE_SOURCE == "merge_request_event"` first in
|
|
177
|
+
`workflow:rules` when `.gitlab-ci.yml` declares rules without it: GitLab then
|
|
178
|
+
creates no merge request pipeline, and `ucm` checks no export.
|
|
179
|
+
|
|
180
|
+
Both jobs set `inherit: default: false`. A project `default:` block does not
|
|
181
|
+
reach them: its `before_script` would run before the token is unset, and would
|
|
182
|
+
fail in `ucm-rapport`, which has no clone. Global variables are still inherited.
|
|
177
183
|
`ucm` unsets `UCM_GITLAB_TOKEN` before `npm ci`, so install scripts do not
|
|
178
184
|
inherit it on executors that set variables in the job script. `ucm-rapport`
|
|
179
185
|
runs no code from the repository: it clones nothing, receives `ci-report.md`
|
|
@@ -182,7 +188,7 @@ directory. It writes a minimal report when the check stopped before writing
|
|
|
182
188
|
one, then posts the report:
|
|
183
189
|
|
|
184
190
|
```sh
|
|
185
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
191
|
+
npx --yes @ucm-kit/cli@0.1.45 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
|
|
186
192
|
```
|
|
187
193
|
|
|
188
194
|
| Option | Effect |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
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.1.
|
|
32
|
+
"@ucm-kit/core": "0.1.39"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"yaml": "^2.9.1"
|
package/src/check.mjs
CHANGED
|
@@ -59,7 +59,7 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
|
|
|
59
59
|
let contratsModifies;
|
|
60
60
|
try {
|
|
61
61
|
contratsModifies = git([
|
|
62
|
-
"diff", "--name-only", base, "HEAD", "--", ":(glob)**/*.contract.json",
|
|
62
|
+
"diff", "--name-only", "-z", base, "HEAD", "--", ":(glob)**/*.contract.json",
|
|
63
63
|
]);
|
|
64
64
|
} catch (erreur) {
|
|
65
65
|
return {
|
|
@@ -79,7 +79,7 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
|
|
|
79
79
|
tokensModifies = true;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
return { contratsModifies, tokensModifies };
|
|
82
|
+
return { contratsModifies: contratsModifies.replaceAll("\0", "\n"), tokensModifies };
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
package/src/init.mjs
CHANGED
|
@@ -520,8 +520,16 @@ function workflow(version) {
|
|
|
520
520
|
" # --edit-last met à jour le commentaire précédent au lieu d'en empiler",
|
|
521
521
|
" # un nouveau à chaque push ; s'il n'en existe pas encore, on en crée un.",
|
|
522
522
|
" run: |",
|
|
523
|
-
'
|
|
524
|
-
'
|
|
523
|
+
' printf "<!-- ucm-rapport -->\\n" > ucm-report.md',
|
|
524
|
+
' cat ci-report.md >> ucm-report.md',
|
|
525
|
+
' COMPTE="$(gh api user --jq .login)"',
|
|
526
|
+
' NOTE="$(gh api "repos/$GITHUB_REPOSITORY/issues/$NUMERO/comments" --paginate \\',
|
|
527
|
+
' --jq ".[] | select(.user.login == \\\"$COMPTE\\\") | select(.body | startswith(\\\"<!-- ucm-rapport -->\\\")) | .id" | tail -n 1)"',
|
|
528
|
+
' if [ -n "$NOTE" ]; then',
|
|
529
|
+
' gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$NOTE" -f body="$(cat ucm-report.md)"',
|
|
530
|
+
' else',
|
|
531
|
+
' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ucm-report.md',
|
|
532
|
+
' fi',
|
|
525
533
|
"",
|
|
526
534
|
].join("\n");
|
|
527
535
|
}
|
|
@@ -566,6 +574,10 @@ function workflowGitlab(version) {
|
|
|
566
574
|
"# Écrit par `ucm init`. Adaptez-le : il ne sera jamais réécrit par-dessus.",
|
|
567
575
|
"ucm:",
|
|
568
576
|
" image: node:22",
|
|
577
|
+
" # Le before_script d'un default: du projet tournerait avec le jeton de la",
|
|
578
|
+
" # note. Les variables globales, elles, restent héritées.",
|
|
579
|
+
" inherit:",
|
|
580
|
+
" default: false",
|
|
569
581
|
" variables:",
|
|
570
582
|
" # Le diff avec la base délimite les états informatifs du rapport.",
|
|
571
583
|
' GIT_DEPTH: "0"',
|
|
@@ -591,6 +603,9 @@ function workflowGitlab(version) {
|
|
|
591
603
|
"",
|
|
592
604
|
"ucm-rapport:",
|
|
593
605
|
" image: node:22",
|
|
606
|
+
" # Sans clone, le before_script d'un default: du projet échouerait.",
|
|
607
|
+
" inherit:",
|
|
608
|
+
" default: false",
|
|
594
609
|
" needs:",
|
|
595
610
|
" - job: ucm",
|
|
596
611
|
" artifacts: true",
|
|
@@ -601,7 +616,7 @@ function workflowGitlab(version) {
|
|
|
601
616
|
" allow_failure: true",
|
|
602
617
|
" variables:",
|
|
603
618
|
" # Aucun clone : ni .npmrc ni node_modules du repository.",
|
|
604
|
-
" GIT_STRATEGY:
|
|
619
|
+
" GIT_STRATEGY: empty",
|
|
605
620
|
' NPM_CONFIG_IGNORE_SCRIPTS: "true"',
|
|
606
621
|
" script:",
|
|
607
622
|
" # Filet : sans rapport, `ucm` s'est arrêté avant le contrôle (clone,",
|
|
@@ -622,9 +637,22 @@ function workflowGitlab(version) {
|
|
|
622
637
|
].join("\n");
|
|
623
638
|
}
|
|
624
639
|
|
|
640
|
+
/**
|
|
641
|
+
* Le texte d'une clé de premier niveau d'un YAML, lignes indentées comprises,
|
|
642
|
+
* ou `null` quand la clé est absente.
|
|
643
|
+
*
|
|
644
|
+
* La CLI n'a aucune dépendance YAML : ce découpage lit la forme qu'écrit un
|
|
645
|
+
* `.gitlab-ci.yml` courant. Une clé venue d'un `include:` n'est pas vue.
|
|
646
|
+
*/
|
|
647
|
+
function blocDeRacine(yaml, cle) {
|
|
648
|
+
const bloc = new RegExp(`^${cle}:([^\\n]*(?:\\n(?:[ \\t]+[^\\n]*|-[^\\n]*|#[^\\n]*|[ \\t]*)(?=\\n|$))*)`, "m").exec(yaml);
|
|
649
|
+
return bloc ? bloc[1] : null;
|
|
650
|
+
}
|
|
651
|
+
|
|
625
652
|
/**
|
|
626
653
|
* Les lignes qu'`init` ne peut pas écrire pour GitLab : des réglages du projet,
|
|
627
|
-
*
|
|
654
|
+
* un `stages:` qui refuserait le job, et un `workflow:rules` qui ne crée aucun
|
|
655
|
+
* pipeline de merge request.
|
|
628
656
|
*/
|
|
629
657
|
function lignesGitlab(racine) {
|
|
630
658
|
const lignes = [
|
|
@@ -639,13 +667,21 @@ function lignesGitlab(racine) {
|
|
|
639
667
|
];
|
|
640
668
|
try {
|
|
641
669
|
const ci = readFileSync(join(racine, ".gitlab-ci.yml"), "utf8");
|
|
642
|
-
const stages =
|
|
643
|
-
if (stages &&
|
|
670
|
+
const stages = blocDeRacine(ci, "stages");
|
|
671
|
+
if (stages !== null && !/(?:^|[\s,\[])(?:-\s*)?test(?=$|[\s,\]])/m.test(stages)) {
|
|
644
672
|
lignes.push({
|
|
645
673
|
fichier: ".gitlab-ci.yml",
|
|
646
674
|
ligne: "ajoutez `test` à `stages:`. Le job ucm s'y range, et GitLab refuse un pipeline dont un job vise un stage absent.",
|
|
647
675
|
});
|
|
648
676
|
}
|
|
677
|
+
const workflow = blocDeRacine(ci, "workflow");
|
|
678
|
+
const exclutLesMr = /if:\s*[^\n]*merge_request_event[\s\S]{0,160}?when:\s*never/.test(workflow ?? '');
|
|
679
|
+
if (workflow !== null && /^[ \t]+rules:/m.test(workflow) && (!workflow.includes("merge_request_event") || exclutLesMr)) {
|
|
680
|
+
lignes.push({
|
|
681
|
+
fichier: ".gitlab-ci.yml",
|
|
682
|
+
ligne: "ajoutez `- if: $CI_PIPELINE_SOURCE == \"merge_request_event\"` en tête de `workflow:rules`. Sans cette règle, GitLab ne crée aucun pipeline de merge request et le job ucm ne contrôle aucun export.",
|
|
683
|
+
});
|
|
684
|
+
}
|
|
649
685
|
} catch {
|
|
650
686
|
// Sans .gitlab-ci.yml, celui qu'`init` écrit ne déclare aucun stage.
|
|
651
687
|
}
|
package/src/rapport-gitlab.mjs
CHANGED
|
@@ -20,6 +20,14 @@ import { resolve } from "node:path";
|
|
|
20
20
|
|
|
21
21
|
export const MARQUEUR_RAPPORT = "<!-- ucm-rapport -->";
|
|
22
22
|
|
|
23
|
+
function neutraliserActionsRapides(texte) {
|
|
24
|
+
return texte.replace(/^([ \t]*)(\/\S.*)$/gm, (_entier, avant, action) => {
|
|
25
|
+
const longueur = Math.max(0, ...[...action.matchAll(/`+/g)].map(([suite]) => suite.length)) + 1;
|
|
26
|
+
const borne = "`".repeat(longueur);
|
|
27
|
+
return `${avant}${borne}${action}${borne}`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
const API_PAR_DEFAUT = "https://gitlab.com/api/v4";
|
|
24
32
|
|
|
25
33
|
const USAGE = "ucm rapport-gitlab --projet <id> --merge-request <iid> --fichier <chemin> [--api <url>]";
|
|
@@ -105,7 +113,7 @@ export async function rapportGitlab(arguments_, {
|
|
|
105
113
|
alerter(`Le rapport ${valeurs.fichier} ne se lit pas (${erreurLecture?.code ?? erreurLecture?.message}) : aucune note n'est publiée.`);
|
|
106
114
|
return 1;
|
|
107
115
|
}
|
|
108
|
-
const corps = `${MARQUEUR_RAPPORT}\n${rapport}`;
|
|
116
|
+
const corps = `${MARQUEUR_RAPPORT}\n${neutraliserActionsRapides(rapport)}`;
|
|
109
117
|
const projet = encodeURIComponent(valeurs.projet);
|
|
110
118
|
const notes = `${valeurs.api}/projects/${projet}/merge_requests/${encodeURIComponent(valeurs.mergeRequest)}/notes`;
|
|
111
119
|
|
|
@@ -114,23 +122,36 @@ export async function rapportGitlab(arguments_, {
|
|
|
114
122
|
try {
|
|
115
123
|
reponse = await requete(url, {
|
|
116
124
|
...init,
|
|
125
|
+
redirect: "manual",
|
|
117
126
|
headers: { "PRIVATE-TOKEN": jeton, "Content-Type": "application/json" },
|
|
118
127
|
});
|
|
119
128
|
} catch (panne) {
|
|
120
|
-
throw new RefusGitlab(null, `La requête vers GitLab n'a pas abouti en voulant ${action}
|
|
129
|
+
throw new RefusGitlab(null, `La requête vers GitLab n'a pas abouti en voulant ${action}. Relancez le job.`);
|
|
130
|
+
}
|
|
131
|
+
if (reponse.status >= 300 && reponse.status < 400) {
|
|
132
|
+
throw new RefusGitlab(reponse.status, `GitLab a redirige la requete en voulant ${action}.`);
|
|
121
133
|
}
|
|
122
134
|
if (!reponse.ok) throw new RefusGitlab(reponse.status, gesteDuStatut(reponse.status, action));
|
|
123
135
|
return reponse;
|
|
124
136
|
}
|
|
125
137
|
|
|
126
138
|
try {
|
|
127
|
-
|
|
139
|
+
let compte;
|
|
140
|
+
try {
|
|
141
|
+
compte = await (await appeler(`${valeurs.api}/user`, "lire le compte du jeton")).json();
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (error instanceof RefusGitlab) throw error;
|
|
144
|
+
throw new RefusGitlab(null, "GitLab a rendu une réponse illisible en lisant le compte du jeton. Relancez le job.");
|
|
145
|
+
}
|
|
128
146
|
|
|
129
147
|
let existante = null;
|
|
130
148
|
let page = "1";
|
|
131
149
|
while (page && !existante) {
|
|
132
150
|
const reponse = await appeler(`${notes}?per_page=100&sort=asc&page=${page}`, "lire les notes de la merge request");
|
|
133
|
-
|
|
151
|
+
let lues;
|
|
152
|
+
try { lues = await reponse.json(); } catch {
|
|
153
|
+
throw new RefusGitlab(null, "GitLab a rendu une réponse illisible en lisant les notes de la merge request. Relancez le job.");
|
|
154
|
+
}
|
|
134
155
|
existante = lues.find((note) => !note.system && note.author?.id === compte.id
|
|
135
156
|
&& typeof note.body === "string" && note.body.includes(MARQUEUR_RAPPORT)) ?? null;
|
|
136
157
|
page = reponse.headers.get("x-next-page");
|
package/src/tokens-css.mjs
CHANGED
|
@@ -293,6 +293,10 @@ export function feuilleDesTokens(document, { axes = [], attributs = new Map(), r
|
|
|
293
293
|
const parNom = new Map();
|
|
294
294
|
for (const chemin of index.keys()) {
|
|
295
295
|
const nom = tokenCssVariable(chemin);
|
|
296
|
+
if (nom === "--") {
|
|
297
|
+
refus.push(`La feuille « ${chemin} » ne donne aucun nom CSS.`);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
296
300
|
if (nom.startsWith(PREFIXE_DES_INTERMEDIAIRES)) {
|
|
297
301
|
refus.push(`La feuille « ${chemin} » donne la propriété « ${nom} », dont le préfixe ${PREFIXE_DES_INTERMEDIAIRES} est réservé aux collections étendues.`);
|
|
298
302
|
}
|
|
@@ -569,7 +573,8 @@ export function tokensCss(arguments_, {
|
|
|
569
573
|
return 2;
|
|
570
574
|
};
|
|
571
575
|
|
|
572
|
-
const
|
|
576
|
+
const cheminDansLEnTete = configuration.tokens.replaceAll("*/", "* /");
|
|
577
|
+
const enTete = `/* Généré par ucm tokens css depuis ${cheminDansLEnTete}. Relancer la commande plutôt que modifier ce fichier. */\n`;
|
|
573
578
|
|
|
574
579
|
if (!existsSync(source)) {
|
|
575
580
|
const cites = contratsQuiCitentDesTokens(racine, configuration.components);
|
package/src/ucm.mjs
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* publient les décisions du noyau sans dupliquer son orchestration.
|
|
5
5
|
* Codes : 0 succès, 1 contrôles rouges, 2 invocation ou configuration fautive.
|
|
6
6
|
*/
|
|
7
|
-
import { realpathSync } from "node:fs";
|
|
7
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
+
import { dirname, resolve } from "node:path";
|
|
8
9
|
import process from "node:process";
|
|
9
10
|
import { pathToFileURL } from "node:url";
|
|
10
11
|
|
|
@@ -113,6 +114,18 @@ function executerCommande(arguments_, {
|
|
|
113
114
|
ecrire = console.log,
|
|
114
115
|
...sorties
|
|
115
116
|
} = {}) {
|
|
117
|
+
const racineInitiale = racine;
|
|
118
|
+
for (let candidate = resolve(racine); ; candidate = dirname(candidate)) {
|
|
119
|
+
if (existsSync(resolve(candidate, "ucm.config.json")) || existsSync(resolve(candidate, ".git"))) {
|
|
120
|
+
racine = candidate;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
const parent = dirname(candidate);
|
|
124
|
+
if (parent === candidate) {
|
|
125
|
+
racine = racineInitiale;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
116
129
|
const [commande] = arguments_;
|
|
117
130
|
|
|
118
131
|
if (commande === undefined || commande === "--help" || commande === "-h") {
|