Skip to content

Commit

Permalink
feat(loader): support envData.startTime
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 9, 2023
1 parent ed2ec75 commit e85f94b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/koishi/src/cli/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace Event {

let child: ChildProcess

process.env.KOISHI_SHARED = '{}'
process.env.KOISHI_SHARED = JSON.stringify({
startTime: Date.now(),
})

function toArg(key: string) {
return key.length === 1 ? `-${key}` : `--${hyphenate(key)}`
Expand Down
8 changes: 6 additions & 2 deletions packages/loader/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare module '@koishijs/core' {

interface EnvData {
message?: StartMessage
startTime?: number
}
}

Expand Down Expand Up @@ -110,7 +111,10 @@ export abstract class Loader {

// process
public baseDir = process.cwd()
public envData = JSON.parse(process.env.KOISHI_SHARED || '{}')
public envData = process.env.KOISHI_SHARED
? JSON.parse(process.env.KOISHI_SHARED)
: { startTime: Date.now() }

public params = {
env: process.env,
}
Expand Down Expand Up @@ -139,7 +143,6 @@ export abstract class Loader {
this.prolog = this.prolog.slice(-1000)
},
})
new Logger('app').info('%C', `Koishi/${version}`)
}

async init(filename?: string) {
Expand Down Expand Up @@ -315,6 +318,7 @@ export abstract class Loader {
}

async createApp() {
new Logger('app').info('%C', `Koishi/${version}`)
const app = this.app = new Context(this.interpolate(this.config))
app.loader = this
app.baseDir = this.baseDir
Expand Down

0 comments on commit e85f94b

Please sign in to comment.