nexushub-commands 2.0.0 → 2.0.2
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/shared-commands/ParserSharedCommands.service.d.ts +1 -0
- package/lib/shared-commands/ParserSharedCommands.service.js +2 -1
- package/lib/shared-commands/SharedCommands.server.js +4 -2
- package/lib/shared-commands/SharedCommands.service.d.ts +1 -0
- package/lib/shared-commands/SharedCommands.service.js +1 -1
- package/package.json +1 -1
- package/src/shared-commands/ParserSharedCommands.service.ts +4 -3
- package/src/shared-commands/SharedCommands.server.ts +4 -2
- package/src/shared-commands/SharedCommands.service.ts +2 -2
|
@@ -89,7 +89,7 @@ class ParserSharedCommandsService {
|
|
|
89
89
|
processedArgs = `{ value: ${processedArgs} }`;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs})`;
|
|
92
|
+
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs}).then((res) => res.data)`;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Преобразует команду и возвращает объект с кодом и названием класса
|
|
@@ -168,6 +168,7 @@ class ParserSharedCommandsService {
|
|
|
168
168
|
filePath: fullPath,
|
|
169
169
|
transformedCode,
|
|
170
170
|
className,
|
|
171
|
+
object: require(fullPath.replace('.ts', '.js').replace('src', 'dist'))[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
|
}
|
|
@@ -7,7 +7,7 @@ const ParserSharedCommands_service_1 = require("./ParserSharedCommands.service")
|
|
|
7
7
|
class SharedCommandsService {
|
|
8
8
|
static init(projectName) {
|
|
9
9
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
this.commands = ParserSharedCommands_service_1.ParserSharedCommandsService.transformAllCommands();
|
|
10
|
+
this.commands = ParserSharedCommands_service_1.ParserSharedCommandsService.transformAllCommands(process.cwd() + '/src');
|
|
11
11
|
yield __1.Client.API.delete(`/projects/${projectName}/commands`).catch(console.error);
|
|
12
12
|
for (const command of this.commands)
|
|
13
13
|
yield __1.Client.API.post(`/projects/${projectName}/commands`, {
|
package/package.json
CHANGED
|
@@ -98,7 +98,7 @@ export class ParserSharedCommandsService {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs})`
|
|
101
|
+
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs}).then((res) => res.data)`
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -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.replace('.ts', '.js').replace('src', 'dist'))[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
|
-
|
|
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,10 +2,10 @@ 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
|
-
this.commands = ParserSharedCommandsService.transformAllCommands()
|
|
8
|
+
this.commands = ParserSharedCommandsService.transformAllCommands(process.cwd() + '/src')
|
|
9
9
|
|
|
10
10
|
await Client.API.delete(`/projects/${projectName}/commands`).catch(console.error)
|
|
11
11
|
for (const command of this.commands)
|