-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-to-docs.js
33 lines (27 loc) · 1.77 KB
/
build-to-docs.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
const fs = require('fs');
const path = require('path');
const sourceFolder = path.join(__dirname, 'build'); // Path of source folder. Replace 'source' with your actual source folder name.
const destinationFolder = path.join(__dirname, 'docs'); // Path of destination folder. Replace 'destination' with your actual destination folder name.
if (!fs.existsSync(destinationFolder)) {
fs.mkdirSync(destinationFolder);
}
const files = fs.readdirSync(sourceFolder); // Read all files in the source folder.
files.forEach(file => { // Iterate over each file in the source folder. Replace 'file' with a variable name of your choice.
const sourceFilePath = path.join(sourceFolder, file); // Get the path of the source file.
const destinationFilePath = path.join(destinationFolder, file); // Get the path of the destination file.
// Check if the current item is a file
if (fs.lstatSync(sourceFilePath).isFile()) {
const sourceStream = fs.createReadStream(sourceFilePath); // Create a read stream for the source file.
const destinationStream = fs.createWriteStream(destinationFilePath); // Create a write stream for the destination file.
sourceStream.pipe(destinationStream); // Pipe the source stream to the destination stream.
sourceStream.on('finish', () => { // Print a success message when the file is copied.
console.log(`File '${file}' copied successfully.`);
});
sourceStream.on('error', err => { // Print an error message when an error occurs.
console.error(`Error copying file '${file}': ${err.message}`);
});
} else {
console.log(`Skipping directory '${file}'`);
}
});
console.log('Files copied successfully.'); // Print a success message when all files are copied.