@feathersjs/generators 5.0.27 → 5.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/app/index.d.ts +3 -3
  3. package/lib/app/index.js +1 -2
  4. package/lib/app/index.js.map +1 -1
  5. package/lib/app/templates/gitignore.tpl.d.ts +5 -0
  6. package/lib/app/{static/.gitignore → templates/gitignore.tpl.js} +5 -1
  7. package/lib/app/templates/gitignore.tpl.js.map +1 -0
  8. package/lib/authentication/index.d.ts +3 -3
  9. package/lib/commons.d.ts +4 -4
  10. package/lib/commons.js +4 -0
  11. package/lib/commons.js.map +1 -1
  12. package/lib/hook/index.d.ts +2 -2
  13. package/package.json +32 -33
  14. package/lib/app/index.ts +0 -215
  15. package/lib/app/templates/app.test.tpl.ts +0 -50
  16. package/lib/app/templates/app.tpl.ts +0 -141
  17. package/lib/app/templates/channels.tpl.ts +0 -54
  18. package/lib/app/templates/client.test.tpl.ts +0 -28
  19. package/lib/app/templates/client.tpl.ts +0 -53
  20. package/lib/app/templates/configuration.tpl.ts +0 -89
  21. package/lib/app/templates/declarations.tpl.ts +0 -42
  22. package/lib/app/templates/index.html.tpl.ts +0 -44
  23. package/lib/app/templates/index.tpl.ts +0 -26
  24. package/lib/app/templates/logger.tpl.ts +0 -56
  25. package/lib/app/templates/package.json.tpl.ts +0 -78
  26. package/lib/app/templates/prettierrc.tpl.ts +0 -14
  27. package/lib/app/templates/readme.md.tpl.ts +0 -57
  28. package/lib/app/templates/services.tpl.ts +0 -20
  29. package/lib/app/templates/tsconfig.json.tpl.ts +0 -29
  30. package/lib/app/templates/validators.tpl.ts +0 -39
  31. package/lib/authentication/index.ts +0 -119
  32. package/lib/authentication/templates/authentication.tpl.ts +0 -52
  33. package/lib/authentication/templates/client.test.tpl.ts +0 -78
  34. package/lib/authentication/templates/config.tpl.ts +0 -60
  35. package/lib/authentication/templates/declarations.tpl.ts +0 -38
  36. package/lib/commons.ts +0 -341
  37. package/lib/connection/index.ts +0 -138
  38. package/lib/connection/templates/knex.tpl.ts +0 -73
  39. package/lib/connection/templates/mongodb.tpl.ts +0 -50
  40. package/lib/hook/index.ts +0 -52
  41. package/lib/hook/templates/hook.tpl.ts +0 -33
  42. package/lib/index.ts +0 -8
  43. package/lib/service/index.ts +0 -214
  44. package/lib/service/templates/client.tpl.ts +0 -33
  45. package/lib/service/templates/schema.json.tpl.ts +0 -143
  46. package/lib/service/templates/schema.typebox.tpl.ts +0 -131
  47. package/lib/service/templates/service.tpl.ts +0 -161
  48. package/lib/service/templates/shared.tpl.ts +0 -64
  49. package/lib/service/templates/test.tpl.ts +0 -33
  50. package/lib/service/type/custom.tpl.ts +0 -112
  51. package/lib/service/type/knex.tpl.ts +0 -105
  52. package/lib/service/type/mongodb.tpl.ts +0 -64
