-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdev-fast.js
More file actions
61 lines (52 loc) · 1.68 KB
/
dev-fast.js
File metadata and controls
61 lines (52 loc) · 1.68 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
/**
* Custom dev script for faster development
* This script temporarily renames the main page.tsx to page.original.tsx
* and uses a simplified page for development
*/
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
// Paths
const APP_DIR = path.join(__dirname, 'src', 'app');
const MAIN_PAGE = path.join(APP_DIR, 'page.tsx');
const BACKUP_PAGE = path.join(APP_DIR, 'page.original.tsx');
const FAST_PAGE = path.join(APP_DIR, 'fast-dev.tsx');
const TEMP_PAGE = path.join(APP_DIR, 'page.temp.tsx');
// Ensure the backup file exists before continuing
if (!fs.existsSync(FAST_PAGE)) {
console.error(
'Fast dev page not found. Make sure src/app/fast-dev.tsx exists.',
);
process.exit(1);
}
// Check if we need to backup the original page
if (fs.existsSync(MAIN_PAGE) && !fs.existsSync(BACKUP_PAGE)) {
console.log('Backing up original page...');
fs.copyFileSync(MAIN_PAGE, BACKUP_PAGE);
}
// Now replace the main page with our fast version
console.log('Using fast dev page for development...');
fs.copyFileSync(FAST_PAGE, MAIN_PAGE);
// Function to restore the original page on exit
function restoreOriginalPage() {
if (fs.existsSync(BACKUP_PAGE)) {
console.log('\nRestoring original page...');
fs.copyFileSync(BACKUP_PAGE, MAIN_PAGE);
}
}
// Start Next.js dev server with turbo
console.log('Starting Next.js dev server...');
const nextDev = spawn('npx', ['next', 'dev'], {
stdio: 'inherit',
shell: true,
});
// Handle process termination
process.on('SIGINT', () => {
restoreOriginalPage();
process.exit(0);
});
// Listen for child process exit
nextDev.on('exit', (code) => {
restoreOriginalPage();
process.exit(code);
});