Skip to content

Commit e4eb457

Browse files
committed
feat: adds .env file support
1 parent 2c6f085 commit e4eb457

9 files changed

+56
-0
lines changed

.env.example

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitattributes

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/deps.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/files.json

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { awscdk, javascript, SampleFile, TextFile } from 'projen';
12
import { CdkConfig } from 'projen/lib/awscdk';
23

34
const project = new awscdk.AwsCdkConstructLibrary({
@@ -21,13 +22,35 @@ const project = new awscdk.AwsCdkConstructLibrary({
2122
'@aws-cdk/integ-tests-alpha',
2223
'@types/env-ci',
2324
'esbuild',
25+
'dotenv',
2426
],
2527
gitignore: [
28+
'.env',
2629
'cdk.context.json',
2730
],
2831
integrationTestAutoDiscover: true,
2932
});
3033

34+
const DOT_ENV_EXAMPLE: Record<string, string> = {
35+
AWS_ACCOUNT_ID: '000000000',
36+
ROOT_ZONE_NAME: 'foo.example.com',
37+
};
38+
39+
const dotEnvExample = new TextFile(project, '.env.example', {
40+
lines: Object.entries(DOT_ENV_EXAMPLE).map((kv) => kv.join('=')),
41+
});
42+
43+
new TextFile(project, `${project.testdir}/env.ts`, {
44+
lines: [
45+
"import 'dotenv/config';",
46+
...Object.keys(DOT_ENV_EXAMPLE).map((key) => `export const ${key} = String(process.env.${key});`),
47+
],
48+
});
49+
50+
new SampleFile(project, '.env', {
51+
sourcePath: dotEnvExample.path,
52+
});
53+
3154
// Fixes: https://github.com/projen/projen/issues/1347
3255
const cdkConfig = new CdkConfig(project, {
3356
app: '', // Required for types.

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/env.ts

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)