Skip to content

Commit

Permalink
add --env option for cli to load env file
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 22, 2024
1 parent a817069 commit 152f807
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,21 @@ const checkRegisterFeature = () => {
return true;
};

const loadEnv = (cliOptions) => {
if (!cliOptions.env) {
return;
}
const envFile = cliOptions.env === true ? '.env' : cliOptions.env;
const loadEnvFile = process.loadEnvFile;
if (typeof loadEnvFile === 'function') {
loadEnvFile(envFile);
}
};

const initNodeOptions = async (cliOptions) => {

loadEnv(cliOptions);

const supportRegister = checkRegisterFeature();
if (!supportRegister) {
return;
Expand Down Expand Up @@ -207,6 +220,8 @@ program
.option('--import <module>', 'preload module at startup')
.option('--require <module>', 'preload module at startup')

.option('--env [path]', 'env file (default: ".env")')

.action((_command, cliOptions) => {
const args = [].concat(program.args).concat(subArgv);
if (args[0] === '--') {
Expand Down

0 comments on commit 152f807

Please sign in to comment.