From f31fcd9e84202e77e16e47d86e7e7a3b4481a1ae Mon Sep 17 00:00:00 2001 From: mpuckett Date: Thu, 25 Jun 2026 12:24:51 -0500 Subject: [PATCH] Initial --- package.json | 8 ++++---- scripts/ensure-build.mjs | 13 +++++++++++++ scripts/start-api.mjs | 20 ++++++++++++++++++++ scripts/start-ui-prod.mjs | 15 +++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 scripts/ensure-build.mjs create mode 100644 scripts/start-api.mjs create mode 100644 scripts/start-ui-prod.mjs diff --git a/package.json b/package.json index e2f9044..95b393b 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,11 @@ "type": "module", "scripts": { "dev": "concurrently -n API,UI -c cyan,magenta \"npm run api:dev\" \"npm run ui:dev\"", - "prod": "if [ ! -f dist/index.html ]; then npm run build; fi; concurrently -n API,UI -c cyan,magenta \"npm run api:prod\" \"npm run ui:prod\"", - "api:dev": "NODE_ENV=development nodemon server/index.js", - "api:prod": "NODE_ENV=production node server/index.js", + "prod": "node scripts/ensure-build.mjs && concurrently -n API,UI -c cyan,magenta \"npm run api:prod\" \"npm run ui:prod\"", + "api:dev": "node scripts/start-api.mjs development --watch", + "api:prod": "node scripts/start-api.mjs production", "ui:dev": "vite --host 0.0.0.0 --port 3000 --strictPort", - "ui:prod": "NODE_ENV=production vite preview --host 0.0.0.0 --port 3000 --strictPort", + "ui:prod": "node scripts/start-ui-prod.mjs", "start": "npm run prod", "test": "node --test 'server/test/*.test.mjs'", "build": "vite build", diff --git a/scripts/ensure-build.mjs b/scripts/ensure-build.mjs new file mode 100644 index 0000000..1608292 --- /dev/null +++ b/scripts/ensure-build.mjs @@ -0,0 +1,13 @@ +import fs from 'node:fs'; +import { spawnSync } from 'node:child_process'; + +if (fs.existsSync('dist/index.html')) { + process.exit(0); +} + +const result = spawnSync('npm', ['run', 'build'], { + stdio: 'inherit', + shell: process.platform === 'win32' +}); + +process.exit(result.status ?? 1); diff --git a/scripts/start-api.mjs b/scripts/start-api.mjs new file mode 100644 index 0000000..76e5905 --- /dev/null +++ b/scripts/start-api.mjs @@ -0,0 +1,20 @@ +import { spawn } from 'node:child_process'; + +const mode = process.argv[2] || 'development'; +const watch = process.argv.includes('--watch'); +const command = watch ? 'nodemon' : 'node'; +const args = watch ? ['server/index.js'] : ['server/index.js']; + +const child = spawn(command, args, { + stdio: 'inherit', + shell: process.platform === 'win32', + env: { + ...process.env, + NODE_ENV: mode + } +}); + +child.on('exit', (code, signal) => { + if (signal) process.kill(process.pid, signal); + process.exit(code ?? 0); +}); diff --git a/scripts/start-ui-prod.mjs b/scripts/start-ui-prod.mjs new file mode 100644 index 0000000..21b87b0 --- /dev/null +++ b/scripts/start-ui-prod.mjs @@ -0,0 +1,15 @@ +import { spawn } from 'node:child_process'; + +const child = spawn('vite', ['preview', '--host', '0.0.0.0', '--port', '3000', '--strictPort'], { + stdio: 'inherit', + shell: process.platform === 'win32', + env: { + ...process.env, + NODE_ENV: 'production' + } +}); + +child.on('exit', (code, signal) => { + if (signal) process.kill(process.pid, signal); + process.exit(code ?? 0); +});