Files
commitinfo/ts/commitinfo.classes.commitinfo.ts
T

55 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-25 09:58:42 +02:00
import * as plugins from './commitinfo.plugins.js';
2022-04-26 16:57:02 +02:00
export class CommitInfo {
// Instance
public projectDir: string;
public plannedCommitVersionTypeArg: 'patch' | 'minor' | 'major';
public projectinfoNpmRef: plugins.projectinfo.ProjectinfoNpm | undefined;
public smartVersionRef: plugins.smartversion.SmartVersion | undefined;
private projectinfoNpmPromise: Promise<plugins.projectinfo.ProjectinfoNpm>;
2022-04-26 16:57:02 +02:00
constructor(projectDirArg: string, plannedCommitVersionTypeArg: 'patch' | 'minor' | 'major') {
this.projectDir = projectDirArg;
this.plannedCommitVersionTypeArg = plannedCommitVersionTypeArg;
this.projectinfoNpmPromise = plugins.projectinfo.ProjectinfoNpm.create(projectDirArg);
}
private async getProjectinfoNpmRef(): Promise<plugins.projectinfo.ProjectinfoNpm> {
if (!this.projectinfoNpmRef) {
this.projectinfoNpmRef = await this.projectinfoNpmPromise;
}
return this.projectinfoNpmRef;
2022-04-26 16:57:02 +02:00
}
2024-06-23 12:57:23 +02:00
public async getNextPlannedVersion() {
const projectinfoNpmRef = await this.getProjectinfoNpmRef();
this.smartVersionRef = new plugins.smartversion.SmartVersion(projectinfoNpmRef.version);
2024-06-23 12:57:23 +02:00
return this.smartVersionRef.getNewVersion(this.plannedCommitVersionTypeArg);
}
2022-04-26 16:57:02 +02:00
public async writeIntoPotentialDirs(potentialDirs: string[] = ['ts', 'ts_web']) {
const projectinfoNpmRef = await this.getProjectinfoNpmRef();
2024-06-23 12:57:23 +02:00
const expectedDefinitiveVersion = await this.getNextPlannedVersion();
2022-04-26 16:57:02 +02:00
for (const dir of potentialDirs) {
const dirPath = plugins.path.join(this.projectDir, dir);
const dirExists = plugins.fs.existsSync(dirPath) && plugins.fs.statSync(dirPath).isDirectory();
2022-04-26 16:57:02 +02:00
if (dirExists) {
const writePath = plugins.path.join(this.projectDir, dir, '00_commitinfo_data.ts');
await plugins.fs.promises.writeFile(
writePath,
2022-04-26 16:59:15 +02:00
`/**
2024-06-23 12:57:23 +02:00
* autocreated commitinfo by @push.rocks/commitinfo
2022-04-26 16:59:15 +02:00
*/
2022-04-28 11:24:27 +02:00
export const commitinfo = {
name: '${projectinfoNpmRef.name}',
2022-04-28 11:24:27 +02:00
version: '${expectedDefinitiveVersion.versionString}',
description: '${projectinfoNpmRef.packageJson.description}'
2022-04-28 11:24:27 +02:00
}
2022-04-26 17:03:15 +02:00
`,
'utf8'
2022-04-26 16:57:02 +02:00
);
}
}
}
}