Files
warframe-center/output/index.js
Anatoly 1c7d4cc74e
Some checks failed
continuous-integration/drone/push Build is failing
Базовый handlebars
2022-02-18 02:47:00 +03:00

40 lines
864 B
JavaScript

const fs = require('fs')
const Handlebars = require('handlebars')
const OutputItem = require('./OutputItem')
class Output {
constructor () {
this.items = []
this.timestamp = null
}
addItem (...p) {
this.items.push(new OutputItem(...p))
}
async compileTemplate () {
const templateFile = await fs.readFileSync('./output/template.hbs', 'utf8')
const template = Handlebars.compile(templateFile)
return template(this)
}
async writeToFile (content) {
const filename = 'index.html'
try {
await fs.unlinkSync(filename)
} catch {
console.log('File probably doesnt exist')
}
fs.writeFileSync(filename, content, 'utf-8')
}
async submit () {
this.timestamp = new Date()
const content = await this.compileTemplate()
await this.writeToFile(content)
}
}
module.exports = new Output()