Skip to content

Commit

Permalink
Print renames
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-rc committed Dec 5, 2023
1 parent 9871c6e commit cea7444
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/services/filesync/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Level } from "../output/log/level.js";
import { createLogger } from "../output/log/logger.js";
import type { PrintTableOptions } from "../output/log/printer.js";
import { sprint } from "../output/sprint.js";
import { isNever } from "../util/is.js";
import { isNever, isString } from "../util/is.js";
import { ensureLength } from "../util/string.js";

const log = createLogger({ name: "changes" });
Expand Down Expand Up @@ -41,7 +41,6 @@ export class Changes extends Map<string, Change> {
* @param changes - The changes to print.
* @param tense - The tense to use for the change type.
* @param limit - The maximum number of changes to print.
* @param mt - The number of empty lines to print before the changes.
*/
export const printChanges = ({
changes,
Expand All @@ -60,14 +59,22 @@ export const printChanges = ({

const created = chalk.greenBright("+ " + (tense === "past" ? "created" : "create"));
const updated = chalk.blueBright("± " + (tense === "past" ? "updated" : "update"));
const renamed = chalk.blueBright("→ " + (tense === "past" ? "renamed" : "rename"));
const deleted = chalk.redBright("- " + (tense === "past" ? "deleted" : "delete"));

const rows = Array.from(changes.entries())
.sort((a, b) => a[0].localeCompare(b[0]))
.slice(0, limit)
.map(([path, change]) => {
path = ensureLength(path, 46);
if (change.type === "create" && isString(change.oldPath)) {
path = `${ensureLength(change.oldPath, 21)}${ensureLength(path, 21)}`;
} else {
path = ensureLength(path, 45);
}

switch (true) {
case change.type === "create" && isString(change.oldPath):
return [chalk.blueBright(path), renamed];
case change.type === "create":
return [chalk.greenBright(path), created];
case change.type === "update":
Expand Down
2 changes: 1 addition & 1 deletion src/services/filesync/filesync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class FileSync {

printChanges({
changes,
tense: "past",
tense: "present",
message: sprint`→ Sent {gray ${dayjs().format("hh:mm:ss A")}}`,
});
}
Expand Down

0 comments on commit cea7444

Please sign in to comment.