cloving 0.1.12 → 0.1.13
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.
|
@@ -62,29 +62,6 @@ Do not add any commentary or context to the message other than the commit messag
|
|
|
62
62
|
An example of the output for this should look like the following:
|
|
63
63
|
\`\`\`
|
|
64
64
|
|
|
65
|
-
2. **src/commands/generate/code.ts**
|
|
66
|
-
|
|
67
|
-
\`\`\`typescript
|
|
68
|
-
import ncp from 'copy-paste'
|
|
69
|
-
import inquirer from 'inquirer'
|
|
70
|
-
import highlight from 'cli-highlight'
|
|
71
|
-
import { collectSpecialFileContents } from '../../utils/command_utils'
|
|
72
|
-
import { getConfig, getClovingConfig, getAllFiles } from '../../utils/config_utils'
|
|
73
|
-
import { parseMarkdownInstructions, extractMarkdown } from '../../utils/string_utils'
|
|
74
|
-
import ClovingGPT from '../../cloving_gpt'
|
|
75
|
-
import type { ClovingGPTOptions } from '../../utils/types'
|
|
76
|
-
import fs from 'fs'
|
|
77
|
-
import path from 'path'
|
|
78
|
-
|
|
79
|
-
const generateCodePrompt = (prompt: string | undefined, files: string[], contextFiles: Record<string, string>, previousCode?: string): string => {
|
|
80
|
-
const specialFileContents = collectSpecialFileContents()
|
|
81
|
-
const specialFiles = Object.keys(specialFileContents).map((file) => \`### Contents of \${file}\\n\\n\${JSON.stringify(specialFileContents[file], null, 2)}\\n\\n\`).join('\\n')
|
|
82
|
-
const contextFileContents = Object.keys(contextFiles).map((file) => \`### Contents of \${file}\\n\\n\${contextFiles[file]}\\n\\n\`).join('\\n')
|
|
83
|
-
|
|
84
|
-
return 'Here is a description of my app:'
|
|
85
|
-
}
|
|
86
|
-
\`\`\`
|
|
87
|
-
|
|
88
65
|
### Request
|
|
89
66
|
|
|
90
67
|
Generate code that does the following: ${prompt}
|
|
@@ -94,8 +71,10 @@ Do not use any data from the example response structure, only use the structure.
|
|
|
94
71
|
};
|
|
95
72
|
const generateExplainCodePrompt = (prompt) => {
|
|
96
73
|
return `${prompt}
|
|
97
|
-
|
|
98
|
-
|
|
74
|
+
|
|
75
|
+
## Task
|
|
76
|
+
|
|
77
|
+
Please briefly explain how the code works in this.`;
|
|
99
78
|
};
|
|
100
79
|
const generateCode = async (gpt, prompt, allSrcFiles, contextFiles, previousCode) => {
|
|
101
80
|
const codePrompt = generateCodePrompt(prompt, allSrcFiles, contextFiles, previousCode);
|
|
@@ -275,7 +254,7 @@ const code = async (options) => {
|
|
|
275
254
|
type: 'confirm',
|
|
276
255
|
name: 'includeMore',
|
|
277
256
|
message: `Do you want to include any${firstFile ? '' : ' other'} files or directories as context for the prompt?`,
|
|
278
|
-
default:
|
|
257
|
+
default: true,
|
|
279
258
|
},
|
|
280
259
|
]);
|
|
281
260
|
firstFile = false;
|
|
@@ -324,7 +303,24 @@ const code = async (options) => {
|
|
|
324
303
|
}
|
|
325
304
|
const rawCodeCommand = await generateCode(gpt, prompt, allSrcFiles, contextFiles);
|
|
326
305
|
displayGeneratedCode(rawCodeCommand);
|
|
327
|
-
|
|
306
|
+
if (options.save) {
|
|
307
|
+
const [files, fileContents] = (0, string_utils_1.extractFilesAndContent)(rawCodeCommand);
|
|
308
|
+
files.forEach(file => {
|
|
309
|
+
if (fileContents[file]) {
|
|
310
|
+
const filePath = path_1.default.resolve(file);
|
|
311
|
+
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
312
|
+
fs_1.default.writeFileSync(filePath, fileContents[file]);
|
|
313
|
+
console.log(`${file} has been saved.`);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
console.log(`File content not found for ${file}.`);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
console.log('All files have been saved.');
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
await handleUserAction(gpt, rawCodeCommand, prompt, allSrcFiles, contextFiles);
|
|
323
|
+
}
|
|
328
324
|
}
|
|
329
325
|
catch (error) {
|
|
330
326
|
console.error('Could not generate code', error);
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ generate
|
|
|
69
69
|
.command('code')
|
|
70
70
|
.alias('c')
|
|
71
71
|
.description('Generate code based on a prompt')
|
|
72
|
+
.option('--save', 'Automatically save all files to dist after generating the code')
|
|
72
73
|
.option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
|
|
73
74
|
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
|
|
74
75
|
.option('-p, --prompt <prompt>', 'Specify the prompt to use')
|