@roomi-fields/grillhouse 0.26.0 → 0.28.0

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.
Files changed (74) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/agents/explorateur.md +1 -1
  3. package/cadre/templates/paquet/docs/CADRE.md +36 -0
  4. package/cadre/templates/paquet/docs/INTERFACE.md +10 -0
  5. package/cadre/templates/projet/CLAUDE.md +7 -0
  6. package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
  7. package/cadre/templates/python/package.json +18 -0
  8. package/charte.md +48 -1
  9. package/docs/ARCHITECTURE.md +113 -20
  10. package/docs/CADRE.md +7 -6
  11. package/docs/INTERFACE.md +111 -32
  12. package/package.json +1 -1
  13. package/scripts/circuit.mjs +304 -40
  14. package/scripts/commande-du-langage.mjs +2 -2
  15. package/scripts/commandes-composees.mjs +156 -0
  16. package/scripts/composition-des-langages.mjs +306 -0
  17. package/scripts/conformite.mjs +1 -3
  18. package/scripts/dernier-vert.mjs +15 -2
  19. package/scripts/engendres.mjs +170 -0
  20. package/scripts/enveloppe/lancer.sh +10 -6
  21. package/scripts/enveloppe/travail-de-la-copie.mjs +82 -8
  22. package/scripts/etapes.mjs +18 -5
  23. package/scripts/gardes-du-cadre.mjs +7 -4
  24. package/scripts/grillhouse-maj.mjs +157 -103
  25. package/scripts/index-interfaces.mjs +78 -0
  26. package/scripts/init.mjs +5 -5
  27. package/scripts/integration/file.mjs +74 -13
  28. package/scripts/integration/integrer.mjs +50 -62
  29. package/scripts/jointure.d.ts +44 -13
  30. package/scripts/langages/cargo/binaires.mjs +29 -6
  31. package/scripts/langages/cargo/clippy.mjs +4 -2
  32. package/scripts/langages/cargo/commandes.mjs +45 -7
  33. package/scripts/langages/cargo/exemples.mjs +1 -15
  34. package/scripts/langages/cargo/index-interfaces.mjs +20 -3
  35. package/scripts/langages/cargo/index.mjs +12 -10
  36. package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
  37. package/scripts/langages/cargo/sccache.mjs +29 -0
  38. package/scripts/langages/cargo/squelette.mjs +111 -0
  39. package/scripts/langages/python/binaires.json +3 -0
  40. package/scripts/langages/python/binaires.mjs +59 -0
  41. package/scripts/langages/python/commandes.mjs +411 -0
  42. package/scripts/langages/python/composants.mjs +272 -0
  43. package/scripts/langages/python/exemples.mjs +260 -0
  44. package/scripts/langages/python/index-interfaces.mjs +77 -0
  45. package/scripts/langages/python/index.mjs +97 -0
  46. package/scripts/langages/python/lot.mjs +76 -0
  47. package/scripts/langages/python/mise-a-jour.mjs +54 -0
  48. package/scripts/langages/python/squelette.mjs +66 -0
  49. package/scripts/langages/python/tailles-des-tests.mjs +102 -0
  50. package/scripts/langages/python/verdict.mjs +85 -0
  51. package/scripts/langages/typescript/exemples.mjs +1 -20
  52. package/scripts/langages/typescript/frontieres.mjs +14 -1
  53. package/scripts/langages/typescript/index-interfaces.mjs +10 -3
  54. package/scripts/langages/typescript/index.mjs +14 -15
  55. package/scripts/langages/typescript/squelette.mjs +120 -0
  56. package/scripts/langages-des-paquets.mjs +171 -0
  57. package/scripts/langages.mjs +60 -41
  58. package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
  59. package/scripts/migrations.mjs +2 -0
  60. package/scripts/outils-cles.mjs +1 -1
  61. package/scripts/paquet.mjs +261 -0
  62. package/scripts/resultats.mjs +54 -1
  63. package/scripts/session-start.sh +34 -9
  64. package/scripts/sources.mjs +2 -1
  65. package/scripts/sous-commandes.mjs +6 -3
  66. package/scripts/tableau-des-composants.mjs +140 -0
  67. package/scripts/verrous/verrou.mjs +3 -2
  68. package/skills/explorateur/SKILL.md +33 -4
  69. package/skills/grill/SKILL.md +14 -1
  70. package/skills/pitmaster/SKILL.md +34 -4
  71. package/skills/pitmaster/references/consigne-agent.md +33 -4
  72. package/skills/redacteur/references/documents-d-un-composant.md +12 -0
  73. package/skills/relecteur/SKILL.md +12 -0
  74. package/skills/testwriter/SKILL.md +6 -0
