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.11.2 to 0.12.0

123

dist/cli.js
#!/usr/bin/env node --enable-source-maps
import process from 'node:process';
import { parseArgs } from 'node:util';
import importFromEsm from 'import-from-esm';
import { ShowUsageError } from './errors.js';
import { getConfig } from './get-config.js';
const useColors = (values) => {
if (values['no-color']) {
return false;
}
return values.color;
};
const importAll = async (cwd, modules) => {
for await (const module of modules) {
await importFromEsm(cwd, module);
}
};
const up = async (args) => {

@@ -19,2 +31,8 @@ const config = await getConfig('up');

},
import: {
type: 'string',
short: 'i',
multiple: true,
default: [],
},
reporter: {

@@ -37,2 +55,8 @@ type: 'string',

},
color: {
type: 'boolean',
},
'no-color': {
type: 'boolean',
},
},

@@ -47,8 +71,12 @@ allowPositionals: false,

-h, --help Show this help message and exit
-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
-h, --help Show this help message and exit
-d, --directory The directory where the migration files are located (required)
-i, --import Additional modules/packages to import before running the migrations (can be specified multiple times)
For example if you want to use Dotenv to load environment variables or when using TypeScript
-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
--color Force color output (this option is passed to the reporter)
--no-color Disable color output (this option is passed to the reporter)

@@ -60,2 +88,3 @@ Examples:

emigrate up -d src/migrations -s postgres -r json --dry
emigrate up -d ./migrations -s mysql --import dotenv/config
`;

@@ -67,7 +96,9 @@ if (values.help) {

}
const { directory = config.directory, storage = config.storage, reporter = config.reporter, dry } = values;
const cwd = process.cwd();
const { directory = config.directory, storage = config.storage, reporter = config.reporter, dry, import: imports = [], } = values;
const plugins = [...(config.plugins ?? []), ...(values.plugin ?? [])];
await importAll(cwd, imports);
try {
const { default: upCommand } = await import('./commands/up.js');
process.exitCode = await upCommand({ storage, reporter, directory, plugins, dry });
process.exitCode = await upCommand({ storage, reporter, directory, plugins, cwd, dry, color: useColors(values) });
}

@@ -107,3 +138,3 @@ catch (error) {

type: 'string',
short: 'e',
short: 'x',
},

@@ -116,2 +147,8 @@ plugin: {

},
color: {
type: 'boolean',
},
'no-color': {
type: 'boolean',
},
},

@@ -136,4 +173,6 @@ allowPositionals: true,

(if the extension option is not provided the template file's extension will be used)
-e, --extension The extension to use for the new migration file
-x, --extension The extension to use for the new migration file
(if no template or plugin is provided an empty migration file will be created with the given extension)
--color Force color output (this option is passed to the reporter)
--no-color Disable color output (this option is passed to the reporter)

@@ -146,4 +185,4 @@ One of the --template, --extension or the --plugin options must be specified

emigrate new --directory ./migrations --plugin @emigrate/postgres create_users_table
emigrate new -d ./migrations -e .sql create_users_table
emigrate new -d ./migrations -t .migration-template -e .sql "drop some table"
emigrate new -d ./migrations -x .sql create_users_table
emigrate new -d ./migrations -t .migration-template -x .sql "drop some table"
`;

@@ -155,2 +194,3 @@ if (values.help) {

}
const cwd = process.cwd();
const { directory = config.directory, template = config.template, extension = config.extension, reporter = config.reporter, } = values;

@@ -161,3 +201,3 @@ const plugins = [...(config.plugins ?? []), ...(values.plugin ?? [])];

const { default: newCommand } = await import('./commands/new.js');
await newCommand({ directory, template, plugins, extension, reporter }, name);
await newCommand({ directory, template, plugins, extension, reporter, cwd, color: useColors(values) }, name);
}

@@ -187,2 +227,8 @@ catch (error) {

},
import: {
type: 'string',
short: 'i',
multiple: true,
default: [],
},
reporter: {

@@ -196,2 +242,8 @@ type: 'string',

},
color: {
type: 'boolean',
},
'no-color': {
type: 'boolean',
},
},

