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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Move @backstage/cli create-app to separate package #1745

Merged
merged 9 commits into from
Aug 2, 2020

Conversation

ayshiff
Copy link
Contributor

@ayshiff ayshiff commented Jul 26, 2020

Hey, I just made a Pull Request!

Closes #1537

It creates another package create-app which contains the logic for downloading and executing templates.
I need some help to finish this refacto 馃憤

I have some questions about what I did:

  • Is there a place where I could put some utilities shared between different packages (the src/lib(paths-tasks...).ts utilities). As I need them inside create-app package, it makes it redundant.
  • I don't know if this is a good solution to require templates from another package ? I thought I understood from reading the issue that the package should not contain templates (Shouldn't the packages be independent from each other ?)
  • Should we move the e2e tests related to the create-app inside the package ?

鉁旓笍 Checklist

  • All tests are passing yarn test
  • Screenshots attached (for UI changes)
  • Relevant documentation updated
  • Prettier run on changed files
  • Tests added for new functionality
  • Regression tests added for bug fixes

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Thanks! Sorry about the slow review 馃槄

Definitely agree we need a common place to put some of the modules in the CLI. Some of the stuff is needed in other places too, like the backend and config-loader. Completely fine with having the duplicated code for now and dealing with it in a followup.

Regarding the template the idea as to download it from git, but tbh I think we should just put it in a templates/ folder like in the CLI, and think about downloading it later. The main use-case for downloading is to be able to point to multiple different templates, and we don't have that 馃榿

I think the e2e tests can stay in the CLI, they're testing many different parts of the repo, but mostly related to the CLI.

packages/create-app/README.md Outdated Show resolved Hide resolved
packages/create-app/package.json Outdated Show resolved Hide resolved
"commander": "^4.1.1",
"chalk": "^4.0.0",
"fs-extra": "^9.0.0",
"react-dev-utils": "^10.2.1",
Copy link
Member

Choose a reason for hiding this comment

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

I think we can get rid of this right? Afaik it's only used in the bundling parts of the cli.

@@ -107,7 +107,7 @@ export default async (cmd: Command): Promise<void> => {
];
const answers: Answers = await inquirer.prompt(questions);

const templateDir = paths.resolveOwn('templates/default-app');
const templateDir = paths.resolveOwnRoot('packages/cli/templates/default-app');
Copy link
Member

Choose a reason for hiding this comment

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

So this won't be available when running via npx, as it assumes this monorepo layout we'll be executed as a package in node_modules. I'd say just move over the default-app template to this package instead. It does create a problem with the dependency on the template in app:diff, but tbh I think we can remove that for now as it isn't very useful in its current form anyway.

packages/create-app/src/index.ts Outdated Show resolved Hide resolved
return resolvePath(ownDir, '../..');
}

export function findPaths(): Paths {
Copy link
Member

Choose a reason for hiding this comment

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

Planning to move this entire util and file to a separate package, so let's duplicate this for now and deal with it later.

}
}

export async function templatingTask(
Copy link
Member

@Rugvip Rugvip Jul 28, 2020

Choose a reason for hiding this comment

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

Will be sure to find a common place for these things too 馃榿

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

I think it's time to promote this to a proper PR 馃槑

Best double check that everything has been moved out of the app template in master btw. I think there were some additions recently.

@ayshiff
Copy link
Contributor Author

ayshiff commented Jul 31, 2020

I am a little bit struggling with making the e2e tests pass.

@ayshiff ayshiff marked this pull request as ready for review July 31, 2020 09:11
@ayshiff ayshiff requested a review from a team as a code owner July 31, 2020 09:11
"backstage"
],
"license": "Apache-2.0",
"main": "src/index.ts",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"main": "src/index.ts",
"main": "dist/index.cjs.js",

I think e2e tests break because specifying src/index.ts as the entrypoint causes it to be included in the packages version, just like if you included it in the files list. That in turn causes the entrypoint script to believe that it's a local development package, i.e. isLocal is set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean that I have to put the builder part into the package?

Copy link
Member

Choose a reason for hiding this comment

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

Nah I think this change should be enough

Copy link
Member

Choose a reason for hiding this comment

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

ayshiff#1 馃榿

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @Rugvip 馃憤

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Thanks! Hoping that last addition did the trick 馃榿

@Rugvip Rugvip merged commit bd3d0de into backstage:master Aug 2, 2020
@freben freben mentioned this pull request Aug 4, 2020
@stefanbuck
Copy link
Contributor

Hi,

I've just noticed that running yarn backstage-cli app:diff is failing with

Error: Failed to read template directory: ENOENT: no such file or directory, scandir '/Users/ramba/code/backstage/node_modules/@backstage/cli/templates/default-app'

Looks like changes made in this PR like moving files from packages/cli/templates/default-app/* to packages/create-app/templates/default-app/* is the root cause for this issue.

The fact that no one has noticed this (or at least there is not GitHub issue) makes me wonder if its worth keeping this functionallty at all. On the other hand I'm in the middle of upgrading backstage and without running npx @backstage/create-app I'm kind of lost. Any thoughts?

@benjdlambert
Copy link
Member

@stefanbuck so you're right, I don't think people really use that way as much.

I'd recommend updating the backstage-cli dependency in your project, and then run yarn backstage-cli versions:bump. That will upgrade you to all the latest dependencies, and print change logs for you to go through with some breaking changes.

Feel free to contribute a fix to the this command too if you feel it's better :)

@stefanbuck
Copy link
Contributor

Well, if no one was complaining about this command being broken for the past 6 months, I would rather tend to remove it. Would you would accept a PR for this?

@benjdlambert
Copy link
Member

@Rugvip - thoughts?

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.

Move @backstage/cli create-app to separate package
4 participants