Skip to content

Commit

Permalink
feat(cli): add dotenv support
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 13, 2022
1 parent ae91173 commit 13a9feb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"cac": "^6.7.12",
"chokidar": "^3.5.3",
"dotenv": "^16.0.0",
"js-yaml": "^4.1.0",
"kleur": "^4.1.4",
"koishi": "^4.2.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { resolve, extname, dirname, isAbsolute } from 'path'
import { readdirSync, readFileSync, writeFileSync } from 'fs'
import { App, Dict, Logger, interpolate, Modules, unwrapExports, valueMap } from 'koishi'
import * as yaml from 'js-yaml'
import * as dotenv from 'dotenv'

declare module 'koishi' {
namespace Context {
Expand Down Expand Up @@ -81,6 +82,11 @@ export class Loader {
config = module.default || module
}

// load .env file into process.env
dotenv.config({
path: resolve(this.dirname, '.env'),
})

let resolved = new App.Config(config)
if (this.isWritable) {
// schemastery may change original config
Expand Down

0 comments on commit 13a9feb

Please sign in to comment.