-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·63 lines (58 loc) · 1.83 KB
/
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
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
#!/usr/bin/env node
const chalk = require('chalk')
const sywac = require('sywac')
const cli = sywac.command('setup', {
desc: 'Create templates from an Itch.io project, profile, or jam URL',
setup: sywac => {
sywac.positional('<url>', { paramsDesc: 'Project, profile, or jam URL' })
.check((argv, ctx) => {
if (argv.url) {
try {
const URL = require("url").URL
const url = new URL(argv.url)
if (! (/(^|\.)itch\.io$/.test(url.host) && ['https:', 'http:'].includes(url.protocol))) {
ctx.cliMessage(chalk`{red ${argv.url} is not a valid itch.io url}`)
}
} catch(err) {
ctx.cliMessage(chalk`{red ${argv.url} is not a valid url}`)
}
}
})
},
run (argv, context) {
require('./lib/template')(argv.url)
}
}).command('serve', {
desc: 'Run local development server',
setup: sywac => {
sywac.string(chalk`{green --host} {blue <hostname>}`, { desc: 'Development server host', defaultValue: '127.0.0.1' })
.number(chalk`{green -p, --port} {blue <number>}`, { desc: 'Development server port', defaultValue: 1234 })
},
run (argv, context) {
require('./lib/proxy').serve(argv.host, argv.port)
}
}).command('build', {
desc: 'Compile custom html and scss',
setup: sywac => {
sywac.boolean('--no-minify', {
desc: 'Disable CSS and HTML minification',
defaultValue: false
})
},
run (argv, context) {
require('./lib/proxy').build({ minify: !argv['no-minify'] })
}
}).help('-h, --help')
.style({
flags: s => chalk.green(s),
desc: s => chalk.white(s),
hints: s => chalk.dim(s)
})
.version('-v, --version')
.showHelpByDefault()
.outputSettings({ maxWidth: 75 })
module.exports = cli
async function main () {
cli.parseAndExit()
}
if (require.main === module) main()