feat: display projects as pokemons in pokemon platinum

This commit is contained in:
2025-12-11 17:16:00 +01:00
parent 25313d19a8
commit 2910eb15bd
59 changed files with 393 additions and 480 deletions

View File

@@ -29,41 +29,39 @@ export default defineNuxtModule({
return;
}
if (!existsSync(publicDir)) {
await mkdir(publicDir, { recursive: true });
}
const entries = await readdir(projectsDir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory()) continue;
const projectName = entry.name;
const sourceDir = join(projectsDir, projectName);
const destDir = join(publicDir, projectName);
const sourcePath = join(projectsDir, projectName, "index.webp");
const destPath = join(publicDir, `${projectName}.webp`);
if (!existsSync(destDir)) {
await mkdir(destDir, { recursive: true });
if (!existsSync(sourcePath)) {
continue;
}
const files = await readdir(sourceDir);
for (const file of files) {
if (!file.endsWith(".webp")) continue;
// only copy if destination doesn't exist, or if not the same as source
let shouldCopy = true;
if (existsSync(destPath)) {
const sourceChecksum = await getFileChecksum(sourcePath);
const destChecksum = await getFileChecksum(destPath);
const sourcePath = join(sourceDir, file);
const destPath = join(destDir, file);
// only copy if destination doesn't exist, or if not the same as source
let shouldCopy = true;
if (existsSync(destPath)) {
const sourceChecksum = await getFileChecksum(sourcePath);
const destChecksum = await getFileChecksum(destPath);
if (sourceChecksum === destChecksum) {
shouldCopy = false;
}
if (sourceChecksum === destChecksum) {
shouldCopy = false;
}
}
if (shouldCopy) {
await copyFile(sourcePath, destPath);
logger.success(`Copied: ${projectName}/${file}`);
}
if (shouldCopy) {
await copyFile(sourcePath, destPath);
logger.success(
`Copied: ${projectName}/index.webp -> ${projectName}.webp`,
);
}
}
} catch (error) {
@@ -77,9 +75,10 @@ export default defineNuxtModule({
if (nuxt.options.dev) {
nuxt.hook("ready", () => {
watch(contentDir, { recursive: true }, async (_, filename) => {
if (filename?.endsWith(".webp")) {
logger.info(`Detected change: ${filename}`);
watch(contentDir, { recursive: true }, async (_, filePath) => {
// NOTE: only match /PROJECT_NAME/index.webp
if (filePath?.endsWith("/index.webp")) {
logger.info(`Detected change: ${filePath}`);
await copyWebpFiles();
}
});