diff --git a/.pnp.cjs b/.pnp.cjs index 315339e1c4..d09ea9036f 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -12104,6 +12104,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["commander", "npm:9.0.0"], ["decompress", "npm:4.2.1"], ["decompress-targz", "npm:4.1.1"], + ["dotenv", "npm:15.0.0"], ["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.5.1"], ["ora", "npm:5.4.1"], ["uuid", "npm:8.3.2"], diff --git a/packages/cli/package.json b/packages/cli/package.json index 3502941098..b11bce0a7a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -47,6 +47,7 @@ "commander": "9.0.0", "decompress": "4.2.1", "decompress-targz": "4.1.1", + "dotenv": "15.0.0", "ora": "5.4.1", "uuid": "8.3.2", "yaml": "2.0.0-10" diff --git a/packages/cli/src/commands/build/build.js b/packages/cli/src/commands/build/build.js index 674a4a4c69..a6da6af5f0 100644 --- a/packages/cli/src/commands/build/build.js +++ b/packages/cli/src/commands/build/build.js @@ -18,11 +18,13 @@ import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js'; import copyPluginsFolder from '../../utils/copyPluginsFolder.js'; import getServer from '../../utils/getServer.js'; import installServer from '../../utils/installServer.js'; +import readDotEnv from '../../utils/readDotEnv.js'; import runLowdefyBuild from '../../utils/runLowdefyBuild.js'; import runNextBuild from '../../utils/runNextBuild.js'; async function build({ context }) { context.print.info('Starting build.'); + readDotEnv(context); const directory = context.directories.server; await getServer({ context, packageName: '@lowdefy/server', directory }); await copyPluginsFolder({ context, directory }); diff --git a/packages/cli/src/commands/start/start.js b/packages/cli/src/commands/start/start.js index 2c70aedc3f..a423ec7d17 100644 --- a/packages/cli/src/commands/start/start.js +++ b/packages/cli/src/commands/start/start.js @@ -15,12 +15,14 @@ */ import runStart from './runStart.js'; +import readDotEnv from '../../utils/readDotEnv.js'; // TODO: Handle "spawn yarn ENOENT" error if no built server exists. async function build({ context }) { context.print.info('Starting server.'); context.sendTelemetry({ sendTypes: true }); + readDotEnv(context); await runStart({ context, directory: context.directories.server }); } diff --git a/packages/cli/src/utils/readDotEnv.js b/packages/cli/src/utils/readDotEnv.js new file mode 100644 index 0000000000..0cda5c14f7 --- /dev/null +++ b/packages/cli/src/utils/readDotEnv.js @@ -0,0 +1,24 @@ +/* + Copyright 2020-2022 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import path from 'path'; +import dotenv from 'dotenv'; + +function readDotEnv(context) { + dotenv.config({ path: path.join(context.directories.config, '.env'), silent: true }); +} + +export default readDotEnv; diff --git a/yarn.lock b/yarn.lock index c00ab4ea86..0d28701774 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9962,6 +9962,7 @@ __metadata: commander: 9.0.0 decompress: 4.2.1 decompress-targz: 4.1.1 + dotenv: 15.0.0 jest: 27.5.1 ora: 5.4.1 uuid: 8.3.2