@dxtmisha/scripts 0.4.5 → 0.5.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/bin/ai-doc.ts +9 -0
- package/package.json +9 -7
- package/src/classes/Ai/AiAbstract.ts +94 -13
- package/src/classes/Ai/AiDoc.ts +62 -0
- package/src/classes/Ai/AiDocItem.ts +20 -0
- package/src/classes/Ai/AiDocItemAbstract.ts +198 -0
- package/src/classes/Ai/AiDocItemClasses.ts +20 -0
- package/src/classes/Ai/AiDocItemComposables.ts +13 -0
- package/src/classes/Ai/AiDocType.ts +45 -0
- package/src/classes/Ai/AiGoogle.ts +7 -29
- package/src/classes/Ai/AiGoogleCli.ts +24 -0
- package/src/classes/Ai/AiGoogleCliLite.ts +144 -0
- package/src/classes/Ai/AiGoogleLite.ts +77 -0
- package/src/classes/BuildItem.ts +176 -0
- package/src/classes/Component/ComponentCreator.ts +2 -0
- package/src/classes/Component/ComponentItem.ts +3 -1
- package/src/classes/Component/ComponentWiki.ts +107 -190
- package/src/classes/Component/ComponentWikiFile.ts +102 -15
- package/src/classes/Design/DesignCommand.ts +3 -1
- package/src/classes/Design/DesignComponent.ts +3 -1
- package/src/classes/Design/DesignConstructor.ts +3 -1
- package/src/classes/Design/DesignConstructors.ts +3 -1
- package/src/classes/Design/DesignReplace.ts +3 -1
- package/src/classes/Design/DesignStructure.ts +3 -1
- package/src/classes/Design/DesignStructureClasses.ts +3 -1
- package/src/classes/Design/DesignStructureItemAbstract.ts +2 -0
- package/src/classes/Design/DesignStructureRead.ts +3 -1
- package/src/classes/Design/DesignStructureStyles.ts +2 -0
- package/src/classes/Design/DesignTypescript.ts +1 -1
- package/src/classes/Design/DesignUi.ts +3 -1
- package/src/classes/Design/DesignWiki.ts +3 -1
- package/src/classes/Git/GitRead.ts +258 -0
- package/src/classes/Library/LibraryExport.ts +3 -1
- package/src/classes/Library/LibraryFlags.ts +3 -1
- package/src/classes/Library/LibraryItems.ts +3 -1
- package/src/classes/Library/LibraryMedia.ts +3 -1
- package/src/classes/Package/PackageInit.ts +2 -0
- package/src/classes/Package/PackageItem.ts +2 -0
- package/src/classes/Properties/Properties.ts +3 -1
- package/src/classes/Properties/PropertiesCache.ts +3 -1
- package/src/classes/Properties/PropertiesConfig.ts +21 -0
- package/src/classes/Properties/PropertiesConvector.ts +3 -1
- package/src/classes/Properties/PropertiesFile.ts +11 -1
- package/src/classes/Properties/PropertiesImport.ts +3 -1
- package/src/classes/Properties/PropertiesItems.ts +3 -1
- package/src/classes/Properties/PropertiesKeys.ts +3 -1
- package/src/classes/Properties/PropertiesMain.ts +3 -1
- package/src/classes/Properties/PropertiesPalette.ts +3 -1
- package/src/classes/Properties/PropertiesPath.ts +3 -1
- package/src/classes/Properties/PropertiesScss.ts +3 -1
- package/src/classes/Properties/PropertiesSeparator.ts +3 -1
- package/src/classes/Properties/PropertiesSettings.ts +3 -1
- package/src/classes/Properties/PropertiesStandard.ts +3 -1
- package/src/classes/Properties/PropertiesTool.ts +3 -1
- package/src/classes/Properties/PropertiesTypes.ts +3 -1
- package/src/classes/Properties/PropertiesValues.ts +2 -0
- package/src/classes/Properties/PropertiesWrap.ts +3 -1
- package/src/classes/Properties/convector/convectorColor.ts +2 -0
- package/src/classes/Properties/convector/convectorFontFamilies.ts +2 -0
- package/src/classes/Properties/convector/convectorShadow.ts +3 -1
- package/src/classes/Properties/convector/convectorTypography.ts +3 -1
- package/src/classes/Properties/to/PropertiesToAbstract.ts +2 -0
- package/src/classes/Properties/to/PropertiesToAnimate.ts +3 -1
- package/src/classes/Properties/to/PropertiesToClass.ts +2 -0
- package/src/classes/Properties/to/PropertiesToClone.ts +3 -1
- package/src/classes/Properties/to/PropertiesToComponent.ts +2 -0
- package/src/classes/Properties/to/PropertiesToDrag.ts +3 -1
- package/src/classes/Properties/to/PropertiesToDuplicate.ts +3 -1
- package/src/classes/Properties/to/PropertiesToFull.ts +2 -0
- package/src/classes/Properties/to/PropertiesToLink.ts +6 -3
- package/src/classes/Properties/to/PropertiesToMedia.ts +3 -1
- package/src/classes/Properties/to/PropertiesToMulti.ts +3 -1
- package/src/classes/Properties/to/PropertiesToNone.ts +3 -1
- package/src/classes/Properties/to/PropertiesToPalette.ts +3 -1
- package/src/classes/Properties/to/PropertiesToProperty.ts +3 -1
- package/src/classes/Properties/to/PropertiesToRemove.ts +3 -1
- package/src/classes/Properties/to/PropertiesToReplace.ts +2 -0
- package/src/classes/Properties/to/PropertiesToRoot.ts +2 -0
- package/src/classes/Properties/to/PropertiesToSimilar.ts +3 -1
- package/src/classes/Properties/to/PropertiesToSort.ts +3 -1
- package/src/classes/Properties/to/PropertiesToState.ts +3 -1
- package/src/classes/Properties/to/PropertiesToStyle.ts +3 -1
- package/src/classes/Properties/to/PropertiesToSub.ts +2 -0
- package/src/classes/Properties/to/PropertiesToSubclass.ts +2 -0
- package/src/classes/Properties/to/PropertiesToVar.ts +3 -1
- package/src/classes/Properties/to/PropertiesToVariable.ts +3 -1
- package/src/classes/Styles/Styles.ts +3 -1
- package/src/classes/Styles/StylesClasses.ts +3 -1
- package/src/classes/Styles/StylesProperties.ts +2 -0
- package/src/classes/Styles/StylesRoot.ts +2 -0
- package/src/classes/Styles/StylesTool.ts +3 -1
- package/src/classes/Styles/to/StylesToAbstract.ts +3 -1
- package/src/classes/Styles/to/StylesToAnimate.ts +2 -0
- package/src/classes/Styles/to/StylesToClass.ts +2 -0
- package/src/classes/Styles/to/StylesToClassFull.ts +2 -0
- package/src/classes/Styles/to/StylesToContainer.ts +2 -0
- package/src/classes/Styles/to/StylesToMedia.ts +2 -0
- package/src/classes/Styles/to/StylesToProperty.ts +3 -1
- package/src/classes/Styles/to/StylesToRoot.ts +2 -0
- package/src/classes/Styles/to/StylesToSelector.ts +3 -1
- package/src/classes/Styles/to/StylesToVar.ts +3 -1
- package/src/classes/Styles/to/StylesToVirtual.ts +2 -0
- package/src/composables/useAi.ts +3 -0
- package/src/config.ts +11 -0
- package/src/functions/getComponentPaths.ts +2 -0
- package/src/functions/getConfigAi.ts +13 -0
- package/src/functions/getConstructorProperties.ts +3 -1
- package/src/functions/getNameDirByPaths.ts +2 -0
- package/src/functions/toPathStandardSep.ts +2 -0
- package/src/library-ai.ts +3 -0
- package/src/library.ts +2 -89
- package/src/media/ai/ai-doc-types.ts +21 -0
- package/src/media/properties/css.ts +4 -1
- package/src/media/properties/listSort.ts +1 -1
- package/src/media/properties/style.ts +2 -0
- package/src/media/templates/component/DesignComponent.vue +1 -1
- package/src/media/templates/constructors/ConstructorsDesign.tsx +4 -2
- package/src/media/templates/packages/library/package.json +2 -1
- package/src/media/templates/prompts/aiDocClassPrompt.en.txt +66 -0
- package/src/media/templates/prompts/aiDocClassPrompt.ru.txt +64 -0
- package/src/media/templates/prompts/aiDocComposablePrompt.en.txt +67 -0
- package/src/media/templates/prompts/aiDocComposablePrompt.ru.txt +67 -0
- package/src/media/templates/prompts/aiDocFunctionPrompt.en.txt +57 -0
- package/src/media/templates/prompts/aiDocFunctionPrompt.ru.txt +57 -0
- package/src/media/templates/prompts/componentPrompt.en.txt +105 -0
- package/src/media/templates/prompts/componentPrompt.ru.txt +105 -0
- package/src/media/templates/prompts/demoClassEn.mdx +111 -0
- package/src/media/templates/prompts/demoClassRu.mdx +111 -0
- package/src/media/templates/prompts/demoComponentEn.mdx +282 -0
- package/src/media/templates/prompts/demoComponentRu.mdx +282 -0
- package/src/media/templates/prompts/demoComposableEn.mdx +103 -0
- package/src/media/templates/prompts/demoComposableRu.mdx +103 -0
- package/src/media/templates/prompts/demoDocEn.mdx +30 -0
- package/src/media/templates/prompts/demoDocRu.mdx +30 -0
- package/src/media/templates/viteComponentTemplateConfig.ts +1 -1
- package/src/types/aiTypes.ts +19 -0
- package/src/types/configTypes.ts +8 -2
- package/src/types/gitTypes.ts +59 -0
- package/src/media/templates/componentPrompt.en.txt +0 -447
- package/src/media/templates/componentPrompt.ru.txt +0 -449
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { exec } from 'node:child_process'
|
|
2
|
+
import { AiAbstract } from './AiAbstract'
|
|
3
|
+
import { PropertiesFile } from '../Properties/PropertiesFile.ts'
|
|
4
|
+
import { forEach } from '@dxtmisha/functional-basic'
|
|
5
|
+
|
|
6
|
+
const TEMPORARY_DIR = './ai-tmp'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Google AI (Gemini) implementation via CLI.
|
|
10
|
+
* Uses system shell to execute Gemini CLI commands.
|
|
11
|
+
*
|
|
12
|
+
* Реализация Google AI (Gemini) через CLI.
|
|
13
|
+
* Использует системную оболочку для выполнения команд Gemini CLI.
|
|
14
|
+
*
|
|
15
|
+
* Responsibilities / Ответственности:
|
|
16
|
+
* - Construct CLI command / Сформировать CLI команду
|
|
17
|
+
* - Execute command via shell / Выполнить команду через оболочку
|
|
18
|
+
* - Return stdout as result / Вернуть stdout как результат
|
|
19
|
+
*
|
|
20
|
+
* Notes / Примечания:
|
|
21
|
+
* - Requires 'gemini' CLI tool installed / Требует установленной утилиты 'gemini'
|
|
22
|
+
* - API key is passed via environment variable or config / API ключ передается через переменную окружения или конфиг
|
|
23
|
+
*/
|
|
24
|
+
export class AiGoogleCliLite extends AiAbstract<{}> {
|
|
25
|
+
/**
|
|
26
|
+
* Counter for generating unique temporary file names/
|
|
27
|
+
* Счетчик для генерации уникальных имен временных файлов
|
|
28
|
+
*/
|
|
29
|
+
protected idFile = 1
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generates a unique file path for the temporary prompt.
|
|
33
|
+
*
|
|
34
|
+
* Генерирует уникальный путь к файлу для временного промпта.
|
|
35
|
+
*/
|
|
36
|
+
protected getFileName(): string {
|
|
37
|
+
return `${TEMPORARY_DIR}/Prompt-${this.idFile++}.txt`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the "client".
|
|
42
|
+
* For CLI, we just mark it as initialized.
|
|
43
|
+
*
|
|
44
|
+
* Инициализирует "клиента".
|
|
45
|
+
* Для CLI мы просто помечаем его как инициализированный.
|
|
46
|
+
*/
|
|
47
|
+
protected init(): void {
|
|
48
|
+
this.ai = {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Implementation hook: convert accumulated images to model-specific format.
|
|
53
|
+
* CLI implementation currently ignores images.
|
|
54
|
+
*
|
|
55
|
+
* Хук реализации: преобразовать накопленные изображения в формат, специфичный для модели.
|
|
56
|
+
* Реализация CLI в настоящее время игнорирует изображения.
|
|
57
|
+
*/
|
|
58
|
+
protected toImages(): any {
|
|
59
|
+
return []
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Implementation hook: convert accumulated contents to model-specific format.
|
|
64
|
+
* Returns array of strings.
|
|
65
|
+
*
|
|
66
|
+
* Хук реализации: преобразовать накопленное содержимое в формат, специфичный для модели.
|
|
67
|
+
* Возвращает массив строк.
|
|
68
|
+
*/
|
|
69
|
+
protected toContents(): any {
|
|
70
|
+
return forEach(
|
|
71
|
+
this.contents,
|
|
72
|
+
content => this.createFile(content)
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Performs content generation request via CLI and returns textual result.
|
|
78
|
+
*
|
|
79
|
+
* Выполняет запрос генерации контента через CLI и возвращает текстовый результат.
|
|
80
|
+
* @param model Model identifier / Идентификатор модели
|
|
81
|
+
* @param contents Composed contents for generation / Собранный контент для генерации
|
|
82
|
+
*/
|
|
83
|
+
protected async response(
|
|
84
|
+
model: string,
|
|
85
|
+
contents: string
|
|
86
|
+
): Promise<string> {
|
|
87
|
+
return new Promise((resolve) => {
|
|
88
|
+
const fullPrompt = [
|
|
89
|
+
...this.toContents(),
|
|
90
|
+
this.createFile(contents)
|
|
91
|
+
].join('\n\n##################\n\n')
|
|
92
|
+
|
|
93
|
+
const escapedPrompt = fullPrompt.replace(/"/g, '\\"')
|
|
94
|
+
const modelFlag = model ? ` --model "${model}"` : ''
|
|
95
|
+
const command = `gemini "${escapedPrompt}" Output strictly the code/answer. No preamble, no chatter, no reasoning ${modelFlag} --yolo`
|
|
96
|
+
|
|
97
|
+
exec(
|
|
98
|
+
command,
|
|
99
|
+
{
|
|
100
|
+
encoding: 'utf8',
|
|
101
|
+
env: {
|
|
102
|
+
...process.env,
|
|
103
|
+
GEMINI_API_KEY: this.key
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
(error, stdout, stderr) => {
|
|
107
|
+
if (error) {
|
|
108
|
+
console.error('Error executing Gemini CLI:', stderr || error.message)
|
|
109
|
+
resolve('')
|
|
110
|
+
} else {
|
|
111
|
+
resolve(stdout.trim())
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
this.removeFile()
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Creates a temporary file with the prompt content and returns the path formatted for the CLI.
|
|
122
|
+
*
|
|
123
|
+
* Создает временный файл с содержимым промпта и возвращает путь, отформатированный для CLI.
|
|
124
|
+
* @param content Prompt content / Содержимое промпта
|
|
125
|
+
* @returns Formatted file path (e.g., @./ai-tmp/Prompt-1.txt) / Отформатированный путь к файлу
|
|
126
|
+
*/
|
|
127
|
+
protected createFile(content: string): string {
|
|
128
|
+
const name = this.getFileName()
|
|
129
|
+
|
|
130
|
+
PropertiesFile.writeByPath(name, content)
|
|
131
|
+
|
|
132
|
+
return `Please read the following file as it contains the prompt instructions: @${name}`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Cleans up temporary files and directories.
|
|
137
|
+
*
|
|
138
|
+
* Очищает временные файлы и директории.
|
|
139
|
+
* @protected
|
|
140
|
+
*/
|
|
141
|
+
protected removeFile(): void {
|
|
142
|
+
PropertiesFile.removeDir(TEMPORARY_DIR)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { forEach } from '@dxtmisha/functional-basic'
|
|
2
|
+
import { AiAbstract } from './AiAbstract'
|
|
3
|
+
import { GoogleGenAI } from '@google/genai'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Google AI (Gemini) implementation of AiAbstract.
|
|
7
|
+
* Initializes GoogleGenAI client and performs text generation requests.
|
|
8
|
+
*
|
|
9
|
+
* Реализация Google AI (Gemini) поверх AiAbstract.
|
|
10
|
+
* Инициализирует клиент GoogleGenAI и выполняет запросы генерации текста.
|
|
11
|
+
*
|
|
12
|
+
* Responsibilities / Ответственности:
|
|
13
|
+
* - Provide API key / Предоставить API ключ
|
|
14
|
+
* - Initialize low-level client / Инициализировать низкоуровневый клиент
|
|
15
|
+
* - Call generateContent and extract plain text / Вызвать generateContent и извлечь текст
|
|
16
|
+
*
|
|
17
|
+
* Notes / Примечания:
|
|
18
|
+
* - Model must be set via setModel() before generate() / Модель нужно задать через setModel()
|
|
19
|
+
* - Returns empty string if response is missing / Возвращает пустую строку при отсутствии результата
|
|
20
|
+
*/
|
|
21
|
+
export class AiGoogleLite extends AiAbstract<GoogleGenAI> {
|
|
22
|
+
/**
|
|
23
|
+
* Initializes GoogleGenAI client instance.
|
|
24
|
+
*
|
|
25
|
+
* Инициализирует экземпляр клиента GoogleGenAI.
|
|
26
|
+
*/
|
|
27
|
+
protected init(): void {
|
|
28
|
+
this.ai = new GoogleGenAI({ apiKey: this.key })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Implementation hook: convert accumulated images to model-specific format.
|
|
33
|
+
*
|
|
34
|
+
* Хук реализации: преобразовать накопленные изображения в формат, специфичный для модели.
|
|
35
|
+
*/
|
|
36
|
+
protected toImages(): any {
|
|
37
|
+
return forEach(this.images, image => ({
|
|
38
|
+
inlineData: {
|
|
39
|
+
mimeType: image.mime,
|
|
40
|
+
data: image.base64
|
|
41
|
+
}
|
|
42
|
+
}))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected toContents(): any {
|
|
46
|
+
return forEach(this.contents, content => ({
|
|
47
|
+
text: content
|
|
48
|
+
}))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Performs content generation request and returns textual result.
|
|
53
|
+
*
|
|
54
|
+
* Выполняет запрос генерации контента и возвращает текстовый результат.
|
|
55
|
+
* @param model Model identifier / Идентификатор модели
|
|
56
|
+
* @param contents Composed contents for generation / Собранный контент для генерации
|
|
57
|
+
*/
|
|
58
|
+
protected async response(
|
|
59
|
+
model: string,
|
|
60
|
+
contents: string
|
|
61
|
+
): Promise<string> {
|
|
62
|
+
const response = await this.ai?.models.generateContent({
|
|
63
|
+
model,
|
|
64
|
+
contents: [
|
|
65
|
+
...this.toImages(),
|
|
66
|
+
{
|
|
67
|
+
parts: [
|
|
68
|
+
...this.toContents(),
|
|
69
|
+
{ text: contents }
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return response?.text ?? ''
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { promisify } from 'node:util'
|
|
2
|
+
import { exec } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
import { PropertiesFile } from './Properties/PropertiesFile'
|
|
5
|
+
import { ComponentWikiFile } from './Component/ComponentWikiFile'
|
|
6
|
+
|
|
7
|
+
import { UI_DIR_DIST_TEMPORARY, UI_FILE_NAME_VITE, UI_FILE_NAME_VITE_WORKERS } from '../config'
|
|
8
|
+
|
|
9
|
+
/** Template vite config file path / Путь к файлу шаблона vite-конфига */
|
|
10
|
+
const FILE_VITE_SAMPLE = [__dirname, '..', 'media', 'templates', 'viteComponentTemplateConfig.ts']
|
|
11
|
+
|
|
12
|
+
/** Async exec wrapper / Обёртка для асинхронного exec */
|
|
13
|
+
const execAsync = promisify(exec)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Builds a component using a temporary Vite config.
|
|
17
|
+
*
|
|
18
|
+
* Билдит компонент с использованием временного Vite-конфига.
|
|
19
|
+
*/
|
|
20
|
+
export class BuildItem {
|
|
21
|
+
/** Template vite config file / Файл шаблона vite-конфига */
|
|
22
|
+
protected readonly viteSample: ComponentWikiFile
|
|
23
|
+
|
|
24
|
+
/** Aggregated built code file / Файл агрегированного собранного кода */
|
|
25
|
+
protected readonly codeFile: ComponentWikiFile
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Constructor
|
|
29
|
+
* @param path component path / путь к компоненту
|
|
30
|
+
*/
|
|
31
|
+
constructor(
|
|
32
|
+
protected readonly path: string
|
|
33
|
+
) {
|
|
34
|
+
this.viteSample = new ComponentWikiFile(FILE_VITE_SAMPLE)
|
|
35
|
+
|
|
36
|
+
this.codeFile = new ComponentWikiFile([
|
|
37
|
+
...this.getPathTemporaryDist(),
|
|
38
|
+
'code.txt'
|
|
39
|
+
])
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns distribution temp directory path segments.
|
|
44
|
+
*
|
|
45
|
+
* Возвращает сегменты пути дистрибутива (temp).
|
|
46
|
+
*/
|
|
47
|
+
getPathTemporaryDist(): string[] {
|
|
48
|
+
return [
|
|
49
|
+
UI_DIR_DIST_TEMPORARY
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns aggregated built code content.
|
|
55
|
+
*
|
|
56
|
+
* Возвращает содержимое агрегированного собранного кода.
|
|
57
|
+
*/
|
|
58
|
+
getCode(): string {
|
|
59
|
+
return this.codeFile.read()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Removes temporary distribution directory.
|
|
64
|
+
*
|
|
65
|
+
* Удаляет временную директорию дистрибутива.
|
|
66
|
+
*/
|
|
67
|
+
removeDir(): void {
|
|
68
|
+
PropertiesFile.removeDir(this.getPathTemporaryDist())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Prepares temporary vite config, triggers build, then restores original.
|
|
73
|
+
*
|
|
74
|
+
* Готовит временный vite-конфиг, запускает билд, затем восстанавливает оригинал.
|
|
75
|
+
*/
|
|
76
|
+
async make(): Promise<boolean> {
|
|
77
|
+
this.saveViteConfig()
|
|
78
|
+
|
|
79
|
+
const vite = this.viteSample
|
|
80
|
+
.read()
|
|
81
|
+
.replace('[path]', this.path)
|
|
82
|
+
|
|
83
|
+
PropertiesFile.writeByPath(UI_FILE_NAME_VITE, vite)
|
|
84
|
+
|
|
85
|
+
const status = await this.run()
|
|
86
|
+
|
|
87
|
+
this.resetViteConfig()
|
|
88
|
+
this.readAndWriteALlFiles()
|
|
89
|
+
|
|
90
|
+
return status
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Saves existing vite config aside (rename) before custom build.
|
|
95
|
+
*
|
|
96
|
+
* Сохраняет существующий vite-конфиг (переименовывает) перед кастомным билдом.
|
|
97
|
+
*/
|
|
98
|
+
protected saveViteConfig() {
|
|
99
|
+
if (!PropertiesFile.is(UI_FILE_NAME_VITE_WORKERS)) {
|
|
100
|
+
PropertiesFile.rename(
|
|
101
|
+
UI_FILE_NAME_VITE,
|
|
102
|
+
UI_FILE_NAME_VITE_WORKERS
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Restores original vite config after build.
|
|
109
|
+
*
|
|
110
|
+
* Восстанавливает оригинальный vite-конфиг после билда.
|
|
111
|
+
*/
|
|
112
|
+
protected resetViteConfig() {
|
|
113
|
+
if (PropertiesFile.is(UI_FILE_NAME_VITE_WORKERS)) {
|
|
114
|
+
PropertiesFile.removeFile(UI_FILE_NAME_VITE)
|
|
115
|
+
PropertiesFile.rename(
|
|
116
|
+
UI_FILE_NAME_VITE_WORKERS,
|
|
117
|
+
UI_FILE_NAME_VITE
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reads built file content and wraps with header comment (file name).
|
|
124
|
+
*
|
|
125
|
+
* Читает содержимое собранного файла и оборачивает заголовком с именем файла.
|
|
126
|
+
* @param path relative built file path / относительный путь собранного файла
|
|
127
|
+
*/
|
|
128
|
+
protected readFile(path: string): string {
|
|
129
|
+
const pathFull = PropertiesFile.joinPath([...this.getPathTemporaryDist(), path])
|
|
130
|
+
const content = PropertiesFile.readFileOnly(pathFull)
|
|
131
|
+
|
|
132
|
+
return `
|
|
133
|
+
// File: ${path}
|
|
134
|
+
${content}
|
|
135
|
+
`.trim()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Aggregates all built files into a single code snapshot file.
|
|
140
|
+
*
|
|
141
|
+
* Агрегирует все собранные файлы в единый снимок кода.
|
|
142
|
+
*/
|
|
143
|
+
protected readAndWriteALlFiles(): void {
|
|
144
|
+
const list = PropertiesFile.readDirRecursive(this.getPathTemporaryDist())
|
|
145
|
+
const content: string[] = []
|
|
146
|
+
|
|
147
|
+
list.forEach((file) => {
|
|
148
|
+
content.push(this.readFile(file))
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
this.codeFile.write(content.join('\r\n'))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Runs build command (npm run build) capturing stdout/stderr.
|
|
156
|
+
*
|
|
157
|
+
* Запускает команду билда (npm run build), перехватывая stdout/stderr.
|
|
158
|
+
*/
|
|
159
|
+
protected async run(): Promise<boolean> {
|
|
160
|
+
try {
|
|
161
|
+
const { stdout, stderr } = await execAsync('npm run build')
|
|
162
|
+
|
|
163
|
+
console.info(stdout)
|
|
164
|
+
|
|
165
|
+
if (stderr) {
|
|
166
|
+
console.error('STD error', stderr)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return true
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('Error', error)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
}
|