@@ -4,9 +4,9 @@
4
4
  // guards of structure and their generators. The core loads it by scripts/langages.mjs, and this
5
5
  // module imports of the core its published entries alone.
6
6
  //
7
- // - Where it is found: a repository with a tsconfig.json at its root or in a package of the frame
8
- // (`trouve`), which the update declares typescript; its tools, the optional peers of the package
9
- // the update installs in such a project (`outils`).
7
+ // - The manifest of its package, which the guard of the languages asks of a package the
8
+ // architecture declares typescript (`manifeste`): a package.json; its tools, the optional peers of
9
+ // the package the update installs in such a project (`outils`).
10
10
  // - The components: the folders `packages/<x>` and `src/<x>` of the frame (`composants` of
11
11
  // ./consommateurs.mjs), out of the frame left out; a file's is the component that holds it; the
12
12
  // shared test material, the components whose package exports `./test-fixtures` (`matieres`); a
@@ -36,6 +36,8 @@
36
36
  // (./regle-des-tests.mjs).
37
37
  // - The generated files, each its command, the guard that checks it and the names its findings
38
38
  // carry: the index of the interfaces, the turbo.json of the packages, the reports of API.
39
+ // - The entries of the index of each interface (`entreesDeLIndex`, ./index-interfaces.mjs), which
40
+ // the core assembles in a project of several languages.
39
41
  // - The guards of structure, in the order they play.
40
42
  // - The migrations of a project of TypeScript (./migrations/): the base configuration of Vitest,
41
43
  // and the ones that replay a guard of this module, which the update plays with the core's
@@ -43,8 +45,9 @@
43
45
  // - No binary of the machine (`binaires`); what its tools write in a project, `.turbo`
44
46
  // (`ignorer`); its share of the update (./mise-a-jour.mjs, `miseAJour`): the tests by Vitest,
45
47
  // the frame's package declared, the typing, the turbo.json, and the generators.
48
+ // - The skeleton of a new package (./squelette.mjs, `squelette`), which `grillhouse paquet` writes.
46
49
  import { spawnSync } from 'node:child_process';
47
- import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
50
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
48
51
  import { createRequire } from 'node:module';
49
52
  import { tmpdir } from 'node:os';
50
53
  import path from 'node:path';
@@ -52,12 +55,12 @@ import { fileURLToPath } from 'node:url';
52
55
  import { composants as lesComposants, matieres } from './consommateurs.mjs';
53
56
  import { elementsDuLot } from './elements-du-lot.mjs';
54
57
  import { A_ELAGUER, lireSarif, RESULTATS } from '../../resultats.mjs';
55
- import { paquets } from '../../paquets.mjs';
56
58
  import { lecteurs } from './lecteurs.mjs';
57
59
  import { estUnTest, manifestes } from './regle-des-tests.mjs';
58
60
  import { SCRIPT_DES_TESTS } from './script-des-tests.mjs';
59
61
  import { verdict } from './verdict.mjs';
60
62
  import { miseAJour } from './mise-a-jour.mjs';
63
+ import { squelette } from './squelette.mjs';
61
64
  import * as configVitest from './migrations/0.23.0-config-vitest.mjs';
62
65
  import * as nomsDeclaresInutilises from './migrations/0.24.4-noms-declares-inutilises.mjs';
63
66
  import * as lignesMalFormees from './migrations/0.24.6-lignes-mal-formees.mjs';
@@ -67,6 +70,7 @@ import * as cheminsDesTests from './migrations/0.25.0-chemins-des-tests.mjs';
67
70
 
68
71
  // The scripts of this module, beside this file.
69
72
  const SCRIPTS = path.dirname(fileURLToPath(import.meta.url));
73
+ const requis = createRequire(import.meta.url);
70
74
  const ici = nom => path.join(SCRIPTS, nom);
71
75
  const generateur = (script, ...args) => [`node ${JSON.stringify(ici(script))}`, ...args].join(' ');
