In my Typescript project, I am working on matching all environment variables that are de-structured from process.env
. This includes de-structuring on both single and multiple lines.
Consider the following examples in TS code that involve de-structuring from process.env. One example is on a single line, while the other spans across multiple lines:
File1.ts:
const { OKTA_AUDIENCE_DOMAIN, OKTA_DOMAIN = '', OKTA_WEB_CLIENT_ID, OKTA_ISSUER: issuer = '', AUTH_TWO: ISSUE_TWO = '', } = process.env;
File2.ts:
const {
OKTA_AUDIENCE_DOMAIN,
OKTA_DOMAIN = '',
OKTA_WEB_CLIENT_ID,
OKTA_ISSUER: issuer = '',
AUTH_TWO: ISSUE_TWO = '',
} = process.env;
I have managed to create a script that matches de-structured variables on a single line. However, I want it to be able to match variables de-structured on both single and multiple lines.
This is the current script I have:
grep -Ezo '\{[^}]*\} = process.env' File1.ts
If run on File1
, it should give me the expected output as follows:
{ AUTH0_AUDIENCE_DOMAIN, AUTH0_DOMAIN = '', AUTH0_WEB_CLIENT_ID, AUTH0_ISSUER: issuer = '', AUTH_TWO: ISSUE_TWO = '', } = process.env
As seen here, the script has successfully matched the environment variables being de-structured from process.env.
However, running the same script on File2.ts
will return empty output:
grep -Ezo '\{[^}]*\} = process.env' File2.ts
The result is blank.
I am looking for a way to modify this script so that it can correctly match environment variables being de-structured on both single and multiple lines.