feat(reporters): pass the CLI's version number to reporters (#38)
This commit is contained in:
parent
bf34cc427a
commit
bad4e252f3
9 changed files with 32 additions and 7 deletions
6
.changeset/little-tools-invite.md
Normal file
6
.changeset/little-tools-invite.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'@emigrate/plugin-tools': minor
|
||||||
|
'@emigrate/cli': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Pass the Emigrate CLI's version number to reporters
|
||||||
|
|
@ -365,8 +365,7 @@ Commands:
|
||||||
if (command) {
|
if (command) {
|
||||||
console.error(`Unknown command: ${command}\n`);
|
console.error(`Unknown command: ${command}\n`);
|
||||||
} else if (values.version) {
|
} else if (values.version) {
|
||||||
const { getPackageInfo } = await import('./get-package-info.js');
|
const { version } = await import('./get-package-info.js');
|
||||||
const { version } = await getPackageInfo();
|
|
||||||
console.log(version);
|
console.log(version);
|
||||||
process.exitCode = 0;
|
process.exitCode = 0;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { exec } from '../exec.js';
|
||||||
import { migrationRunner } from '../migration-runner.js';
|
import { migrationRunner } from '../migration-runner.js';
|
||||||
import { arrayFromAsync } from '../array-from-async.js';
|
import { arrayFromAsync } from '../array-from-async.js';
|
||||||
import { collectMigrations } from '../collect-migrations.js';
|
import { collectMigrations } from '../collect-migrations.js';
|
||||||
|
import { version } from '../get-package-info.js';
|
||||||
|
|
||||||
const lazyDefaultReporter = async () => import('../reporters/default.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());
|
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { type MigrationMetadata } from '@emigrate/plugin-tools/types';
|
||||||
import { BadOptionError, MissingArgumentsError, MissingOptionError, UnexpectedError } from '../errors.js';
|
import { BadOptionError, MissingArgumentsError, MissingOptionError, UnexpectedError } from '../errors.js';
|
||||||
import { type Config } from '../types.js';
|
import { type Config } from '../types.js';
|
||||||
import { withLeadingPeriod } from '../with-leading-period.js';
|
import { withLeadingPeriod } from '../with-leading-period.js';
|
||||||
|
import { version } from '../get-package-info.js';
|
||||||
|
|
||||||
const lazyDefaultReporter = async () => import('../reporters/default.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 filename: string | undefined;
|
||||||
let content: string | undefined;
|
let content: string | undefined;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { type Config } from '../types.js';
|
||||||
import { getMigration } from '../get-migration.js';
|
import { getMigration } from '../get-migration.js';
|
||||||
import { getDuration } from '../get-duration.js';
|
import { getDuration } from '../get-duration.js';
|
||||||
import { exec } from '../exec.js';
|
import { exec } from '../exec.js';
|
||||||
|
import { version } from '../get-package-info.js';
|
||||||
|
|
||||||
type ExtraFlags = {
|
type ExtraFlags = {
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
|
|
@ -56,7 +57,7 @@ export default async function removeCommand(
|
||||||
return 1;
|
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);
|
const migrationFile = await getMigration(cwd, directory, name, !force);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
type Plugin,
|
type Plugin,
|
||||||
type SerializedError,
|
type SerializedError,
|
||||||
} from '@emigrate/plugin-tools/types';
|
} from '@emigrate/plugin-tools/types';
|
||||||
|
import { version } from '../get-package-info.js';
|
||||||
import upCommand from './up.js';
|
import upCommand from './up.js';
|
||||||
|
|
||||||
type Mocked<T> = {
|
type Mocked<T> = {
|
||||||
|
|
@ -30,6 +31,7 @@ describe('up', () => {
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
dry: false,
|
dry: false,
|
||||||
|
version,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
@ -105,6 +107,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: false,
|
dry: false,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
@ -142,6 +145,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: true,
|
dry: true,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
@ -179,6 +183,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: false,
|
dry: false,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
@ -204,6 +209,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: false,
|
dry: false,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
@ -249,6 +255,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: false,
|
dry: false,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
@ -295,6 +302,7 @@ describe('up', () => {
|
||||||
{
|
{
|
||||||
command: 'up',
|
command: 'up',
|
||||||
cwd: '/emigrate',
|
cwd: '/emigrate',
|
||||||
|
version,
|
||||||
dry: false,
|
dry: false,
|
||||||
directory: 'migrations',
|
directory: 'migrations',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { migrationRunner } from '../migration-runner.js';
|
||||||
import { filterAsync } from '../filter-async.js';
|
import { filterAsync } from '../filter-async.js';
|
||||||
import { collectMigrations } from '../collect-migrations.js';
|
import { collectMigrations } from '../collect-migrations.js';
|
||||||
import { arrayFromAsync } from '../array-from-async.js';
|
import { arrayFromAsync } from '../array-from-async.js';
|
||||||
|
import { version } from '../get-package-info.js';
|
||||||
|
|
||||||
type ExtraFlags = {
|
type ExtraFlags = {
|
||||||
cwd?: string;
|
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());
|
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ type PackageInfo = {
|
||||||
version: string;
|
version: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPackageInfo = async () => {
|
const getPackageInfo = async () => {
|
||||||
const packageInfoPath = fileURLToPath(new URL('../package.json', import.meta.url));
|
const packageInfoPath = fileURLToPath(new URL('../package.json', import.meta.url));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -26,3 +26,5 @@ export const getPackageInfo = async () => {
|
||||||
|
|
||||||
throw new Error(`Could not read package info from: ${packageInfoPath}`);
|
throw new Error(`Could not read package info from: ${packageInfoPath}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const { version } = await getPackageInfo();
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,12 @@ export type LoaderPlugin = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ReporterInitParameters = {
|
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
|
* The command that is being executed
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue