import * as plugins from './commitinfo.plugins.js'; 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; constructor(projectDirArg: string, plannedCommitVersionTypeArg: 'patch' | 'minor' | 'major') { this.projectDir = projectDirArg; this.plannedCommitVersionTypeArg = plannedCommitVersionTypeArg; this.projectinfoNpmPromise = plugins.projectinfo.ProjectinfoNpm.create(projectDirArg); } private async getProjectinfoNpmRef(): Promise { if (!this.projectinfoNpmRef) { this.projectinfoNpmRef = await this.projectinfoNpmPromise; } return this.projectinfoNpmRef; } public async getNextPlannedVersion() { const projectinfoNpmRef = await this.getProjectinfoNpmRef(); this.smartVersionRef = new plugins.smartversion.SmartVersion(projectinfoNpmRef.version); return this.smartVersionRef.getNewVersion(this.plannedCommitVersionTypeArg); } public async writeIntoPotentialDirs(potentialDirs: string[] = ['ts', 'ts_web']) { const projectinfoNpmRef = await this.getProjectinfoNpmRef(); const expectedDefinitiveVersion = await this.getNextPlannedVersion(); for (const dir of potentialDirs) { const dirPath = plugins.path.join(this.projectDir, dir); const dirExists = plugins.fs.existsSync(dirPath) && plugins.fs.statSync(dirPath).isDirectory(); if (dirExists) { const writePath = plugins.path.join(this.projectDir, dir, '00_commitinfo_data.ts'); await plugins.fs.promises.writeFile( writePath, `/** * autocreated commitinfo by @push.rocks/commitinfo */ export const commitinfo = { name: '${projectinfoNpmRef.name}', version: '${expectedDefinitiveVersion.versionString}', description: '${projectinfoNpmRef.packageJson.description}' } `, 'utf8' ); } } } }