Skip to content
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

Solution #358

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
23 changes: 13 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@mate-academy/eslint-config": "latest",
"@mate-academy/scripts": "^1.8.6",
"@mate-academy/scripts": "^1.9.12",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
17 changes: 8 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Copy files

**Read [the guideline](https://github.com/mate-academy/js_task-guideline/blob/master/README.md) before start**
### Description

Write an app in `app.js` file, that will copy a file from one specified location to another like
Linux cp command: `cp file.txt file-copy.txt`.
- Wrote an app that will copy a file from one specified location to another

- It must do nothing in case the user is trying to copy to the same location.
- The app must support only copying of files, and no additional options (flags). Plain copying of files.
- Throw an error with the console.error() command
### Stack

## Node Version Requirement
- Node

### Note: Use Node.js version 20 or higher
### Tools

If you haven't installed a specific Node.js version, you can manage multiple Node.js versions on your machine using tools like [nvm (Node Version Manager)](https://github.com/nvm-sh/nvm) or [(Node.js version management)](https://nodejs.org/en/blog/release/v20.9.0). Ensure that the selected Node.js version aligns with the specified minimum version before proceeding with the project setup.
- ESlint
- Prettier
- Jest
23 changes: 23 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
/* eslint-disable no-console */
'use strict';

const fs = require('fs');

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

if (!dest) {
console.error('Please provide two arguments');
}
Comment on lines +9 to +11

Choose a reason for hiding this comment

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

The code checks if the destination argument is missing and logs an error message, but it does not exit the function. Consider adding a return statement after logging the error to prevent further execution.


try {
if (src && dest && src !== dest) {

Choose a reason for hiding this comment

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

The condition src !== dest is checked, which is good to prevent copying a file onto itself. However, ensure that this logic is intended and correctly handles cases where the source and destination are the same.

const fileData = fs.readFileSync(src, 'utf8');

fs.writeFileSync(dest, fileData);
}
} catch (err) {
console.error(err);
}
}

copyFile();
Loading