@dxtmisha/scripts 0.6.3 → 0.7.6

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.
Files changed (121) hide show
  1. package/bin/ai-doc.ts +1 -3
  2. package/bin/build-functional.ts +5 -0
  3. package/bin/design-flags.ts +5 -0
  4. package/bin/design-wiki-storm.ts +9 -0
  5. package/package.json +14 -8
  6. package/src/classes/Ai/AiAbstract.ts +14 -1
  7. package/src/classes/Ai/AiGoogleLite.ts +2 -1
  8. package/src/classes/Build/__tests__/buildFunctional.test.ts +43 -0
  9. package/src/classes/Build/buildFunctional.ts +54 -0
  10. package/src/classes/Component/ComponentCreator.ts +1 -0
  11. package/src/classes/Component/ComponentItem.ts +15 -0
  12. package/src/classes/Component/ComponentWiki.ts +8 -0
  13. package/src/classes/Component/ComponentWikiFile.ts +2 -0
  14. package/src/classes/Component/__tests__/ComponentCreator.test.ts +71 -0
  15. package/src/classes/Component/__tests__/ComponentItem.test.ts +71 -0
  16. package/src/classes/Design/DesignCommand.ts +65 -10
  17. package/src/classes/Design/DesignComponent.ts +303 -39
  18. package/src/classes/Design/DesignConstructor.ts +49 -20
  19. package/src/classes/Design/DesignConstructors.ts +61 -2
  20. package/src/classes/Design/DesignFlags.ts +215 -0
  21. package/src/classes/Design/DesignReplace.ts +11 -7
  22. package/src/classes/Design/DesignStructure.ts +8 -6
  23. package/src/classes/Design/DesignStructureClasses.ts +8 -4
  24. package/src/classes/Design/DesignStructureItemAbstract.ts +11 -2
  25. package/src/classes/Design/DesignStructureRead.ts +8 -4
  26. package/src/classes/Design/DesignStructureStyles.ts +8 -4
  27. package/src/classes/Design/DesignTypes.ts +53 -28
  28. package/src/classes/Design/DesignTypescript.ts +11 -2
  29. package/src/classes/Design/DesignUi.ts +74 -4
  30. package/src/classes/Design/DesignWiki.ts +4 -6
  31. package/src/classes/Design/DesignWikiStorm.ts +94 -0
  32. package/src/classes/Design/DesignWikiStormItem.ts +246 -0
  33. package/src/classes/Git/GitRead.ts +1 -0
  34. package/src/classes/Git/__tests__/GitRead.test.ts +70 -0
  35. package/src/classes/Library/LibraryAiWiki.ts +127 -0
  36. package/src/classes/Library/LibraryAiWikiItem.ts +79 -0
  37. package/src/classes/Library/LibraryExport.ts +0 -2
  38. package/src/classes/Library/LibraryFlags.ts +9 -7
  39. package/src/classes/Library/LibraryItems.ts +22 -13
  40. package/src/classes/Library/LibraryList.ts +189 -0
  41. package/src/classes/Library/LibraryMedia.ts +22 -8
  42. package/src/classes/Library/LibraryPlugin.ts +73 -0
  43. package/src/classes/Library/LibraryTypes.ts +130 -0
  44. package/src/classes/Package/PackageInit.ts +12 -4
  45. package/src/classes/Package/PackageItem.ts +16 -5
  46. package/src/classes/Properties/Properties.ts +14 -3
  47. package/src/classes/Properties/PropertiesCache.ts +19 -20
  48. package/src/classes/Properties/PropertiesConfig.ts +46 -26
  49. package/src/classes/Properties/PropertiesConvector.ts +10 -6
  50. package/src/classes/Properties/PropertiesFile.ts +27 -31
  51. package/src/classes/Properties/PropertiesImport.ts +10 -7
  52. package/src/classes/Properties/PropertiesItems.ts +19 -12
  53. package/src/classes/Properties/PropertiesKeys.ts +15 -9
  54. package/src/classes/Properties/PropertiesMain.ts +13 -7
  55. package/src/classes/Properties/PropertiesPalette.ts +12 -6
  56. package/src/classes/Properties/PropertiesPath.ts +17 -11
  57. package/src/classes/Properties/PropertiesScss.ts +10 -8
  58. package/src/classes/Properties/PropertiesSeparator.ts +9 -11
  59. package/src/classes/Properties/PropertiesSettings.ts +8 -6
  60. package/src/classes/Properties/PropertiesStandard.ts +5 -6
  61. package/src/classes/Properties/PropertiesTool.ts +16 -9
  62. package/src/classes/Properties/PropertiesTypes.ts +12 -12
  63. package/src/classes/Properties/PropertiesValues.ts +14 -14
  64. package/src/classes/Properties/PropertiesWrap.ts +5 -6
  65. package/src/classes/Properties/convector/convectorColor.ts +5 -3
  66. package/src/classes/Properties/to/PropertiesToAbstract.ts +18 -4
  67. package/src/classes/Styles/Styles.ts +1 -0
  68. package/src/composables/__tests__/useAi.test.ts +75 -0
  69. package/src/config.ts +9 -0
  70. package/src/functions/__tests__/getComponentPaths.test.ts +19 -0
  71. package/src/functions/__tests__/getConfigAi.test.ts +26 -0
  72. package/src/functions/__tests__/getConstructorProperties.test.ts +51 -0
  73. package/src/functions/__tests__/getDirname.test.ts +31 -0
  74. package/src/functions/__tests__/getNameDirByPaths.test.ts +40 -0
  75. package/src/functions/__tests__/getPackageJson.test.ts +34 -0
  76. package/src/functions/__tests__/hasNativeDirname.test.ts +18 -0
  77. package/src/functions/__tests__/toPathStandardSep.test.ts +31 -0
  78. package/src/functions/getConfigAi.ts +3 -2
  79. package/src/functions/toPathStandardSep.ts +1 -1
  80. package/src/library-ai.ts +0 -1
  81. package/src/library.ts +10 -0
  82. package/src/media/properties/css.ts +3 -1
  83. package/src/media/templates/component/{DesignComponentWikiAi.vue → DesignComponentAiWiki.vue} +2 -2
  84. package/src/media/templates/component/props.ts +2 -3
  85. package/src/media/templates/component/styleToken.scss +1 -1
  86. package/src/media/templates/component/wiki.ts +6 -12
  87. package/src/media/templates/component/wikiData.ts +28 -0
  88. package/src/media/templates/constructors/props.ts +3 -4
  89. package/src/media/templates/packages/figma/README.md +1 -0
  90. package/src/media/templates/packages/figma/ai.sample.config.ts +2 -0
  91. package/src/media/templates/packages/figma/design.config.json +3 -0
  92. package/src/media/templates/packages/figma/index.html +12 -0
  93. package/src/media/templates/packages/figma/manifest.json +25 -0
  94. package/src/media/templates/packages/figma/package.json +37 -0
  95. package/src/media/templates/packages/figma/src/App.vue +9 -0
  96. package/src/media/templates/packages/figma/src/classes/_.gitignore.txt +1 -0
  97. package/src/media/templates/packages/figma/src/code.ts +16 -0
  98. package/src/media/templates/packages/figma/src/components/_.gitignore.txt +1 -0
  99. package/src/media/templates/packages/figma/src/composables/_.gitignore.txt +1 -0
  100. package/src/media/templates/packages/figma/src/functions/_.gitignore.txt +1 -0
  101. package/src/media/templates/packages/figma/src/library.ts +0 -0
  102. package/src/media/templates/packages/figma/src/main.ts +4 -0
  103. package/src/media/templates/packages/figma/src/media/_.gitignore.txt +1 -0
  104. package/src/media/templates/packages/figma/src/storybook/_.gitignore.txt +1 -0
  105. package/src/media/templates/packages/figma/src/types/_.gitignore.txt +1 -0
  106. package/src/media/templates/packages/figma/src/vite-env.d.ts +1 -0
  107. package/src/media/templates/packages/figma/tsconfig.app.json +12 -0
  108. package/src/media/templates/packages/figma/tsconfig.json +7 -0
  109. package/src/media/templates/packages/figma/tsconfig.node.json +8 -0
  110. package/src/media/templates/packages/figma/vite.config.ts +7 -0
  111. package/src/media/templates/packages/library/src/main.ts +1 -1
  112. package/src/media/templates/packages/project/design.config.json +3 -0
  113. package/src/media/templates/packages/project/index.html +1 -2
  114. package/src/media/templates/packages/project/public/_.gitignore.txt +0 -0
  115. package/src/media/templates/packages/project/src/main.ts +2 -1
  116. package/src/media/templates/packages/project/src/vite-env.d.ts +1 -0
  117. package/src/types/configTypes.ts +6 -0
  118. package/src/types/designTypes.ts +12 -0
  119. package/src/types/libraryTypes.ts +1 -1
  120. package/src/types/webTypes.ts +105 -0
  121. /package/src/media/templates/packages/{library/public/_.gitignore.txt → figma/src/config.ts} +0 -0
