commitinfo/ts/commitinfo.classes.commitinfo.ts

42 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-04-25 07:58:42 +00:00
import * as plugins from './commitinfo.plugins.js';
2022-04-26 14:57:02 +00:00
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);
}
2024-06-23 10:57:23 +00:00
public async getNextPlannedVersion() {
return this.smartVersionRef.getNewVersion(this.plannedCommitVersionTypeArg);
}
2022-04-26 14:57:02 +00:00
public async writeIntoPotentialDirs(potentialDirs: string[] = ['ts', 'ts_web']) {
2024-06-23 10:57:23 +00:00
const expectedDefinitiveVersion = await this.getNextPlannedVersion();
2022-04-26 14:57:02 +00:00
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(
2022-04-26 14:59:15 +00:00
`/**
2024-06-23 10:57:23 +00:00
* autocreated commitinfo by @push.rocks/commitinfo
2022-04-26 14:59:15 +00:00
*/
2022-04-28 09:24:27 +00:00
export const commitinfo = {
name: '${this.projectinfoNpmRef.name}',
version: '${expectedDefinitiveVersion.versionString}',
description: '${this.projectinfoNpmRef.packageJson.description}'
}
2022-04-26 15:03:15 +00:00
`,
2022-04-26 14:57:02 +00:00
writePath
);
}
}
}
}