Skip to content

Commit

Permalink
feat: create an empty changelog file when it does not yet exist and f…
Browse files Browse the repository at this point in the history
…irst release was provided (#31)
  • Loading branch information
imranbarbhuiya committed Nov 17, 2022
1 parent 06a5af7 commit 90acb2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions 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<unknown, Error>(() => writeFile(path, ''));

return !result.isErr();
}
18 changes: 13 additions & 5 deletions src/lib/preflight-checks.ts
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 90acb2a

Please sign in to comment.