node-karin 0.12.11 → 0.12.14

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 {
@@ -89,7 +89,7 @@ e: KarinMessageType,
89
89
  /** 是否继续执行下一个中间件 */
90
90
  next: () => void,
91
91
  /** 是否退出此条消息 不再执行匹配插件 */
92
- exit: () => void) => Promise<boolean>;
92
+ exit: () => void) => Promise<void>;
93
93
  /**
94
94
  * 回复消息前 中间件实现方法
95
95
  */
@@ -101,7 +101,7 @@ element: KarinElement[],
101
101
  /** 是否继续执行下一个中间件 */
102
102
  next: () => void,
103
103
  /** 是否不发送此条消息 */
104
- exit: () => void) => Promise<boolean>;
104
+ exit: () => void) => Promise<void>;
105
105
  /**
106
106
  * 发送主动消息前 中间件实现方法
107
107
  */
@@ -115,7 +115,7 @@ element: KarinElement[],
115
115
  /** 是否继续执行下一个中间件 */
116
116
  next: () => void,
117
117
  /** 是否不发送此条消息 */
118
- exit: () => void) => Promise<boolean>;
118
+ exit: () => void) => Promise<void>;
119
119
  /**
120
120
  * 发送合并转发前 中间件实现方法
121
121
  */
@@ -127,7 +127,7 @@ elements: Array<NodeElement>,
127
127
  /** 是否继续执行下一个中间件 */
128
128
  next: () => void,
129
129
  /** 是否不发送此条消息 */
130
- exit: () => void) => Promise<boolean>;
130
+ exit: () => void) => Promise<void>;
131
131
  /**
132
132
  * 消息事件没有找到任何匹配的插件触发 中间件实现方法
133
133
  */
@@ -137,7 +137,7 @@ e: KarinMessageType,
137
137
  /** 是否继续执行下一个中间件 */
138
138
  next: () => void,
139
139
  /** 是否退出此条消息 不再执行匹配插件 */
140
- exit: () => void) => Promise<boolean>;
140
+ exit: () => void) => Promise<void>;
141
141
  /** use规则集类型 */
142
142
  export interface UseInfo<T extends keyof UseMapType = keyof UseMapType> extends Omit<AppBase, 'log'> {
143
143
  type: `${AppType.Use}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.11",
3
+ "version": "0.12.14",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -123,6 +123,7 @@
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",
126
127
  "pub": "npm publish --access public",
127
128
  "sort": "npx sort-package-json && sort-json tsconfig.json",
128
129
  "start": "node lib/cli/start.js start"