72
76
  const CHAMPS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
@@ -195,18 +199,9 @@ const joueDesTests = (_racine, composant) =>
195
199
  typeof lireJson(path.join(composant.dossier, 'package.json'))?.scripts?.[SCRIPT_DES_TESTS] ===
196
200
  'string';
197
201
 
198
- // Whether the repository at <racine> holds TypeScript: a tsconfig.json at its root or in one of its
199
- // packages of the frame, as @nx/js infers a project from its tsconfig.
200
- const trouve = racine =>
201
- existsSync(path.join(racine, 'tsconfig.json')) ||
202
- paquets(racine).some(
203
- ({ dossier, hors }) => !hors && existsSync(path.join(racine, dossier, 'tsconfig.json'))
204
- );
205
-
206
202
  export default {
207
203
  nom: 'typescript',
208
- trouve,
209
- signe: 'un tsconfig.json à la racine ou dans un paquet',
204
+ manifeste: 'package.json',
210
205
  // The tools a project of TypeScript installs, optional peers of the package: what this module
211
206
  // runs as commands (Turborepo, knip, dependency-cruiser) and what its scripts import (API
212
207
  // Extractor, its model, TSDoc's configuration, jsonc-parser); the project's own TypeScript and
@@ -313,6 +308,9 @@ export default {
313
308
  []
314
309
  ),
315
310
  ],
311
+ // Loaded at the call: ./index-interfaces.mjs imports the services of the core, which import the
312
+ // join that loads this module.
313
+ entreesDeLIndex: racine => requis('./index-interfaces.mjs').entreesDeLIndex(racine),
316
314
  gardes: () => [
317
315
  [ici('turbo-des-paquets.mjs')],
318
316
  [ici('index-interfaces.mjs'), '--verifier'],
@@ -334,4 +332,5 @@ export default {
334
332
  cheminsDesTests,
335
333
  ],
336
334
  miseAJour: miseAJour(joueDesTests),
335
+ squelette,
337
336
  };
