@trigger.dev/cli: Parse .env files using dotenv instead of hand-parsing

This commit is contained in:
Eric Allam
2023-07-17 16:45:12 +01:00
parent b95826840a
commit 1bf2802b67
4 changed files with 20 additions and 27 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/cli": patch
---
Parse .env file using dotenv instead of hand-parsing it
+1
View File
@@ -57,6 +57,7 @@
"chokidar": "^3.5.3",
"commander": "^9.4.1",
"degit": "^2.8.4",
"dotenv": "^16.3.1",
"execa": "^7.0.0",
"gradient-string": "^2.0.2",
"inquirer": "^9.1.4",
+6 -14
View File
@@ -8,6 +8,7 @@ import { pathExists, readFile } from "../utils/fileSystem.js";
import { logger } from "../utils/logger.js";
import { resolvePath } from "../utils/parseNameAndPath.js";
import { TriggerApi } from "../utils/triggerApi.js";
import dotenv from "dotenv";
export const DevCommandOptionsSchema = z.object({
port: z.coerce.number(),
@@ -195,26 +196,17 @@ async function getTriggerApiDetails(path: string, envFile: string) {
process.exit(1);
}
if (
!resolvedEnvFile.content.includes("TRIGGER_API_KEY") ||
!resolvedEnvFile.content.includes("TRIGGER_API_URL")
) {
const parsedEnvFile = dotenv.parse(resolvedEnvFile.content);
if (!parsedEnvFile.TRIGGER_API_KEY || !parsedEnvFile.TRIGGER_API_KEY) {
logger.error(
`You must add TRIGGER_API_KEY and TRIGGER_API_URL to your ${envFile} file.`
);
process.exit(1);
}
const envFileLines = resolvedEnvFile.content.split("\n");
const apiKeyLine = envFileLines.find((line) =>
line.includes("TRIGGER_API_KEY")
);
const apiUrlLine = envFileLines.find((line) =>
line.includes("TRIGGER_API_URL")
);
const apiKey = apiKeyLine?.split("=")[1];
const apiUrl = apiUrlLine?.split("=")[1];
const apiKey = parsedEnvFile.TRIGGER_API_KEY;
const apiUrl = parsedEnvFile.TRIGGER_API_URL;
if (!apiKey || !apiUrl) {
logger.error(
+8 -13
View File
@@ -557,6 +557,7 @@ importers:
chokidar: ^3.5.3
commander: ^9.4.1
degit: ^2.8.4
dotenv: ^16.3.1
execa: ^7.0.0
gradient-string: ^2.0.2
inquirer: ^9.1.4
@@ -580,6 +581,7 @@ importers:
chokidar: 3.5.3
commander: 9.5.0
degit: 2.8.4
dotenv: 16.3.1
execa: 7.0.0
gradient-string: 2.0.2
inquirer: 9.1.4
@@ -11462,7 +11464,7 @@ packages:
/axios/0.21.4_debug@4.3.2:
resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==}
dependencies:
follow-redirects: 1.15.2_debug@4.3.2
follow-redirects: 1.15.2
transitivePeerDependencies:
- debug
dev: false
@@ -13186,6 +13188,11 @@ packages:
engines: {node: '>=12'}
dev: true
/dotenv/16.3.1:
resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==}
engines: {node: '>=12'}
dev: false
/duplexer2/0.1.4:
resolution: {integrity: sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==}
dependencies:
@@ -15249,18 +15256,6 @@ packages:
optional: true
dev: false
/follow-redirects/1.15.2_debug@4.3.2:
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
engines: {node: '>=4.0'}
peerDependencies:
debug: '*'
peerDependenciesMeta:
debug:
optional: true
dependencies:
debug: 4.3.2
dev: false
/for-each/0.3.3:
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
dependencies: