Skip to content

Commit

Permalink
fix(cli): Improve generated application and client (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Aug 3, 2022
1 parent 8d7e04a commit bd55ffb
Show file tree
Hide file tree
Showing 31 changed files with 1,084 additions and 1,509 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i npm -g
- run: npm install -g codeclimate-test-reporter
- run: npm install
- run: npm test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ dist/

# TypeScript compiled files
packages/**/lib
packages/cli/test/*.tgz
*.sqlite
2,499 changes: 1,022 additions & 1,477 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
"prettier": "npx prettier \"packages/{,!(node_modules)/**/(src|test)/**/}*.ts\" --write",
"eslint": "eslint \"packages/**/*.ts\" --fix",
"lint": "npm run prettier && npm run eslint",
"compile": "lerna run compile",
"update-dependencies": "ncu -u && lerna exec -- ncu -u -x node-fetch -x chalk",
"clean": "find . -name node_modules -exec rm -rf '{}' + && find . -name package-lock.json -exec rm -rf '{}' +",
"test:deno": "deno test --config deno/tsconfig.json deno/test.ts",
"test": "npm run lint && lerna run compile && c8 lerna run test --ignore @feathersjs/tests"
"test": "npm run lint && npm run compile && c8 lerna run test --ignore @feathersjs/tests --ignore @feathersjs/adapter-commons"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.31.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"types": "lib/",
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"types": "lib/",
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication-oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"scripts": {
"start": "ts-node test/app",
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
},
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/app/templates/declarations.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface ServiceTypes {}
// The application instance type that will be used everywhere else
export type Application = FeathersApplication<ServiceTypes, Configuration>
export type HookContext = FeathersHookContext<Application>
// The context for hook functions - can be typed with a service class
export type HookContext<S = any> = FeathersHookContext<Application, S>
`

export const generate = (ctx: AppGeneratorContext) =>
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/app/templates/package.json.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ const packageJson = ({
lib,
test
},
main: `${lib}/`,
browser: language === 'ts' ? 'dist/client' : `${lib}/client`,
main: language === 'ts' ? 'lib/client' : `${lib}/client`,
...(language === 'ts' ? tsPackageJson(lib) : jsPackageJson(lib))
})

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/app/templates/tsconfig.json.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const generate = (ctx: AppGeneratorContext) =>
module: 'commonjs',
outDir: './lib',
rootDir: `./${lib}`,
declaration: true,
strict: true,
esModuleInterop: true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
schema: ${camelName}DataSchema,
validate: 'before',
properties: {
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
}
})
Expand All @@ -41,7 +41,9 @@ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
schema: ${camelName}PatchSchema,
validate: 'before',
properties: {}
properties: {
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
}
})
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/hook/templates/hook.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HookGeneratorContext } from '../index'
import { renderSource } from '../../commons'

const aroundTemplate = ({ camelName, name }: HookGeneratorContext) => `
import { HookContext, NextFunction } from '../declarations'
import type { HookContext, NextFunction } from '../declarations'
export const ${camelName} = async (context: HookContext, next: NextFunction) => {
console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
Expand All @@ -12,8 +12,9 @@ export const ${camelName} = async (context: HookContext, next: NextFunction) =>
`

const regularTemplate = ({
camelName
}: HookGeneratorContext) => `import { HookContext } from '../declarations'
camelName,
name
}: HookGeneratorContext) => `import type { HookContext } from '../declarations'
export const ${camelName} = async (context: HookContext) => {
console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/service/templates/client.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const schemaImports = ({ upperName, folder, fileName }: ServiceGeneratorContext)
${upperName}Data,
${upperName}Result,
${upperName}Query,
} from './services/${folder.join('/')}/${fileName}.schema'`
} from './services/${folder.join('/')}/${fileName}.schema'
export * from './services/${folder.join('/')}/${fileName}.schema'`

const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
` '${path}': Service<${upperName}Data, ${upperName}Result, Params<${upperName}Query>>`
` '${path}': Service<${upperName}Result, ${upperName}Data, Params<${upperName}Query>>`

const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client.ts'])

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import pkg from '../package.json'
import { DependencyVersions } from '../src/commons'
import lernaConfig from '../../../lerna.json'

export function combinate<O extends Record<string | number, any[]>>(obj: O) {
let combos: { [k in keyof O]: O[k][number] }[] = []
Expand All @@ -23,7 +24,7 @@ export const dependencyVersions = Object.keys(pkg.devDependencies as any)
.reduce((acc, dep) => {
const [, name] = dep.split('/')

acc[dep] = `file://${path.join(__dirname, '..', '..', name)}`
acc[dep] = path.join(__dirname, `feathersjs-${name}-${lernaConfig.version}.tgz`)

return acc
}, {} as DependencyVersions)
3 changes: 2 additions & 1 deletion packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"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"
},
"semistandard": {
Expand Down
3 changes: 2 additions & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/feathers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"prepublish": "npm run compile",
"version": "npm run write-version",
"publish": "npm run reset-version",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/knex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**/*.test.ts"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/rest-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"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"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/socketio-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"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"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/socketio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"compile": "shx rm -rf lib/ && tsc && npm run pack",
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion packages/transport-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"pack": "npm pack --pack-destination ../cli/test",
"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"
},
Expand Down

0 comments on commit bd55ffb

Please sign in to comment.