2024-04-03 11:34:26 +00:00
|
|
|
import type { AiDoc } from '../classes.aidoc.js';
|
|
|
|
import * as plugins from '../plugins.js';
|
|
|
|
import { ProjectContext } from './projectcontext.js';
|
|
|
|
|
|
|
|
interface IDescriptionInterface {
|
|
|
|
description: string;
|
|
|
|
keywords: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Description {
|
|
|
|
// INSTANCE
|
|
|
|
private aiDocsRef: AiDoc;
|
|
|
|
private projectDir: string;
|
|
|
|
|
|
|
|
constructor(aiDocsRef: AiDoc, projectDirArg: string) {
|
|
|
|
this.aiDocsRef = aiDocsRef;
|
|
|
|
this.projectDir = projectDirArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async build() {
|
|
|
|
// we can now assemble the directory structure.
|
|
|
|
const projectContext = new ProjectContext(this.projectDir);
|
|
|
|
const contextString = await projectContext.update();
|
|
|
|
|
2024-05-17 15:38:35 +00:00
|
|
|
let result = await this.aiDocsRef.openaiInstance.chat({
|
|
|
|
systemMessage: `
|
|
|
|
You create a json adhering the following interface:
|
|
|
|
{
|
|
|
|
description: string; // a sensible short, one sentence description of the project
|
|
|
|
keywords: string[]; // an array of tags that describe the project
|
|
|
|
}
|
|
|
|
|
|
|
|
The description should be based on what you understand from the project's files.
|
|
|
|
The keywords should be based on use cases you see from the files.
|
|
|
|
Don't be cheap about the way you think.
|
2024-04-03 11:34:26 +00:00
|
|
|
|
2024-05-17 15:38:35 +00:00
|
|
|
Important: Answer only in valid JSON.
|
|
|
|
You answer should be parseable with JSON.parse() without modifying anything.
|
2024-04-03 11:34:26 +00:00
|
|
|
|
2024-05-17 15:38:35 +00:00
|
|
|
Don't wrap the JSON in three ticks json!!!
|
|
|
|
`,
|
|
|
|
messageHistory: [],
|
|
|
|
userMessage: contextString,
|
|
|
|
});
|
2024-04-03 11:34:26 +00:00
|
|
|
|
2024-05-17 15:38:35 +00:00
|
|
|
console.log(result.message);
|
|
|
|
const resultObject: IDescriptionInterface = JSON.parse(
|
2024-06-22 11:20:55 +00:00
|
|
|
result.message.replace('```json', '').replace('```', ''),
|
2024-04-03 11:34:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const npmextraJson = (await projectContext.gatherFiles()).smartfilesNpmextraJSON;
|
|
|
|
const npmextraJsonContent = JSON.parse(npmextraJson.contents.toString());
|
|
|
|
|
|
|
|
npmextraJsonContent.gitzone.module.description = resultObject.description;
|
|
|
|
npmextraJsonContent.gitzone.module.keywords = resultObject.keywords;
|
|
|
|
|
|
|
|
npmextraJson.contents = Buffer.from(JSON.stringify(npmextraJsonContent, null, 2));
|
|
|
|
await npmextraJson.write();
|
|
|
|
|
|
|
|
// do the same with packageJson
|
|
|
|
const packageJson = (await projectContext.gatherFiles()).smartfilePackageJSON;
|
|
|
|
const packageJsonContent = JSON.parse(packageJson.contents.toString());
|
|
|
|
packageJsonContent.description = resultObject.description;
|
|
|
|
packageJsonContent.keywords = resultObject.keywords;
|
|
|
|
packageJson.contents = Buffer.from(JSON.stringify(packageJsonContent, null, 2));
|
|
|
|
await packageJson.write();
|
|
|
|
|
|
|
|
console.log(`\n======================\n`);
|
|
|
|
console.log(JSON.stringify(resultObject, null, 2));
|
|
|
|
console.log(`\n======================\n`);
|
2024-05-17 15:38:35 +00:00
|
|
|
return result.message;
|
2024-04-03 11:34:26 +00:00
|
|
|
}
|
2024-05-17 15:38:35 +00:00
|
|
|
}
|