@feathersjs/generators 5.0.28 → 5.0.30

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 (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/lib/app/index.js +1 -2
  5. package/lib/app/index.js.map +1 -1
  6. package/lib/app/templates/gitignore.tpl.d.ts +5 -0
  7. package/lib/app/templates/gitignore.tpl.js +125 -0
  8. package/lib/app/templates/gitignore.tpl.js.map +1 -0
  9. package/package.json +28 -29
  10. package/lib/app/index.ts +0 -215
  11. package/lib/app/templates/app.test.tpl.ts +0 -50
  12. package/lib/app/templates/app.tpl.ts +0 -141
  13. package/lib/app/templates/channels.tpl.ts +0 -54
  14. package/lib/app/templates/client.test.tpl.ts +0 -28
  15. package/lib/app/templates/client.tpl.ts +0 -53
  16. package/lib/app/templates/configuration.tpl.ts +0 -89
  17. package/lib/app/templates/declarations.tpl.ts +0 -42
  18. package/lib/app/templates/index.html.tpl.ts +0 -44
  19. package/lib/app/templates/index.tpl.ts +0 -26
  20. package/lib/app/templates/logger.tpl.ts +0 -56
  21. package/lib/app/templates/package.json.tpl.ts +0 -78
  22. package/lib/app/templates/prettierrc.tpl.ts +0 -14
  23. package/lib/app/templates/readme.md.tpl.ts +0 -57
  24. package/lib/app/templates/services.tpl.ts +0 -20
  25. package/lib/app/templates/tsconfig.json.tpl.ts +0 -29
  26. package/lib/app/templates/validators.tpl.ts +0 -39
  27. package/lib/authentication/index.ts +0 -119
  28. package/lib/authentication/templates/authentication.tpl.ts +0 -52
  29. package/lib/authentication/templates/client.test.tpl.ts +0 -78
  30. package/lib/authentication/templates/config.tpl.ts +0 -60
  31. package/lib/authentication/templates/declarations.tpl.ts +0 -38
  32. package/lib/commons.ts +0 -346
  33. package/lib/connection/index.ts +0 -138
  34. package/lib/connection/templates/knex.tpl.ts +0 -73
  35. package/lib/connection/templates/mongodb.tpl.ts +0 -50
  36. package/lib/hook/index.ts +0 -52
  37. package/lib/hook/templates/hook.tpl.ts +0 -33
  38. package/lib/index.ts +0 -8
  39. package/lib/service/index.ts +0 -214
  40. package/lib/service/templates/client.tpl.ts +0 -33
  41. package/lib/service/templates/schema.json.tpl.ts +0 -143
  42. package/lib/service/templates/schema.typebox.tpl.ts +0 -131
  43. package/lib/service/templates/service.tpl.ts +0 -161
  44. package/lib/service/templates/shared.tpl.ts +0 -64
  45. package/lib/service/templates/test.tpl.ts +0 -33
  46. package/lib/service/type/custom.tpl.ts +0 -112
  47. package/lib/service/type/knex.tpl.ts +0 -105
  48. package/lib/service/type/mongodb.tpl.ts +0 -64
@@ -1,141 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const tsKoaApp = ({
6
- transports,
7
- schema
8
- }: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/application.html
9
- import { feathers } from '@feathersjs/feathers'
10
- import configuration from '@feathersjs/configuration'
11
- import {
12
- koa, rest, bodyParser, errorHandler, parseAuthentication, cors, serveStatic
13
- } from '@feathersjs/koa'
14
- ${transports.includes('websockets') ? "import socketio from '@feathersjs/socketio'" : ''}
15
-
16
- ${schema !== false ? `import { configurationValidator } from './configuration'` : ''}
17
- import type { Application } from './declarations'
18
- import { logError } from './hooks/log-error'
19
- import { services } from './services/index'
20
- ${transports.includes('websockets') ? `import { channels } from './channels'` : ''}
21
-
22
- const app: Application = koa(feathers())
23
-
24
- // Load our app configuration (see config/ folder)
25
- app.configure(configuration(${schema !== false ? 'configurationValidator' : ''}))
26
-
27
- // Set up Koa middleware
28
- app.use(cors())
29
- app.use(serveStatic(app.get('public')))
30
- app.use(errorHandler())
31
- app.use(parseAuthentication())
32
- app.use(bodyParser())
33
-
34
- // Configure services and transports
35
- app.configure(rest())
36
- ${
37
- transports.includes('websockets')
38
- ? `app.configure(socketio({
39
- cors: {
40
- origin: app.get('origins')
41
- }
42
- }))`
43
- : ''
44
- }
45
- app.configure(services)
46
- ${transports.includes('websockets') ? 'app.configure(channels)' : ''}
47
-
48
-
49
- // Register hooks that run on all service methods
50
- app.hooks({
51
- around: {
52
- all: [ logError ]
53
- },
54
- before: {},
55
- after: {},
56
- error: {}
57
- })
58
- // Register application setup and teardown hooks here
59
- app.hooks({
60
- setup: [],
61
- teardown: []
62
- })
63
-
64
- export { app }
65
- `
66
-
67
- const tsExpressApp = ({
68
- transports,
69
- schema
70
- }: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/application.html
71
- import { feathers } from '@feathersjs/feathers'
72
- import express, {
73
- rest, json, urlencoded, cors,
74
- serveStatic, notFound, errorHandler
75
- } from '@feathersjs/express'
76
- import configuration from '@feathersjs/configuration'
77
- ${transports.includes('websockets') ? "import socketio from '@feathersjs/socketio'" : ''}
78
-
79
- import type { Application } from './declarations'
80
- ${schema !== false ? `import { configurationValidator } from './configuration'` : ''}
81
- import { logger } from './logger'
82
- import { logError } from './hooks/log-error'
83
- import { services } from './services/index'
84
- ${transports.includes('websockets') ? `import { channels } from './channels'` : ''}
85
-
86
- const app: Application = express(feathers())
87
-
88
- // Load app configuration
89
- app.configure(configuration(${schema !== false ? 'configurationValidator' : ''}))
90
- app.use(cors())
91
- app.use(json())
92
- app.use(urlencoded({ extended: true }))
93
- // Host the public folder
94
- app.use('/', serveStatic(app.get('public')))
95
-
96
- // Configure services and real-time functionality
97
- app.configure(rest())
98
- ${
99
- transports.includes('websockets')
100
- ? `app.configure(socketio({
101
- cors: {
102
- origin: app.get('origins')
103
- }
104
- }))`
105
- : ''
106
- }
107
- app.configure(services)
108
- ${transports.includes('websockets') ? 'app.configure(channels)' : ''}
109
-
110
- // Configure a middleware for 404s and the error handler
111
- app.use(notFound())
112
- app.use(errorHandler({ logger }))
113
-
114
- // Register hooks that run on all service methods
115
- app.hooks({
116
- around: {
117
- all: [ logError ]
118
- },
119
- before: {},
120
- after: {},
121
- error: {}
122
- })
123
- // Register application setup and teardown hooks here
124
- app.hooks({
125
- setup: [],
126
- teardown: []
127
- })
128
-
129
- export { app }
130
- `
131
-
132
- const template = (ctx: AppGeneratorContext) =>
133
- ctx.framework === 'express' ? tsExpressApp(ctx) : tsKoaApp(ctx)
134
-
135
- export const generate = (ctx: AppGeneratorContext) =>
136
- Promise.resolve(ctx).then(
137
- renderSource(
138
- template,
139
- toFile<AppGeneratorContext>(({ lib }) => lib, 'app')
140
- )
141
- )
@@ -1,54 +0,0 @@
1
- import { toFile, when } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template = ({
6
- language
7
- }: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/channels.html
8
- import type { RealTimeConnection, Params } from '@feathersjs/feathers'
9
- import type { AuthenticationResult } from '@feathersjs/authentication'
10
- import '@feathersjs/transport-commons'
11
- import type { Application, HookContext } from './declarations'
12
- import { logger } from './logger'
13
-
14
- export const channels = (app: Application) => {
15
- logger.warn('Publishing all events to all authenticated users. See \`channels.${language}\` and https://dove.feathersjs.com/api/channels.html for more information.')
16
-
17
- app.on('connection', (connection: RealTimeConnection) => {
18
- // On a new real-time connection, add it to the anonymous channel
19
- app.channel('anonymous').join(connection)
20
- })
21
-
22
- app.on('login', (authResult: AuthenticationResult, { connection }: Params) => {
23
- // connection can be undefined if there is no
24
- // real-time connection, e.g. when logging in via REST
25
- if(connection) {
26
- // The connection is no longer anonymous, remove it
27
- app.channel('anonymous').leave(connection)
28
-
29
- // Add it to the authenticated user channel
30
- app.channel('authenticated').join(connection)
31
- }
32
- })
33
-
34
- // eslint-disable-next-line no-unused-vars
35
- app.publish((data: any, context: HookContext) => {
36
- // Here you can add event publishers to channels set up in \`channels.js\`
37
- // To publish only for a specific event use \`app.publish(eventname, () => {})\`
38
-
39
- // e.g. to publish all service events to all authenticated users use
40
- return app.channel('authenticated')
41
- })
42
- }
43
- `
44
-
45
- export const generate = (ctx: AppGeneratorContext) =>
46
- Promise.resolve(ctx).then(
47
- when<AppGeneratorContext>(
48
- ({ transports }) => transports.includes('websockets'),
49
- renderSource(
50
- template,
51
- toFile<AppGeneratorContext>(({ lib }) => lib, 'channels')
52
- )
53
- )
54
- )
@@ -1,28 +0,0 @@
1
- import { toFile, when } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template = ({ lib }: AppGeneratorContext) => /* ts */ `import assert from 'assert'
6
- import axios from 'axios'
7
- import type { Server } from 'http'
8
- import { app } from '../${lib}/app'
9
- import { createClient } from '../${lib}/client'
10
-
11
- import rest from '@feathersjs/rest-client'
12
-
13
- const port = app.get('port')
14
- const appUrl = \`http://\${app.get('host')}:\${port}\`
15
-
16
- describe('client tests', () => {
17
- const client = createClient(rest(appUrl).axios(axios))
18
-
19
- it('initialized the client', () => {
20
- assert.ok(client)
21
- })
22
- })
23
- `
24
-
25
- export const generate = (ctx: AppGeneratorContext) =>
26
- Promise.resolve(ctx).then(
27
- when<AppGeneratorContext>((ctx) => ctx.client, renderSource(template, toFile('test', 'client.test')))
28
- )
@@ -1,53 +0,0 @@
1
- import { toFile, when } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template = ({
6
- name,
7
- language
8
- }: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/client.html
9
- import { feathers } from '@feathersjs/feathers'
10
- import type { TransportConnection, Application } from '@feathersjs/feathers'
11
- import authenticationClient from '@feathersjs/authentication-client'
12
- import type { AuthenticationClientOptions } from '@feathersjs/authentication-client'
13
-
14
- export interface Configuration {
15
- connection: TransportConnection<ServiceTypes>
16
- }
17
-
18
- export interface ServiceTypes {}
19
-
20
- export type ClientApplication = Application<ServiceTypes, Configuration>
21
-
22
- /**
23
- * Returns a ${language === 'ts' ? 'typed' : ''} client for the ${name} app.
24
- *
25
- * @param connection The REST or Socket.io Feathers client connection
26
- * @param authenticationOptions Additional settings for the authentication client
27
- * @see https://dove.feathersjs.com/api/client.html
28
- * @returns The Feathers client application
29
- */
30
- export const createClient = <Configuration = any> (
31
- connection: TransportConnection<ServiceTypes>,
32
- authenticationOptions: Partial<AuthenticationClientOptions> = {}
33
- ) => {
34
- const client: ClientApplication = feathers()
35
-
36
- client.configure(connection)
37
- client.configure(authenticationClient(authenticationOptions))
38
- client.set('connection', connection)
39
-
40
- return client
41
- }
42
- `
43
-
44
- export const generate = async (ctx: AppGeneratorContext) =>
45
- Promise.resolve(ctx).then(
46
- when<AppGeneratorContext>(
47
- (ctx) => ctx.client,
48
- renderSource(
49
- template,
50
- toFile<AppGeneratorContext>(({ lib }) => lib, 'client')
51
- )
52
- )
53
- )
@@ -1,89 +0,0 @@
1
- import { toFile, when, writeJSON } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const defaultConfig = ({}: AppGeneratorContext) => ({
6
- host: 'localhost',
7
- port: 3030,
8
- public: './public/',
9
- origins: ['http://localhost:3030'],
10
- paginate: {
11
- default: 10,
12
- max: 50
13
- }
14
- })
15
-
16
- const customEnvironment = {
17
- port: {
18
- __name: 'PORT',
19
- __format: 'number'
20
- },
21
- host: 'HOSTNAME',
22
- authentication: {
23
- secret: 'FEATHERS_SECRET'
24
- }
25
- }
26
-
27
- const testConfig = {
28
- port: 8998
29
- }
30
-
31
- const configurationJsonTemplate =
32
- ({}: AppGeneratorContext) => `import { defaultAppSettings, getValidator } from '@feathersjs/schema'
33
- import type { FromSchema } from '@feathersjs/schema'
34
-
35
- import { dataValidator } from './validators'
36
-
37
- export const configurationSchema = {
38
- $id: 'configuration',
39
- type: 'object',
40
- additionalProperties: false,
41
- required: [ 'host', 'port', 'public' ],
42
- properties: {
43
- ...defaultAppSettings,
44
- host: { type: 'string' },
45
- port: { type: 'number' },
46
- public: { type: 'string' }
47
- }
48
- } as const
49
-
50
- export const configurationValidator = getValidator(configurationSchema, dataValidator)
51
-
52
- export type ApplicationConfiguration = FromSchema<typeof configurationSchema>
53
- `
54
-
55
- const configurationTypeboxTemplate =
56
- ({}: AppGeneratorContext) => `import { Type, getValidator, defaultAppConfiguration } from '@feathersjs/typebox'
57
- import type { Static } from '@feathersjs/typebox'
58
-
59
- import { dataValidator } from './validators'
60
-
61
- export const configurationSchema = Type.Intersect([
62
- defaultAppConfiguration,
63
- Type.Object({
64
- host: Type.String(),
65
- port: Type.Number(),
66
- public: Type.String()
67
- })
68
- ])
69
-
70
- export type ApplicationConfiguration = Static<typeof configurationSchema>
71
-
72
- export const configurationValidator = getValidator(configurationSchema, dataValidator)
73
- `
74
-
75
- export const generate = (ctx: AppGeneratorContext) =>
76
- Promise.resolve(ctx)
77
- .then(writeJSON(defaultConfig, toFile('config', 'default.json')))
78
- .then(writeJSON(testConfig, toFile('config', 'test.json')))
79
- .then(writeJSON(customEnvironment, toFile('config', 'custom-environment-variables.json')))
80
- .then(
81
- when<AppGeneratorContext>(
82
- (ctx) => ctx.schema !== false,
83
- renderSource(
84
- async (ctx) =>
85
- ctx.schema === 'typebox' ? configurationTypeboxTemplate(ctx) : configurationJsonTemplate(ctx),
86
- toFile<AppGeneratorContext>(({ lib }) => lib, 'configuration')
87
- )
88
- )
89
- )
@@ -1,42 +0,0 @@
1
- import { toFile, when, renderTemplate } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
-
4
- const template = ({
5
- framework,
6
- schema
7
- }: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/typescript.html
8
- import { HookContext as FeathersHookContext, NextFunction } from '@feathersjs/feathers'
9
- import { Application as FeathersApplication } from '@feathersjs/${framework}'
10
- ${
11
- schema === false
12
- ? `type ApplicationConfiguration = any`
13
- : `import { ApplicationConfiguration } from './configuration'`
14
- }
15
-
16
- export type { NextFunction }
17
-
18
- // The types for app.get(name) and app.set(name)
19
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
20
- export interface Configuration extends ApplicationConfiguration {}
21
-
22
- // A mapping of service names to types. Will be extended in service files.
23
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
24
- export interface ServiceTypes {}
25
-
26
- // The application instance type that will be used everywhere else
27
- export type Application = FeathersApplication<ServiceTypes, Configuration>
28
-
29
- // The context for hook functions - can be typed with a service class
30
- export type HookContext<S = any> = FeathersHookContext<Application, S>
31
- `
32
-
33
- export const generate = (ctx: AppGeneratorContext) =>
34
- Promise.resolve(ctx).then(
35
- when<AppGeneratorContext>(
36
- ({ language }) => language === 'ts',
37
- renderTemplate(
38
- template,
39
- toFile<AppGeneratorContext>(({ lib }) => lib, 'declarations.ts')
40
- )
41
- )
42
- )
@@ -1,44 +0,0 @@
1
- import { renderTemplate, toFile } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
-
4
- const template = ({ name, description }: AppGeneratorContext) => /* html */ `<!DOCTYPE html>
5
- <html lang="en">
6
- <head>
7
- <title>${name}</title>
8
- <meta name="description" content="${description}">
9
- <meta name="viewport" content="width=device-width, initial-scale=1">
10
- <style>
11
- * {
12
- margin: 0;
13
- padding: 0;
14
- box-sizing: border-box;
15
- }
16
-
17
- html {
18
- height: 100%;
19
- }
20
-
21
- body {
22
- min-height: 100%;
23
- display: flex;
24
- align-items: center;
25
- }
26
-
27
- img.logo {
28
- display: block;
29
- margin: auto auto;
30
- width: 30%;
31
- max-width: 100%;
32
- max-height: 100%;
33
- }
34
- </style>
35
- </head>
36
- <body>
37
- <img class="logo" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUwMCIgaGVpZ2h0PSIyNTAwIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+PHBhdGggZD0iTTEyOCA5LjEwMmM2NS42NjUgMCAxMTguODk4IDUzLjIzMyAxMTguODk4IDExOC44OTggMCA2NS42NjUtNTMuMjMzIDExOC44OTgtMTE4Ljg5OCAxMTguODk4QzYyLjMzNSAyNDYuODk4IDkuMTAyIDE5My42NjUgOS4xMDIgMTI4IDkuMTAyIDYyLjMzNSA2Mi4zMzUgOS4xMDIgMTI4IDkuMTAyTTEyOCAwQzU3LjQyMSAwIDAgNTcuNDIxIDAgMTI4YzAgNzAuNTc5IDU3LjQyMSAxMjggMTI4IDEyOCA3MC41NzkgMCAxMjgtNTcuNDIxIDEyOC0xMjhDMjU2IDU3LjQyMSAxOTguNTc5IDAgMTI4IDBtMjAuODMgMjUuNTI0Yy0xMC40My0xLjg5Ni0zNS42NTEgMzYuNDA5LTQzLjk5NCA1OS43MzQtLjYzNCAxLjc2OS0yLjA4NiA4LjI0OS0yLjA4NiA5Ljk1NSAwIDAgNi41MzEgMTQuMDU1IDguMzQzIDE3LjM1MS0zLjAzNC0xLjU4LTkuMzIzLTEzLjc1Ni05LjMyMy0xMy43NTYtMy4wMzQgNS43ODQtNS45NDIgMzIuMzQtNC45OTQgMzcuMjcxIDAgMCA2Ljc2MiAxMC4wNjIgOS4zODcgMTIuNTc4LTMuNjAzLTEuMjAxLTkuNjcxLTkuMzU1LTkuNjcxLTkuMzU1LTEuMTM4IDMuNTA4LS45MTYgMTAuODA3LS4zNzkgMTMuMjc0IDQuNTUxIDYuNjM3IDEwLjYxOSA3LjM5NiAxMC42MTkgNy4zOTZzLTYuNjM3IDY2LjE4MSAzLjQxMyA3MS4xMTFjNi4yNTgtMS4zMjcgNy43NzUtNzMuOTU2IDcuNzc1LTczLjk1NnM3LjU4NS41NjkgOS4yOTItMS4zMjdjMy44NTYtMi42NTUgMTIuODI2LTMwLjIyNCAxMi45NTgtMzQuMjAyIDAgMC0xMC40MSAxLjk1Mi0xNS40ODcgMy45MjQgMy44MjYtMy44IDE2LjA0OS02LjM1MiAxNi4wNDktNi4zNTIgMy4zMTUtMy45NzkgMTAuMjkxLTMxLjA0NyAxMC45OTQtMzkuMzkxLjE3Ni0yLjA5My41ODMtNC42NTcuMjY4LTguMzk4IDAgMC05Ljk0MSAyLjE3Ny0xMi4wMTQgMS40MjQgMi4xMDQtLjIzNyAxMi4yNjMtNC4xNCAxMi4yNjMtNC4xNCAxLjgwMS0xNi4yMTMgMi4zNTgtNDIuMDkxLTMuNDEzLTQzLjE0MXptLTM2LjM4IDE3MS42OTFjLS43OTUgMTkuNDk2LTEuMjk0IDI1LjAwNC0yLjExNSAyOS42MDEtLjM3OS44NTctLjc1OC45OTctMS4xMzgtLjA5NS0zLjQ3Ny0xNS45OTItMy4yMjQtMTM2LjQzOCAzNi40MDktMTkxLjI0MS0yMy4wNSA0Mi4wOTItMzMuNTM1IDEyMi44NjEtMzMuMTU2IDE2MS43MzV6IiBmaWxsPSIjMzMzIi8+PC9zdmc+" />
38
- </body>
39
- </html>
40
-
41
- `
42
-
43
- export const generate = (ctx: AppGeneratorContext) =>
44
- Promise.resolve(ctx).then(renderTemplate(template, toFile('public', 'index.html')))
@@ -1,26 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template = ({}: AppGeneratorContext) => /* ts */ `import { app } from './app'
6
- import { logger } from './logger'
7
-
8
- const port = app.get('port')
9
- const host = app.get('host')
10
-
11
- process.on('unhandledRejection', (reason) =>
12
- logger.error('Unhandled Rejection %O', reason)
13
- )
14
-
15
- app.listen(port).then(() => {
16
- logger.info(\`Feathers app listening on http://\${host}:\${port}\`)
17
- })
18
- `
19
-
20
- export const generate = (ctx: AppGeneratorContext) =>
21
- Promise.resolve(ctx).then(
22
- renderSource(
23
- template,
24
- toFile<AppGeneratorContext>(({ lib }) => lib, 'index')
25
- )
26
- )
@@ -1,56 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template =
6
- ({}: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/logging.html
7
- import { createLogger, format, transports } from 'winston'
8
-
9
- // Configure the Winston logger. For the complete documentation see https://github.com/winstonjs/winston
10
- export const logger = createLogger({
11
- // To see more detailed errors, change this to 'debug'
12
- level: 'info',
13
- format: format.combine(
14
- format.splat(),
15
- format.simple()
16
- ),
17
- transports: [
18
- new transports.Console()
19
- ]
20
- })
21
- `
22
-
23
- export const logErrorTemplate = /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/log-error.html
24
- import type { HookContext, NextFunction } from '../declarations'
25
- import { logger } from '../logger'
26
-
27
- export const logError = async (context: HookContext, next: NextFunction) => {
28
- try {
29
- await next()
30
- } catch (error: any) {
31
- logger.error(error.stack)
32
-
33
- // Log validation errors
34
- if (error.data) {
35
- logger.error('Data: %O', error.data)
36
- }
37
-
38
- throw error
39
- }
40
- }
41
- `
42
-
43
- export const generate = (ctx: AppGeneratorContext) =>
44
- Promise.resolve(ctx)
45
- .then(
46
- renderSource(
47
- template,
48
- toFile<AppGeneratorContext>(({ lib }) => lib, 'logger')
49
- )
50
- )
51
- .then(
52
- renderSource(
53
- logErrorTemplate,
54
- toFile<AppGeneratorContext>(({ lib }) => lib, 'hooks', 'log-error')
55
- )
56
- )
@@ -1,78 +0,0 @@
1
- import { toFile, writeJSON } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
-
4
- const jsPackageJson = (lib: string) => ({
5
- type: 'module',
6
- scripts: {
7
- start: `node ${lib}`,
8
- dev: `nodemon ${lib}/`,
9
- prettier: 'npx prettier "**/*.js" --write',
10
- mocha: 'cross-env NODE_ENV=test mocha test/ --recursive --exit',
11
- test: 'npm run mocha',
12
- 'bundle:client': 'npm pack --pack-destination ./public'
13
- }
14
- })
15
-
16
- const tsPackageJson = (lib: string) => ({
17
- scripts: {
18
- dev: `nodemon -x ts-node ${lib}/index.ts`,
19
- compile: 'shx rm -rf lib/ && tsc',
20
- start: 'node lib/',
21
- prettier: 'npx prettier "**/*.ts" --write',
22
- mocha:
23
- 'cross-env NODE_ENV=test mocha test/ --require ts-node/register --recursive --extension .ts --exit',
24
- test: 'npm run mocha',
25
- 'bundle:client': 'npm run compile && npm pack --pack-destination ./public'
26
- }
27
- })
28
-
29
- const packageJson = ({
30
- name,
31
- description,
32
- client,
33
- language,
34
- packager,
35
- database,
36
- framework,
37
- transports,
38
- lib,
39
- test,
40
- schema
41
- }: AppGeneratorContext) => ({
42
- name,
43
- description,
44
- version: '0.0.0',
45
- homepage: '',
46
- private: true,
47
- keywords: ['feathers'],
48
- author: {},
49
- contributors: [] as string[],
50
- bugs: {},
51
- engines: {
52
- node: `>= ${process.version.substring(1)}`
53
- },
54
- feathers: {
55
- language,
56
- packager,
57
- database,
58
- framework,
59
- transports,
60
- schema
61
- },
62
- directories: {
63
- lib,
64
- test
65
- },
66
- ...(client
67
- ? {
68
- files: ['lib/client.js', 'lib/**/*.d.ts', 'lib/**/*.shared.js'],
69
- main: language === 'ts' ? 'lib/client' : `${lib}/client`
70
- }
71
- : {
72
- main: 'lib/index'
73
- }),
74
- ...(language === 'ts' ? tsPackageJson(lib) : jsPackageJson(lib))
75
- })
76
-
77
- export const generate = (ctx: AppGeneratorContext) =>
78
- Promise.resolve(ctx).then(writeJSON(packageJson, toFile('package.json')))
@@ -1,14 +0,0 @@
1
- import { toFile, writeJSON } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
- import { PRETTIERRC } from '../../commons.js'
4
-
5
- export const generate = (ctx: AppGeneratorContext) =>
6
- Promise.resolve(ctx).then(
7
- writeJSON<AppGeneratorContext>(
8
- (ctx) => ({
9
- ...PRETTIERRC,
10
- parser: ctx.language === 'ts' ? 'typescript' : 'babel'
11
- }),
12
- toFile('.prettierrc')
13
- )
14
- )