writeOutputFile.js 446 B

12345678910111213141516
  1. 'use strict';
  2. const path = require('path');
  3. const { mkdir } = require('fs').promises;
  4. const stripAnsi = require('strip-ansi');
  5. const writeFileAtomic = require('write-file-atomic');
  6. /**
  7. * @param {string} content
  8. * @param {string} filePath
  9. * @returns {Promise<void>}
  10. */
  11. module.exports = (content, filePath) =>
  12. mkdir(path.dirname(filePath), { recursive: true }).then(() =>
  13. writeFileAtomic(path.normalize(filePath), stripAnsi(content)),
  14. );