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 project preview command #1367

Merged
merged 6 commits into from
Jan 16, 2024
Merged

Conversation

volodymyr-rutskyi
Copy link
Contributor

@volodymyr-rutskyi volodymyr-rutskyi commented Dec 22, 2023

What/Why/How?

Add a preview command that allows to run a preview of Redocly projects.
The command can accept the product to use for preview as an argument, deduce it fro the project's package.json, or use Realm by default.

The product package is executed via NPX.

The supported products are:

  • Redoc: @redocly/redoc
  • Revel: @redocly/revel
  • Reef: @redocly/reef
  • Realm: @redocly/realm
  • Redoc + Revel: @redocly/redoc-revel
  • Redoc + Reef: @redocly/redoc-reef
  • Revel + Reef: @redocly/revel-reef

Reference

Docs PR: #1384

Testing

Screenshots (optional)

image

Check yourself

  • Code is linted
  • Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@volodymyr-rutskyi volodymyr-rutskyi requested a review from a team as a code owner December 22, 2023 08:09
Copy link

changeset-bot bot commented Dec 22, 2023

⚠️ No Changeset found

Latest commit: a26c262

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 22, 2023

Command Mean [s] Min [s] Max [s] Relative
redocly lint packages/core/src/benchmark/benches/rebilly.yaml 1.060 ± 0.049 1.021 1.195 1.01 ± 0.05
redocly-next lint packages/core/src/benchmark/benches/rebilly.yaml 1.053 ± 0.023 1.015 1.083 1.00

Copy link
Contributor

github-actions bot commented Dec 22, 2023

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 75.8% 4100/5409
🟡 Branches 66.09% 2183/3303
🟡 Functions 68.14% 663/973
🟡 Lines 76% 3847/5062
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / constants.ts
0% 100% 100% 0%
🔴
... / index.ts
0% 0% 0% 0%

Test suite run success

671 tests passing in 94 suites.

Report generated by 🧪jest coverage report action from a26c262

@volodymyr-rutskyi volodymyr-rutskyi changed the title feat: add project previiew command feat: add project preview command Jan 4, 2024
packages/cli/src/commands/preview-project/index.ts Outdated Show resolved Hide resolved
packages/cli/src/index.ts Show resolved Hide resolved
packages/cli/src/commands/preview-project/index.ts Outdated Show resolved Hide resolved
packages/cli/src/index.ts Outdated Show resolved Hide resolved
volodymyr-rutskyi and others added 2 commits January 5, 2024 10:12
Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
@tatomyr
Copy link
Contributor

tatomyr commented Jan 5, 2024

This looks good. However, the solution seems to be fragile. I'm afraid of the future situation when a user has an older version of Redocly CLI with one config structure, and the preview command pulls the latest version of Realm with a different config schema. Am I getting that right? Can we avoid the situation somehow?

@lornajane
Copy link
Contributor

If the user has the other package dependency installed, could that package be used instead of npx? I'm thinking of how we evolve changes that affect both packages, and how users can pin versions if they need to (either for software dependency process reasons, or because they aren't ready to accept a change in our newer releases).

I'm not sure if the errors are coming through to the CLI correctly. If you supply a directory that is not a directory, it says it's launching the preview and then exits.

@lornajane
Copy link
Contributor

A few comments on the command design:

  • The project directory argument is strange, could we use --sourceDir instead, or something else?
  • Is the directory required? It looks like it's not, but then the default (the current directory I think) should be included in the help output.
  • What's the default value for the optional product parameter? (I think realm? Let's just add it to the help output)
  • Please expand the command description to say what it does, it's too terse IMO.

I don't see any documentation for the preview command, but it should be included with the pull request, especially given the confusing naming with our existing preview-docs command, and explanations added to both pages. We'll also need to add some information about how the preview command is run since it's different to our other commands.

@volodymyr-rutskyi
Copy link
Contributor Author

@lornajane thank you for the extensive feedback!

If the user has the other package dependency installed, could that package be used instead of npx? I'm thinking of how we evolve changes that affect both packages, and how users can pin versions if they need to (either for software dependency process reasons, or because they aren't ready to accept a change in our newer releases).

If the user has one of the product packages in package.json, then that package will be used. Then, if the user has a specific version in node_modules, NPX will launch that version.

However, if the user specifies the product argument, that product's package will be used ignoring what's in package.json (version from `node_modules will still be used if available).


I'm not sure if the errors are coming through to the CLI correctly. If you supply a directory that is not a directory, it says it's launching the preview and then exits.

The CLI preview command only serves as an interface for launching previews using product NPM packages, all of the output from those packages is shown and the console is also interactive. The behavior you described seems to be the fault of the packages that are being launched and should be fixed on that side. I will look into that.


I don't see any documentation for the preview command, but it should be included with the pull request, especially given the confusing naming with our existing preview-docs command, and explanations added to both pages. We'll also need to add some information about how the preview command is run since it's different to our other commands.

I was told that the docs should come in a separate PR because the docs are published right after PR merge and the CLI changes go through a different release process. I have the docs as a WIP and will open a PR and link it to this one later today or on Monday morning.


What's the default value for the optional product parameter? (I think realm? Let's just add it to the help output)

By default if the argument is not specified it tries to find a package.json file in the project directory and see if one of the packages is present there. If not, it defaults to realm. That info will be in the docs and I'll try to make it clearer in the help output.

@volodymyr-rutskyi
Copy link
Contributor Author

This looks good. However, the solution seems to be fragile. I'm afraid of the future situation when a user has an older version of Redocly CLI with one config structure, and the preview command pulls the latest version of Realm with a different config schema. Am I getting that right? Can we avoid the situation somehow?

This should not be a problem. The preview does not rely on Redocly CLI for config. Right now, product NPM packages handle config schema by themselves and in the future they might handle config using the core package pinned in their dependencies, but should not rely on the CLI that launches them.

@volodymyr-rutskyi volodymyr-rutskyi mentioned this pull request Jan 8, 2024
5 tasks
@volodymyr-rutskyi
Copy link
Contributor Author

Adjusted some naming and descriptions and linked a PR with documentation for the command.
@lornajane

@volodymyr-rutskyi volodymyr-rutskyi merged commit 8e29966 into main Jan 16, 2024
29 checks passed
@volodymyr-rutskyi volodymyr-rutskyi deleted the feat/project-preview-command branch January 16, 2024 11:00
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.

3 participants