@@ -206,6 +258,10 @@ allowPositionals: false,

-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)
-h, --help Show this help message and exit
-d, --directory The directory where the migration files are located (required)
-i, --import Additional modules/packages to import before listing the migrations (can be specified multiple times)
For example if you want to use Dotenv to load environment variables
-r, --reporter The reporter to use for reporting the migrations
-s, --storage The storage to use to get the migration history (required)
--color Force color output (this option is passed to the reporter)
--no-color Disable color output (this option is passed to the reporter)

@@ -222,6 +278,8 @@ Examples:

}
const { directory = config.directory, storage = config.storage, reporter = config.reporter } = values;
const cwd = process.cwd();
const { directory = config.directory, storage = config.storage, reporter = config.reporter, import: imports = [], } = values;
await importAll(cwd, imports);
try {
const { default: listCommand } = await import('./commands/list.js');
process.exitCode = await listCommand({ directory, storage, reporter });
process.exitCode = await listCommand({ directory, storage, reporter, cwd, color: useColors(values) });
}

@@ -251,2 +309,8 @@ catch (error) {

},
import: {
type: 'string',
short: 'i',
multiple: true,
default: [],
},
force: {

@@ -264,2 +328,8 @@ type: 'boolean',

},
color: {
type: 'boolean',
},
'no-color': {
type: 'boolean',
},
},

@@ -281,2 +351,4 @@ allowPositionals: true,

-d, --directory The directory where the migration files are located (required)
-i, --import Additional modules/packages to import before removing the migration (can be specified multiple times)
For example if you want to use Dotenv to load environment variables
-r, --reporter The reporter to use for reporting the removal process

@@ -286,2 +358,4 @@ -s, --storage The storage to use to get the migration history (required)

or it's in a non-failed state
--color Force color output (this option is passed to the reporter)
--no-color Disable color output (this option is passed to the reporter)

@@ -292,2 +366,3 @@ Examples:

