@dxtmisha/scripts 0.9.1 → 0.10.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.json +2 -1
  3. package/src/classes/Ai/AiClaudeAgent.ts +16 -0
  4. package/src/classes/Ai/AiClaudeAgentLite.ts +86 -0
  5. package/src/classes/Ai/AiClaudeCliLite.ts +29 -65
  6. package/src/classes/Ai/AiClaudeLite.ts +19 -7
  7. package/src/classes/Ai/AiGoogleCliLite.ts +27 -64
  8. package/src/classes/Ai/AiOpenAi.ts +26 -0
  9. package/src/classes/Ai/AiOpenAiLite.ts +107 -0
  10. package/src/classes/Ai/AiZAi.ts +17 -0
  11. package/src/classes/Ai/AiZAiLite.ts +26 -0
  12. package/src/classes/Ai/ApiTmp.ts +43 -0
  13. package/src/classes/Build/BuildPackages.ts +33 -7
  14. package/src/classes/Design/DesignComponent.ts +1 -1
  15. package/src/classes/Library/LibraryAiPromptItem.ts +36 -2
  16. package/src/composables/useAi.ts +15 -0
  17. package/src/config.ts +2 -0
  18. package/src/demo/ai.ts +10 -0
  19. package/src/library-ai.ts +4 -4
  20. package/src/library.ts +67 -54
  21. package/src/media/templates/componentDoc/wiki/prompt.txt +7 -2
  22. package/src/media/templates/prompts/aiCodeGlobalPrompt.en.txt +19 -0
  23. package/src/media/templates/prompts/aiCodeGlobalPrompt.ru.txt +21 -0
  24. package/src/types/configTypes.ts +9 -2
  25. package/src/classes/Component/__tests__/ComponentCreator.test.ts +0 -71
  26. package/src/classes/Component/__tests__/ComponentItem.test.ts +0 -71
  27. package/src/classes/Git/__tests__/GitRead.test.ts +0 -70
  28. package/src/composables/__tests__/useAi.test.ts +0 -75
  29. package/src/functions/__tests__/getComponentPaths.test.ts +0 -19
  30. package/src/functions/__tests__/getConfigAi.test.ts +0 -26
  31. package/src/functions/__tests__/getConstructorProperties.test.ts +0 -51
  32. package/src/functions/__tests__/getDirname.test.ts +0 -31
  33. package/src/functions/__tests__/getNameDirByPaths.test.ts +0 -40
  34. package/src/functions/__tests__/getPackageJson.test.ts +0 -34
  35. package/src/functions/__tests__/hasNativeDirname.test.ts +0 -18
  36. package/src/functions/__tests__/toPathStandardSep.test.ts +0 -31
