Skip to content

Commit

Permalink
feat(eval): support worker.addSetupFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 10, 2021
1 parent 32e9f2d commit c5f3079
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/plugin-eval/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export function apply(ctx: Context, config: Config = {}) {
// addons are registered in another plugin
if (config.root) ctx.plugin(addon, config)

// wait for dependents to be executed
process.nextTick(() => {
ctx.on('connect', () => ctx.worker.start())
ctx.before('disconnect', () => ctx.worker.stop())
})

ctx.before('command', ({ command, session }) => {
if (command.config.noEval && session._isEval) {
return `不能在 evaluate 指令中调用 ${command.name} 指令。`
Expand Down
11 changes: 9 additions & 2 deletions packages/plugin-eval/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ export class EvalWorker {

constructor(public ctx: Context, public config: EvalConfig) {
this.local = new MainAPI(ctx.app)
ctx.on('connect', () => this.start())
ctx.before('disconnect', () => this.stop())
}

addSetupFile(name: string, filename: string) {
if (this.config.setupFiles[name] === filename) return
const ctx = this[Context.current]
this.config.setupFiles[name] = filename
ctx.before('disconnect', () => {
delete this.config.setupFiles[name]
})
}

// delegated class methods which use instance properties
Expand Down

0 comments on commit c5f3079

Please sign in to comment.