mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-21 14:48:23 +00:00
chore: add prettier .vscode config
This commit is contained in:
parent
633e889370
commit
3f6414d624
9
.vscode/settings.json
vendored
Normal file
9
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
},
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
}
|
||||||
|
}
|
@ -29,16 +29,21 @@ export type Api = {
|
|||||||
|
|
||||||
const buildNotimpl = (name: string) => {
|
const buildNotimpl = (name: string) => {
|
||||||
const fn = () =>
|
const fn = () =>
|
||||||
l.error(new Error(`没有引擎提供 ${bgMagenta(white(name))}。可能没有加载所需的引擎?`), {
|
l.error(
|
||||||
code: 2159,
|
new Error(
|
||||||
throw: true,
|
`没有引擎提供 ${bgMagenta(white(name))}。可能没有加载所需的引擎?`,
|
||||||
})
|
),
|
||||||
|
{
|
||||||
|
code: 2159,
|
||||||
|
throw: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
; (
|
;(
|
||||||
fn as unknown as {
|
fn as unknown as {
|
||||||
[notimplSym]: boolean
|
[notimplSym]: boolean
|
||||||
}
|
}
|
||||||
)[notimplSym] = true
|
)[notimplSym] = true
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
}
|
}
|
||||||
@ -46,7 +51,7 @@ const buildNotimpl = (name: string) => {
|
|||||||
const handler: ProxyHandler<Api> = {
|
const handler: ProxyHandler<Api> = {
|
||||||
get: (target, name) =>
|
get: (target, name) =>
|
||||||
typeof name === 'symbol' ||
|
typeof name === 'symbol' ||
|
||||||
Object.prototype.hasOwnProperty.call(target, name)
|
Object.prototype.hasOwnProperty.call(target, name)
|
||||||
? target[name as keyof Methods]
|
? target[name as keyof Methods]
|
||||||
: buildNotimpl(name),
|
: buildNotimpl(name),
|
||||||
}
|
}
|
||||||
@ -55,20 +60,23 @@ export const api = new Proxy({} as Api, handler)
|
|||||||
|
|
||||||
api.register =
|
api.register =
|
||||||
(engine: string, defaultPriority: number = 0) =>
|
(engine: string, defaultPriority: number = 0) =>
|
||||||
<M extends keyof Methods>(
|
<M extends keyof Methods>(
|
||||||
method: M,
|
method: M,
|
||||||
impl: (...args: Methods[M][0]) => Promise<Methods[M][1]>,
|
impl: (...args: Methods[M][0]) => Promise<Methods[M][1]>,
|
||||||
priority: number = -1,
|
priority: number = -1,
|
||||||
) => {
|
) => {
|
||||||
const newPriority = priority === -1 ? defaultPriority : priority
|
const newPriority = priority === -1 ? defaultPriority : priority
|
||||||
if (api[method]) {
|
if (api[method]) {
|
||||||
l.warn(`${cyan(engine)}(${newPriority}) 与 ${cyan(api[method].engine)}(${api[method].priority
|
l.warn(
|
||||||
}) 重复注册了方法 ${bgMagenta(white(method))},将采用 ${newPriority > api[method].priority ? engine : api[method].engine} 的版本。`)
|
`${cyan(engine)}(${newPriority}) 与 ${cyan(api[method].engine)}(${
|
||||||
|
api[method].priority
|
||||||
|
}) 重复注册了方法 ${bgMagenta(white(method))},将采用 ${newPriority > api[method].priority ? engine : api[method].engine} 的版本。`,
|
||||||
|
)
|
||||||
|
|
||||||
if (newPriority < api[method].priority) return
|
if (newPriority < api[method].priority) return
|
||||||
}
|
|
||||||
// FIXME: Do not use type assertion
|
|
||||||
api[method] = impl /* ApiImpl<M> */ as Api[M]
|
|
||||||
api[method].engine = engine
|
|
||||||
api[method].priority = newPriority
|
|
||||||
}
|
}
|
||||||
|
// FIXME: Do not use type assertion
|
||||||
|
api[method] = impl /* ApiImpl<M> */ as Api[M]
|
||||||
|
api[method].engine = engine
|
||||||
|
api[method].priority = newPriority
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user