-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 921 Bytes
/
index.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
35
36
37
38
39
40
41
const core = require('@actions/core');
const github = require('@actions/github');
const handlebars = require('handlebars');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
try {
const template = core.getInput('template');
const output = core.getInput('output');
const vars = core.getInput('vars');
fs.readFile(template, 'utf8', function(err, data){
if(err){
throw new Error(err);
}
var tpl = handlebars.compile(data)
var out = tpl(JSON.parse(vars))
if( output == "-" ){
process.stdout.write(out);
} else {
var p = path.dirname(output)
mkdirp.sync(p)
fs.writeFile(output, out, 'utf8', function(err){
if(err){
throw new Error(err)
}
console.log(`Generated templated output: ${template} -> ${output}`)
});
}
});
} catch (error) {
core.setFailed(error.message);
}