All files / lib create-file.js

71.43% Statements 5/7
50% Branches 1/2
100% Functions 2/2
71.43% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29            1x                   1x 1x 1x     1x              
/**
 * Create file module
 *
 * This module is mainly responsible for generating the output file.
 */
 
import fs from 'fs'
 
/**
 * createFile - Given a name for a file and a final generated model, creates
 * the output file.
 * @param {String} fileName The name of the output file
 * @param {Object} data An object containing parsed and generated models.
 * @return {Void}
 */
export function createFile(fileName, data) {
  try {
    fs.writeFile(`${process.cwd()}/${fileName}`, data, 'utf8', function (err) {
      Iif (err) {
        throw new Error(err)
      }
      console.log('\x1b[32m', `Your file has been saved in ${process.cwd()}/output/${fileName}.`);
    });
  }
  catch (err) {
    console.error(err)
  }
}