From 0ba8c21d5dd1ff2dec214dfb01e006c3e32483fa Mon Sep 17 00:00:00 2001 From: BodyaKuts Date: Thu, 19 Sep 2024 13:49:59 +0300 Subject: [PATCH] solution --- src/app.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/app.js b/src/app.js index ad9a93a..10100da 100644 --- a/src/app.js +++ b/src/app.js @@ -1 +1,40 @@ +/* eslint-disable no-console */ 'use strict'; + +const fs = require('fs'); + +const [inputPath, outputPath] = process.argv.slice(2); + +async function copyFile(from, to) { + let isItFile = true; + + fs.stat(from, (err, stats) => { + if (err) { + console.error('File not found!'); + + return false; + } + + isItFile = stats.isFile(); + }); + + if (from && to && isItFile && from !== to) { + try { + const fileData = fs.readFileSync(from, 'utf-8'); + + fs.writeFileSync(to, fileData); + } catch (err) { + console.error(err); + } + + console.log('\x1b[32m', 'File was copied succesfully!'); + + return; + } + + console.error('File not found!'); +} + +copyFile(inputPath, outputPath); + +module.exports = { copyFile };