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

stage-1 #269

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^1.2.12",
"@mate-academy/scripts": "^1.7.0",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
16 changes: 16 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
'use strict';

const { copyFile } = require('./copyFile');

/* eslint no-console: "warn" */

try {
if (process.argv.length < 2 + 2) {
throw new Error('Script accepts 2 arguments');
}

const [oldPath, newPath] = copyFile(...process.argv.slice(2));

console.info(`Successfully copyed ${oldPath} to ${newPath}`);

Check warning on line 14 in src/app.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
} catch (error) {
console.error(error);

Check warning on line 16 in src/app.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
}
27 changes: 27 additions & 0 deletions src/copyFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const fs = require('node:fs');

/* eslint no-useless-escape: "warn" */

module.exports = {
copyFile,
};

/**
* @param {string} src
* @param {string} dst
* @returns {string[]} */
function copyFile(src, dst) {
if (src === dst) {
throw new Error('Source and destination are the same');
}

if (fs.existsSync(dst) && fs.lstatSync(dst).isDirectory()) {
throw new Error('The path leads to the directory');
}

fs.copyFileSync(src, dst);

return [src, dst];
}
Loading