{"size": 1560, "ext": "js", "max_stars_repo_path": "05-merge-styles/index.js", "max_stars_repo_name": "RomanKostyrin/HTML-builder-1", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "05-merge-styles/index.js", "max_issues_repo_name": "RomanKostyrin/HTML-builder-1", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05-merge-styles/index.js", "max_forks_repo_name": "RomanKostyrin/HTML-builder-1", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.1612903226, "max_line_length": 88, "alphanum_fraction": 0.5897435897}
const fs = require('fs');
const { mkdir, readdir } = require('fs').promises;
const path = require('path');
const pathToFolder = path.join(__dirname, 'project-dist');

async function getData() {
  try {
    const data = [];
    const pathToFiles = path.join(__dirname, 'styles');

    const writeableStream = fs.createWriteStream(path.join(pathToFolder, 'bundle.css'));
    const files = await readdir(pathToFiles, {
      withFileTypes: true,
    });
    for (const file of files) {
      const pathToFile = path.join(pathToFiles, file.name);
      const readableStream = fs.createReadStream(pathToFile, 'utf8');
      const f = path.parse(pathToFile);
      if (file.isFile() && f.ext.slice(1) === 'css') {
        for await (const chunk of readableStream) {
          data.push(chunk);
        }
      }
    }
    for (const row of data) {
      writeableStream.write(row);
    }
  } catch (err) {
    console.error(err);
  }
}

async function makeDir() {
  try {
    console.log('create directory project-dist...');
    console.log('---------------------------');
    await mkdir(pathToFolder, { recursive: true });
  } catch (err) {
    console.error(err);
  }
}

async function makeFile() {
  try {
    console.log('create file bundle.css...');
    console.log('---------------------------');
    fs.appendFile(path.join(pathToFolder, 'bundle.css'), '', function (err) {
      if (err) throw err;
    });
  } catch (err) {
    console.error(err);
  }
}

async function startApp() {
  await makeDir();
  await makeFile();
  await getData();
}

startApp();
