What I have
I have multiple projects using Percy for Cypress where I set the PERCY_TOKEN
env variable inside the .env
file. The token is different for each project. In the CI I set different env variables for each project, but locally I have to do it in the .env
file. Because of this, I have to edit the .env
file whenever I change between projects.
Goal
I would like to set them in the .env
file this way:
PROJECT_A_PERCY_TOKEN=tokenhash1PROJECT_B_PERCY_TOKEN=tokenhash2
So later I could rename these variables to PERCY_TOKEN
, eliminating the need to constantly change the .env
file.
What I tried
I'm trying to do this inside the package.json
file's scripts
property. Unfortunately echo $PROJECT_A_PERCY_TOKEN
prints nothing. I know that I could create a shell/python/js script that parses the .env
file, then passes the value back or calls npm run
directly but I would like to do this without an external script.
Problem
It appears to me that I can't access the env variables inside package.json
. Is there a way to rename the variable only using the npm script?