feat(reporters): pass the CLI's version number to reporters (#38)

This commit is contained in:
Joakim Carlstein 2023-12-14 13:11:55 +01:00 committed by GitHub
parent bf34cc427a
commit bad4e252f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 7 deletions

View file

@ -365,8 +365,7 @@ Commands:
if (command) {
console.error(`Unknown command: ${command}\n`);
} else if (values.version) {
const { getPackageInfo } = await import('./get-package-info.js');
const { version } = await getPackageInfo();
const { version } = await import('./get-package-info.js');
console.log(version);
process.exitCode = 0;
return;

View file

@ -6,6 +6,7 @@ import { exec } from '../exec.js';
import { migrationRunner } from '../migration-runner.js';
import { arrayFromAsync } from '../array-from-async.js';
import { collectMigrations } from '../collect-migrations.js';
import { version } from '../get-package-info.js';
const lazyDefaultReporter = async () => import('../reporters/default.js');
@ -30,7 +31,7 @@ export default async function listCommand({ directory, reporter: reporterConfig,
);
}
await reporter.onInit?.({ command: 'list', cwd, dry: false, directory });
await reporter.onInit?.({ command: 'list', version, cwd, dry: false, directory });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

View file

@ -6,6 +6,7 @@ import { type MigrationMetadata } from '@emigrate/plugin-tools/types';
import { BadOptionError, MissingArgumentsError, MissingOptionError, UnexpectedError } from '../errors.js';
import { type Config } from '../types.js';
import { withLeadingPeriod } from '../with-leading-period.js';
import { version } from '../get-package-info.js';
const lazyDefaultReporter = async () => import('../reporters/default.js');
@ -36,7 +37,7 @@ export default async function newCommand(
);
}
await reporter.onInit?.({ command: 'new', cwd, dry: false, directory });
await reporter.onInit?.({ command: 'new', version, cwd, dry: false, directory });
let filename: string | undefined;
let content: string | undefined;

View file

@ -13,6 +13,7 @@ import { type Config } from '../types.js';
import { getMigration } from '../get-migration.js';
import { getDuration } from '../get-duration.js';
import { exec } from '../exec.js';
import { version } from '../get-package-info.js';
type ExtraFlags = {
force?: boolean;
@ -56,7 +57,7 @@ export default async function removeCommand(
return 1;
}
await reporter.onInit?.({ command: 'remove', cwd, dry: false, directory });
await reporter.onInit?.({ command: 'remove', version, cwd, dry: false, directory });
const migrationFile = await getMigration(cwd, directory, name, !force);

View file

@ -10,6 +10,7 @@ import {
type Plugin,
type SerializedError,
} from '@emigrate/plugin-tools/types';
import { version } from '../get-package-info.js';
import upCommand from './up.js';
type Mocked<T> = {
@ -30,6 +31,7 @@ describe('up', () => {
command: 'up',
cwd: '/emigrate',
dry: false,
version,
directory: 'migrations',
},
]);
@ -105,6 +107,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: false,
directory: 'migrations',
},
@ -142,6 +145,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: true,
directory: 'migrations',
},
@ -179,6 +183,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: false,
directory: 'migrations',
},
@ -204,6 +209,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: false,
directory: 'migrations',
},
@ -249,6 +255,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: false,
directory: 'migrations',
},
@ -295,6 +302,7 @@ describe('up', () => {
{
command: 'up',
cwd: '/emigrate',
version,
dry: false,
directory: 'migrations',
},

View file

@ -10,6 +10,7 @@ import { migrationRunner } from '../migration-runner.js';
import { filterAsync } from '../filter-async.js';
import { collectMigrations } from '../collect-migrations.js';
import { arrayFromAsync } from '../array-from-async.js';
import { version } from '../get-package-info.js';
type ExtraFlags = {
cwd?: string;
@ -48,7 +49,7 @@ export default async function upCommand({
);
}
await reporter.onInit?.({ command: 'up', cwd, dry, directory });
await reporter.onInit?.({ command: 'up', version, cwd, dry, directory });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

View file

@ -5,7 +5,7 @@ type PackageInfo = {
version: string;
};
export const getPackageInfo = async () => {
const getPackageInfo = async () => {
const packageInfoPath = fileURLToPath(new URL('../package.json', import.meta.url));
try {
@ -26,3 +26,5 @@ export const getPackageInfo = async () => {
throw new Error(`Could not read package info from: ${packageInfoPath}`);
};
export const { version } = await getPackageInfo();

View file

@ -180,6 +180,12 @@ export type LoaderPlugin = {
};
export type ReporterInitParameters = {
/**
* The version of the emigrate CLI that is being used
*
* @example 1.0.0
*/
version: string;
/**
* The command that is being executed
*/