-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·97 lines (84 loc) · 2.34 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /usr/bin/env node
//-----------------------------------------------------------------------------
// Corona HTML5 Builder
// (c)2018 C. Byerley (develephant)
//-----------------------------------------------------------------------------
const path = require("path")
const shell = require("shelljs")
const paths = require("./lib/paths")
const { pp } = require("./lib/clr")
const watch = require('./lib/watch')
const build = require('./lib/build')
const core = require('./lib/core')
const pkg = require('./package')
const ArgParser = require('argparse').ArgumentParser
//check we are in a valid directory
if (!shell.test('-f', path.join(paths.base, 'main.lua'))) {
pp.dashes()
pp.err("You must be in a project directory to run commands.")
pp.dashes()
return
}
const parser = new ArgParser({
description: "Corona HTML5 Builder",
version: pkg.version,
prog: "coronahtml5",
epilog: '(c)2018 C. Byerley [develephant]'
})
let subparsers = parser.addSubparsers({
title: "commands",
dest: "action",
addHelp: true,
help: "Use -h, --help for command arguments."
})
let init_parser = subparsers.addParser('init', {
help: "Initialize the package.lua config file.",
})
init_parser.addArgument('--app', {
action: 'store',
help: "The Corona application project name.",
required: true,
metavar: "APP_NAME"
})
init_parser.addArgument('--html', {
action: 'store',
help: "Full path to the HTML5 output directory.",
required: true,
metavar: "HTML5_DIR"
})
let build_parser = subparsers.addParser('build', {
help: "Build the Corona HTML5 project output."
})
build_parser.addArgument('--clean', {
action: 'storeTrue',
help: "Clean the HTML5 output directory before build.",
defaultValue: false
})
let watch_parser = subparsers.addParser('watch', {
help: "Start a live browser session of the project."
})
watch_parser.addArgument(['-d', '--debug'], {
action: 'storeTrue',
help: "Open as debug session (index-debug.html).",
defaultValue: false
})
watch_parser.addArgument('--proxy', {
action: 'store',
help: "A proxy address for the session.",
metavar: "PROXY_ADDR"
})
const args = parser.parseArgs()
switch(args.action) {
case 'init':
pp.dashes()
pp.title()
pp.dashes()
core(args.app, args.html)
break
case 'build':
build(args.clean)
break
case 'watch':
watch(args.debug, args.proxy)
break
}