- Add shared env loader for migration scripts to load .env and .env.local files at module init - Add migration script to fix broken delivery note relation fields and backfill missing company data - Update delivery notes list page: add status filter tabs, company-based collapsible grouping, increased fetch limit, and improved global search - Add per-item cost price, markup calculations, and total summary rows for cost, selling price, markup, and margin to delivery note detail pages
31 lines
No EOL
985 B
TypeScript
31 lines
No EOL
985 B
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
/**
|
|
* Inline .env/.env.local loader — must be the FIRST import in any
|
|
* migration script that reads process.env at module-init time.
|
|
* tsx's ESM hoisting means all top-level imports run before the
|
|
* body, so we load env inside the imported module's TOP-LEVEL
|
|
* SCOPE (here) instead of in the consumer's body.
|
|
*/
|
|
function loadEnv(): void {
|
|
for (const name of [".env", ".env.local"]) {
|
|
try {
|
|
const raw = readFileSync(resolve(process.cwd(), name), "utf8");
|
|
for (const line of raw.split("\n")) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const m = trimmed.match(/^([A-Z0-9_]+)\s*=\s*(.+)$/i);
|
|
if (m && !process.env[m[1]]) {
|
|
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "").trim();
|
|
}
|
|
}
|
|
} catch {
|
|
// missing file — rely on shell env
|
|
}
|
|
}
|
|
}
|
|
|
|
loadEnv();
|
|
|
|
export { loadEnv }; |