@@ -0,0 +1,120 @@
1
+ // The skeleton of a new package of the module typescript, the demand `squelette` of the join
2
+ // (scripts/jointure.d.ts), which `grillhouse paquet` writes (scripts/paquet.mjs), as `nx g
3
+ // @nx/js:lib` and `turbo gen workspace` write one: no behaviour, no test.
4
+ //
5
+ // - A package of TypeScript lives under `packages/<nom>`, where the module finds its components
6
+ // (./composants.mjs); another path is refused, named.
7
+ // - Its files: its package.json (its name, the root's scope before the folder's name when the root's
8
+ // name has one, as Nx names a library after the workspace's scope; private; an ES module; its
9
+ // script `test:unit`, which makes it a package that plays tests, and the tools of its tests and
10
+ // of its typing the root does not declare, TypeScript, Vitest and Node's types, at the versions of
11
+ // the module's template); its tsconfig.json, which types its sources, its tests and its
12
+ // configuration, nothing emitted; its vitest.config.ts, the frame's base configuration by its
13
+ // name, which passes while the package has no test yet, as the configuration of a library that
14
+ // Nx generates (`passWithNoTests`); `src/index.ts`, an empty module; `tests/.gitkeep`, its folder
15
+ // of tests. The update gives it its script `typecheck` and the frame's package in its
16
+ // devDependencies (./mise-a-jour.mjs).
17
+ // - The workspace: the root package.json receives the package's path in its `workspaces` (created
18
+ // when the root has none), unless a pattern there covers it already.
19
+ // - The lock of the versions: `npm install`, at the root.
20
+ import { existsSync, readFileSync } from 'node:fs';
21
+ import path from 'node:path';
22
+
23
+ const CHAMPS = ['dependencies', 'devDependencies', 'optionalDependencies'];
24
+ // The tools of a package's tests and of its typing, at the versions of the module's template.
25
+ const OUTILS_DU_PAQUET = ['@types/node', 'typescript', 'vitest'];
26
+
27
+ const lireJson = f => (existsSync(f) ? JSON.parse(readFileSync(f, 'utf8')) : null);
28
+ const json = v => `${JSON.stringify(v, null, 2)}\n`;
29
+
30
+ const TSCONFIG = {
31
+ compilerOptions: {
32
+ target: 'ES2022',
33
+ lib: ['ES2022'],
34
+ module: 'Node16',
35
+ moduleResolution: 'Node16',
36
+ resolveJsonModule: true,
37
+ noEmit: true,
38
+ esModuleInterop: true,
39
+ forceConsistentCasingInFileNames: true,
40
+ isolatedModules: true,
41
+ strict: true,
42
+ noUnusedLocals: true,
43
+ noUnusedParameters: true,
44
+ noImplicitReturns: true,
45
+ noFallthroughCasesInSwitch: true,
46
+ noUncheckedIndexedAccess: true,
47
+ skipLibCheck: true,
48
+ },
49
+ include: ['src/**/*', 'tests/**/*', '*.ts'],
50
+ exclude: ['node_modules', 'dist'],
51
+ };
52
+
53
+ const VITEST = `import { defineConfig, mergeConfig } from 'vitest/config';
54
+ import base from '@roomi-fields/grillhouse/vitest-config';
55
+
56
+ // The tests of the package: the frame's base configuration, by its name, extended with what is the
57
+ // package's own. It passes while the package has no test yet, as the configuration of a library
58
+ // that Nx generates; its first test plays as any other.
59
+ export default mergeConfig(
60
+ base,
61
+ defineConfig({
62
+ test: {
63
+ include: ['src/**/*.{test,spec}.{ts,js,mjs}', 'tests/**/*.{test,spec}.{ts,js,mjs}'],
64
+ passWithNoTests: true,
65
+ },
66
+ })
67
+ );
68
+ `;
69
+
70
+ /** @type {import('../../jointure.js').Langage['squelette']} */
71
+ export function squelette(racine, { chemin, modele }) {
72
+ if (!/^packages\/[^/]+$/.test(chemin)) {
73
+ throw new Error(
74
+ `${chemin} : un paquet typescript vit sous packages/<nom>, où le module trouve ses composants.`
75
+ );
76
+ }
77
+ const racinePkg = lireJson(path.join(racine, 'package.json')) ?? {};
78
+ const nom = path.posix.basename(chemin);
79
+ const portee = /^(@[^/]+)\//.exec(String(racinePkg.name ?? ''))?.[1];
80
+ const declare = n => CHAMPS.some(c => racinePkg[c]?.[n] !== undefined);
81
+ const versions = modele.devDependencies ?? {};
82
+ const devDependencies = Object.fromEntries(
83
+ OUTILS_DU_PAQUET.filter(n => !declare(n) && typeof versions[n] === 'string').map(n => [
84
+ n,
85
+ versions[n],
86
+ ])
87
+ );
88
+ const pkg = {
89
+ name: portee ? `${portee}/${nom}` : nom,
90
+ version: '0.0.0',
91
+ private: true,
92
+ type: 'module',
93
+ scripts: { 'test:unit': 'vitest run' },
94
+ ...(Object.keys(devDependencies).length ? { devDependencies } : {}),
95
+ };
96
+ const fichiers = {
97
+ [`${chemin}/package.json`]: json(pkg),
98
+ [`${chemin}/tsconfig.json`]: json(TSCONFIG),
99
+ [`${chemin}/vitest.config.ts`]: VITEST,
100
+ [`${chemin}/src/index.ts`]: `// The entry of the package ${nom}: its interface, docs/INTERFACE.md, says what it exports.\nexport {};\n`,
101
+ [`${chemin}/tests/.gitkeep`]: '',
102
+ };
103
+ const espaces = Array.isArray(racinePkg.workspaces)
104
+ ? racinePkg.workspaces
105
+ : (racinePkg.workspaces?.packages ?? null);
106
+ const couvert = (espaces ?? []).some(
107
+ m => typeof m === 'string' && !m.startsWith('!') && path.matchesGlob(chemin, m)
108
+ );
109
+ let espace = null;
110
+ if (!couvert) {
111
+ const p = { ...racinePkg };
112
+ if (Array.isArray(p.workspaces) || p.workspaces === undefined) {
113
+ p.workspaces = [...(p.workspaces ?? []), chemin];
114
+ } else {
115
+ p.workspaces = { ...p.workspaces, packages: [...(p.workspaces.packages ?? []), chemin] };
116
+ }
117
+ espace = { fichier: 'package.json', texte: json(p) };
118
+ }
119
+ return { fichiers, espace, verrouiller: { commande: 'npm', args: ['install'], dossier: '.' } };
120
+ }
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ // The guard of the languages of the packages: each package follows the language the architecture
3
+ // declares for it, as Bazel builds each target by the rule its BUILD file names, and refuses a
4
+ // source the rule does not take.
5
+ //
6
+ // npx grillhouse langages-des-paquets (one of the frame's guards, scripts/gardes-du-cadre.mjs)
7
+ //
8
+ // - The packages are the folders the module of every language of the frame finds (`LANGAGES`),
9
+ // not of the declared languages alone: a crate in a project whose table names typescript alone
10
+ // is a package to judge. Each manifest is read to refuse a gap, never to declare: the
11
+ // declaration stays the tables of the components of docs/ARCHITECTURE.md
12
+ // (./tableau-des-composants.mjs), their rows with a language, each table read by its own column
13
+ // of the names.
14
+ // - Refused, each finding named with its package: a package that holds the manifest of its module
15
+ // (`manifeste`: a package.json, a Cargo.toml) and that no row names, « que l'architecture ne
16
+ // déclare pas »; a package a row declares of a language whose module does not find it there,
17
+ // named with the manifest it holds; a package a row declares without the manifest of that
18
+ // language; a docs/INTERFACE.md of the package, or of
19
+ // the root for the row that names it (`.`), whose line `**Langage** : <nom>` names another
20
+ // language; a row that names a folder of the project no module finds (a package of Python
21
+ // without its pyproject.toml, grillhouse-ziy), without the manifest of its language. A folder of
22
+ // a module without its manifest and without row (a folder of `src/` of a project of one package)
23
+ // is no package; a row that names neither a component nor a folder (a package not yet created,
24
+ // a crate of another repository) is not judged.
25
+ // - Each finding is written in SARIF under the guard's name, and on the error stream after ⛔; the
26
+ // exit code is 1 when there is one, 0 otherwise.
27
+ import { existsSync, readFileSync, statSync } from 'node:fs';
28
+ import path from 'node:path';
29
+ import { fileURLToPath, pathToFileURL } from 'node:url';
30
+ import { LANGAGES, langage, langagesDe } from './langages.mjs';
31
+ import { ecrireSarif } from './resultats.mjs';
32
+ import {
33
+ ARCHITECTURE,
34
+ colonneDesNoms,
35
+ COLONNE,
36
+ langageDeLaCellule,
37
+ nomme,
38
+ nomsDe,
39
+ tableauxDesComposants,
40
+ } from './tableau-des-composants.mjs';
41
+
42
+ /** This script. */
43
+ export const SCRIPT = fileURLToPath(import.meta.url);
44
+ /** The name its findings carry. */
45
+ export const GARDE = 'langages-des-paquets';
46
+
47
+ // The language the docs/INTERFACE.md under <dossier> names (`**Langage** : <nom>`), null for none.
48
+ function langageDeLInterface(dossier) {
49
+ const f = path.join(dossier, 'docs', 'INTERFACE.md');
50
+ if (!existsSync(f)) {
51
+ return null;
52
+ }
53
+ const m = readFileSync(f, 'utf8').match(/^\*\*Langu?age\*\*\s*:\s*(.+)$/m);
54
+ return m ? langageDeLaCellule(m[1]) || null : null;
55
+ }
56
+
57
+ /**
58
+ * The findings of the guard on the project at <racine>: `{ fichier, ligne?, message }`, none when
59
+ * each package follows the architecture.
60
+ * @param {string} racine the root of the project
61
+ */
62
+ export function constats(racine) {
63
+ langagesDe(racine);
64
+ // Each folder a module of the frame finds, with the components and the modules that find it.
65
+ const dossiers = new Map();
66
+ for (const nom of Object.keys(LANGAGES)) {
67
+ const m = langage(nom);
68
+ for (const c of m.composants(racine)) {
69
+ const d = dossiers.get(c.dossier) ?? { composants: [], modules: [] };
70
+ d.composants.push(c);
71
+ d.modules.push(m);
72
+ dossiers.set(c.dossier, d);
73
+ }
74
+ }
75
+ // The root, which a row names `.` when no module makes a component of it.
76
+ const laRacine = { dossier: racine, nom: '.', paquet: null };
77
+ const tous = [...[...dossiers.values()].flatMap(d => d.composants), laRacine];
78
+ // The rows that declare a package, each table read by its own column of the names.
79
+ const declarees = tableauxDesComposants(racine).flatMap(t => {
80
+ const lignes = t.lignes.filter(l => langageDeLaCellule(l.cellules[t.colonne]));
81
+ const colonne = colonneDesNoms(lignes, tous, racine, t.colonne);
82
+ return colonne < 0
83
+ ? []
84
+ : lignes.map(l => ({
85
+ index: l.index,
86
+ langage: langageDeLaCellule(l.cellules[t.colonne]),
87
+ noms: nomsDe(l.cellules[colonne]),
88
+ }));
89
+ });
90
+ const ligneDe = composants =>
91
+ declarees.find(l => composants.some(c => nomme(l.noms, c, racine))) ?? null;
92
+ const rel = d => path.relative(racine, d).split(path.sep).join('/') || '.';
93
+ const ou = l => `${ARCHITECTURE}:${l.index + 1}`;
94
+ const out = [];
95
+ const interface_ = (dossier, l) => {
96
+ const lu = langageDeLInterface(dossier);
97
+ if (lu !== null && lu !== l.langage) {
98
+ const f = rel(path.join(dossier, 'docs', 'INTERFACE.md'));
99
+ out.push({
100
+ fichier: f,
101
+ message: `${f} : langage ${lu}, quand ${ou(l)} déclare ${l.langage} ; l'interface reprend le langage de l'architecture.`,
102
+ });
103
+ }
104
+ };
105
+ const vus = new Set();
106
+ for (const [dossier, { composants, modules }] of dossiers) {
107
+ const avec = modules.filter(m => existsSync(path.join(dossier, m.manifeste)));
108
+ const l = ligneDe(composants);
109
+ if (!l) {
110
+ if (avec.length) {
111
+ out.push({
112
+ fichier: ARCHITECTURE,
113
+ message: `${rel(dossier)} : paquet ${avec[0].nom} (son ${avec[0].manifeste}) que ${ARCHITECTURE} ne déclare pas ; sa ligne d'un tableau des composants nomme son langage (colonne « ${COLONNE} »).`,
114
+ });
115
+ }
116
+ continue;
117
+ }
118
+ vus.add(l);
119
+ const declare = langage(l.langage);
120
+ const autre = avec.find(m => m !== declare);
121
+ if (modules.includes(declare) && existsSync(path.join(dossier, declare.manifeste))) {
122
+ // The package follows its row.
123
+ } else if (autre) {
124
+ out.push({
125
+ fichier: ARCHITECTURE,
126
+ ligne: l.index + 1,
127
+ message: `${rel(dossier)} : déclaré ${l.langage} (${ou(l)}), mais son manifeste est celui de ${autre.nom} (${autre.manifeste}) ; un paquet ${l.langage} porte son ${declare.manifeste}.`,
128
+ });
129
+ } else {
130
+ out.push({
131
+ fichier: ARCHITECTURE,
132
+ ligne: l.index + 1,
133
+ message: `${rel(dossier)} : déclaré ${l.langage} (${ou(l)}), sans son ${declare.manifeste}.`,
134
+ });
135
+ }
136
+ interface_(dossier, l);
137
+ }
138
+ const l = ligneDe([laRacine]);
139
+ if (l && !vus.has(l)) {
140
+ interface_(racine, l);
141
+ }
142
+ // A row that names a folder of the project no module finds: the package without its manifest.
143
+ for (const d of declarees.filter(x => !vus.has(x) && x !== l)) {
144
+ const manifeste = langage(d.langage).manifeste;
145
+ for (const n of d.noms.filter(x => existsSync(path.join(racine, x)) && x !== '.')) {
146
+ if (statSync(path.join(racine, n)).isDirectory()) {
147
+ out.push({
148
+ fichier: ARCHITECTURE,
149
+ ligne: d.index + 1,
150
+ message: `${n} : déclaré ${d.langage} (${ou(d)}), sans son ${manifeste}.`,
151
+ });
152
+ }
153
+ }
154
+ }
155
+ return out;
156
+ }
157
+
158
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
159
+ const racine = process.cwd();
160
+ let refus;
161
+ try {
162
+ refus = constats(racine);
163
+ } catch (e) {
164
+ refus = [{ message: e.message.replace(/^⛔ /, '') }];
165
+ }
166
+ for (const r of refus) {
167
+ process.stderr.write(`⛔ ${r.message}\n`);
168
+ }
169
+ ecrireSarif({ garde: GARDE, racine, constats: refus });
170
+ process.exitCode = refus.length ? 1 : 0;
171
+ }
@@ -1,32 +1,45 @@
1
- // The join of the languages: the module of language that serves a project, as Pants activates the
2
- // backends its configuration names (`backend_packages`). The core asks it what docs/INTERFACE.md
1
+ // The join of the languages: the modules of language that serve a project, as Pants activates the
2
+ // backends its configuration names (`backend_packages`). The core asks them what docs/INTERFACE.md
3
3
  // writes and scripts/jointure.d.ts types, and imports no other file of a module of language.
