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

Add list and link commands to hydrogen-cli #784

Merged
merged 13 commits into from
May 1, 2023
Merged

Conversation

graygilmore
Copy link
Contributor

@graygilmore graygilmore commented Apr 12, 2023

WHY are these changes introduced?

This is the first of many steps in updating the hydrogen-cli to better communicate and interact with Hydrogen storefronts created on Shopify. We want a seamless experience for developers when they are working on their storefront locally.

WHAT is this pull request doing?

This PR introduces new commands to the CLI:

  • list: list all of the Hydrogen storefronts on a shop
  • link: link your local development to a specific Hydrogen storefront
  • unlink: remove the link to a Hydrogen storefront

In and of itself this change will not introduce any new functionality for developers but it lays a foundation for us to build other commands on top of (coming soon: environment variables). In addition to the commands this introduces a new concept of a Shopify project configuration file that lives inside of your local workspace (and is automatically added to your .gitignore).

This PR is split into smaller, atomic commits that should make reviewing much easier.

List

➜  cli git:(cli-list-and-link) h2 list
Found 2 Hydrogen storefronts on test.myshopify.com:

ID   Name         Production URL                          Current deployment
───  ───────────  ──────────────────────────────────────  ──────────────────────────────────
1    Hydrogen     https://hydrogen-1.o2.myshopify.dev     March 22, 2023, Add lockfile
2    Test Shop    https://test-shop-2.o2.myshopify.dev    March 13, 2023, Update README.md

Link

➜  cli git:(cli-list-and-link) h2 link
?  Choose a storefront to link your local development to:

   (1) Hydrogen https://hydrogen-1.o2.myshopify.dev
>  (2) Test Shop https://test-shop-2.o2.myshopify.dev

   Press ↑↓ arrows to select, enter to confirm

After selection:

✅ Success! Linked to Test Shop.
Admin URL: https://test.myshopify.com/admin/custom_storefronts/2
Site URL: https://test-shop-2.o2.myshopify.dev

HOW to test your changes?

  1. Pull the branch and navigate to the cli directory
  2. Run npm run build
  3. Run export SHOPIFY_HYDROGEN_FLAG_PATH=../../templates/demo-store so we're always targeting the demo store
  4. Run h2 list (note: if h2 is unavailable run npx shopify hydrogen shortcut first) to see a list of your storefronts
  • You should be prompted to provide a shop
  • You should then be prompted to authenticate with that shop
  • If you don't have any storefronts you'll be prompted with next steps to rectify that
  1. Run h2 link to link to a specific storefront
  2. Run h2 unlink to remove the link

Post-merge steps

These commands are currently hidden.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

@gfscott gfscott left a comment

Choose a reason for hiding this comment

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

Nice! 🤩 Few tweaks and questions, and I think I need to tophat it in the terminal to really get the full flavor, but some initial suggestions here.


if (configStorefront && !force) {
const overwriteLink = await renderConfirmationPrompt({
message: `${configStorefront.title} is currently linked to your local environment. Do you want to change storefronts?`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe local project here too?

Wondering if we need to introduce the idea and terminology of local/remote, or if we can get away with storefront as the stand-in for the idea of "remote"

Suggested change
message: `${configStorefront.title} is currently linked to your local environment. Do you want to change storefronts?`,
message: `Your project is currently linked to ${configStorefront.title}. Do you want to re-link to a different Hydrogen storefront?`,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've been struggling with the terminology here because I don't want to keep saying "Hydrogen storefront defined in the admin". Maybe we can include the word Shopify to imply that it's a record we hold?

Your project is currently linked to ${title}. Do you want to re-link to a different Hydrogen storefront on Shopify?

Does "on Shopify" make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe "a different Shopify Hydrogen storefront"?


export default class List extends Command {
static description =
"Returns a list of storefronts in your Shop's Hydrogen sales channel.";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a good idea to name the shop every time. Some people will work across multiple merchant clients etc. Let's just remove even the possibility of ambiguity here.

Also I think it makes sense to be specific across the board about Hydrogen storefronts.

Suggested change
"Returns a list of storefronts in your Shop's Hydrogen sales channel.";
`Returns a list of Hydrogen storefronts available on ${shop}.`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This description won't have access to any data so we can't insert things here, unfortunately. We can make this a little cleaner, though:

Returns a list of Hydrogen storefronts available on a given shop.

@graygilmore graygilmore force-pushed the cli-list-and-link branch 2 times, most recently from 9606961 to 07dae0d Compare April 18, 2023 22:55
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

Good job, just adding minor comments here.
Should we keep these commands hidden from users until they can actually be used for something?

@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

@graygilmore
Copy link
Contributor Author

Should we keep these commands hidden from users until they can actually be used for something?

@frandiox exactly! I was going to keep them hidden until we've been able to get things merged in and have the whole flow tested. I understand anyone will be able to use them if they're watching these PRs (👋🏻) but marking them as hidden is the one lever I feel that's available to us to mark something as beta-ish.

@graygilmore graygilmore marked this pull request as ready for review April 19, 2023 21:46
@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with 2023-04 now that it's been released

@graygilmore graygilmore changed the base branch from 2023-01 to 2023-04 April 21, 2023 18:22
Copy link
Contributor

@cartogram cartogram left a comment

Choose a reason for hiding this comment

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

This looks great! Just a few comments.

});

describe('when a shop is passed via flag', () => {
it('returns the shop', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up, eventually I would like to add the shopify cli eslint configs to this package which will prefer we write test instead of it. We'll change the entire package over in one go when we add the rules.


import {newHydrogenStorefrontUrl} from './admin-urls.js';

export function missingStorefronts(adminSession: AdminSession) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of starting a more specific sub-set of cli-kit/node/ui that is specific to custom-storefronts and lives inside this package (lib/ui?). This should be a future thing, but for now I would call this renderMissingStorefronts so that the name is more suggestive of what the function does (render things).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooo I like that! Let's revisit that idea when this first batch of commands go in.

Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

I'd say let's get this merged asap after checking comments from other reviewers 👍

@graygilmore graygilmore force-pushed the cli-list-and-link branch from 9fc0047 to 0432916 Compare May 1, 2023 17:11
@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with 2023-04 since this was sitting for a week
  • Renamed missingStorefronts to logMissingStorefronts to match missing-routes functions

@graygilmore graygilmore merged commit 3d458e2 into 2023-04 May 1, 2023
@graygilmore graygilmore deleted the cli-list-and-link branch May 1, 2023 18: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.

4 participants