Skip to content

Commit

Permalink
feat(generators): Move core code generators to shared generators pack…
Browse files Browse the repository at this point in the history
…age (#2982)
  • Loading branch information
daffl authored Jan 12, 2023
1 parent 4b720f0 commit 0328d22
Show file tree
Hide file tree
Showing 78 changed files with 2,626 additions and 2,457 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ dist/

# TypeScript compiled files
packages/**/lib
packages/cli/test/build/*.tgz
**/build/*.tgz
*.sqlite
docs/.vitepress/cache
4 changes: 2 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"timeout": 20000,
"require": [ "ts-node/register", "source-map-support/register" ],
"timeout": 30000,
"require": ["ts-node/register", "source-map-support/register"],
"reporter": "Dot",
"extension": ".test.ts",
"exit": true
Expand Down
2,311 changes: 1,218 additions & 1,093 deletions docs/package-lock.json

Large diffs are not rendered by default.

2,428 changes: 1,168 additions & 1,260 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/adapter-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"types": "lib/",
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"types": "lib/",
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"scripts": {
"start": "ts-node test/app",
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc && shx cp -r src/. lib/",
"compile": "shx rm -rf lib/ && tsc",
"mocha": "mocha --timeout 60000 --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
"test": "npm run compile && npm run mocha"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@feathershq/pinion": "^0.3.5",
"chalk": "^4.0.1",
"commander": "^9.4.1",
"lodash": "^4.17.21",
"prettier": "^2.8.1"
"chalk": "^4.0.1",
"@feathersjs/generators": "^5.0.0-pre.34"
},
"devDependencies": {
"@feathersjs/adapter-commons": "^5.0.0-pre.34",
Expand Down
68 changes: 0 additions & 68 deletions packages/cli/src/cli.ts

This file was deleted.

71 changes: 69 additions & 2 deletions packages/cli/src/index.ts
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 ')}`
)
8 changes: 8 additions & 0 deletions packages/cli/test/cli.test.ts
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)
})
})
2 changes: 1 addition & 1 deletion packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "NODE_CONFIG_DIR=./test/config mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/feathers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"prepublish": "npm run compile",
"version": "npm run write-version",
"publish": "npm run reset-version",
"pack": "npm pack --pack-destination ../cli/test/build",
"pack": "npm pack --pack-destination ../generators/test/build",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/"
},
Expand Down
23 changes: 23 additions & 0 deletions packages/generators/README.md
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).
Loading

0 comments on commit 0328d22

Please # to comment.