@nocode-factory/sanity-kit 2.59.0 → 2.60.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.
package/README.md CHANGED
@@ -17,6 +17,20 @@ npm install @nocode-factory/sanity-kit@latest
17
17
  Un `.npmrc` qui envoie `@nocode-factory` vers `npm.pkg.github.com` est un
18
18
  reste d'avant la 2.0.0 (figé en 1.8.0) : le retirer.
19
19
 
20
+ ## Mettre à jour le kit dans un projet
21
+
22
+ Depuis `studio/` :
23
+
24
+ ```bash
25
+ npx ncf-kit upgrade
26
+ ```
27
+
28
+ Installe la dernière version dans `studio/` et `web/`, affiche ce qu'il faut **brancher
29
+ dans le projet** pour chaque version sautée (une mise à jour du kit n'apporte jamais le
30
+ code du projet), puis lance `doctor`. Ensuite : brancher, `npx ncf-kit doctor` (zéro ✖),
31
+ `npm run deploy` dans `studio/`, vérifier sur la préprod. Jamais un `npm install` nu : il
32
+ n'affiche rien.
33
+
20
34
  ## Checklist d'un projet complet
21
35
 
22
36
  | Où | Quoi |
@@ -0,0 +1,64 @@
1
+ // Journal des versions du kit (docs/CHANGELOG.md, recopié dans le paquet à la
2
+ // publication) : chaque version a une rubrique « ### À brancher dans le projet »,
3
+ // ce qu'une mise à jour du kit n'apporte PAS toute seule (code du projet à reprendre
4
+ // du starter). Lu par `npx ncf-kit upgrade` pour l'afficher, et par la CI du kit
5
+ // pour l'exiger. Module pur, sans dépendance ; testé (test/changelog.test.ts).
6
+
7
+ export const WIRING_HEADING = 'À brancher dans le projet'
8
+
9
+ const parseVersion = (v) => {
10
+ const m = String(v ?? '').trim().replace(/^[\^~v]/, '').match(/^(\d+)\.(\d+)\.(\d+)/)
11
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null
12
+ }
13
+
14
+ /** -1, 0 ou 1 ; null si une version est illisible. */
15
+ export function compareVersions(a, b) {
16
+ const x = parseVersion(a)
17
+ const y = parseVersion(b)
18
+ if (!x || !y) return null
19
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1
20
+ return 0
21
+ }
22
+
23
+ /**
24
+ * Entrées du journal : [{version, title, wiring}] dans l'ordre du fichier. `wiring` :
25
+ * texte de la rubrique « À brancher dans le projet » (sans le titre), `null` si la
26
+ * version n'en a pas (anciennes versions).
27
+ */
28
+ export function parseChangelog(text) {
29
+ const entries = []
30
+ let current = null
31
+ let section = null
32
+ for (const line of String(text ?? '').split('\n')) {
33
+ const h2 = line.match(/^## (\d+\.\d+\.\d+)\s*[:—-]?\s*(.*)$/)
34
+ if (h2) {
35
+ current = {version: h2[1], title: h2[2].trim(), wiring: null, lines: []}
36
+ entries.push(current)
37
+ section = null
38
+ continue
39
+ }
40
+ if (!current) continue
41
+ const h3 = line.match(/^### (.+)$/)
42
+ if (h3) {
43
+ section = h3[1].trim()
44
+ if (section === WIRING_HEADING) current.wiring = ''
45
+ continue
46
+ }
47
+ if (section === WIRING_HEADING) current.wiring += `${line}\n`
48
+ }
49
+ return entries.map(({version, title, wiring}) => ({version, title, wiring: wiring === null ? null : wiring.trim()}))
50
+ }
51
+
52
+ /** « Rien », « Rien à brancher », vide : la version n'a rien à brancher. */
53
+ export const isNothing = (wiring) => !wiring || /^[-*\s]*rien\b/i.test(wiring.trim())
54
+
55
+ /**
56
+ * Ce qu'il faut brancher en passant de `from` (exclue) à `to` (incluse), de la plus
57
+ * ancienne à la plus récente, sans les versions qui n'ont rien à brancher.
58
+ */
59
+ export function wiringBetween(entries, from, to) {
60
+ return entries
61
+ .filter((e) => (from ? compareVersions(e.version, from) === 1 : true) && compareVersions(e.version, to) !== 1)
62
+ .filter((e) => e.wiring !== null && !isNothing(e.wiring))
63
+ .sort((a, b) => compareVersions(a.version, b.version))
64
+ }
package/bin/ncf-kit.mjs CHANGED
@@ -34,9 +34,10 @@ const has = (name) => args.includes(`--${name}`)
34
34
  function usage(code = 0) {
35
35
  console.log(`Usage :
36
36
  npx ncf-kit setup --types page,homePage [options] active le projet, clé du journal, webhook
37
+ npx ncf-kit upgrade [--version <v>] met le kit à jour (studio et web) + ce qu'il faut brancher + doctor
37
38
  npx ncf-kit doctor [--web <dossier>] [--offline] vérifie que le projet est complet
38
39
  npx ncf-kit check-environments [--page <chemin>] test prod / préprod, BLOQUANT (postbuild du site)
39
- npx ncf-kit check-deploy [--skip-data] avant sanity deploy : l'appId est bien le Studio de CE projet, alerte _type
40
+ npx ncf-kit check-deploy [--skip-data] [--skip-doctor] avant sanity deploy : appId de CE projet, alerte _type et branchements
40
41
  npx ncf-kit translate-json [--from <langue>] [--apply] textes du site (messages/<langue>.json, titres du registre) traduits par IA
41
42
  npx ncf-kit translations [export] [--out <fichier>] champs « À traduire » → JSON (texte source et actuel)
42
43
  npx ncf-kit translations apply <fichier> écrit les traductions dans les brouillons
@@ -555,6 +556,8 @@ async function doctor() {
555
556
  return false
556
557
  }
557
558
  })()
559
+ if (!usesEditing && existsSync(join(web, 'package.json')))
560
+ warn('Édition sur place', "le kit propose l'édition sur place dans l'aperçu (texte modifié à sa place, « Remplacer cette image », mode édition / visite, kit >= 2.58) ; le site ne la branche pas : reprendre du starter web/components/PreviewEditing.tsx (ncfOverlayComponents + NcfPreviewEditing), web/sanity/fetch.ts (annotateImageEditTargets), web/components/sections/index.tsx (withPreviewEditTargets, rekeyOwnImageTargets, inheritedEditScriptProps), web/components/SanityImage.tsx (imageEditAttributes, imageAlt), les libellés previewEditing, puis déclarer @sanity/visual-editing et @sanity/mutate dans web/package.json et npm dedupe.")
558
561
  if (usesEditing) {
559
562
  const top = read(join(web, 'node_modules', '@sanity', 'visual-editing', 'package.json'))
560
563
  const nested = read(join(web, 'node_modules', 'next-sanity', 'node_modules', '@sanity', 'visual-editing', 'package.json'))
@@ -776,6 +779,50 @@ async function itemTypes() {
776
779
  }
777
780
  }
778
781
 
782
+ /**
783
+ * MISE À JOUR DU KIT : la seule commande à utiliser (pas un `npm install` nu, qui
784
+ * n'affiche rien). Installe la dernière version dans studio/ et web/, affiche pour
785
+ * TOUTES les versions sautées ce qu'il faut brancher dans le projet (rubrique « À
786
+ * brancher dans le projet » du journal), puis lance `doctor --offline`.
787
+ */
788
+ async function upgrade() {
789
+ const studio = resolve(flag('dir') ?? process.cwd())
790
+ const root = dirname(studio)
791
+ if (!existsSync(join(studio, 'package.json'))) fail(`Pas de package.json dans ${studio} : lance la commande depuis le dossier du studio, ou passe --dir.`)
792
+ const web = resolve(flag('web') ?? [join(root, 'web'), join(root, 'frontend')].find((d) => existsSync(join(d, 'package.json'))) ?? join(root, 'web'))
793
+ const installedVersion = () => {
794
+ const pkg = [studio, root].map((d) => read(join(d, 'node_modules', PKG, 'package.json'))).find(Boolean)
795
+ return pkg ? JSON.parse(pkg).version : null
796
+ }
797
+ const from = installedVersion()
798
+ const target = flag('version') ?? 'latest'
799
+ const {spawnSync} = await import('node:child_process')
800
+ for (const dir of [studio, web]) {
801
+ if (!new RegExp(`"${PKG.replace('/', '\\/')}"\\s*:`).test(read(join(dir, 'package.json')))) continue
802
+ console.log(`\n• ${dir.replace(root + '/', '')} : npm install ${PKG}@${target}`)
803
+ const r = spawnSync('npm', ['install', '--no-audit', '--no-fund', `${PKG}@${target}`], {cwd: dir, stdio: 'inherit'})
804
+ if (r.status !== 0) fail(`npm install a échoué dans ${dir}.`)
805
+ }
806
+ const to = installedVersion()
807
+ console.log(`\n✔ Kit : ${from ?? 'non installé'} → ${to}`)
808
+
809
+ const {parseChangelog, wiringBetween} = await import('./changelog.mjs')
810
+ const changelog = read(join(studio, 'node_modules', PKG, 'CHANGELOG.md')) || read(join(root, 'node_modules', PKG, 'CHANGELOG.md'))
811
+ if (!changelog) console.log('⚠ Journal des versions absent du paquet : voir docs/CHANGELOG.md du dépôt du kit.')
812
+ else {
813
+ const todo = wiringBetween(parseChangelog(changelog), from, to)
814
+ if (!todo.length) console.log('✔ À brancher dans le projet : rien pour ces versions.')
815
+ else {
816
+ console.log(`\n⚠ À BRANCHER DANS LE PROJET (une mise à jour du kit ne l'apporte pas toute seule) :`)
817
+ for (const e of todo) console.log(`\n ${e.version} : ${e.title}\n${e.wiring.split('\n').map((l) => ` ${l}`).join('\n')}`)
818
+ }
819
+ }
820
+
821
+ console.log('\n• Contrôle du projet (doctor --offline) :')
822
+ spawnSync(process.execPath, [new URL(import.meta.url).pathname, 'doctor', '--offline', '--dir', studio, '--web', web], {stdio: 'inherit'})
823
+ console.log('\nEnsuite : brancher ce qui est listé, `npx ncf-kit doctor` (zéro ✖), redéployer le Studio (`npm run deploy` dans studio/), vérifier sur la préprod, committer.')
824
+ }
825
+
779
826
  async function translations() {
780
827
  const sub = args[1] && !args[1].startsWith('--') ? args[1] : 'export'
781
828
  const dir = resolve(flag('dir') ?? process.cwd())
@@ -1040,18 +1087,31 @@ if (command === 'setup') {
1040
1087
  // planterait en les ouvrant). ALERTE seulement : un déploiement livre du code, il
1041
1088
  // ne réécrit jamais des données sans qu'on le voie ; la correction reste un geste
1042
1089
  // volontaire (npx ncf-kit item-types --apply). `--skip-data` pour la sauter.
1043
- if (has('skip-data')) return
1044
- const scan = await scanItemTypes(resolve(flag('dir') ?? process.cwd()), {quiet: true}).catch(() => null)
1045
- if (!scan) console.log('⚠ Éléments de liste typés : non vérifié (jeton Sanity ou `sanity schema extract` indisponible).')
1046
- else if (scan.count)
1047
- console.log(
1048
- `⚠ Éléments de liste typés : ${scan.count} élément(s) sans _type dans ${scan.todo.length} document(s) : le formulaire du Studio plantera en les ouvrant. Corriger : npx ncf-kit item-types (liste), puis --apply. Le déploiement continue.`,
1049
- )
1050
- else console.log(`✔ Éléments de liste typés : aucun écart (${scan.docs} documents).`)
1090
+ if (!has('skip-data')) {
1091
+ const scan = await scanItemTypes(resolve(flag('dir') ?? process.cwd()), {quiet: true}).catch(() => null)
1092
+ if (!scan) console.log('⚠ Éléments de liste typés : non vérifié (jeton Sanity ou `sanity schema extract` indisponible).')
1093
+ else if (scan.count)
1094
+ console.log(
1095
+ `⚠ Éléments de liste typés : ${scan.count} élément(s) sans _type dans ${scan.todo.length} document(s) : le formulaire du Studio plantera en les ouvrant. Corriger : npx ncf-kit item-types (liste), puis --apply. Le déploiement continue.`,
1096
+ )
1097
+ else console.log(`✔ Éléments de liste typés : aucun écart (${scan.docs} documents).`)
1098
+ }
1099
+ // Ce que le kit attend du projet et qui manque (branchements d'une version
1100
+ // installée sans les reprendre du starter) : affiché ici, au passage obligé pour
1101
+ // qu'une nouvelle version arrive en ligne. Informatif, le déploiement continue.
1102
+ if (has('skip-doctor')) return
1103
+ const {spawnSync} = await import('node:child_process')
1104
+ const studioDir = resolve(flag('dir') ?? process.cwd())
1105
+ const out = spawnSync(process.execPath, [new URL(import.meta.url).pathname, 'doctor', '--offline', '--dir', studioDir], {encoding: 'utf8'})
1106
+ const issues = String(out.stdout ?? '').split('\n').filter((l) => /^\s*[✖⚠]/.test(l))
1107
+ if (issues.length) console.log(`⚠ Branchements du kit à reprendre (npx ncf-kit doctor) :\n${issues.map((l) => ` ${l.trim()}`).join('\n')}`)
1108
+ else console.log('✔ Branchements du kit : complets (doctor --offline).')
1051
1109
  })
1052
1110
  .catch((error) => fail(error?.message ?? String(error)))
1053
1111
  } else if (command === 'translate-json') {
1054
1112
  translateJson().catch((error) => fail(error?.message ?? String(error)))
1113
+ } else if (command === 'upgrade') {
1114
+ upgrade().catch((error) => fail(error?.message ?? String(error)))
1055
1115
  } else if (command === 'item-types') {
1056
1116
  itemTypes().catch((error) => fail(error?.message ?? String(error)))
1057
1117
  } else if (command === 'translations') {
package/dist/index.d.ts CHANGED
@@ -1427,7 +1427,7 @@ export declare function ActorName(props: {
1427
1427
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1428
1428
  * le vérifie.
1429
1429
  */
1430
- export declare const KIT_VERSION = "2.59.0";
1430
+ export declare const KIT_VERSION = "2.60.0";
1431
1431
  /**
1432
1432
  * Données de la page proposées comme colonnes.
1433
1433
  *
package/dist/index.js CHANGED
@@ -1423,7 +1423,7 @@ function explainGrantError(error) {
1423
1423
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1424
1424
  * le vérifie.
1425
1425
  */
1426
- const KIT_VERSION = "2.59.0";
1426
+ const KIT_VERSION = "2.60.0";
1427
1427
  /**
1428
1428
  * Signale ce Studio au service du kit, une fois par montage.
1429
1429
  *
@@ -1921,7 +1921,7 @@ function useKitUpdate() {
1921
1921
  !controller.signal.aborted && body?.version && setLatest(body.version);
1922
1922
  }).catch(() => {}), () => controller.abort();
1923
1923
  }, []);
1924
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.59.0") > 0);
1924
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.60.0") > 0);
1925
1925
  return {
1926
1926
  current: KIT_VERSION,
1927
1927
  latest,