Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@emigrate/cli

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emigrate/cli - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

dist/commands/list.d.ts

2

dist/cli.d.ts

@@ -1,3 +0,3 @@

#!/usr/bin/env node
#!/usr/bin/env node --enable-source-maps
export {};
//# sourceMappingURL=cli.d.ts.map

@@ -1,2 +0,2 @@

#!/usr/bin/env node
#!/usr/bin/env node --enable-source-maps
import process from 'node:process';

@@ -19,2 +19,10 @@ import { parseArgs } from 'node:util';

},
reporter: {
type: 'string',
short: 'r',
},
storage: {
type: 'string',
short: 's',
},
dry: {

@@ -40,3 +48,5 @@ type: 'boolean',

-d, --directory The directory where the migration files are located (required)
-s, --storage The storage to use for where to store the migration history (required)
-p, --plugin The plugin(s) to use (can be specified multiple times)
-r, --reporter The reporter to use for reporting the migration progress
--dry List the pending migrations that would be run without actually running them

@@ -46,5 +56,5 @@

emigrate up --directory src/migrations
emigrate up -d ./migrations --plugin @emigrate/plugin-storage-mysql
emigrate up -d src/migrations --dry
emigrate up --directory src/migrations -s fs
emigrate up -d ./migrations --storage @emigrate/storage-mysql
emigrate up -d src/migrations -s postgres -r json --dry
`;

@@ -56,7 +66,7 @@ if (values.help) {

}
const { directory = config.directory, dry } = values;
const { directory = config.directory, storage = config.storage, reporter = config.reporter, dry } = values;
const plugins = [...(config.plugins ?? []), ...(values.plugin ?? [])];
try {
const { default: upCommand } = await import('./up-command.js');
await upCommand({ directory, plugins, dry });
const { default: upCommand } = await import('./commands/up.js');
await upCommand({ storage, reporter, directory, plugins, dry });
}

@@ -86,2 +96,6 @@ catch (error) {

},
reporter: {
type: 'string',
short: 'r',
},
template: {

@@ -108,2 +122,6 @@ type: 'string',

Arguments:
name The name of the migration file to create (required)
Options:

@@ -113,2 +131,3 @@

-d, --directory The directory where the migration files are located (required)
-r, --reporter The reporter to use for reporting the migration file creation progress
-p, --plugin The plugin(s) to use (can be specified multiple times)

@@ -134,8 +153,8 @@ -t, --template A template file to use as contents for the new migration file

}
const { directory = config.directory, template = config.template, extension = config.extension } = values;
const { directory = config.directory, template = config.template, extension = config.extension, reporter = config.reporter, } = values;
const plugins = [...(config.plugins ?? []), ...(values.plugin ?? [])];
const name = positionals.join(' ').trim();
try {
const { default: newCommand } = await import('./new-command.js');
await newCommand({ directory, template, plugins, extension }, name);
const { default: newCommand } = await import('./commands/new.js');
await newCommand({ directory, template, plugins, extension, reporter }, name);
}

@@ -153,2 +172,3 @@ catch (error) {

const list = async (args) => {
const config = await getConfig('list');
const { values } = parseArgs({

@@ -161,19 +181,131 @@ args,

},
plugin: {
directory: {
type: 'string',
short: 'p',
multiple: true,
default: [],
short: 'd',
},
reporter: {
type: 'string',
short: 'r',
},
storage: {
type: 'string',
short: 's',
},
},
allowPositionals: false,
});
console.log(values);
const usage = `Usage: emigrate list [options]
List all migrations and their status. This command does not run any migrations.
Options:
-h, --help Show this help message and exit
-d, --directory The directory where the migration files are located (required)
-r, --reporter The reporter to use for reporting the migrations
-s, --storage The storage to use to get the migration history (required)
Examples:
emigrate list -d migrations -s fs
emigrate list --directory ./migrations --storage postgres --reporter json
`;
if (values.help) {
console.log(usage);
process.exitCode = 1;
return;
}
const { directory = config.directory, storage = config.storage, reporter = config.reporter } = values;
try {
const { default: listCommand } = await import('./commands/list.js');
await listCommand({ directory, storage, reporter });
}
catch (error) {
if (error instanceof ShowUsageError) {
console.error(error.message, '\n');
console.log(usage);
process.exitCode = 1;
return;
}
throw error;
}
};
const remove = async (args) => {
const config = await getConfig('remove');
const { values, positionals } = parseArgs({
args,
options: {
help: {
type: 'boolean',
short: 'h',
},
directory: {
type: 'string',
short: 'd',
},
force: {
type: 'boolean',
short: 'f',
},
reporter: {
type: 'string',
short: 'r',
},
storage: {
type: 'string',
short: 's',
},
},
allowPositionals: true,
});
const usage = `Usage: emigrate remove [options] <name>
Remove entries from the migration history.
This is useful if you want to retry a migration that has failed.
Arguments:
name The name of the migration file to remove from the history (required)
Options:
-h, --help Show this help message and exit
-d, --directory The directory where the migration files are located (required)
-r, --reporter The reporter to use for reporting the removal process
-s, --storage The storage to use to get the migration history (required)
-f, --force Force removal of the migration history entry even if the migration file does not exist
or it's in a non-failed state
Examples:
emigrate remove -d migrations -s fs 20231122120529381_some_migration_file.js
emigrate remove --directory ./migrations --storage postgres 20231122120529381_some_migration_file.sql
`;
if (values.help) {
console.log(usage);
process.exitCode = 1;
return;
}
const { directory = config.directory, storage = config.storage, reporter = config.reporter, force } = values;
try {
const { default: removeCommand } = await import('./commands/remove.js');
await removeCommand({ directory, storage, reporter, force }, positionals[0] ?? '');
}
catch (error) {
if (error instanceof ShowUsageError) {
console.error(error.message, '\n');
console.log(usage);
process.exitCode = 1;
return;
}
throw error;
}
};
const commands = {
up,
list,
remove,
new: newMigration,
};
const command = process.argv[2];
const command = process.argv[2]?.toLowerCase();
const action = command ? commands[command] : undefined;

@@ -191,5 +323,6 @@ if (!action) {

up Run all pending migrations
up Run all pending migrations (or do a dry run)
new Create a new migration file
list List all migrations
list List all migrations and their status
remove Remove entries from the migration history
`);

