debut refacto

This commit is contained in:
Tom Boullay
2026-04-14 14:18:40 +02:00
parent ab9685b6ee
commit e9ae6ffc41
13 changed files with 721 additions and 554 deletions
+72
View File
@@ -0,0 +1,72 @@
import { REQUIRED_TEXTURES } from './constants'
import type { FileChange } from './types'
/**
* Build a formatted commit message based on the upload context.
*
* Symbols:
* - ✅ = new file
* - 🔄 = modified file
* - ❌ = missing texture (new upload) or deleted file (update)
* - Unchanged files are omitted entirely
*/
export function buildCommitMessage(
folderName: string,
destination: string,
modelFilename: string,
textureNames: string[],
compressed: boolean,
isReplace: boolean,
fileChanges: Map<string, FileChange>,
deletedFileNames: string[],
): string {
const title = isReplace
? `update: upload-gltf update -> ${destination}/${folderName}`
: `update: upload-gltf add a new model -> ${destination}/${folderName}`
const lines: string[] = [title, '']
// Model section — only show if changed or new
const modelChange = fileChanges.get(modelFilename.toLowerCase())
if (modelChange === 'new') {
lines.push('📦 Model')
lines.push(`${modelFilename}${compressed ? ' (compressed)' : ''}`)
} else if (modelChange === 'changed') {
lines.push('📦 Model')
lines.push(` 🔄 ${modelFilename}${compressed ? ' (compressed)' : ''}`)
}
// Textures section — only show lines that have changes
const foundTextures = new Set(
textureNames.map((t) => t.toLowerCase().replace(/\.[^.]+$/, '')),
)
const textureLines: string[] = []
for (const tex of REQUIRED_TEXTURES) {
if (foundTextures.has(tex)) {
const actual = textureNames.find(
(t) => t.toLowerCase().replace(/\.[^.]+$/, '') === tex,
)!
const change = fileChanges.get(actual.toLowerCase())
if (change === 'new') {
textureLines.push(`${actual}`)
} else if (change === 'changed') {
textureLines.push(` 🔄 ${actual}`)
}
} else if (!isReplace) {
textureLines.push(`${tex} (manquant)`)
}
}
for (const name of deletedFileNames) {
textureLines.push(`${name} (supprime)`)
}
if (textureLines.length > 0) {
lines.push('🎨 Textures')
lines.push(...textureLines)
}
return lines.join('\n')
}