Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
'use strict';

const fs = require('fs');
const path = require('path');

function main() {
const args = process.argv.slice(2);
const sourceArg = args[0];
const destArg = args[1];

if (!sourceArg || !destArg) {
// eslint-disable-next-line no-console
console.error(
'Error: Please provide both source and destination file paths.',
);

return;
}

const sourcePath = path.resolve(sourceArg);
const destPath = path.resolve(destArg);

if (sourcePath === destPath) {
return;
}

if (!fs.existsSync(sourcePath)) {
// eslint-disable-next-line no-console
console.error('Error: Source file does not exist.');

return;
}

const sourceStats = fs.statSync(sourcePath);

if (sourceStats.isDirectory()) {
// eslint-disable-next-line no-console
console.error('Error: Source path is a directory.');

return;
}

if (fs.existsSync(destPath)) {
const destStats = fs.statSync(destPath);

if (destStats.isDirectory()) {
// eslint-disable-next-line no-console
console.error('Error: Destination path is a directory.');

return;
}
}

fs.copyFileSync(sourcePath, destPath);
}

main();
Loading