-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.js
34 lines (26 loc) · 852 Bytes
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const fs = require('fs');
const handlebars = require('handlebars');
const configJson = require('./config.json');
function compileTemplate(templateFile, config) {
handlebars.registerHelper('object', function (links) {
return JSON.stringify(links);
});
let template = handlebars.compile(templateFile);
return template(config);
}
fs.readFile('./function/url-forward.handlebars', function (err, data) {
if (err) {
console.log('Error reading file');
return err;
}
let compiledFunction = compileTemplate(data.toString(), configJson);
try {
fs.writeFileSync('./dist/url-forward-build.js', compiledFunction);
} catch (err) {
console.log('Error writing file');
return err;
}
console.log('Successfully wrote function to file');
return;
});