@dxtmisha/scripts 0.5.9 → 0.5.12

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.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env vite-node
2
+
3
+ import { DesignTypes } from '../src/classes/Design/DesignTypes'
4
+
5
+ const dir: string = process.argv?.[2] ?? 'dist'
6
+
7
+ new DesignTypes(dir).make()
package/bin/design-ui.ts CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  import { DesignUi } from '../src/classes/Design/DesignUi'
4
4
 
5
- const name: string = process.argv?.[2] ?? ''
5
+ const name: string | undefined = process.argv?.[2] ?? undefined
6
6
 
7
7
  new DesignUi(name).make()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dxtmisha/scripts",
3
3
  "private": false,
4
- "version": "0.5.9",
4
+ "version": "0.5.12",
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 = [
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'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env vite-node
2
+ /// <reference types="node" />
2
3
 
3
4
  import { spawn } from 'node:child_process'
4
5
 
@@ -12,7 +12,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
12
12
  ### Documentation Structure:
13
13
 
14
14
  1. **Header**:
15
- ```javascript (or typescript if typing is present)
15
+ ```javascript (or typescript if generics are present)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -42,8 +42,8 @@ Use the following template and style. Your response must contain ONLY MDX code.
42
42
  - List: `- `name: type` — description`.
43
43
  - **Returns:** (if it returns a value)
44
44
  - `Type` — description.
45
- - **Code Example**:
46
- ```javascript (or typescript if typing is present)
45
+ - **Code Example** (use typescript only if generics are present):
46
+ ```javascript (or typescript if generics are present)
47
47
  // Example usage
48
48
  Class.method(arg);
49
49
  ```
@@ -56,6 +56,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
56
56
  3.2. Try to preserve original descriptions unchanged.
57
57
  4. Use the correct terminology.
58
58
  4.1. All headings must be in [wikiLanguage].
59
+ 4.2. Avoid using Generics and TypeScript types in code examples if possible (e.g., avoid `export type EventHandler<T = any> = (data: T) => void`).
59
60
  5. Do not add unnecessary introductions or conclusions, only MDX.
60
61
  6. Return only the full MDX documentation code without any additional text, comments, or markdown formatting (```).
61
62
  7. The result must be exclusively text (response); do not attach any files.
@@ -12,7 +12,7 @@
12
12
  ### Структура документации:
13
13
 
14
14
  1. **Шапка**:
15
- ```javascript (или typescript, если есть типизация)
15
+ ```javascript (или typescript, если есть generics)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -42,8 +42,8 @@
42
42
  - Список: `- `имя: тип` — описание`.
43
43
  - **Возвращает:** (если возвращает значение)
44
44
  - `Тип` — описание.
45
- - **Пример кода**:
46
- ```javascript (или typescript, если есть типизация)
45
+ - **Пример кода** (используй typescript, только если есть generics):
46
+ ```javascript (или typescript, если есть generics)
47
47
  // Пример вызова
48
48
  Class.method(arg);
49
49
  ```
@@ -56,6 +56,7 @@
56
56
  3.2. Старайся сохранять оригинальные описания без изменений.
57
57
  4. Используй правильную терминологию.
58
58
  4.1. Все заголовки должны быть на языке [wikiLanguage].
59
+ 4.2. Избегай использования Generics и типов TypeScript в примерах кода, если это возможно (например, избегай `export type EventHandler<T = any> = (data: T) => void`).
59
60
  5. Не добавляй лишних введений или заключений, только MDX.
60
61
  6. Верни только полный MDX-код документации без какого-либо дополнительного текста, комментариев или форматирования markdown (```).
61
62
  7. Результат должен быть исключительно в виде текста (ответа), не прикрепляй никаких файлов.
@@ -12,7 +12,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
12
12
  ### Documentation Structure:
13
13
 
14
14
  1. **Header**:
15
- ```javascript (or typescript if typing is present)
15
+ ```javascript (or typescript if generics are present)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -38,8 +38,8 @@ Use the following template and style. Your response must contain ONLY MDX code.
38
38
  - **Returned Object Description** (if it returns a complex object, describe its properties here):
39
39
  - **TypeName:**
40
40
  - List of properties: `- `name: type` — description`.
41
- - **Code Example**:
42
- ```javascript (or typescript if typing is present)
41
+ - **Code Example** (use typescript only if generics are present):
42
+ ```javascript (or typescript if generics are present)
43
43
  import { useName } from '@package'
44
44
  // Initialization example
45
45
  ```
@@ -47,7 +47,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
47
47
  5. **Basic Usage**:
48
48
  - Header `## Basic Usage`
49
49
  - Subheaders with examples of various usage scenarios `### Scenario Name`.
50
- - Code and brief description if needed.
50
+ - Code (use typescript only if generics are present) and brief description if needed.
51
51
 
52
52
  6. **Data Types** (Optional, if there are additional important types not described in the Function section):
53
53
  - Header `## Data Types`
@@ -60,6 +60,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
60
60
  3.2. Try to preserve original descriptions unchanged.
61
61
  4. Use the correct terminology (Composable, Ref, Reactive).
62
62
  4.1. All headings must be in [wikiLanguage].
63
+ 4.2. Avoid using Generics and TypeScript types in code examples if possible (e.g., avoid `export type EventHandler<T = any> = (data: T) => void`).
63
64
  5. Do not add unnecessary introductions or conclusions, only MDX.
