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

[Feature] Add shortcut keys to theme dev #4830

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EvilGenius13
Copy link
Contributor

@EvilGenius13 EvilGenius13 commented Nov 11, 2024

Do you suffer from long logs? Do you accidentally close your browser window and have to scroll all the way up in your terminal to find the theme dev links? Look no further than the addition of shortcut keys!

WHY are these changes introduced?

Closes #4713
Closes https://github.com/Shopify/develop-advanced-edits/issues/427

With the amount of logs theme dev generates, it can be difficult to find the original store links such as previewing your theme, or opening the theme editor. Having shortcut keys is a simple way to open the links without needing to physically click on them in the terminal.

WHAT is this pull request doing?

Add shortcut keys to the theme dev command
We look for keypresses, specifically:
t - opens the theme locally
e - opens the theme editor
p - opens the share preview
g - opens the gift cards preview
we also look for ctrl + c to exit the process (current behaviour)

Screenshot 2024-11-21 at 4 51 40 PM

How to test your changes?

Pull down the branch
Build the branch
Run the theme dev command
Try out the shortcut keys. Click some links, save some files, and see that it does not affect anything else running, ctrl+c out to confirm you can exit the same as before.

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Nov 11, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74.52% (-0% 🔻)
8541/11462
🟡 Branches
70.34% (+0.05% 🔼)
4171/5930
🟡 Functions
74.01% (-0.05% 🔻)
2241/3028
🟡 Lines
75.05% (-0.01% 🔻)
8078/10763
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / update-extension.ts
71.79% (-0.71% 🔻)
58.33% 60%
76.47% (-0.67% 🔻)
🟢
... / app-watcher-esbuild.ts
82.76% (-0.57% 🔻)
100% (+12.5% 🔼)
78.57% (-1.43% 🔻)
85.19% (-2.69% 🔻)
🔴
... / draftable-extension.ts
34.78%
33.33% (-16.67% 🔻)
12.5% 36.36%
🟢
... / bundle.ts
80.65% (-1.71% 🔻)
75.76% (+9.09% 🔼)
66.67% (-6.67% 🔻)
81.67% (-2.01% 🔻)

Test suite run success

1946 tests passing in 885 suites.

Report generated by 🧪jest coverage report action from 45d6424

@EvilGenius13 EvilGenius13 force-pushed the add-shortcut-keys-to-theme-dev branch 2 times, most recently from 6a9b244 to 989d98e Compare November 20, 2024 19:20
@@ -113,7 +142,7 @@ export function renderLinks(store: string, themeId: string, host = DEFAULT_HOST,
body: [
{
list: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using the theme delete command, shortcut keys, such as (y) for yes, are put before the description. We opted to put it after for readability.

@@ -113,7 +142,7 @@ export function renderLinks(store: string, themeId: string, host = DEFAULT_HOST,
body: [
{
list: {
title: {bold: 'Preview your theme'},
title: chalk.bold('Preview your theme ') + chalk.cyan('(t)'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to constraints on the usability of outputContent and outputToken, we were unable to add colour to the list of commands. Using chalk which is already available in the repo allows us to do so.

process.stdin.setRawMode(true)
}

process.stdin.on('keypress', (_str, key) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checking for ctrl + c at the beginning ensures we kill the process. We need to have stdin set to rawMode as it looks character by character and doesn't require hitting the enter key.

@EvilGenius13 EvilGenius13 force-pushed the add-shortcut-keys-to-theme-dev branch 3 times, most recently from a895e5c to ea14203 Compare November 20, 2024 20:37
@EvilGenius13 EvilGenius13 marked this pull request as ready for review November 20, 2024 20:43
@EvilGenius13 EvilGenius13 requested review from a team as code owners November 20, 2024 20:43

This comment has been minimized.

packages/theme/src/cli/services/dev.ts Outdated Show resolved Hide resolved
packages/theme/src/cli/services/dev.ts Outdated Show resolved Hide resolved
}
}

renderLinks(urls)
if (options.open) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Test:

  • Pass 'open'
  • Mock openURL to throw an error
  • Validate that handleOpenURLError is called by checking if renderWarning is called

This commit adds shortcut keys to the theme dev CLI service. The keys are as follows:
e - open theme editor
t - preview your theme locally
p - preview your theme (share)
g - preview gift cards
Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thank you, @EvilGenius13 🔥 🚀 Amazing stuff! I've left only one minor comment :)

renderSuccess({
body: [
{
list: {
title: {bold: 'Preview your theme'},
items: [localUrl],
title: chalk.bold('Preview your theme ') + chalk.cyan('(t)'),
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we could follow the CLI-kit standards to present the shortcuts. Thus, this line could be presented as:

title: [{bold: 'Preview your theme'}, {subdued: '(t)'}],

or:

title: [{bold: 'Preview your theme'}, {command: '(t)'}],

I believe that subdued fits a bit more in this context. While it's a bit tempting to be opinionated about the color, it's nice to use CLI-kit standard colors, so we may make the CLI more cohesive across commands :)

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.

[Feature]: Shopify Theme Dev Shortcuts
4 participants