-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Improve CLI interface (#2753)
- Loading branch information
Showing
14 changed files
with
270 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
'use strict' | ||
|
||
const { yargs } = require('@feathershq/pinion') | ||
const { command } = require('../lib') | ||
const { program } = require('../lib') | ||
|
||
const cli = cmd => command(yargs(cmd)).argv | ||
|
||
cli(process.argv.slice(2)); | ||
program.parse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import chalk from 'chalk' | ||
import { Command } from 'commander' | ||
import { generator, runGenerator, getContext } from '@feathershq/pinion' | ||
import { FeathersBaseContext, version } from './commons' | ||
|
||
export * from 'commander' | ||
|
||
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() | ||
|
||
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 ')}` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,2 @@ | ||
import { Argv, generator, runGenerator, getContext } from '@feathershq/pinion' | ||
import { FeathersBaseContext, initializeBaseContext } from './commons' | ||
|
||
export const commandRunner = (yarg: any) => { | ||
const ctx = getContext<FeathersBaseContext>({ | ||
...yarg.argv | ||
}) | ||
|
||
return generate(ctx) | ||
} | ||
|
||
export const generate = (ctx: FeathersBaseContext) => | ||
generator(ctx) | ||
.then(initializeBaseContext()) | ||
.then(runGenerator(__dirname, (ctx: FeathersBaseContext) => `${ctx._[1]}`, 'index')) | ||
|
||
export const command = (yargs: Argv) => | ||
yargs | ||
.command('generate', 'Run a generator', (yarg) => | ||
yarg | ||
.command('app', 'Generate a new app', commandRunner) | ||
.command('service', 'Generate a service', commandRunner) | ||
.command('hook', 'Generate a hook', commandRunner) | ||
.command('connection', 'Connect to a different database', commandRunner) | ||
.command('authentication', 'Set up authentication with a custom entity', commandRunner) | ||
) | ||
.usage('Usage: $0 <command> [options]') | ||
.help() | ||
export * from './cli' | ||
export * from './commons' |
Oops, something went wrong.