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 1, 2020
2 parents aefa45a + 3a7077d commit e4f4db4
Show file tree
Hide file tree
Showing 32 changed files with 459 additions and 288 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tsconfig.tsbuildinfo
.DS_Store
.idea
.vscode
.yarn
*.suo
*.ntvs*
*.njsproj
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ koishi run

完整的文档在 [这里](https://koishi.js.org/guide/getting-started.html)

此外,我们还准备了一个模板仓库供参考:https://github.com/koishijs/boilerplate。

## 最新版本

| 包名 | 版本 |
Expand Down
45 changes: 25 additions & 20 deletions build/dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ interface Dependency {
workspaces[name] = { meta, path }
delete dependencies[name]

for (const type of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as DependencyType[]) {
for (const type of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const) {
for (const dep in meta[type] || {}) {
// skip workspaces and symlinks
if (workspaces[dep] || meta[type][dep].startsWith('file:')) continue
if (workspaces[dep] || meta[type][dep].includes(':')) continue
if (!dependencies[dep]) dependencies[dep] = { dependents: [] }
dependencies[dep].dependents.push({ name, type })
}
Expand All @@ -63,30 +63,35 @@ interface Dependency {
}, { concurrency: 10 })
spinner.succeed()

const bumpMap = new Map<string, boolean>()
async function shouldBump (name: string, dep: string, version: string, oldVersion: string) {
if (!gt(version, oldVersion.replace(/^[~^]/, ''))) return
const message = `${name} > ${yellow(dep)}: ${cyan(oldVersion)} -> ${green(version)}`
if (satisfies(version, oldVersion)) return message
let result = bumpMap.get(dep)
if (result === undefined) {
const data = await prompts({
name: 'value',
type: 'confirm',
message,
})
result = data.value
bumpMap.set(dep, result)
}
return result && message
}

const output: string[] = []
for (const dep in dependencies) {
const { version, dependents } = dependencies[dep]
for (const { name, type } of dependents) {
const workspace = workspaces[name]
const oldVersion = workspace.meta[type][dep]
if (gt(version, oldVersion.replace(/^[~^]/, ''))) {
let update: boolean
const message = `${name} > ${yellow(dep)}: ${cyan(oldVersion)} -> ${green(version)}`
if (!satisfies(version, oldVersion)) {
const result = await prompts({
name: 'value',
type: 'confirm',
message,
})
update = result.value
} else {
update = true
}
if (update) {
workspace.dirty = true
workspace.meta[type][dep] = '^' + version
output.push(message)
}
const message = await shouldBump(name, dep, version, oldVersion)
if (message) {
workspace.dirty = true
workspace.meta[type][dep] = '^' + version
output.push(message)
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions build/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ const [,, argv2, argv3] = process.argv
if (argv2 && !argv2.startsWith('-')) {
args.push(argv2)
if (argv3 && !argv3.startsWith('-')) {
args.push('--collectCoverageFrom', `**/${argv3}/**/*.ts`, ...process.argv.slice(3))
args.push('--collectCoverageFrom')
if (argv3.endsWith('.ts')) {
args.push(`**/${argv3}`)
} else {
args.push(`**/${argv3}/**/*.ts`)
}
args.push(...process.argv.slice(4))
} else {
args.push(...process.argv.slice(3))
}
} else {
args.push('packages/.+\\.spec\\.ts', ...process.argv.slice(2))
}

const child = spawn('npx', args, { stdio: 'inherit' })

child.on('close', () => {
open(resolve(__dirname, '../coverage/lcov-report/index.html'))
})
spawn('npx', args, { stdio: 'inherit' })
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@octokit/rest": "^16.38.3",
"@octokit/rest": "^16.40.1",
"@types/cross-spawn": "^6.0.1",
"@types/fs-extra": "^8.0.1",
"@types/jest": "^24.9.1",
"@types/node": "^13.5.0",
"@types/semver": "^6.2.0",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"cac": "^6.5.5",
"@types/jest": "^25.1.1",
"@types/node": "^13.5.2",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"cac": "^6.5.6",
"cross-spawn": "^7.0.1",
"del": "^5.1.0",
"eslint": "^6.8.0",
Expand All @@ -47,12 +47,12 @@
"jest": "^25.1.0",
"kleur": "^3.0.3",
"latest-version": "^5.1.0",
"open": "^7.0.0",
"open": "^7.0.1",
"ora": "^4.0.3",
"p-map": "^3.0.0",
"prompts": "^2.3.0",
"semver": "^7.1.1",
"ts-jest": "^25.0.0",
"ts-jest": "^25.1.0",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
}
Expand Down
8 changes: 5 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.0.9",
"version": "1.1.0",
"main": "dist/index.js",
"files": [
"dist"
Expand Down Expand Up @@ -33,12 +33,14 @@
"leveldb"
],
"devDependencies": {
"koishi-test-utils": "^3.0.0"
"koishi-test-utils": "^3.0.1"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
},
"dependencies": {
"@types/leveldown": "^4.0.2",
"@types/levelup": "^4.3.0",
"koishi-core": "^1.7.0",
"koishi-utils": "^1.0.2",
"leveldown": "^5.4.1",
"levelup": "^4.3.2",
Expand Down
6 changes: 4 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.0.2",
"version": "1.1.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -21,8 +21,10 @@
"url": "https://github.com/koishijs/koishi/issues"
},
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme",
"peerDependencies": {
"koishi-core": "^1.8.0"
},
"dependencies": {
"koishi-core": "^1.7.0",
"koishi-utils": "^1.0.2"
}
}
6 changes: 4 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.0.9",
"version": "1.1.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -34,8 +34,10 @@
"devDependencies": {
"@types/mysql": "^2.15.8"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
},
"dependencies": {
"koishi-core": "^1.7.0",
"koishi-utils": "^1.0.2",
"mysql": "^2.18.1"
}
Expand Down
8 changes: 5 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.5",
"version": "1.0.0-alpha.6",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,10 +22,12 @@
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-sqlite#readme",
"devDependencies": {
"@types/sqlite3": "^3.1.6",
"koishi-test-utils": "^3.0.0"
"koishi-test-utils": "^3.0.1"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
},
"dependencies": {
"koishi-core": "^1.7.0",
"koishi-utils": "^1.0.2",
"sqlite3": "^4.1.1"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/koishi-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ koishi run

完整的文档在 [这里](https://koishi.js.org/guide/getting-started.html)

此外,我们还准备了一个模板仓库供参考:https://github.com/koishijs/boilerplate。

## 更新日志

参见 [releases](https://github.com/koishijs/koishi/releases)
Expand Down
14 changes: 6 additions & 8 deletions packages/koishi-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"name": "koishi",
"description": "A QQ bot framework based on CQHTTP",
"version": "1.7.0",
"version": "1.8.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"bin": {
"koishi": "dist/cli.js"
},
"bin": "dist/cli.js",
"author": "Shigma <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -37,12 +35,12 @@
"@types/prompts": "^2.0.3"
},
"dependencies": {
"cac": "^6.5.5",
"cac": "^6.5.6",
"js-yaml": "^3.13.1",
"kleur": "^3.0.3",
"koishi-core": "^1.7.0",
"koishi-plugin-common": "^2.1.0",
"koishi-plugin-schedule": "^1.0.5",
"koishi-core": "^1.8.0",
"koishi-plugin-common": "^2.1.1",
"koishi-plugin-schedule": "^1.0.6",
"koishi-utils": "^1.0.2",
"prompts": "^2.3.0"
}
Expand Down
77 changes: 41 additions & 36 deletions packages/koishi-cli/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, startAll, AppOptions, onStart, Context, Plugin, appList } from 'koishi-core'
import { resolve, extname } from 'path'
import { resolve, extname, dirname } from 'path'
import { capitalize } from 'koishi-utils'
import { performance } from 'perf_hooks'
import { cyan, yellow } from 'kleur'
Expand All @@ -23,16 +23,51 @@ function handleException (error: any) {

process.on('uncaughtException', handleException)

const cwd = process.cwd()
export type PluginConfig = (string | Plugin | [string | Plugin, any?])[]

export interface AppConfig extends AppOptions {
plugins?: PluginConfig | Record<string, PluginConfig>
logLevel?: number
logFilter?: Record<string, number>
}

const configFile = resolve(process.cwd(), process.env.KOISHI_CONFIG_FILE || 'koishi.config')
const extension = extname(configFile)
const configDir = dirname(configFile)
let config: AppConfig | AppConfig[]

function tryCallback <T> (callback: () => T) {
try {
return callback()
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND' && error.code !== 'ENOENT') {
throw error
}
}
}

if (['.js', '.json', '.ts'].includes(extension)) {
config = tryCallback(() => require(configFile))
} else if (['.yaml', '.yml'].includes(extension)) {
config = tryCallback(() => safeLoad(readFileSync(configFile, 'utf8')))
} else {
config = tryCallback(() => require(configFile))
|| tryCallback(() => safeLoad(readFileSync(configFile + '.yml', 'utf8')))
|| tryCallback(() => safeLoad(readFileSync(configFile + '.yaml', 'utf8')))
}

if (!config) {
throw new Error(`config file not found. use ${yellow('koishi init')} command to initialize a config file.`)
}

function loadEcosystem (type: string, name: string) {
const modules = [resolve(cwd, name)]
const modules = [resolve(configDir, name)]
const prefix = `koishi-${type}-`
if (name.includes(prefix) || name.startsWith('.')) {
modules.unshift(name)
if (name.includes(prefix)) {
modules.push(name)
} else {
const index = name.lastIndexOf('/')
modules.unshift(name.slice(0, index + 1) + prefix + name.slice(index + 1))
modules.push(name.slice(0, index + 1) + prefix + name.slice(index + 1))
}
for (const name of modules) {
try {
Expand All @@ -46,14 +81,6 @@ function loadEcosystem (type: string, name: string) {
throw new Error(`cannot resolve ${type} ${name}`)
}

export type PluginConfig = (string | Plugin | [string | Plugin, any?])[]

export interface AppConfig extends AppOptions {
plugins?: PluginConfig | Record<string, PluginConfig>
logLevel?: number
logFilter?: Record<string, number>
}

function loadPlugins (ctx: Context, plugins: PluginConfig) {
for (const item of plugins) {
let plugin: Plugin, options
Expand Down Expand Up @@ -86,28 +113,6 @@ function prepareApp (config: AppConfig) {
}
}

const configFile = resolve(cwd, process.env.KOISHI_CONFIG_FILE || 'koishi.config')
const extension = extname(configFile)
let config: AppConfig | AppConfig[]

function tryCallback <T> (callback: () => T) {
try {
return callback()
} catch {}
}

if (['.js', '.json', '.ts'].includes(extension)) {
config = tryCallback(() => require(configFile))
} else if (['.yaml', '.yml'].includes(extension)) {
config = tryCallback(() => safeLoad(readFileSync(configFile, 'utf8')))
} else {
config = tryCallback(() => require(configFile))
|| tryCallback(() => safeLoad(readFileSync(configFile + '.yml', 'utf8')))
|| tryCallback(() => safeLoad(readFileSync(configFile + '.yaml', 'utf8')))
}

if (!config) throw new Error(`config file not found. use ${yellow('koishi init')} command to initialize a config file.`)

if (Array.isArray(config)) {
config.forEach(conf => prepareApp(conf))
} else {
Expand Down
Loading

0 comments on commit e4f4db4

Please sign in to comment.