feat(generators): Move core code generators to shared generators package (#2982)

This commit is contained in:
David Luecke 2023-01-11 21:24:42 -08:00 committed by GitHub
parent 4b720f0588
commit 0328d22921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 2606 additions and 2437 deletions

2
.gitignore vendored
View File

@ -41,6 +41,6 @@ dist/
# TypeScript compiled files
packages/**/lib
packages/cli/test/build/*.tgz
**/build/*.tgz
*.sqlite
docs/.vitepress/cache

View File

@ -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

2311
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

2388
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -44,7 +44,7 @@
],
"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"
},
@ -52,11 +52,9 @@
"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",

View File

@ -1,68 +0,0 @@
import chalk from 'chalk'
import { Command } from 'commander'
import { generator, runGenerator, getContext } from '@feathershq/pinion'
import { FeathersBaseContext, version } from './commons'
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()
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 ')}`
)

View File

@ -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 ')}`
)

View File

@ -0,0 +1,8 @@
import { strict } from 'assert'
import { program } from '../src'
describe('cli tests', () => {
it('exports the program', async () => {
strict.ok(program)
})
})

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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/"
},

View File

@ -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).

View File

@ -0,0 +1,89 @@
{
"name": "@feathersjs/generators",
"version": "5.0.0-pre.34",
"description": "Feathers CLI core generators, powered by Pinion",
"homepage": "https://feathersjs.com",
"keywords": [
"feathers",
"pinion"
],
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/daffl"
},
"repository": {
"type": "git",
"url": "git://github.com/feathersjs/feathers.git",
"directory": "packages/commons"
},
"author": {
"name": "Feathers contributor",
"email": "hello@feathersjs.com",
"url": "https://feathersjs.com"
},
"contributors": [],
"bugs": {
"url": "https://github.com/feathersjs/feathers/issues"
},
"engines": {
"node": ">= 16"
},
"main": "lib/",
"types": "lib/",
"files": [
"CHANGELOG.md",
"LICENSE",
"README.md",
"lib/**",
"lib/app/static/.gitignore",
"*.d.ts",
"*.js"
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc && shx cp -r src/. lib/",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
"lib": "lib"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@feathershq/pinion": "^0.3.5",
"chalk": "^4.0.1",
"lodash": "^4.17.21",
"prettier": "^2.8.1"
},
"devDependencies": {
"@feathersjs/adapter-commons": "^5.0.0-pre.34",
"@feathersjs/authentication": "^5.0.0-pre.34",
"@feathersjs/authentication-client": "^5.0.0-pre.34",
"@feathersjs/authentication-local": "^5.0.0-pre.34",
"@feathersjs/authentication-oauth": "^5.0.0-pre.34",
"@feathersjs/configuration": "^5.0.0-pre.34",
"@feathersjs/errors": "^5.0.0-pre.34",
"@feathersjs/express": "^5.0.0-pre.34",
"@feathersjs/feathers": "^5.0.0-pre.34",
"@feathersjs/knex": "^5.0.0-pre.34",
"@feathersjs/koa": "^5.0.0-pre.34",
"@feathersjs/mongodb": "^5.0.0-pre.34",
"@feathersjs/rest-client": "^5.0.0-pre.34",
"@feathersjs/schema": "^5.0.0-pre.34",
"@feathersjs/socketio": "^5.0.0-pre.34",
"@feathersjs/transport-commons": "^5.0.0-pre.34",
"@feathersjs/typebox": "^5.0.0-pre.34",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.18",
"@types/prettier": "^2.7.2",
"axios": "^1.2.2",
"mocha": "^10.2.0",
"shx": "^0.3.4",
"ts-node": "^10.9.1",
"type-fest": "^3.5.0",
"typescript": "^4.9.4"
},
"gitHead": "42cca600d00f0b3b9d89fa79be30fcd46bc50132"
}

View File

@ -6,6 +6,7 @@ const template = ({
language
}: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/channels.html
import type { RealTimeConnection, Params } from '@feathersjs/feathers'
import type { AuthenticationResult } from '@feathersjs/authentication'
import '@feathersjs/transport-commons'
import type { Application, HookContext } from './declarations'
import { logger } from './logger'
@ -16,14 +17,14 @@ export const channels = (app: Application) => {
return
}
logger.warn('Publishing all events to all authenticated users. See \`channels.${language}\` and https://docs.feathersjs.com/api/channels.html for more information.')
logger.warn('Publishing all events to all authenticated users. See \`channels.${language}\` and https://dove.feathersjs.com/api/channels.html for more information.')
app.on('connection', (connection: any) => {
app.on('connection', (connection: RealTimeConnection) => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection)
})
app.on('login', (authResult: any, { connection }: Params) => {
app.on('login', (authResult: AuthenticationResult, { connection }: Params) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if(connection) {

View File

@ -0,0 +1,8 @@
export * from '@feathershq/pinion'
export * from './commons'
export * as app from './app'
export * as authentication from './authentication'
export * as connection from './connection'
export * as hook from './hook'
export * as service from './service'

View File

@ -38,7 +38,7 @@ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({})
// Schema for updating existing entries
export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
export const ${camelName}PatchSchema = Type.Partial(${camelName}DataSchema, {
$id: '${upperName}Patch'
})
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>

View File

@ -29,7 +29,7 @@ const defaultCombination = {
const combinations =
process.version > 'v16.0.0' ? (process.env.CI ? combinate(matrix as any) : [defaultCombination]) : []
describe('@feathersjs/cli', () => {
describe('@feathersjs/generators', () => {
for (const { language, framework } of combinations) {
describe(`${language} ${framework} app`, () => {
const name = `feathers_${language}_${framework}`

View File

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig",
"include": [
"src/**/*.ts"
],
"compilerOptions": {
"outDir": "lib",
"resolveJsonModule": true
}
}

View File

@ -40,7 +40,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"
},

View File

@ -38,7 +38,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"
},

View File

@ -38,7 +38,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"
},

View File

@ -40,7 +40,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"
},

View File

@ -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"
},

View File

@ -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",
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
"test": "npm run compile && npm run mocha"

View File

@ -33,7 +33,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",
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
"test": "npm run mocha"

View File

@ -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"
},

View File

@ -33,7 +33,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": "npm run mocha",
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"

View File

@ -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",
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
"test": "npm run compile && npm run mocha"