-
-
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(generators): Move core code generators to shared generators pack…
…age (#2982)
- Loading branch information
Showing
78 changed files
with
2,626 additions
and
2,457 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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,2 +1,69 @@ | ||
export * from './cli' | ||
export * from './commons' | ||
import chalk from 'chalk' | ||
import { Command } from 'commander' | ||
import { dirname } from 'path' | ||
import { generator, runGenerator, getContext, FeathersBaseContext, version } from '@feathersjs/generators' | ||
|
||
export * from 'commander' | ||
export { chalk } | ||
|
||
export const commandRunner = (name: string) => async (options: any) => { | ||
const folder = dirname(require.resolve('@feathersjs/generators')) | ||
const ctx = getContext<FeathersBaseContext>({ | ||
...options | ||
}) | ||
|
||
await generator(ctx) | ||
.then(runGenerator(folder, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { strict } from 'assert' | ||
import { program } from '../src' | ||
|
||
describe('cli tests', () => { | ||
it('exports the program', async () => { | ||
strict.ok(program) | ||
}) | ||
}) |
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
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,23 @@ | ||
# @feathersjs/generators | ||
|
||
[![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI) | ||
[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/socketio)](https://david-dm.org/feathersjs/feathers?path=packages/generators) | ||
[![Download Status](https://img.shields.io/npm/dm/@feathersjs/generators.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/cli) | ||
|
||
> Feathers core code generators used by the CLI powered by [Pinion](https://github.com/feathershq/pinion/) | ||
## Installation | ||
|
||
``` | ||
npm install @feathersjs/generators --save-dev | ||
``` | ||
|
||
## Documentation | ||
|
||
Refer to the [Feathers documentation](https://docs.feathersjs.com) for more details. | ||
|
||
## License | ||
|
||
Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) | ||
|
||
Licensed under the [MIT license](LICENSE). |
Oops, something went wrong.