copy.js

1const { exec } = require('child_process');
2const path = require('path');
3
4const files = [
5	{
6		source: path.resolve(__dirname, '../src/data'),
7		destination: path.resolve(__dirname, '../bin/data'),
8	},
9];
10
11const PLATFORM = process.platform;
12const COPY_COMMAND = PLATFORM === 'win32' ? 'xcopy' : 'cp';
13
14files.forEach((file) => {
15	console.log(
16		`Copying from ${file.source} to ${file.destination} using ${COPY_COMMAND}`,
17	);
18	const command = `${COPY_COMMAND} ${PLATFORM !== 'win32' ? '-r' : ''} "${file.source}" "${file.destination}" ${
19		PLATFORM === 'win32' ? '/E /I /Y' : ''
20	}`;
21
22	exec(command, (err, stdout, stderr) => {
23		if (err) {
24			console.error(`Error: ${err.message}`);
25			console.error(stderr); // Log the error message from the command
26			return;
27		}
28
29		console.log(stdout); // Log the output from the command
30		console.log(`Successfully copied ${file.source} to ${file.destination}`);
31	});
32});
33