cloving 0.1.13 → 0.1.14
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/dist/commands/generate/code.js +113 -84
- package/dist/commands/generate/context.js +69 -0
- package/dist/commands/init.js +6 -13
- package/dist/index.js +8 -2
- package/dist/package.json +1 -1
- package/dist/utils/command_utils.js +34 -34
- package/package.json +1 -1
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
9
11
|
const command_utils_1 = require("../../utils/command_utils");
|
|
10
12
|
const config_utils_1 = require("../../utils/config_utils");
|
|
11
13
|
const string_utils_1 = require("../../utils/string_utils");
|
|
12
14
|
const cloving_gpt_1 = __importDefault(require("../../cloving_gpt"));
|
|
13
|
-
const fs_1 = __importDefault(require("fs"));
|
|
14
|
-
const path_1 = __importDefault(require("path"));
|
|
15
15
|
const generateCodePrompt = (prompt, files, contextFiles, previousCode) => {
|
|
16
16
|
const specialFileContents = (0, command_utils_1.collectSpecialFileContents)();
|
|
17
17
|
const specialFiles = Object.keys(specialFileContents).map((file) => `### Contents of ${file}\n\n${JSON.stringify(specialFileContents[file], null, 2)}\n\n`).join('\n');
|
|
@@ -100,8 +100,33 @@ const displayGeneratedCode = (rawCodeCommand) => {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
|
-
const
|
|
103
|
+
const saveGeneratedFiles = async (files, fileContents) => {
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
if (fileContents[file]) {
|
|
106
|
+
const filePath = path_1.default.resolve(file);
|
|
107
|
+
await fs_1.default.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
108
|
+
await fs_1.default.promises.writeFile(filePath, fileContents[file]);
|
|
109
|
+
console.log(`${file} has been saved.`);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.log(`File content not found for ${file}.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const updateContextFiles = async (contextFiles, files, fileContents) => {
|
|
117
|
+
for (const file of files) {
|
|
118
|
+
if (fileContents[file]) {
|
|
119
|
+
contextFiles[file] = fileContents[file];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contextFiles, options) => {
|
|
104
124
|
const [files, fileContents] = (0, string_utils_1.extractFilesAndContent)(rawCodeCommand);
|
|
125
|
+
if (options.save) {
|
|
126
|
+
await saveGeneratedFiles(files, fileContents);
|
|
127
|
+
await updateContextFiles(contextFiles, files, fileContents);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
105
130
|
const { action } = await inquirer_1.default.prompt([
|
|
106
131
|
{
|
|
107
132
|
type: 'list',
|
|
@@ -127,9 +152,25 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
127
152
|
message: 'How would you like to modify the output:',
|
|
128
153
|
},
|
|
129
154
|
]);
|
|
155
|
+
let includeMoreFiles = true;
|
|
156
|
+
while (includeMoreFiles) {
|
|
157
|
+
const { contextFile } = await inquirer_1.default.prompt([
|
|
158
|
+
{
|
|
159
|
+
type: 'input',
|
|
160
|
+
name: 'contextFile',
|
|
161
|
+
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
if (contextFile) {
|
|
165
|
+
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
includeMoreFiles = false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
130
171
|
const newRawCodeCommand = await generateCode(gpt, newPrompt, allSrcFiles, contextFiles, rawCodeCommand);
|
|
131
172
|
displayGeneratedCode(newRawCodeCommand);
|
|
132
|
-
await handleUserAction(gpt, newRawCodeCommand, newPrompt, allSrcFiles, contextFiles);
|
|
173
|
+
await handleUserAction(gpt, newRawCodeCommand, newPrompt, allSrcFiles, contextFiles, options);
|
|
133
174
|
break;
|
|
134
175
|
case 'explain':
|
|
135
176
|
const explainPrompt = generateExplainCodePrompt(rawCodeCommand);
|
|
@@ -184,9 +225,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
184
225
|
]);
|
|
185
226
|
if (fileContents[fileToSave]) {
|
|
186
227
|
const filePath = path_1.default.resolve(fileToSave);
|
|
187
|
-
fs_1.default.
|
|
188
|
-
fs_1.default.
|
|
228
|
+
await fs_1.default.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
229
|
+
await fs_1.default.promises.writeFile(filePath, fileContents[fileToSave]);
|
|
189
230
|
console.log(`${fileToSave} has been saved.`);
|
|
231
|
+
await updateContextFiles(contextFiles, [fileToSave], fileContents);
|
|
190
232
|
}
|
|
191
233
|
else {
|
|
192
234
|
console.log('File content not found.');
|
|
@@ -203,80 +245,45 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
203
245
|
}
|
|
204
246
|
break;
|
|
205
247
|
case 'saveAll':
|
|
206
|
-
files
|
|
207
|
-
|
|
208
|
-
const filePath = path_1.default.resolve(file);
|
|
209
|
-
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
210
|
-
fs_1.default.writeFileSync(filePath, fileContents[file]);
|
|
211
|
-
console.log(`${file} has been saved.`);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
console.log(`File content not found for ${file}.`);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
248
|
+
await saveGeneratedFiles(files, fileContents);
|
|
249
|
+
await updateContextFiles(contextFiles, files, fileContents);
|
|
217
250
|
console.log('All files have been saved.');
|
|
218
251
|
break;
|
|
219
252
|
case 'done':
|
|
220
253
|
break;
|
|
221
254
|
}
|
|
222
255
|
};
|
|
223
|
-
const addFilesToContext = async (contextFiles, filePath) => {
|
|
224
|
-
const stats = fs_1.default.statSync(filePath);
|
|
225
|
-
if (stats.isDirectory()) {
|
|
226
|
-
const files = fs_1.default.readdirSync(filePath);
|
|
227
|
-
for (const file of files) {
|
|
228
|
-
await addFilesToContext(contextFiles, path_1.default.join(filePath, file));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
else if (stats.isFile()) {
|
|
232
|
-
const content = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
233
|
-
contextFiles[filePath] = content;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
256
|
const code = async (options) => {
|
|
237
257
|
let { prompt, files } = options;
|
|
238
258
|
options.silent = (0, config_utils_1.getConfig)(options).globalSilent || false;
|
|
239
259
|
const gpt = new cloving_gpt_1.default(options);
|
|
240
260
|
const allSrcFiles = await (0, config_utils_1.getAllFiles)(options, false);
|
|
241
|
-
|
|
261
|
+
let contextFiles = {};
|
|
242
262
|
try {
|
|
243
263
|
if (files) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
264
|
+
for (const file of files) {
|
|
265
|
+
const filePath = path_1.default.resolve(file);
|
|
266
|
+
if (await fs_1.default.promises.stat(filePath).then(stat => stat.isFile()).catch(() => false)) {
|
|
267
|
+
const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
|
|
268
|
+
contextFiles[file] = content;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
247
271
|
}
|
|
248
272
|
else {
|
|
249
|
-
let firstFile = true;
|
|
250
273
|
let includeMoreFiles = true;
|
|
251
274
|
while (includeMoreFiles) {
|
|
252
|
-
const {
|
|
275
|
+
const { contextFile } = await inquirer_1.default.prompt([
|
|
253
276
|
{
|
|
254
|
-
type: '
|
|
255
|
-
name: '
|
|
256
|
-
message: `
|
|
257
|
-
default: true,
|
|
277
|
+
type: 'input',
|
|
278
|
+
name: 'contextFile',
|
|
279
|
+
message: `Enter the relative path of a file or directory you would like to include as context (or press enter to continue):`,
|
|
258
280
|
},
|
|
259
281
|
]);
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
type: 'input',
|
|
266
|
-
name: 'contextFile',
|
|
267
|
-
message: 'Enter the relative path of a file or directory you would like to include as context:',
|
|
268
|
-
},
|
|
269
|
-
]);
|
|
270
|
-
if (contextFile) {
|
|
271
|
-
const filePath = path_1.default.resolve(contextFile);
|
|
272
|
-
if (fs_1.default.existsSync(filePath)) {
|
|
273
|
-
await addFilesToContext(contextFiles, filePath);
|
|
274
|
-
console.log(`Added ${filePath} to context.`);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
console.log(`File or directory ${contextFile} does not exist.`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
282
|
+
if (contextFile) {
|
|
283
|
+
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
includeMoreFiles = false;
|
|
280
287
|
}
|
|
281
288
|
}
|
|
282
289
|
}
|
|
@@ -290,36 +297,58 @@ const code = async (options) => {
|
|
|
290
297
|
]);
|
|
291
298
|
prompt = userPrompt;
|
|
292
299
|
}
|
|
293
|
-
|
|
294
|
-
// Check if the files exist
|
|
295
|
-
const nonExistentFiles = files.filter(file => !fs_1.default.existsSync(file));
|
|
296
|
-
if (nonExistentFiles.length > 0) {
|
|
297
|
-
throw new Error(`The following files do not exist: ${nonExistentFiles.join(', ')}`);
|
|
298
|
-
}
|
|
299
|
-
// Read the content of the provided files
|
|
300
|
-
for (const file of files) {
|
|
301
|
-
await addFilesToContext(contextFiles, file);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const rawCodeCommand = await generateCode(gpt, prompt, allSrcFiles, contextFiles);
|
|
300
|
+
let rawCodeCommand = await generateCode(gpt, prompt, allSrcFiles, contextFiles);
|
|
305
301
|
displayGeneratedCode(rawCodeCommand);
|
|
306
302
|
if (options.save) {
|
|
307
303
|
const [files, fileContents] = (0, string_utils_1.extractFilesAndContent)(rawCodeCommand);
|
|
308
|
-
files
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
304
|
+
await saveGeneratedFiles(files, fileContents);
|
|
305
|
+
await updateContextFiles(contextFiles, files, fileContents);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
await handleUserAction(gpt, rawCodeCommand, prompt, allSrcFiles, contextFiles, options);
|
|
309
|
+
}
|
|
310
|
+
if (options.interactive) {
|
|
311
|
+
let continueInteractive = true;
|
|
312
|
+
while (continueInteractive) {
|
|
313
|
+
const { newPrompt } = await inquirer_1.default.prompt([
|
|
314
|
+
{
|
|
315
|
+
type: 'input',
|
|
316
|
+
name: 'newPrompt',
|
|
317
|
+
message: 'Revise the code (or press enter to finish):',
|
|
318
|
+
},
|
|
319
|
+
]);
|
|
320
|
+
if (newPrompt.trim() === '') {
|
|
321
|
+
continueInteractive = false;
|
|
314
322
|
}
|
|
315
323
|
else {
|
|
316
|
-
|
|
324
|
+
let includeMoreFiles = true;
|
|
325
|
+
while (includeMoreFiles) {
|
|
326
|
+
const { contextFile } = await inquirer_1.default.prompt([
|
|
327
|
+
{
|
|
328
|
+
type: 'input',
|
|
329
|
+
name: 'contextFile',
|
|
330
|
+
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
331
|
+
},
|
|
332
|
+
]);
|
|
333
|
+
if (contextFile) {
|
|
334
|
+
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
includeMoreFiles = false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
rawCodeCommand = await generateCode(gpt, newPrompt, allSrcFiles, contextFiles, rawCodeCommand);
|
|
341
|
+
displayGeneratedCode(rawCodeCommand);
|
|
342
|
+
if (options.save || options.interactive) {
|
|
343
|
+
const [files, fileContents] = (0, string_utils_1.extractFilesAndContent)(rawCodeCommand);
|
|
344
|
+
await saveGeneratedFiles(files, fileContents);
|
|
345
|
+
await updateContextFiles(contextFiles, files, fileContents);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
await handleUserAction(gpt, rawCodeCommand, newPrompt, allSrcFiles, contextFiles, options);
|
|
349
|
+
}
|
|
317
350
|
}
|
|
318
|
-
}
|
|
319
|
-
console.log('All files have been saved.');
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
await handleUserAction(gpt, rawCodeCommand, prompt, allSrcFiles, contextFiles);
|
|
351
|
+
}
|
|
323
352
|
}
|
|
324
353
|
}
|
|
325
354
|
catch (error) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
7
|
+
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
8
|
+
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
9
|
+
const command_utils_1 = require("../../utils/command_utils");
|
|
10
|
+
const config_utils_1 = require("../../utils/config_utils");
|
|
11
|
+
const generateContextPrompt = (files, contextFiles) => {
|
|
12
|
+
const specialFileContents = (0, command_utils_1.collectSpecialFileContents)();
|
|
13
|
+
const specialFiles = Object.keys(specialFileContents).map((file) => `### Contents of ${file}\n\n${JSON.stringify(specialFileContents[file], null, 2)}\n\n`).join('\n');
|
|
14
|
+
const contextFileContents = Object.keys(contextFiles).map((file) => `### Contents of ${file}\n\n${contextFiles[file]}\n\n`).join('\n');
|
|
15
|
+
return `### Description of App
|
|
16
|
+
|
|
17
|
+
${JSON.stringify((0, config_utils_1.getClovingConfig)(), null, 2)}
|
|
18
|
+
|
|
19
|
+
${specialFiles}
|
|
20
|
+
|
|
21
|
+
${contextFileContents}
|
|
22
|
+
|
|
23
|
+
### Directory structure
|
|
24
|
+
|
|
25
|
+
${files.join('\n')}`;
|
|
26
|
+
};
|
|
27
|
+
const context = async (options) => {
|
|
28
|
+
options.silent = (0, config_utils_1.getConfig)(options).globalSilent || false;
|
|
29
|
+
const allSrcFiles = await (0, config_utils_1.getAllFiles)(options, false);
|
|
30
|
+
let contextFiles = {};
|
|
31
|
+
try {
|
|
32
|
+
let includeMoreFiles = true;
|
|
33
|
+
while (includeMoreFiles) {
|
|
34
|
+
const { contextFile } = await inquirer_1.default.prompt([
|
|
35
|
+
{
|
|
36
|
+
type: 'input',
|
|
37
|
+
name: 'contextFile',
|
|
38
|
+
message: `Enter the relative path of a file or directory you would like to include as context (or press enter to continue):`,
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
41
|
+
if (contextFile) {
|
|
42
|
+
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
includeMoreFiles = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const contextPrompt = generateContextPrompt(allSrcFiles, contextFiles);
|
|
49
|
+
console.log('\nGenerated Context Prompt:');
|
|
50
|
+
console.log((0, cli_highlight_1.default)(contextPrompt, { language: 'markdown' }));
|
|
51
|
+
const { copyToClipboard } = await inquirer_1.default.prompt([
|
|
52
|
+
{
|
|
53
|
+
type: 'confirm',
|
|
54
|
+
name: 'copyToClipboard',
|
|
55
|
+
message: 'Do you want to copy the context prompt to your clipboard?',
|
|
56
|
+
default: true,
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
if (copyToClipboard) {
|
|
60
|
+
copy_paste_1.default.copy(contextPrompt, () => {
|
|
61
|
+
console.log('Context prompt copied to clipboard');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('Could not generate context', error);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.default = context;
|
package/dist/commands/init.js
CHANGED
|
@@ -42,18 +42,15 @@ technologies used. This will provide better context for future Cloving requests.
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
if (!(0, command_utils_1.checkForSpecialFiles)()) {
|
|
45
|
-
const {
|
|
45
|
+
const { technologies } = await inquirer_1.default.prompt([
|
|
46
46
|
{
|
|
47
|
-
type: '
|
|
48
|
-
name: '
|
|
49
|
-
message: 'No special files detected.
|
|
50
|
-
|
|
47
|
+
type: 'input',
|
|
48
|
+
name: 'technologies',
|
|
49
|
+
message: 'No special files detected. Please describe the main technologies used in your project:',
|
|
50
|
+
validate: (input) => input.trim().length > 0 || 'Please provide a description of the technologies used.',
|
|
51
51
|
},
|
|
52
52
|
]);
|
|
53
|
-
|
|
54
|
-
console.log('Operation aborted by the user.');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
53
|
+
specialFileContents['description'] = technologies;
|
|
57
54
|
}
|
|
58
55
|
const tempFilePath = path_1.default.join(os_1.default.tmpdir(), `describe_${Date.now()}.tmp`);
|
|
59
56
|
try {
|
|
@@ -73,10 +70,6 @@ technologies used. This will provide better context for future Cloving requests.
|
|
|
73
70
|
}
|
|
74
71
|
});
|
|
75
72
|
const limitedFileList = filteredFileList.slice(0, 100);
|
|
76
|
-
if (specialFileNames.length === 0) {
|
|
77
|
-
console.error('No special files found.');
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
73
|
const projectDetails = {
|
|
81
74
|
files: limitedFileList,
|
|
82
75
|
specialFiles: specialFileContents
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const models_1 = __importDefault(require("./commands/models"));
|
|
|
13
13
|
const shell_1 = __importDefault(require("./commands/generate/shell"));
|
|
14
14
|
const code_1 = __importDefault(require("./commands/generate/code"));
|
|
15
15
|
const commit_1 = __importDefault(require("./commands/generate/commit"));
|
|
16
|
+
const context_1 = __importDefault(require("./commands/generate/context"));
|
|
16
17
|
const unit_tests_1 = __importDefault(require("./commands/generate/unit_tests"));
|
|
17
18
|
const review_1 = __importDefault(require("./commands/generate/review"));
|
|
18
19
|
const init_2 = __importDefault(require("./commands/project/init"));
|
|
@@ -69,9 +70,10 @@ generate
|
|
|
69
70
|
.command('code')
|
|
70
71
|
.alias('c')
|
|
71
72
|
.description('Generate code based on a prompt')
|
|
72
|
-
.option('--save', 'Automatically save all files
|
|
73
|
+
.option('--save', 'Automatically save all files after generating the code')
|
|
74
|
+
.option('-i, --interactive', 'Auto-save generated code and then show a new prompt with existing context to revise the code further')
|
|
73
75
|
.option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
|
|
74
|
-
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5
|
|
76
|
+
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5:sonnet-20240620)')
|
|
75
77
|
.option('-p, --prompt <prompt>', 'Specify the prompt to use')
|
|
76
78
|
.option('-f, --files <filenames...>', 'Specify filenames of files with context to use for generating code')
|
|
77
79
|
.action(code_1.default);
|
|
@@ -81,6 +83,10 @@ generate
|
|
|
81
83
|
.option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
|
|
82
84
|
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
|
|
83
85
|
.action(commit_1.default);
|
|
86
|
+
generate
|
|
87
|
+
.command('context')
|
|
88
|
+
.description('Create a context string for generating code')
|
|
89
|
+
.action(context_1.default);
|
|
84
90
|
generate
|
|
85
91
|
.command('unit-tests')
|
|
86
92
|
.alias('u')
|
package/dist/package.json
CHANGED
|
@@ -3,40 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readFileContent = exports.fetchModels = exports.runCommand = exports.generateFileList = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = void 0;
|
|
6
|
+
exports.addFileOrDirectoryToContext = exports.readFileContent = exports.fetchModels = exports.runCommand = exports.generateFileList = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const config_utils_1 = require("./config_utils");
|
|
9
11
|
exports.SPECIAL_FILES = [
|
|
10
|
-
'package.json',
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'pom.xml',
|
|
16
|
-
'build.gradle',
|
|
17
|
-
'.csproj',
|
|
18
|
-
'packages.config',
|
|
19
|
-
'composer.json',
|
|
20
|
-
'CMakeLists.txt',
|
|
21
|
-
'conanfile.txt',
|
|
22
|
-
'conanfile.py',
|
|
23
|
-
'go.mod',
|
|
24
|
-
'Cargo.toml',
|
|
25
|
-
'Package.swift',
|
|
26
|
-
'build.gradle.kts',
|
|
27
|
-
'Podfile',
|
|
28
|
-
'Cartfile',
|
|
29
|
-
'cpanfile',
|
|
30
|
-
'DESCRIPTION',
|
|
31
|
-
'mix.exs',
|
|
32
|
-
'build.sbt',
|
|
33
|
-
'pubspec.yaml',
|
|
34
|
-
'stack.yaml',
|
|
35
|
-
'cabal.project',
|
|
36
|
-
'Project.toml',
|
|
37
|
-
'rockspec',
|
|
38
|
-
'rebar.config',
|
|
39
|
-
'project.clj'
|
|
12
|
+
'package.json', 'Gemfile', 'requirements.txt', 'Pipfile', 'pyproject.toml', 'pom.xml', 'build.gradle',
|
|
13
|
+
'.csproj', 'packages.config', 'composer.json', 'CMakeLists.txt', 'conanfile.txt', 'conanfile.py',
|
|
14
|
+
'go.mod', 'Cargo.toml', 'Package.swift', 'build.gradle.kts', 'Podfile', 'Cartfile', 'cpanfile',
|
|
15
|
+
'DESCRIPTION', 'mix.exs', 'build.sbt', 'pubspec.yaml', 'stack.yaml', 'cabal.project', 'Project.toml',
|
|
16
|
+
'rockspec', 'rebar.config', 'project.clj'
|
|
40
17
|
];
|
|
41
18
|
const collectSpecialFileContents = () => {
|
|
42
19
|
const specialFileContents = {};
|
|
@@ -54,9 +31,7 @@ const collectSpecialFileContents = () => {
|
|
|
54
31
|
return specialFileContents;
|
|
55
32
|
};
|
|
56
33
|
exports.collectSpecialFileContents = collectSpecialFileContents;
|
|
57
|
-
const checkForSpecialFiles = () =>
|
|
58
|
-
return exports.SPECIAL_FILES.some(file => fs_1.default.existsSync(file));
|
|
59
|
-
};
|
|
34
|
+
const checkForSpecialFiles = () => exports.SPECIAL_FILES.some(file => fs_1.default.existsSync(file));
|
|
60
35
|
exports.checkForSpecialFiles = checkForSpecialFiles;
|
|
61
36
|
const generateFileList = async () => {
|
|
62
37
|
try {
|
|
@@ -115,3 +90,28 @@ const readFileContent = (file) => {
|
|
|
115
90
|
}
|
|
116
91
|
};
|
|
117
92
|
exports.readFileContent = readFileContent;
|
|
93
|
+
const addFileOrDirectoryToContext = async (contextFile, contextFiles, options) => {
|
|
94
|
+
const filePath = path_1.default.resolve(contextFile);
|
|
95
|
+
if (await fs_1.default.promises.stat(filePath).then(stat => stat.isDirectory()).catch(() => false)) {
|
|
96
|
+
// Add all files in the specified directory
|
|
97
|
+
const files = await (0, config_utils_1.getAllFiles)(options, false);
|
|
98
|
+
for (const file of files) {
|
|
99
|
+
// if the file is in the same directory as the context file, add it to the context
|
|
100
|
+
if (path_1.default.dirname(file) === path_1.default.dirname(filePath)) {
|
|
101
|
+
const content = await fs_1.default.promises.readFile(file, 'utf-8');
|
|
102
|
+
contextFiles[path_1.default.relative(process.cwd(), file)] = content;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
console.log(`Added contents of ${contextFile} to context.`);
|
|
106
|
+
}
|
|
107
|
+
else if (await fs_1.default.promises.stat(filePath).then(stat => stat.isFile()).catch(() => false)) {
|
|
108
|
+
const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
|
|
109
|
+
contextFiles[contextFile] = content;
|
|
110
|
+
console.log(`Added ${filePath} to context.`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log(`File or directory ${contextFile} does not exist.`);
|
|
114
|
+
}
|
|
115
|
+
return contextFiles;
|
|
116
|
+
};
|
|
117
|
+
exports.addFileOrDirectoryToContext = addFileOrDirectoryToContext;
|