nexushub-commands 1.11.2 → 1.12.0
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/Client.d.ts +1 -0
- package/lib/shared-commands/ParserSharedCommands.service.d.ts +54 -0
- package/lib/shared-commands/ParserSharedCommands.service.js +160 -0
- package/lib/shared-commands/SharedCommands.service.d.ts +5 -0
- package/lib/shared-commands/SharedCommands.service.js +21 -0
- package/package.json +2 -1
- package/src/Client.ts +1 -0
- package/src/shared-commands/ParserSharedCommands.service.ts +171 -0
- package/src/shared-commands/SharedCommands.service.ts +17 -0
package/lib/Client.d.ts
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare class ParserSharedCommandsService {
|
|
2
|
+
/**
|
|
3
|
+
* Парсит название класса из кода команды
|
|
4
|
+
* @param commandContent - исходный код команды
|
|
5
|
+
* @returns название класса или null, если не найдено
|
|
6
|
+
*/
|
|
7
|
+
parseClassName(commandContent: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Преобразует команду, заменяя приватные методы на API вызовы
|
|
10
|
+
* @param commandContent - исходный код команды
|
|
11
|
+
* @returns преобразованный код команды
|
|
12
|
+
*/
|
|
13
|
+
transformCommand(commandContent: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Преобразует команду и возвращает объект с кодом и названием класса
|
|
16
|
+
* @param commandContent - исходный код команды
|
|
17
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
18
|
+
*/
|
|
19
|
+
transformCommandWithMetadata(commandContent: string): {
|
|
20
|
+
transformedCode: string;
|
|
21
|
+
className: string | null;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Преобразует файл команды
|
|
25
|
+
* @param filePath - путь к файлу команды
|
|
26
|
+
* @returns преобразованный код команды
|
|
27
|
+
*/
|
|
28
|
+
transformCommandFile(filePath: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Преобразует файл команды и возвращает объект с кодом и названием класса
|
|
31
|
+
* @param filePath - путь к файлу команды
|
|
32
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
33
|
+
*/
|
|
34
|
+
transformCommandFileWithMetadata(filePath: string): {
|
|
35
|
+
transformedCode: string;
|
|
36
|
+
className: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Преобразует команду и возвращает строку с кодом
|
|
40
|
+
* @param originalFilePath - путь к оригинальному файлу
|
|
41
|
+
* @returns преобразованный код команды
|
|
42
|
+
*/
|
|
43
|
+
transformCommandToCode(originalFilePath: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Рекурсивно находит все .srdcmd файлы в директории src и преобразует их
|
|
46
|
+
* @param srcDir - директория src для поиска команд
|
|
47
|
+
* @returns массив объектов с путем к файлу, преобразованным кодом и названием класса
|
|
48
|
+
*/
|
|
49
|
+
transformAllCommands(srcDir?: string): Array<{
|
|
50
|
+
filePath: string;
|
|
51
|
+
transformedCode: string;
|
|
52
|
+
className: string | null;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParserSharedCommandsService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
class ParserSharedCommandsService {
|
|
8
|
+
/**
|
|
9
|
+
* Парсит название класса из кода команды
|
|
10
|
+
* @param commandContent - исходный код команды
|
|
11
|
+
* @returns название класса или null, если не найдено
|
|
12
|
+
*/
|
|
13
|
+
parseClassName(commandContent) {
|
|
14
|
+
// Ищем объявление класса: class ClassName extends ...
|
|
15
|
+
const classRegex = /class\s+(\w+)\s+extends\s+\w+/g;
|
|
16
|
+
const match = classRegex.exec(commandContent);
|
|
17
|
+
if (match && match[1])
|
|
18
|
+
return match[1];
|
|
19
|
+
else
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Преобразует команду, заменяя приватные методы на API вызовы
|
|
24
|
+
* @param commandContent - исходный код команды
|
|
25
|
+
* @returns преобразованный код команды
|
|
26
|
+
*/
|
|
27
|
+
transformCommand(commandContent) {
|
|
28
|
+
// Убираем все импорты
|
|
29
|
+
let transformedContent = commandContent.replace(/import\s+.*?from\s+['"][^'"]*['"];?\n?/g, '');
|
|
30
|
+
// Заменяем extends на SharedCommand
|
|
31
|
+
transformedContent = transformedContent.replace(/extends\s+\w+/g, 'extends SharedCommand');
|
|
32
|
+
// Находим все приватные методы
|
|
33
|
+
const privateMethodRegex = /private\s+async\s+(\w+)\s*\([^)]*\)\s*\{[\s\S]*?\}/g;
|
|
34
|
+
const privateMethods = [];
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = privateMethodRegex.exec(commandContent)) !== null) {
|
|
37
|
+
privateMethods.push(match[1]);
|
|
38
|
+
}
|
|
39
|
+
// Заменяем вызовы приватных методов на API вызовы
|
|
40
|
+
privateMethods.forEach((methodName) => {
|
|
41
|
+
// Паттерн для поиска вызовов this.methodName(...)
|
|
42
|
+
const methodCallRegex = new RegExp(`this\\.${methodName}\\s*\\(([^)]*)\\)`, 'g');
|
|
43
|
+
transformedContent = transformedContent.replace(methodCallRegex, (match, args) => {
|
|
44
|
+
// Обрабатываем аргументы
|
|
45
|
+
let processedArgs = args.trim();
|
|
46
|
+
// Если аргументы пустые, создаем пустой объект
|
|
47
|
+
if (!processedArgs) {
|
|
48
|
+
processedArgs = '{}';
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Если это объект, оставляем как есть
|
|
52
|
+
if (processedArgs.startsWith('{') && processedArgs.endsWith('}')) {
|
|
53
|
+
// Убираем лишние пробелы
|
|
54
|
+
processedArgs = processedArgs.replace(/\s+/g, ' ');
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Если это не объект, оборачиваем в объект
|
|
58
|
+
processedArgs = `{ value: ${processedArgs} }`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs})`;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
// Удаляем все приватные методы
|
|
65
|
+
transformedContent = transformedContent.replace(privateMethodRegex, '');
|
|
66
|
+
// Убираем лишние пустые строки
|
|
67
|
+
transformedContent = transformedContent.replace(/\n\s*\n\s*\n/g, '\n\n');
|
|
68
|
+
return transformedContent;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Преобразует команду и возвращает объект с кодом и названием класса
|
|
72
|
+
* @param commandContent - исходный код команды
|
|
73
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
74
|
+
*/
|
|
75
|
+
transformCommandWithMetadata(commandContent) {
|
|
76
|
+
const className = this.parseClassName(commandContent);
|
|
77
|
+
const transformedCode = this.transformCommand(commandContent);
|
|
78
|
+
return {
|
|
79
|
+
transformedCode,
|
|
80
|
+
className,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Преобразует файл команды
|
|
85
|
+
* @param filePath - путь к файлу команды
|
|
86
|
+
* @returns преобразованный код команды
|
|
87
|
+
*/
|
|
88
|
+
transformCommandFile(filePath) {
|
|
89
|
+
try {
|
|
90
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
91
|
+
return this.transformCommand(content);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Ошибка при чтении файла ${filePath}: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Преобразует файл команды и возвращает объект с кодом и названием класса
|
|
99
|
+
* @param filePath - путь к файлу команды
|
|
100
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
101
|
+
*/
|
|
102
|
+
transformCommandFileWithMetadata(filePath) {
|
|
103
|
+
try {
|
|
104
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
105
|
+
return this.transformCommandWithMetadata(content);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw new Error(`Ошибка при чтении файла ${filePath}: ${error}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Преобразует команду и возвращает строку с кодом
|
|
113
|
+
* @param originalFilePath - путь к оригинальному файлу
|
|
114
|
+
* @returns преобразованный код команды
|
|
115
|
+
*/
|
|
116
|
+
transformCommandToCode(originalFilePath) {
|
|
117
|
+
return this.transformCommandFile(originalFilePath);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Рекурсивно находит все .srdcmd файлы в директории src и преобразует их
|
|
121
|
+
* @param srcDir - директория src для поиска команд
|
|
122
|
+
* @returns массив объектов с путем к файлу, преобразованным кодом и названием класса
|
|
123
|
+
*/
|
|
124
|
+
transformAllCommands(srcDir = './src') {
|
|
125
|
+
if (!fs.existsSync(srcDir)) {
|
|
126
|
+
throw new Error(`Директория src не существует: ${srcDir}`);
|
|
127
|
+
}
|
|
128
|
+
const results = [];
|
|
129
|
+
// Рекурсивно проходим по всем файлам в src
|
|
130
|
+
const processDirectory = (dir) => {
|
|
131
|
+
const items = fs.readdirSync(dir);
|
|
132
|
+
items.forEach((item) => {
|
|
133
|
+
const fullPath = path.join(dir, item);
|
|
134
|
+
const stat = fs.statSync(fullPath);
|
|
135
|
+
if (stat.isDirectory()) {
|
|
136
|
+
// Рекурсивно обрабатываем поддиректории
|
|
137
|
+
processDirectory(fullPath);
|
|
138
|
+
}
|
|
139
|
+
else if (item.endsWith('.srdcmd.ts')) {
|
|
140
|
+
// Нашли .srdcmd файл - преобразуем его
|
|
141
|
+
try {
|
|
142
|
+
const { transformedCode, className } = this.transformCommandFileWithMetadata(fullPath);
|
|
143
|
+
results.push({
|
|
144
|
+
filePath: fullPath,
|
|
145
|
+
transformedCode,
|
|
146
|
+
className,
|
|
147
|
+
});
|
|
148
|
+
console.log(`Команда преобразована: ${fullPath} (Класс: ${className || 'не найден'})`);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error(`Ошибка при преобразовании ${fullPath}: ${error}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
processDirectory(srcDir);
|
|
157
|
+
return results;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.ParserSharedCommandsService = ParserSharedCommandsService;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedCommandsService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const ParserSharedCommands_service_1 = require("./ParserSharedCommands.service");
|
|
7
|
+
class SharedCommandsService {
|
|
8
|
+
static init(projectName) {
|
|
9
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
this.commands = this.parser.transformAllCommands();
|
|
11
|
+
for (const command of this.commands)
|
|
12
|
+
yield __1.Client.API.post(`/projects/${projectName}/commands`, {
|
|
13
|
+
name: command.className,
|
|
14
|
+
code: command.transformedCode,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.SharedCommandsService = SharedCommandsService;
|
|
20
|
+
SharedCommandsService.commands = [];
|
|
21
|
+
SharedCommandsService.parser = new ParserSharedCommands_service_1.ParserSharedCommandsService();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexushub-commands",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"evogram": "^2.0.8"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@types/node": "^24.3.0",
|
|
14
15
|
"evogram": "^2.2.3"
|
|
15
16
|
}
|
|
16
17
|
}
|
package/src/Client.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
|
|
4
|
+
export class ParserSharedCommandsService {
|
|
5
|
+
/**
|
|
6
|
+
* Парсит название класса из кода команды
|
|
7
|
+
* @param commandContent - исходный код команды
|
|
8
|
+
* @returns название класса или null, если не найдено
|
|
9
|
+
*/
|
|
10
|
+
parseClassName(commandContent: string): string | null {
|
|
11
|
+
// Ищем объявление класса: class ClassName extends ...
|
|
12
|
+
const classRegex = /class\s+(\w+)\s+extends\s+\w+/g
|
|
13
|
+
const match = classRegex.exec(commandContent)
|
|
14
|
+
|
|
15
|
+
if (match && match[1]) return match[1]
|
|
16
|
+
else return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Преобразует команду, заменяя приватные методы на API вызовы
|
|
21
|
+
* @param commandContent - исходный код команды
|
|
22
|
+
* @returns преобразованный код команды
|
|
23
|
+
*/
|
|
24
|
+
transformCommand(commandContent: string): string {
|
|
25
|
+
// Убираем все импорты
|
|
26
|
+
let transformedContent = commandContent.replace(/import\s+.*?from\s+['"][^'"]*['"];?\n?/g, '')
|
|
27
|
+
|
|
28
|
+
// Заменяем extends на SharedCommand
|
|
29
|
+
transformedContent = transformedContent.replace(/extends\s+\w+/g, 'extends SharedCommand')
|
|
30
|
+
|
|
31
|
+
// Находим все приватные методы
|
|
32
|
+
const privateMethodRegex = /private\s+async\s+(\w+)\s*\([^)]*\)\s*\{[\s\S]*?\}/g
|
|
33
|
+
const privateMethods: string[] = []
|
|
34
|
+
let match
|
|
35
|
+
|
|
36
|
+
while ((match = privateMethodRegex.exec(commandContent)) !== null) {
|
|
37
|
+
privateMethods.push(match[1])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Заменяем вызовы приватных методов на API вызовы
|
|
41
|
+
privateMethods.forEach((methodName) => {
|
|
42
|
+
// Паттерн для поиска вызовов this.methodName(...)
|
|
43
|
+
const methodCallRegex = new RegExp(`this\\.${methodName}\\s*\\(([^)]*)\\)`, 'g')
|
|
44
|
+
|
|
45
|
+
transformedContent = transformedContent.replace(methodCallRegex, (match, args) => {
|
|
46
|
+
// Обрабатываем аргументы
|
|
47
|
+
let processedArgs = args.trim()
|
|
48
|
+
|
|
49
|
+
// Если аргументы пустые, создаем пустой объект
|
|
50
|
+
if (!processedArgs) {
|
|
51
|
+
processedArgs = '{}'
|
|
52
|
+
} else {
|
|
53
|
+
// Если это объект, оставляем как есть
|
|
54
|
+
if (processedArgs.startsWith('{') && processedArgs.endsWith('}')) {
|
|
55
|
+
// Убираем лишние пробелы
|
|
56
|
+
processedArgs = processedArgs.replace(/\s+/g, ' ')
|
|
57
|
+
} else {
|
|
58
|
+
// Если это не объект, оборачиваем в объект
|
|
59
|
+
processedArgs = `{ value: ${processedArgs} }`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return `this.API.post(\`/commands/\${this.constructor.name}/${methodName}\`, ${processedArgs})`
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Удаляем все приватные методы
|
|
68
|
+
transformedContent = transformedContent.replace(privateMethodRegex, '')
|
|
69
|
+
|
|
70
|
+
// Убираем лишние пустые строки
|
|
71
|
+
transformedContent = transformedContent.replace(/\n\s*\n\s*\n/g, '\n\n')
|
|
72
|
+
|
|
73
|
+
return transformedContent
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Преобразует команду и возвращает объект с кодом и названием класса
|
|
78
|
+
* @param commandContent - исходный код команды
|
|
79
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
80
|
+
*/
|
|
81
|
+
transformCommandWithMetadata(commandContent: string): { transformedCode: string; className: string | null } {
|
|
82
|
+
const className = this.parseClassName(commandContent)
|
|
83
|
+
const transformedCode = this.transformCommand(commandContent)
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
transformedCode,
|
|
87
|
+
className,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Преобразует файл команды
|
|
93
|
+
* @param filePath - путь к файлу команды
|
|
94
|
+
* @returns преобразованный код команды
|
|
95
|
+
*/
|
|
96
|
+
transformCommandFile(filePath: string): string {
|
|
97
|
+
try {
|
|
98
|
+
const content = fs.readFileSync(filePath, 'utf-8')
|
|
99
|
+
return this.transformCommand(content)
|
|
100
|
+
} catch (error) {
|
|
101
|
+
throw new Error(`Ошибка при чтении файла ${filePath}: ${error}`)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Преобразует файл команды и возвращает объект с кодом и названием класса
|
|
107
|
+
* @param filePath - путь к файлу команды
|
|
108
|
+
* @returns объект с преобразованным кодом и названием класса
|
|
109
|
+
*/
|
|
110
|
+
transformCommandFileWithMetadata(filePath: string): { transformedCode: string; className: string | null } {
|
|
111
|
+
try {
|
|
112
|
+
const content = fs.readFileSync(filePath, 'utf-8')
|
|
113
|
+
return this.transformCommandWithMetadata(content)
|
|
114
|
+
} catch (error) {
|
|
115
|
+
throw new Error(`Ошибка при чтении файла ${filePath}: ${error}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Преобразует команду и возвращает строку с кодом
|
|
121
|
+
* @param originalFilePath - путь к оригинальному файлу
|
|
122
|
+
* @returns преобразованный код команды
|
|
123
|
+
*/
|
|
124
|
+
transformCommandToCode(originalFilePath: string): string {
|
|
125
|
+
return this.transformCommandFile(originalFilePath)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Рекурсивно находит все .srdcmd файлы в директории src и преобразует их
|
|
130
|
+
* @param srcDir - директория src для поиска команд
|
|
131
|
+
* @returns массив объектов с путем к файлу, преобразованным кодом и названием класса
|
|
132
|
+
*/
|
|
133
|
+
transformAllCommands(srcDir: string = './src'): Array<{ filePath: string; transformedCode: string; className: string | null }> {
|
|
134
|
+
if (!fs.existsSync(srcDir)) {
|
|
135
|
+
throw new Error(`Директория src не существует: ${srcDir}`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const results: Array<{ filePath: string; transformedCode: string; className: string | null }> = []
|
|
139
|
+
|
|
140
|
+
// Рекурсивно проходим по всем файлам в src
|
|
141
|
+
const processDirectory = (dir: string) => {
|
|
142
|
+
const items = fs.readdirSync(dir)
|
|
143
|
+
|
|
144
|
+
items.forEach((item: string) => {
|
|
145
|
+
const fullPath = path.join(dir, item)
|
|
146
|
+
const stat = fs.statSync(fullPath)
|
|
147
|
+
|
|
148
|
+
if (stat.isDirectory()) {
|
|
149
|
+
// Рекурсивно обрабатываем поддиректории
|
|
150
|
+
processDirectory(fullPath)
|
|
151
|
+
} else if (item.endsWith('.srdcmd.ts')) {
|
|
152
|
+
// Нашли .srdcmd файл - преобразуем его
|
|
153
|
+
try {
|
|
154
|
+
const { transformedCode, className } = this.transformCommandFileWithMetadata(fullPath)
|
|
155
|
+
results.push({
|
|
156
|
+
filePath: fullPath,
|
|
157
|
+
transformedCode,
|
|
158
|
+
className,
|
|
159
|
+
})
|
|
160
|
+
console.log(`Команда преобразована: ${fullPath} (Класс: ${className || 'не найден'})`)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error(`Ошибка при преобразовании ${fullPath}: ${error}`)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
processDirectory(srcDir)
|
|
169
|
+
return results
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Client } from '..'
|
|
2
|
+
import { ParserSharedCommandsService } from './ParserSharedCommands.service'
|
|
3
|
+
|
|
4
|
+
export class SharedCommandsService {
|
|
5
|
+
private static commands: { filePath: string; transformedCode: string; className: string | null }[] = []
|
|
6
|
+
private static parser = new ParserSharedCommandsService()
|
|
7
|
+
|
|
8
|
+
public static async init(projectName: string) {
|
|
9
|
+
this.commands = this.parser.transformAllCommands()
|
|
10
|
+
|
|
11
|
+
for (const command of this.commands)
|
|
12
|
+
await Client.API.post(`/projects/${projectName}/commands`, {
|
|
13
|
+
name: command.className,
|
|
14
|
+
code: command.transformedCode,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|