Skip to content

Commit

Permalink
feat(play): support config storage
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 16, 2023
1 parent be33853 commit baa31a3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
7 changes: 5 additions & 2 deletions packages/console/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ export class Client {
readonly id: string = Random.id()

constructor(readonly ctx: Context, public socket: AbstractWebSocket) {
socket.addEventListener('message', this.receive.bind(this))
socket.addEventListener('message', this.receive)
ctx.on('dispose', () => {
socket.removeEventListener('message', this.receive)
})
this.refresh()
}

send(payload: any) {
this.socket.send(JSON.stringify(payload))
}

async receive(data: AbstractWebSocket.MessageEvent) {
receive = async (data: AbstractWebSocket.MessageEvent) => {
const { type, args, id } = JSON.parse(data.data.toString())
const listener = this.ctx.console.listeners[type]
if (!listener) {
Expand Down
1 change: 0 additions & 1 deletion packages/insight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
},
"devDependencies": {
"@koishijs/client": "^5.4.0",
"@koishijs/loader": "^2.6.1",
"@types/d3-force": "^3.0.3",
"@types/throttle-debounce": "^2.1.0",
"d3-force": "^3.0.0"
Expand Down
10 changes: 2 additions & 8 deletions packages/play/app/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function resolveName(name: string) {
}
}

process.cwd = () => '/'

class BrowserLoader extends Loader {
public envData: any = {}
public config: any = { plugins: {} }
Expand All @@ -27,14 +29,6 @@ class BrowserLoader extends Loader {
}
}

readConfig() {
return {}
}

writeConfig() {
this.app.emit('config')
}

async resolve(name: string) {
await (this._initTask ||= this.prepare())
return this.cache[name]
Expand Down
7 changes: 4 additions & 3 deletions packages/play/app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref } from 'vue'
import { useLocalStorage } from '@vueuse/core'
import { dump, load } from 'js-yaml'
import { dump } from 'js-yaml'
import { promises as fs } from 'fs'
import loader from './loader'

Expand Down Expand Up @@ -42,8 +42,8 @@ export async function activate(id?: string) {
data.value.current = id
const filename = `${root}/${id}/koishi.yml`
try {
loader.config = load(await fs.readFile(filename, 'utf8'))
if (!loader.config?.plugins) throw new Error()
await loader.init(`${root}/${id}`)
await loader.readConfig()
} catch {
loader.config = {
plugins: {
Expand All @@ -56,6 +56,7 @@ export async function activate(id?: string) {
await fs.mkdir(`${root}/${id}`, { recursive: true })
await fs.writeFile(filename, dump(loader.config))
instances.value = await fs.readdir(root)
await loader.init(`${root}/${id}`)
}
const app = await loader.createApp()
await app.start()
Expand Down
4 changes: 2 additions & 2 deletions packages/play/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
],
"devDependencies": {
"@koishijs/client": "^5.4.0",
"@koishijs/loader": "^2.6.1",
"filer": "^1.4.1"
"@koishijs/loader": "^3.0.0",
"fsa-browserify": "^1.2.0"
},
"yakumo": {
"client": "./scripts/build"
Expand Down
5 changes: 4 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"rewrites": [{
"source": "/(.*)",
"destination": "/index.html"
}]
}],
"github": {
"silent": true
}
}

0 comments on commit baa31a3

Please sign in to comment.