4
4
  //
5
- // - A project declares its languages in its package.json, `grillhouse.langages`, a list of names
6
- // of the frame's closed list (`LANGAGES`), each a module under `scripts/langages/<nom>/`. The
7
- // declaration is the only reading: a project that declares none, or a directory without
8
- // package.json, is refused, named, with the command that writes it (`grillhouse maj`).
9
- // - What the update writes is what the modules find in the repository (`langagesTrouves`), as each
10
- // plugin of Nx infers its projects from its own files (`createNodes`): each module answers by
11
- // its `trouve`.
12
- // - One language is served: a declaration of several is refused, each named; a name out of the
13
- // list is refused, the list named.
5
+ // - A project declares the language of each package at its design, in the column « Langage » of
6
+ // the table of the components of its docs/ARCHITECTURE.md (./tableau-des-composants.mjs), as
7
+ // the BUILD file of Bazel names the rule of each target: nothing is guessed from the files. Its
8
+ // languages are the set of that column, in every table that holds it, each a name of the
9
+ // frame's closed list (`LANGAGES`), a module under `scripts/langages/<nom>/`. That column is the only reading (`langagesDeclares`,
10
+ // the one function that reads it): a project that declares none is refused, named, with the
11
+ // column to write. The guard of the languages (./langages-des-paquets.mjs) judges each package
12
+ // against its row.
13
+ // - A project has several languages, a package one, as Bazel and Nx run one list of targets, one
14
+ // tool per language: `langagesDe` gives the declared modules, in the order of the table, and
15
+ // `langageDe` their join (./composition-des-langages.mjs), which gives each file to the module
16
+ // of its component, the module itself when one is declared. A name out of the list is refused,
17
+ // named.
14
18
  // - A module is loaded once per process, synchronously (`require` of an ES module, Node 22): the
