Skip to content
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

feat: add makeUsingStub to BaseCommand #4147

Merged
merged 1 commit into from
May 9, 2023
Merged

Conversation

Julien-R44
Copy link
Member

@Julien-R44 Julien-R44 commented May 8, 2023

Proposed changes

Add a method makeUsingStub to Ace BaseCommand.

this.makeUsingStub(stubPath, stubState, stubsRoot)

Further comments

Not sure about this PR. It doesn't seem very clean to me because we have a particular OOP architecture here and so I was forced to duplicate the code in ListCommand, and also to leave the stubsGenerator property in public. (that's also why I preferred to using composition here by extracting the StubGenerator class)

I almost went further and refactored it maybe with Mixins (to remove the fact that ListCommand implements BaseCommand) because it seems to be problematic
But I prefered to keep it simple and just duplicate for the moment because it's a very small change

Let me know what you think!

@Julien-R44 Julien-R44 requested a review from thetutlage May 8, 2023 13:39
Comment on lines +21 to +46
class StubGenerator {
#command: BaseCommand | ListCommand
#flags: Record<string, any>

constructor(command: BaseCommand, flags: Record<string, any>) {
this.#command = command
this.#flags = flags
}

async generate(stubsRoot: string, stubPath: string, stubState: Record<string, any>) {
const stub = await this.#command.app.stubs.build(stubPath, { source: stubsRoot })
const output = await stub.generate(Object.assign({ flags: this.#flags }, stubState))

const entityFileName = slash(this.#command.app.relativePath(output.destination))
const result = { ...output, relativeFileName: entityFileName }

if (output.status === 'skipped') {
this.#command.logger.action(`create ${entityFileName}`).skipped(output.skipReason)
return result
}

this.#command.logger.action(`create ${entityFileName}`).succeeded()
return result
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this class? Can't we just inline all the generate method code inside the makeUsingStub method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid duplicating the code in the ListCommand class that implements BaseCommand as I explain in my comment above
As it is the case for the terminate function for example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, I see. I think, we will run into this issue more often as we try to expand the capabilities of the base command.

Should we fix it right now maybe using mixins?

@thetutlage thetutlage merged commit 9cbbc09 into next May 9, 2023
7 of 8 checks passed
@thetutlage thetutlage deleted the feat/stubs-generator branch May 9, 2023 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants