-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·55 lines (49 loc) · 1.48 KB
/
cli.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
const Input = require('./lib/config/input.js');
const { hoppla } = require('./lib/hoppla.js');
const argv = require('yargs')
.options({
t: { alias: 'template', describe: 'Path to template folder', type: 'string', demandOption: true },
d: { alias: 'destination', describe: 'Path to destination folder', type: 'string', default: '.' },
i: { alias: 'input', describe: 'HJSON input data', type: 'string'},
f: { alias: 'force', describe: 'Overwrites existing files', type: 'boolean' },
'ed': { alias: 'ejs-delimiter', describe: 'Which EJS delimiter to use', type: 'string', default: '%'}
})
.argv
const startHoppla = function(input) {
if (input === false) {
return;
}
try {
hoppla({
template: argv.template,
destination: argv.destination,
force: argv.force,
ejsOptions: {
delimiter: argv['ejs-delimiter']
},
input
})
}
catch(err) {
console.error(err);
}
}
Promise.resolve()
.then(() => {
var input = argv.input;
if (input != null) {
if (input === '') {
return Input.getFromStdin();
}
return input;
}
return '{}'
})
.then(Input.parse)
.catch((err) => {
console.error('Input was not readable as HJSON')
console.error(err);
return false;
})
.then(startHoppla)