Fix grade seed path for production deploy

This commit is contained in:
2026-05-16 23:41:14 +07:00
parent 14bb9bf744
commit 9141f99f6a
3 changed files with 171 additions and 12 deletions

1
scripts/data/.gitkeep Normal file
View File

@ -0,0 +1 @@

View File

@ -1,18 +1,33 @@
import path from "node:path";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import XLSX from "xlsx";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const sourcePath =
process.argv[2] ?? "/Users/wirabasalamah/work/abelbirdnest/data gudang/Grade.xls";
const defaultSourcePath = path.join(__dirname, "data", "Grade.xls");
const sourcePath = process.argv[2] ?? process.env.GRADE_XLS_PATH ?? defaultSourcePath;
function formatCode(prefix, sequence) {
return `${prefix}${String(sequence).padStart(5, "0")}`;
}
async function main() {
if (!fs.existsSync(sourcePath)) {
throw new Error(
[
`File grade tidak ditemukan: ${sourcePath}`,
"Simpan file Grade.xls di scripts/data/Grade.xls",
"atau jalankan: node scripts/seed-grades-from-xls.mjs /path/ke/Grade.xls",
"atau set env: GRADE_XLS_PATH=/path/ke/Grade.xls"
].join("\n")
);
}
const workbook = XLSX.readFile(sourcePath);
const sheetName = workbook.SheetNames[0];
const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], { defval: "" });