From f79c3e4a1d68a46e57a33d1d31ce1bc8288f8569 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Sun, 13 Sep 2020 22:44:41 +0800 Subject: [PATCH] feat(cli): check adapter dependency --- packages/koishi/package.json | 1 - packages/koishi/src/init.ts | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/koishi/package.json b/packages/koishi/package.json index bcad87c227..d3b3c95af4 100644 --- a/packages/koishi/package.json +++ b/packages/koishi/package.json @@ -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" diff --git a/packages/koishi/src/init.ts b/packages/koishi/src/init.ts index 8f02658ab4..2fe8a615e2 100644 --- a/packages/koishi/src/init.ts +++ b/packages/koishi/src/init.ts @@ -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`)