Skip to content

Commit

Permalink
node, start: Support .env (#774)
Browse files Browse the repository at this point in the history
This is a minor convenience over repeated `ENVIRONMENT=local` prefixes.
  • Loading branch information
72636c authored Feb 20, 2022
1 parent 342a539 commit 2e4081a
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 197 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-humans-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"skuba": minor
---

node, start: Load environment variables from `.env` file
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@types/node": ">=14.18",
"chalk": "^4.1.0",
"concurrently": "^7.0.0",
"dotenv": "^16.0.0",
"ejs": "^3.1.6",
"enquirer": "^2.3.6",
"eslint": "^7.27.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default Jest.mergePreset({
\\"build\\": \\"skuba build\\",
\\"format\\": \\"skuba format\\",
\\"lint\\": \\"skuba lint\\",
\\"start\\": \\"ENVIRONMENT=local skuba start\\",
\\"start\\": \\"skuba start\\",
\\"test\\": \\"skuba test --coverage\\",
\\"test:watch\\": \\"skuba test --watch\\"
},
Expand Down
2 changes: 1 addition & 1 deletion src/cli/configure/modules/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('packageModule', () => {
build: 'skuba build',
format: 'skuba format',
lint: 'skuba lint',
start: 'ENVIRONMENT=local skuba start',
start: 'skuba start',
test: 'skuba test --coverage',
'test:watch': 'skuba test --watch',
},
Expand Down
2 changes: 1 addition & 1 deletion src/cli/configure/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const packageModule = async ({
build: type === 'package' ? 'skuba build-package' : 'skuba build',
format: 'skuba format',
lint: 'skuba lint',
...(type === 'package' ? {} : { start: 'ENVIRONMENT=local skuba start' }),
...(type === 'package' ? {} : { start: 'skuba start' }),
test: 'skuba test --coverage',
'test:watch': 'skuba test --watch',
},
Expand Down
4 changes: 3 additions & 1 deletion src/cli/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const node = async () => {
'node',
...args.node,
'--require',
'dotenv/config',
'--require',
'tsconfig-paths/register',
'--require',
'ts-node/register/transpile-only',
Expand All @@ -38,7 +40,7 @@ export const node = async () => {
return tsNode
.createRepl({
service: tsNode.register({
require: ['tsconfig-paths/register'],
require: ['dotenv/config', 'tsconfig-paths/register'],
transpileOnly: true,
}),
})
Expand Down
6 changes: 3 additions & 3 deletions src/cli/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export const start = async () => {
getPort(),
]);

if (!args.entryPoint) {
args.entryPoint = await getEntryPointFromManifest();
}
args.entryPoint ??= await getEntryPointFromManifest();

const execProcess = createExec({
env: {
Expand All @@ -28,6 +26,8 @@ export const start = async () => {
'ts-node-dev',
...args.node,
'--require',
'dotenv/config',
'--require',
'tsconfig-paths/register',
'--respawn',
'--transpile-only',
Expand Down
1 change: 1 addition & 0 deletions template/express-rest-api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENVIRONMENT=local
2 changes: 1 addition & 1 deletion template/express-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "skuba build",
"format": "skuba format",
"lint": "skuba lint",
"start": "ENVIRONMENT=local skuba start --port <%- port %>",
"start": "skuba start --port <%- port %>",
"start:debug": "yarn start --inspect-brk",
"test": "skuba test",
"test:ci": "skuba test --coverage",
Expand Down
2 changes: 1 addition & 1 deletion template/greeter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "skuba build",
"format": "skuba format",
"lint": "skuba lint",
"start": "ENVIRONMENT=local skuba start",
"start": "skuba start",
"start:debug": "yarn start --inspect-brk",
"test": "skuba test",
"test:ci": "skuba test --coverage",
Expand Down
1 change: 1 addition & 0 deletions template/koa-rest-api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENVIRONMENT=local
2 changes: 1 addition & 1 deletion template/koa-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"build": "skuba build",
"format": "skuba format",
"lint": "skuba lint",
"start": "ENVIRONMENT=local skuba start --port <%- port %>",
"start": "skuba start --port <%- port %>",
"start:debug": "yarn start --inspect-brk",
"test": "skuba test",
"test:ci": "skuba test --coverage",
Expand Down
1 change: 1 addition & 0 deletions template/lambda-sqs-worker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENVIRONMENT=local
2 changes: 1 addition & 1 deletion template/lambda-sqs-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"format": "skuba format",
"lint": "skuba lint",
"smoke": "serverless invoke --data '{}' --function Worker",
"start": "ENVIRONMENT=local skuba start --port <%- port %>",
"start": "skuba start --port <%- port %>",
"start:debug": "yarn start --inspect-brk",
"test": "skuba test",
"test:ci": "skuba test --coverage",
Expand Down
Loading

0 comments on commit 2e4081a

Please sign in to comment.