@dxtmisha/scripts 0.5.10 → 0.5.13
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/bin/design-types.ts +7 -0
- package/bin/design-ui.ts +1 -1
- package/package.json +2 -1
- package/src/classes/Ai/AiGoogleCliLite.ts +3 -2
- package/src/classes/Design/DesignTypes.ts +196 -0
- package/src/classes/Package/PackageItem.ts +1 -1
- package/src/classes/Properties/PropertiesFile.ts +24 -2
- package/src/config.ts +2 -0
- package/src/functions/getPackageJson.ts +11 -0
- package/src/library.ts +2 -0
- package/src/media/templates/componentDoc/wiki/run.ts +1 -0
- package/src/types/designTypes.ts +7 -0
package/bin/design-ui.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxtmisha/scripts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Development scripts and CLI tools for DXT UI projects - automated component generation, library building and project management tools",
|
|
7
7
|
"keywords": [
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"dxt-constructor": "bin/design-constructor.ts",
|
|
47
47
|
"dxt-library": "bin/design-library.ts",
|
|
48
48
|
"dxt-package": "bin/design-package.ts",
|
|
49
|
+
"dxt-types": "bin/design-types.ts",
|
|
49
50
|
"dxt-ui": "bin/design-ui.ts"
|
|
50
51
|
},
|
|
51
52
|
"exports": {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { forEach } from '@dxtmisha/functional-basic'
|
|
1
2
|
import { exec } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
import { PropertiesFile } from '../Properties/PropertiesFile'
|
|
2
5
|
import { AiAbstract } from './AiAbstract'
|
|
3
|
-
import { PropertiesFile } from '../Properties/PropertiesFile.ts'
|
|
4
|
-
import { forEach } from '@dxtmisha/functional-basic'
|
|
5
6
|
|
|
6
7
|
const TEMPORARY_DIR = './ai-tmp'
|
|
7
8
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { forEach } from '@dxtmisha/functional-basic'
|
|
2
|
+
import { useAi } from '../../composables/useAi'
|
|
3
|
+
|
|
4
|
+
import { PropertiesFile } from '../Properties/PropertiesFile'
|
|
5
|
+
|
|
6
|
+
import type { DesignTypesList } from '../../types/designTypes'
|
|
7
|
+
|
|
8
|
+
import { UI_FILE_AI_TYPES } from '../../config'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Class for generating AI-optimized type definitions.
|
|
12
|
+
*
|
|
13
|
+
* Класс для генерации оптимизированных ИИ определений типов.
|
|
14
|
+
*/
|
|
15
|
+
export class DesignTypes {
|
|
16
|
+
/**
|
|
17
|
+
* Array of directory path segments.
|
|
18
|
+
*
|
|
19
|
+
* Массив сегментов пути директории.
|
|
20
|
+
*/
|
|
21
|
+
protected readonly dirArray: string[]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Constructor
|
|
25
|
+
* @param dir directory path / путь к директории
|
|
26
|
+
*/
|
|
27
|
+
constructor(
|
|
28
|
+
protected readonly dir: string = 'dist'
|
|
29
|
+
) {
|
|
30
|
+
this.dirArray = this.dir.split('/')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Main method to execute the type generation process.
|
|
35
|
+
*
|
|
36
|
+
* Основной метод для выполнения процесса генерации типов.
|
|
37
|
+
*/
|
|
38
|
+
make() {
|
|
39
|
+
console.log('DesignTypes: making AI types...')
|
|
40
|
+
|
|
41
|
+
const files = this.getListByFilter()
|
|
42
|
+
const fullContent = this.toOneFile(files)
|
|
43
|
+
|
|
44
|
+
this.toAiEdit(fullContent).then(
|
|
45
|
+
(aiContent) => {
|
|
46
|
+
this.save(aiContent)
|
|
47
|
+
|
|
48
|
+
console.log('DesignTypes: AI types saved.')
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the file is a valid declaration file.
|
|
55
|
+
*
|
|
56
|
+
* Проверяет, является ли файл валидным файлом декларации.
|
|
57
|
+
* @param file file name / имя файла
|
|
58
|
+
*/
|
|
59
|
+
protected isFile(file: string): boolean {
|
|
60
|
+
return file.endsWith('.d.ts')
|
|
61
|
+
&& (
|
|
62
|
+
!file.includes('constructors/')
|
|
63
|
+
|| (
|
|
64
|
+
!file.endsWith('/props.d.ts')
|
|
65
|
+
&& !file.endsWith('/types.d.ts')
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Checks if the content contains type definitions.
|
|
72
|
+
*
|
|
73
|
+
* Проверяет, содержит ли контент определения типов.
|
|
74
|
+
* @param content file content / содержимое файла
|
|
75
|
+
*/
|
|
76
|
+
protected isContent(content?: string): content is string {
|
|
77
|
+
return Boolean(
|
|
78
|
+
content && (
|
|
79
|
+
content.includes('export interface')
|
|
80
|
+
|| content.includes('export type')
|
|
81
|
+
|| content.includes('export enum')
|
|
82
|
+
))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Returns the full path segments for a file.
|
|
87
|
+
*
|
|
88
|
+
* Возвращает сегменты полного пути для файла.
|
|
89
|
+
* @param file file name / имя файла
|
|
90
|
+
*/
|
|
91
|
+
protected getPath(file: string): string[] {
|
|
92
|
+
return [...this.dirArray, file]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Reads the directory recursively.
|
|
97
|
+
*
|
|
98
|
+
* Читает директорию рекурсивно.
|
|
99
|
+
*/
|
|
100
|
+
protected getList() {
|
|
101
|
+
return PropertiesFile.readDirRecursive(this.dirArray)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gets a list of files filtered by criteria.
|
|
106
|
+
*
|
|
107
|
+
* Получает список файлов, отфильтрованный по критериям.
|
|
108
|
+
*/
|
|
109
|
+
protected getListByFilter(): DesignTypesList {
|
|
110
|
+
return forEach(
|
|
111
|
+
this.getList(),
|
|
112
|
+
(file) => {
|
|
113
|
+
if (this.isFile(file)) {
|
|
114
|
+
const content = this.readFile(file)
|
|
115
|
+
|
|
116
|
+
if (this.isContent(content)) {
|
|
117
|
+
return {
|
|
118
|
+
path: file,
|
|
119
|
+
content
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return undefined
|
|
125
|
+
}
|
|
126
|
+
) as DesignTypesList
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Reads the content of a file.
|
|
131
|
+
*
|
|
132
|
+
* Читает содержимое файла.
|
|
133
|
+
* @param path file path / путь к файлу
|
|
134
|
+
*/
|
|
135
|
+
protected readFile(path: string): string | undefined {
|
|
136
|
+
return PropertiesFile.readFileOnly(this.getPath(path))
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Saves the generated content to a file.
|
|
141
|
+
*
|
|
142
|
+
* Сохраняет сгенерированный контент в файл.
|
|
143
|
+
* @param content content to save / контент для сохранения
|
|
144
|
+
*/
|
|
145
|
+
protected save(content: string) {
|
|
146
|
+
PropertiesFile.writeByPath(
|
|
147
|
+
UI_FILE_AI_TYPES,
|
|
148
|
+
content
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Combines a list of files into a single string.
|
|
154
|
+
*
|
|
155
|
+
* Объединяет список файлов в одну строку.
|
|
156
|
+
* @param list list of files / список файлов
|
|
157
|
+
*/
|
|
158
|
+
protected toOneFile(list: DesignTypesList): string {
|
|
159
|
+
return forEach(
|
|
160
|
+
list,
|
|
161
|
+
item => `// File: ${item.path}\n${item.content}`
|
|
162
|
+
)
|
|
163
|
+
.join('\n\n')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Sends content to AI for optimization.
|
|
168
|
+
*
|
|
169
|
+
* Отправляет контент ИИ для оптимизации.
|
|
170
|
+
* @param content content to optimize / контент для оптимизации
|
|
171
|
+
*/
|
|
172
|
+
protected async toAiEdit(content: string): Promise<string> {
|
|
173
|
+
const ai = useAi()
|
|
174
|
+
|
|
175
|
+
if (ai) {
|
|
176
|
+
ai.addPrompt(`File Content: ${content}`)
|
|
177
|
+
|
|
178
|
+
const generate = await ai.generate(
|
|
179
|
+
'Remove all Russian comments from this code. '
|
|
180
|
+
+ 'Remove comments if the property name makes its purpose obvious. '
|
|
181
|
+
+ 'Remove all imports. '
|
|
182
|
+
+ 'Remove empty lines. '
|
|
183
|
+
+ 'Remove the "export" keyword if possible. '
|
|
184
|
+
+ 'Keep only "type", "interface" and "enum" definitions, remove everything else. '
|
|
185
|
+
+ 'Minimize the content as much as possible without losing any data or logic. '
|
|
186
|
+
+ 'Return only the corrected code without any additional text or explanations.'
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
if (generate) {
|
|
190
|
+
return generate
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return content
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// export:none
|
|
2
2
|
|
|
3
3
|
import requirePath from 'path'
|
|
4
|
+
import { PropertiesConfig } from '../Properties/PropertiesConfig'
|
|
4
5
|
import { PropertiesFile } from '../Properties/PropertiesFile'
|
|
5
6
|
|
|
6
7
|
import { UI_DIR_PACKAGES, UI_DIRS_LIBRARY, UI_FILE_PACKAGE } from '../../config'
|
|
7
|
-
import { PropertiesConfig } from '../Properties/PropertiesConfig.ts'
|
|
8
8
|
|
|
9
9
|
const DIR_SAMPLE = [__dirname, '..', '..', 'media', 'templates', 'packages']
|
|
10
10
|
const DIR_STORYBOOK = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Datetime, toArray, toKebabCase, transformation } from '@dxtmisha/functional-basic'
|
|
1
|
+
import { Datetime, forEach, toArray, toKebabCase, transformation } from '@dxtmisha/functional-basic'
|
|
2
2
|
|
|
3
3
|
import requireFs from 'fs'
|
|
4
4
|
import requirePath from 'path'
|
|
@@ -64,7 +64,12 @@ export class PropertiesFile {
|
|
|
64
64
|
* @param path a sequence of path segments/ последовательность сегментов пути
|
|
65
65
|
*/
|
|
66
66
|
static joinPath(path: PropertiesFilePath): string {
|
|
67
|
-
|
|
67
|
+
const pathArray = forEach(
|
|
68
|
+
toArray(path),
|
|
69
|
+
item => this.toSep(item)
|
|
70
|
+
) as string[]
|
|
71
|
+
|
|
72
|
+
return requirePath.join(...pathArray)
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
/**
|
|
@@ -226,6 +231,23 @@ export class PropertiesFile {
|
|
|
226
231
|
return new Datetime(this.stat(path)?.mtimeMs, 'full').standard()
|
|
227
232
|
}
|
|
228
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Converts the path to use the current OS separator.
|
|
236
|
+
*
|
|
237
|
+
* Преобразует путь для использования текущего разделителя ОС.
|
|
238
|
+
* @param path path to the directory/ путь к директории
|
|
239
|
+
*/
|
|
240
|
+
static toSep(path: PropertiesFilePath): PropertiesFilePath {
|
|
241
|
+
const sep = this.sep()
|
|
242
|
+
|
|
243
|
+
if (sep === '/') {
|
|
244
|
+
return path
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return this.joinPath(path)
|
|
248
|
+
.replace('/', this.sep())
|
|
249
|
+
}
|
|
250
|
+
|
|
229
251
|
/**
|
|
230
252
|
* Reads the contents of the directory.
|
|
231
253
|
*
|
package/src/config.ts
CHANGED
|
@@ -83,6 +83,8 @@ export const UI_FILE_NAME_VITE_WORKERS = 'vite-workers.config.ts'
|
|
|
83
83
|
|
|
84
84
|
export const UI_FILE_INDEX = 'index.ts'
|
|
85
85
|
|
|
86
|
+
export const UI_FILE_AI_TYPES = 'ai-types.txt'
|
|
87
|
+
|
|
86
88
|
/** SCSS file extension/ Расширение файлов SCSS */
|
|
87
89
|
export const UI_EXTENSION_STYLE = 'scss'
|
|
88
90
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PropertiesFile } from '../classes/Properties/PropertiesFile'
|
|
2
|
+
import { UI_FILE_PACKAGE } from '../config'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the package.json file content.
|
|
6
|
+
*
|
|
7
|
+
* Возвращает содержимое файла package.json.
|
|
8
|
+
*/
|
|
9
|
+
export function getPackageJson(): Record<string, any> | undefined {
|
|
10
|
+
return PropertiesFile.readFile<Record<string, any>>(UI_FILE_PACKAGE)
|
|
11
|
+
}
|
package/src/library.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './classes/Ai/AiGoogleCli'
|
|
|
11
11
|
export * from './classes/Ai/AiGoogleCliLite'
|
|
12
12
|
export * from './classes/Ai/AiGoogleLite'
|
|
13
13
|
export * from './classes/BuildItem'
|
|
14
|
+
export * from './classes/Design/DesignTypes'
|
|
14
15
|
export * from './classes/Design/DesignTypescript'
|
|
15
16
|
export * from './classes/Git/GitRead'
|
|
16
17
|
export * from './classes/Properties/PropertiesFile'
|
|
@@ -20,6 +21,7 @@ export * from './composables/useAi'
|
|
|
20
21
|
|
|
21
22
|
// Functions
|
|
22
23
|
export * from './functions/getConfigAi'
|
|
24
|
+
export * from './functions/getPackageJson'
|
|
23
25
|
|
|
24
26
|
// Types
|
|
25
27
|
export * from './types/aiTypes'
|
package/src/types/designTypes.ts
CHANGED
|
@@ -94,3 +94,10 @@ export type DesignTypescriptItem = {
|
|
|
94
94
|
|
|
95
95
|
/** List of TypeScript items / Список TypeScript элементов */
|
|
96
96
|
export type DesignTypescriptList = DesignTypescriptItem[]
|
|
97
|
+
|
|
98
|
+
export type DesignTypesItem = {
|
|
99
|
+
path: string
|
|
100
|
+
content: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type DesignTypesList = DesignTypesItem[]
|