fix(shopping/loyalty): fail build when card env missing instead of rmSync
CI / update (push) Successful in 52s
CI / update (push) Successful in 52s
Previous behavior silently deleted static/shopping/*.svg when SHOPPING_*_NUMBER env vars were unset, then rsync --delete propagated the deletion to the prod server — the loyalty buttons disappeared on deploys where the env didn't reach the build (or during the brief rm→write window of a parallel run). Now the script exits non-zero with a clear message; deploy.sh's set -e aborts before any destructive sync.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "homepage",
|
"name": "homepage",
|
||||||
"version": "1.59.1",
|
"version": "1.59.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
* Build-time generation of loyalty-card barcode SVGs.
|
* Build-time generation of loyalty-card barcode SVGs.
|
||||||
*
|
*
|
||||||
* Reads card numbers from env vars and writes static/shopping/supercard.svg
|
* Reads card numbers from env vars and writes static/shopping/supercard.svg
|
||||||
* + static/shopping/cumulus.svg. Skips cards whose env var is unset so the
|
* + static/shopping/cumulus.svg. Fails the build if any required env is
|
||||||
* site still builds in environments without secrets.
|
* unset so deploys can't silently ship a broken UI.
|
||||||
*
|
*
|
||||||
* SHOPPING_COOP_SUPERCARD_NUMBER → Data Matrix (Coop Supercard)
|
* SHOPPING_COOP_SUPERCARD_NUMBER → Data Matrix (Coop Supercard)
|
||||||
* SHOPPING_MIGROS_CUMULUS_NUMBER → Code 128 (Migros Cumulus)
|
* SHOPPING_MIGROS_CUMULUS_NUMBER → Code 128 (Migros Cumulus)
|
||||||
*
|
*
|
||||||
* Run: pnpm exec vite-node scripts/generate-loyalty-cards.ts
|
* Run: pnpm exec vite-node scripts/generate-loyalty-cards.ts
|
||||||
*/
|
*/
|
||||||
import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
||||||
import { dirname, resolve } from 'node:path';
|
import { dirname, resolve } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { toSVG } from 'bwip-js/node';
|
import { toSVG } from 'bwip-js/node';
|
||||||
@@ -37,16 +37,16 @@ const cards: CardSpec[] = [
|
|||||||
|
|
||||||
mkdirSync(OUT_DIR, { recursive: true });
|
mkdirSync(OUT_DIR, { recursive: true });
|
||||||
|
|
||||||
for (const card of cards) {
|
const missing = cards.filter((c) => !process.env[c.envVar]?.trim()).map((c) => c.envVar);
|
||||||
const value = process.env[card.envVar]?.trim();
|
if (missing.length) {
|
||||||
const outPath = resolve(OUT_DIR, card.filename);
|
console.error(`[loyalty-cards] missing required env: ${missing.join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
if (!value) {
|
|
||||||
try { rmSync(outPath); } catch { /* not present */ }
|
|
||||||
console.log(`[loyalty-cards] ${card.envVar} not set — skipped ${card.filename}`);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const card of cards) {
|
||||||
|
const value = process.env[card.envVar]!.trim();
|
||||||
|
const outPath = resolve(OUT_DIR, card.filename);
|
||||||
|
|
||||||
const svg = toSVG({
|
const svg = toSVG({
|
||||||
bcid: card.bcid,
|
bcid: card.bcid,
|
||||||
text: value,
|
text: value,
|
||||||
|
|||||||
Reference in New Issue
Block a user