nexushub-commands 2.0.0 → 2.0.1

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.
@@ -57,5 +57,6 @@ export declare class ParserSharedCommandsService {
57
57
  filePath: string;
58
58
  transformedCode: string;
59
59
  className: string | null;
60
+ object: any;
60
61
  }>;
61
62
  }
@@ -168,6 +168,7 @@ class ParserSharedCommandsService {
168
168
  filePath: fullPath,
169
169
  transformedCode,
170
170
  className,
171
+ object: require(fullPath)[className],
171
172
  });
172
173
  console.log(`Команда преобразована: ${fullPath} (Класс: ${className || 'не найден'})`);
173
174
  }
@@ -13,9 +13,11 @@ class SharedCommandsServer {
13
13
  var _a;
14
14
  const { name, method } = req.params;
15
15
  //@ts-ignore
16
- const execute = (_a = SharedCommands_service_1.SharedCommandsService.commands.find((c) => c.className === name)) === null || _a === void 0 ? void 0 : _a[method];
16
+ const execute = (_a = SharedCommands_service_1.SharedCommandsService.commands.find((c) => c.className === name)) === null || _a === void 0 ? void 0 : _a.object[method];
17
17
  if (execute)
18
- res.send(yield execute(req.body));
18
+ res.send(yield execute(req.body).catch(console.error));
19
+ else
20
+ res.send(null);
19
21
  }));
20
22
  });
21
23
  }
@@ -3,6 +3,7 @@ export declare class SharedCommandsService {
3
3
  filePath: string;
4
4
  transformedCode: string;
5
5
  className: string | null;
6
+ object: any;
6
7
  }[];
7
8
  static init(projectName: string): Promise<void>;
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexushub-commands",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -158,12 +158,12 @@ export class ParserSharedCommandsService {
158
158
  * @param srcDir - директория src для поиска команд
159
159
  * @returns массив объектов с путем к файлу, преобразованным кодом и названием класса
160
160
  */
161
- static transformAllCommands(srcDir: string = './src'): Array<{ filePath: string; transformedCode: string; className: string | null }> {
161
+ static transformAllCommands(srcDir: string = './src'): Array<{ filePath: string; transformedCode: string; className: string | null; object: any }> {
162
162
  if (!fs.existsSync(srcDir)) {
163
163
  throw new Error(`Директория src не существует: ${srcDir}`)
164
164
  }
165
165
 
166
- const results: Array<{ filePath: string; transformedCode: string; className: string | null }> = []
166
+ const results: Array<{ filePath: string; transformedCode: string; className: string | null; object: any }> = []
167
167
 
168
168
  // Рекурсивно проходим по всем файлам в src
169
169
  const processDirectory = (dir: string) => {
@@ -184,6 +184,7 @@ export class ParserSharedCommandsService {
184
184
  filePath: fullPath,
185
185
  transformedCode,
186
186
  className,
187
+ object: require(fullPath)[className as any],
187
188
  })
188
189
  console.log(`Команда преобразована: ${fullPath} (Класс: ${className || 'не найден'})`)
189
190
  } catch (error) {
@@ -9,8 +9,10 @@ export class SharedCommandsServer {
9
9
  const { name, method } = req.params
10
10
 
11
11
  //@ts-ignore
12
- const execute = SharedCommandsService.commands.find((c) => c.className === name)?.[method]
13
- if (execute) res.send(await execute(req.body))
12
+ const execute = SharedCommandsService.commands.find((c) => c.className === name)?.object[method]
13
+
14
+ if (execute) res.send(await execute(req.body).catch(console.error))
15
+ else res.send(null)
14
16
  })
15
17
  }
16
18
  }
@@ -2,7 +2,7 @@ import { Client } from '..'
2
2
  import { ParserSharedCommandsService } from './ParserSharedCommands.service'
3
3
 
4
4
  export class SharedCommandsService {
5
- public static commands: { filePath: string; transformedCode: string; className: string | null }[] = []
5
+ public static commands: { filePath: string; transformedCode: string; className: string | null; object: any }[] = []
6
6
 
7
7
  public static async init(projectName: string) {
8
8
  this.commands = ParserSharedCommandsService.transformAllCommands()