-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
cli.js
executable file
·70 lines (63 loc) · 1.43 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env node
var fs = require('fs')
var exit = require('exit')
var parseArgs = require('minimist')
var createHTML = require('./index')
var argv = parseArgs(process.argv.slice(2), {
alias: {
t: 'title',
l: 'lang',
b: 'body',
d: 'dir',
H: 'head',
f: 'favicon',
c: 'css',
C: ['css-async', 'cssAsync'],
s: 'script',
a: ['script-async', 'scriptAsync'],
o: 'output',
h: 'help'
},
string: [
'output'
],
boolean: [
'script-async',
'css-async'
]
})
var usage = `
Usage:
create-html [options]
Options:
--title, -t Page title
--script, -s JavaScript filename, optional
--script-async, -a Add async attribute to script tag
--css, -c CSS filename, optional
--css-async, -C Load CSS asynchronously
--favicon, -f Site favicon
--lang, -l Language of content
--dir, -d Direction of content
--head, -H Content to insert into <head> tag
--body, -b Content to insert into <body> tag
--output, -o File name. optional. default: stdout
--help, -h Show this help message
`
if (argv.help) {
console.log(usage)
exit()
}
if (argv.output && argv.output.length) {
fs.writeFile(argv.output, createHTML(argv), function (err) {
if (err) {
console.log(`
Error:
${err}
Usage:
${usage}
`)
}
})
} else {
process.stdout.write(createHTML(argv))
}