-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(market): expose installer service
- Loading branch information
Showing
10 changed files
with
130 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Context, Dict, version } from 'koishi' | ||
import { DataService } from '@koishijs/plugin-console' | ||
import { Dependency } from '../shared' | ||
|
||
class Dependencies extends DataService<Dict<Dependency>> { | ||
constructor(public ctx: Context) { | ||
super(ctx, 'dependencies', { authority: 4 }) | ||
} | ||
|
||
async get(force = false) { | ||
const objects = this.ctx.loader.market.objects.filter(o => o.portable) | ||
objects.push({ | ||
name: 'koishi', | ||
version, | ||
versions: { | ||
[version]: {}, | ||
}, | ||
} as any) | ||
return Object.fromEntries(objects.map((object) => [object.name, { | ||
request: object.version, | ||
resolved: object.version, | ||
versions: object.versions, | ||
latest: object.version, | ||
}])) | ||
} | ||
} | ||
|
||
export default Dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Context, Dict, Schema } from 'koishi' | ||
import { DataService } from '@koishijs/plugin-console' | ||
import { Dependency } from '../shared' | ||
|
||
declare module '@koishijs/plugin-console' { | ||
interface Events { | ||
'market/install'(deps: Dict<string>): Promise<number> | ||
} | ||
} | ||
|
||
class Dependencies extends DataService<Dict<Dependency>> { | ||
constructor(public ctx: Context, public config: Dependencies.Config) { | ||
super(ctx, 'dependencies', { authority: 4 }) | ||
|
||
ctx.console.addListener('market/install', async (deps) => { | ||
const code = await ctx.installer.installDep(deps) | ||
this.refresh() | ||
this.ctx.console.packages?.refresh() | ||
return code | ||
}, { authority: 4 }) | ||
} | ||
|
||
async get(force = false) { | ||
return this.ctx.installer.get(force) | ||
} | ||
} | ||
|
||
namespace Dependencies { | ||
export interface Config {} | ||
export const Config: Schema<Config> = Schema.object({}) | ||
} | ||
|
||
export default Dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.