diff --git a/README.md b/README.md index 13cf8c0..78afd70 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ The default deploy flow is: ```sh git pull --ff-only -npm install --include=dev +npm install --production=false --include=dev --omit=optional npm run build pm2 reload tssbot-web --update-env ``` @@ -94,6 +94,13 @@ Only processes listed in `PM2_RESTART_TARGETS` are reloaded. The default is `tssbot-web`, so unrelated PM2 processes are left alone. The webhook exits after 24 hours so PM2 restarts it cleanly. +When webhook code changes are deployed, restart the webhook process once so PM2 +loads the updated listener: + +```sh +pm2 reload tssbot-webhook --update-env +``` + The webhook listener reads `.env` on startup. To send a Discord notification whenever the listener starts or restarts, set: diff --git a/webhook.cjs b/webhook.cjs index cb93a97..525f2a7 100644 --- a/webhook.cjs +++ b/webhook.cjs @@ -97,6 +97,23 @@ function run(command, args, options = {}) { }) } +async function ensureBuildDependencies() { + await run('npm', ['install', '--production=false', '--include=dev', '--omit=optional'], { + env: { + NODE_ENV: 'development', + npm_config_include: 'dev', + npm_config_omit: 'optional', + npm_config_production: 'false', + }, + }) + + try { + require.resolve('@vitejs/plugin-react') + } catch { + throw new Error('@vitejs/plugin-react is missing after npm install; dev dependencies were not installed') + } +} + function postDiscordWebhook(payload) { if (!DISCORD_WEBHOOK_URL) return Promise.resolve() @@ -162,11 +179,7 @@ function notifyDiscordRestart() { async function deploy() { await run('git', ['pull', '--ff-only']) - await run('npm', ['install', '--include=dev'], { - env: { - npm_config_production: 'false', - }, - }) + await ensureBuildDependencies() await run('npm', ['run', 'build']) for (const target of RESTART_TARGETS) {