Files
warframe-center/output/index.js
Anatoly 9afda59e27
Some checks failed
continuous-integration/drone/push Build was killed
Split style into own file
2022-02-18 16:16:48 +03:00

40 lines
873 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 = './public/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()