@nocode-factory/sanity-kit 2.5.0 → 2.6.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 +43 -0
- package/bin/ncf-kit.mjs +165 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/version.ts +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @nocode-factory/sanity-kit
|
|
2
|
+
|
|
3
|
+
Outils Sanity Studio de NoCode Factory : **Pages** (liste + board), **Composants**,
|
|
4
|
+
**Historique**, aperçu multi-environnements et partage de préversion. Plus, côté
|
|
5
|
+
site Next.js : garde de préproduction, bascule brouillons / en ligne, bandeau.
|
|
6
|
+
|
|
7
|
+
## Installer
|
|
8
|
+
|
|
9
|
+
Public sur npmjs, sans jeton. Dans le studio **et** dans le site :
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @nocode-factory/sanity-kit@latest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Un `.npmrc` qui envoie `@nocode-factory` vers `npm.pkg.github.com` est un
|
|
16
|
+
reste d'avant la 2.0.0 (figé en 1.8.0) : le retirer.
|
|
17
|
+
|
|
18
|
+
## Checklist d'un projet complet
|
|
19
|
+
|
|
20
|
+
| Où | Quoi |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `studio/sanity.config.ts` | `ncfKit(options)` ; `presentationTool({allowOrigins: ncfAllowedOrigins(options), …})` |
|
|
23
|
+
| `studio/.env` (+ `.env.production.local`) | `SANITY_STUDIO_PREVIEW_URL` = site en ligne, `SANITY_STUDIO_PREVIEW_URL_PREPROD` = `https://preview-<projet>.vercel.app`, `SANITY_STUDIO_NCF_PROJECT_KEY` |
|
|
24
|
+
| Vercel | domaine fixe `preview-<projet>.vercel.app` assigné à la branche `preprod` ; pas de Vercel Authentication sur les préversions (la garde du kit gère l'accès) |
|
|
25
|
+
| `web/proxy.ts` | `const guarded = await ncfPreviewGuard(req); if (guarded) return guarded` |
|
|
26
|
+
| `web/app/api/draft-mode/toggle/route.ts` | `export const {GET} = ncfDraftModeToggle()` |
|
|
27
|
+
| layout racine du site | `{isPreviewSite() && <NcfPreviewBanner isDraft={isDraft} />}` |
|
|
28
|
+
| `.github/workflows/` | captures `public/sections/<bloc>.png` (workflow du starter) |
|
|
29
|
+
| Studio | `npx ncf-kit setup --types <types de pages>` (journal), puis `npx sanity deploy` |
|
|
30
|
+
|
|
31
|
+
Puis, depuis `studio/` :
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx ncf-kit doctor
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Zéro ✖ = projet complet. Sortie 1 sinon (utilisable en CI).
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
Dans le dépôt `nocode-factory/ncf-sanity-kit` : `docs/INSTALL.md` (options),
|
|
42
|
+
`docs/NOUVEAU-PROJET.md` (prompt d'installation), `docs/CHANGELOG.md`. Le
|
|
43
|
+
starter `nocode-factory/sanity-next-starter` est déjà câblé de bout en bout.
|
package/bin/ncf-kit.mjs
CHANGED
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
// 3. crée le webhook du journal via l'API de gestion Sanity, avec la bonne
|
|
8
8
|
// forme (brouillons inclus, projection, secret), sans jamais supprimer un
|
|
9
9
|
// webhook existant : au quota, elle s'arrête et le dit.
|
|
10
|
+
//
|
|
11
|
+
// Et `npx ncf-kit doctor` : vérifie qu'un projet est complet (registre, version,
|
|
12
|
+
// préproduction, bandeau, garde, captures) et dit quoi corriger.
|
|
10
13
|
// Aucune dépendance : Node 22 suffit.
|
|
11
|
-
import {readFileSync, writeFileSync, existsSync} from 'node:fs'
|
|
12
|
-
import {join, resolve} from 'node:path'
|
|
14
|
+
import {readFileSync, writeFileSync, existsSync, readdirSync, statSync} from 'node:fs'
|
|
15
|
+
import {dirname, join, resolve} from 'node:path'
|
|
13
16
|
import {homedir} from 'node:os'
|
|
14
17
|
|
|
15
18
|
const DEFAULT_ENDPOINT = 'https://dkoxgivytgsmvqmjvmjt.supabase.co/functions/v1'
|
|
@@ -27,11 +30,17 @@ const flag = (name) => {
|
|
|
27
30
|
const has = (name) => args.includes(`--${name}`)
|
|
28
31
|
|
|
29
32
|
function usage(code = 0) {
|
|
30
|
-
console.log(`Usage :
|
|
33
|
+
console.log(`Usage :
|
|
34
|
+
npx ncf-kit setup --types page,homePage [options] active le projet, clé du journal, webhook
|
|
35
|
+
npx ncf-kit doctor [--web <dossier>] [--offline] vérifie que le projet est complet
|
|
31
36
|
|
|
32
37
|
Depuis le dossier du studio (celui de sanity.config.ts et de .env).
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
doctor :
|
|
40
|
+
--web <chemin> Dossier du site Next.js (défaut : ../web, sinon ../frontend).
|
|
41
|
+
--offline Saute les vérifications en ligne (site, préproduction, npm).
|
|
42
|
+
|
|
43
|
+
Options de setup :
|
|
35
44
|
--types <a,b> Types de documents journalisés (obligatoire) : les types de pages.
|
|
36
45
|
--name <nom> Nom du client dans le registre (défaut : nom du projet Sanity).
|
|
37
46
|
--dir <chemin> Dossier du studio (défaut : dossier courant).
|
|
@@ -191,8 +200,160 @@ Reste à faire :
|
|
|
191
200
|
Le journal part de maintenant : rien n'est reconstitué en arrière.`)
|
|
192
201
|
}
|
|
193
202
|
|
|
203
|
+
/* ------------------------------------------------------------------------ */
|
|
204
|
+
/* doctor : un projet est-il complet ? */
|
|
205
|
+
/* ------------------------------------------------------------------------ */
|
|
206
|
+
|
|
207
|
+
const PKG = '@nocode-factory/sanity-kit'
|
|
208
|
+
|
|
209
|
+
/** Fichiers texte d'un dossier, sans node_modules ni sorties de build. */
|
|
210
|
+
function walk(dir, out = [], depth = 0) {
|
|
211
|
+
if (!existsSync(dir) || depth > 8) return out
|
|
212
|
+
for (const name of readdirSync(dir)) {
|
|
213
|
+
if (['node_modules', '.next', 'dist', '.git', '.sanity', '.vercel', 'out'].includes(name)) continue
|
|
214
|
+
const path = join(dir, name)
|
|
215
|
+
const stat = statSync(path)
|
|
216
|
+
if (stat.isDirectory()) walk(path, out, depth + 1)
|
|
217
|
+
else if (/\.(m?[jt]sx?|json|ya?ml)$/.test(name)) out.push(path)
|
|
218
|
+
}
|
|
219
|
+
return out
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const read = (file) => (existsSync(file) ? readFileSync(file, 'utf8') : '')
|
|
223
|
+
const findUsage = (files, needle) => files.find((f) => read(f).includes(needle))
|
|
224
|
+
|
|
225
|
+
async function probe(url, init = {}) {
|
|
226
|
+
try {
|
|
227
|
+
const response = await fetch(url, {redirect: 'manual', ...init, signal: AbortSignal.timeout(15000)})
|
|
228
|
+
const body = response.status === 401 ? await response.text() : ''
|
|
229
|
+
return {status: response.status, headers: response.headers, body}
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return {status: 0, error: error?.message ?? String(error)}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function deducedPreprod(previewUrl) {
|
|
236
|
+
try {
|
|
237
|
+
const {protocol, hostname} = new URL(previewUrl)
|
|
238
|
+
if (!hostname.endsWith('.vercel.app')) return null
|
|
239
|
+
return `${protocol}//preview-${hostname}`
|
|
240
|
+
} catch {
|
|
241
|
+
return null
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function doctor() {
|
|
246
|
+
const studio = resolve(flag('dir') ?? process.cwd())
|
|
247
|
+
const root = dirname(studio)
|
|
248
|
+
const offline = has('offline')
|
|
249
|
+
const web = resolve(flag('web') ?? [join(root, 'web'), join(root, 'frontend')].find((d) => existsSync(join(d, 'package.json'))) ?? join(root, 'web'))
|
|
250
|
+
|
|
251
|
+
const results = []
|
|
252
|
+
const ok = (label, detail) => results.push({level: 'ok', label, detail})
|
|
253
|
+
const warn = (label, detail) => results.push({level: 'warn', label, detail})
|
|
254
|
+
const ko = (label, detail) => results.push({level: 'ko', label, detail})
|
|
255
|
+
|
|
256
|
+
if (!existsSync(join(studio, 'package.json'))) fail(`Pas de package.json dans ${studio} : lance doctor depuis le dossier du studio, ou passe --dir.`)
|
|
257
|
+
const env = {
|
|
258
|
+
...parseEnv(read(join(studio, '.env'))),
|
|
259
|
+
...parseEnv(read(join(studio, '.env.production.local'))), // prioritaire au déploiement
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Registre : le kit est sur npmjs depuis la 2.0.0 */
|
|
263
|
+
const npmrcs = [join(studio, '.npmrc'), join(web, '.npmrc'), join(root, '.npmrc')]
|
|
264
|
+
const stale = npmrcs.find((f) => /@nocode-factory:registry\s*=\s*https:\/\/npm\.pkg\.github\.com/.test(read(f)))
|
|
265
|
+
if (stale) ko('Registre', `${stale.replace(root + '/', '')} envoie @nocode-factory vers GitHub Packages, figé en 1.8.0 et qui exige un jeton. Le kit est public sur npmjs depuis la 2.0.0 : retirer ces lignes, puis réinstaller.`)
|
|
266
|
+
else ok('Registre', 'npmjs (public, sans jeton)')
|
|
267
|
+
|
|
268
|
+
/* Version installée */
|
|
269
|
+
const installed = [studio, root].map((d) => read(join(d, 'node_modules', PKG, 'package.json'))).find(Boolean)
|
|
270
|
+
const version = installed ? JSON.parse(installed).version : null
|
|
271
|
+
let latest = null
|
|
272
|
+
if (!offline) {
|
|
273
|
+
const r = await probe(`https://registry.npmjs.org/${PKG}/latest`)
|
|
274
|
+
if (r.status === 200) latest = (await (await fetch(`https://registry.npmjs.org/${PKG}/latest`)).json()).version
|
|
275
|
+
}
|
|
276
|
+
if (!version) ko('Version du kit', 'non installé dans le studio')
|
|
277
|
+
else if (latest && version !== latest) warn('Version du kit', `${version} installée, ${latest} disponible : npm install ${PKG}@latest (studio et site)`)
|
|
278
|
+
else ok('Version du kit', version)
|
|
279
|
+
|
|
280
|
+
/* Studio : URLs et clés */
|
|
281
|
+
const previewUrl = env.SANITY_STUDIO_PREVIEW_URL
|
|
282
|
+
if (!previewUrl) ko('Aperçu (Presentation)', 'SANITY_STUDIO_PREVIEW_URL absent : le Studio en ligne ne saura pas quel site afficher.')
|
|
283
|
+
else if (/localhost|127\.0\.0\.1/.test(previewUrl)) warn('Aperçu (Presentation)', `${previewUrl} : valable en local seulement. Avant \`sanity deploy\`, mettre l'URL du site en ligne (studio/.env.production.local).`)
|
|
284
|
+
else ok('Aperçu (Presentation)', previewUrl)
|
|
285
|
+
|
|
286
|
+
const preprod = env.SANITY_STUDIO_PREVIEW_URL_PREPROD || (previewUrl ? deducedPreprod(previewUrl) : null)
|
|
287
|
+
if (!env.SANITY_STUDIO_PREVIEW_URL_PREPROD) ko('Préproduction', `SANITY_STUDIO_PREVIEW_URL_PREPROD absent${preprod ? ` (déduite : ${preprod})` : ''}. Vercel → Settings → Domains : preview-<projet>.vercel.app sur la branche \`preprod\`, puis le recopier dans studio/.env.`)
|
|
288
|
+
else ok('Préproduction', env.SANITY_STUDIO_PREVIEW_URL_PREPROD)
|
|
289
|
+
|
|
290
|
+
if (!env.SANITY_STUDIO_NCF_PROJECT_KEY) ko('Historique', 'SANITY_STUDIO_NCF_PROJECT_KEY absent : lancer `npx ncf-kit setup --types …`.')
|
|
291
|
+
else ok('Historique', 'clé du journal présente')
|
|
292
|
+
|
|
293
|
+
const config = ['sanity.config.ts', 'sanity.config.tsx', 'sanity.config.js'].map((f) => read(join(studio, f))).find(Boolean) ?? ''
|
|
294
|
+
if (!config.includes('ncfKit(')) ko('Plugin', 'ncfKit(...) absent de sanity.config')
|
|
295
|
+
else ok('Plugin', 'ncfKit branché')
|
|
296
|
+
if (!config.includes('ncfAllowedOrigins')) ko('Origines autorisées', "presentationTool sans allowOrigins: ncfAllowedOrigins(options) : l'aperçu de la préproduction s'affiche mais reste muet.")
|
|
297
|
+
else ok('Origines autorisées', 'ncfAllowedOrigins')
|
|
298
|
+
if (/preprodUrl\s*:\s*false/.test(config)) ko('Préproduction désactivée', "sanity.config contient preprodUrl: false : la préproduction conventionnelle est retirée. À n'utiliser que si le projet n'en a vraiment pas.")
|
|
299
|
+
if (/as\s+NcfKitConfig/.test(config)) warn('Typage', 'sanity.config force le type (as NcfKitConfig) : une option inconnue ou mal écrite passerait inaperçue.')
|
|
300
|
+
|
|
301
|
+
/* Site */
|
|
302
|
+
const webPkg = read(join(web, 'package.json'))
|
|
303
|
+
if (!webPkg) warn('Site', `aucun site trouvé (${web}) : passer --web <dossier>.`)
|
|
304
|
+
else {
|
|
305
|
+
const files = walk(web).filter((f) => !f.endsWith('package.json') && !f.endsWith('package-lock.json'))
|
|
306
|
+
if (!webPkg.includes(PKG)) ko('Kit côté site', `${PKG} absent de ${web.replace(root + '/', '')}/package.json (bandeau, bascule et garde en dépendent).`)
|
|
307
|
+
else ok('Kit côté site', 'installé')
|
|
308
|
+
const banner = findUsage(files, 'NcfPreviewBanner')
|
|
309
|
+
banner ? ok('Bandeau de préversion', banner.replace(root + '/', '')) : ko('Bandeau de préversion', "NcfPreviewBanner absent du layout : {isPreviewSite() && <NcfPreviewBanner isDraft={isDraft} />}")
|
|
310
|
+
const toggle = findUsage(files, 'ncfDraftModeToggle')
|
|
311
|
+
toggle ? ok('Bascule brouillons', toggle.replace(root + '/', '')) : ko('Bascule brouillons', 'app/api/draft-mode/toggle/route.ts : export const {GET} = ncfDraftModeToggle()')
|
|
312
|
+
const guard = findUsage(files, 'ncfPreviewGuard')
|
|
313
|
+
guard ? ok('Garde de préproduction', guard.replace(root + '/', '')) : ko('Garde de préproduction', 'ncfPreviewGuard absent de proxy.ts (ou middleware.ts) : la préproduction serait publique.')
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/* Captures des composants */
|
|
317
|
+
const workflows = walk(join(root, '.github', 'workflows'))
|
|
318
|
+
const captures = workflows.find((f) => /public\/sections/.test(read(f)))
|
|
319
|
+
captures ? ok('Captures des composants', captures.replace(root + '/', '')) : warn('Captures des composants', "aucun workflow ne produit public/sections/<bloc>.png : l'onglet Composants affichera « Pas de capture ». Reprendre .github/workflows/section-screenshots.yml du starter.")
|
|
320
|
+
|
|
321
|
+
/* En ligne */
|
|
322
|
+
if (!offline) {
|
|
323
|
+
if (previewUrl && !/localhost/.test(previewUrl)) {
|
|
324
|
+
const r = await probe(previewUrl)
|
|
325
|
+
r.status && r.status < 500 ? ok('Site en ligne', `${previewUrl} répond (${r.status})`) : ko('Site en ligne', `${previewUrl} : ${r.error ?? r.status}`)
|
|
326
|
+
}
|
|
327
|
+
if (preprod) {
|
|
328
|
+
const r = await probe(preprod)
|
|
329
|
+
// Vercel Authentication : redirection vers vercel.com/sso-api, ou 401 « Vercel Authentication ».
|
|
330
|
+
const location = r.headers?.get('location') ?? ''
|
|
331
|
+
const vercelAuth = (r.status >= 300 && r.status < 400 && /vercel\.com\/sso/.test(location)) || (r.status === 401 && /vercel authentication/i.test(r.body))
|
|
332
|
+
if (!r.status) ko('Préproduction en ligne', `${preprod} injoignable (${r.error}) : domaine non créé, ou branche \`preprod\` jamais poussée.`)
|
|
333
|
+
else if (r.status === 404) ko('Préproduction en ligne', `${preprod} : 404, domaine non assigné à la branche \`preprod\`.`)
|
|
334
|
+
else if (vercelAuth) ko('Préproduction en ligne', `${preprod} demande une connexion Vercel (Vercel Authentication) : le lien « Partager la préversion » et l'aperçu du Studio tombent sur la connexion Vercel. Vercel → Settings → Deployment Protection : la désactiver pour les préversions, la garde du kit gère l'accès.`)
|
|
335
|
+
else if (r.status === 401) ok('Préproduction en ligne', `${preprod} protégée par la garde du kit (401 sans laissez-passer)`)
|
|
336
|
+
else if (r.status < 500) {
|
|
337
|
+
const noindex = /noindex/i.test(r.headers.get('x-robots-tag') ?? '')
|
|
338
|
+
noindex ? ok('Préproduction en ligne', `${preprod} répond (${r.status}), noindex`) : warn('Préproduction en ligne', `${preprod} répond (${r.status}) sans garde ni noindex : elle est publique.`)
|
|
339
|
+
} else ko('Préproduction en ligne', `${preprod} : erreur ${r.status}`)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* Rapport */
|
|
344
|
+
const icon = {ok: '✔', warn: '⚠', ko: '✖'}
|
|
345
|
+
console.log(`\nNCF Kit — diagnostic de ${root}\n`)
|
|
346
|
+
for (const r of results) console.log(`${icon[r.level]} ${r.label}${r.detail ? ` : ${r.detail}` : ''}`)
|
|
347
|
+
const kos = results.filter((r) => r.level === 'ko').length
|
|
348
|
+
const warns = results.filter((r) => r.level === 'warn').length
|
|
349
|
+
console.log(`\n${kos ? `${kos} point(s) à corriger` : 'Rien de bloquant'}${warns ? `, ${warns} avertissement(s)` : ''}.`)
|
|
350
|
+
process.exit(kos ? 1 : 0)
|
|
351
|
+
}
|
|
352
|
+
|
|
194
353
|
if (command === 'setup') {
|
|
195
354
|
setup().catch((error) => fail(error?.message ?? String(error)))
|
|
355
|
+
} else if (command === 'doctor') {
|
|
356
|
+
doctor().catch((error) => fail(error?.message ?? String(error)))
|
|
196
357
|
} else if (!command || command === 'help' || has('help')) {
|
|
197
358
|
usage(command ? 0 : 1)
|
|
198
359
|
} else {
|
package/dist/index.d.ts
CHANGED
|
@@ -1270,7 +1270,7 @@ export declare function ActorName(props: {
|
|
|
1270
1270
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1271
1271
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1272
1272
|
*/
|
|
1273
|
-
export declare const KIT_VERSION = "2.
|
|
1273
|
+
export declare const KIT_VERSION = "2.6.0";
|
|
1274
1274
|
/**
|
|
1275
1275
|
* Données de la page proposées comme colonnes.
|
|
1276
1276
|
*
|
package/dist/index.js
CHANGED
|
@@ -1287,7 +1287,7 @@ function explainGrantError(error) {
|
|
|
1287
1287
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1288
1288
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1289
1289
|
*/
|
|
1290
|
-
const KIT_VERSION = "2.
|
|
1290
|
+
const KIT_VERSION = "2.6.0";
|
|
1291
1291
|
/**
|
|
1292
1292
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1293
1293
|
*
|
|
@@ -1539,7 +1539,7 @@ function useKitUpdate() {
|
|
|
1539
1539
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1540
1540
|
}).catch(() => {}), () => controller.abort();
|
|
1541
1541
|
}, []);
|
|
1542
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1542
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.6.0") > 0);
|
|
1543
1543
|
return {
|
|
1544
1544
|
current: KIT_VERSION,
|
|
1545
1545
|
latest,
|