datocms / cli

Official CLI to interact with DatoCMS projects!
MIT License
7 stars 7 forks source link

Idea: using `.env` variable for auto generate commands #28

Open thomasverleye opened 2 months ago

thomasverleye commented 2 months ago

The idea

As the CLI is already reading out the DATOCMS_API_TOKEN, would it be an option to use DATOCMS_ENVIRONMENT to use if available for the --autogenerate command?

Bonus points to use a third env variable DATOCMS_ENVIRONMENT_SOURCE from which the user can tell the CLI the fork has been created.

The potential way of working

So the CLI would run something like this automagically when env vars are available:

npx datocms migration:new someMigrationFileName --autogenerate=$DATOCMS_ENVIRONMENT:$DATOCMS_ENVIRONMENT_SOURCE

Reasoning behind the idea

When developing in larger teams it might happen that you create new features and new DatoCMS environments async and create new environment on a frequent basis (especially with continuous deployments).

When one developer brings their changes to main and deploy it to a new environment, the other developers still might need to generate their migration based on an older environment. If they in this case forget to set the source environment, they will end up generating a migration, removing all new fields/models/blocks that have been brought to primary environment.

This feature would make that process slightly less error prone ✌🏻

arcataroger commented 2 months ago

In case anyone else sees this, there is a workaround on the forum: https://community.datocms.com/t/datocms-cli-env-variable-usage-for-environment-names/5304/3?u=roger