Skip to content

Commit

Permalink
feat(cli): check adapter dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 13, 2020
1 parent ec3b26c commit f79c3e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/koishi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"dependencies": {
"cac": "^6.6.1",
"kleur": "^4.1.1",
"koishi-adapter-cqhttp": "^1.0.4",
"koishi-core": "^2.3.0",
"koishi-plugin-common": "^3.0.1",
"prompts": "^2.3.2"
Expand Down
15 changes: 11 additions & 4 deletions packages/koishi/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,20 @@ async function updateMeta(config: AppConfig) {
const meta: Package = JSON.parse(await fs.readFile(path, 'utf8'))
let modified = false
if (!meta.dependencies) meta.dependencies = {}
for (const [name] of config.plugins as string[]) {
const fullname = 'koishi-plugin-' + name
if (!meta.dependencies[fullname]) {

function checkDependency(name: string) {
if (!meta.dependencies[name]) {
modified = true
meta.dependencies[fullname] = '^' + ecosystem[fullname].version
meta.dependencies[name] = '^' + ecosystem[name].version
}
}

const [name] = config.type.split('.', 1)
checkDependency('koishi-adapter-' + name)
for (const [name] of config.plugins as string[]) {
checkDependency('koishi-plugin-' + name)
}

if (!modified) return
await fs.writeFile(path, JSON.stringify(meta, null, 2))
console.log(`${success} package.json was updated, type "npm install" to install new dependencies`)
Expand Down

0 comments on commit f79c3e4

Please sign in to comment.