feat(core): Added smarttime dependency and improved changelog generation

This commit is contained in:
Philipp Kunz 2024-06-23 18:38:34 +02:00
parent e8372effc7
commit a060cd1a03
6 changed files with 51 additions and 30 deletions

View File

@ -1,5 +1,14 @@
# Changelog # Changelog
```markdown
## [1.2.4]
### Fixed
- Refactor logger initialization to use commitinfo data
## 1.3.0
feat(core): Added smarttime dependency and improved changelog generation
```
## [1.2.4] - 1.2.4 ## [1.2.4] - 1.2.4
fix(logging): Refactor logger initialization to use commitinfo data fix(logging): Refactor logger initialization to use commitinfo data

View File

@ -39,6 +39,7 @@
"@push.rocks/smartlog-destination-local": "^9.0.2", "@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartpath": "^5.0.18", "@push.rocks/smartpath": "^5.0.18",
"@push.rocks/smartshell": "^3.0.5", "@push.rocks/smartshell": "^3.0.5",
"@push.rocks/smarttime": "^4.0.6",
"typedoc": "^0.26.0", "typedoc": "^0.26.0",
"typescript": "^5.5.2" "typescript": "^5.5.2"
}, },

3
pnpm-lock.yaml generated
View File

@ -47,6 +47,9 @@ importers:
'@push.rocks/smartshell': '@push.rocks/smartshell':
specifier: ^3.0.5 specifier: ^3.0.5
version: 3.0.5 version: 3.0.5
'@push.rocks/smarttime':
specifier: ^4.0.6
version: 4.0.6
typedoc: typedoc:
specifier: ^0.26.0 specifier: ^0.26.0
version: 0.26.0(typescript@5.5.2) version: 0.26.0(typescript@5.5.2)

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tsdoc', name: '@git.zone/tsdoc',
version: '1.2.4', version: '1.3.0',
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

