cli icon indicating copy to clipboard operation
cli copied to clipboard

[Feature]: Theme command to load the default environment

Open cesarho opened this issue 1 year ago • 8 comments

What area(s) will this request affect?

Theme

What type of change do you want to see?

New feature

Overview

The Shopify CLI already supports environment settings through shopify.theme.toml. I propose a small tweak to improve the default behavior by automatically loading the default environment if it is available.

Proposed Change Modify the default behavior of shopify theme related command to load the environment configuration by default. Specifically:

  • When a developer runs shopify theme dev, the CLI would effectively execute shopify theme dev -e default in the background.
  • If the developer has created a shopify.theme.toml file with the default store settings, the command will automatically load these settings.
  • If the shopify.theme.toml file doesn’t exist or doesn't contain default environment, the CLI would continue to work as it currently does —without any breaking changes.

Example Configuration

[environments.default]
store = "abc.myshopify.com"

With this change, developers could avoid unexpected deployment issues and simplify their workflow, particularly when switching between different stores.

How do you feel about this feature enhancement? If this makes sense, I’d be happy to go ahead and raise a PR to implement it.

Motivation

Currently, the Shopify CLI remembers the last store that was worked on and keeps this stored for future sessions. However, this behavior can lead to unexpected issues: when a developer switches to another project folder and runs shopify theme dev, the CLI mistakenly uploads files to the previous working store instead of the intended one. This can cause significant, unintended trouble, especially if the developer is unaware of this stored preference.

Although there are alternatives, such as setting the environment variable manually or writing scripts to ensure the correct store information is set, I believe the CLI could handle this more seamlessly by improving the default behavior. A solution that prevents accidental deployment to the wrong store would benefit everyone and make the experience smoother and safer for all users.

cesarho avatar Oct 19 '24 12:10 cesarho

@jamesmengo @graygilmore I believe this issue illustrates well how Shopify CLI aims to support multiple-store development (mentioning this, because I've noticed you're investigating https://github.com/Shopify/cli/issues/3509).

karreiro avatar Oct 21 '24 11:10 karreiro

You can set SHOPIFY_FLAG_ENVIRONMENT in your shell config and overriding that with the -e flag as needed. Let me know how that works out for you!

Related:

  • https://github.com/Shopify/cli/issues/4431

jamesmengo avatar Nov 04 '24 18:11 jamesmengo

I second the addition of a default environment with the shopify.theme.toml is present. It would provide a place to put passwords and the like without having to resort to environment variables until you need to make something "different."

Specifically in the case of #3509 and #4431, it's great to have all the CLI details in an environment and then only change a single value SHOPIFY_FLAG_ENVIRONMENT when you need to switch contexts.

In Shopkeeper, we manipulate the current env via a .env as people move between buckets. In the next release, we'll be changing our defaults to only switch SHOPIFY_FLAG_ENVIRONMENT and recommend people use the TOML for creds.

If a default environment was implemented, we'd probably make our default bucket match in name to remove the additional piece of config. Some extra context if it's helpful.

jeffreyguenther avatar Jan 09 '25 00:01 jeffreyguenther

@cesarho This is great idea and must-have feature for the freelancers that works on multiple "single" stores.

kfalkiewicz avatar Jan 12 '25 10:01 kfalkiewicz

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Feb 24 '25 03:02 github-actions[bot]

People are interested.

jeffreyguenther avatar Feb 24 '25 18:02 jeffreyguenther

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Apr 08 '25 03:04 github-actions[bot]

People are interested, still.

JanVormeister avatar Apr 08 '25 06:04 JanVormeister