@@ -11,13 +11,11 @@ import {
11
11
  } from '../../config'
12
12
 
13
13
  /**
14
- * The DesignWiki class is responsible for managing and generating files
15
- * that contain descriptions of components for the wiki. It ensures that
16
- * the necessary files are created and initialized properly.
14
+ * Utility for managing and generating the central wiki configuration for the design system.
15
+ * It ensures that the primary registry for storybook arguments and component descriptions is correctly initialized and synchronized with the project's design configuration.
17
16
  *
18
- * Класс DesignWiki отвечает за управление и генерацию файлов,
19
- * содержащих описания компонентов для wiki. Он гарантирует, что
20
- * необходимые файлы создаются и инициализируются должным образом.
17
+ * Утилита для управления и генерации центральной конфигурации вики для дизайн-системы.
18
+ * Гарантирует, что основной реестр аргументов Storybook и описаний компонентов правильно инициализирован и синхронизирован с конфигурацией дизайна проекта.
21
19
  */
22
20
  export class DesignWiki {
23
21
  /**
@@ -0,0 +1,94 @@
1
+ import { toCamelCaseFirst } from '@dxtmisha/functional-basic'
2
+ import { getPackageJson } from '../../functions/getPackageJson'
3
+
4
+ import { PropertiesConfig } from '../Properties/PropertiesConfig'
5
+ import { PropertiesFile } from '../Properties/PropertiesFile'
6
+ import { LibraryItems } from '../Library/LibraryItems'
7
+ import { DesignWikiStormItem } from './DesignWikiStormItem'
8
+
9
+ import type { WebTypesTags, WebTypesVueJson } from '../../types/webTypes'
10
+
11
+ /**
12
+ * Engine for generating `web-types.json` to provide rich metadata and IDE support (IntelliSense) for the design system components in JetBrains editors (IntelliJ IDEA, WebStorm).
13
+ * It aggregates component tags, attributes, and events from the entire library and formats them into the standard Web-Types schema.
14
+ *
15
+ * Движок для генерации `web-types.json`, обеспечивающий расширенные метаданные и поддержку IDE (IntelliSense) для компонентов дизайн-системы в редакторах JetBrains (IntelliJ IDEA, WebStorm).
16
+ * Он агрегирует теги компонентов, атрибуты и события из всей библиотеки и форматирует их в стандартную схему Web-Types.
17
+ */
18
+ export class DesignWikiStorm {
19
+ protected readonly components: LibraryItems
20
+
21
+ /**
22
+ * Constructor for DesignWikiStorm.
23
+ *
24
+ * Конструктор для DesignWikiStorm.
25
+ * @param dir target directory for saving the `web-types.json` file / целевая директория для сохранения файла `web-types.json`
26
+ */
27
+ constructor(
28
+ protected dir: string = 'dist'
29
+ ) {
30
+ this.components = new LibraryItems()
31
+ }
32
+
33
+ /**
34
+ * Generates the web-types.json file.
35
+ *
36
+ * Генерирует файл web-types.json.
37
+ */
38
+ async make(): Promise<void> {
39
+ const packageFile = getPackageJson()
40
+
41
+ console.log('[DesignWikiStorm] make')
42
+
43
+ if (packageFile) {
44
+ const data: WebTypesVueJson = {
45
+ $schema: 'https://json.schemastore.org/web-types',
46
+ framework: 'vue',
47
+ name: toCamelCaseFirst(PropertiesConfig.getDesignName()),
48
+ version: packageFile.version,
49
+ contributions: {
50
+ html: {
51
+ 'types-syntax': 'typescript',
52
+ 'description-markup': 'markdown',
53
+ 'tags': await this.getComponents()
54
+ }
55
+ }
56
+ }
57
+
58
+ PropertiesFile.writeByPath(
59
+ [this.dir, 'web-types.json'],
60
+ data
61
+ )
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Creates or updates the list of components.
67
+ *
68
+ * Создает или обновляет список компонентов.
69
+ */
70
+ protected async getComponents(): Promise<WebTypesTags> {
71
+ const packageFile = getPackageJson()
72
+ const tags: WebTypesTags = []
73
+
74
+ if (packageFile) {
75
+ for (const component of this.components.getComponentList()) {
76
+ const item = new DesignWikiStormItem(
77
+ packageFile.name,
78
+ this.components.getComponentsPath(),
79
+ component
80
+ )
81
+
82
+ await item.init()
83
+
84
+ const tag = await item.get()
85
+
86
+ if (tag) {
87
+ tags.push(tag)
88
+ }
89
+ }
90
+ }
91
+
92
+ return tags
93
+ }
94
+ }
@@ -0,0 +1,246 @@
1
+ import { toCamelCaseFirst } from '@dxtmisha/functional'
2
+ import { type WikiDataItem, WikiStorybook, WikiStorybookProp } from '@dxtmisha/wiki'
3
+ import { wiki, wikiDescriptions } from '@dxtmisha/wiki/media'
4
+
5
+ import { PropertiesConfig } from '../Properties/PropertiesConfig'
6
+ import { PropertiesFile } from '../Properties/PropertiesFile'
7
+
8
+ import type { LibraryData } from '../../types/libraryTypes'
9
+ import type { WebTypesAttributeItem, WebTypesAttributes, WebTypesEvents, WebTypesSlots, WebTypesTagItem } from '../../types/webTypes'
10
+
11
+ /**
12
+ * Resolver for extracting and formatting IDE metadata for a specific component.
13
+ * It coordinates the transformation of Storybook-specific wiki data into JetBrains Web-Types tag and attribute definitions.
14
+ *
15
+ * Резолвер для извлечения и форматирования метаданных IDE для конкретного компонента.
16
+ * Координирует преобразование данных вики для Storybook в определения тегов и атрибутов JetBrains Web-Types.
17
+ */
18
+ export class DesignWikiStormItem {
19
+ protected wiki?: WikiStorybook
20
+ protected dataComponent?: WikiDataItem
21
+
22
+ /**
23
+ * Constructor for DesignWikiStormItem.
24
+ *
25
+ * Конструктор для DesignWikiStormItem.
26
+ * @param project name of the project for module mapping / имя проекта для маппинга модулей
27
+ * @param path array of directory path segments to the component / массив сегментов пути к директории компонента
28
+ * @param data component metadata from the library / метаданные компонента из библиотеки
29
+ */
30
+ constructor(
31
+ protected readonly project: string,
32
+ protected readonly path: string[],
33
+ protected readonly data: LibraryData
34
+ ) {
35
+ }
36
+
37
+ /**
38
+ * Returns the tag definition for web-types.
39
+ *
40
+ * Возвращает определение тега для web-types.
41
+ */
42
+ async get(): Promise<WebTypesTagItem | undefined> {
43
+ if (this.wiki) {
44
+ const name = `${toCamelCaseFirst(PropertiesConfig.getDesignName())}${this.wiki.getName()}`
45
+
46
+ const tag: WebTypesTagItem = {
47
+ name,
48
+ description: this.wiki.getDescription(),
49
+ source: {
50
+ module: `${this.project}/${name}`,
51
+ symbol: name
52
+ },
53
+ attributes: this.getAttributes()
54
+ }
55
+
56
+ const slots = await this.getSlots()
57
+
58
+ if (slots) {
59
+ tag.slots = slots
60
+ }
61
+
62
+ const events = await this.getEvents()
63
+
64
+ if (events) {
65
+ tag.events = events
66
+ }
67
+
68
+ return tag
69
+ }
70
+
71
+ return undefined
72
+ }
73
+
74
+ /**
75
+ * Returns the attribute definition.
76
+ *
77
+ * Возвращает определение атрибута.
78
+ * @param item prop item / элемент свойства
79
+ */
80
+ getAttribute(item: WikiStorybookProp): WebTypesAttributeItem {
81
+ return {
82
+ name: item.getName(),
83
+ description: item.getDescription(),
84
+ default: item.getDefaultValue(),
85
+ value: {
86
+ kind: 'expression',
87
+ type: item.getType()
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Returns a list of attributes.
94
+ *
95
+ * Возвращает список атрибутов.
96
+ */
97
+ getAttributes(): WebTypesAttributes {
98
+ const attributes: WebTypesAttributes = []
99
+
100
+ if (this.wiki) {
101
+ this.wiki.getWikiObject()
102
+ .forEach(
103
+ props => attributes.push(this.getAttribute(props))
104
+ )
105
+ }
106
+
107
+ return attributes
108
+ }
109
+
110
+ /**
111
+ * Returns a list of slots.
112
+ *
113
+ * Возвращает список слотов.
114
+ */
115
+ async getSlots(): Promise<WebTypesSlots | undefined> {
116
+ const data = await this.getData()
117
+
118
+ if (data && data.slots) {
119
+ const slots: WebTypesSlots = []
120
+
121
+ data.slots.forEach(
122
+ props => slots.push({
123
+ name: props.name,
124
+ description: props.description,
125
+ 'vue-properties': props.properties ?? []
126
+ })
127
+ )
128
+
129
+ return slots
130
+ }
131
+
132
+ return undefined
133
+ }
134
+
135
+ /**
136
+ * Returns a list of events.
137
+ *
138
+ * Возвращает список событий.
139
+ */
140
+ async getEvents(): Promise<WebTypesEvents | undefined> {
141
+ const data = await this.getData()
142
+
143
+ if (data && data.events) {
144
+ const events: WebTypesEvents = []
145
+
146
+ data.events.forEach(
147
+ event => events.push({
148
+ name: event.name,
149
+ description: event.description,
150
+ arguments: event.properties ?? []
151
+ })
152
+ )
153
+
154
+ return events
155
+ }
156
+
157
+ return undefined
158
+ }
159
+
160
+ /**
161
+ * Returns the directory name.
162
+ *
163
+ * Возвращает имя директории.
164
+ */
165
+ getDirName() {
166
+ return this.data.dir
167
+ }
168
+
169
+ /**
170
+ * Initializes the class.
171
+ *
172
+ * Инициализирует класс.
173
+ */
174
+ async init(): Promise<this> {
175
+ this.wiki = await this.initWiki()
176
+ return this
177
+ }
178
+
179
+ /**
180
+ * Gets data from wikiData.ts.
181
+ *
182
+ * Получает данные из wikiData.ts.
183
+ */
184
+ protected async getData(): Promise<WikiDataItem | undefined> {
185
+ if (!this.dataComponent) {
186
+ const filePath = this.getPaths(['wikiData.ts'])
187
+
188
+ if (PropertiesFile.is(filePath)) {
189
+ const wiki: Record<string, any> = await import(filePath.join('/'))
190
+ const data: WikiDataItem | undefined = Object.values(wiki).find(item => 'component' in item)
191
+
192
+ this.dataComponent = data
193
+ }
194
+ }
195
+
196
+ return this.dataComponent
197
+ }
198
+
199
+ /**
200
+ * Returns the list of directories.
201
+ *
202
+ * Возвращает список директорий.
203
+ */
204
+ protected getDirs(): string[] {
205
+ return [
206
+ '.',
207
+ ...this.path,
208
+ this.getDirName()
209
+ ]
210
+ }
211
+
212
+ /**
213
+ * Returns the full path to the file.
214
+ *
215
+ * Возвращает полный путь к файлу.
216
+ * @param paths path segments / сегменты пути
217
+ */
218
+ protected getPaths(paths: string[]): string[] {
219
+ return [
220
+ ...this.getDirs(),
221
+ ...paths
222
+ ]
223
+ }
224
+
225
+ /**
226
+ * Initializes the wiki object.
227
+ *
228
+ * Инициализирует объект wiki.
229
+ */
230
+ protected async initWiki(): Promise<WikiStorybook | undefined> {
231
+ const data = await this.getData()
232
+
233
+ if (data) {
234
+ return new WikiStorybook(
235
+ data.component,
236
+ data.props,
237
+ data.defaults,
238
+ data.wikiDesign,
239
+ wiki,
240
+ wikiDescriptions
241
+ )
242
+ }
243
+
244
+ return undefined
245
+ }
246
+ }
@@ -253,6 +253,7 @@ export class GitRead {
253
253
  *
254
254
  * Выполняет Git команду и возвращает результат.
255
255
  * @param command - command to execute / команда для выполнения
256
+ * @protected
256
257
  */
257
258
  protected static exec(command: string): string {
258
259
  return execSync(command, { encoding: 'utf8' }).trim()
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it, vi, beforeEach } from 'vitest'
2
+ import { GitRead } from '../GitRead'
3
+ import { execSync } from 'node:child_process'
4
+ import { PropertiesFile } from '../../Properties/PropertiesFile'
5
+
6
+ vi.mock('node:child_process', () => ({
7
+ execSync: vi.fn()
8
+ }))
9
+
10
+ vi.mock('../../Properties/PropertiesFile', () => ({
11
+ PropertiesFile: {
12
+ getTime: vi.fn()
13
+ }
14
+ }))
15
+
16
+ describe('GitRead', () => {
17
+ beforeEach(() => {
18
+ vi.clearAllMocks()
19
+ })
20
+
21
+ it('getDirPrefix should return the result of git rev-parse', () => {
22
+ vi.mocked(execSync).mockReturnValue('packages/scripts/' as any)
23
+ const result = GitRead.getDirPrefix()
24
+ expect(execSync).toHaveBeenCalledWith('git rev-parse --show-prefix', expect.anything())
25
+ expect(result).toBe('packages/scripts/')
26
+ })
27
+
28
+ it('getFilesPath should return list of HEAD files', () => {
29
+ vi.mocked(execSync).mockReturnValue('file1.ts\nfile2.ts\n' as any)
30
+ const result = GitRead.getFilesPath()
31
+ expect(result).toEqual(['file1.ts', 'file2.ts'])
32
+ })
33
+
34
+ it('getList should return files with metadata', () => {
35
+ vi.mocked(execSync).mockImplementation((cmd: string) => {
36
+ if (cmd.startsWith('git rev-parse')) return 'prefix/' as any
37
+ if (cmd.startsWith('git ls-tree')) return 'file.ts\n' as any
38
+ if (cmd.startsWith('git log')) return '2023-10-27 12:00:00 +0300' as any
39
+ return '' as any
40
+ })
41
+
42
+ const result = GitRead.getList()
43
+ expect(result[0]).toMatchObject({
44
+ path: 'file.ts',
45
+ pathFull: 'prefix/file.ts',
46
+ date: expect.stringContaining('2023-10-27')
47
+ })
48
+ })
49
+
50
+ it('getListPorcelain should parse git status and metadata', () => {
51
+ vi.mocked(execSync).mockImplementation((cmd: string) => {
52
+ if (cmd.startsWith('git rev-parse')) return 'prefix/' as any
53
+ if (cmd.startsWith('git status')) return 'M file.ts\nA new.ts\n' as any
54
+ return '' as any
55
+ })
56
+ vi.mocked(PropertiesFile.getTime).mockReturnValue('2023-10-27 12:00:00' as any)
57
+
58
+ const result = GitRead.getListPorcelain()
59
+ expect(result).toHaveLength(2)
60
+ expect(result[0]).toMatchObject({
61
+ path: 'file.ts',
62
+ status: 'M'
63
+ })
64
+ })
65
+
66
+ it('splitPath should correctly split string', () => {
67
+ expect(GitRead.splitPath('a/b/c')).toEqual(['a', 'b', 'c'])
68
+ expect(GitRead.splitPath('/a/b/')).toEqual(['a', 'b'])
69
+ })
70
+ })
@@ -0,0 +1,127 @@
1
+ import { PropertiesFile } from '../Properties/PropertiesFile'
2
+ import { LibraryItems } from './LibraryItems'
3
+ import { LibraryAiWikiItem } from './LibraryAiWikiItem'
4
+
5
+ import { UI_DIRS_COMPONENTS } from '../../config'
6
+
7
+ /**
8
+ * Class for creating a list of components for AI Wiki.
9
+ *
10
+ * Класс для создания списка компонентов для AI Wiki.
11
+ */
12
+ export class LibraryAiWiki {
13
+ /**
14
+ * Constructor
15
+ * @param items object for working with the list of components / объект для работы со списком компонентов
16
+ */
17
+ constructor(
18
+ protected readonly items: LibraryItems
19
+ ) {
20
+ }
21
+
22
+ /**
23
+ * Creates files for AI Wiki.
24
+ *
25
+ * Создает файлы для AI Wiki.
26
+ */
27
+ make(): void {
28
+ this.makeList()
29
+ this.makeComponent()
30
+ }
31
+
32
+ /**
33
+ * Returns the file name for the list.
34
+ *
35
+ * Возвращает имя файла для списка.
36
+ */
37
+ protected getFileList(): string {
38
+ return 'ai-list'
39
+ }
40
+
41
+ /**
42
+ * Returns a list of components for AI Wiki.
43
+ *
44
+ * Возвращает список компонентов для AI Wiki.
45
+ */
46
+ protected getList(): LibraryAiWikiItem[] {
47
+ const data: LibraryAiWikiItem[] = []
48
+
49
+ this.items.getComponentList()
50
+ .forEach((component) => {
51
+ const aiWiki = new LibraryAiWikiItem(component)
52
+
53
+ if (aiWiki.isAiWiki()) {
54
+ data.push(aiWiki)
55
+ }
56
+ })
57
+
58
+ return data
59
+ }
60
+
61
+ /**
62
+ * Creates a file with a list of components.
63
+ *
64
+ * Создает файл со списком компонентов.
65
+ */
66
+ protected makeList(): void {
67
+ const data = this.getList()
68
+ const imports: string[] = []
69
+ const list: string[] = []
70
+
71
+ console.log('Ai wiki:', data.length, 'components')
72
+
73
+ data.forEach((item) => {
74
+ imports.push(item.getImport())
75
+ list.push(` ${item.getCode()}`)
76
+ })
77
+
78
+ this.items.write(
79
+ this.getFileList(),
80
+ [
81
+ ...imports,
82
+ '',
83
+ 'export const aiList: any[] = [',
84
+ list.join(',\r\n'),
85
+ ']'
86
+ ],
87
+ 'wiki.ts'
88
+ )
89
+ }
90
+
91
+ /**
92
+ * Creates a component for displaying the list.
93
+ *
94
+ * Создает компонент для отображения списка.
95
+ */
96
+ protected makeComponent() {
97
+ PropertiesFile.writeByPath(
98
+ [...UI_DIRS_COMPONENTS, 'AiWiki.vue'],
99
+ `<script setup lang="ts">
100
+ // This file is generated by a script, do not edit.
101
+
102
+ import { DxtTestPage, DxtTestWikiAnchor, DxtTestWikiHide } from '@dxtmisha/test'
103
+ import { aiList } from '../library/${this.getFileList()}.wiki'
104
+
105
+ defineOptions({
106
+ name: 'AiWiki'
107
+ })
108
+ </script>
109
+
110
+ <template>
111
+ <DxtTestPage
112
+ title="List of available UI components"
113
+ description="Below is a list of Vue 3 components available in the UI. These components are available immediately and do not need to be imported."
114
+ >
115
+ <DxtTestWikiHide/>
116
+ <DxtTestWikiAnchor :list="aiList"/>
117
+ <component
118
+ v-for="(item, key) in aiList"
119
+ :key="key"
120
+ :is="item"
121
+ />
122
+ </DxtTestPage>
123
+ </template>
124
+ `
125
+ )
126
+ }
127
+ }
@@ -0,0 +1,79 @@
1
+ import type { LibraryData } from '../../types/libraryTypes'
2
+
3
+ import { PropertiesConfig } from '../Properties/PropertiesConfig'
4
+ import { PropertiesFile } from '../Properties/PropertiesFile'
5
+
6
+ import { UI_DIRS_COMPONENTS } from '../../config'
7
+
8
+ /**
9
+ * Class for working with the AI Wiki component.
10
+ *
11
+ * Класс для работы с компонентом AI Wiki.
12
+ */
13
+ export class LibraryAiWikiItem {
14
+ /**
15
+ * Constructor
16
+ * @param item component data / данные компонента
17
+ */
18
+ constructor(
19
+ protected readonly item: LibraryData
20
+ ) {
21
+ }
22
+
23
+ /**
24
+ * Checks if the AI Wiki file exists.
25
+ *
26
+ * Проверяет, существует ли файл AI Wiki.
27
+ */
28
+ isAiWiki(): boolean {
29
+ return PropertiesFile.is(this.getPath())
30
+ }
31
+
32
+ /**
33
+ * Returns the component code.
34
+ *
35
+ * Возвращает код компонента.
36
+ */
37
+ getCode(): string {
38
+ return this.item.codeFull
39
+ }
40
+
41
+ /**
42
+ * Returns the file name for the AI Wiki component.
43
+ *
44
+ * Возвращает имя файла для компонента AI Wiki.
45
+ */
46
+ getComponentFileNameAiWiki(): string {
47
+ return `${this.item.codeFull}AiWiki.vue`
48
+ }
49
+
50
+ /**
51
+ * Returns the import string for the component.
52
+ *
53
+ * Возвращает строку импорта для компонента.
54
+ */
55
+ getImport(): string {
56
+ const code = this.item.codeFull
57
+ const path: string[] = [
58
+ '..',
59
+ '..',
60
+ ...this.getPath()
61
+ ]
62
+
63
+ return `import ${code} from '${path.join('/')}'`
64
+ }
65
+
66
+ /**
67
+ * Returns the path to the file.
68
+ *
69
+ * Возвращает путь к файлу.
70
+ */
71
+ protected getPath(): string[] {
72
+ return [
73
+ ...UI_DIRS_COMPONENTS,
74
+ PropertiesConfig.getProjectName(),
75
+ this.item.dir,
76
+ this.getComponentFileNameAiWiki()
77
+ ]
78
+ }
79
+ }
@@ -1,5 +1,3 @@
1
- // export:none
2
-
3
1
  import { PropertiesFile } from '../Properties/PropertiesFile'
4
2
 
5
3
  import type { LibraryFiles } from '../../types/libraryTypes'
@@ -8,24 +8,26 @@ import { LibraryItems } from './LibraryItems'
8
8
  import { UI_FILE_NAME_FLAGS } from '../../config'
9
9
 
10
10
  /**
11
- * Class for generating a file to connect flags.
11
+ * Class for generating connection files for country flags and providing a list of flag identifiers.
12
12
  *
13
- * Класс для формирования файла для подключения флагов.
13
+ * Класс для формирования файлов подключения флагов стран и предоставления списка идентификаторов флагов.
14
14
  */
15
15
  export class LibraryFlags {
16
16
  /**
17
- * Constructor
18
- * @param items object for working with the list of components/ объект для работы со списком компонентов
17
+ * Constructor for LibraryFlags.
18
+ *
19
+ * Конструктор для LibraryFlags.
20
+ * @param items object for working with the list of components / объект для работы со списком компонентов
19
21
  */
20
-
21
22
  constructor(
22
23
  protected readonly items: LibraryItems
23
24
  ) {
24
25
  }
25
26
 
26
27
  /**
27
- * Adds a file with flags.<br>
28
- * Добавляет файл с флагами.
28
+ * Generates flag connection files (TypeScript) and a list of flag keys (JSON).
29
+ *
30
+ * Генерирует файлы подключения флагов (TypeScript) и список ключей флагов (JSON).
29
31
  */
30
32
  make(): void {
31
33
  const data: string[] = []