@ -6,6 +6,7 @@ export interface INextCommitObject {
recommendedNextVersionLevel: 'fix' | 'feat' | 'BREAKING CHANGE'; // the recommended next version level of the project recommendedNextVersionLevel: 'fix' | 'feat' | 'BREAKING CHANGE'; // the recommended next version level of the project
recommendedNextVersionScope: string; // the recommended scope name of the next version, like "core" or "cli", or specific class names. recommendedNextVersionScope: string; // the recommended scope name of the next version, like "core" or "cli", or specific class names.
recommendedNextVersionMessage: string; // the commit message. Don't put fix() feat() or BREAKING CHANGE in the message. Please just the message itself. recommendedNextVersionMessage: string; // the commit message. Don't put fix() feat() or BREAKING CHANGE in the message. Please just the message itself.
recommendedNextVersionDetauls: string[]; // detailed bullet points for the changelog
recommendedNextVersion: string; // the recommended next version of the project, x.x.x recommendedNextVersion: string; // the recommended next version of the project, x.x.x
changelog?: string; // the changelog for the next version changelog?: string; // the changelog for the next version
} }
@ -49,10 +50,12 @@ Important: Answer only in valid JSON.
Your answer should be parseable with JSON.parse() without modifying anything. Your answer should be parseable with JSON.parse() without modifying anything.
Here is the structure of the JSON you should return: Here is the structure of the JSON you should return:
{
interface {
recommendedNextVersionLevel: 'fix' | 'feat' | 'BREAKING CHANGE'; // the recommended next version level of the project recommendedNextVersionLevel: 'fix' | 'feat' | 'BREAKING CHANGE'; // the recommended next version level of the project
recommendedNextVersionScope: string; // the recommended scope name of the next version, like "core" or "cli", or specific class names. recommendedNextVersionScope: string; // the recommended scope name of the next version, like "core" or "cli", or specific class names.
recommendedNextVersionMessage: string; // the commit message. Don't put fix() feat() or BREAKING CHANGE in the message. Please just the message itself. recommendedNextVersionMessage: string; // the commit message. Don't put fix() feat() or BREAKING CHANGE in the message. Please just the message itself.
recommendedNextVersionDetails: string[]; // detailed bullet points for the changelog
recommendedNextVersion: string; // the recommended next version of the project, x.x.x recommendedNextVersion: string; // the recommended next version of the project, x.x.x
} }
@ -76,40 +79,43 @@ Also you are given a diff
if (await plugins.smartfile.fs.fileExists(previousChangelogPath)) { if (await plugins.smartfile.fs.fileExists(previousChangelogPath)) {
previousChangelog = await plugins.smartfile.SmartFile.fromFilePath(previousChangelogPath); previousChangelog = await plugins.smartfile.SmartFile.fromFilePath(previousChangelogPath);
} }
if (!previousChangelog) {
let result2 = await this.aiDocsRef.openaiInstance.chat({ let result2 = await this.aiDocsRef.openaiInstance.chat({
messageHistory: [], messageHistory: [],
systemMessage: ` systemMessage: `
You are building a changelog file for the projext. You are building a changelog.md file for the project.
Omit commits and versions that lack relevant changes. Omit commits and versions that lack relevant changes.
You are given A changelog entry should look like this:
* the previous changelog file (if available)
## yyyy-mm-dd - x.x.x - scope here
main descriptiom here
- detailed bullet points follow
You are given:
* the commit messages of the project * the commit messages of the project
Only return the changelog file, so it can be written directly to changelog.md Only return the changelog file, so it can be written directly to changelog.md`,
For the latest version, that is not yet part of the commit messages, add a placeholder entry that uses {{nextVersion}} and {{nextVersionMessage}} as variables to filled later.
Only output newer versions and their changes compared to ones already mentioned. We take of appending your output later.
If there is no previous changelog file, generate a complete changelog from commit messages with heading and everything + the placeholder section mentioned above.
`,
userMessage: ` userMessage: `
The previous changelog file is: Here are the commit messages:
${!previousChangelog ? 'No previous changelog file found' : previousChangelog.contents.toString()}
Here are the commit messages so far: ${commitMessages.join('\n')}
${commitMessages.join('\n\n')}
`, `,
}); });
if (previousChangelog) {
let newChangelog = result2.message; previousChangelog = await plugins.smartfile.SmartFile.fromString(previousChangelogPath, result2.message, 'utf8');
newChangelog = newChangelog.replace('# Changelog\n\n', '');
let oldChangelog = previousChangelog.contents.toString().replace('# Changelog\n\n', '');
newChangelog = `# Changelog\n\n${newChangelog}\n\n${oldChangelog}`;
resultObject.changelog = newChangelog;
} else {
resultObject.changelog = result2.message;
} }
let oldChangelog = previousChangelog.contents.toString().replace('# Changelog\n\n', '');
let newDateString = new plugins.smarttime.ExtendedDate().exportToEuropeanDate();
let newChangelog = `# Changelog\n\n${
`## ${newDateString} - {{nextVersion}} - {{nextVersionScope}}
{{nextVersionMessage}}
{{nextVersionDetails}}
`}\n\n${oldChangelog}\n`;
resultObject.changelog = newChangelog;
return resultObject; return resultObject;
} }
} }

View File

@ -16,6 +16,7 @@ import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local'; import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartpath from '@push.rocks/smartpath'; import * as smartpath from '@push.rocks/smartpath';
import * as smartshell from '@push.rocks/smartshell'; import * as smartshell from '@push.rocks/smartshell';
import * as smarttime from '@push.rocks/smarttime';
export { export {
npmextra, npmextra,
@ -30,6 +31,7 @@ export {
smartlogDestinationLocal, smartlogDestinationLocal,
smartpath, smartpath,
smartshell, smartshell,
smarttime,
}; };
// third party scope // third party scope