-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (21 loc) · 917 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
const ejs = require('ejs')
const fs = require('fs')
const yaml = require('js-yaml')
const program = require('commander')
const { exec } = require('child_process')
const defaultSource = './Content/content.yaml'
program
.option('-m, --markup', 'compile markup only, no document')
.option('-s, --source <content>', 'file to provide copy, defaults to content.yaml', defaultSource)
.option('-o, --dont-open', 'open in browser')
.parse(process.argv)
const output = program.args[0] ? `${program.args[0]}.html` : 'MTAFlyer.html'
const data = yaml.safeLoad(fs.readFileSync(program.source, 'utf8'))
const document = program.markup ? 'Poster.ejs' : 'Head.ejs'
const options = { rmWhitespace: true }
ejs.renderFile(`./Templates/${document}`, data, options, function(err, str) {
if(err) {
throw err}
fs.writeFileSync(`./Build/${output}`, str)})
if(!program.dontOpen) {
exec('open ' + `./Build/${output}`)}