Skip to content

Commit

Permalink
feat(cli): Cli to load .env for build and start commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gervwyk committed May 24, 2022
1 parent 7324826 commit ac34fe8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/build/build.js
Expand Up @@ -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 });
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/start/start.js
Expand Up @@ -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 });
}

Expand Down
24 changes: 24 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions yarn.lock
Expand Up @@ -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
Expand Down

0 comments on commit ac34fe8

Please sign in to comment.