UNPKG

1.18 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict'
3
4const fs = require('fs')
5const meow = require('meow')
6const path = require('path')
7
8const cli = meow(`
9 Usage:
10 $ mightymite [command] [options]
11
12 Commands:
13 build # Build api from content files
14 watch # Trigger build on file change
15
16 Options
17 --src # Specify content directory
18 --out # Specify output directory
19 --config # Specify config file
20
21 Examples
22 $ mightymite build --src content --out api
23`, {
24 flags: {
25 src: {
26 type: 'string'
27 },
28 out: {
29 type: 'string'
30 },
31 config: {
32 type: 'string'
33 }
34 }
35})
36
37// Show help if no commands are passed
38if (!cli.input.length) cli.showHelp()
39
40// Import command
41const command = require('../src')[cli.input.shift()]
42
43// Show help if command isn't recognized
44if (!command) cli.showHelp()
45
46// If config was passed, use custom config file
47if (cli.flags.config) {
48 try {
49 const config = require(path.join(process.cwd(), cli.flags.config))
50 command.apply(null, [ config ])
51 } catch (err) {
52 console.error(`No config file found at: ${cli.flags.config}`)
53 }
54} else {
55 command.apply(null, cli.input.concat(cli.flags))
56}