add: meal ingestion CLI for images and metadata
All checks were successful
Deploy on push / deploy (push) Has been skipped

This commit is contained in:
2026-03-22 20:09:23 -07:00
parent 21c3a0c4b2
commit 8f9a7eda2f
6 changed files with 308 additions and 12 deletions

View File

@@ -60,6 +60,10 @@ function validateMeals(meals) {
}
}
if (!/^\d+$/.test(meal.id)) {
throw new Error(`Meal ${index} has a non-numeric id "${meal.id}"`);
}
if (meal.position !== undefined && typeof meal.position !== "string") {
throw new Error(`Meal ${index} has a non-string "position" value`);
}
@@ -82,8 +86,31 @@ function loadMeals() {
return meals;
}
function saveMeals(meals) {
validateMeals(meals);
fs.writeFileSync(mealsPath, `${JSON.stringify(meals, null, 2)}\n`);
}
function getNextMealId(meals) {
if (meals.length === 0) {
return "01";
}
const nextNumber =
Math.max(...meals.map((meal) => Number.parseInt(meal.id, 10))) + 1;
const idWidth = Math.max(
2,
...meals.map((meal) => meal.id.length),
String(nextNumber).length
);
return String(nextNumber).padStart(idWidth, "0");
}
module.exports = {
getNextMealId,
loadMeals,
mealsPath,
repoRoot,
saveMeals,
};