1 | #!/usr/bin/env node
|
2 | 'use strict'
|
3 |
|
4 | const fs = require('fs')
|
5 | const meow = require('meow')
|
6 | const path = require('path')
|
7 |
|
8 | const 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 |
|
38 | if (!cli.input.length) cli.showHelp()
|
39 |
|
40 |
|
41 | const command = require('../src')[cli.input.shift()]
|
42 |
|
43 |
|
44 | if (!command) cli.showHelp()
|
45 |
|
46 |
|
47 | if (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 | }
|