Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 19, 2020
2 parents 888a5aa + d86c5c0 commit 9552572
Show file tree
Hide file tree
Showing 32 changed files with 164 additions and 152 deletions.
2 changes: 0 additions & 2 deletions build/jest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import spawn from 'cross-spawn'
import open from 'open'
import { resolve } from 'path'

const args = ['jest', '--coverage']

Expand Down
9 changes: 7 additions & 2 deletions build/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ if (CI && (GITHUB_REF !== 'refs/heads/master' || GITHUB_EVENT_NAME !== 'push'))
const headerMap = {
feat: 'Features',
fix: 'Bug Fixes',
dep: 'Dependencies',
}

const prefixes = Object.keys(headerMap)
const prefixRegExp = new RegExp(`^(${prefixes.join('|')})(?:\\((\\S+)\\))?: (.+)$`)

;(async () => {
let folders = await getWorkspaces()
if (process.argv[2]) {
Expand Down Expand Up @@ -60,15 +64,16 @@ const headerMap = {
return console.log(`Tag ${version} already exists.`)
}

const updates = { fix: '', feat: '' }
const updates = {}
const lastTag = tags[tags.length - 1]
const commits = spawnSync(`git log ${lastTag}..HEAD --format=%H%s`).split(/\r?\n/).reverse()
for (const commit of commits) {
const hash = commit.slice(0, 40)
const details = /^(fix|feat)(?:\((\S+)\))?: (.+)$/.exec(commit.slice(40))
const details = prefixRegExp.exec(commit.slice(40))
if (!details) continue
let message = details[3]
if (details[2]) message = `**${details[2]}:** ${message}`
if (!updates[details[1]]) updates[details[1]] = ''
updates[details[1]] += `- ${message} (${hash})\n`
}

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"devDependencies": {
"@octokit/rest": "^16.43.1",
"@types/cross-spawn": "^6.0.1",
"@types/fs-extra": "^8.0.1",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.1.2",
"@types/node": "^13.7.0",
"@types/node": "^13.7.1",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"cac": "^6.5.6",
"cross-spawn": "^7.0.1",
"del": "^5.1.0",
Expand All @@ -50,8 +50,8 @@
"open": "^7.0.2",
"ora": "^4.0.3",
"p-map": "^3.0.0",
"prompts": "^2.3.0",
"semver": "^7.1.2",
"prompts": "^2.3.1",
"semver": "^7.1.3",
"ts-jest": "^25.2.0",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
Expand Down
6 changes: 3 additions & 3 deletions packages/database-level/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-level",
"description": "Leveldb support for Koishi",
"version": "1.1.1",
"version": "1.1.2",
"main": "dist/index.js",
"files": [
"dist"
Expand Down Expand Up @@ -33,10 +33,10 @@
"leveldb"
],
"devDependencies": {
"koishi-test-utils": "^3.1.0"
"koishi-test-utils": "^3.1.1"
},
"peerDependencies": {
"koishi-core": "^1.8.1"
"koishi-core": "^1.9.0"
},
"dependencies": {
"@types/leveldown": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/database-memory/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-memory",
"description": "An in-memory database implementation for Koishi",
"version": "1.1.1",
"version": "1.1.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme",
"peerDependencies": {
"koishi-core": "^1.8.1"
"koishi-core": "^1.9.0"
},
"dependencies": {
"koishi-utils": "^1.0.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/database-mysql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-mysql",
"description": "MySQL support for Koishi",
"version": "1.1.1",
"version": "1.1.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,7 +35,7 @@
"@types/mysql": "^2.15.8"
},
"peerDependencies": {
"koishi-core": "^1.8.1"
"koishi-core": "^1.9.0"
},
"dependencies": {
"koishi-utils": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/database-mysql/src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ injectMethods('mysql', 'group', {
},

async getAllGroups (...args) {
let assignees: number[], fields: GroupField[]
let assignees: readonly number[], fields: readonly GroupField[]
if (args.length > 1) {
fields = args[0]
assignees = args[1]
Expand Down
2 changes: 1 addition & 1 deletion packages/database-mysql/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ injectMethods('mysql', 'user', {
},

async getUsers (...args) {
let ids: number[], fields: UserField[]
let ids: readonly number[], fields: readonly UserField[]
if (args.length > 1) {
ids = args[0]
fields = args[1]
Expand Down
6 changes: 3 additions & 3 deletions packages/database-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-database-sqlite",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.8",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,10 +22,10 @@
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-sqlite#readme",
"devDependencies": {
"@types/sqlite3": "^3.1.6",
"koishi-test-utils": "^3.1.0"
"koishi-test-utils": "^3.1.1"
},
"peerDependencies": {
"koishi-core": "^1.8.1"
"koishi-core": "^1.9.0"
},
"dependencies": {
"koishi-utils": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/database-sqlite/src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ injectMethods('sqlite', 'group', {
},

async getAllGroups (...args) {
let assignees: number[], fields: GroupField[]
let assignees: readonly number[], fields: readonly GroupField[]
if (args.length > 1) {
fields = args[0]
assignees = args[1]
Expand Down
2 changes: 1 addition & 1 deletion packages/database-sqlite/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ injectMethods('sqlite', 'user', {
},

async getUsers (...args) {
let ids: number[], fields: UserField[]
let ids: readonly number[], fields: readonly UserField[]
if (args.length > 1) {
ids = args[0]
fields = args[1]
Expand Down
10 changes: 5 additions & 5 deletions packages/koishi-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi",
"description": "A QQ bot framework based on CQHTTP",
"version": "1.8.1",
"version": "1.9.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -38,10 +38,10 @@
"cac": "^6.5.6",
"js-yaml": "^3.13.1",
"kleur": "^3.0.3",
"koishi-core": "^1.8.1",
"koishi-plugin-common": "^2.1.2",
"koishi-plugin-schedule": "^1.0.7",
"koishi-core": "^1.9.0",
"koishi-plugin-common": "^2.1.3",
"koishi-plugin-schedule": "^1.0.8",
"koishi-utils": "^1.0.3",
"prompts": "^2.3.0"
"prompts": "^2.3.1"
}
}
6 changes: 3 additions & 3 deletions packages/koishi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-core",
"description": "Core features for Koishi",
"version": "1.8.1",
"version": "1.9.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,8 +35,8 @@
"@types/debug": "^4.1.5",
"@types/ws": "^7.2.1",
"get-port": "^5.1.1",
"koishi-database-memory": "^1.1.1",
"koishi-test-utils": "^3.1.0"
"koishi-database-memory": "^1.1.2",
"koishi-test-utils": "^3.1.1"
},
"dependencies": {
"axios": "^0.19.2",
Expand Down
15 changes: 7 additions & 8 deletions packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ export class App extends Context {
this.receiver.on('before-group', Command.attachGroupFields)
this.middleware(this._preprocess)

this.receiver.on('logger', (scope, message) => {
debug('koishi:' + scope)(message)
})
// apply default logger
this.receiver.on('logger', (scope, message) => debug(scope)(message))
}

get users () {
Expand Down Expand Up @@ -236,7 +235,7 @@ export class App extends Context {
}
await Promise.all(tasks)
this.status = Status.open
this.logger('app').debug('started')
this.logger('koishi:app').debug('started')
this.receiver.emit('connect')
if (this.selfId && !this._isReady) {
this.receiver.emit('ready')
Expand All @@ -261,7 +260,7 @@ export class App extends Context {
this.server.close()
}
this.status = Status.closed
this.logger('app').debug('stopped')
this.logger('koishi:app').debug('stopped')
this.receiver.emit('disconnect')
if (appList.every(app => app.status === Status.closed)) {
onStopHooks.forEach(hook => hook(...appList))
Expand All @@ -270,15 +269,15 @@ export class App extends Context {

emitEvent <K extends Events> (meta: Meta, event: K, ...payload: Parameters<EventMap[K]>) {
if (!meta.$ctxType) {
this.logger('receiver').debug('/', 'emits', event)
this.logger('koishi:receiver').debug('/', 'emits', event)
this.receiver.emit(event, ...payload)
return
}

for (const path in this._contexts) {
const context = this._contexts[path]
if (!context.match(meta)) continue
this.logger('receiver').debug(path, 'emits', event)
this.logger('koishi:receiver').debug(path, 'emits', event)
context.receiver.emit(event, ...payload)
}
}
Expand Down Expand Up @@ -434,7 +433,7 @@ export class App extends Context {
let index = 0
const next = async (fallback?: NextFunction) => {
if (!this._middlewareSet.has(counter)) {
return this.logger().warn(new Error(errors.ISOLATED_NEXT))
return this.logger('koishi').warn(new Error(errors.ISOLATED_NEXT))
}
if (fallback) middlewares.push((_, next) => fallback(next))
try {
Expand Down
8 changes: 4 additions & 4 deletions packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ParsedCommandLine extends Partial<ParsedLine> {
}

export type UserType <T> = T | ((user: UserData) => T)
export type CommandUsage = string | ((this: Command, meta: Meta) => string | Promise<string>)

export interface CommandConfig {
/** disallow unknown options */
Expand All @@ -39,7 +40,6 @@ export interface CommandConfig {
authority?: number
disable?: UserType<boolean>
maxUsage?: UserType<number>
maxUsageText?: string
minInterval?: UserType<number>
showWarning?: boolean | number
noHelpOption?: boolean
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Command {

_aliases: string[] = []
_options: CommandOption[] = []
_usage?: string
_usage?: CommandUsage
_examples: string[] = []
_shortcuts: Record<string, ShortcutConfig> = {}
_userFields = new Set<UserField>()
Expand Down Expand Up @@ -186,7 +186,7 @@ export class Command {
return this
}

usage (text: string) {
usage (text: CommandUsage) {
this._usage = text
return this
}
Expand Down Expand Up @@ -285,7 +285,7 @@ export class Command {
if (code) return this._sendHint(code, meta)

// execute command
this.context.logger('command').debug('execute %s', this.name)
this.context.logger('koishi:command').debug('execute %s', this.name)
this.app.emitEvent(meta, 'command', argv)

let skipped = false
Expand Down
21 changes: 11 additions & 10 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { format } from 'util'
export type NextFunction = (next?: NextFunction) => any
export type Middleware = (meta: Meta<'message'>, next: NextFunction) => any

type PluginFunction <T extends Context, U> = (ctx: T, options: U) => void
type PluginObject <T extends Context, U> = { name?: string, apply: PluginFunction<T, U> }
type PluginFunction <T extends Context, U = any> = (ctx: T, options: U) => void
type PluginObject <T extends Context, U = any> = { name?: string, apply: PluginFunction<T, U> }
export type Plugin <T extends Context = Context, U = any> = PluginFunction<T, U> | PluginObject<T, U>

type Subscope = [number[], number[]]
Expand Down Expand Up @@ -65,7 +65,7 @@ export class Context {

constructor (public readonly identifier: string, private readonly _scope: ContextScope) {
this.receiver.on('error', (error) => {
this.logger().warn(error)
this.logger('koishi').warn(error)
})

this.logger = (scope = '') => {
Expand Down Expand Up @@ -127,15 +127,15 @@ export class Context {
})
}

plugin <U> (plugin: PluginFunction<this, U>, options?: U): this
plugin <U> (plugin: PluginObject<this, U>, options?: U): this
plugin <U> (plugin: Plugin<this, U>, options: any) {
plugin <T extends PluginFunction<this>> (plugin: T, options?: T extends PluginFunction<this, infer U> ? U : never): this
plugin <T extends PluginObject<this>> (plugin: T, options?: T extends PluginObject<this, infer U> ? U : never): this
plugin <T extends Plugin<this>> (plugin: T, options?: T extends Plugin<this, infer U> ? U : never) {
if (options === false) return
const ctx = Object.create(this)
if (typeof plugin === 'function') {
plugin(ctx, options)
(plugin as PluginFunction<this>)(ctx, options)
} else if (plugin && typeof plugin === 'object' && typeof plugin.apply === 'function') {
plugin.apply(ctx, options)
(plugin as PluginObject<this>).apply(ctx, options)
} else {
throw new Error(errors.INVALID_PLUGIN)
}
Expand All @@ -145,7 +145,7 @@ export class Context {
middleware (middleware: Middleware) {
const { maxMiddlewares } = this.app.options
if (this.app._middlewares.length >= maxMiddlewares) {
this.logger().warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares)))
this.logger('koishi').warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares)))
} else {
this.app._middlewares.push([this, middleware])
}
Expand All @@ -159,7 +159,7 @@ export class Context {
prependMiddleware (middleware: Middleware) {
const { maxMiddlewares } = this.app.options
if (this.app._middlewares.length >= maxMiddlewares) {
this.logger().warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares)))
this.logger('koishi').warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares)))
} else {
this.app._middlewares.unshift([this, middleware])
}
Expand Down Expand Up @@ -291,6 +291,7 @@ export interface EventMap {
'lifecycle' (meta: Meta<'meta_event'>): any
'lifecycle/enable' (meta: Meta<'meta_event'>): any
'lifecycle/disable' (meta: Meta<'meta_event'>): any
'lifecycle/connect' (meta: Meta<'meta_event'>): any
'before-user' (fields: Set<UserField>, argv: ParsedCommandLine): any
'before-group' (fields: Set<GroupField>, argv: ParsedCommandLine): any
'attach' (meta: Meta<'message'>): any
Expand Down
Loading

0 comments on commit 9552572

Please sign in to comment.