39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
#!/usr/bin/env tsx
|
|
/**
|
|
* Create or recreate the Elasticsearch index used by the app.
|
|
*
|
|
* Usage:
|
|
* npm run create:index
|
|
* npm run create:index -- --recreate
|
|
*
|
|
* Notes:
|
|
* - Loads environment from .env/.env.local via `-r dotenv/config` in the npm script.
|
|
* - Resolves TS path aliases via `-r tsconfig-paths/register`.
|
|
*/
|
|
import { ensureIndex } from "@/lib/elasticsearch";
|
|
|
|
function parseRecreateArg(argv: string[]): boolean {
|
|
let recreate = false;
|
|
for (const arg of argv) {
|
|
if (arg === "--recreate" || arg === "-r") {
|
|
recreate = true;
|
|
} else if (arg.startsWith("--recreate=")) {
|
|
const v = arg.split("=")[1]?.trim().toLowerCase();
|
|
recreate = v === "1" || v === "true" || v === "yes";
|
|
}
|
|
}
|
|
return recreate;
|
|
}
|
|
|
|
async function main() {
|
|
const recreate = parseRecreateArg(process.argv.slice(2));
|
|
console.log(`[create-index] Starting. recreate=${recreate}`);
|
|
await ensureIndex({ recreate });
|
|
console.log("[create-index] Done.");
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("[create-index] Failed:", err);
|
|
process.exit(1);
|
|
});
|