64
65
  6. Return only the full MDX documentation code without any additional text, comments, or markdown formatting (```).
65
66
  7. The result must be exclusively text (response); do not attach any files.
@@ -12,7 +12,7 @@
12
12
  ### Структура документации:
13
13
 
14
14
  1. **Шапка**:
15
- ```javascript (или typescript, если есть типизация)
15
+ ```javascript (или typescript, если есть generics)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -38,8 +38,8 @@
38
38
  - **Описание возвращаемого объекта** (если возвращает сложный объект, опиши его свойства тут же):
39
39
  - **ИмяТипа:**
40
40
  - Список свойств: `- `имя: тип` — описание`.
41
- - **Пример кода**:
42
- ```javascript (или typescript, если есть типизация)
41
+ - **Пример кода** (используй typescript, только если есть generics):
42
+ ```javascript (или typescript, если есть generics)
43
43
  import { useName } from '@package'
44
44
  // Пример инициализации
45
45
  ```
@@ -47,7 +47,7 @@
47
47
  5. **Основное использование (Basic Usage)**:
48
48
  - Заголовок `## Основное использование`
49
49
  - Подзаголовки с примерами различных сценариев использования `### Название сценария`.
50
- - Код и краткое описание если нужно.
50
+ - Код (используй typescript, только если есть generics) и краткое описание если нужно.
51
51
 
52
52
  6. **Типы данных** (Опционально, если есть дополнительные важные типы, которые не описаны в разделе Функция):
53
53
  - Заголовок `## Типы данных`
@@ -60,6 +60,7 @@
60
60
  3.2. Старайся сохранять оригинальные описания без изменений.
61
61
  4. Используй правильную терминологию (Composable, Ref, Reactive).
62
62
  4.1. Все заголовки должны быть на языке [wikiLanguage].
63
+ 4.2. Избегай использования Generics и типов TypeScript в примерах кода, если это возможно (например, избегай `export type EventHandler<T = any> = (data: T) => void`).
63
64
  5. Не добавляй лишних введений или заключений, только MDX.
64
65
  6. Верни только полный MDX-код документации без какого-либо дополнительного текста, комментариев или форматирования markdown (```).
65
66
  7. Результат должен быть исключительно в виде текста (ответа), не прикрепляй никаких файлов.
@@ -12,7 +12,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
12
12
  ### Documentation Structure:
13
13
 
14
14
  1. **Header**:
15
- ```javascript (or typescript if typing is present)
15
+ ```javascript (or typescript if generics are present)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -31,8 +31,8 @@ Use the following template and style. Your response must contain ONLY MDX code.
31
31
  - Description of the return value or type.
32
32
 
33
33
  5. **Example**:
34
- - Usage code example.
35
- ```javascript (or typescript if typing is present)
34
+ - Usage code example (use typescript only if generics are present).
35
+ ```javascript (or typescript if generics are present)
36
36
  import { name } from '@package'
37
37
  // Call example
38
38
  ```
@@ -50,6 +50,7 @@ Use the following template and style. Your response must contain ONLY MDX code.
50
50
  3.2. Try to preserve original descriptions unchanged.
51
51
  4. Use the correct terminology.
52
52
  4.1. All headings must be in [wikiLanguage].
53
+ 4.2. Avoid using Generics and TypeScript types in code examples if possible (e.g., avoid `export type EventHandler<T = any> = (data: T) => void`).
53
54
  5. Do not add unnecessary introductions or conclusions, only MDX.
54
55
  6. Return only the full MDX documentation code without any additional text, comments, or markdown formatting (```).
55
56
  7. The result must be exclusively text (response); do not attach any files.
@@ -12,7 +12,7 @@
12
12
  ### Структура документации:
13
13
 
14
14
  1. **Шапка**:
15
- ```javascript (или typescript, если есть типизация)
15
+ ```javascript (или typescript, если есть generics)
16
16
  import {Meta} from '@storybook/addon-docs/blocks'
17
17
 
18
18
  <Meta title='[title]'/>
@@ -31,8 +31,8 @@
31
31
  - Описание возвращаемого значения или типа.
32
32
 
33
33
  5. **Пример**:
34
- - Пример кода использования.
35
- ```javascript (или typescript, если есть типизация)
34
+ - Пример кода использования (используй typescript, только если есть generics).
35
+ ```javascript (или typescript, если есть generics)
36
36
  import { name } from '@package'
37
37
  // Пример вызова
38
38
  ```
@@ -50,6 +50,7 @@
50
50
  3.2. Старайся сохранять оригинальные описания без изменений.
51
51
  4. Используй правильную терминологию.
52
52
  4.1. Все заголовки должны быть на языке [wikiLanguage].
53
+ 4.2. Избегай использования Generics и типов TypeScript в примерах кода, если это возможно (например, избегай `export type EventHandler<T = any> = (data: T) => void`).
53
54
  5. Не добавляй лишних введений или заключений, только MDX.
54
55
  6. Верни только полный MDX-код документации без какого-либо дополнительного текста, комментариев или форматирования markdown (```).
55
56
  7. Результат должен быть исключительно в виде текста (ответа), не прикрепляй никаких файлов.
@@ -26,7 +26,7 @@ Use the following template and style.
26
26
  - Format: `- Use case.`
27
27
 
28
28
  4. **Basic Usage**:
29
- - Code example using the component (use typescript if typing is present).
29
+ - Code example using the component.
30
30
  ```html
31
31
  <script setup>
32
32
  // Script code
@@ -26,7 +26,7 @@
26
26
  - Формат: `- Сценарий.`
27
27
 
28
28
  4. **Пример использования (Basic Usage)**:
29
- - Пример кода с использованием компонента (используй typescript, если есть типизация).
29
+ - Пример кода с использованием компонента.
30
30
  ```html
31
31
  <script setup>
32
32
  // Код скрипта
@@ -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[]