Add capability to specify an env file to load configuration from in Stencil CLI commands #1143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This adds an
--envFile, -e
flag tostencil init
andstencil start
commands.For
stencil init
, providing the flag will save Stencil configuration to the provided env filename (e.g..env
) except for the custom layouts.For
stencil start
, providing the flag will read Stencil configuration from the provided env filename instead of from the JSON files except for the custom layouts.Marking this as draft for now to have your thoughts on this first before continuing on other commands / making tests succeed. Open to changing approach, or also suggestions instead of merging this PR.
Why?
In our agency, we are planning on eventually eliminating plaintext secrets from the local machines of the developers. We are using 1Password to store the secrets and in local development, the secrets are stored as "secret references" instead of having it as plaintext in
.env
files.For Stencil theme development, the
op run
command cannot be used because Stencil CLI stores the secret in JSON files instead of env files.We have considered having template config/secrets JSON files and using
op inject
to generate the JSON files used by the CLI and delete those after the Stencil command is ran. However, there are worries about things going wrong in the script that will leave thesecrets.stencil.json
undeleted.We have a PoC that has simpler approach that just overrides the
StencilConfigManager
to read from system env vars directly, but maintaining a fork is not preferred. So this PR is opened with a more inclusive approach that is opt-in by providing a flag and allows not using 1Password CLI.Tickets / Documentation
https://developer.1password.com/docs/cli/use-cases#secrets
https://developer.1password.com/docs/cli/secrets-environment-variables/
https://developer.1password.com/docs/cli/secrets-config-files/
cc @bigcommerce/storefront-team