-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
64 lines (57 loc) · 2.07 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
#!/usr/bin/env node
const path = require('upath')
const open = require('open')
const chalk = require('chalk')
const pkg = require('./package.json')
const server = require('./lib/server')
const compiler = require('./lib/compiler')
const args = require('minimist')(process.argv.slice(2))
const command = args._[0]
if (args.v || args.version) version()
if (!command) usage()
if (args._[1]) var sourceDir = path.resolve(process.cwd(), args._[1])
if (args._[2]) var targetFile = path.resolve(process.cwd(), args._[2])
process.env.CONTEXTER_PORT = args.port || args.p || 3000
process.env.CONTEXTER_IGNORES = args.ignore || args.i || './node_modules'
if (args.all || args.a) process.env.CONTEXTER_WATCH_ALL = true
switch(command) {
case 'sers':
case 'serve':
case 'server':
case 'servez':
case 'servons':
server.start(sourceDir)
break
case 'compile':
case 'build':
case 'extract':
case 'write':
compiler.start(sourceDir, targetFile)
break
case 'help':
case 'docs':
open('https://www.npmjs.com/package/contexter-cli')
break
default:
console.log(`Unrecognized command: ${command}\n`)
usage()
}
function usage() {
console.log(
`
contexter serve Serve the current directory
contexter serve <source-dir> Serve a specific directory
contexter serve <source-dir> --port 1337 Use a custom port. Default is 3000
contexter serve <source-dir> --all Serve all files (even those not datafile nor image)
contexter serve <source-dir> --ignore <ignore-dir> Default is 'node_modules'
contexter write <source-dir> <target-file> Write source directory to file
contexter write <source-dir> Write source directory to stdout
contexter help Open npm README in your browser
`)
console.log(chalk.dim(` version ${pkg.version}`))
process.exit()
}
function version() {
console.log(pkg.version)
process.exit()
}