diff --git a/README.md b/README.md index f768e11..13cf8c0 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ The default deploy flow is: ```sh git pull --ff-only -npm install +npm install --include=dev npm run build pm2 reload tssbot-web --update-env ``` diff --git a/webhook.cjs b/webhook.cjs index 09d13e8..cb93a97 100644 --- a/webhook.cjs +++ b/webhook.cjs @@ -66,18 +66,33 @@ function verifySignature(rawBody, signature) { ) } -function run(command, args) { +function commandFor(command) { + if (process.platform !== 'win32') return command + if (command === 'npm') return 'npm.cmd' + if (command === 'pm2') return 'pm2.cmd' + return command +} + +function run(command, args, options = {}) { return new Promise((resolve, reject) => { - const child = spawn(command, args, { + const label = [command, ...args].join(' ') + console.log(`deploy step started: ${label}`) + + const child = spawn(commandFor(command), args, { cwd: __dirname, + env: { ...process.env, ...options.env }, shell: process.platform === 'win32', stdio: 'inherit', }) child.on('error', reject) child.on('exit', (code) => { - if (code === 0) resolve() - else reject(new Error(`${command} ${args.join(' ')} exited with ${code}`)) + if (code === 0) { + console.log(`deploy step completed: ${label}`) + resolve() + } else { + reject(new Error(`${label} exited with ${code}`)) + } }) }) } @@ -147,7 +162,11 @@ function notifyDiscordRestart() { async function deploy() { await run('git', ['pull', '--ff-only']) - await run('npm', ['install']) + await run('npm', ['install', '--include=dev'], { + env: { + npm_config_production: 'false', + }, + }) await run('npm', ['run', 'build']) for (const target of RESTART_TARGETS) {