@@ -1,70 +0,0 @@
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
- })
@@ -1,75 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { useAi } from '../useAi'
3
- import { PropertiesConfig } from '../../classes/Properties/PropertiesConfig'
4
- import { AiGoogle } from '../../classes/Ai/AiGoogle'
5
- import { AiGoogleCli } from '../../classes/Ai/AiGoogleCli'
6
-
7
- vi.mock('../../classes/Properties/PropertiesConfig', () => ({
8
- PropertiesConfig: {
9
- getAiType: vi.fn()
10
- }
11
- }))
12
-
13
- vi.mock('../../classes/Ai/AiGoogle', () => {
14
- return {
15
- AiGoogle: vi.fn().mockImplementation(function () {
16
- return { name: 'AiGoogleInstance' }
17
- })
18
- }
19
- })
20
-
21
- vi.mock('../../classes/Ai/AiGoogleCli', () => {
22
- return {
23
- AiGoogleCli: vi.fn().mockImplementation(function () {
24
- return { name: 'AiGoogleCliInstance' }
25
- })
26
- }
27
- })
28
-
29
- describe('useAi', () => {
30
- beforeEach(() => {
31
- vi.clearAllMocks()
32
- })
33
-
34
- it('should return an instance of AiGoogle when the type is gemini', () => {
35
- vi.mocked(PropertiesConfig.getAiType).mockReturnValue('gemini')
36
- const mockInstance = { name: 'AiGoogleInstance' }
37
- vi.mocked(AiGoogle).mockImplementation(function () {
38
- return mockInstance as any
39
- })
40
-
41
- const result = useAi()
42
-
43
- expect(result).toEqual(mockInstance)
44
- expect(AiGoogle).toHaveBeenCalled()
45
- })
46
-
47
- it('should return an instance of AiGoogleCli when the type is gemini-cli', () => {
48
- vi.mocked(PropertiesConfig.getAiType).mockReturnValue('gemini-cli')
49
- const mockInstance = { name: 'AiGoogleCliInstance' }
50
- vi.mocked(AiGoogleCli).mockImplementation(function () {
51
- return mockInstance as any
52
- })
53
-
54
- const result = useAi()
55
-
56
- expect(result).toEqual(mockInstance)
57
- expect(AiGoogleCli).toHaveBeenCalled()
58
- })
59
-
60
- it('should return undefined for an unknown type', () => {
61
- vi.mocked(PropertiesConfig.getAiType).mockReturnValue('unknown' as any)
62
-
63
- const result = useAi()
64
-
65
- expect(result).toBeUndefined()
66
- })
67
-
68
- it('should return undefined if no type is configured', () => {
69
- vi.mocked(PropertiesConfig.getAiType).mockReturnValue(undefined as any)
70
-
71
- const result = useAi()
72
-
73
- expect(result).toBeUndefined()
74
- })
75
- })
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { getComponentPaths } from '../getComponentPaths'
3
- import { UI_DIRS_COMPONENTS } from '../../config'
4
-
5
- describe('getComponentPaths', () => {
6
- it('should return an array containing UI_DIRS_COMPONENTS and the given path', () => {
7
- const path = 'test-component'
8
- const result = getComponentPaths(path)
9
-
10
- expect(result).toEqual([...UI_DIRS_COMPONENTS, path])
11
- })
12
-
13
- it('it should work with nested paths', () => {
14
- const path = 'nested/test-component'
15
- const result = getComponentPaths(path)
16
-
17
- expect(result).toEqual([...UI_DIRS_COMPONENTS, path])
18
- })
19
- })
@@ -1,26 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest'
2
- import { getConfigAi } from '../getConfigAi'
3
- import { PropertiesConfig } from '../../classes/Properties/PropertiesConfig'
4
-
5
- vi.mock('../../classes/Properties/PropertiesConfig', () => ({
6
- PropertiesConfig: {
7
- getAiKey: vi.fn(),
8
- getAiModel: vi.fn()
9
- }
10
- }))
11
-
12
- describe('getConfigAi', () => {
13
- it('should return AI key and model from PropertiesConfig', () => {
14
- const mockKey = 'test-key'
15
- const mockModel = 'test-model'
16
-
17
- vi.mocked(PropertiesConfig.getAiKey).mockReturnValue(mockKey)
18
- vi.mocked(PropertiesConfig.getAiModel).mockReturnValue(mockModel)
19
-
20
- const result = getConfigAi()
21
-
22
- expect(result).toEqual([mockKey, mockModel])
23
- expect(PropertiesConfig.getAiKey).toHaveBeenCalled()
24
- expect(PropertiesConfig.getAiModel).toHaveBeenCalled()
25
- })
26
- })
@@ -1,51 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { getConstructorProperties } from '../getConstructorProperties'
3
- import { PropertiesFile } from '../../classes/Properties/PropertiesFile'
4
- import { hasNativeDirname } from '../hasNativeDirname'
5
-
6
- vi.mock('../../classes/Properties/PropertiesFile', () => ({
7
- PropertiesFile: {
8
- readFile: vi.fn()
9
- }
10
- }))
11
-
12
- vi.mock('../hasNativeDirname', () => ({
13
- hasNativeDirname: vi.fn()
14
- }))
15
-
16
- describe('getConstructorProperties', () => {
17
- beforeEach(() => {
18
- vi.clearAllMocks()
19
- })
20
-
21
- it('should return properties for given constructor names', () => {
22
- const mockItem = { some: 'property' }
23
- vi.mocked(hasNativeDirname).mockReturnValue(true)
24
- vi.mocked(PropertiesFile.readFile).mockReturnValue(mockItem)
25
-
26
- const result = getConstructorProperties(['Button', 'Input'])
27
-
28
- expect(result).toEqual({
29
- Button: mockItem,
30
- Input: mockItem
31
- })
32
- expect(PropertiesFile.readFile).toHaveBeenCalledTimes(2)
33
- })
34
-
35
- it('should return an empty object if no constructors found or error occurs', () => {
36
- vi.mocked(hasNativeDirname).mockReturnValue(true)
37
- vi.mocked(PropertiesFile.readFile).mockReturnValue(undefined)
38
-
39
- const result = getConstructorProperties(['NonExistent'])
40
-
41
- expect(result).toEqual({})
42
- })
43
-
44
- it('should handles non-native dirname environment', () => {
45
- vi.mocked(hasNativeDirname).mockReturnValue(false)
46
- vi.mocked(PropertiesFile.readFile).mockReturnValue({ status: 'ok' })
47
-
48
- const result = getConstructorProperties(['Button'])
49
- expect(result).toEqual({ Button: { status: 'ok' } })
50
- })
51
- })
@@ -1,31 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { getDirname } from '../getDirname'
3
- import { hasNativeDirname } from '../hasNativeDirname'
4
-
5
- vi.mock('../hasNativeDirname', () => ({
6
- hasNativeDirname: vi.fn()
7
- }))
8
-
9
- // We can't easily mock import.meta.url or __dirname globally in a way that affects the module internally without ESM tricks,
10
- // but we can at least test that it calls the right path based on hasNativeDirname
11
- describe('getDirname', () => {
12
- beforeEach(() => {
13
- vi.clearAllMocks()
14
- })
15
-
16
- it('should return __dirname when hasNativeDirname is true', () => {
17
- vi.mocked(hasNativeDirname).mockReturnValue(true)
18
-
19
- // In a vitest environment with native support, __dirname should be defined
20
- // We expect it to not throw and return a string
21
- const result = getDirname()
22
- expect(typeof result).toBe('string')
23
- })
24
-
25
- it('should return a path via fileURLToPath when hasNativeDirname is false', () => {
26
- vi.mocked(hasNativeDirname).mockReturnValue(false)
27
-
28
- const result = getDirname()
29
- expect(typeof result).toBe('string')
30
- })
31
- })
@@ -1,40 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { getNameDirByPaths } from '../getNameDirByPaths'
3
- import { PropertiesFile } from '../../classes/Properties/PropertiesFile'
4
-
5
- vi.mock('../../classes/Properties/PropertiesFile', () => ({
6
- PropertiesFile: {
7
- splitForDir: vi.fn(),
8
- joinPath: vi.fn()
9
- }
10
- }))
11
-
12
- describe('getNameDirByPaths', () => {
13
- beforeEach(() => {
14
- vi.clearAllMocks()
15
- })
16
-
17
- it('should return the last directory name from provided paths', () => {
18
- const mockPaths = ['src', 'components', 'button']
19
- const mockJoinedPath = 'src/components/button'
20
- const mockSplitDirs = ['src', 'components', 'button']
21
-
22
- vi.mocked(PropertiesFile.joinPath).mockReturnValue(mockJoinedPath)
23
- vi.mocked(PropertiesFile.splitForDir).mockReturnValue(mockSplitDirs)
24
-
25
- const result = getNameDirByPaths(mockPaths)
26
-
27
- expect(result).toBe('button')
28
- expect(PropertiesFile.joinPath).toHaveBeenCalledWith(mockPaths)
29
- expect(PropertiesFile.splitForDir).toHaveBeenCalledWith(mockJoinedPath)
30
- })
31
-
32
- it('should work with a single path segment', () => {
33
- const mockPaths = ['root']
34
- vi.mocked(PropertiesFile.joinPath).mockReturnValue('root')
35
- vi.mocked(PropertiesFile.splitForDir).mockReturnValue(['root'])
36
-
37
- const result = getNameDirByPaths(mockPaths)
38
- expect(result).toBe('root')
39
- })
40
- })
@@ -1,34 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { getPackageJson } from '../getPackageJson'
3
- import { PropertiesFile } from '../../classes/Properties/PropertiesFile'
4
- import { UI_FILE_PACKAGE } from '../../config'
5
-
6
- vi.mock('../../classes/Properties/PropertiesFile', () => ({
7
- PropertiesFile: {
8
- readFile: vi.fn()
9
- }
10
- }))
11
-
12
- describe('getPackageJson', () => {
13
- beforeEach(() => {
14
- vi.clearAllMocks()
15
- })
16
-
17
- it('should return package.json content via PropertiesFile.readFile', () => {
18
- const mockContent = { name: 'test-package', version: '1.0.0' }
19
- vi.mocked(PropertiesFile.readFile).mockReturnValue(mockContent)
20
-
21
- const result = getPackageJson()
22
-
23
- expect(result).toEqual(mockContent)
24
- expect(PropertiesFile.readFile).toHaveBeenCalledWith(UI_FILE_PACKAGE)
25
- })
26
-
27
- it('should return undefined if file reading fails', () => {
28
- vi.mocked(PropertiesFile.readFile).mockReturnValue(undefined)
29
-
30
- const result = getPackageJson()
31
-
32
- expect(result).toBeUndefined()
33
- })
34
- })
@@ -1,18 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { hasNativeDirname } from '../hasNativeDirname'
3
-
4
- describe('hasNativeDirname', () => {
5
- it('should return a boolean', () => {
6
- const result = hasNativeDirname()
7
- expect(typeof result).toBe('boolean')
8
- })
9
-
10
- it('it should return true if __dirname is defined', () => {
11
- // In vitest/node environment, __dirname is usually defined
12
- // We can't easily "un-define" it for a negative test without complex environment manipulation,
13
- // but we can verify it returns true if it's there
14
- if (typeof __dirname !== 'undefined') {
15
- expect(hasNativeDirname()).toBe(true)
16
- }
17
- })
18
- })
@@ -1,31 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach } from 'vitest'
2
- import { toPathStandardSep } from '../toPathStandardSep'
3
- import requirePath from 'path'
4
-
5
- vi.mock('path', async (importOriginal) => {
6
- const actual = await importOriginal<typeof import('path')>()
7
- return {
8
- ...actual,
9
- default: {
10
- ...actual,
11
- sep: '/'
12
- }
13
- }
14
- })
15
-
16
- describe('toPathStandardSep', () => {
17
- beforeEach(() => {
18
- vi.clearAllMocks()
19
- vi.mocked(requirePath).sep = '/'
20
- })
21
-
22
- it('should replace all forward slashes with the platform-specific separator', () => {
23
- vi.mocked(requirePath).sep = '\\'
24
- expect(toPathStandardSep('src/components/button')).toBe('src\\components\\button')
25
- })
26
-
27
- it('should not change the path if it already uses the correct separator (unix)', () => {
28
- vi.mocked(requirePath).sep = '/'
29
- expect(toPathStandardSep('src/components/button')).toBe('src/components/button')
30
- })
31
- })