Skip to content

Commit

Permalink
refactor: clean up cli messaging
Browse files Browse the repository at this point in the history
refactor: clean up cli messaging
  • Loading branch information
eglavin committed Apr 18, 2024
2 parents 623bb65 + e1638a8 commit 630d957
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ async function runFork() {
const logger = new Logger(config);
const fileManager = new FileManager(config, logger);

logger.log(`Running Fork: ${new Date().toLocaleString()}`);
logger.log(config.dryRun ? "Dry run, no changes will be written to disk.\n" : "");
logger.log(`Running fork-version: ${new Date().toLocaleString()}`);
logger.log(config.dryRun ? "[DRY RUN] No changes will be written to disk.\n" : "\n");

const current = await getCurrentVersion(config, logger, fileManager);
const next = await getNextVersion(config, logger, current.version);
Expand Down
4 changes: 2 additions & 2 deletions src/process/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export async function completedMessage(
const git = new Git(config, logger);

// Print git push command
const branchName = (await git.revParse("--abbrev-ref", "HEAD")).trim();
const branchName = await git.currentBranch();

logger.log(
`Run \`git push --follow-tags origin ${branchName}\` to push the changes and the tag.`,
`\nRun \`git push --follow-tags origin ${branchName}\` to push the changes and the tag.`,
);

// Print npm publish command
Expand Down
1 change: 0 additions & 1 deletion src/strategies/file-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class FileManager implements IFileManager {
*/
public write(filePath: string, newVersion: string): void {
if (this.config.dryRun) {
this.logger.log(`[Dry run]: Not updating ${filePath}`);
return;
}

Expand Down
23 changes: 16 additions & 7 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,40 @@ export class Git {
this.add = this.add.bind(this);
this.commit = this.commit.bind(this);
this.tag = this.tag.bind(this);
this.revParse = this.revParse.bind(this);
this.currentBranch = this.currentBranch.bind(this);
}

public add(...args: (string | undefined)[]) {
if (this.config.dryRun) {
return Promise.resolve("");
}

return this.execGit("add", args.filter(Boolean) as string[]);
}

public commit(...args: (string | undefined)[]) {
if (this.config.dryRun) {
return Promise.resolve("");
}

return this.execGit("commit", args.filter(Boolean) as string[]);
}

public tag(...args: (string | undefined)[]) {
if (this.config.dryRun) {
return Promise.resolve("");
}

return this.execGit("tag", args.filter(Boolean) as string[]);
}

public revParse(...args: (string | undefined)[]) {
return this.execGit("rev-parse", args.filter(Boolean) as string[]);
public async currentBranch() {
return (await this.execGit("rev-parse", ["--abbrev-ref", "HEAD"])).trim();
}

private execGit(command: string, args: string[]): Promise<string> {
if (this.config.dryRun) {
return Promise.resolve("");
}

this.logger.debug(`Executing: git ${command} ${args.join(" ")}`);

return new Promise((onResolve, onReject) => {
execFile(
"git",
Expand Down

0 comments on commit 630d957

Please sign in to comment.