Übergabestand 2026-10-14
Alpenwerk HR — HR-Stammdatenverwaltung Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte, Massenimport und ein lückenloser Nachweis jeder Änderung. Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der Datenbank, die Zugriffsschranke ist Row Level Security. Betrieb auf Windows Server: siehe deploy/windows/README.md. Sicherheitskonzept: docs/sicherheitskonzept.md.
This commit is contained in:
148
scripts/windows-paket.mjs
Normal file
148
scripts/windows-paket.mjs
Normal file
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env node
|
||||
// Baut das Auslieferungspaket für den Betrieb auf einem Windows-Server
|
||||
// (siehe deploy/windows/README.md).
|
||||
//
|
||||
// npm run paket:windows baut neu und packt
|
||||
// npm run paket:windows -- --ohne-build packt den vorhandenen Build
|
||||
//
|
||||
// Ergebnis: dist/alpenwerk-hr-windows-<datum>-<commit>/ und daneben dieselbe
|
||||
// Fassung als .zip. Auf dem Server wird nur Node gebraucht — kein npm, kein
|
||||
// Zugang zur Paketquelle, kein Build.
|
||||
//
|
||||
// ═══ Warum das Paket überall gebaut werden kann ═══
|
||||
//
|
||||
// Der Standalone-Build enthält nur JavaScript, mit einer Ausnahme: `sharp`,
|
||||
// das Next für die Bildoptimierung von next/image mitverfolgt — samt einer
|
||||
// Binärdatei für das Betriebssystem, auf dem gebaut wurde. Die Anwendung
|
||||
// benutzt next/image nirgends (das Logo ist ein schlichtes <img>), sharp wird
|
||||
// also nie geladen und fliegt hier raus. Danach prüft das Skript, dass keine
|
||||
// einzige native Datei (*.node) mehr im Paket liegt; sonst bricht es ab.
|
||||
//
|
||||
// ═══ Symlinks ═══
|
||||
//
|
||||
// Turbopack legt unter .next/node_modules Verweise wie `pg-<hash>` →
|
||||
// ../../node_modules/pg an. Ein Zip-Archiv trägt die unter Windows nicht
|
||||
// verlässlich, deshalb werden sie beim Kopieren aufgelöst.
|
||||
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { join, relative } from "node:path";
|
||||
|
||||
const ohneBuild = process.argv.includes("--ohne-build");
|
||||
|
||||
function lauf(befehl, args) {
|
||||
execFileSync(befehl, args, { stdio: "inherit", shell: process.platform === "win32" });
|
||||
}
|
||||
|
||||
if (!ohneBuild) lauf("npm", ["run", "build"]);
|
||||
|
||||
if (!existsSync(".next/standalone/server.js")) {
|
||||
console.error("Kein Standalone-Build gefunden (.next/standalone/server.js). Erst `npm run build`.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const commit = execFileSync("git", ["rev-parse", "--short", "HEAD"], { encoding: "utf8" }).trim();
|
||||
const unsauber = execFileSync("git", ["status", "--porcelain"], { encoding: "utf8" }).trim() !== "";
|
||||
const datum = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
||||
const name = `alpenwerk-hr-windows-${datum}-${commit}${unsauber ? "-lokal" : ""}`;
|
||||
const ziel = join("dist", name);
|
||||
const app = join(ziel, "app");
|
||||
|
||||
rmSync(ziel, { recursive: true, force: true });
|
||||
rmSync(`${ziel}.zip`, { force: true });
|
||||
mkdirSync(app, { recursive: true });
|
||||
|
||||
// ── Anwendung ─────────────────────────────────────────────────────────
|
||||
cpSync(".next/standalone", app, { recursive: true });
|
||||
// `dereference` von cpSync wirkt nur auf die Quelle selbst, nicht auf
|
||||
// verschachtelte Verweise — deshalb hier von Hand: Verweis weg, Ziel als
|
||||
// echtes Verzeichnis an seine Stelle.
|
||||
(function aufloesen(verzeichnis) {
|
||||
for (const eintrag of readdirSync(verzeichnis)) {
|
||||
const pfad = join(verzeichnis, eintrag);
|
||||
const info = lstatSync(pfad);
|
||||
if (info.isSymbolicLink()) {
|
||||
const quelle = realpathSync(join(".next/standalone", relative(app, pfad)));
|
||||
rmSync(pfad, { force: true });
|
||||
cpSync(quelle, pfad, { recursive: true });
|
||||
} else if (info.isDirectory()) {
|
||||
aufloesen(pfad);
|
||||
}
|
||||
}
|
||||
})(app);
|
||||
cpSync("public", join(app, "public"), { recursive: true });
|
||||
cpSync(".next/static", join(app, ".next/static"), { recursive: true });
|
||||
|
||||
for (const weg of ["node_modules/sharp", "node_modules/@img"]) {
|
||||
rmSync(join(app, weg), { recursive: true, force: true });
|
||||
}
|
||||
// Eine .env gehört nie ins Paket — sie liegt auf dem Server neben der
|
||||
// Anwendung, nicht darin.
|
||||
for (const datei of readdirSync(app)) {
|
||||
if (datei.startsWith(".env")) rmSync(join(app, datei), { force: true });
|
||||
}
|
||||
|
||||
// ── Datenbank-Werkzeuge ───────────────────────────────────────────────
|
||||
// Mit denselben relativen Pfaden wie im Repository: beide Skripte lesen
|
||||
// db/migrations bzw. deploy/db-init vom Arbeitsverzeichnis aus, und `pg` finden
|
||||
// sie in app/node_modules.
|
||||
mkdirSync(join(app, "scripts"), { recursive: true });
|
||||
cpSync("scripts/migrate.mjs", join(app, "scripts/migrate.mjs"));
|
||||
cpSync("scripts/db-setup.mjs", join(app, "scripts/db-setup.mjs"));
|
||||
cpSync("db/migrations", join(app, "db/migrations"), { recursive: true });
|
||||
// Der Rauchtest gehoert mit aufs Ziel.
|
||||
//
|
||||
// Er ist die einzige Pruefung, die die Funktionen wirklich **aufruft** statt
|
||||
// ihren Text zu lesen: Einstellung, Versetzung, Befoerderung, Austritt,
|
||||
// Wiedereintritt, in einer Transaktion, die am Ende verworfen wird. Genau die
|
||||
// Luecke, die er schliesst, hat eine kaputte Funktion zwoelf Tage lang
|
||||
// unbemerkt gelassen.
|
||||
//
|
||||
// Ohne ihn im Paket gibt es auf dem Zielserver keine Moeglichkeit zu pruefen,
|
||||
// ob die Anwendung dort nicht nur startet, sondern auch arbeitet.
|
||||
cpSync("db/tests", join(app, "db/tests"), { recursive: true });
|
||||
mkdirSync(join(app, "deploy/db-init"), { recursive: true });
|
||||
cpSync("deploy/db-init/01-auth-attrappe.sql", join(app, "deploy/db-init/01-auth-attrappe.sql"));
|
||||
|
||||
// ── Betriebsskripte ───────────────────────────────────────────────────
|
||||
cpSync("deploy/windows", join(ziel, "windows"), { recursive: true });
|
||||
|
||||
writeFileSync(
|
||||
join(ziel, "VERSION.txt"),
|
||||
[
|
||||
`Commit: ${commit}${unsauber ? " (mit lokalen, nicht eingecheckten Änderungen)" : ""}`,
|
||||
`Gebaut: ${new Date().toISOString()}`,
|
||||
`Mit Node: ${process.version}`,
|
||||
"",
|
||||
].join("\r\n")
|
||||
);
|
||||
|
||||
// ── Prüfungen ─────────────────────────────────────────────────────────
|
||||
const fremd = [];
|
||||
(function durchsuchen(verzeichnis) {
|
||||
for (const eintrag of readdirSync(verzeichnis)) {
|
||||
const pfad = join(verzeichnis, eintrag);
|
||||
const info = lstatSync(pfad);
|
||||
if (info.isSymbolicLink()) fremd.push(`Symlink: ${pfad}`);
|
||||
else if (info.isDirectory()) durchsuchen(pfad);
|
||||
else if (eintrag.endsWith(".node")) fremd.push(`Native Datei: ${pfad}`);
|
||||
}
|
||||
})(ziel);
|
||||
if (fremd.length > 0) {
|
||||
console.error("Das Paket ist nicht plattformunabhängig:\n " + fremd.join("\n "));
|
||||
process.exit(1);
|
||||
}
|
||||
if (!existsSync(join(app, ".next/node_modules")) || !statSync(join(app, "node_modules/pg")).isDirectory()) {
|
||||
console.error("pg fehlt im Paket — der Build hat sich verändert, die Annahmen hier stimmen nicht mehr.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// ── Zip ──────────────────────────────────────────────────────────────
|
||||
// tar mit -a wählt das Format nach der Endung; bsdtar auf macOS und das tar
|
||||
// in Windows 10+ können beide Zip schreiben.
|
||||
try {
|
||||
execFileSync("tar", ["-a", "-c", "-f", `${name}.zip`, name], { cwd: "dist", stdio: "inherit" });
|
||||
console.log(`\nPaket: ${ziel}.zip`);
|
||||
} catch {
|
||||
console.log(`\nZip konnte nicht erstellt werden; das Verzeichnis ${ziel} ist vollständig.`);
|
||||
}
|
||||
Reference in New Issue
Block a user