@viewdo/dxp-story-cli
Version:
README.md
34 lines (29 loc) • 970 B
JavaScript
const path = require('path');
const fs = require('fs');
class HtmlWriter {
constructor(console = console) {
Object.assign(this, {
path,
console,
fs
});
}
write(data ={}, file_path) {
const { fs,path } = this;
const { labelHTML, html = "" } = data;
const html_contents = labelHTML ? labelHTML : html;
if (fs.existsSync(file_path)) {
if(this.console.debug) this.console.debug(`Can't create file, ${file_path}, because it already exists!`)
return;
};
if(this.console.debug) this.console.debug(`Creating file ${file_path}.`)
try {
fs.writeFileSync(path.resolve(file_path), html_contents);
if(this.console.debug) this.console.debug(`Finished creating file ${file_path}.`)
} catch (err) {
this.console.error(err);
throw err;
}
}
}
module.exports = HtmlWriter;