15
19
  // locks and the guards ask it in a hook, where nothing waits.
16
- import { readFileSync } from 'node:fs';
17
20
  import { createRequire } from 'node:module';
18
21
  import path from 'node:path';
22
+ import { composer } from './composition-des-langages.mjs';
23
+ import {
24
+ ARCHITECTURE,
25
+ COLONNE,
26
+ langageDeLaCellule,
27
+ tableauxDesComposants,
28
+ } from './tableau-des-composants.mjs';
19
29
 
20
30
  // The frame's languages, each its module, from this directory.
21
31
  export const LANGAGES = {
22
32
  typescript: './langages/typescript/index.mjs',
23
33
  cargo: './langages/cargo/index.mjs',
34
+ python: './langages/python/index.mjs',
24
35
  };
25
36
 
26
37
  const requis = createRequire(import.meta.url);
27
38
  const charges = new Map();
28
39
  const charger = nom => {
29
- if (!charges.has(nom)) {charges.set(nom, requis(LANGAGES[nom]).default);}
40
+ if (!charges.has(nom)) {
41
+ charges.set(nom, requis(LANGAGES[nom]).default);
42
+ }
30
43
  return charges.get(nom);
31
44
  };
32
45
 
@@ -37,49 +50,55 @@ const charger = nom => {
37
50
  */
38
51
  export const langage = nom => charger(nom);
39
52
 
40
- // The languages the project at <racine> declares (`grillhouse.langages` of its package.json), an
41
- // empty list when it declares none.
53
+ /**
54
+ * The languages the project at <racine> declares: the cells of the column « Langage » of the tables
55
+ * of the components of its docs/ARCHITECTURE.md (./tableau-des-composants.mjs), each once, in the
56
+ * order of the document; an empty list without document, table or language.
57
+ * @param {string} racine the root of the project
58
+ * @returns {string[]}
59
+ */
42
60
  export function langagesDeclares(racine) {
43
- let declares;
44
- try {
45
- declares = JSON.parse(readFileSync(path.join(racine, 'package.json'), 'utf8'))?.grillhouse
46
- ?.langages;
47
- } catch {
48
- declares = undefined;
49
- }
50
- return Array.isArray(declares) ? declares.map(String) : [];
51
- }
52
-
53
- // The languages of the frame whose module finds its code in the repository at <racine>, in the
54
- // order of the list.
55
- export function langagesTrouves(racine) {
56
- return Object.keys(LANGAGES).filter(nom => charger(nom).trouve(racine));
61
+ const noms = tableauxDesComposants(racine).flatMap(t =>
62
+ t.lignes.map(l => langageDeLaCellule(l.cellules[t.colonne])).filter(Boolean)
63
+ );
64
+ return [...new Set(noms)];
57
65
  }
58
66
 
59
67
  /**
60
- * The module of the language that serves the project at <racine>. Throws when the project
61
- * declares none, a language out of the frame's list, or several.
68
+ * The modules of the languages the project at <racine> declares, in the order of the table.
69
+ * Throws when it declares none, or a language out of the frame's list.
62
70
  * @param {string} racine the root of the project
63
- * @returns {import('./jointure.js').Langage}
71
+ * @returns {import('./jointure.js').Langage[]}
64
72
  */
65
- export function langageDe(racine) {
73
+ export function langagesDe(racine) {
66
74
  const noms = langagesDeclares(racine);
67
- const fichier = path.join(racine, 'package.json');
75
+ const fichier = path.join(racine, ARCHITECTURE);
68
76
  if (noms.length === 0) {
69
77
  throw new Error(
70
- `⛔ ${fichier} ne déclare aucun langage (grillhouse.langages) ; \`npx grillhouse maj\` l'écrit d'après ce qu'il trouve (les langages du cadre : ${Object.keys(LANGAGES).join(', ')}).`
78
+ `⛔ ${fichier} ne déclare aucun langage : la colonne « ${COLONNE} » de son tableau des composants nomme le langage de chaque paquet (le grill l'écrit, branche 8 ; \`npx grillhouse maj\` y reporte la déclaration d'une version antérieure du cadre ; les langages du cadre : ${Object.keys(LANGAGES).join(', ')}).`
71
79
  );
72
80
  }
73
81
  const inconnus = noms.filter(n => !Object.hasOwn(LANGAGES, n));
74
82
  if (inconnus.length) {
75
83
  throw new Error(
76
- `⛔ langage inconnu du cadre : ${inconnus.join(', ')} (grillhouse.langages de ${fichier}) ; les langages du cadre : ${Object.keys(LANGAGES).join(', ')}.`
84
+ `⛔ langage inconnu du cadre : ${inconnus.join(', ')} (colonne « ${COLONNE} » de ${fichier}) ; les langages du cadre : ${Object.keys(LANGAGES).join(', ')}.`
77
85
  );
78
86
  }
79
- if (noms.length > 1) {
80
- throw new Error(
81
- `⛔ ${noms.join(', ')} : le cadre sert un seul langage par projet (grillhouse.langages de ${fichier}).`
82
- );
87
+ return noms.map(charger);
88
+ }
89
+
90
+ const composes = new Map();
91
+ /**
92
+ * The join of the modules that serve the project at <racine> (`langagesDe`): the module itself
93
+ * when the project declares one, else their composition, built once per list of languages.
94
+ * @param {string} racine the root of the project
95
+ * @returns {import('./jointure.js').Composition}
96
+ */
97
+ export function langageDe(racine) {
98
+ const modules = langagesDe(racine);
99
+ const cle = modules.map(m => m.nom).join('+');
100
+ if (!composes.has(cle)) {
101
+ composes.set(cle, composer(modules));
83
102
  }
84
- return charger(noms[0]);
103
+ return composes.get(cle);
85
104
  }