Files
faunosteo/scripts/scaffold-species.mjs
Bastien ChanotandClaude Opus 4.7 7dd4f633f8 chore: rename project from osteo-report to zoosteo
Remote moved to git.bchanot.fr/bchanot/zoosteo.git; brand strings
and production URL updated to match new identity.

- package.json: name → zoosteo
- src/config/env.ts: AppConfig DEFAULTS → "Zoosteo"
- docker/entrypoint.sh: APP_*_NAME fallbacks → "Zoosteo"
- src/i18n/{fr,en}.ts: import error message + PDF title prefix
- src/pdf/attachment.ts: embedded description metadata "state v2"
- index.html: <title> fallback
- scripts/scaffold-species.mjs: console banner
- tests/unit/components.Brand.test.tsx: regex
- README.md, CLAUDE.md, CHANGELOG.md, docs/ADDING-A-SPECIES.md:
  brand headings + intro lines
- DEPLOY.md: env defaults table + osteo.example.com → zoosteo.fr
  (clone URL, paths, certbot, curl, container name references)

PDF attachment FILENAME 'osteo-report.json' and the startsWith
contract in src/pdf/attachment.ts:35,40 are preserved — changing
them would break PDF import for every PDF already exported by the
app. docs/superpowers/** and .claude/audits/** left unchanged as
historical records.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 05:53:12 +02:00

236 lines
7.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Scaffolds a new species: prompts for the few required values then
* writes the boilerplate that the auto-discovery registry expects.
*
* Run via: pnpm scaffold:species
* or: node scripts/scaffold-species.mjs
*
* The script never touches existing files — it refuses to write if any
* of the targets already exist, so you can rerun it after fixing typos
* without losing work. SVG assets are NOT created; drop them in
* `public/species/<assetFolder>/` yourself after the script finishes.
*/
import { existsSync } from 'node:fs'
import { mkdir, writeFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import readline from 'node:readline/promises'
import { stdin as input, stdout as output } from 'node:process'
const HERE = dirname(fileURLToPath(import.meta.url))
const PROJECT_ROOT = resolve(HERE, '..')
const rl = readline.createInterface({ input, output })
async function ask(question, fallback) {
const suffix = fallback === undefined ? '' : ` [${fallback}]`
const raw = (await rl.question(`${question}${suffix}: `)).trim()
return raw || (fallback ?? '')
}
async function askRequired(question, validate) {
while (true) {
const v = (await rl.question(`${question}: `)).trim()
if (!v) {
console.log(' (required)')
continue
}
if (validate) {
const err = validate(v)
if (err) {
console.log(` ${err}`)
continue
}
}
return v
}
}
async function askPositiveInt(question, fallback) {
while (true) {
const v = await ask(question, String(fallback))
const n = Number(v)
if (Number.isInteger(n) && n > 0) return n
console.log(' enter a positive integer')
}
}
function isKebab(s) {
return /^[a-z][a-z0-9-]*$/.test(s)
}
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1)
}
function indexTs({ id, labelFr, mainSvgPath, details, formulaConstName }) {
const detailLines = details
.map((d) => ` ${d.key}: '${d.path}',`)
.join('\n')
return `import type { SpeciesManifest } from '@/domain/species/types'
import { ${formulaConstName} } from './vertebrae'
export const ${id}: SpeciesManifest = {
id: '${id}',
labelFr: '${labelFr.replace(/'/g, "\\'")}',
mainSvg: '${mainSvgPath}',
details: {
${detailLines}
},
vertebralFormula: ${formulaConstName},
findings: () => import('./pathologies'),
}
export default ${id}
`
}
function vertebraeTs({ formulaConstName, labelFr, formula }) {
return `import type { VertebralFormula } from '@/domain/species/types'
/** Vertebral formula for ${labelFr}. Adjust to species-specific anatomy. */
export const ${formulaConstName}: VertebralFormula = {
C: ${formula.C},
T: ${formula.T},
L: ${formula.L},
S: ${formula.S},
Cd: ${formula.Cd},
}
`
}
function pathologiesTs() {
return `import {
SpeciesFindingsSchema,
type SpeciesFindings,
} from '@/domain/schema/findings'
import data from './pathologies.json'
const FINDINGS: SpeciesFindings = SpeciesFindingsSchema.parse(data)
export default FINDINGS
`
}
function pathologiesJsonTemplate({ id, labelFr, labelEn }) {
return JSON.stringify(
{
schema_version: '1.1',
scope_disclaimer:
"Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire.",
species: {
id,
name_fr: labelFr,
name_en: labelEn,
},
zones: {},
},
null,
2,
)
}
async function collectDetails() {
const details = []
console.log('\nDetail popup SVGs (optional — leave key blank to stop).')
console.log(' Each "key" must match a data-anno-opens-detail value on a hitbox in the main SVG.')
for (;;) {
const key = (await rl.question(' detail key (e.g. head, patte): ')).trim()
if (!key) return details
if (!isKebab(key)) {
console.log(' → key must be kebab-case (lowercase, hyphen-separated). Try again.')
continue
}
const path = await askRequired(
` detail SVG path for "${key}" (e.g. /species/canine/Dog_head.svg)`,
(v) => (v.startsWith('/species/') ? '' : ' path must start with /species/'),
)
details.push({ key, path })
}
}
async function main() {
console.log('\nZoosteo — new species scaffold')
console.log('-----------------------------------\n')
const id = await askRequired(
'species id (kebab-case, e.g. canine, feline, bovine)',
(v) => (isKebab(v) ? '' : 'must be kebab-case (lowercase letters / digits / hyphens; start with a letter)'),
)
const labelFr = await askRequired('display label (FR), e.g. "Chien"')
const labelEn = await ask('display label (EN), e.g. "Dog"', capitalize(id))
const assetFolder = await ask(
'public asset folder under /species/',
id,
)
const mainSvgFile = await askRequired(
`main SVG filename in /public/species/${assetFolder}/ (e.g. Dog.svg)`,
)
const mainSvgPath = `/species/${assetFolder}/${mainSvgFile}`
const details = await collectDetails()
console.log('\nVertebral formula (counts per region):')
const formula = {
C: await askPositiveInt(' cervical (C)', 7),
T: await askPositiveInt(' thoracic (T)', 13),
L: await askPositiveInt(' lumbar (L)', 6),
S: await askPositiveInt(' sacral (S)', 5),
Cd: await askPositiveInt(' caudal (Cd)', 18),
}
const formulaConstName = `${id.replace(/-/g, '_').toUpperCase()}_VERTEBRAL_FORMULA`
const speciesDir = resolve(PROJECT_ROOT, 'src/domain/species', id)
const targets = {
'index.ts': indexTs({ id, labelFr, mainSvgPath, details, formulaConstName }),
'vertebrae.ts': vertebraeTs({ formulaConstName, labelFr, formula }),
'pathologies.ts': pathologiesTs(),
'pathologies.json': pathologiesJsonTemplate({ id, labelFr, labelEn }),
}
// Refuse to clobber.
for (const file of Object.keys(targets)) {
const p = resolve(speciesDir, file)
if (existsSync(p)) {
console.error(`\n✖ ${p} already exists. Aborting to protect existing work.`)
process.exit(1)
}
}
await mkdir(speciesDir, { recursive: true })
for (const [file, body] of Object.entries(targets)) {
await writeFile(resolve(speciesDir, file), body)
}
const publicDir = resolve(PROJECT_ROOT, 'public/species', assetFolder)
await mkdir(publicDir, { recursive: true })
console.log(`\n✓ Created src/domain/species/${id}/`)
for (const file of Object.keys(targets)) console.log(` - ${file}`)
console.log(`✓ Ensured public/species/${assetFolder}/ exists`)
console.log('\nNext steps:')
console.log(` 1. Drop your SVG assets into public/species/${assetFolder}/`)
console.log(` - main: ${mainSvgFile}`)
for (const d of details) {
const file = d.path.split('/').pop()
console.log(` - detail "${d.key}": ${file}`)
}
console.log(` 2. Author the findings tree in src/domain/species/${id}/pathologies.json`)
console.log(` (schema documented in src/domain/schema/findings.ts).`)
console.log(` 3. Adjust the vertebral counts in vertebrae.ts if needed.`)
console.log(` 4. Run: pnpm typecheck && pnpm test:run && pnpm dev`)
console.log(' The new species will appear automatically in the animal picker.\n')
}
main()
.catch((err) => {
console.error('Scaffold failed:', err)
process.exit(1)
})
.finally(() => {
rl.close()
})