Skip to content

[CLI] Generating index.ts in each models/repositories/controllers automatically #1127

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

Closed
dhmlau opened this issue Mar 13, 2018 · 12 comments · Fixed by #1363
Closed

[CLI] Generating index.ts in each models/repositories/controllers automatically #1127

dhmlau opened this issue Mar 13, 2018 · 12 comments · Fixed by #1363
Assignees
Labels
CLI developer-experience Issues affecting ease of use and overall experience of LB users

Comments

@dhmlau
Copy link
Member

dhmlau commented Mar 13, 2018

Description / Steps to reproduce / Feature proposal

In an LB4 app (e.g. in example-getting-started example), it seems like the general pattern is to have the export statements in the index.ts file in each folders (models/repositories/controllers), so that the classes in those folders can simply be imported by
import {SomeClass} from "../models";

Acceptance Criteria

I wonder if this is a good idea to:

  • generate those index.ts automatically as part of lb4 app command
  • for any artifacts created by CLI (currently we only have lb4 controller), add the export in index.ts
    e.g. export * from './someclass.repository';
@dhmlau dhmlau added developer-experience Issues affecting ease of use and overall experience of LB users CLI suggestion labels Mar 13, 2018
@virkt25
Copy link
Contributor

virkt25 commented Mar 13, 2018

Do we still want this with pattern with @loopback/boot in place which can just discover and bind the classes.

That said someone might still want to import a class for type information

@shimks
Copy link
Contributor

shimks commented Mar 13, 2018

I'd say we still want this so that users can easily import them to unit/integration test. That being said, I'm not sure if this is something we NEED to have.

@dhmlau
Copy link
Member Author

dhmlau commented Mar 13, 2018

Currently if I want to reference some model in models folder in a controller, i think we still need to import it even with boot. right?
IMO, it's just nice-to-have, because when I was creating my own app, I had to create the index.ts for each folder. It would be nice if the tooling can do it for me. But we don't have the generator for models and repositories (which might have bigger need).

@virkt25
Copy link
Contributor

virkt25 commented Mar 13, 2018

If we are generating the artifacts, this part should be easy. +1 for it.

@raymondfeng
Copy link
Contributor

The complexity comes into play when we add the 2nd controller. To maintain controllers/index.ts, the cli needs to know to how to add new entries to the existing index.ts.

@shimks
Copy link
Contributor

shimks commented Mar 13, 2018

That sounds easy enough for me; check the content of index.ts if it exists. If the import is already there, leave it alone. If it isn't, then add it.

@dhmlau
Copy link
Member Author

dhmlau commented Mar 13, 2018

i thought we are going to have a separate export statement for each class? then if it exists, then we have to append from what's existing.

export * from './test1.controller';
export * from './test2.controller';

@virkt25
Copy link
Contributor

virkt25 commented Mar 13, 2018

Well, when a new artifact is generated using lb4 it should generate a index.ts in the artifact folder if not present and if present, it should append the new file as an import.

@dhmlau dhmlau added the DP3 label Apr 19, 2018
@dhmlau
Copy link
Member Author

dhmlau commented Apr 19, 2018

Discussed with @bajtos , what's in scope for DP3 is to decide as a team on what to do with this.

@virkt25
Copy link
Contributor

virkt25 commented Apr 19, 2018

This isn't anything particularly difficult about implementing this IMO. Here's some modules we can leverage to accomplish this task:

@bajtos
Copy link
Member

bajtos commented Apr 27, 2018

@virkt25 nice! I'd rather avoid using modules in 0.x version, that leaves only one candidate: https://www.npmjs.com/package/create-ts-index

Originally, I was thinking about editing index.ts files manually in our lb4 CLI. If create-ts-index works well enough, then I am all for using it.

virkt25 added a commit that referenced this issue May 25, 2018
virkt25 added a commit that referenced this issue May 26, 2018
@bajtos
Copy link
Member

bajtos commented May 29, 2018

Assigned to @virkt25, looks like he is already working on something related in #1363

virkt25 added a commit that referenced this issue May 30, 2018
virkt25 added a commit that referenced this issue Jun 1, 2018
virkt25 added a commit that referenced this issue Jun 2, 2018
virkt25 added a commit that referenced this issue Jun 3, 2018
virkt25 added a commit that referenced this issue Jun 4, 2018
virkt25 added a commit that referenced this issue Jun 4, 2018
virkt25 added a commit that referenced this issue Jun 5, 2018
@dhmlau dhmlau added this to the June Milestone milestone Jun 5, 2018
virkt25 added a commit that referenced this issue Jun 12, 2018
virkt25 added a commit that referenced this issue Jun 13, 2018
@bajtos bajtos added the p1 label Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI developer-experience Issues affecting ease of use and overall experience of LB users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants