Files
Talks/tools/build-deck.mjs
Le Prévost-Corvellec Arnault 354c8cd9ef Add Makefile, package.json, and initial configuration for VitePress and Slidev integration
- Introduced a Makefile for streamlined commands related to building, running, and managing presentations.
- Created package.json to define project metadata, dependencies, and scripts for development and testing.
- Added .gitignore entries to exclude build artifacts and temporary files from version control.
- Included playwright.config.mjs for end-to-end testing setup with Playwright.
- Added README.md for project documentation, outlining setup instructions and development guidelines.
2026-04-11 15:59:20 +02:00

70 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Build Slidev pour un slug → dossier dist-<slug>/ à la racine du dépôt.
* Usage : node tools/build-deck.mjs <slug>
*/
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { execFileSync } from 'node:child_process'
import { sitePath } from './site-base.mjs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const root = path.resolve(__dirname, '..')
function publishBuild(wipDir, finalDir) {
fs.mkdirSync(finalDir, { recursive: true })
fs.cpSync(wipDir, finalDir, { recursive: true, force: true })
fs.rmSync(wipDir, { recursive: true, force: true })
}
function slidevBin() {
const p = path.join(root, 'node_modules', '.bin', 'slidev')
if (fs.existsSync(p)) return p
return 'slidev'
}
const slug = process.argv[2]
if (!slug || slug.startsWith('wip_')) {
console.error('usage: node tools/build-deck.mjs <slug>')
process.exit(1)
}
const entry = path.join(root, 'slides', slug, 'slides.md')
const metaPath = path.join(root, 'slides', slug, 'meta.json')
if (!fs.existsSync(entry) || !fs.existsSync(metaPath)) {
console.error(`[build-deck] slides/${slug}/ incomplet (slides.md + meta.json requis)`)
process.exit(1)
}
const finalDir = path.join(root, `dist-${slug}`)
const wipDir = path.join(root, '.slide-wip', slug)
const base = sitePath(`/slides/${slug}/`)
if (!base.endsWith('/')) throw new Error(`base invalide: ${base}`)
fs.rmSync(wipDir, { recursive: true, force: true })
fs.mkdirSync(wipDir, { recursive: true })
/* Ne pas supprimer slides/<slug>/index.html avant le build : Slidev s’attend à pouvoir unlink ce fichier en fin de build. */
console.log(`[build-deck] ${slug} → dist-${slug}/ (base=${base})`)
try {
execFileSync(
slidevBin(),
['build', entry, '--out', wipDir, '--base', base],
{ stdio: 'inherit', cwd: root, env: process.env },
)
publishBuild(wipDir, finalDir)
/* Slidev peut écrire un index.html à côté de slides.md — inutile et bruyant au build suivant */
try {
fs.rmSync(path.join(root, 'slides', slug, 'index.html'), { force: true })
} catch {
/* ignore */
}
} catch (e) {
try {
fs.rmSync(wipDir, { recursive: true, force: true })
} catch {
/* ignore */
}
process.exit(1)
}