diff --git a/src/daemon-command/script.ts b/src/daemon-command/script.ts index 8f41934..5c69e3e 100644 --- a/src/daemon-command/script.ts +++ b/src/daemon-command/script.ts @@ -1,5 +1,7 @@ import { ChildProcess, execSync, spawn } from "child_process"; import colors from "colors"; +import * as dotenv from "dotenv"; +import * as dotenvExpand from "dotenv-expand"; import { Socket } from "net"; import waitOn from "wait-on"; @@ -8,6 +10,10 @@ import { ScriptDefinition } from "../script-definition.type"; const KEEP_LOG_LINES = 100; export type ScriptStatus = "started" | "stopping" | "stopped" | "waiting" | "backoff"; +const expandedEnv = { ...(process.env as Record) }; +dotenv.config({ processEnv: expandedEnv }); +dotenvExpand.expand({ processEnv: expandedEnv }); + export class Script { scriptDefinition: ScriptDefinition; status: ScriptStatus = "stopped"; @@ -40,7 +46,7 @@ export class Script { const waitOn = Array.isArray(this.scriptDefinition.waitOn) ? this.scriptDefinition.waitOn : [this.scriptDefinition.waitOn]; return waitOn.map((str) => str.replace(/\$[a-z\d_]+/gi, function (match) { - const sub = process.env[match.substring(1)]; + const sub = expandedEnv[match.substring(1)]; return sub || match; }), ); diff --git a/src/index.ts b/src/index.ts index ba3f846..83213ea 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,6 @@ #!/usr/bin/env node import { Command, Option } from "commander"; -import * as dotenv from "dotenv"; -import * as dotenvExpand from "dotenv-expand"; import { logs, restart, shutdown, start, status } from "./commands"; import { startDaemon } from "./commands/start-daemon.command"; @@ -10,9 +8,6 @@ import { stop } from "./commands/stop.command"; export { Config } from "./config.type"; -const env = dotenv.config(); -dotenvExpand.expand(env); - const program = new Command(); // eslint-disable-next-line @typescript-eslint/no-var-requires program.version(require("../package.json").version);