alemonjs 1.0.2 → 1.0.4

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.
Files changed (75) hide show
  1. package/README.md +6 -22
  2. package/bin/main.js +17 -0
  3. package/lib/alemon/dealmsg.js +66 -18
  4. package/lib/alemon/puppeteer.js +9 -16
  5. package/lib/config/index.js +8 -0
  6. package/lib/config/login.js +87 -0
  7. package/lib/config/pup.js +75 -0
  8. package/lib/config/types.js +1 -0
  9. package/lib/default/login/discord.js +16 -0
  10. package/lib/default/login/kook.js +5 -0
  11. package/lib/default/login/ntqq.js +17 -0
  12. package/lib/default/login/qq.js +16 -0
  13. package/lib/default/login/villa.js +13 -0
  14. package/lib/default/mysql.js +7 -0
  15. package/lib/default/pup.js +15 -0
  16. package/lib/default/redis.js +6 -0
  17. package/lib/default/server.js +4 -0
  18. package/lib/{types.js → default/types.js} +8 -2
  19. package/lib/define/api.js +23 -0
  20. package/lib/define/child_process.js +10 -0
  21. package/lib/define/command.js +22 -0
  22. package/lib/define/index.js +7 -0
  23. package/lib/define/main.js +205 -0
  24. package/lib/define/map.js +47 -0
  25. package/lib/define/plugin.js +25 -0
  26. package/lib/define/types.js +1 -0
  27. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
  28. package/lib/discord/index.js +1 -1
  29. package/lib/discord/login.js +18 -63
  30. package/lib/index.js +23 -7
  31. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
  32. package/lib/kook/index.js +1 -1
  33. package/lib/kook/login.js +7 -40
  34. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +1 -1
  35. package/lib/ntqq/index.js +2 -2
  36. package/lib/ntqq/login.js +15 -64
  37. package/lib/ntqq/sdk/wss.js +0 -1
  38. package/lib/qq/alemon/conversation.js +1 -1
  39. package/lib/qq/alemon/message/MESSAGE.js +1 -1
  40. package/lib/qq/index.js +14 -3
  41. package/lib/qq/login.js +3 -125
  42. package/lib/villa/alemon/message/MESSAGES.js +1 -1
  43. package/lib/villa/index.js +1 -1
  44. package/lib/villa/login.js +11 -52
  45. package/package.json +62 -60
  46. package/types/alemon/dealmsg.d.ts +10 -0
  47. package/types/config/index.d.ts +8 -0
  48. package/types/config/pup.d.ts +7 -0
  49. package/types/config/types.d.ts +18 -0
  50. package/types/default/login/discord.d.ts +8 -0
  51. package/types/default/login/kook.d.ts +6 -0
  52. package/types/default/login/ntqq.d.ts +16 -0
  53. package/types/default/login/qq.d.ts +12 -0
  54. package/types/default/login/villa.d.ts +14 -0
  55. package/types/default/mysql.d.ts +8 -0
  56. package/types/default/pup.d.ts +3 -0
  57. package/types/default/redis.d.ts +7 -0
  58. package/types/default/server.d.ts +5 -0
  59. package/types/default/types.d.ts +300 -0
  60. package/types/define/api.d.ts +30 -0
  61. package/types/define/child_process.d.ts +1 -0
  62. package/types/define/command.d.ts +1 -0
  63. package/types/define/index.d.ts +7 -0
  64. package/types/define/main.d.ts +20 -0
  65. package/types/define/map.d.ts +12 -0
  66. package/types/define/plugin.d.ts +4 -0
  67. package/types/define/types.d.ts +111 -0
  68. package/types/index.d.ts +17 -2
  69. package/lib/bot.js +0 -98
  70. package/lib/config.js +0 -25
  71. package/lib/login.js +0 -115
  72. package/types/bot.d.ts +0 -15
  73. package/types/config.d.ts +0 -12
  74. package/types/types.d.ts +0 -135
  75. /package/types/{login.d.ts → config/login.d.ts} +0 -0
package/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  > 支持 NtQQ、QQ 频道、Discord、米游社大别野、KOOK
6
6
 
