-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.js
59 lines (51 loc) · 1.66 KB
/
entrypoint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
/**
* Entrypoint script for the Dockerfile.
* This script is responsible for running the necessary commands to start the application.
*/
import { execSync } from 'node:child_process';
import { styleText } from 'node:util';
console.log(styleText('bold', 'Starting entry script...'));
console.log('Current directory:', styleText('yellow', process.cwd()));
console.log('Available npm scripts:');
try {
execSync('node --run', { stdio: 'inherit' });
} catch (error) {
console.error('node --run failed');
process.exit(1);
}
console.log('Running db:generate...');
try {
execSync('node --run db:generate', { stdio: 'inherit' });
} catch {
console.error(styleText('red', '⨯') + ' db:generate failed');
process.exit(1);
}
console.log('Running db:push...');
try {
execSync('node --run db:push', { stdio: 'inherit' });
} catch {
console.error(styleText('red', '⨯') + ' db:push failed');
process.exit(1);
}
if (process.env.NODE_ENV === 'production') {
console.log('Running in production mode...');
try {
execSync('node --run db:seed-prod', { stdio: 'inherit' });
execSync('node --run build', { stdio: 'inherit' });
execSync('npm start', { stdio: 'inherit' });
} catch {
console.error(styleText('red', '⨯') + ' Production commands failed');
process.exit(1);
}
} else {
console.log('Running in development mode...');
try {
execSync('node --run db:seed-dev', { stdio: 'inherit' });
execSync('node --run dev', { stdio: 'inherit' });
} catch {
console.error(styleText('red', '⨯') + ' Development commands failed');
process.exit(1);
}
}
console.log(styleText('green', '✓') + ' Script execution completed.');