-
Notifications
You must be signed in to change notification settings - Fork 535
feat: implement copyFiles function #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,68 @@ | ||
| /* eslint-disable no-console */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: the task requires the app to be implemented in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation: error branches call |
||
|
|
||
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment.
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 issrc/app.js— confirm the required file location and move/rename toapp.jsat project root if the grader expects that exact path (checklist item #4).