Fix grade seed path for production deploy
This commit is contained in:
1
scripts/data/.gitkeep
Normal file
1
scripts/data/.gitkeep
Normal file
@ -0,0 +1 @@
|
||||
|
||||
@ -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: "" });
|
||||
|
||||
Reference in New Issue
Block a user