Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit bbfe7cf

Browse files
committed
feat(cli): add dotenv params
1 parent 2c1561f commit bbfe7cf

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/cli/cli.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
defer,
1212
importDefault,
1313
} from '@neematajs/application'
14+
import { config } from 'dotenv'
1415

1516
/** @type {import('@neematajs/server')} */
1617
const NeemataServer = await import('@neematajs/server').catch(() => null)
@@ -31,15 +32,27 @@ const { values, positionals } = parseArgs({
3132
type: 'string',
3233
multiple: false,
3334
},
35+
env: {
36+
type: 'string',
37+
multiple: true,
38+
default: [],
39+
},
3440
},
3541
})
3642

3743
const [command, ...args] = positionals
38-
const { env, entry, swc, timeout, ...kwargs } = values
44+
const { env: envPaths, entry, swc, timeout, ...kwargs } = values
3945

4046
const shutdownTimeout =
4147
(typeof timeout === 'string' ? Number.parseInt(timeout) : undefined) || 1000
4248

49+
for (const env of envPaths) {
50+
if (typeof env === 'string') {
51+
const { error } = config({ path: env })
52+
if (error) console.warn(error)
53+
}
54+
}
55+
4356
const entryPath = resolve(
4457
process.env.NEEMATA_ENTRY ||
4558
(typeof entry === 'string' ? entry : swc ? 'index.ts' : 'index.js'),

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"dependencies": {
2323
"@swc/core": "^1.4.16",
24+
"dotenv": "^16.4.5",
2425
"tsconfig-paths": "^4.2.0"
2526
},
2627
"peerDependencies": {

packages/server/lib/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class ApplicationServer {
9292
name: type,
9393
execArgv,
9494
workerData,
95+
env: process.env,
9596
})
9697

9798
const { threadId } = worker

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)