emigrate remove --directory ./migrations --storage postgres 20231122120529381_some_migration_file.sql
emigrate remove -i dotenv/config -d ./migrations -s postgres 20231122120529381_some_migration_file.sql
`;

@@ -299,6 +374,8 @@ if (values.help) {

}
const { directory = config.directory, storage = config.storage, reporter = config.reporter, force } = values;
const cwd = process.cwd();
const { directory = config.directory, storage = config.storage, reporter = config.reporter, force, import: imports = [], } = values;
await importAll(cwd, imports);
try {
const { default: removeCommand } = await import('./commands/remove.js');
process.exitCode = await removeCommand({ directory, storage, reporter, force }, positionals[0] ?? '');
process.exitCode = await removeCommand({ directory, storage, reporter, force, cwd, color: useColors(values) }, positionals[0] ?? '');
}

@@ -377,5 +454,5 @@ catch (error) {

if (error instanceof Error) {
console.error(error.message);
console.error(error);
if (error.cause instanceof Error) {
console.error(error.cause.stack);
console.error(error.cause);
}

@@ -382,0 +459,0 @@ }

import { type Config } from '../types.js';
export default function listCommand({ directory, reporter: reporterConfig, storage: storageConfig }: Config): Promise<0 | 1>;
type ExtraFlags = {
cwd: string;
};
export default function listCommand({ directory, reporter: reporterConfig, storage: storageConfig, color, cwd, }: Config & ExtraFlags): Promise<0 | 1>;
export {};
//# sourceMappingURL=list.d.ts.map

6

dist/commands/list.js

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

import process from 'node:process';
import { getOrLoadReporter, getOrLoadStorage } from '@emigrate/plugin-tools';

@@ -10,7 +9,6 @@ import { BadOptionError, MissingOptionError, StorageInitError, toError } from '../errors.js';

const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function listCommand({ directory, reporter: reporterConfig, storage: storageConfig }) {
export default async function listCommand({ directory, reporter: reporterConfig, storage: storageConfig, color, cwd, }) {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}
const cwd = process.cwd();
const storagePlugin = await getOrLoadStorage([storageConfig]);

@@ -24,3 +22,3 @@ if (!storagePlugin) {

}
await reporter.onInit?.({ command: 'list', version, cwd, dry: false, directory });
await reporter.onInit?.({ command: 'list', version, cwd, dry: false, directory, color });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

@@ -27,0 +25,0 @@ if (storageError) {

import { type Config } from '../types.js';
export default function newCommand({ directory, template, reporter: reporterConfig, plugins, extension }: Config, name: string): Promise<void>;
type ExtraFlags = {
cwd: string;
};
export default function newCommand({ directory, template, reporter: reporterConfig, plugins, cwd, extension, color }: Config & ExtraFlags, name: string): Promise<void>;
export {};
//# sourceMappingURL=new.d.ts.map

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

import process from 'node:process';
import { hrtime } from 'node:process';
import fs from 'node:fs/promises';

@@ -11,3 +11,3 @@ import path from 'node:path';

const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function newCommand({ directory, template, reporter: reporterConfig, plugins = [], extension }, name) {
export default async function newCommand({ directory, template, reporter: reporterConfig, plugins = [], cwd, extension, color }, name) {
if (!directory) {

@@ -22,3 +22,2 @@ throw MissingOptionError.fromOption('directory');

}
const cwd = process.cwd();
const reporter = await getOrLoadReporter([reporterConfig ?? lazyDefaultReporter]);

@@ -28,4 +27,4 @@ if (!reporter) {

}
await reporter.onInit?.({ command: 'new', version, cwd, dry: false, directory });
const start = process.hrtime();
await reporter.onInit?.({ command: 'new', version, cwd, dry: false, directory, color });
const start = hrtime();
let filename;

@@ -35,3 +34,3 @@ let content;

const fs = await import('node:fs/promises');
const templatePath = path.resolve(process.cwd(), template);
const templatePath = path.resolve(cwd, template);
const fileExtension = path.extname(templatePath);

@@ -65,3 +64,3 @@ try {

}
const directoryPath = path.resolve(process.cwd(), directory);
const directoryPath = path.resolve(cwd, directory);
const filePath = path.resolve(directoryPath, filename);

@@ -68,0 +67,0 @@ const migration = {

import { type Config } from '../types.js';
type ExtraFlags = {
cwd: string;
force?: boolean;
};
export default function removeCommand({ directory, reporter: reporterConfig, storage: storageConfig, force }: Config & ExtraFlags, name: string): Promise<0 | 1>;
export default function removeCommand({ directory, reporter: reporterConfig, storage: storageConfig, color, cwd, force }: Config & ExtraFlags, name: string): Promise<0 | 1>;
export {};
//# sourceMappingURL=remove.d.ts.map

@@ -9,3 +9,3 @@ import process from 'node:process';

const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function removeCommand({ directory, reporter: reporterConfig, storage: storageConfig, force }, name) {
export default async function removeCommand({ directory, reporter: reporterConfig, storage: storageConfig, color, cwd, force = false }, name) {
if (!directory) {

@@ -17,3 +17,2 @@ throw MissingOptionError.fromOption('directory');

}
const cwd = process.cwd();
const storagePlugin = await getOrLoadStorage([storageConfig]);

@@ -27,2 +26,3 @@ if (!storagePlugin) {

}
await reporter.onInit?.({ command: 'remove', version, cwd, dry: false, directory, color });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

@@ -33,3 +33,2 @@ if (storageError) {

}
await reporter.onInit?.({ command: 'remove', version, cwd, dry: false, directory });
const [migrationFile, fileError] = await exec(async () => getMigration(cwd, directory, name, !force));

@@ -36,0 +35,0 @@ if (fileError) {

import { type Config } from '../types.js';
import { type GetMigrationsFunction } from '../get-migrations.js';
type ExtraFlags = {
cwd?: string;
cwd: string;
dry?: boolean;
getMigrations?: GetMigrationsFunction;
};
export default function upCommand({ storage: storageConfig, reporter: reporterConfig, directory, dry, plugins, cwd, getMigrations, }: Config & ExtraFlags): Promise<number>;
export default function upCommand({ storage: storageConfig, reporter: reporterConfig, directory, color, dry, plugins, cwd, getMigrations, }: Config & ExtraFlags): Promise<number>;
export {};
//# sourceMappingURL=up.d.ts.map

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

import process from 'node:process';
import { getOrLoadPlugins, getOrLoadReporter, getOrLoadStorage } from '@emigrate/plugin-tools';

@@ -14,3 +13,3 @@ import { isFinishedMigration } from '@emigrate/types';

const lazyPluginLoaderJs = async () => import('../plugin-loader-js.js');
export default async function upCommand({ storage: storageConfig, reporter: reporterConfig, directory, dry = false, plugins = [], cwd = process.cwd(), getMigrations, }) {
export default async function upCommand({ storage: storageConfig, reporter: reporterConfig, directory, color, dry = false, plugins = [], cwd, getMigrations, }) {
if (!directory) {

@@ -27,3 +26,3 @@ throw MissingOptionError.fromOption('directory');

}
await reporter.onInit?.({ command: 'up', version, cwd, dry, directory });
await reporter.onInit?.({ command: 'up', version, cwd, dry, directory, color });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

@@ -30,0 +29,0 @@ if (storageError) {

@@ -18,2 +18,3 @@ import { describe, it, mock } from 'node:test';

dry: false,
color: undefined,
version,

@@ -82,2 +83,3 @@ directory: 'migrations',

dry: false,
color: undefined,
directory: 'migrations',

@@ -112,2 +114,3 @@ },

dry: true,
color: undefined,
directory: 'migrations',

@@ -142,2 +145,3 @@ },

dry: false,
color: undefined,
directory: 'migrations',

@@ -166,2 +170,3 @@ },

dry: false,
color: undefined,
directory: 'migrations',

@@ -206,2 +211,3 @@ },

dry: false,
color: undefined,
directory: 'migrations',

@@ -244,2 +250,3 @@ },

dry: false,
color: undefined,
directory: 'migrations',

@@ -246,0 +253,0 @@ },

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

import process from 'node:process';
import { hrtime } from 'node:process';
import { isFinishedMigration, isFailedMigration, } from '@emigrate/types';

@@ -84,3 +84,3 @@ import { toError, EmigrateError, MigrationRunError, toSerializedError } from './errors.js';

await reporter.onMigrationStart?.(migration);
const start = process.hrtime();
const start = hrtime();
const [, migrationError] = await exec(async () => execute(migration));

@@ -87,0 +87,0 @@ const duration = getDuration(start);

@@ -13,2 +13,3 @@ import { type EmigrateStorage, type Awaitable, type Plugin, type EmigrateReporter } from '@emigrate/types';

extension?: string;
color?: boolean;
};

@@ -15,0 +16,0 @@ export type EmigrateConfig = Config & {

{
"name": "@emigrate/cli",
"version": "0.11.2",
"version": "0.12.0",
"publishConfig": {

@@ -43,2 +43,3 @@ "access": "public"

"figures": "6.0.1",
"import-from-esm": "1.3.3",
"is-interactive": "2.0.0",

@@ -48,4 +49,4 @@ "log-update": "6.0.0",

"serialize-error": "11.0.3",
"@emigrate/plugin-tools": "0.9.2",
"@emigrate/types": "0.9.1"
"@emigrate/plugin-tools": "0.9.3",
"@emigrate/types": "0.10.0"
},

@@ -52,0 +53,0 @@ "volta": {

@@ -5,2 +5,4 @@ # @emigrate/cli

📖 Read the [documentation](https://emigrate.dev) for more information!
## Installation

@@ -11,3 +13,9 @@

```bash
npm install --save-dev @emigrate/cli
npm install @emigrate/cli
# or
pnpm add @emigrate/cli
# or
yarn add @emigrate/cli
# or
bun add @emigrate/cli
```

@@ -20,5 +28,11 @@

```bash
emigrate new -d migrations -e .js create some fancy table
npx emigrate new -d migrations create some fancy table
# or
pnpm emigrate new -d migrations create some fancy table
# or
yarn emigrate new -d migrations create some fancy table
# or
bunx --bun emigrate new -d migrations create some fancy table
```
Will create a new empty JavaScript migration file with the name "YYYYMMDDHHmmssuuu_create_some_fancy_table.js" in the `migrations` directory.

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

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