@@ -196,0 +329,0 @@ process.exit(1);

@@ -16,2 +16,6 @@ import { type MigrationHistoryEntry, type MigrationMetadata } from '@emigrate/plugin-tools/types';

}
export declare class OptionNeededError extends ShowUsageError {
option: string;
constructor(option: string, message: string);
}
export declare class BadOptionError extends ShowUsageError {

@@ -36,2 +40,6 @@ option: string;

}
export declare class MigrationNotRunError extends EmigrateError {
metadata: MigrationMetadata;
constructor(message: string, metadata: MigrationMetadata, options?: ErrorOptions);
}
//# sourceMappingURL=errors.d.ts.map

@@ -7,2 +7,3 @@ const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });

this.code = code;
this.name = `${this.name} [${this.code}]`;
}

@@ -26,2 +27,9 @@ }

}
export class OptionNeededError extends ShowUsageError {
option;
constructor(option, message) {
super('ERR_OPT_NEEDED', message);
this.option = option;
}
}
export class BadOptionError extends ShowUsageError {

@@ -42,3 +50,3 @@ option;

constructor(message, entry) {
super('ERR_MIGRATION_HISTORY', message);
super('ERR_MIGRATION_HISTORY', message, { cause: entry.error });
this.entry = entry;

@@ -61,2 +69,9 @@ }

}
export class MigrationNotRunError extends EmigrateError {
metadata;
constructor(message, metadata, options) {
super('ERR_MIGRATION_NOT_RUN', message, options);
this.metadata = metadata;
}
}
//# sourceMappingURL=errors.js.map
import { type Config } from './types.js';
export declare const getConfig: (command: 'up' | 'list' | 'new') => Promise<Config>;
declare const commands: readonly ["up", "list", "new", "remove"];
type Command = (typeof commands)[number];
export declare const getConfig: (command: Command) => Promise<Config>;
export {};
//# sourceMappingURL=get-config.d.ts.map
import { cosmiconfig } from 'cosmiconfig';
const commands = ['up', 'list', 'new', 'remove'];
export const getConfig = async (command) => {

@@ -8,8 +9,10 @@ const explorer = cosmiconfig('emigrate');

}
const { plugins, directory, template, ...commandsConfig } = result.config;
if (commandsConfig[command]) {
return { plugins, directory, template, ...commandsConfig[command] };
const config = result.config;
const commandConfig = config[command];
for (const command of commands) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete config[command];
}
return { plugins, directory, template };
return { ...config, ...commandConfig };
};
//# sourceMappingURL=get-config.js.map

@@ -1,5 +0,10 @@

import { type Plugin } from '@emigrate/plugin-tools/types';
import { type EmigrateStorage, type Awaitable, type Plugin, type EmigrateReporter } from '@emigrate/plugin-tools/types';
export type EmigratePlugin = Plugin;
type StringOrModule<T> = string | T | (() => Awaitable<T>) | (() => Awaitable<{
default: T;
}>);
export type Config = {
plugins?: Array<string | EmigratePlugin>;
storage?: StringOrModule<EmigrateStorage>;
reporter?: StringOrModule<EmigrateReporter>;
plugins?: Array<StringOrModule<EmigratePlugin>>;
directory?: string;

@@ -13,3 +18,5 @@ template?: string;

list?: Config;
remove?: Config;
};
export {};
//# sourceMappingURL=types.d.ts.map
{
"name": "@emigrate/cli",
"version": "0.4.0",
"version": "0.5.0",
"publishConfig": {

@@ -46,3 +46,3 @@ "access": "public"

"pretty-ms": "8.0.0",
"@emigrate/plugin-tools": "0.3.0"
"@emigrate/plugin-tools": "0.4.0"
},

@@ -54,4 +54,5 @@ "volta": {

"build": "tsc --pretty",
"build:watch": "tsc --pretty --watch"
"build:watch": "tsc --pretty --watch",
"lint": "xo --cwd=../.. $(pwd)"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc