Initial
This commit is contained in:
@@ -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",
|
||||
|
||||
13
scripts/ensure-build.mjs
Normal file
13
scripts/ensure-build.mjs
Normal file
@@ -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);
|
||||
20
scripts/start-api.mjs
Normal file
20
scripts/start-api.mjs
Normal file
@@ -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);
|
||||
});
|
||||
15
scripts/start-ui-prod.mjs
Normal file
15
scripts/start-ui-prod.mjs
Normal file
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user