@mikro-orm/cli 6.3.14-dev.6 → 6.3.14-dev.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLIConfigurator.d.ts +1 -1
- package/CLIConfigurator.js +1 -0
- package/CLIHelper.d.ts +5 -4
- package/CLIHelper.js +14 -15
- package/commands/ClearCacheCommand.js +1 -1
- package/commands/CreateDatabaseCommand.js +1 -1
- package/commands/CreateSeederCommand.js +2 -2
- package/commands/DatabaseSeedCommand.js +1 -1
- package/commands/DebugCommand.js +8 -3
- package/commands/GenerateCacheCommand.js +1 -1
- package/commands/GenerateEntitiesCommand.js +1 -1
- package/commands/ImportCommand.d.ts +6 -2
- package/commands/ImportCommand.js +1 -1
- package/commands/MigrationCommandFactory.js +1 -1
- package/commands/SchemaCommandFactory.js +1 -1
- package/package.json +3 -3
package/CLIConfigurator.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends Co
|
|
|
14
14
|
export declare class CLIConfigurator {
|
|
15
15
|
private static createBasicConfig;
|
|
16
16
|
static configure(): yargs.Argv<{
|
|
17
|
-
config: string | undefined;
|
|
17
|
+
config: string[] | undefined;
|
|
18
18
|
}>;
|
|
19
19
|
}
|
package/CLIConfigurator.js
CHANGED
package/CLIHelper.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ import { MikroORM, type Configuration, type IDatabaseDriver, type Options } from
|
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
5
|
export declare class CLIHelper {
|
|
6
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver>(
|
|
7
|
-
static getORM(
|
|
8
|
-
static isDBConnected(reason?:
|
|
6
|
+
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver>(configPaths?: string[], options?: Partial<Options<D>>, validate?: boolean): Promise<Configuration<D>>;
|
|
7
|
+
static getORM<D extends IDatabaseDriver = IDatabaseDriver>(configPaths?: string[], opts?: Partial<Options<D>>, validate?: boolean): Promise<MikroORM<D>>;
|
|
8
|
+
static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
|
|
9
|
+
static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
|
|
9
10
|
static getNodeVersion(): string;
|
|
10
|
-
static getDriverDependencies():
|
|
11
|
+
static getDriverDependencies(config: Configuration): string[];
|
|
11
12
|
static dump(text: string, config?: Configuration): void;
|
|
12
13
|
static getConfigPaths(): string[];
|
|
13
14
|
static dumpDependencies(): Promise<void>;
|
package/CLIHelper.js
CHANGED
|
@@ -11,15 +11,18 @@ const core_1 = require("@mikro-orm/core");
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
class CLIHelper {
|
|
14
|
-
static async getConfiguration(
|
|
14
|
+
static async getConfiguration(configPaths, options = {}, validate = true) {
|
|
15
15
|
const deps = core_1.ConfigurationLoader.getORMPackages();
|
|
16
16
|
if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI) {
|
|
17
17
|
throw new Error('@mikro-orm/cli needs to be installed as a local dependency!');
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
core_1.ConfigurationLoader.commonJSCompat(options);
|
|
20
|
+
core_1.ConfigurationLoader.registerDotenv(options);
|
|
21
|
+
configPaths ??= core_1.ConfigurationLoader.getConfigPaths();
|
|
22
|
+
return core_1.ConfigurationLoader.getConfiguration(configPaths, options, validate);
|
|
20
23
|
}
|
|
21
|
-
static async getORM(
|
|
22
|
-
const options = await CLIHelper.getConfiguration(
|
|
24
|
+
static async getORM(configPaths, opts = {}, validate) {
|
|
25
|
+
const options = await CLIHelper.getConfiguration(configPaths, opts, validate);
|
|
23
26
|
const settings = core_1.ConfigurationLoader.getSettings();
|
|
24
27
|
options.set('allowGlobalContext', true);
|
|
25
28
|
options.set('debug', !!settings.verbose);
|
|
@@ -28,18 +31,19 @@ class CLIHelper {
|
|
|
28
31
|
if (settings.useTsNode !== false) {
|
|
29
32
|
options.set('tsNode', true);
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
// The only times when we don't care to have a warning about no entities is also the time when we ignore entities.
|
|
35
|
+
if (opts.discovery?.warnWhenNoEntities === false) {
|
|
36
|
+
options.set('entities', []);
|
|
37
|
+
options.set('entitiesTs', []);
|
|
33
38
|
}
|
|
34
39
|
return core_1.MikroORM.init(options.getAll());
|
|
35
40
|
}
|
|
36
|
-
static async isDBConnected(reason = false) {
|
|
41
|
+
static async isDBConnected(config, reason = false) {
|
|
37
42
|
try {
|
|
38
|
-
const config = await CLIHelper.getConfiguration();
|
|
39
43
|
await config.getDriver().connect();
|
|
40
44
|
const isConnected = await config.getDriver().getConnection().checkConnection();
|
|
41
45
|
await config.getDriver().close();
|
|
42
|
-
return isConnected.
|
|
46
|
+
return isConnected.ok || (reason ? isConnected.reason : false);
|
|
43
47
|
}
|
|
44
48
|
catch {
|
|
45
49
|
return false;
|
|
@@ -48,9 +52,8 @@ class CLIHelper {
|
|
|
48
52
|
static getNodeVersion() {
|
|
49
53
|
return process.versions.node;
|
|
50
54
|
}
|
|
51
|
-
static
|
|
55
|
+
static getDriverDependencies(config) {
|
|
52
56
|
try {
|
|
53
|
-
const config = await CLIHelper.getConfiguration();
|
|
54
57
|
return config.getDriver().getDependencies();
|
|
55
58
|
}
|
|
56
59
|
catch {
|
|
@@ -73,10 +76,6 @@ class CLIHelper {
|
|
|
73
76
|
CLIHelper.dump(` - mikro-orm ${core_1.colors.green(version)}`);
|
|
74
77
|
CLIHelper.dump(` - node ${core_1.colors.green(CLIHelper.getNodeVersion())}`);
|
|
75
78
|
if ((0, fs_extra_1.pathExistsSync)(process.cwd() + '/package.json')) {
|
|
76
|
-
const drivers = await CLIHelper.getDriverDependencies();
|
|
77
|
-
for (const driver of drivers) {
|
|
78
|
-
CLIHelper.dump(` - ${driver} ${await CLIHelper.getModuleVersion(driver)}`);
|
|
79
|
-
}
|
|
80
79
|
/* istanbul ignore next */
|
|
81
80
|
if (process.versions.bun) {
|
|
82
81
|
CLIHelper.dump(` - typescript via bun`);
|
|
@@ -10,7 +10,7 @@ class ClearCacheCommand {
|
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
*/
|
|
12
12
|
async handler(args) {
|
|
13
|
-
const config = await CLIHelper_1.CLIHelper.getConfiguration();
|
|
13
|
+
const config = await CLIHelper_1.CLIHelper.getConfiguration(args.config);
|
|
14
14
|
if (!config.get('metadataCache').enabled) {
|
|
15
15
|
CLIHelper_1.CLIHelper.dump(core_1.colors.red('Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command.'));
|
|
16
16
|
return;
|
|
@@ -9,7 +9,7 @@ class CreateDatabaseCommand {
|
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
11
|
async handler(args) {
|
|
12
|
-
const orm = await CLIHelper_1.CLIHelper.getORM();
|
|
12
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
|
|
13
13
|
const schemaGenerator = orm.getSchemaGenerator();
|
|
14
14
|
await schemaGenerator.ensureDatabase();
|
|
15
15
|
await orm.close(true);
|
|
@@ -9,8 +9,8 @@ class CreateSeederCommand {
|
|
|
9
9
|
builder = (args) => {
|
|
10
10
|
args.positional('seeder', {
|
|
11
11
|
describe: 'Name for the seeder class. (e.g. "test" will generate "TestSeeder" or "TestSeeder" will generate "TestSeeder")',
|
|
12
|
+
demandOption: true,
|
|
12
13
|
});
|
|
13
|
-
args.demandOption('seeder');
|
|
14
14
|
return args;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
@@ -18,7 +18,7 @@ class CreateSeederCommand {
|
|
|
18
18
|
*/
|
|
19
19
|
async handler(args) {
|
|
20
20
|
const className = CreateSeederCommand.getSeederClassName(args.seeder);
|
|
21
|
-
const orm = await CLIHelper_1.CLIHelper.getORM();
|
|
21
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
|
|
22
22
|
const seeder = orm.getSeeder();
|
|
23
23
|
const path = await seeder.createSeeder(className);
|
|
24
24
|
CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
|
|
@@ -18,7 +18,7 @@ class DatabaseSeedCommand {
|
|
|
18
18
|
* @inheritDoc
|
|
19
19
|
*/
|
|
20
20
|
async handler(args) {
|
|
21
|
-
const orm = await CLIHelper_1.CLIHelper.getORM();
|
|
21
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
|
|
22
22
|
const className = args.class ?? orm.config.get('seeder').defaultSeeder;
|
|
23
23
|
await orm.getSeeder().seedString(className);
|
|
24
24
|
CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${className} successfully executed`));
|
package/commands/DebugCommand.js
CHANGED
|
@@ -16,13 +16,18 @@ class DebugCommand {
|
|
|
16
16
|
if (!process.versions.bun && settings.useTsNode !== false) {
|
|
17
17
|
CLIHelper_1.CLIHelper.dump(' - ts-node ' + core_1.colors.green('enabled'));
|
|
18
18
|
}
|
|
19
|
-
const configPaths = CLIHelper_1.CLIHelper.getConfigPaths();
|
|
19
|
+
const configPaths = args.config ?? CLIHelper_1.CLIHelper.getConfigPaths();
|
|
20
20
|
CLIHelper_1.CLIHelper.dump(' - searched config paths:');
|
|
21
21
|
await DebugCommand.checkPaths(configPaths, 'yellow');
|
|
22
22
|
try {
|
|
23
|
-
const config = await CLIHelper_1.CLIHelper.getConfiguration();
|
|
23
|
+
const config = await CLIHelper_1.CLIHelper.getConfiguration(configPaths);
|
|
24
24
|
CLIHelper_1.CLIHelper.dump(` - configuration ${core_1.colors.green('found')}`);
|
|
25
|
-
const
|
|
25
|
+
const drivers = CLIHelper_1.CLIHelper.getDriverDependencies(config);
|
|
26
|
+
CLIHelper_1.CLIHelper.dump(' - driver dependencies:');
|
|
27
|
+
for (const driver of drivers) {
|
|
28
|
+
CLIHelper_1.CLIHelper.dump(` - ${driver} ${await CLIHelper_1.CLIHelper.getModuleVersion(driver)}`);
|
|
29
|
+
}
|
|
30
|
+
const isConnected = await CLIHelper_1.CLIHelper.isDBConnected(config, true);
|
|
26
31
|
if (isConnected === true) {
|
|
27
32
|
CLIHelper_1.CLIHelper.dump(` - ${core_1.colors.green('database connection successful')}`);
|
|
28
33
|
}
|
|
@@ -23,7 +23,7 @@ class GenerateCacheCommand {
|
|
|
23
23
|
*/
|
|
24
24
|
async handler(args) {
|
|
25
25
|
const options = args.combined ? { combined: './metadata.json' } : {};
|
|
26
|
-
const config = await CLIHelper_1.CLIHelper.getConfiguration(
|
|
26
|
+
const config = await CLIHelper_1.CLIHelper.getConfiguration(args.config, {
|
|
27
27
|
metadataCache: { enabled: true, adapter: core_1.FileCacheAdapter, options },
|
|
28
28
|
});
|
|
29
29
|
config.getMetadataCacheAdapter().clear();
|
|
@@ -37,7 +37,7 @@ class GenerateEntitiesCommand {
|
|
|
37
37
|
if (!args.save && !args.dump) {
|
|
38
38
|
return CLIHelper_1.CLIHelper.showHelp();
|
|
39
39
|
}
|
|
40
|
-
const orm = await CLIHelper_1.CLIHelper.getORM(false);
|
|
40
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config, { discovery: { warnWhenNoEntities: false } });
|
|
41
41
|
const dump = await orm.entityGenerator.generate({
|
|
42
42
|
save: args.save,
|
|
43
43
|
path: args.path,
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
2
|
import type { BaseArgs, BaseCommand } from '../CLIConfigurator';
|
|
3
|
-
|
|
3
|
+
type ImportArgs = BaseArgs & {
|
|
4
|
+
file: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class ImportCommand implements BaseCommand<ImportArgs> {
|
|
4
7
|
command: string;
|
|
5
8
|
describe: string;
|
|
6
9
|
/**
|
|
7
10
|
* @inheritDoc
|
|
8
11
|
*/
|
|
9
|
-
handler(args: ArgumentsCamelCase<
|
|
12
|
+
handler(args: ArgumentsCamelCase<ImportArgs>): Promise<void>;
|
|
10
13
|
}
|
|
14
|
+
export {};
|
|
@@ -10,7 +10,7 @@ class ImportCommand {
|
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
*/
|
|
12
12
|
async handler(args) {
|
|
13
|
-
const orm = await CLIHelper_1.CLIHelper.getORM();
|
|
13
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config, { multipleStatements: true });
|
|
14
14
|
await orm.em.getConnection().loadFile(args.file);
|
|
15
15
|
CLIHelper_1.CLIHelper.dump(core_1.colors.green(`File ${args.file} successfully imported`));
|
|
16
16
|
await orm.close(true);
|
|
@@ -82,7 +82,7 @@ class MigrationCommandFactory {
|
|
|
82
82
|
static async handleMigrationCommand(args, method) {
|
|
83
83
|
// to be able to run have a master transaction, but run marked migrations outside of it, we need a second connection
|
|
84
84
|
const options = { pool: { min: 1, max: 2 } };
|
|
85
|
-
const orm = await CLIHelper_1.CLIHelper.getORM(
|
|
85
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config, options);
|
|
86
86
|
const migrator = orm.getMigrator();
|
|
87
87
|
switch (method) {
|
|
88
88
|
case 'create':
|
|
@@ -82,7 +82,7 @@ class SchemaCommandFactory {
|
|
|
82
82
|
if (!args.run && !args.dump) {
|
|
83
83
|
return CLIHelper_1.CLIHelper.showHelp();
|
|
84
84
|
}
|
|
85
|
-
const orm = await CLIHelper_1.CLIHelper.getORM();
|
|
85
|
+
const orm = await CLIHelper_1.CLIHelper.getORM(args.config);
|
|
86
86
|
const generator = orm.getSchemaGenerator();
|
|
87
87
|
const params = { wrap: args.fkChecks == null ? undefined : !args.fkChecks, ...args };
|
|
88
88
|
if (args.dump) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"version": "6.3.14-dev.
|
|
3
|
+
"version": "6.3.14-dev.61",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@jercle/yargonaut": "1.1.5",
|
|
66
|
-
"@mikro-orm/core": "6.3.14-dev.
|
|
67
|
-
"@mikro-orm/knex": "6.3.14-dev.
|
|
66
|
+
"@mikro-orm/core": "6.3.14-dev.61",
|
|
67
|
+
"@mikro-orm/knex": "6.3.14-dev.61",
|
|
68
68
|
"fs-extra": "11.2.0",
|
|
69
69
|
"tsconfig-paths": "4.2.0",
|
|
70
70
|
"yargs": "17.7.2"
|