genaicode 0.0.35 → 0.1.1
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/README.md +3 -0
- package/bin/genaicode-dev.js +11 -0
- package/bin/genaicode.cjs +8 -1
- package/dist/ai-service/ai-studio.d.ts +5 -0
- package/dist/ai-service/ai-studio.js +135 -0
- package/dist/ai-service/ai-studio.js.map +1 -0
- package/dist/ai-service/anthropic.d.ts +5 -0
- package/dist/ai-service/anthropic.js +133 -0
- package/dist/ai-service/anthropic.js.map +1 -0
- package/dist/ai-service/chat-gpt.d.ts +5 -0
- package/dist/ai-service/chat-gpt.js +131 -0
- package/dist/ai-service/chat-gpt.js.map +1 -0
- package/dist/ai-service/common.d.ts +57 -0
- package/dist/ai-service/common.js +38 -0
- package/dist/ai-service/common.js.map +1 -0
- package/dist/ai-service/common.test.d.ts +1 -0
- package/dist/ai-service/common.test.js +85 -0
- package/dist/ai-service/common.test.js.map +1 -0
- package/dist/ai-service/dall-e.d.ts +14 -0
- package/dist/ai-service/dall-e.js +47 -0
- package/dist/ai-service/dall-e.js.map +1 -0
- package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
- package/dist/ai-service/vertex-ai-claude.js +93 -0
- package/dist/ai-service/vertex-ai-claude.js.map +1 -0
- package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
- package/dist/ai-service/vertex-ai-imagen.js +74 -0
- package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
- package/dist/ai-service/vertex-ai.d.ts +7 -0
- package/dist/ai-service/vertex-ai.js +147 -0
- package/dist/ai-service/vertex-ai.js.map +1 -0
- package/dist/cli/cli-options.d.ts +10 -0
- package/dist/cli/cli-options.js +124 -0
- package/dist/cli/cli-options.js.map +1 -0
- package/dist/cli/cli-options.test.d.ts +1 -0
- package/dist/cli/cli-options.test.js +34 -0
- package/dist/cli/cli-options.test.js.map +1 -0
- package/dist/cli/cli-params.d.ts +29 -0
- package/dist/cli/cli-params.js +103 -0
- package/dist/cli/cli-params.js.map +1 -0
- package/dist/cli/cli-params.test.d.ts +1 -0
- package/dist/cli/cli-params.test.js +38 -0
- package/dist/cli/cli-params.test.js.map +1 -0
- package/dist/cli/service-autodetect.d.ts +2 -0
- package/dist/cli/service-autodetect.js +17 -0
- package/dist/cli/service-autodetect.js.map +1 -0
- package/dist/cli/service-autodetect.test.d.ts +1 -0
- package/dist/cli/service-autodetect.test.js +38 -0
- package/dist/cli/service-autodetect.test.js.map +1 -0
- package/dist/cli/validate-cli-params.d.ts +18 -0
- package/dist/cli/validate-cli-params.js +128 -0
- package/dist/cli/validate-cli-params.js.map +1 -0
- package/dist/cli/validate-cli-params.test.d.ts +1 -0
- package/dist/cli/validate-cli-params.test.js +106 -0
- package/dist/cli/validate-cli-params.test.js.map +1 -0
- package/dist/files/file-utils.d.ts +2 -0
- package/dist/files/file-utils.js +7 -0
- package/dist/files/file-utils.js.map +1 -0
- package/dist/files/file-utils.test.d.ts +1 -0
- package/dist/files/file-utils.test.js +18 -0
- package/dist/files/file-utils.test.js.map +1 -0
- package/dist/files/find-files.d.ts +8 -0
- package/dist/files/find-files.js +76 -0
- package/dist/files/find-files.js.map +1 -0
- package/dist/files/read-files.d.ts +13 -0
- package/dist/files/read-files.js +61 -0
- package/dist/files/read-files.js.map +1 -0
- package/dist/files/read-files.test.d.ts +1 -0
- package/dist/files/read-files.test.js +89 -0
- package/dist/files/read-files.test.js.map +1 -0
- package/dist/files/temp-buffer.d.ts +2 -0
- package/dist/files/temp-buffer.js +12 -0
- package/dist/files/temp-buffer.js.map +1 -0
- package/dist/files/update-files.d.ts +5 -0
- package/dist/files/update-files.js +197 -0
- package/dist/files/update-files.js.map +1 -0
- package/dist/images/ensure-alpha.d.ts +1 -0
- package/dist/images/ensure-alpha.js +5 -0
- package/dist/images/ensure-alpha.js.map +1 -0
- package/dist/images/imgly-remove-background.d.ts +2 -0
- package/dist/images/imgly-remove-background.js +21 -0
- package/dist/images/imgly-remove-background.js.map +1 -0
- package/dist/images/resize-image.d.ts +19 -0
- package/dist/images/resize-image.js +22 -0
- package/dist/images/resize-image.js.map +1 -0
- package/dist/images/split-image.d.ts +18 -0
- package/dist/images/split-image.js +25 -0
- package/dist/images/split-image.js.map +1 -0
- package/dist/main/codegen.d.ts +2 -0
- package/dist/main/codegen.js +101 -0
- package/dist/main/codegen.js.map +1 -0
- package/dist/main/codegen.test.d.ts +2 -0
- package/dist/main/codegen.test.js +259 -0
- package/dist/main/codegen.test.js.map +1 -0
- package/dist/main/config-lib.d.ts +8 -0
- package/dist/main/config-lib.js +28 -0
- package/dist/main/config-lib.js.map +1 -0
- package/dist/main/config-lib.test.d.ts +1 -0
- package/dist/main/config-lib.test.js +64 -0
- package/dist/main/config-lib.test.js.map +1 -0
- package/dist/main/config.d.ts +5 -0
- package/{src → dist}/main/config.js +16 -22
- package/dist/main/config.js.map +1 -0
- package/dist/prompt/function-calling-validate.d.ts +3 -0
- package/dist/prompt/function-calling-validate.js +27 -0
- package/dist/prompt/function-calling-validate.js.map +1 -0
- package/dist/prompt/function-calling.d.ts +5 -0
- package/dist/prompt/function-calling.js +48 -0
- package/dist/prompt/function-calling.js.map +1 -0
- package/dist/prompt/function-defs/ask-question.d.ts +31 -0
- package/dist/prompt/function-defs/ask-question.js +32 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -0
- package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
- package/dist/prompt/function-defs/codegen-summary.js +80 -0
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
- package/dist/prompt/function-defs/create-directory.d.ts +21 -0
- package/dist/prompt/function-defs/create-directory.js +22 -0
- package/dist/prompt/function-defs/create-directory.js.map +1 -0
- package/dist/prompt/function-defs/create-file.d.ts +25 -0
- package/dist/prompt/function-defs/create-file.js +26 -0
- package/dist/prompt/function-defs/create-file.js.map +1 -0
- package/dist/prompt/function-defs/delete-file.d.ts +21 -0
- package/dist/prompt/function-defs/delete-file.js +22 -0
- package/dist/prompt/function-defs/delete-file.js.map +1 -0
- package/dist/prompt/function-defs/download-file.d.ts +25 -0
- package/dist/prompt/function-defs/download-file.js +26 -0
- package/dist/prompt/function-defs/download-file.js.map +1 -0
- package/dist/prompt/function-defs/explanation.d.ts +17 -0
- package/dist/prompt/function-defs/explanation.js +18 -0
- package/dist/prompt/function-defs/explanation.js.map +1 -0
- package/dist/prompt/function-defs/generate-image.d.ts +48 -0
- package/dist/prompt/function-defs/generate-image.js +49 -0
- package/dist/prompt/function-defs/generate-image.js.map +1 -0
- package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
- package/dist/prompt/function-defs/get-image-assets.js +21 -0
- package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
- package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
- package/dist/prompt/function-defs/get-source-code.js +21 -0
- package/dist/prompt/function-defs/get-source-code.js.map +1 -0
- package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
- package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
- package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
- package/dist/prompt/function-defs/move-file.d.ts +25 -0
- package/dist/prompt/function-defs/move-file.js +26 -0
- package/dist/prompt/function-defs/move-file.js.map +1 -0
- package/dist/prompt/function-defs/patch-file.d.ts +25 -0
- package/dist/prompt/function-defs/patch-file.js +39 -0
- package/dist/prompt/function-defs/patch-file.js.map +1 -0
- package/dist/prompt/function-defs/resize-image.d.ts +36 -0
- package/dist/prompt/function-defs/resize-image.js +37 -0
- package/dist/prompt/function-defs/resize-image.js.map +1 -0
- package/dist/prompt/function-defs/split-image.d.ts +57 -0
- package/dist/prompt/function-defs/split-image.js +46 -0
- package/dist/prompt/function-defs/split-image.js.map +1 -0
- package/dist/prompt/function-defs/update-file.d.ts +25 -0
- package/dist/prompt/function-defs/update-file.js +26 -0
- package/dist/prompt/function-defs/update-file.js.map +1 -0
- package/dist/prompt/limits.d.ts +3 -0
- package/dist/prompt/limits.js +19 -0
- package/dist/prompt/limits.js.map +1 -0
- package/dist/prompt/limits.test.d.ts +1 -0
- package/dist/prompt/limits.test.js +35 -0
- package/dist/prompt/limits.test.js.map +1 -0
- package/dist/prompt/prompt-codegen.d.ts +4 -0
- package/dist/prompt/prompt-codegen.js +81 -0
- package/dist/prompt/prompt-codegen.js.map +1 -0
- package/dist/prompt/prompt-codegen.test.d.ts +1 -0
- package/dist/prompt/prompt-codegen.test.js +94 -0
- package/dist/prompt/prompt-codegen.test.js.map +1 -0
- package/dist/prompt/prompt-consts.d.ts +1 -0
- package/{src → dist}/prompt/prompt-consts.js +1 -0
- package/dist/prompt/prompt-consts.js.map +1 -0
- package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
- package/dist/prompt/prompt-service-ask-question.test.js +146 -0
- package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
- package/dist/prompt/prompt-service.d.ts +13 -0
- package/dist/prompt/prompt-service.js +278 -0
- package/dist/prompt/prompt-service.js.map +1 -0
- package/dist/prompt/prompt-service.test.d.ts +1 -0
- package/dist/prompt/prompt-service.test.js +511 -0
- package/dist/prompt/prompt-service.test.js.map +1 -0
- package/dist/prompt/systemprompt.d.ts +2 -0
- package/dist/prompt/systemprompt.js +43 -0
- package/dist/prompt/systemprompt.js.map +1 -0
- package/dist/prompt/systemprompt.test.d.ts +2 -0
- package/dist/prompt/systemprompt.test.js +47 -0
- package/dist/prompt/systemprompt.test.js.map +1 -0
- package/package.json +15 -5
- package/bin/genaicode.js +0 -5
- package/src/ai-service/anthropic.js +0 -95
- package/src/ai-service/chat-gpt.js +0 -99
- package/src/ai-service/common.js +0 -40
- package/src/ai-service/common.test.js +0 -107
- package/src/ai-service/dall-e.js +0 -50
- package/src/ai-service/vertex-ai-claude.js +0 -99
- package/src/ai-service/vertex-ai-imagen.js +0 -78
- package/src/ai-service/vertex-ai.js +0 -156
- package/src/cli/cli-options.js +0 -120
- package/src/cli/cli-options.test.js +0 -50
- package/src/cli/cli-params.js +0 -99
- package/src/cli/cli-params.test.js +0 -43
- package/src/cli/service-autodetect.js +0 -11
- package/src/cli/service-autodetect.test.js +0 -43
- package/src/cli/validate-cli-params.js +0 -117
- package/src/cli/validate-cli-params.test.js +0 -134
- package/src/files/file-utils.js +0 -7
- package/src/files/file-utils.test.js +0 -21
- package/src/files/find-files.js +0 -86
- package/src/files/read-files.js +0 -60
- package/src/files/read-files.test.js +0 -102
- package/src/files/temp-buffer.js +0 -13
- package/src/files/update-files.js +0 -205
- package/src/images/ensure-alpha.js +0 -5
- package/src/images/imgly-remove-background.js +0 -23
- package/src/images/resize-image.js +0 -23
- package/src/images/split-image.js +0 -26
- package/src/main/codegen.js +0 -120
- package/src/main/codegen.test.js +0 -334
- package/src/main/config-lib.js +0 -33
- package/src/main/config-lib.test.js +0 -80
- package/src/prompt/function-calling-validate.js +0 -25
- package/src/prompt/function-calling.js +0 -454
- package/src/prompt/limits.js +0 -23
- package/src/prompt/limits.test.js +0 -40
- package/src/prompt/prompt-codegen.js +0 -106
- package/src/prompt/prompt-codegen.test.js +0 -116
- package/src/prompt/prompt-service.js +0 -287
- package/src/prompt/prompt-service.test.js +0 -601
- package/src/prompt/systemprompt.js +0 -32
- package/src/prompt/systemprompt.test.js +0 -63
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { validateCliParams, getCliParamValue, hasCliParam } from './validate-cli-params.js';
|
|
3
|
-
|
|
4
|
-
describe('validateCliParams', () => {
|
|
5
|
-
const originalArgv = process.argv;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
process.argv = ['node', 'script.js'];
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
process.argv = originalArgv;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should not throw for valid parameters', () => {
|
|
16
|
-
process.argv.push('--dry-run', '--consider-all-files');
|
|
17
|
-
expect(() => validateCliParams()).not.toThrow();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should throw for invalid parameters', () => {
|
|
21
|
-
process.argv.push('--invalid-param');
|
|
22
|
-
expect(() => validateCliParams()).toThrow();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should throw for parameters without --', () => {
|
|
26
|
-
process.argv.push('invalid-param');
|
|
27
|
-
expect(() => validateCliParams()).toThrow();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should not throw for valid --temperature parameter', () => {
|
|
31
|
-
process.argv.push('--temperature=0.5');
|
|
32
|
-
expect(() => validateCliParams()).not.toThrow();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should throw for invalid --temperature parameter', () => {
|
|
36
|
-
process.argv.push('--temperature=invalid');
|
|
37
|
-
expect(() => validateCliParams()).toThrow();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should throw an error when both vision and vertexAi flags are true', () => {
|
|
41
|
-
process.argv.push('--vision');
|
|
42
|
-
process.argv.push('--vertex-ai');
|
|
43
|
-
|
|
44
|
-
expect(() => validateCliParams()).toThrow('--vision and --vertex-ai are currently not supported together.');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// New tests for --imagen parameter
|
|
48
|
-
it('should not throw for valid --imagen parameter with vertex-ai', () => {
|
|
49
|
-
process.argv.push('--imagen=vertex-ai');
|
|
50
|
-
expect(() => validateCliParams()).not.toThrow();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should not throw for valid --imagen parameter with dall-e', () => {
|
|
54
|
-
process.argv.push('--imagen=dall-e');
|
|
55
|
-
expect(() => validateCliParams()).not.toThrow();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should throw for invalid --imagen parameter value', () => {
|
|
59
|
-
process.argv.push('--imagen=invalid-service');
|
|
60
|
-
expect(() => validateCliParams()).toThrow('Invalid --imagen value. It must be either "vertex-ai" or "dall-e".');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should throw for --imagen parameter without value', () => {
|
|
64
|
-
process.argv.push('--imagen=');
|
|
65
|
-
expect(() => validateCliParams()).toThrow('Invalid --imagen value. It must be either "vertex-ai" or "dall-e".');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('getCliParamValue', () => {
|
|
70
|
-
const originalArgv = process.argv;
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
process.argv = ['node', 'script.js'];
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
process.argv = originalArgv;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should return the value for a parameter with a value', () => {
|
|
81
|
-
process.argv.push('--explicit-prompt=Test prompt');
|
|
82
|
-
expect(getCliParamValue('--explicit-prompt')).toBe('Test prompt');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should return null for a parameter without a value', () => {
|
|
86
|
-
process.argv.push('--dry-run');
|
|
87
|
-
expect(getCliParamValue('--dry-run')).toBeNull();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should return null for a non-existent parameter', () => {
|
|
91
|
-
expect(getCliParamValue('--non-existent')).toBeNull();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should return the value for --temperature parameter', () => {
|
|
95
|
-
process.argv.push('--temperature=0.5');
|
|
96
|
-
expect(getCliParamValue('--temperature')).toBe('0.5');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should return the value for --imagen parameter', () => {
|
|
100
|
-
process.argv.push('--imagen=vertex-ai');
|
|
101
|
-
expect(getCliParamValue('--imagen')).toBe('vertex-ai');
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('hasCliParam', () => {
|
|
106
|
-
const originalArgv = process.argv;
|
|
107
|
-
|
|
108
|
-
beforeEach(() => {
|
|
109
|
-
process.argv = ['node', 'script.js'];
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
afterEach(() => {
|
|
113
|
-
process.argv = originalArgv;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should return true for an existing parameter', () => {
|
|
117
|
-
process.argv.push('--dry-run');
|
|
118
|
-
expect(hasCliParam('--dry-run')).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should return false for a non-existent parameter', () => {
|
|
122
|
-
expect(hasCliParam('--non-existent')).toBe(false);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should return true for --temperature parameter', () => {
|
|
126
|
-
process.argv.push('--temperature=0.5');
|
|
127
|
-
expect(hasCliParam('--temperature')).toBe(true);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should return true for --imagen parameter', () => {
|
|
131
|
-
process.argv.push('--imagen=dall-e');
|
|
132
|
-
expect(hasCliParam('--imagen')).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
});
|
package/src/files/file-utils.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
/** Check if directory is ancestor of given directory */
|
|
4
|
-
export function isAncestorDirectory(parent, dir) {
|
|
5
|
-
const relative = path.relative(parent, dir);
|
|
6
|
-
return parent === dir || (relative && !relative.startsWith('..') && !path.isAbsolute(relative));
|
|
7
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { vi, describe, beforeEach, it, expect } from 'vitest';
|
|
2
|
-
import { isAncestorDirectory } from './file-utils.js';
|
|
3
|
-
|
|
4
|
-
// Test for isAncestorDirectory
|
|
5
|
-
describe('isAncestorDirectory', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
vi.resetAllMocks();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should return true if directories are the same', () => {
|
|
11
|
-
expect(isAncestorDirectory('/project', '/project')).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should return true if parent is ancestor of dir', () => {
|
|
15
|
-
expect(isAncestorDirectory('/project', '/project/src')).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return false if parent is not ancestor of dir', () => {
|
|
19
|
-
expect(isAncestorDirectory('/project', '/other')).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/files/find-files.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { rcConfig, sourceExtensions, IMAGE_ASSET_EXTENSIONS, ignorePaths } from '../main/config.js';
|
|
4
|
-
|
|
5
|
-
// List of possible extensions for dependency resolution
|
|
6
|
-
const POSSIBLE_DEPENDENCY_EXTENSIONS = ['.ts', '.js', '.tsx', '.jsx'];
|
|
7
|
-
|
|
8
|
-
function findFiles(dir, recursive, extensions) {
|
|
9
|
-
const files = [];
|
|
10
|
-
const items = fs.readdirSync(dir);
|
|
11
|
-
for (const item of items) {
|
|
12
|
-
const fullPath = path.join(dir, item);
|
|
13
|
-
|
|
14
|
-
if (ignorePaths.some((ignorePath) => fullPath.endsWith(ignorePath))) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
19
|
-
if (recursive) {
|
|
20
|
-
files.push(...findFiles(fullPath, true, extensions));
|
|
21
|
-
}
|
|
22
|
-
} else if (extensions.includes(path.extname(fullPath))) {
|
|
23
|
-
files.push(fullPath);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return files;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getDependencies(filePath) {
|
|
30
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
31
|
-
const dependencyRegex = /import\s+.+?\s+from\s+['"](.+?\/?[^'"]+)['"]/g;
|
|
32
|
-
const dependencies = [];
|
|
33
|
-
let match;
|
|
34
|
-
while ((match = dependencyRegex.exec(content)) !== null) {
|
|
35
|
-
const dependencyPath = match[1];
|
|
36
|
-
// Resolve relative paths from the file's directory
|
|
37
|
-
let resolvedPath = path.resolve(path.dirname(filePath), dependencyPath);
|
|
38
|
-
|
|
39
|
-
// Only add the dependency if it's a local file and not a module
|
|
40
|
-
if (fs.existsSync(resolvedPath)) {
|
|
41
|
-
dependencies.push(resolvedPath);
|
|
42
|
-
} else {
|
|
43
|
-
const possibleExtensions = POSSIBLE_DEPENDENCY_EXTENSIONS;
|
|
44
|
-
for (const ext of possibleExtensions) {
|
|
45
|
-
const extendedPath = resolvedPath + ext;
|
|
46
|
-
if (fs.existsSync(extendedPath)) {
|
|
47
|
-
dependencies.push(extendedPath);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return dependencies;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Generates a dependency list for given file */
|
|
56
|
-
export function getDependencyList(entryFile) {
|
|
57
|
-
const visitedFiles = new Set();
|
|
58
|
-
const result = new Set();
|
|
59
|
-
|
|
60
|
-
function traverse(file) {
|
|
61
|
-
if (visitedFiles.has(file)) return;
|
|
62
|
-
visitedFiles.add(file);
|
|
63
|
-
const dependencies = getDependencies(file);
|
|
64
|
-
dependencies.forEach((dependency) => result.add(dependency));
|
|
65
|
-
dependencies.forEach(traverse);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
result.add(path.resolve(entryFile));
|
|
69
|
-
traverse(entryFile);
|
|
70
|
-
|
|
71
|
-
return Array.from(result);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const sourceFiles = findFiles(rcConfig.rootDir, true, sourceExtensions);
|
|
75
|
-
|
|
76
|
-
/** Get source files of the application */
|
|
77
|
-
export function getSourceFiles() {
|
|
78
|
-
return [...sourceFiles];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const imageAssetFiles = findFiles(rcConfig.rootDir, true, IMAGE_ASSET_EXTENSIONS);
|
|
82
|
-
|
|
83
|
-
/** Get source files of the application */
|
|
84
|
-
export function getImageAssetFiles() {
|
|
85
|
-
return [...imageAssetFiles];
|
|
86
|
-
}
|
package/src/files/read-files.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import mime from 'mime-types';
|
|
3
|
-
import sizeOf from 'image-size';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
import { getSourceFiles, getImageAssetFiles } from './find-files.js';
|
|
7
|
-
import { rcConfig } from '../main/config.js';
|
|
8
|
-
import { verifySourceCodeLimit } from '../prompt/limits.js';
|
|
9
|
-
import { taskFile, contentMask } from '../cli/cli-params.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Read contents of source files and create a map with file path as key and file content as value
|
|
13
|
-
*/
|
|
14
|
-
function readSourceFiles(filterPaths) {
|
|
15
|
-
const sourceCode = {};
|
|
16
|
-
for (const file of getSourceFiles()) {
|
|
17
|
-
if (!filterPaths || filterPaths.includes(file)) {
|
|
18
|
-
// Apply content mask filter if it's set
|
|
19
|
-
if (!filterPaths && contentMask) {
|
|
20
|
-
const relativePath = path.relative(rcConfig.rootDir, file);
|
|
21
|
-
if (!relativePath.startsWith(contentMask)) {
|
|
22
|
-
sourceCode[file] = { content: null }; // Include the file path but set content to null
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const content = fs.readFileSync(file, 'utf-8');
|
|
27
|
-
sourceCode[file] = { content };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return sourceCode;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Print source code of all source files */
|
|
34
|
-
export function getSourceCode(filterPaths) {
|
|
35
|
-
const sourceCode = readSourceFiles(filterPaths);
|
|
36
|
-
|
|
37
|
-
if (taskFile && !sourceCode[taskFile]) {
|
|
38
|
-
sourceCode[taskFile] = {
|
|
39
|
-
content: fs.readFileSync(taskFile, 'utf-8'),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
verifySourceCodeLimit(JSON.stringify(sourceCode));
|
|
44
|
-
return sourceCode;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Get image asset files summary */
|
|
48
|
-
export function getImageAssets() {
|
|
49
|
-
const imageAssets = {};
|
|
50
|
-
for (const file of getImageAssetFiles()) {
|
|
51
|
-
const dimensions = sizeOf(file);
|
|
52
|
-
imageAssets[file] = {
|
|
53
|
-
mimeType: mime.lookup(file),
|
|
54
|
-
width: dimensions.width,
|
|
55
|
-
height: dimensions.height,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
verifySourceCodeLimit(JSON.stringify(imageAssets));
|
|
59
|
-
return imageAssets;
|
|
60
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import mime from 'mime-types';
|
|
4
|
-
import sizeOf from 'image-size';
|
|
5
|
-
import { getSourceCode, getImageAssets } from './read-files.js';
|
|
6
|
-
import { getSourceFiles, getImageAssetFiles } from './find-files.js';
|
|
7
|
-
import { verifySourceCodeLimit } from '../prompt/limits.js';
|
|
8
|
-
import * as cliParams from '../cli/cli-params.js';
|
|
9
|
-
import { rcConfig } from '../main/config.js';
|
|
10
|
-
|
|
11
|
-
vi.mock('fs');
|
|
12
|
-
vi.mock('mime-types');
|
|
13
|
-
vi.mock('image-size');
|
|
14
|
-
vi.mock('./find-files.js', () => ({
|
|
15
|
-
getImageAssetFiles: vi.fn(),
|
|
16
|
-
getSourceFiles: vi.fn(),
|
|
17
|
-
}));
|
|
18
|
-
vi.mock('../prompt/limits.js');
|
|
19
|
-
vi.mock('../cli/cli-params.js', () => ({
|
|
20
|
-
taskFile: null,
|
|
21
|
-
contentMask: null,
|
|
22
|
-
}));
|
|
23
|
-
vi.mock('../main/config.js', () => ({
|
|
24
|
-
rcConfig: { rootDir: '/home/project' },
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
describe('read-files', () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
vi.resetAllMocks();
|
|
30
|
-
vi.mocked(cliParams).contentMask = undefined;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
vi.clearAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getSourceCode', () => {
|
|
38
|
-
it('should return source code for all files', () => {
|
|
39
|
-
const mockFiles = ['/home/project/file1.js', '/home/project/file2.js'];
|
|
40
|
-
getSourceFiles.mockReturnValue(mockFiles);
|
|
41
|
-
fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
|
|
42
|
-
rcConfig.rootDir = '/home/project';
|
|
43
|
-
|
|
44
|
-
const result = getSourceCode();
|
|
45
|
-
|
|
46
|
-
expect(result).toEqual({
|
|
47
|
-
'/home/project/file1.js': { content: 'Content of /home/project/file1.js' },
|
|
48
|
-
'/home/project/file2.js': { content: 'Content of /home/project/file2.js' },
|
|
49
|
-
});
|
|
50
|
-
expect(verifySourceCodeLimit).toHaveBeenCalled();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should apply content mask when specified', () => {
|
|
54
|
-
const mockFiles = ['/home/project/file1.js', '/home/project/subfolder/file2.js'];
|
|
55
|
-
getSourceFiles.mockReturnValue(mockFiles);
|
|
56
|
-
fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
|
|
57
|
-
rcConfig.rootDir = '/home/project';
|
|
58
|
-
vi.mocked(cliParams).contentMask = 'subfolder';
|
|
59
|
-
|
|
60
|
-
const result = getSourceCode();
|
|
61
|
-
|
|
62
|
-
expect(result).toEqual({
|
|
63
|
-
'/home/project/file1.js': { content: null },
|
|
64
|
-
'/home/project/subfolder/file2.js': {
|
|
65
|
-
content: 'Content of /home/project/subfolder/file2.js',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should include task file when specified', () => {
|
|
71
|
-
const mockFiles = ['/home/project/file1.js'];
|
|
72
|
-
getSourceFiles.mockReturnValue(mockFiles);
|
|
73
|
-
fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
|
|
74
|
-
rcConfig.rootDir = '/home/project';
|
|
75
|
-
vi.mocked(cliParams).taskFile = '/home/project/task.md';
|
|
76
|
-
|
|
77
|
-
const result = getSourceCode();
|
|
78
|
-
|
|
79
|
-
expect(result).toEqual({
|
|
80
|
-
'/home/project/file1.js': { content: 'Content of /home/project/file1.js' },
|
|
81
|
-
'/home/project/task.md': { content: 'Content of /home/project/task.md' },
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('getImageAssets', () => {
|
|
87
|
-
it('should return image assets information', () => {
|
|
88
|
-
const mockImageFiles = ['/home/project/image1.png', '/home/project/image2.jpg'];
|
|
89
|
-
getImageAssetFiles.mockReturnValue(mockImageFiles);
|
|
90
|
-
mime.lookup.mockImplementation((file) => (file.endsWith('.png') ? 'image/png' : 'image/jpeg'));
|
|
91
|
-
sizeOf.mockImplementation(() => ({ width: 100, height: 200 }));
|
|
92
|
-
|
|
93
|
-
const result = getImageAssets();
|
|
94
|
-
|
|
95
|
-
expect(result).toEqual({
|
|
96
|
-
'/home/project/image1.png': { mimeType: 'image/png', width: 100, height: 200 },
|
|
97
|
-
'/home/project/image2.jpg': { mimeType: 'image/jpeg', width: 100, height: 200 },
|
|
98
|
-
});
|
|
99
|
-
expect(verifySourceCodeLimit).toHaveBeenCalled();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
package/src/files/temp-buffer.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Temporary storage */
|
|
2
|
-
let tempId = 1;
|
|
3
|
-
const temp = {};
|
|
4
|
-
|
|
5
|
-
export function getTempBuffer(url) {
|
|
6
|
-
return temp[url];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function setTempBuffer(buffer) {
|
|
10
|
-
const imageUrl = 'temp://' + tempId++;
|
|
11
|
-
temp[imageUrl] = buffer;
|
|
12
|
-
return imageUrl;
|
|
13
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import assert from 'node:assert';
|
|
4
|
-
import * as diff from 'diff';
|
|
5
|
-
|
|
6
|
-
import { getSourceFiles } from './find-files.js';
|
|
7
|
-
import { isAncestorDirectory } from './file-utils.js';
|
|
8
|
-
import { rcConfig } from '../main/config.js';
|
|
9
|
-
import {
|
|
10
|
-
allowDirectoryCreate,
|
|
11
|
-
allowFileCreate,
|
|
12
|
-
allowFileDelete,
|
|
13
|
-
allowFileMove,
|
|
14
|
-
anthropic,
|
|
15
|
-
chatGpt,
|
|
16
|
-
vertexAiClaude,
|
|
17
|
-
} from '../cli/cli-params.js';
|
|
18
|
-
import { getTempBuffer } from './temp-buffer.js';
|
|
19
|
-
import { imglyRemoveBackground } from '../images/imgly-remove-background.js';
|
|
20
|
-
import { splitImage } from '../images/split-image.js';
|
|
21
|
-
import { resizeImageFile } from '../images/resize-image.js';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @param functionCalls Result of the code generation, a map of file paths to new content
|
|
25
|
-
*/
|
|
26
|
-
export async function updateFiles(functionCalls) {
|
|
27
|
-
for (const { name, args } of functionCalls) {
|
|
28
|
-
let {
|
|
29
|
-
filePath,
|
|
30
|
-
newContent,
|
|
31
|
-
source,
|
|
32
|
-
destination,
|
|
33
|
-
patch,
|
|
34
|
-
inputFilePath,
|
|
35
|
-
outputFilePath,
|
|
36
|
-
backgroundColor,
|
|
37
|
-
parts,
|
|
38
|
-
size,
|
|
39
|
-
} = args;
|
|
40
|
-
|
|
41
|
-
// Check if filePath is absolute, if not use rootDir as baseline
|
|
42
|
-
if (name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage') {
|
|
43
|
-
filePath = path.isAbsolute(filePath) ? filePath : path.join(rcConfig.rootDir, filePath);
|
|
44
|
-
} else if (name === 'moveFile') {
|
|
45
|
-
source = path.isAbsolute(source) ? source : path.join(rcConfig.rootDir, source);
|
|
46
|
-
destination = path.isAbsolute(destination) ? destination : path.join(rcConfig.rootDir, destination);
|
|
47
|
-
} else if (name === 'imglyRemoveBackground' || name === 'splitImage') {
|
|
48
|
-
inputFilePath = path.isAbsolute(inputFilePath) ? inputFilePath : path.join(rcConfig.rootDir, inputFilePath);
|
|
49
|
-
if (name === 'imglyRemoveBackground') {
|
|
50
|
-
outputFilePath = path.isAbsolute(outputFilePath) ? outputFilePath : path.join(rcConfig.rootDir, outputFilePath);
|
|
51
|
-
} else if (name === 'splitImage') {
|
|
52
|
-
parts.forEach(
|
|
53
|
-
(part) =>
|
|
54
|
-
(part.outputFilePath = path.isAbsolute(part.outputFilePath)
|
|
55
|
-
? part.outputFilePath
|
|
56
|
-
: path.join(rcConfig.rootDir, part.outputFilePath)),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ignore files which are not located inside project directory (sourceFiles)
|
|
62
|
-
if (
|
|
63
|
-
(name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage' && !isProjectPath(filePath)) ||
|
|
64
|
-
(name === 'moveFile' && (!isProjectPath(source) || !isProjectPath(destination))) ||
|
|
65
|
-
(name === 'imglyRemoveBackground' && (!isProjectPath(inputFilePath) || !isProjectPath(outputFilePath))) ||
|
|
66
|
-
(name === 'splitImage' &&
|
|
67
|
-
(!isProjectPath(inputFilePath) || parts.some((part) => !isProjectPath(part.outputFilePath))))
|
|
68
|
-
) {
|
|
69
|
-
console.log(`Skipping file: ${filePath || source || inputFilePath}`);
|
|
70
|
-
throw new Error(
|
|
71
|
-
`File ${filePath || source || inputFilePath} is not located inside project directory, something is wrong?`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (name === 'deleteFile') {
|
|
76
|
-
assert(allowFileDelete, 'File delete option was not enabled');
|
|
77
|
-
console.log(`Removing file: ${filePath}`);
|
|
78
|
-
fs.unlinkSync(filePath);
|
|
79
|
-
} else if (name === 'createDirectory') {
|
|
80
|
-
assert(allowDirectoryCreate, 'Directory create option was not enabled');
|
|
81
|
-
console.log(`Creating directory: ${filePath}`);
|
|
82
|
-
fs.mkdirSync(filePath, { recursive: true });
|
|
83
|
-
} else if (name === 'updateFile' || name === 'createFile' || name === 'patchFile') {
|
|
84
|
-
if (name === 'patchFile') {
|
|
85
|
-
console.log(`Applying a patch: ${filePath} content`);
|
|
86
|
-
newContent = diff.applyPatch(fs.readFileSync(filePath, 'utf-8'), patch);
|
|
87
|
-
assert(!!newContent, 'Patch was not successful');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
assert(!!newContent, 'newContent must not be empty');
|
|
91
|
-
if (name === 'createFile') {
|
|
92
|
-
console.log(`Creating file: ${filePath}`);
|
|
93
|
-
assert(allowFileCreate, 'File create option was not enabled');
|
|
94
|
-
assert(!fs.existsSync(filePath), 'File already exists');
|
|
95
|
-
if (allowDirectoryCreate) {
|
|
96
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
console.log(`Updating file: ${filePath}`);
|
|
100
|
-
assert(fs.existsSync(filePath), 'File does not exist');
|
|
101
|
-
}
|
|
102
|
-
fs.writeFileSync(
|
|
103
|
-
filePath,
|
|
104
|
-
chatGpt || anthropic || vertexAiClaude
|
|
105
|
-
? newContent
|
|
106
|
-
: // Fixing a problem caused by vertex function calling. Possibly not a good fix
|
|
107
|
-
newContent.replace(/\\n/g, '\n').replace(/\\'/g, "'"),
|
|
108
|
-
'utf-8',
|
|
109
|
-
);
|
|
110
|
-
} else if (name === 'moveFile') {
|
|
111
|
-
console.log(`Moving file from ${source} to ${destination}`);
|
|
112
|
-
assert(fs.existsSync(source), 'Source file does not exist');
|
|
113
|
-
assert(!fs.existsSync(destination), 'Destination file already exists');
|
|
114
|
-
assert(allowFileMove, 'File move option was not enabled');
|
|
115
|
-
if (allowDirectoryCreate) {
|
|
116
|
-
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
117
|
-
}
|
|
118
|
-
fs.renameSync(source, destination);
|
|
119
|
-
} else if (name === 'downloadFile') {
|
|
120
|
-
console.log(`Downloading image: ${filePath}`);
|
|
121
|
-
assert(fs.existsSync(filePath) || allowFileCreate, 'File create option was not enabled and file does not exist');
|
|
122
|
-
if (allowDirectoryCreate) {
|
|
123
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
124
|
-
}
|
|
125
|
-
try {
|
|
126
|
-
assert(args.downloadUrl, 'image url is not empty');
|
|
127
|
-
if (args.downloadUrl.startsWith('temp://')) {
|
|
128
|
-
assert(getTempBuffer(args.downloadUrl), 'Temp buffer not present but expected');
|
|
129
|
-
fs.writeFileSync(filePath, getTempBuffer(args.downloadUrl));
|
|
130
|
-
} else {
|
|
131
|
-
const imageResponse = await fetch(args.downloadUrl);
|
|
132
|
-
const arrayBuffer = await imageResponse.arrayBuffer();
|
|
133
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
134
|
-
fs.writeFileSync(filePath, buffer);
|
|
135
|
-
}
|
|
136
|
-
console.log(`Image download and saved to: ${filePath}`);
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error(`Failed to download image: ${error.message}`);
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
} else if (name === 'imglyRemoveBackground') {
|
|
142
|
-
console.log(`Removing background from image: ${inputFilePath}`);
|
|
143
|
-
assert(fs.existsSync(inputFilePath), 'Input file does not exist');
|
|
144
|
-
assert(
|
|
145
|
-
allowFileCreate || fs.existsSync(outputFilePath),
|
|
146
|
-
'File create option was not enabled and output file does not exist',
|
|
147
|
-
);
|
|
148
|
-
if (allowDirectoryCreate) {
|
|
149
|
-
fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
await imglyRemoveBackground(inputFilePath, outputFilePath, backgroundColor);
|
|
153
|
-
console.log(`Background removed and image saved to: ${outputFilePath}`);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(`Failed to remove background: ${error.message}`);
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
} else if (name === 'splitImage') {
|
|
159
|
-
console.log(`Splitting image: ${inputFilePath}`, parts);
|
|
160
|
-
assert(fs.existsSync(inputFilePath), 'Input file does not exist');
|
|
161
|
-
assert(Array.isArray(parts) && parts.length > 0, 'Parts array must not be empty');
|
|
162
|
-
for (const part of parts) {
|
|
163
|
-
assert(
|
|
164
|
-
allowFileCreate || fs.existsSync(part.outputFilePath),
|
|
165
|
-
'File create option was not enabled and output file does not exist',
|
|
166
|
-
);
|
|
167
|
-
if (allowDirectoryCreate) {
|
|
168
|
-
fs.mkdirSync(path.dirname(part.outputFilePath), { recursive: true });
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
await splitImage(inputFilePath, parts);
|
|
173
|
-
console.log(`Image split successfully`);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error(`Failed to split image: ${error.message}`);
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
} else if (name === 'resizeImage') {
|
|
179
|
-
console.log(`Resizing image: ${filePath}`, size);
|
|
180
|
-
assert(fs.existsSync(filePath), 'Input file does not exist');
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
await resizeImageFile(filePath, size);
|
|
184
|
-
console.log(`Image resized successfully`);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.error(`Failed to resize image: ${error.message}`);
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function isProjectPath(filePath) {
|
|
194
|
-
const sourceFiles = getSourceFiles();
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
isAncestorDirectory(rcConfig.rootDir, filePath) ||
|
|
198
|
-
sourceFiles.includes(filePath) ||
|
|
199
|
-
!sourceFiles.some(
|
|
200
|
-
(sourceFile) =>
|
|
201
|
-
path.dirname(filePath) === path.dirname(sourceFile) ||
|
|
202
|
-
isAncestorDirectory(path.dirname(sourceFile), path.dirname(filePath)),
|
|
203
|
-
)
|
|
204
|
-
);
|
|
205
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
|
|
4
|
-
import { removeBackground } from '@imgly/background-removal-node';
|
|
5
|
-
|
|
6
|
-
/** Converts white color to transparency on a image and saves to destination path */
|
|
7
|
-
export async function imglyRemoveBackground(inputFilePath, outputFilePath) {
|
|
8
|
-
try {
|
|
9
|
-
console.log(`Removing background for image: ${inputFilePath}`);
|
|
10
|
-
|
|
11
|
-
const publicPath = 'file://' + createRequire(import.meta.url).resolve('@imgly/background-removal-node');
|
|
12
|
-
const blob = await removeBackground(inputFilePath, {
|
|
13
|
-
publicPath,
|
|
14
|
-
});
|
|
15
|
-
fs.writeFileSync(outputFilePath, Buffer.from(await blob.arrayBuffer()));
|
|
16
|
-
|
|
17
|
-
console.log(`Background removed successfully. Saved to: ${outputFilePath}`);
|
|
18
|
-
return outputFilePath;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error('Error removing background:', error);
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import sharp from 'sharp';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {Buffer} input
|
|
7
|
-
* @param {{width: number, height: number}} size
|
|
8
|
-
* @returns {Buffer}
|
|
9
|
-
*/
|
|
10
|
-
export async function resizeImageBuffer(input, size) {
|
|
11
|
-
return await sharp(input).resize(size.width, size.height).toBuffer();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {string} filePath
|
|
17
|
-
* @param {{width: number, height: number}} size
|
|
18
|
-
* @returns {Buffer}
|
|
19
|
-
*/
|
|
20
|
-
export async function resizeImageFile(filePath, size) {
|
|
21
|
-
const buffer = await resizeImageBuffer(filePath, size);
|
|
22
|
-
fs.writeFileSync(filePath, buffer);
|
|
23
|
-
}
|