-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-export.js
More file actions
76 lines (62 loc) · 2.34 KB
/
create-export.js
File metadata and controls
76 lines (62 loc) · 2.34 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
const fs = require('fs');
const path = require('path');
const sourceDir = path.join(__dirname, '.next');
const targetDir = path.join(__dirname, 'out');
// Create out directory
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
// Copy static files
const staticDir = path.join(sourceDir, 'static');
if (fs.existsSync(staticDir)) {
const targetStaticDir = path.join(targetDir, '_next', 'static');
fs.mkdirSync(path.join(targetDir, '_next'), { recursive: true });
fs.cpSync(staticDir, targetStaticDir, { recursive: true });
console.log('✓ Copied static files');
}
// Copy server/app HTML files
const serverAppDir = path.join(sourceDir, 'server', 'app');
if (fs.existsSync(serverAppDir)) {
const files = fs.readdirSync(serverAppDir, { recursive: true });
files.forEach(file => {
const srcPath = path.join(serverAppDir, file);
const stat = fs.statSync(srcPath);
if (stat.isFile() && file.endsWith('.html')) {
const targetPath = path.join(targetDir, file);
const targetDirPath = path.dirname(targetPath);
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath, { recursive: true });
}
fs.copyFileSync(srcPath, targetPath);
console.log(`✓ Copied ${file}`);
}
});
}
// Copy public files
const publicDir = path.join(__dirname, 'public');
if (fs.existsSync(publicDir)) {
const files = fs.readdirSync(publicDir, { recursive: true });
files.forEach(file => {
const srcPath = path.join(publicDir, file);
const stat = fs.statSync(srcPath);
if (stat.isFile()) {
const targetPath = path.join(targetDir, file);
const targetDirPath = path.dirname(targetPath);
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath, { recursive: true });
}
fs.copyFileSync(srcPath, targetPath);
}
});
console.log('✓ Copied public files');
}
// Create .nojekyll file to prevent GitHub Pages from ignoring _next directory
fs.writeFileSync(path.join(targetDir, '.nojekyll'), '');
console.log('✓ Created .nojekyll file');
// Copy CNAME file if it exists
const cnameFile = path.join(__dirname, 'CNAME');
if (fs.existsSync(cnameFile)) {
fs.copyFileSync(cnameFile, path.join(targetDir, 'CNAME'));
console.log('✓ Copied CNAME file');
}
console.log('\n✓ Static export created in /out directory');