diff --git a/.changeset/lazy-needles-notice.md b/.changeset/lazy-needles-notice.md new file mode 100644 index 0000000..b64e4fe --- /dev/null +++ b/.changeset/lazy-needles-notice.md @@ -0,0 +1,5 @@ +--- +'@emigrate/reporter-pino': minor +--- + +Include the Emigrate CLI's version number in each log diff --git a/.changeset/pink-taxis-fold.md b/.changeset/pink-taxis-fold.md new file mode 100644 index 0000000..21ddb84 --- /dev/null +++ b/.changeset/pink-taxis-fold.md @@ -0,0 +1,5 @@ +--- +'@emigrate/cli': minor +--- + +The default reporter now prints the relative path instead of only the migration file name when logging migrations. Thanks to this most shells supports opening the corresponding migration file by clicking it. diff --git a/.changeset/thick-feet-fry.md b/.changeset/thick-feet-fry.md new file mode 100644 index 0000000..bd978c4 --- /dev/null +++ b/.changeset/thick-feet-fry.md @@ -0,0 +1,5 @@ +--- +'@emigrate/cli': minor +--- + +Print Emigrate CLI version when using the default reporter diff --git a/packages/cli/src/reporters/default.ts b/packages/cli/src/reporters/default.ts index db5a931..67104e0 100644 --- a/packages/cli/src/reporters/default.ts +++ b/packages/cli/src/reporters/default.ts @@ -1,4 +1,3 @@ -import path from 'node:path'; import { black, blueBright, bold, cyan, dim, faint, gray, green, red, redBright, yellow } from 'ansis'; import logUpdate from 'log-update'; import elegantSpinner from 'elegant-spinner'; @@ -25,10 +24,10 @@ const formatDuration = (duration: number): string => { return yellow(pretty.replaceAll(/([^\s\d]+)/g, dim('$1'))); }; -const getTitle = ({ command, directory, dry, cwd }: ReporterInitParameters) => { - return `${black.bgBlueBright(' Emigrate ').trim()} ${blueBright.bold(command)} ${gray(cwd + path.sep)}${directory}${ - dry ? yellow` (dry run)` : '' - }`; +const getTitle = ({ command, version, dry, cwd }: ReporterInitParameters) => { + return `${black.bgBlueBright(' Emigrate ').trim()} ${blueBright.bold(command)} ${blueBright(`v${version}`)} ${gray( + cwd, + )}${dry ? yellow` (dry run)` : ''}`; }; const getMigrationStatus = ( @@ -94,11 +93,12 @@ const getMigrationText = ( migration: MigrationMetadata | MigrationMetadataFinished, activeMigration?: MigrationMetadata, ) => { + const pathWithoutName = migration.relativeFilePath.slice(0, -migration.name.length); const nameWithoutExtension = migration.name.slice(0, -migration.extension.length); const status = getMigrationStatus(migration, activeMigration); const parts = [' ', getIcon(status)]; - parts.push(`${getName(nameWithoutExtension, status)}${dim(migration.extension)}`); + parts.push(`${dim(pathWithoutName)}${getName(nameWithoutExtension, status)}${dim(migration.extension)}`); if ('status' in migration) { parts.push(gray(`(${migration.status})`)); diff --git a/packages/reporter-pino/src/index.ts b/packages/reporter-pino/src/index.ts index 18af18e..ee259d3 100644 --- a/packages/reporter-pino/src/index.ts +++ b/packages/reporter-pino/src/index.ts @@ -42,7 +42,7 @@ class PinoReporter implements Required { return this.options.errorKey ?? 'error'; } - onInit({ command, ...parameters }: ReporterInitParameters): Awaitable { + onInit({ command, version, ...parameters }: ReporterInitParameters): Awaitable { this.#command = command; this.#logger = pino({ name: 'emigrate', @@ -50,6 +50,7 @@ class PinoReporter implements Required { errorKey: this.errorKey, base: { scope: command, + version, }, }); @@ -171,11 +172,14 @@ class PinoReporter implements Required { if (error) { this.#logger.error( - { failed, done, skipped, pending, total, [this.errorKey]: error }, + { result: { failed, done, skipped, pending, total }, [this.errorKey]: error }, `Emigrate "${this.#command}" failed`, ); } else { - this.#logger.info({ failed, done, skipped, pending, total }, `Emigrate "${this.#command}" finished successfully`); + this.#logger.info( + { result: { failed, done, skipped, pending, total } }, + `Emigrate "${this.#command}" finished successfully`, + ); } } }