Skip to content

Commit b773fa5

Browse files
authored
fix(cli): Generator fixes to work with the new guide (#2674)
1 parent 5b84925 commit b773fa5

10 files changed

Lines changed: 237 additions & 89 deletions

File tree

package-lock.json

Lines changed: 200 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/app/templates/app.test.tpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('Feathers application tests', () => {
1818
server = await app.listen(port)
1919
})
2020
21-
after(done => {
22-
server.close(done)
21+
after(async () => {
22+
await app.teardown()
2323
})
2424
2525
it('starts and shows the index page', async () => {

packages/cli/src/app/templates/channels.tpl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const channels = (app: Application) => {
2424
// connection can be undefined if there is no
2525
// real-time connection, e.g. when logging in via REST
2626
if(connection) {
27-
// Obtain the logged in user from the connection
28-
// const user = connection.user
27+
// Obtain the logged in user
28+
// const user = authResult.user
2929
3030
// The connection is no longer anonymous, remove it
3131
app.channel('anonymous').leave(connection)
@@ -52,8 +52,6 @@ export const channels = (app: Application) => {
5252
// Here you can add event publishers to channels set up in \`channels.js\`
5353
// To publish only for a specific event use \`app.publish(eventname, () => {})\`
5454
55-
console.log('Publishing all events to all authenticated users. See \`channels.js\` and https://docs.feathersjs.com/api/channels.html for more information.') // eslint-disable-line
56-
5755
// e.g. to publish all service events to all authenticated users use
5856
return app.channel('authenticated')
5957
})

packages/cli/src/app/templates/client.tpl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { renderSource } from '../../commons'
33
import { AppGeneratorContext } from '../index'
44

55
const template = ({}: AppGeneratorContext) =>
6-
`import { feathers, type Service, type TransportConnection } from '@feathersjs/feathers'
6+
`import { feathers } from '@feathersjs/feathers'
7+
import type { Service, TransportConnection, Params } from '@feathersjs/feathers'
78
89
// A mapping of client side services
910
export interface ServiceTypes {

packages/cli/src/app/templates/tsconfig.json.tpl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ export const generate = (ctx: AppGeneratorContext) =>
1313
compilerOptions: {
1414
target: 'es2020',
1515
module: 'commonjs',
16-
outDir: './dist',
16+
outDir: './lib',
1717
rootDir: `./${lib}`,
1818
strict: true,
1919
esModuleInterop: true
2020
},
21+
include: [lib],
2122
exclude: ['test']
2223
}),
2324
toFile('tsconfig.json')

packages/cli/src/authentication/templates/knex.tpl.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,24 @@ export async function down(knex: Knex): Promise<void> {
3939
`
4040

4141
export const generate = (ctx: AuthenticationGeneratorContext) =>
42-
generator(ctx).then(
43-
when(
44-
(ctx) => getDatabaseAdapter(ctx.feathers.database) === 'knex',
45-
renderSource(
46-
migrationTemplate,
47-
toFile(
48-
toFile<AuthenticationGeneratorContext>('migrations', () => {
49-
const now = new Date()
50-
const migrationDate =
51-
`${now.getUTCFullYear()}${now.getUTCMonth()}${now.getUTCDay()}` +
52-
`${now.getUTCHours()}${now.getUTCMinutes()}${now.getUTCSeconds() + 1}`
42+
generator(ctx)
43+
// We need to wait a second otherwise the migration filenames won't be in the right order
44+
.then(
45+
(ctx) => new Promise<AuthenticationGeneratorContext>((resolve) => setTimeout(() => resolve(ctx), 1100))
46+
)
47+
.then(
48+
when(
49+
(ctx) => getDatabaseAdapter(ctx.feathers.database) === 'knex',
50+
renderSource(
51+
migrationTemplate,
52+
toFile(
53+
toFile<AuthenticationGeneratorContext>('migrations', () => {
54+
// Probably not great but it works to align with the Knex migration file format
55+
const migrationDate = new Date().toISOString().replace(/\D/g, '').substring(0, 14)
5356

54-
return `${migrationDate}_authentication`
55-
})
57+
return `${migrationDate}_authentication`
58+
})
59+
)
5660
)
5761
)
5862
)
59-
)

packages/cli/src/connection/templates/knex.tpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const generate = (ctx: ConnectionGeneratorContext) =>
5757
{
5858
scripts: {
5959
migrate: 'knex migrate:latest',
60-
'migrate:create': 'knex migrate:create',
60+
'migrate:make': 'knex migrate:make',
6161
test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
6262
}
6363
},

packages/cli/src/service/type/knex.tpl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ export const generate = (ctx: ServiceGeneratorContext) =>
5151
renderSource(
5252
migrationTemplate,
5353
toFile<ServiceGeneratorContext>('migrations', ({ kebabName }) => {
54-
const now = new Date()
55-
const migrationDate =
56-
`${now.getUTCFullYear()}${now.getUTCMonth()}${now.getUTCDay()}` +
57-
`${now.getUTCHours()}${now.getUTCMinutes()}${now.getUTCSeconds()}`
54+
// Probably not great but it works to align with the Knex migration file format
55+
const migrationDate = new Date().toISOString().replace(/\D/g, '').substring(0, 14)
5856

5957
return `${migrationDate}_${kebabName}`
6058
})

packages/cli/test/generators.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('@feathersjs/cli', () => {
3535

3636
before(async () => {
3737
cwd = await mkdtemp(path.join(os.tmpdir(), name + '-'))
38-
console.log(cwd)
3938
context = await generate(
4039
getContext<AppGeneratorContext>(
4140
{
@@ -115,6 +114,14 @@ describe('@feathersjs/cli', () => {
115114
assert.ok(customServiceContext)
116115
assert.strictEqual(testResult, 0)
117116
})
117+
118+
it('compiles successfully', async () => {
119+
if (language === 'ts' && framework === 'koa') {
120+
const testResult = await context.pinion.exec('npm', ['run', 'compile'], { cwd })
121+
122+
assert.strictEqual(testResult, 0)
123+
}
124+
})
118125
})
119126
}
120127
})

packages/knex/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"*.js"
4040
],
4141
"scripts": {
42+
"prepublish": "npm run compile",
4243
"compile": "shx rm -rf lib/ && tsc",
4344
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
4445
},

0 commit comments

Comments
 (0)