in src/lib/emitter.js [68:99]
save(append = false) {
if (!this.config.dir) {
throw new Error('`option.dir` should not be empty');
}
if (!this.config.filename) {
throw new Error('filename cannot be empty');
}
const targetPath = this.savePath();
if (!fs.existsSync(path.dirname(targetPath))) {
fs.mkdirSync(path.dirname(targetPath), {
recursive: true
});
}
if (append && fs.existsSync(targetPath)) {
fs.appendFileSync(targetPath, this.output);
} else {
fs.writeFileSync(targetPath, this.output);
}
this.output = '';
const consoleInfo = append ? 'append file : ' : 'save path : ';
if (this.config.showInfo) {
console.log('');
console.log(`\x1b[32${consoleInfo}${path.resolve(targetPath)}\x1b[0m`);
console.log('');
}
}