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';
|
2026-05-01 18:16:09 +00:00
|
|
|
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;
|
2026-05-01 18:16:09 +00:00
|
|
|
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() {
|
2026-05-01 18:16:09 +00:00
|
|
|
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']) {
|
2026-05-01 18:16:09 +00:00
|
|
|
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) {
|
2026-05-01 18:16:09 +00:00
|
|
|
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');
|
2026-05-01 18:16:09 +00:00
|
|
|
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 = {
|
2026-05-01 18:16:09 +00:00
|
|
|
name: '${projectinfoNpmRef.name}',
|
2022-04-28 11:24:27 +02:00
|
|
|
version: '${expectedDefinitiveVersion.versionString}',
|
2026-05-01 18:16:09 +00:00
|
|
|
description: '${projectinfoNpmRef.packageJson.description}'
|
2022-04-28 11:24:27 +02:00
|
|
|
}
|
2022-04-26 17:03:15 +02:00
|
|
|
`,
|
2026-05-01 18:16:09 +00:00
|
|
|
'utf8'
|
2022-04-26 16:57:02 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|