-
-
Notifications
You must be signed in to change notification settings - Fork 797
Expand file tree
/
Copy pathcli.ts
More file actions
71 lines (57 loc) · 1.95 KB
/
cli.ts
File metadata and controls
71 lines (57 loc) · 1.95 KB
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
import chalk from 'chalk'
import { Command } from 'commander'
import { generator, runGenerator, getContext } from '@feathershq/pinion'
import { FeathersBaseContext, version } from './commons'
import { cloudLogin } from './cloud'
export * from 'commander'
export { chalk }
export const commandRunner = (name: string) => async (options: any) => {
const ctx = getContext<FeathersBaseContext>({
...options
})
await generator(ctx)
.then(runGenerator(__dirname, name, 'index'))
.catch((error) => {
const { logger } = ctx.pinion
logger.error(`Error: ${chalk.white(error.message)}`)
})
}
export const program = new Command()
program
.name('feathers')
.description('The Feathers command line interface 🕊️')
.version(version)
.showHelpAfterError()
program.command('login').action(cloudLogin)
const generate = program.command('generate').alias('g')
generate
.command('app')
.description('Generate a new application')
.option('--name <name>', 'The name of the application')
.action(commandRunner('app'))
generate
.command('service')
.description('Generate a new service')
.option('--name <name>', 'The service name')
.option('--path <path>', 'The path to register the service on')
.option('--type <type>', 'The service type (knex, mongodb, custom)')
.action(commandRunner('service'))
generate
.command('hook')
.description('Generate a hook')
.option('--name <name>', 'The name of the hook')
.option('--type <type>', 'The hook type (around or regular)')
.action(commandRunner('hook'))
generate
.command('connection')
.description('Add a new database connection')
.action(commandRunner('connection'))
generate
.command('authentication')
.description('Add authentication to the application')
.action(commandRunner('authentication'))
generate.description(
`Run a generator. Currently available: \n ${generate.commands
.map((cmd) => `${chalk.blue(cmd.name())}: ${cmd.description()} `)
.join('\n ')}`
)