commitinfo/ts/commitinfo.classes.commitinfo.ts
2024-06-23 12:57:23 +02:00

42 lines
1.6 KiB
TypeScript

import * as plugins from './commitinfo.plugins.js';
export class CommitInfo {
// Instance
public projectDir: string;
public plannedCommitVersionTypeArg: 'patch' | 'minor' | 'major';
public projectinfoNpmRef: plugins.projectinfo.ProjectinfoNpm;
public smartVersionRef: plugins.smartversion.SmartVersion;
constructor(projectDirArg: string, plannedCommitVersionTypeArg: 'patch' | 'minor' | 'major') {
this.projectDir = projectDirArg;
this.plannedCommitVersionTypeArg = plannedCommitVersionTypeArg;
this.projectinfoNpmRef = new plugins.projectinfo.ProjectinfoNpm(projectDirArg);
this.smartVersionRef = new plugins.smartversion.SmartVersion(this.projectinfoNpmRef.version);
}
public async getNextPlannedVersion() {
return this.smartVersionRef.getNewVersion(this.plannedCommitVersionTypeArg);
}
public async writeIntoPotentialDirs(potentialDirs: string[] = ['ts', 'ts_web']) {
const expectedDefinitiveVersion = await this.getNextPlannedVersion();
for (const dir of potentialDirs) {
const dirExists = plugins.smartfile.fs.isDirectory(plugins.path.join(this.projectDir, dir));
if (dirExists) {
const writePath = plugins.path.join(this.projectDir, dir, '00_commitinfo_data.ts');
await plugins.smartfile.memory.toFs(
`/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '${this.projectinfoNpmRef.name}',
version: '${expectedDefinitiveVersion.versionString}',
description: '${this.projectinfoNpmRef.packageJson.description}'
}
`,
writePath
);
}
}
}
}