This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
95 lines (81 loc) · 2.9 KB
/
Copy pathbuild.js
File metadata and controls
95 lines (81 loc) · 2.9 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
/**
* Production Build Script for HyperDAG
*
* This script handles the complete production build process:
* 1. Builds the client application
* 2. Compiles the TypeScript server to JavaScript
* 3. Ensures all production files are ready for deployment
*/
import { execSync } from 'child_process';
import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from 'fs';
import path from 'path';
const log = (message) => {
console.log(`[build] ${message}`);
};
const runCommand = (command, description) => {
log(`${description}...`);
try {
execSync(command, { stdio: 'inherit' });
log(`✓ ${description} completed successfully`);
} catch (error) {
log(`✗ ${description} failed: ${error.message}`);
process.exit(1);
}
};
async function buildProduction() {
log('Starting production build process...');
// Ensure directories exist
if (!existsSync('server/public')) {
mkdirSync('server/public', { recursive: true });
}
// Build client application
runCommand(
'vite build --mode production --minify esbuild',
'Building client application'
);
// Compile TypeScript server to JavaScript with production optimizations
const serverBuildCommand = [
'esbuild server/index.ts',
'--platform=node',
'--packages=external',
'--bundle',
'--format=esm',
'--outfile=server/index.js',
'--minify',
'--target=node18',
'--define:process.env.NODE_ENV=\\"production\\"',
'--define:process.env.HYPERDAG_COMPILED=\\"true\\"',
'--sourcemap=external',
'--tree-shaking=true'
].join(' ');
runCommand(serverBuildCommand, 'Compiling server TypeScript to JavaScript');
// Verify build outputs
if (!existsSync('server/public/index.html')) {
log('⚠ Warning: Client build output not found at server/public/index.html');
log('Checking dist directory...');
if (existsSync('dist/index.html')) {
log('Found client build in dist/, copying to server/public/...');
runCommand('cp -r dist/* server/public/', 'Copying client build to server/public');
} else {
log('✗ Client build not found in expected locations');
process.exit(1);
}
}
if (!existsSync('server/index.js')) {
log('✗ Server compilation failed - server/index.js not found');
process.exit(1);
}
// Add production flag to compiled server
const compiledServer = readFileSync('server/index.js', 'utf8');
const productionServer = `// HyperDAG Production Build - ${new Date().toISOString()}\nprocess.env.HYPERDAG_COMPILED = 'true';\n${compiledServer}`;
writeFileSync('server/index.js', productionServer);
log('✓ Production build completed successfully!');
log('✓ Client build: server/public/');
log('✓ Server build: server/index.js');
log('Ready for deployment with: npm start');
}
buildProduction().catch(error => {
log(`✗ Build failed: ${error.message}`);
process.exit(1);
});