node-karin 0.12.11 → 0.12.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli/init.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { getRegistry } from './pkg.js';
3
3
  import { KarinCfgInit } from '../core/init/config.js';
4
+ import { isPkg } from '../core/init/dir.js';
4
5
  /**
5
6
  * 休眠函数
6
7
  * @param ms 毫秒
@@ -9,6 +10,8 @@ function sleep(ms) {
9
10
  return new Promise(resolve => setTimeout(resolve, ms));
10
11
  }
11
12
  async function main() {
13
+ if (!isPkg)
14
+ return;
12
15
  /** 捕获错误 打印日志 */
13
16
  process.on('uncaughtException', err => console.error(err));
14
17
  process.on('unhandledRejection', err => console.error(err));
@@ -175,6 +175,21 @@ export class KarinCfgInit {
175
175
  else {
176
176
  console.log('检测到已安装pm2~');
177
177
  }
178
+ /** 检查是否为官方源 如果不是则生成.npmrc */
179
+ const registry = await this.shell('npm config get registry');
180
+ if (registry !== 'https://registry.npmjs.org/') {
181
+ const text = `node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3
182
+ better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3
183
+ sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass
184
+ sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp
185
+ sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips
186
+ canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas
187
+ # 19以下版本
188
+ puppeteer_download_host=https://registry.npmmirror.com/mirrors
189
+ # 20以上版本
190
+ PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing`;
191
+ fs.writeFileSync('.npmrc', text);
192
+ }
178
193
  console.log('依赖环境初始化完成~');
179
194
  }
180
195
  /**
@@ -525,12 +525,21 @@ class PluginLoader {
525
525
  const keys = Object.keys(this.dependErr);
526
526
  if (!keys.length)
527
527
  return;
528
- const msg = ['-----依赖缺失----'];
528
+ const msg = ['\n-----依赖缺失----'];
529
529
  keys.forEach(key => {
530
530
  const { plugin, path, file, depend } = this.dependErr[key];
531
531
  msg.push(`[${plugin}]${path ? `[${path}]` : ''}[${file}] 缺少依赖:${logger.red(depend)}`);
532
532
  });
533
533
  msg.push('-------------------');
534
+ const one = this.dependErr[keys[0]];
535
+ msg.push(...[
536
+ '温馨提示:',
537
+ `1. 如果是新安装的插件,请尝试执行 ${logger.red('pnpm install -P')} 自动安装依赖`,
538
+ `2. 如果执行第一步无效,请尝试执行 ${logger.red('pnpm add 依赖名称 -w')} 手动安装依赖`,
539
+ `举例: ${logger.red(`pnpm add ${one.depend} -w`)}`,
540
+ logger.yellow('对于手动安装的依赖,如果对应插件未在使用,请进行及时卸载: pnpm uninstall 依赖名称'),
541
+ ]);
542
+ msg.push('-------------------');
534
543
  logger.error(msg.join('\n'));
535
544
  }
536
545
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.11",
3
+ "version": "0.12.13",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -123,6 +123,8 @@
123
123
  "dev": "node lib/cli/start.js dev",
124
124
  "fix": "eslint lib/**/*.js --fix",
125
125
  "fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix",
126
+ "init": "node lib/cli/init.js",
127
+ "postinstall": "npm run init",
126
128
  "pub": "npm publish --access public",
127
129
  "sort": "npx sort-package-json && sort-json tsconfig.json",
128
130
  "start": "node lib/cli/start.js start"