-
Notifications
You must be signed in to change notification settings - Fork 0
/
magpiler-dev.js
65 lines (59 loc) · 1.84 KB
/
magpiler-dev.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
const commandLineArgs = require('command-line-args');
const getUsage = require('command-line-usage');
const { loadData, parseOptions, startServer, DEFAULT_PORT } = require('./magpiler-core');
const optionDefinitions = [
{ name: 'port', alias: 'p', type: Number, description: "port on which server will listen (default "+DEFAULT_PORT+")"},
{ name: 'input', alias: 'i', defaultOption: true, type: String, description: "input folder to process"},
{ name: 'args', alias: 'a', type: String, description: "k1:v1,k2:v2 strings to add to options" },
{ name: 'help', alias: 'h', type: Boolean, description: "print this usage help and exit"}
];
const sections = [
{
header: 'magpiler-dev',
content: 'Xpiler for a Markdown- and JS-based website.\nRun a dev server.'
},
{
header: 'Options',
optionList: [
{
name: 'input',
typeLabel: '{underline folder}',
description: '(Default with no flags.) The input folder to process (e.g. {underline /path/to/src}).'
},
{
name: 'args',
typeLabel: '{underline k1:v1,k2:v2,...}',
description: "key value pairs to add to options object, available to config.js and global.js"
},
{
name: 'port',
typeLabel: '{underline number}',
description: "port on which server will listen (default "+DEFAULT_PORT+")"
},
{
name: 'help',
description: 'Print this usage guide.'
}
]
}
];
function serverMain(sections, options) {
options = parseOptions(sections, options);
if (!options) {
return;
}
loadData(options);
startServer(options);
}
function main(options) {
if (options) {
serverMain(options);
}
if (process.argv.length <= 2) {
console.log(getUsage(sections));
return;
}
options = commandLineArgs(optionDefinitions);
serverMain(sections, options);
}
main();