Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create an empty changelog file when it does not yet exist and first release was provided #31

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
});
}
favna marked this conversation as resolved.
Show resolved Hide resolved
}

const hasGitCliff = await doActionAndLog(
Expand Down