package/lib/commons.ts DELETED
@@ -1,341 +0,0 @@
1
- import fs from 'fs'
2
- import { join, dirname } from 'path'
3
- import { PackageJson } from 'type-fest'
4
- import { readFile, writeFile } from 'fs/promises'
5
- import {
6
- Callable,
7
- PinionContext,
8
- loadJSON,
9
- fromFile,
10
- getCallable,
11
- renderTemplate,
12
- inject,
13
- Location,
14
- exec
15
- } from '@featherscloud/pinion'
16
- import ts from 'typescript'
17
- import prettier, { Options as PrettierOptions } from 'prettier'
18
- import path from 'path'
19
- import { fileURLToPath } from 'url'
20
-
21
- // Set __dirname in es module
22
- const __dirname = dirname(fileURLToPath(import.meta.url))
23
-
24
- export const { version } = JSON.parse(fs.readFileSync(join(__dirname, '..', 'package.json')).toString())
25
-
26
- export type DependencyVersions = { [key: string]: string }
27
-
28
- export const DATABASE_TYPES = ['mongodb', 'mysql', 'postgresql', 'sqlite', 'mssql', 'other'] as const
29
-
30
- /**
31
- * The database types supported by this generator
32
- */
33
- export type DatabaseType = (typeof DATABASE_TYPES)[number]
34
-
35
- /**
36
- * Returns the name of the Feathers database adapter for a supported database type
37
- *
38
- * @param database The type of the database
39
- * @returns The name of the adapter
40
- */
41
- export const getDatabaseAdapter = (database: DatabaseType) => (database === 'mongodb' ? 'mongodb' : 'knex')
42
-
43
- export type FeathersAppInfo = {
44
- /**
45
- * The application language
46
- */
47
- language: 'ts' | 'js'
48
- /**
49
- * The main database
50
- */
51
- database: DatabaseType
52
- /**
53
- * The package manager used
54
- */
55
- packager: 'yarn' | 'npm' | 'pnpm'
56
- /**
57
- * A list of all chosen transports
58
- */
59
- transports: ('rest' | 'websockets')[]
60
- /**
61
- * The HTTP framework used
62
- */
63
- framework: 'koa' | 'express'
64
- /**
65
- * The main schema definition format
66
- */
67
- schema: 'typebox' | 'json' | false
68
- }
69
-
70
- export interface AppPackageJson extends PackageJson {
71
- feathers?: FeathersAppInfo
72
- }
73
-
74
- export interface FeathersBaseContext extends PinionContext {
75
- /**
76
- * Information about the Feathers application (like chosen language, database etc.)
77
- * usually taken from `package.json`
78
- */
79
- feathers: FeathersAppInfo
80
- /**
81
- * The package.json file
82
- */
83
- pkg: AppPackageJson
84
- /**
85
- * The folder where source files are put
86
- */
87
- lib: string
88
- /**
89
- * The folder where test files are put
90
- */
91
- test: string
92
- /**
93
- * The language the app is generated in
94
- */
95
- language: 'js' | 'ts'
96
- /**
97
- * A list dependencies that should be installed with a certain version.
98
- * Used for installing development dependencies during testing.
99
- */
100
- dependencyVersions?: DependencyVersions
101
- }
102
-
103
- /**
104
- * Returns dependencies with the versions from the context attached (if available)
105
- *
106
- * @param dependencies The dependencies to install
107
- * @param versions The dependency version list
108
- * @returns A list of dependencies with their versions
109
- */
110
- export const addVersions = (dependencies: string[], versions: DependencyVersions) =>
111
- dependencies.map((dep) => `${dep}@${versions[dep] ? versions[dep] : 'latest'}`)
112
-
113
- /**
114
- * Loads the application package.json and populates information like the library and test directory
115
- * and Feathers app specific information.
116
- *
117
- * @returns The updated context
118
- */
119
- export const initializeBaseContext =
120
- () =>
121
- <C extends FeathersBaseContext>(ctx: C) =>
122
- Promise.resolve(ctx)
123
- .then(loadJSON(fromFile('package.json'), (pkg) => ({ pkg }), {}))
124
- .then(
125
- loadJSON(path.join(__dirname, '..', 'package.json'), (pkg: PackageJson) => ({
126
- dependencyVersions: {
127
- ...pkg.devDependencies,
128
- ...ctx.dependencyVersions,
129
- '@feathersjs/cli': version
130
- }
131
- }))
132
- )
133
- .then((ctx) => ({
134
- ...ctx,
135
- lib: ctx.pkg?.directories?.lib || 'src',
136
- test: ctx.pkg?.directories?.test || 'test',
137
- language: ctx.language || ctx.pkg?.feathers?.language,
138
- feathers: ctx.pkg?.feathers
139
- }))
140
-
141
- /**
142
- * Checks if the current context contains a valid generated application. This is necesary for most
143
- * generators (besides the app generator).
144
- *
145
- * @param ctx The context to check against
146
- * @returns Throws an error or returns the original context
147
- */
148
- export const checkPreconditions =
149
- () =>
150
- async <T extends FeathersBaseContext>(ctx: T) => {
151
- if (!ctx.feathers) {
152
- throw new Error(`Can not run generator since the current folder does not appear to be a Feathers application.
153
- Either your package.json is missing or it does not have \`feathers\` property.
154
- `)
155
- }
156
-
157
- return ctx
158
- }
159
-
160
- const importRegex = /from '(\..*)'/g
161
- const escapeNewLines = (code: string) => code.replace(/\n\n/g, '\n/* :newline: */')
162
- const restoreNewLines = (code: string) => code.replace(/\/\* :newline: \*\//g, '\n')
163
- const fixLocalImports = (code: string) => code.replace(importRegex, "from '$1.js'")
164
-
165
- /**
166
- * Returns the transpiled and prettified JavaScript for a TypeScript source code
167
- *
168
- * @param typescript The TypeScript source code
169
- * @param options TypeScript transpilation options
170
- * @returns The formatted JavaScript source code
171
- */
172
- export const getJavaScript = (typescript: string, options: ts.TranspileOptions = {}) => {
173
- const source = escapeNewLines(typescript)
174
- const transpiled = ts.transpileModule(source, {
175
- ...options,
176
- compilerOptions: {
177
- module: ts.ModuleKind.ESNext,
178
- target: ts.ScriptTarget.ES2020,
179
- preserveValueImports: true,
180
- ...options.compilerOptions
181
- }
182
- })
183
-
184
- return fixLocalImports(restoreNewLines(transpiled.outputText))
185
- }
186
-
187
- const getFileName = async <C extends PinionContext & { language: 'js' | 'ts' }>(
188
- target: Callable<string, C>,
189
- ctx: C
190
- ) => `${await getCallable(target, ctx)}.${ctx.language}`
191
-
192
- /**
193
- * The default configuration for prettifying files
194
- */
195
- export const PRETTIERRC: PrettierOptions = {
196
- tabWidth: 2,
197
- useTabs: false,
198
- printWidth: 110,
199
- semi: false,
200
- trailingComma: 'none',
201
- singleQuote: true
202
- }
203
-
204
- /*
205
- * Format a source file using Prettier. Will use the local configuration, the settings set in
206
- * `options` or a default configuration
207
- *
208
- * @param target The file to prettify
209
- * @param options The Prettier options
210
- * @returns The updated context
211
- */
212
- export const prettify =
213
- <C extends PinionContext & { language: 'js' | 'ts' }>(
214
- target: Callable<string, C>,
215
- options: PrettierOptions = PRETTIERRC
216
- ) =>
217
- async (ctx: C) => {
218
- const fileName = await getFileName(target, ctx)
219
- const config = (await prettier.resolveConfig(ctx.cwd)) || options
220
- const content = (await readFile(fileName)).toString()
221
-
222
- try {
223
- await writeFile(
224
- fileName,
225
- await prettier.format(content, {
226
- parser: ctx.language === 'ts' ? 'typescript' : 'babel',
227
- ...config
228
- })
229
- )
230
- } catch (error: any) {
231
- throw new Error(`Error prettifying ${fileName}: ${error.message}`)
232
- }
233
-
234
- return ctx
235
- }
236
-
237
- /**
238
- * Render a source file template for the language set in the context.
239
- *
240
- * @param templates The JavaScript and TypeScript template to render
241
- * @param target The target filename without extension (will be added based on language)
242
- * @returns The updated context
243
- */
244
- export const renderSource =
245
- <C extends PinionContext & { language: 'js' | 'ts' }>(
246
- template: Callable<string, C>,
247
- target: Callable<string, C>,
248
- options?: { force: boolean }
249
- ) =>
250
- async (ctx: C) => {
251
- const { language } = ctx
252
- const fileName = await getFileName(target, ctx)
253
- const content = language === 'js' ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
254
- const renderer = renderTemplate(content, fileName, options)
255
-
256
- return renderer(ctx).then(prettify(target))
257
- }
258
-
259
- export const install =
260
- <C extends PinionContext & { language: 'js' | 'ts' }>(
261
- dependencies: Callable<string[], C>,
262
- dev: Callable<boolean, C>,
263
- packager: Callable<string, C>
264
- ) =>
265
- async (ctx: C) => {
266
- const dependencyList = await getCallable(dependencies, ctx)
267
- const packageManager = await getCallable(packager, ctx)
268
- const flags = dev ? [packageManager === 'yarn' ? '--dev' : '--save-dev'] : []
269
-
270
- return exec(packager, [packageManager === 'yarn' ? 'add' : 'install', ...dependencyList, ...flags])(ctx)
271
- }
272
-
273
- /**
274
- * Inject a source template as the language set in the context.
275
- *
276
- * @param template The source template to render
277
- * @param location The location to inject the code to. Must use the target language.
278
- * @param target The target file name
279
- * @param transpile Set to `false` if the code should not be transpiled to JavaScript
280
- * @returns
281
- */
282
- export const injectSource =
283
- <C extends PinionContext & { language: 'js' | 'ts' }>(
284
- template: Callable<string, C>,
285
- location: Location<C>,
286
- target: Callable<string, C>,
287
- transpile = true
288
- ) =>
289
- async (ctx: C) => {
290
- const { language } = ctx
291
- const source =
292
- language === 'js' && transpile ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
293
- const fileName = await getFileName(target, ctx)
294
- const injector = inject(source, location, fileName)
295
-
296
- return injector(ctx).then(prettify(target))
297
- }
298
-
299
- /**
300
- * Synchronously checks if a file exits
301
- * @param context The base context
302
- * @param filenames The filenames to check
303
- * @returns Wether the file exists or not
304
- */
305
- export const fileExists = (...filenames: string[]) => fs.existsSync(join(...filenames))
306
-
307
- /**
308
- * The helper used by Knex to create migration names
309
- * @returns The current date and time in the format `YYYYMMDDHHMMSS`
310
- */
311
- export const yyyymmddhhmmss = (offset = 0) => {
312
- const now = new Date(Date.now() + offset)
313
-
314
- return (
315
- now.getUTCFullYear().toString() +
316
- (now.getUTCMonth() + 1).toString().padStart(2, '0') +
317
- now.getUTCDate().toString().padStart(2, '0') +
318
- now.getUTCHours().toString().padStart(2, '0') +
319
- now.getUTCMinutes().toString().padStart(2, '0') +
320
- now.getUTCSeconds().toString().padStart(2, '0')
321
- )
322
- }
323
-
324
- /**
325
- * Render a template if `local` authentication strategy has been selected
326
- * @param authStrategies The list of selected authentication strategies
327
- * @param content The content to render if `local` is selected
328
- * @param alt The content to render if `local` is not selected
329
- * @returns
330
- */
331
- export const localTemplate = (authStrategies: string[], content: string, alt = '') =>
332
- authStrategies.includes('local') ? content : alt
333
-
334
- /**
335
- * Render a template if an `oauth` authentication strategy has been selected
336
- * @param authStrategies
337
- * @param content
338
- * @returns
339
- */
340
- export const oauthTemplate = (authStrategies: string[], content: string) =>
341
- authStrategies.filter((s) => s !== 'local').length > 0 ? content : ''
@@ -1,138 +0,0 @@
1
- import { dirname } from 'path'
2
- import { runGenerator, prompt, mergeJSON, toFile, when } from '@featherscloud/pinion'
3
- import { fileURLToPath } from 'url'
4
- import chalk from 'chalk'
5
- import {
6
- install,
7
- FeathersBaseContext,
8
- DatabaseType,
9
- getDatabaseAdapter,
10
- addVersions,
11
- checkPreconditions,
12
- initializeBaseContext
13
- } from '../commons.js'
14
-
15
- // Set __dirname in es module
16
- const __dirname = dirname(fileURLToPath(import.meta.url))
17
-
18
- export interface ConnectionGeneratorContext extends FeathersBaseContext {
19
- name?: string
20
- database: DatabaseType
21
- connectionString: string
22
- dependencies: string[]
23
- }
24
-
25
- export type ConnectionGeneratorArguments = FeathersBaseContext &
26
- Partial<Pick<ConnectionGeneratorContext, 'database' | 'connectionString' | 'name'>>
27
-
28
- export const defaultConnectionString = (type: DatabaseType, name: string) => {
29
- const connectionStrings = {
30
- mongodb: `mongodb://127.0.0.1:27017/${name}`,
31
- mysql: `mysql://root:@localhost:3306/${name}`,
32
- postgresql: `postgres://postgres:@localhost:5432/${name}`,
33
- sqlite: `${name}.sqlite`,
34
- mssql: `mssql://root:password@localhost:1433/${name}`,
35
- other: ''
36
- }
37
-
38
- return connectionStrings[type]
39
- }
40
-
41
- export const prompts = ({ database, connectionString, pkg, name }: ConnectionGeneratorArguments) => [
42
- {
43
- name: 'database',
44
- type: 'list',
45
- when: !database,
46
- message: 'Which database are you connecting to?',
47
- suffix: chalk.grey(' Databases can be added at any time'),
48
- choices: [
49
- { value: 'sqlite', name: 'SQLite' },
50
- { value: 'mongodb', name: 'MongoDB' },
51
- { value: 'postgresql', name: 'PostgreSQL' },
52
- { value: 'mysql', name: 'MySQL/MariaDB' },
53
- { value: 'mssql', name: 'Microsoft SQL' },
54
- {
55
- value: 'other',
56
- name: `Another database ${chalk.grey('(not configured automatically, use with custom services)')}`
57
- }
58
- ]
59
- },
60
- {
61
- name: 'connectionString',
62
- type: 'input',
63
- when: (answers: ConnectionGeneratorContext) =>
64
- !connectionString && database !== 'other' && answers.database !== 'other',
65
- message: 'Enter your database connection string',
66
- default: (answers: ConnectionGeneratorContext) =>
67
- defaultConnectionString(answers.database, answers.name || name || pkg.name)
68
- }
69
- ]
70
-
71
- export const DATABASE_CLIENTS = {
72
- mongodb: 'mongodb',
73
- sqlite: 'sqlite3',
74
- postgresql: 'pg',
75
- mysql: 'mysql',
76
- mssql: 'mssql'
77
- }
78
-
79
- export const getDatabaseClient = (database: DatabaseType) =>
80
- database === 'other' ? null : DATABASE_CLIENTS[database]
81
-
82
- export const generate = (ctx: ConnectionGeneratorArguments) =>
83
- Promise.resolve(ctx)
84
- .then(initializeBaseContext())
85
- .then(checkPreconditions())
86
- .then(prompt(prompts))
87
- .then((ctx) => ctx as ConnectionGeneratorContext)
88
- .then(
89
- when<ConnectionGeneratorContext>(
90
- (ctx) => ctx.database !== 'other',
91
- runGenerator<ConnectionGeneratorContext>(
92
- __dirname,
93
- 'templates',
94
- ({ database }) => `${getDatabaseAdapter(database)}.tpl.js`
95
- ),
96
- mergeJSON<ConnectionGeneratorContext>(
97
- ({ connectionString, database }) =>
98
- getDatabaseAdapter(database) === 'knex'
99
- ? {
100
- [database]: {
101
- client: getDatabaseClient(database),
102
- connection: connectionString,
103
- ...(database === 'sqlite' ? { useNullAsDefault: true } : {})
104
- }
105
- }
106
- : {
107
- [database]: connectionString
108
- },
109
- toFile('config', 'default.json')
110
- ),
111
- async (ctx: ConnectionGeneratorContext) => {
112
- const dependencies: string[] = []
113
- const adapter = getDatabaseAdapter(ctx.database)
114
- const dbClient = getDatabaseClient(ctx.database)
115
-
116
- dependencies.push(`@feathersjs/${adapter}`)
117
-
118
- if (adapter === 'knex') {
119
- dependencies.push('knex')
120
- }
121
-
122
- dependencies.push(dbClient)
123
-
124
- if (ctx.dependencies) {
125
- return {
126
- ...ctx,
127
- dependencies: [...ctx.dependencies, ...dependencies]
128
- }
129
- }
130
-
131
- return install<ConnectionGeneratorContext>(
132
- addVersions(dependencies, ctx.dependencyVersions),
133
- false,
134
- ctx.feathers.packager
135
- )(ctx)
136
- }
137
- )
138
- )
@@ -1,73 +0,0 @@
1
- import { toFile, before, mergeJSON } from '@featherscloud/pinion'
2
- import { ConnectionGeneratorContext } from '../index.js'
3
- import { injectSource, renderSource } from '../../commons.js'
4
- import { mkdir } from 'fs/promises'
5
- import path from 'path'
6
-
7
- const template = ({
8
- database
9
- }: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
10
- import knex from 'knex'
11
- import type { Knex } from 'knex'
12
- import type { Application } from './declarations'
13
-
14
- declare module './declarations' {
15
- interface Configuration {
16
- ${database}Client: Knex
17
- }
18
- }
19
-
20
- export const ${database} = (app: Application) => {
21
- const config = app.get('${database}')
22
- const db = knex(config!)
23
-
24
- app.set('${database}Client', db)
25
- }
26
- `
27
-
28
- const knexfile = ({
29
- lib,
30
- language,
31
- database
32
- }: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
33
- import { app } from './${lib}/app'
34
-
35
- // Load our database connection info from the app configuration
36
- const config = app.get('${database}')
37
-
38
- ${language === 'js' ? 'export default config' : 'module.exports = config'}
39
- `
40
-
41
- const importTemplate = ({ database }: ConnectionGeneratorContext) =>
42
- `import { ${database} } from './${database}'`
43
- const configureTemplate = ({ database }: ConnectionGeneratorContext) => `app.configure(${database})`
44
-
45
- const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
46
-
47
- export const generate = (ctx: ConnectionGeneratorContext) =>
48
- Promise.resolve(ctx)
49
- .then(
50
- renderSource(
51
- template,
52
- toFile<ConnectionGeneratorContext>(({ lib, database }) => [lib, database])
53
- )
54
- )
55
- .then(renderSource(knexfile, toFile('knexfile')))
56
- .then(
57
- mergeJSON<ConnectionGeneratorContext>(
58
- (ctx) => ({
59
- scripts: {
60
- migrate: 'knex migrate:latest',
61
- 'migrate:make': 'knex migrate:make' + (ctx.language === 'js' ? ' -x mjs' : ''),
62
- test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
63
- }
64
- }),
65
- toFile('package.json')
66
- )
67
- )
68
- .then(injectSource(importTemplate, before('import { services } from'), toAppFile))
69
- .then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
70
- .then(async (ctx) => {
71
- await mkdir(path.join(ctx.cwd, 'migrations'))
72
- return ctx
73
- })
@@ -1,50 +0,0 @@
1
- import { toFile, before, prepend, append } from '@featherscloud/pinion'
2
- import { ConnectionGeneratorContext } from '../index.js'
3
- import { injectSource, renderSource } from '../../commons.js'
4
-
5
- const template = ({
6
- database
7
- }: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
8
- import { MongoClient } from 'mongodb'
9
- import type { Db } from 'mongodb'
10
- import type { Application } from './declarations'
11
-
12
- declare module './declarations' {
13
- interface Configuration {
14
- ${database}Client: Promise<Db>
15
- }
16
- }
17
-
18
- export const ${database} = (app: Application) => {
19
- const connection = app.get('${database}') as string
20
- const database = new URL(connection).pathname.substring(1)
21
- const mongoClient = MongoClient.connect(connection)
22
- .then(client => client.db(database))
23
-
24
- app.set('${database}Client', mongoClient)
25
- }
26
- `
27
-
28
- const keywordImport = `import { keywordObjectId } from '@feathersjs/mongodb'`
29
-
30
- const keywordTemplate = `dataValidator.addKeyword(keywordObjectId)
31
- queryValidator.addKeyword(keywordObjectId)`
32
-
33
- const importTemplate = ({ database }: ConnectionGeneratorContext) =>
34
- `import { ${database} } from './${database}'`
35
- const configureTemplate = ({ database }: ConnectionGeneratorContext) => `app.configure(${database})`
36
- const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
37
- const toValidatorFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'validators'])
38
-
39
- export const generate = (ctx: ConnectionGeneratorContext) =>
40
- Promise.resolve(ctx)
41
- .then(
42
- renderSource(
43
- template,
44
- toFile<ConnectionGeneratorContext>(({ lib, database }) => [lib, database])
45
- )
46
- )
47
- .then(injectSource(importTemplate, before('import { services } from'), toAppFile))
48
- .then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
49
- .then(injectSource(keywordImport, prepend(), toValidatorFile))
50
- .then(injectSource(keywordTemplate, append(), toValidatorFile))
package/lib/hook/index.ts DELETED
@@ -1,52 +0,0 @@
1
- import { dirname } from 'path'
2
- import { fileURLToPath } from 'url'
3
- import { prompt, runGenerators } from '@featherscloud/pinion'
4
- import _ from 'lodash'
5
- import { checkPreconditions, FeathersBaseContext, initializeBaseContext } from '../commons.js'
6
-
7
- // Set __dirname in es module
8
- const __dirname = dirname(fileURLToPath(import.meta.url))
9
-
10
- export interface HookGeneratorContext extends FeathersBaseContext {
11
- name: string
12
- camelName: string
13
- kebabName: string
14
- type: 'regular' | 'around'
15
- }
16
-
17
- export const generate = (ctx: HookGeneratorContext) =>
18
- Promise.resolve(ctx)
19
- .then(initializeBaseContext())
20
- .then(checkPreconditions())
21
- .then(
22
- prompt<HookGeneratorContext>(({ type, name }) => [
23
- {
24
- type: 'input',
25
- name: 'name',
26
- message: 'What is the name of the hook?',
27
- when: !name
28
- },
29
- {
30
- name: 'type',
31
- type: 'list',
32
- when: !type,
33
- message: 'What kind of hook is it?',
34
- choices: [
35
- { value: 'around', name: 'Around' },
36
- { value: 'regular', name: 'Before, After or Error' }
37
- ]
38
- }
39
- ])
40
- )
41
- .then((ctx) => {
42
- const { name } = ctx
43
- const kebabName = _.kebabCase(name)
44
- const camelName = _.camelCase(name)
45
-
46
- return {
47
- ...ctx,
48
- kebabName,
49
- camelName
50
- }
51
- })
52
- .then(runGenerators(__dirname, 'templates'))
@@ -1,33 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { HookGeneratorContext } from '../index.js'
3
- import { renderSource } from '../../commons.js'
4
-
5
- const aroundTemplate = ({
6
- camelName,
7
- name
8
- }: HookGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
9
- import type { HookContext, NextFunction } from '../declarations'
10
-
11
- export const ${camelName} = async (context: HookContext, next: NextFunction) => {
12
- console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
13
- await next()
14
- }
15
- `
16
-
17
- const regularTemplate = ({
18
- camelName,
19
- name
20
- }: HookGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
21
- import type { HookContext } from '../declarations'
22
-
23
- export const ${camelName} = async (context: HookContext) => {
24
- console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
25
- }`
26
-
27
- export const generate = (ctx: HookGeneratorContext) =>
28
- Promise.resolve(ctx).then(
29
- renderSource(
30
- (ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)),
31
- toFile<HookGeneratorContext>(({ lib, kebabName }) => [lib, 'hooks', kebabName])
32
- )
33
- )
package/lib/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from '@featherscloud/pinion'
2
-
3
- export * from './commons.js'
4
- export * as app from './app/index.js'
5
- export * as authentication from './authentication/index.js'
6
- export * as connection from './connection/index.js'
7
- export * as hook from './hook/index.js'
8
- export * as service from './service/index.js'