7
- [☞Alemon 文档](https://alemonjs.com)
8
-
9
7
  | 分支 | 类型 | 说明 |
10
8
  | ----- | ------ | -------------------- |
11
9
  | main | 核心 | 机器实例 |
@@ -13,35 +11,21 @@
13
11
  | cli | 脚手架 | 开发模板脚手架 |
14
12
  | web | 网站 | 共享平台插件贡献地址 |
15
13
 
16
- ## 快速开始
17
-
18
- ```shell
19
- npm init almeonjs@latest -y #安装
20
- ```
21
-
22
- ```shell
23
- cd alemon-bot #进入
24
- ```
14
+ > 需要配置机器人才可启动
25
15
 
26
- ```shell
27
- npm run app qq #启动
28
- ```
16
+ 文档查看 OPEN[alemonjs.com](https://alemonjs.com)
29
17
 
30
- ## 配置管理
18
+ 开发模板 GITEE[create-alemonjs](https://gitee.com/ningmengchongshui/alemon/tree/cli/bin/template)
31
19
 
32
- 打开 alemon.toml 文件
33
-
34
- 参考配置说明进行更改[config](./config.md)
20
+ 开发模板 GITHUB[create-alemonjs](https://github.com/ningmengchongshui/alemon/tree/cli/bin/template)
35
21
 
36
22
  ### 共享平台
37
23
 
38
24
  > 仓库只做资源收集,对齐安全性不做任何检查,请谨慎选择
39
25
 
40
- Gitee [贡献资源](https://gitee.com/ningmengchongshui/alemon/tree/web/docs/root/examples/about/plugins.md)
41
-
42
- Github ☞[贡献资源](https://github.com/ningmengchongshui/alemon/tree/web/docs/root/examples/about/plugins.md)
26
+ 贡献资源 OPEN[Gitee](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
43
27
 
44
- ### 平台推送
28
+ 贡献资源 OPEN[Github](https://gitee.com/ningmengchongshui/alemon/blob/web/docs/about/plugins.md)
45
29
 
46
30
  > 仅限签署开源协议的仓库、不开源将不做考虑范围内
47
31
 
package/bin/main.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'child_process'
4
+
5
+ const ars = process.argv.slice(2)
6
+
7
+ const command = spawn(`npx ts-node alemon.config.ts ${ars}`, {
8
+ shell: true
9
+ })
10
+
11
+ command.stdout.on('data', data => {
12
+ process.stdout.write(data.toString())
13
+ })
14
+
15
+ command.stderr.on('data', data => {
16
+ process.stderr.write(data.toString())
17
+ })
@@ -34,6 +34,21 @@ let addressMenu = join(process.cwd(), route);
34
34
  * 大正则
35
35
  */
36
36
  let mergedRegex;
37
+ let appRegex = /./;
38
+ let appRegexClose;
39
+ /**
40
+ * 插件名匹配
41
+ * @param val
42
+ */
43
+ export function setAppRegex(val) {
44
+ const { RegexOpen, RegexClose } = val;
45
+ if (RegexOpen) {
46
+ appRegex = RegexOpen;
47
+ }
48
+ if (RegexClose) {
49
+ appRegexClose = RegexClose;
50
+ }
51
+ }
37
52
  /**
38
53
  * 设置指令json地址
39
54
  * @param rt '/public/defset'
@@ -52,17 +67,32 @@ export function getPluginHelp(AppName) {
52
67
  }
53
68
  /**
54
69
  * 创建机器人帮助
70
+ * 存在且得到的app不为[]时才会创建json
55
71
  */
56
72
  function createPluginHelp() {
57
- // 不存在
58
- if (!existsSync(addressMenu))
59
- mkdirSync(addressMenu, { recursive: true });
60
- // 创建help
61
- for (const item in plugins) {
62
- const basePath = join(addressMenu, `${item}.json`);
63
- const jsonData = JSON.stringify(plugins[item], null, 2);
64
- // 异步创建避免阻塞
65
- writeFile(basePath, jsonData, 'utf-8');
73
+ // 存在app才创建
74
+ if (Object.values(plugins).length != 0) {
75
+ // 同时key不能是空数组
76
+ let t = false;
77
+ for (const item in plugins) {
78
+ if (plugins[item] && plugins[item].length != 0) {
79
+ t = true;
80
+ }
81
+ }
82
+ if (t) {
83
+ // 不存在
84
+ if (!existsSync(addressMenu))
85
+ mkdirSync(addressMenu, { recursive: true });
86
+ // 创建help
87
+ for (const item in plugins) {
88
+ if (plugins[item] && plugins[item].length != 0) {
89
+ const basePath = join(addressMenu, `${item}.json`);
90
+ const jsonData = JSON.stringify(plugins[item], null, 2);
91
+ // 异步创建避免阻塞
92
+ writeFile(basePath, jsonData, 'utf-8');
93
+ }
94
+ }
95
+ }
66
96
  }
67
97
  }
68
98
  /**
@@ -167,13 +197,34 @@ async function synthesis(AppsObj, appname, belong) {
167
197
  * @param dir
168
198
  */
169
199
  async function loadPlugins(dir) {
170
- if (!existsSync(dir))
171
- mkdirSync(dir, { recursive: true });
200
+ /**
201
+ * ********************
202
+ * 没有该文件夹直接返回
203
+ * *******************
204
+ */
205
+ if (!existsSync(dir)) {
206
+ return;
207
+ }
172
208
  const flies = readdirSync(dir);
209
+ if (flies.length == 0) {
210
+ return;
211
+ }
212
+ const app = flies
213
+ .filter(item => appRegex.test(item))
214
+ .filter(item => {
215
+ // 关闭符合条件的
216
+ if (!appRegexClose) {
217
+ return true;
218
+ }
219
+ if (appRegexClose.test(item)) {
220
+ return false;
221
+ }
222
+ return true;
223
+ });
173
224
  /**
174
225
  * 识别并执行插件
175
226
  */
176
- for await (const appname of flies) {
227
+ for await (const appname of app) {
177
228
  if (existsSync(`${dir}/${appname}/index.ts`)) {
178
229
  /**
179
230
  * 优先考虑ts
@@ -356,8 +407,7 @@ export async function InstructionMatching(e) {
356
407
  return res;
357
408
  })
358
409
  .catch((err) => {
359
- console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${err}]`);
360
- console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]`);
410
+ console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
361
411
  return false;
362
412
  });
363
413
  // 不是false都直接中断匹配
@@ -396,8 +446,7 @@ export async function typeMessage(e) {
396
446
  return res;
397
447
  })
398
448
  .catch((err) => {
399
- console.error(err);
400
- console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]`);
449
+ console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
401
450
  return false;
402
451
  });
403
452
  if (res) {
@@ -417,7 +466,6 @@ export async function typeMessage(e) {
417
466
  * @param data
418
467
  */
419
468
  function logErr(err, data) {
420
- console.error(err);
421
- console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]`);
469
+ console.error(`\n[${data.event}][${data.belong}][${data.AppName}][${data.fncName}][${false}]\n[${err}]`);
422
470
  return;
423
471
  }
@@ -54,9 +54,11 @@ export async function pupStartCheck() {
54
54
  /**
55
55
  * 检测是否开启
56
56
  */
57
- if (isBrowser == false) {
58
- if (!(await startChrom()))
57
+ if (!isBrowser) {
58
+ const T = await startChrom();
59
+ if (!T) {
59
60
  return false;
61
+ }
60
62
  }
61
63
  if (pic <= RestartControl) {
62
64
  /**
@@ -90,18 +92,12 @@ export async function pupStartCheck() {
90
92
  * @returns
91
93
  */
92
94
  export async function screenshotByFile(htmlPath, Options) {
93
- if (!pupStartCheck())
95
+ const T = await pupStartCheck();
96
+ if (!T) {
94
97
  return false;
98
+ }
95
99
  const { SOptions, tab = 'body', timeout = 120000 } = Options;
96
100
  try {
97
- /**
98
- * 开始
99
- */
100
- if (!isBrowser) {
101
- if (!(await startChrom()))
102
- return false;
103
- }
104
- console.info('[puppeteer] start');
105
101
  /**
106
102
  * 实例化
107
103
  */
@@ -148,13 +144,10 @@ export async function screenshotByFile(htmlPath, Options) {
148
144
  * @returns
149
145
  */
150
146
  export async function screenshotByUrl(val) {
151
- if (!pupStartCheck())
147
+ const T = await pupStartCheck();
148
+ if (!T) {
152
149
  return false;
153
- if (!isBrowser) {
154
- if (!(await startChrom()))
155
- return false;
156
150
  }
157
- console.info('[puppeteer] start');
158
151
  const { url, time, rand, params, tab, cache } = val;
159
152
  if (!pageCache[url]) {
160
153
  pageCache[url] = await browser.newPage();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ********
3
+ * 配置管理器
4
+ * ********
5
+ */
6
+ export * from './login.js';
7
+ export * from './types.js';
8
+ export * from './pup.js';
@@ -0,0 +1,87 @@
1
+ import redis from '../default/redis.js';
2
+ import mysql from '../default/mysql.js';
3
+ import server from '../default/server.js';
4
+ import puppeteer from '../default/pup.js';
5
+ import discord from '../default/login/discord.js';
6
+ import kook from '../default/login/kook.js';
7
+ import villa from '../default/login/villa.js';
8
+ import qq from '../default/login/qq.js';
9
+ import ntqq from '../default/login/ntqq.js';
10
+ /**
11
+ * bot-config
12
+ */
13
+ const config = {
14
+ redis,
15
+ mysql,
16
+ discord,
17
+ kook,
18
+ villa,
19
+ qq,
20
+ ntqq,
21
+ server,
22
+ puppeteer
23
+ };
24
+ /**
25
+ * 初始化配置
26
+ * @param val
27
+ */
28
+ export function setBotConfig(val) {
29
+ // 分布覆盖
30
+ for (const i in val) {
31
+ // 当且仅当存在同key的时候才会覆盖默认配置
32
+ if (Object.prototype.hasOwnProperty.call(config, i)) {
33
+ if (i == 'puppeteer') {
34
+ // pup 不用检查 直接覆盖
35
+ for (const j in val[i]) {
36
+ config[i][j] = val[i][j];
37
+ }
38
+ }
39
+ else {
40
+ for (const j in val[i]) {
41
+ // 当前仅当同属性名的时候才会覆盖默认配置
42
+ if (Object.prototype.hasOwnProperty.call(config[i], j)) {
43
+ config[i][j] = val[i][j];
44
+ }
45
+ else {
46
+ console.info('[alemonjs][存在无效参数]', val[i]);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ else {
52
+ console.info('[alemonjs][存在无效参数]', val[i]);
53
+ }
54
+ }
55
+ }
56
+ /**
57
+ * 设置
58
+ * @param key
59
+ * @param val
60
+ */
61
+ export function setBotConfigByKey(key, val) {
62
+ if (key == 'puppeteer') {
63
+ // pup 不用检查 直接覆盖
64
+ for (const item in val) {
65
+ config[key][item] = val[item];
66
+ }
67
+ }
68
+ else {
69
+ for (const item in val) {
70
+ // 当前仅当同属性名的时候才会覆盖默认配置
71
+ if (Object.prototype.hasOwnProperty.call(config[key], item)) {
72
+ config[key][item] = val[item];
73
+ }
74
+ else {
75
+ console.info('[alemonjs][存在无效参数]', val[item]);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ /**
81
+ * 得到配置
82
+ * @param key
83
+ * @returns
84
+ */
85
+ export function getBotConfigByKey(key) {
86
+ return config[key];
87
+ }
@@ -0,0 +1,75 @@
1
+ import { arch } from 'os';
2
+ import { existsSync, realpathSync } from 'fs';
3
+ import { execSync } from 'child_process';
4
+ const isArch = arch();
5
+ const platform = process.platform;
6
+ const win32Edge = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe';
7
+ // Downloa
8
+ let skipDownload = false;
9
+ // Path
10
+ let executablePath;
11
+ if (process.platform == 'win32' && existsSync(win32Edge)) {
12
+ // win32 Edge
13
+ skipDownload = true;
14
+ executablePath = win32Edge;
15
+ console.info('[Win32 Edge] start');
16
+ }
17
+ else if (platform == 'linux' || platform == 'android') {
18
+ // linux | android
19
+ const chromium = [
20
+ 'whereis chrome-browser',
21
+ 'whereis chrome',
22
+ 'whereis chromium-browser',
23
+ 'whereis chromium',
24
+ 'whereis firefox'
25
+ ];
26
+ // get path
27
+ for (const item of chromium) {
28
+ try {
29
+ const chromiumPath = execSync(item).toString().split(' ')[1]?.trim();
30
+ if (chromiumPath) {
31
+ skipDownload = true;
32
+ executablePath = realpathSync(chromiumPath);
33
+ console.info('[Chromium] start');
34
+ break;
35
+ }
36
+ }
37
+ catch (error) {
38
+ console.error('Failed to get Chromium path:', error);
39
+ continue;
40
+ }
41
+ }
42
+ // not path
43
+ if (!skipDownload) {
44
+ /**
45
+ * search
46
+ */
47
+ const arr = [
48
+ '/usr/bin/chromium',
49
+ '/snap/bin/chromium',
50
+ '/usr/bin/chromium-browser'
51
+ ];
52
+ for (const item of arr) {
53
+ if (existsSync(item)) {
54
+ skipDownload = true;
55
+ executablePath = item;
56
+ console.info('[Chromium] start');
57
+ break;
58
+ }
59
+ }
60
+ }
61
+ // arm64/arrch64
62
+ if (isArch == 'arm64' || isArch == 'aarch64') {
63
+ console.info('[arm64/aarch64] system');
64
+ skipDownload = true;
65
+ }
66
+ }
67
+ /**
68
+ * @type {import("puppeteer").Configuration}
69
+ */
70
+ export function getPupPath() {
71
+ return {
72
+ skipDownload,
73
+ executablePath
74
+ };
75
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { GatewayIntentBits } from 'discord.js';
2
+ export default {
3
+ token: '',
4
+ masterID: '',
5
+ password: '',
6
+ intents: [
7
+ GatewayIntentBits.DirectMessageReactions,
8
+ GatewayIntentBits.DirectMessageTyping,
9
+ GatewayIntentBits.DirectMessages,
10
+ GatewayIntentBits.GuildMessageReactions,
11
+ GatewayIntentBits.GuildMessageTyping,
12
+ GatewayIntentBits.GuildMessages,
13
+ GatewayIntentBits.Guilds,
14
+ GatewayIntentBits.MessageContent // 消息内容
15
+ ]
16
+ };
@@ -0,0 +1,5 @@
1
+ export default {
2
+ token: '',
3
+ masterID: '',
4
+ password: ''
5
+ };
@@ -0,0 +1,17 @@
1
+ export default {
2
+ appID: '',
3
+ token: '',
4
+ secret: '',
5
+ masterID: '',
6
+ password: '',
7
+ intents: [
8
+ 'GROUP_AT_MESSAGE_CREATE',
9
+ 'C2C_MESSAGE_CREATE'
10
+ ],
11
+ shard: [0, 1],
12
+ port: 9090,
13
+ size: 999999,
14
+ img_url: '/api/mys/img',
15
+ IMAGE_DIR: '/data/mys/img',
16
+ http: 'http'
17
+ };
@@ -0,0 +1,16 @@
1
+ import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
2
+ export default {
3
+ appID: '',
4
+ token: '',
5
+ secret: '',
6
+ masterID: '',
7
+ password: '',
8
+ intents: [
9
+ AvailableIntentsEventsEnum.GUILDS,
10
+ AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES,
11
+ AvailableIntentsEventsEnum.DIRECT_MESSAGE,
12
+ AvailableIntentsEventsEnum.GUILD_MEMBERS
13
+ ],
14
+ isPrivate: false,
15
+ sandbox: false
16
+ };
@@ -0,0 +1,13 @@
1
+ export default {
2
+ bot_id: '',
3
+ secret: '',
4
+ pub_key: '',
5
+ masterID: '',
6
+ password: '',
7
+ http: 'http',
8
+ url: '/api/mys/callback',
9
+ port: 8080,
10
+ size: 999999,
11
+ img_url: '/api/mys/img',
12
+ IMAGE_DIR: '/data/mys/img'
13
+ };
@@ -0,0 +1,7 @@
1
+ export default {
2
+ host: 'localhost',
3
+ port: 3306,
4
+ user: 'root',
5
+ password: '',
6
+ database: 'alemonjs'
7
+ };
@@ -0,0 +1,15 @@
1
+ export default {
2
+ headless: 'new',
3
+ timeout: 30000,
4
+ args: [
5
+ '--disable-gpu',
6
+ '--disable-dev-shm-usage',
7
+ '--disable-setuid-sandbox',
8
+ '--no-first-run',
9
+ '--no-sandbox',
10
+ '--no-zygote',
11
+ '--single-process'
12
+ ],
13
+ skipDownload: true,
14
+ executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
15
+ };
@@ -0,0 +1,6 @@
1
+ export default {
2
+ host: '127.0.0.1',
3
+ port: 6379,
4
+ password: '',
5
+ db: 1
6
+ };
@@ -0,0 +1,4 @@
1
+ export default {
2
+ host: 'localhost',
3
+ port: 5000
4
+ };
@@ -1,10 +1,16 @@
1
1
  /**
2
2
  * *****
3
- * ntqq
3
+ * ntqq订阅
4
4
  * ****
5
5
  */
6
6
  export var NtQQEventsEnum;
7
7
  (function (NtQQEventsEnum) {
8
+ /**
9
+ * 群聊消息
10
+ */
8
11
  NtQQEventsEnum["GROUP_AT_MESSAGE_CREATE"] = "GROUP_AT_MESSAGE_CREATE";
9
- NtQQEventsEnum["C2C_MESSAGE_CREATE"] = "C2C_MESSAGE_CREATE"; // 单聊消息
12
+ /**
13
+ * 单聊消息
14
+ */
15
+ NtQQEventsEnum["C2C_MESSAGE_CREATE"] = "C2C_MESSAGE_CREATE";
10
16
  })(NtQQEventsEnum = NtQQEventsEnum || (NtQQEventsEnum = {}));
@@ -0,0 +1,23 @@
1
+ import { ClientAPIByQQ as ClientByNTQQ } from '../ntqq/sdk/index.js';
2
+ import { Client as ClientByVILLA } from 'mys-villa';
3
+ import { KOOKApiClient as ClientByKOOK } from 'kook-ws';
4
+ /**
5
+ * discord客户端
6
+ */
7
+ export const ClientDISCORD = {};
8
+ /**
9
+ * qq客户端
10
+ */
11
+ export const ClientQQ = global.ClientAPIByQQ;
12
+ /**
13
+ * kook客户端
14
+ */
15
+ export const ClientKOOK = ClientByKOOK;
16
+ /**
17
+ * ntqq客户端
18
+ */
19
+ export const ClientNTQQ = ClientByNTQQ;
20
+ /**
21
+ * villa客户端
22
+ */
23
+ export const ClientVILLA = ClientByVILLA;
@@ -0,0 +1,10 @@
1
+ import { spawn } from 'child_process';
2
+ export function nodeScripts(name = 'node', file = '', ars = []) {
3
+ const command = spawn(`${name} ${file} ${ars.join(' ')}`, { shell: true });
4
+ command.stdout.on('data', data => {
5
+ process.stdout.write(data.toString());
6
+ });
7
+ command.stderr.on('data', data => {
8
+ process.stderr.write(data.toString());
9
+ });
10
+ }
@@ -0,0 +1,22 @@
1
+ import { mkdirSync } from 'fs';
2
+ import { execSync } from 'child_process';
3
+ export async function command(cmd) {
4
+ // 错误参数
5
+ if (!cmd)
6
+ process.exit();
7
+ // 锁定位置
8
+ const dirPath = `./`;
9
+ // 没有存在
10
+ mkdirSync(dirPath, { recursive: true });
11
+ console.info('\n');
12
+ try {
13
+ // 切换目录
14
+ process.chdir(dirPath);
15
+ console.info(`[command] ${cmd}`);
16
+ execSync(cmd, { stdio: 'inherit' });
17
+ }
18
+ catch (error) {
19
+ console.info(`${error}`);
20
+ return;
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * ********
3
+ * 初始化
4
+ * ******
5
+ */
6
+ export * from './api.js';
7
+ export * from './main.js';