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
67 changes: 67 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
/* eslint-disable no-console */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires the app to be written in app.js (root). This file is src/app.js — confirm the required file location and move/rename to app.js at project root if the grader expects that exact path (checklist item #4).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical: the task requires the app to be implemented in app.js at the project root so the grader can find it. This file is src/app.js; please move or copy this implementation to app.js at the repository root (checklist-level requirement).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the terms of the assignment, it was not specified anywhere that this file should be outside of the src folder . And when I move it out of the folder, the tests are not run. Therefore, I can't remove it from this folder. Accept my work please

'use strict';

const fs = require('fs/promises');
const path = require('node:path');

async function copyFiles() {
const args = process.argv.slice(2);
const [src, dest] = args;

if (!src || !dest || args.length > 2) {
console.error('Two arguments are required');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: error branches call console.error(...) then return, which leaves the process exit code as 0. Consider setting process.exitCode = 1 (or calling process.exit(1)) after printing errors so failures are visible to callers/CI. Apply the change to all error branches (initial validation, missing source, source not a file, destination is a directory, destination stat error, and copy error).


return;
}

for (const arg of args) {
if (arg.startsWith('-')) {
console.error('Arguments should not start with a dash');

return;
}
}

if (path.resolve(src) === path.resolve(dest)) {
return;
}

let srcStat;

try {
srcStat = await fs.stat(src);
} catch {
console.error('Source file does not exist');

return;
}

if (!srcStat.isFile()) {
console.error('Source is not a file');

return;
}

try {
const destStat = await fs.stat(dest);

if (destStat.isDirectory()) {
console.error('Destination is a directory');

return;
}
} catch (err) {
if (err.code !== 'ENOENT') {
console.error('Error checking destination file');

return;
}
}

try {
await fs.copyFile(src, dest);
} catch (err) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the final catch you log the error message, which is good; also set a non-zero exit code here so callers know the operation failed (see previous comment).

console.error('Error copying file:', err.message);
}
}

copyFiles();