-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: add make:producer command #13
base: feat/kafka-authentication
Are you sure you want to change the base?
Feature: add make:producer command #13
Conversation
This also introduces the idea of a non-explicit commit if autoCommit is true
For some reason these files were suddenly not found, but this works
import { stubsRoot } from '../stubs/main.js' | ||
import { CommandOptions } from '@adonisjs/core/types/ace' | ||
|
||
export default class MakeProducer extends BaseCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file seems to not be emitted using the previous tsc / tsup configuration, hence needing to change.
}, | ||
], | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the export const DefaultProducer = await Kafka.createProducer('default')
or if --producer webhooks
then export const WebhookProducer = await Kafka.createProducer('webhooks')
to #start/kafka.ts
It's a little cludgey but I think it's what we'd want.
await codemods.makeUsingStub(stubsRoot, 'stubs/config/kafka.stub', {}) | ||
await codemods.makeUsingStub(stubsRoot, 'stubs/start/kafka.stub', {}) | ||
await codemods.makeUsingStub(stubsRoot, 'config/kafka.stub', {}) | ||
await codemods.makeUsingStub(stubsRoot, 'start/kafka.stub', {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why I needed to change these, but after adjusting tsc config, suddenly it didn't find the files correctly. Looking at other packages, and it seems I shouldn't have included the stubs/
originally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I had the reverse when I messed with this last, it wouldn’t work without stubs/
even though none of the examples I based this off had them and I tried this in an act of desperation. I’m glad this work correctly now.
} | ||
if (shouldInstallPackages) { | ||
await codemods.installPackages([{ name: 'kafkajs', isDevDependency: false }]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though kafka is a peerDep, this makes sure we install it. There isn't a way to specify a version here though. In theory the peerDep will have us covered, so maybe we don't need this (was inspired by lucid's configure.ts)
9d5d98e
to
f887cd0
Compare
This was really annoying to implement but gives us a
node ace make:producer <topic-name>
which can optionally have a--producer <producerName>
passed. The annoying part was mostly in that tsup / tsc wasn't emitting thebuild/commands/make_producer.js
file, and no matter what I tried I couldn't get it to emit this file.This creates the
app/producers/<TopicName>.ts
file, and if necessary adds a producer to#start/kafka.ts
:The
app/producers/<TopicName>.ts
file needs to be able to import the<ProducerName>Producer
from#start/kafka.ts
, hence doing a codemod and automatically adding it.E.g., in Webhooks, I would've run:
Which would have given me the files that I have in that branch.
If you omit
--producer <produceName>
then it creates a default producer for you calledDefaultProducer
and automatically inserts that to#start/kafka.ts
if necessary.