Skip to content

Add an option to generate a minimal project with Yeoman #1967

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

JMazat
Copy link

@JMazat JMazat commented Jun 25, 2025

This PR introduces in generator-langium, the ability to generate a minimal project instead of the current example "Hello World" project.

The aim of this PR is to skip the tedious process of removing from the currently generated project, anything that is irrelevant to the target language. This speeds up the setup process and avoids the need for error-prone refactoring.

This is the intended fix for ticket: #1764.

What is new

We added questions to be able to choose between the minimal and example projects, without changing the current default behaviour:

  • "Generate example project?"
    Default: Yes
  • "Your grammar entry rule name:"
    Default: Model
    This is only shown if the user answered No to the above question.
    This lets the user choose their own entry name and skip the refactoring that's currently needed.

The generated minimal project is a cleaned-up, de-contextualised version of the example project. It contains TODOs throughout the files to guide the user and provide useful resources, and it should compile as it is.

We can also find commented (non-compiling) code that can be used to quickly implement features and tests that are often needed.

If the user adds the CLI project, a minimal CLI project will also be generated.

How it's done

We decided to keep it simple and use what had already been done as much as possible.

The templates language and cli have been renamed to language-example and cli-example. Separate folders, language-minimal and cli-minimal, contain the base files needed to generate the minimal projects. As no files are shared between these projects, they can be maintained independently and used with the current implementation.

Programmatically we simply change the source folders to be copied based on the user's answers. We have added a new tag <%= EntryName %> in language-minimal that is replaced by the chosen entry name.

@JMazat JMazat marked this pull request as ready for review June 25, 2025 08:38
@JMazat
Copy link
Author

JMazat commented Jun 25, 2025

We are open to suggestions and changes. We made choices based on our needs, but we are unsure what would be preferred here.

I'm mainly thinking about the CLI, which might not be necessary for a minimal project, and the commented code, which could be considered unnecessary.

@msujew msujew self-requested a review June 30, 2025 09:49
@JMazat
Copy link
Author

JMazat commented Jul 4, 2025

I need some help please. I'm looking into this pipeline issue, but I don't understand how to resolve it.

On my branch merged with an up-to-date main:

When I try to run either npm run langium:generate or npm test, I get errors relating to AbstractElement. As far as I understand, this is not something that the generator-langium project should have any influence over.

On my fork's up-to-date main:

The same errors occur.

I also tried bumping the version and updating dependencies first, but the behaviour was the same.

What I am doing wrong here? Thanks.

@msujew
Copy link
Member

msujew commented Jul 4, 2025

@JMazat It seems like you merged main into your branch, which rewrote the history. This in turn makes GitHub think that you now want to merge all those changes into main again, leading to a bunch of merge conflicts (and likely the CI failure as well). I would recommend you to simply rebase your change on the latest main and force push your branch instead.

@JMazat JMazat force-pushed the add-example-prompt branch from 842b90b to c08be17 Compare July 4, 2025 14:25
@JMazat JMazat force-pushed the add-example-prompt branch from c08be17 to 815f9bd Compare July 4, 2025 14:28
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Aside from #1967 (comment) and my comment (see below), I think this looks quite good. We can always iterate on that after merge.

@JMazat JMazat force-pushed the add-example-prompt branch from 815f9bd to a0f5e59 Compare July 7, 2025 10:28
The `.js` extension is no longer imposed when generating a file.
Now, the `destination` parameter is required and indicates where
to generate the file, and with what exension.

The `filePath` parameter is renamed as `source` to better fit
the new behaviour and make the code more readable.
Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Great! Just two details below.

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Thanks - cli-example/src/generator.ts and cli-example/src/main.ts need the new variable for the entry rule name, too.

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.

4 participants