RenaiApp/templates/index.js

25 lines
755 B
JavaScript

const fs = require('fs');
const path = require('path');
const handlebars = require('handlebars');
const packageJson = require('../package');
function compile(isDevMode = false) {
const dataPath = path.resolve(__dirname, 'data.json');
const data = JSON.parse(fs.readFileSync(dataPath).toString());
const templatePath = path.resolve(__dirname, 'index.html.handlebars');
const template = fs.readFileSync(templatePath).toString();
const delegate = handlebars.compile(template);
let extendedData;
if (isDevMode) {
extendedData = data.dev;
} else {
extendedData = data.prod;
}
extendedData.appBundle = './bundle.js';
extendedData.appTitle = packageJson.productName;
return delegate(extendedData);
}
exports.compile = compile;