-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
49 lines (41 loc) · 1.55 KB
/
build.js
File metadata and controls
49 lines (41 loc) · 1.55 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
const fs = require('fs');
const path = require('path');
// List of static assets extensions to include
const ASSET_EXTENSIONS = ['.html', '.css', '.js', '.json', '.exe', '.ps1', '.zip', '.msi'];
// Paths for source and output directories
const SOURCE_DIRECTORY = '.';
const OUTPUT_DIRECTORY = 'public';
// Function to copy files
function copyFiles(srcDir, outputDir) {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.readdirSync(srcDir, { withFileTypes: true }).forEach((entry) => {
const srcPath = path.join(srcDir, entry.name);
const outputPath = path.join(outputDir, entry.name);
// FIXED: Compare absolute paths to avoid infinite copying
if (path.resolve(srcPath) === path.resolve(OUTPUT_DIRECTORY)) return;
// Handle subdirectories recursively
if (entry.isDirectory()) {
// Skip excluded directories
if (['.git', 'node_modules'].includes(entry.name)) return;
copyFiles(srcPath, outputPath);
} else {
// Only include relevant static assets
if (ASSET_EXTENSIONS.includes(path.extname(entry.name))) {
fs.copyFileSync(srcPath, outputPath);
console.log(`Copied: ${srcPath} -> ${outputPath}`);
}
}
});
}
// Function to build the public directory
function buildPublicDirectory() {
if (fs.existsSync(OUTPUT_DIRECTORY)) {
fs.rmSync(OUTPUT_DIRECTORY, { recursive: true, force: true });
}
copyFiles(SOURCE_DIRECTORY, OUTPUT_DIRECTORY);
console.log('Public directory built successfully.');
}
// Execute the build process
buildPublicDirectory();