Compare commits

..

6 Commits

Author SHA1 Message Date
240d6bb314 1.1.35 2024-06-23 12:03:26 +02:00
2d0839a1da fix(core): update 2024-06-23 12:03:25 +02:00
9f250ae2b3 1.1.34 2024-06-23 11:59:39 +02:00
1223bb8567 fix(core): update 2024-06-23 11:59:38 +02:00
9395cfc166 1.1.33 2024-06-22 21:21:53 +02:00
3b4c6bd97f fix(core): update 2024-06-22 21:21:52 +02:00
6 changed files with 76 additions and 17 deletions

View File

@ -1,12 +1,13 @@
{ {
"name": "@git.zone/tsdoc", "name": "@git.zone/tsdoc",
"version": "1.1.32", "version": "1.1.35",
"private": false, "private": false,
"description": "An advanced TypeScript documentation tool using AI to generate and enhance documentation for TypeScript projects.", "description": "An advanced TypeScript documentation tool using AI to generate and enhance documentation for TypeScript projects.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module", "type": "module",
"author": "Lossless GmbH", "exports": {
".": "./dist_ts/index.js"
},
"author": "Task Venture Capital GmbH",
"license": "MIT", "license": "MIT",
"bin": { "bin": {
"tsdoc": "cli.js" "tsdoc": "cli.js"

View File

@ -15,12 +15,24 @@ tap.test('should create an AIdocs class', async () => {
tap.test('should start AIdocs', async () => { tap.test('should start AIdocs', async () => {
await aidocs.start(); await aidocs.start();
});
tap.skip.test('should start AIdocs', async () => {
await aidocs.buildReadme('./'); await aidocs.buildReadme('./');
}); });
tap.test('should start AIdocs', async () => { tap.skip.test('should start AIdocs', async () => {
await aidocs.start();
await aidocs.buildDescription('./'); await aidocs.buildDescription('./');
}); });
tap.test('should build commit object', async () => {
const commitObject = await aidocs.buildNextCommitObject('./');
console.log(commitObject);
expect(commitObject).not.toBeUndefined();
expect(commitObject).toHaveProperty('message');
expect(commitObject).toHaveProperty('recommendedNextVersion');
expect(commitObject).toHaveProperty('recommendedNextVersionLevel');
})
tap.start(); tap.start();

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tsdoc', name: '@git.zone/tsdoc',
version: '1.1.32', version: '1.1.35',
description: 'An advanced TypeScript documentation tool using AI to generate and enhance documentation for TypeScript projects.' description: 'An advanced TypeScript documentation tool using AI to generate and enhance documentation for TypeScript projects.'
} }

View File

@ -2,6 +2,13 @@ import * as plugins from '../plugins.js';
import { AiDoc } from '../classes.aidoc.js'; import { AiDoc } from '../classes.aidoc.js';
import { ProjectContext } from './projectcontext.js'; import { ProjectContext } from './projectcontext.js';
export interface INextCommitObject {
recommendedNextVersionLevel: 'patch' | 'minor' | 'major'; // the recommended next version level of the project
recommendedNextVersion: string; // the recommended next version of the project
message: string; // the commit message. use conventional commits format
changelog?: string; // the changelog
}
export class Commit { export class Commit {
private aiDocsRef: AiDoc; private aiDocsRef: AiDoc;
private projectDir: string; private projectDir: string;
@ -11,9 +18,19 @@ export class Commit {
this.projectDir = projectDirArg; this.projectDir = projectDirArg;
} }
public async build() { public async buildNextCommitObject(): Promise<INextCommitObject> {
const smartgitInstance = new plugins.smartgit.Smartgit();
await smartgitInstance.init();
const gitRepo = await plugins.smartgit.GitRepo.fromOpeningRepoDir(smartgitInstance, this.projectDir);
const diffString = await gitRepo.getUncommittedDiff();
const projectContext = new ProjectContext(this.projectDir); const projectContext = new ProjectContext(this.projectDir);
const contextString = await projectContext.update(); let contextString = await projectContext.update();
contextString = `
${contextString}
Here is the diff:
${diffString}
`
let result = await this.aiDocsRef.openaiInstance.chat({ let result = await this.aiDocsRef.openaiInstance.chat({
systemMessage: ` systemMessage: `
@ -41,15 +58,40 @@ Also you are given a diff
userMessage: contextString, userMessage: contextString,
}); });
console.log(result.message); // console.log(result.message);
const resultObject = JSON.parse(result.message.replace('```json', '').replace('```', '')); const resultObject: INextCommitObject = JSON.parse(result.message.replace('```json', '').replace('```', ''));
const npmextraJson = (await projectContext.gatherFiles()).smartfilesNpmextraJSON; // lets build the changelog based on that
const npmextraJsonContent = JSON.parse(npmextraJson.contents.toString()); const commitMessages = await gitRepo.getAllCommitMessages();
const previousChangelogPath = plugins.path.join(this.projectDir, 'changelog.md');
let previousChangelog: plugins.smartfile.SmartFile;
if (await plugins.smartfile.fs.fileExists(previousChangelogPath)) {
previousChangelog = await plugins.smartfile.SmartFile.fromFilePath(previousChangelogPath);
}
let result2 = await this.aiDocsRef.openaiInstance.chat({
messageHistory: [],
systemMessage: `
You are building a changelog file for the projext.
Omit commits and versions that lack relevant changes.
npmextraJsonContent.gitzone.module.commit = resultObject.message; You are given
* the previous changelog file (if available)
* the commit messages of the project
npmextraJson.contents = Buffer.from(JSON.stringify(npmextraJsonContent, null, 2)); Only return the changelog file, so it can be written directly to changelog.md
await npmextraJson.write();
For the latest version, that is not yet part of the commit messages, use {{nextVersion}} and {{nextDescription}} placeholders.
`,
userMessage: `
The previous changelog file is:
${(!previousChangelog) ? 'No previous changelog file found' : previousChangelog.contents.toString()}
Here are the commit messages so far:
${commitMessages.join('\n\n')}
`
})
resultObject.changelog = result2.message;
return resultObject;
} }
} }

View File

@ -1,3 +1,4 @@
export * from './commit.js';
export * from './description.js'; export * from './description.js';
export * from './projectcontext.js'; export * from './projectcontext.js';
export * from './readme.js'; export * from './readme.js';

View File

@ -85,7 +85,10 @@ export class AiDoc {
return await descriptionInstance.build(); return await descriptionInstance.build();
} }
public async buildNextCommit(projectDirArg: string) {} public async buildNextCommitObject(projectDirArg: string) {
const commitInstance = new aiDocsClasses.Commit(this, projectDirArg);
return await commitInstance.buildNextCommitObject();
}
public async getProjectContext(projectDirArg: string) { public async getProjectContext(projectDirArg: string) {
const projectContextInstance = new aiDocsClasses.ProjectContext(projectDirArg); const projectContextInstance = new aiDocsClasses.ProjectContext(projectDirArg);