diff --git a/src/lib/createFile.ts b/src/lib/createFile.ts new file mode 100644 index 0000000..d414788 --- /dev/null +++ b/src/lib/createFile.ts @@ -0,0 +1,9 @@ +import { Result } from '@sapphire/result'; +import type { PathLike } from 'node:fs'; +import { writeFile } from 'node:fs/promises'; + +export async function createFile(path: PathLike) { + const result = await Result.fromAsync(() => writeFile(path, '')); + + return !result.isErr(); +} diff --git a/src/lib/preflight-checks.ts b/src/lib/preflight-checks.ts index 9bc5dd9..ee6d2ee 100644 --- a/src/lib/preflight-checks.ts +++ b/src/lib/preflight-checks.ts @@ -6,6 +6,7 @@ import { doActionAndLog, readJson } from '#lib/utils'; import { isNullishOrEmpty } from '@sapphire/utilities'; import type { OptionValues } from 'commander'; import { join } from 'path'; +import { createFile } from './createFile'; export async function preflightChecks(options: OptionValues) { if (isNullishOrEmpty(options.name)) { @@ -72,11 +73,18 @@ export async function preflightChecks(options: OptionValues) { ); if (!hasChangelogFileAtCwd) { - logVerboseError({ - text: ['No CHANGELOG.md detected at current directory'], - exitAfterLog: true, - verbose: options.verbose - }); + if (options.firstRelease) { + await doActionAndLog( + 'Creating an empty CHANGELOG.md file in the current working directory', // + createFile(join(packageCwd, 'CHANGELOG.md')) + ); + } else { + logVerboseError({ + text: ['No CHANGELOG.md detected at current directory'], + exitAfterLog: true, + verbose: options.verbose + }); + } } const hasGitCliff = await doActionAndLog(