From 9f1e4f5ef43b534d0ff0b3077acfb71a3324e961 Mon Sep 17 00:00:00 2001 From: tihon228supermegaproIT <119882092+tihon228supermegaproIT@users.noreply.github.com> Date: Wed, 3 May 2023 18:01:00 +0300 Subject: [PATCH 1/5] Update index.js --- 01-read-file/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/01-read-file/index.js b/01-read-file/index.js index e69de29bb..001f6d272 100644 --- a/01-read-file/index.js +++ b/01-read-file/index.js @@ -0,0 +1,9 @@ +const fs = require('fs'); + +fs.readFile('./text.txt', 'utf8', (err, data) => { + if (err) { + console.error(err); + } else { + console.log(data); + } +}); From 719caa4c013180582e78acfb11233c0160014b18 Mon Sep 17 00:00:00 2001 From: tihon228supermegaproIT <119882092+tihon228supermegaproIT@users.noreply.github.com> Date: Wed, 3 May 2023 18:04:29 +0300 Subject: [PATCH 2/5] Update index.js --- 02-write-file/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/02-write-file/index.js b/02-write-file/index.js index e69de29bb..0c7467103 100644 --- a/02-write-file/index.js +++ b/02-write-file/index.js @@ -0,0 +1,18 @@ +const fs = require('fs'); +const readline = require('readline'); + +console.log('Привет! Введи текст для записи в файл:'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.on('line', (text) => { + fs.writeFile('text.txt', text, (err) => { + if (err) throw err; + + console.log(`Текст "${text}" успешно записан в файл text.txt`); + rl.close(); + }); +}); From 87ef189ae1cc812de7f03410b7643e5289c8c76e Mon Sep 17 00:00:00 2001 From: tihon228supermegaproIT <119882092+tihon228supermegaproIT@users.noreply.github.com> Date: Wed, 3 May 2023 18:14:00 +0300 Subject: [PATCH 3/5] Update index.js --- 03-files-in-folder/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/03-files-in-folder/index.js b/03-files-in-folder/index.js index e69de29bb..3b2b0462c 100644 --- a/03-files-in-folder/index.js +++ b/03-files-in-folder/index.js @@ -0,0 +1,13 @@ +const fs = require('fs'); + +const folderPath = './03-files-in-folder/secret-folder'; + +fs.readdir(folderPath, (err, files) => { + if (err) { + console.error('Error reading directory:', err); + return; + } + + console.log(`Files in directory ${folderPath}:`); + files.forEach(file => console.log(file)); +}); From bd8aa47f910298768b727d47f0d2c59f9db34882 Mon Sep 17 00:00:00 2001 From: tihon228supermegaproIT <119882092+tihon228supermegaproIT@users.noreply.github.com> Date: Wed, 3 May 2023 18:19:44 +0300 Subject: [PATCH 4/5] Update index.js --- 04-copy-directory/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/04-copy-directory/index.js b/04-copy-directory/index.js index 8b1378917..a2c9d1fac 100644 --- a/04-copy-directory/index.js +++ b/04-copy-directory/index.js @@ -1 +1,23 @@ +const fs = require('fs'); +function copyDir(sourceDir, targetDir) { + if (!fs.existsSync(sourceDir)) { + throw new Error(`Source directory "${sourceDir}" does not exist`); + } + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir); + } + const files = fs.readdirSync(sourceDir); + files.forEach((file) => { + const sourcePath = `${sourceDir}/${file}`; + const targetPath = `${targetDir}/${file}`; + const stat = fs.statSync(sourcePath); + if (stat.isDirectory()) { + copyDir(sourcePath, targetPath); + } else { + fs.copyFileSync(sourcePath, targetPath); + } + }); +} + +copyDir('./files', './files-copy'); From 7f552fee3794711ca23a2f3c783bc12431049b08 Mon Sep 17 00:00:00 2001 From: tihon228supermegaproIT <119882092+tihon228supermegaproIT@users.noreply.github.com> Date: Thu, 4 May 2023 22:09:41 +0300 Subject: [PATCH 5/5] Update index.js --- 05-merge-styles/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/05-merge-styles/index.js b/05-merge-styles/index.js index e69de29bb..2bffc8f74 100644 --- a/05-merge-styles/index.js +++ b/05-merge-styles/index.js @@ -0,0 +1,21 @@ +const fs = require('fs'); +const concat = require('concat'); + +const stylesFolderPath = './styles'; +const outputFilePath = './project-dist/bundle.css'; + +fs.readdir(stylesFolderPath, (err, files) => { + if (err) { + throw err; + } + + const fileContents = files.map((fileName) => { + return fs.readFileSync(`${stylesFolderPath}/${fileName}`, 'utf-8'); + }); + + const concatenatedContents = concat(fileContents); + + fs.writeFileSync(outputFilePath, concatenatedContents, 'utf-8'); + + console.log('Styles merged successfully'); +});