@mikro-orm/cli 7.0.0-dev.0 → 7.0.0-dev.2
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 +3 -3
- package/CLIConfigurator.js +44 -48
- package/CLIHelper.js +29 -37
- package/cli +7 -17
- package/cli.js +7 -17
- package/commands/ClearCacheCommand.d.ts +1 -1
- package/commands/ClearCacheCommand.js +6 -10
- package/commands/CreateDatabaseCommand.d.ts +1 -1
- package/commands/CreateDatabaseCommand.js +3 -7
- package/commands/CreateSeederCommand.d.ts +1 -1
- package/commands/CreateSeederCommand.js +5 -9
- package/commands/DatabaseSeedCommand.d.ts +1 -1
- package/commands/DatabaseSeedCommand.js +5 -9
- package/commands/DebugCommand.d.ts +1 -1
- package/commands/DebugCommand.js +33 -38
- package/commands/GenerateCacheCommand.d.ts +1 -1
- package/commands/GenerateCacheCommand.js +10 -15
- package/commands/GenerateEntitiesCommand.d.ts +1 -1
- package/commands/GenerateEntitiesCommand.js +5 -9
- package/commands/ImportCommand.d.ts +1 -1
- package/commands/ImportCommand.js +5 -9
- package/commands/MigrationCommandFactory.d.ts +1 -1
- package/commands/MigrationCommandFactory.js +26 -30
- package/commands/SchemaCommandFactory.d.ts +1 -1
- package/commands/SchemaCommandFactory.js +8 -12
- package/index.d.ts +2 -2
- package/index.js +2 -18
- package/package.json +7 -19
- package/esm +0 -18
- package/esm.cmd +0 -3
- package/esm.d.ts +0 -2
- package/esm.js +0 -18
- package/index.mjs +0 -5
package/CLIConfigurator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type CommandModule } from 'yargs';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
@@ -13,9 +13,9 @@ export interface BaseCommand<CommandArgs extends BaseArgs = BaseArgs> extends Co
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class CLIConfigurator {
|
|
15
15
|
private static createBasicConfig;
|
|
16
|
-
static configure(): yargs.Argv<{
|
|
16
|
+
static configure(): Promise<import("yargs").Argv<{
|
|
17
17
|
config: string[] | undefined;
|
|
18
18
|
} & {
|
|
19
19
|
contextName: string;
|
|
20
|
-
}
|
|
20
|
+
}>>;
|
|
21
21
|
}
|
package/CLIConfigurator.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const DebugCommand_1 = require("./commands/DebugCommand");
|
|
14
|
-
const GenerateCacheCommand_1 = require("./commands/GenerateCacheCommand");
|
|
15
|
-
const GenerateEntitiesCommand_1 = require("./commands/GenerateEntitiesCommand");
|
|
16
|
-
const ImportCommand_1 = require("./commands/ImportCommand");
|
|
17
|
-
const MigrationCommandFactory_1 = require("./commands/MigrationCommandFactory");
|
|
18
|
-
const SchemaCommandFactory_1 = require("./commands/SchemaCommandFactory");
|
|
1
|
+
import { ConfigurationLoader, Utils } from '@mikro-orm/core';
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { ClearCacheCommand } from './commands/ClearCacheCommand.js';
|
|
4
|
+
import { CreateDatabaseCommand } from './commands/CreateDatabaseCommand.js';
|
|
5
|
+
import { CreateSeederCommand } from './commands/CreateSeederCommand.js';
|
|
6
|
+
import { DatabaseSeedCommand } from './commands/DatabaseSeedCommand.js';
|
|
7
|
+
import { DebugCommand } from './commands/DebugCommand.js';
|
|
8
|
+
import { GenerateCacheCommand } from './commands/GenerateCacheCommand.js';
|
|
9
|
+
import { GenerateEntitiesCommand } from './commands/GenerateEntitiesCommand.js';
|
|
10
|
+
import { ImportCommand } from './commands/ImportCommand.js';
|
|
11
|
+
import { MigrationCommandFactory } from './commands/MigrationCommandFactory.js';
|
|
12
|
+
import { SchemaCommandFactory } from './commands/SchemaCommandFactory.js';
|
|
19
13
|
/**
|
|
20
14
|
* @internal
|
|
21
15
|
*/
|
|
22
|
-
class CLIConfigurator {
|
|
16
|
+
export class CLIConfigurator {
|
|
23
17
|
static createBasicConfig() {
|
|
24
|
-
return
|
|
18
|
+
return yargs()
|
|
25
19
|
.scriptName('mikro-orm')
|
|
26
20
|
.usage('Usage: $0 <command> [options]')
|
|
21
|
+
.example('$0 debug', 'Show debugging information')
|
|
27
22
|
.example('$0 schema:update --run', 'Runs schema synchronization')
|
|
28
23
|
.option('config', {
|
|
29
24
|
type: 'string',
|
|
@@ -39,40 +34,41 @@ class CLIConfigurator {
|
|
|
39
34
|
.alias('v', 'version')
|
|
40
35
|
.alias('h', 'help')
|
|
41
36
|
.recommendCommands()
|
|
37
|
+
.showHelpOnFail(true)
|
|
38
|
+
.demandCommand(1, '')
|
|
42
39
|
.strict();
|
|
43
40
|
}
|
|
44
|
-
static configure() {
|
|
45
|
-
|
|
46
|
-
const settings =
|
|
47
|
-
const version =
|
|
48
|
-
if (settings.
|
|
49
|
-
const preferTs =
|
|
50
|
-
/*
|
|
41
|
+
static async configure() {
|
|
42
|
+
ConfigurationLoader.checkPackageVersion();
|
|
43
|
+
const settings = ConfigurationLoader.getSettings();
|
|
44
|
+
const version = Utils.getORMVersion();
|
|
45
|
+
if (settings.preferTs !== false) {
|
|
46
|
+
const preferTs = await ConfigurationLoader.registerTypeScriptSupport(settings.tsConfigPath);
|
|
47
|
+
/* v8 ignore next 3 */
|
|
51
48
|
if (!preferTs) {
|
|
52
|
-
process.env.
|
|
49
|
+
process.env.MIKRO_ORM_CLI_PREFER_TS ??= '0';
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
return CLIConfigurator.createBasicConfig()
|
|
56
53
|
.version(version)
|
|
57
|
-
.command(new
|
|
58
|
-
.command(new
|
|
59
|
-
.command(new
|
|
60
|
-
.command(new
|
|
61
|
-
.command(new
|
|
62
|
-
.command(new
|
|
63
|
-
.command(new
|
|
64
|
-
.command(
|
|
65
|
-
.command(
|
|
66
|
-
.command(
|
|
67
|
-
.command(
|
|
68
|
-
.command(
|
|
69
|
-
.command(
|
|
70
|
-
.command(
|
|
71
|
-
.command(
|
|
72
|
-
.command(
|
|
73
|
-
.command(
|
|
74
|
-
.command(
|
|
75
|
-
.command(new
|
|
54
|
+
.command(new ClearCacheCommand())
|
|
55
|
+
.command(new GenerateCacheCommand())
|
|
56
|
+
.command(new GenerateEntitiesCommand())
|
|
57
|
+
.command(new CreateDatabaseCommand())
|
|
58
|
+
.command(new ImportCommand())
|
|
59
|
+
.command(new DatabaseSeedCommand())
|
|
60
|
+
.command(new CreateSeederCommand())
|
|
61
|
+
.command(SchemaCommandFactory.create('create'))
|
|
62
|
+
.command(SchemaCommandFactory.create('drop'))
|
|
63
|
+
.command(SchemaCommandFactory.create('update'))
|
|
64
|
+
.command(SchemaCommandFactory.create('fresh'))
|
|
65
|
+
.command(MigrationCommandFactory.create('create'))
|
|
66
|
+
.command(MigrationCommandFactory.create('up'))
|
|
67
|
+
.command(MigrationCommandFactory.create('down'))
|
|
68
|
+
.command(MigrationCommandFactory.create('list'))
|
|
69
|
+
.command(MigrationCommandFactory.create('check'))
|
|
70
|
+
.command(MigrationCommandFactory.create('pending'))
|
|
71
|
+
.command(MigrationCommandFactory.create('fresh'))
|
|
72
|
+
.command(new DebugCommand());
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
|
-
exports.CLIConfigurator = CLIConfigurator;
|
package/CLIHelper.js
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CLIHelper = void 0;
|
|
7
|
-
const fs_extra_1 = require("fs-extra");
|
|
8
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
9
|
-
const core_1 = require("@mikro-orm/core");
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { colors, ConfigurationLoader, MikroORM, Utils } from '@mikro-orm/core';
|
|
10
3
|
/**
|
|
11
4
|
* @internal
|
|
12
5
|
*/
|
|
13
|
-
class CLIHelper {
|
|
6
|
+
export class CLIHelper {
|
|
14
7
|
static async getConfiguration(contextName, configPaths, options = {}) {
|
|
15
|
-
const deps =
|
|
8
|
+
const deps = ConfigurationLoader.getORMPackages();
|
|
16
9
|
if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI) {
|
|
17
10
|
throw new Error('@mikro-orm/cli needs to be installed as a local dependency!');
|
|
18
11
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
configPaths ??=
|
|
12
|
+
ConfigurationLoader.commonJSCompat(options);
|
|
13
|
+
ConfigurationLoader.registerDotenv(options);
|
|
14
|
+
configPaths ??= ConfigurationLoader.getConfigPaths();
|
|
22
15
|
contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
|
|
23
|
-
return
|
|
16
|
+
return ConfigurationLoader.getConfiguration(contextName, configPaths, options);
|
|
24
17
|
}
|
|
25
18
|
static async getORM(contextName, configPaths, opts = {}) {
|
|
26
19
|
const options = await CLIHelper.getConfiguration(contextName, configPaths, opts);
|
|
27
|
-
const settings =
|
|
20
|
+
const settings = ConfigurationLoader.getSettings();
|
|
28
21
|
options.set('allowGlobalContext', true);
|
|
29
22
|
options.set('debug', !!settings.verbose);
|
|
30
23
|
options.getLogger().setDebugMode(!!settings.verbose);
|
|
31
24
|
options.set('connect', false);
|
|
32
|
-
if (settings.
|
|
25
|
+
if (settings.preferTs !== false) {
|
|
33
26
|
options.set('preferTs', true);
|
|
34
27
|
}
|
|
35
28
|
// The only times when we don't care to have a warning about no entities is also the time when we ignore entities.
|
|
@@ -37,7 +30,7 @@ class CLIHelper {
|
|
|
37
30
|
options.set('entities', []);
|
|
38
31
|
options.set('entitiesTs', []);
|
|
39
32
|
}
|
|
40
|
-
return
|
|
33
|
+
return MikroORM.init(options.getAll());
|
|
41
34
|
}
|
|
42
35
|
static async isDBConnected(config, reason = false) {
|
|
43
36
|
try {
|
|
@@ -69,34 +62,34 @@ class CLIHelper {
|
|
|
69
62
|
console.log(text);
|
|
70
63
|
}
|
|
71
64
|
static getConfigPaths() {
|
|
72
|
-
return
|
|
65
|
+
return ConfigurationLoader.getConfigPaths();
|
|
73
66
|
}
|
|
74
67
|
static async dumpDependencies() {
|
|
75
|
-
const version =
|
|
68
|
+
const version = Utils.getORMVersion();
|
|
76
69
|
CLIHelper.dump(' - dependencies:');
|
|
77
|
-
CLIHelper.dump(` - mikro-orm ${
|
|
78
|
-
CLIHelper.dump(` - node ${
|
|
79
|
-
if (
|
|
80
|
-
/*
|
|
70
|
+
CLIHelper.dump(` - mikro-orm ${colors.green(version)}`);
|
|
71
|
+
CLIHelper.dump(` - node ${colors.green(CLIHelper.getNodeVersion())}`);
|
|
72
|
+
if (Utils.pathExistsSync(process.cwd() + '/package.json')) {
|
|
73
|
+
/* v8 ignore next 3 */
|
|
81
74
|
if (process.versions.bun) {
|
|
82
75
|
CLIHelper.dump(` - typescript via bun`);
|
|
83
76
|
}
|
|
84
77
|
else {
|
|
85
78
|
CLIHelper.dump(` - typescript ${await CLIHelper.getModuleVersion('typescript')}`);
|
|
86
79
|
}
|
|
87
|
-
CLIHelper.dump(' - package.json ' +
|
|
80
|
+
CLIHelper.dump(' - package.json ' + colors.green('found'));
|
|
88
81
|
}
|
|
89
82
|
else {
|
|
90
|
-
CLIHelper.dump(' - package.json ' +
|
|
83
|
+
CLIHelper.dump(' - package.json ' + colors.red('not found'));
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
86
|
static async getModuleVersion(name) {
|
|
94
87
|
try {
|
|
95
|
-
const pkg =
|
|
96
|
-
return
|
|
88
|
+
const pkg = Utils.requireFrom(`${name}/package.json`);
|
|
89
|
+
return colors.green(pkg.version);
|
|
97
90
|
}
|
|
98
91
|
catch {
|
|
99
|
-
return
|
|
92
|
+
return '';
|
|
100
93
|
}
|
|
101
94
|
}
|
|
102
95
|
static dumpTable(options) {
|
|
@@ -111,18 +104,17 @@ class CLIHelper {
|
|
|
111
104
|
});
|
|
112
105
|
});
|
|
113
106
|
let ret = '';
|
|
114
|
-
ret +=
|
|
115
|
-
ret +=
|
|
116
|
-
ret +=
|
|
107
|
+
ret += colors.grey('┌' + lengths.map(length => '─'.repeat(length)).join('┬') + '┐\n');
|
|
108
|
+
ret += colors.grey('│') + lengths.map((length, idx) => ' ' + colors.red(options.columns[idx]) + ' '.repeat(length - options.columns[idx].length - 1)).join(colors.grey('│')) + colors.grey('│\n');
|
|
109
|
+
ret += colors.grey('├' + lengths.map(length => '─'.repeat(length)).join('┼') + '┤\n');
|
|
117
110
|
options.rows.forEach(row => {
|
|
118
|
-
ret +=
|
|
111
|
+
ret += colors.grey('│') + lengths.map((length, idx) => ' ' + row[idx] + ' '.repeat(length - row[idx].length - 1)).join(colors.grey('│')) + colors.grey('│\n');
|
|
119
112
|
});
|
|
120
|
-
ret +=
|
|
113
|
+
ret += colors.grey('└' + lengths.map(length => '─'.repeat(length)).join('┴') + '┘');
|
|
121
114
|
CLIHelper.dump(ret);
|
|
122
115
|
}
|
|
123
|
-
/*
|
|
116
|
+
/* v8 ignore next 3 */
|
|
124
117
|
static showHelp() {
|
|
125
|
-
|
|
118
|
+
yargs(process.argv.slice(2)).showHelp();
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
|
-
exports.CLIHelper = CLIHelper;
|
package/cli
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
.errorsStyle('red');
|
|
10
|
-
const CLIHelper_1 = require("./CLIHelper");
|
|
11
|
-
const CLIConfigurator_1 = require("./CLIConfigurator");
|
|
12
|
-
void (async () => {
|
|
13
|
-
const argv = CLIConfigurator_1.CLIConfigurator.configure();
|
|
14
|
-
const args = await argv.parse(process.argv.slice(2));
|
|
15
|
-
if (args._.length === 0) {
|
|
16
|
-
CLIHelper_1.CLIHelper.showHelp();
|
|
17
|
-
}
|
|
18
|
-
})();
|
|
2
|
+
import { CLIHelper } from './CLIHelper.js';
|
|
3
|
+
import { CLIConfigurator } from './CLIConfigurator.js';
|
|
4
|
+
const argv = await CLIConfigurator.configure();
|
|
5
|
+
const args = await argv.parse(process.argv.slice(2));
|
|
6
|
+
if (args._.length === 0) {
|
|
7
|
+
CLIHelper.showHelp();
|
|
8
|
+
}
|
package/cli.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
.errorsStyle('red');
|
|
10
|
-
const CLIHelper_1 = require("./CLIHelper");
|
|
11
|
-
const CLIConfigurator_1 = require("./CLIConfigurator");
|
|
12
|
-
void (async () => {
|
|
13
|
-
const argv = CLIConfigurator_1.CLIConfigurator.configure();
|
|
14
|
-
const args = await argv.parse(process.argv.slice(2));
|
|
15
|
-
if (args._.length === 0) {
|
|
16
|
-
CLIHelper_1.CLIHelper.showHelp();
|
|
17
|
-
}
|
|
18
|
-
})();
|
|
2
|
+
import { CLIHelper } from './CLIHelper.js';
|
|
3
|
+
import { CLIConfigurator } from './CLIConfigurator.js';
|
|
4
|
+
const argv = await CLIConfigurator.configure();
|
|
5
|
+
const args = await argv.parse(process.argv.slice(2));
|
|
6
|
+
if (args._.length === 0) {
|
|
7
|
+
CLIHelper.showHelp();
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import type { BaseArgs, BaseCommand } from '../CLIConfigurator';
|
|
2
|
+
import type { BaseArgs, BaseCommand } from '../CLIConfigurator.js';
|
|
3
3
|
export declare class ClearCacheCommand implements BaseCommand {
|
|
4
4
|
command: string;
|
|
5
5
|
describe: string;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class ClearCacheCommand {
|
|
1
|
+
import { colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class ClearCacheCommand {
|
|
7
4
|
command = 'cache:clear';
|
|
8
5
|
describe = 'Clear metadata cache';
|
|
9
6
|
/**
|
|
10
7
|
* @inheritDoc
|
|
11
8
|
*/
|
|
12
9
|
async handler(args) {
|
|
13
|
-
const config = await
|
|
10
|
+
const config = await CLIHelper.getConfiguration(args.contextName, args.config);
|
|
14
11
|
if (!config.get('metadataCache').enabled) {
|
|
15
|
-
|
|
12
|
+
CLIHelper.dump(colors.red('Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command.'));
|
|
16
13
|
return;
|
|
17
14
|
}
|
|
18
15
|
const cache = config.getMetadataCacheAdapter();
|
|
19
16
|
await cache.clear();
|
|
20
|
-
|
|
17
|
+
CLIHelper.dump(colors.green('Metadata cache was successfully cleared'));
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.ClearCacheCommand = ClearCacheCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import type { BaseArgs, BaseCommand } from '../CLIConfigurator';
|
|
2
|
+
import type { BaseArgs, BaseCommand } from '../CLIConfigurator.js';
|
|
3
3
|
export declare class CreateDatabaseCommand implements BaseCommand {
|
|
4
4
|
command: string;
|
|
5
5
|
describe: string;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CreateDatabaseCommand = void 0;
|
|
4
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
5
|
-
class CreateDatabaseCommand {
|
|
1
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
2
|
+
export class CreateDatabaseCommand {
|
|
6
3
|
command = 'database:create';
|
|
7
4
|
describe = 'Create your database if it does not exist';
|
|
8
5
|
/**
|
|
9
6
|
* @inheritDoc
|
|
10
7
|
*/
|
|
11
8
|
async handler(args) {
|
|
12
|
-
const orm = await
|
|
9
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
13
10
|
const schemaGenerator = orm.getSchemaGenerator();
|
|
14
11
|
await schemaGenerator.ensureDatabase();
|
|
15
12
|
await orm.close(true);
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.CreateDatabaseCommand = CreateDatabaseCommand;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class CreateSeederCommand {
|
|
1
|
+
import { colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class CreateSeederCommand {
|
|
7
4
|
command = 'seeder:create <seeder>';
|
|
8
5
|
describe = 'Create a new seeder class';
|
|
9
6
|
builder = (args) => {
|
|
@@ -18,10 +15,10 @@ class CreateSeederCommand {
|
|
|
18
15
|
*/
|
|
19
16
|
async handler(args) {
|
|
20
17
|
const className = CreateSeederCommand.getSeederClassName(args.seeder);
|
|
21
|
-
const orm = await
|
|
18
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
22
19
|
const seeder = orm.getSeeder();
|
|
23
20
|
const path = await seeder.createSeeder(className);
|
|
24
|
-
|
|
21
|
+
CLIHelper.dump(colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
|
|
25
22
|
await orm.close(true);
|
|
26
23
|
}
|
|
27
24
|
/**
|
|
@@ -33,4 +30,3 @@ class CreateSeederCommand {
|
|
|
33
30
|
return parts.map(name => name.charAt(0).toUpperCase() + name.slice(1)).join('') + 'Seeder';
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.CreateSeederCommand = CreateSeederCommand;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class DatabaseSeedCommand {
|
|
1
|
+
import { colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class DatabaseSeedCommand {
|
|
7
4
|
command = 'seeder:run';
|
|
8
5
|
describe = 'Seed the database using the seeder class';
|
|
9
6
|
builder = (args) => {
|
|
@@ -18,11 +15,10 @@ class DatabaseSeedCommand {
|
|
|
18
15
|
* @inheritDoc
|
|
19
16
|
*/
|
|
20
17
|
async handler(args) {
|
|
21
|
-
const orm = await
|
|
18
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
22
19
|
const className = args.class ?? orm.config.get('seeder').defaultSeeder;
|
|
23
20
|
await orm.getSeeder().seedString(className);
|
|
24
|
-
|
|
21
|
+
CLIHelper.dump(colors.green(`Seeder ${className} successfully executed`));
|
|
25
22
|
await orm.close(true);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.DatabaseSeedCommand = DatabaseSeedCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import type { BaseArgs, BaseCommand } from '../CLIConfigurator';
|
|
2
|
+
import type { BaseArgs, BaseCommand } from '../CLIConfigurator.js';
|
|
3
3
|
export declare class DebugCommand implements BaseCommand {
|
|
4
4
|
command: string;
|
|
5
5
|
describe: string;
|
package/commands/DebugCommand.js
CHANGED
|
@@ -1,84 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class DebugCommand {
|
|
1
|
+
import { ConfigurationLoader, Utils, colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class DebugCommand {
|
|
7
4
|
command = 'debug';
|
|
8
5
|
describe = 'Debug CLI configuration';
|
|
9
6
|
/**
|
|
10
7
|
* @inheritDoc
|
|
11
8
|
*/
|
|
12
9
|
async handler(args) {
|
|
13
|
-
|
|
14
|
-
await
|
|
15
|
-
const settings =
|
|
16
|
-
if (!process.versions.bun && settings.
|
|
17
|
-
|
|
10
|
+
CLIHelper.dump(`Current ${colors.cyan('MikroORM')} CLI configuration`);
|
|
11
|
+
await CLIHelper.dumpDependencies();
|
|
12
|
+
const settings = ConfigurationLoader.getSettings();
|
|
13
|
+
if (!process.versions.bun && settings.preferTs !== false) {
|
|
14
|
+
CLIHelper.dump(' - TypeScript support ' + colors.green('enabled'));
|
|
18
15
|
}
|
|
19
|
-
const configPaths = args.config ??
|
|
20
|
-
|
|
16
|
+
const configPaths = args.config ?? CLIHelper.getConfigPaths();
|
|
17
|
+
CLIHelper.dump(' - searched config paths:');
|
|
21
18
|
await DebugCommand.checkPaths(configPaths, 'yellow');
|
|
22
|
-
|
|
19
|
+
CLIHelper.dump(` - searched for config name: ${colors.green(args.contextName)}`);
|
|
23
20
|
try {
|
|
24
|
-
const config = await
|
|
25
|
-
|
|
26
|
-
const drivers =
|
|
27
|
-
|
|
21
|
+
const config = await CLIHelper.getConfiguration(args.contextName, configPaths);
|
|
22
|
+
CLIHelper.dump(` - configuration ${colors.green('found')}`);
|
|
23
|
+
const drivers = CLIHelper.getDriverDependencies(config);
|
|
24
|
+
CLIHelper.dump(' - driver dependencies:');
|
|
28
25
|
for (const driver of drivers) {
|
|
29
|
-
|
|
26
|
+
CLIHelper.dump(` - ${driver} ${await CLIHelper.getModuleVersion(driver)}`);
|
|
30
27
|
}
|
|
31
|
-
const isConnected = await
|
|
28
|
+
const isConnected = await CLIHelper.isDBConnected(config, true);
|
|
32
29
|
if (isConnected === true) {
|
|
33
|
-
|
|
30
|
+
CLIHelper.dump(` - ${colors.green('database connection successful')}`);
|
|
34
31
|
}
|
|
35
32
|
else {
|
|
36
|
-
|
|
33
|
+
CLIHelper.dump(` - ${colors.yellow(`database connection failed (${isConnected})`)}`);
|
|
37
34
|
}
|
|
38
35
|
const preferTs = config.get('preferTs');
|
|
39
36
|
if ([true, false].includes(preferTs)) {
|
|
40
37
|
const warning = preferTs ? ' (this value should be set to `false` when running compiled code!)' : '';
|
|
41
|
-
|
|
38
|
+
CLIHelper.dump(` - \`preferTs\` flag explicitly set to ${preferTs}, will use \`entities${preferTs ? 'Ts' : ''}\` array${warning}`);
|
|
42
39
|
}
|
|
43
40
|
const entities = config.get('entities', []);
|
|
44
41
|
if (entities.length > 0) {
|
|
45
|
-
const refs = entities.filter(p => !
|
|
46
|
-
const paths = entities.filter(p =>
|
|
42
|
+
const refs = entities.filter(p => !Utils.isString(p));
|
|
43
|
+
const paths = entities.filter(p => Utils.isString(p));
|
|
47
44
|
const will = !config.get('preferTs') ? 'will' : 'could';
|
|
48
|
-
|
|
45
|
+
CLIHelper.dump(` - ${will} use \`entities\` array (contains ${refs.length} references and ${paths.length} paths)`);
|
|
49
46
|
if (paths.length > 0) {
|
|
50
47
|
await DebugCommand.checkPaths(paths, 'red', config.get('baseDir'));
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
const entitiesTs = config.get('entitiesTs', []);
|
|
54
51
|
if (entitiesTs.length > 0) {
|
|
55
|
-
const refs = entitiesTs.filter(p => !
|
|
56
|
-
const paths = entitiesTs.filter(p =>
|
|
57
|
-
/*
|
|
52
|
+
const refs = entitiesTs.filter(p => !Utils.isString(p));
|
|
53
|
+
const paths = entitiesTs.filter(p => Utils.isString(p));
|
|
54
|
+
/* v8 ignore next */
|
|
58
55
|
const will = config.get('preferTs') ? 'will' : 'could';
|
|
59
|
-
|
|
60
|
-
/* istanbul ignore else */
|
|
56
|
+
CLIHelper.dump(` - ${will} use \`entitiesTs\` array (contains ${refs.length} references and ${paths.length} paths)`);
|
|
61
57
|
if (paths.length > 0) {
|
|
62
58
|
await DebugCommand.checkPaths(paths, 'red', config.get('baseDir'));
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
catch (e) {
|
|
67
|
-
|
|
63
|
+
CLIHelper.dump(`- configuration ${colors.red('not found')} ${colors.red(`(${e.message})`)}`);
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
static async checkPaths(paths, failedColor, baseDir) {
|
|
71
67
|
for (let path of paths) {
|
|
72
|
-
path =
|
|
73
|
-
path =
|
|
74
|
-
const found = await
|
|
68
|
+
path = Utils.absolutePath(path, baseDir);
|
|
69
|
+
path = Utils.normalizePath(path);
|
|
70
|
+
const found = await Utils.pathExists(path);
|
|
75
71
|
if (found) {
|
|
76
|
-
|
|
72
|
+
CLIHelper.dump(` - ${path} (${colors.green('found')})`);
|
|
77
73
|
}
|
|
78
74
|
else {
|
|
79
|
-
|
|
75
|
+
CLIHelper.dump(` - ${path} (${colors[failedColor]('not found')})`);
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
exports.DebugCommand = DebugCommand;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class GenerateCacheCommand {
|
|
1
|
+
import { MetadataDiscovery, MetadataStorage, colors, FileCacheAdapter } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class GenerateCacheCommand {
|
|
7
4
|
command = 'cache:generate';
|
|
8
5
|
describe = 'Generate metadata cache';
|
|
9
6
|
builder = (args) => {
|
|
10
|
-
args.option('ts
|
|
11
|
-
alias: 'ts',
|
|
7
|
+
args.option('ts', {
|
|
12
8
|
type: 'boolean',
|
|
13
|
-
desc: `
|
|
9
|
+
desc: `Generate development cache for '.ts' files`,
|
|
14
10
|
});
|
|
15
11
|
args.option('combined', {
|
|
16
12
|
alias: 'c',
|
|
@@ -23,16 +19,15 @@ class GenerateCacheCommand {
|
|
|
23
19
|
*/
|
|
24
20
|
async handler(args) {
|
|
25
21
|
const options = args.combined ? { combined: './metadata.json' } : {};
|
|
26
|
-
const config = await
|
|
27
|
-
metadataCache: { enabled: true, adapter:
|
|
22
|
+
const config = await CLIHelper.getConfiguration(args.contextName, args.config, {
|
|
23
|
+
metadataCache: { enabled: true, adapter: FileCacheAdapter, options },
|
|
28
24
|
});
|
|
29
25
|
await config.getMetadataCacheAdapter().clear();
|
|
30
|
-
config.set('logger',
|
|
26
|
+
config.set('logger', CLIHelper.dump.bind(null));
|
|
31
27
|
config.set('debug', true);
|
|
32
|
-
const discovery = new
|
|
28
|
+
const discovery = new MetadataDiscovery(MetadataStorage.init(), config.getDriver().getPlatform(), config);
|
|
33
29
|
await discovery.discover(args.ts ?? false);
|
|
34
30
|
const combined = args.combined && config.get('metadataCache').combined;
|
|
35
|
-
|
|
31
|
+
CLIHelper.dump(colors.green(`${combined ? 'Combined ' : ''}${args.ts ? 'TS' : 'JS'} metadata cache was successfully generated${combined ? ' to ' + combined : ''}`));
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
|
-
exports.GenerateCacheCommand = GenerateCacheCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase, Argv } from 'yargs';
|
|
2
|
-
import type { BaseArgs, BaseCommand } from '../CLIConfigurator';
|
|
2
|
+
import type { BaseArgs, BaseCommand } from '../CLIConfigurator.js';
|
|
3
3
|
export type GenerateEntitiesArgs = BaseArgs & {
|
|
4
4
|
dump?: boolean;
|
|
5
5
|
save?: boolean;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.GenerateEntitiesCommand = void 0;
|
|
4
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
5
|
-
class GenerateEntitiesCommand {
|
|
1
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
2
|
+
export class GenerateEntitiesCommand {
|
|
6
3
|
command = 'generate-entities';
|
|
7
4
|
describe = 'Generate entities based on current database schema';
|
|
8
5
|
/**
|
|
@@ -35,18 +32,17 @@ class GenerateEntitiesCommand {
|
|
|
35
32
|
*/
|
|
36
33
|
async handler(args) {
|
|
37
34
|
if (!args.save && !args.dump) {
|
|
38
|
-
return
|
|
35
|
+
return CLIHelper.showHelp();
|
|
39
36
|
}
|
|
40
|
-
const orm = await
|
|
37
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config, { discovery: { warnWhenNoEntities: false } });
|
|
41
38
|
const dump = await orm.entityGenerator.generate({
|
|
42
39
|
save: args.save,
|
|
43
40
|
path: args.path,
|
|
44
41
|
schema: args.schema,
|
|
45
42
|
});
|
|
46
43
|
if (args.dump) {
|
|
47
|
-
|
|
44
|
+
CLIHelper.dump(dump.join('\n\n'));
|
|
48
45
|
}
|
|
49
46
|
await orm.close(true);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
|
-
exports.GenerateEntitiesCommand = GenerateEntitiesCommand;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class ImportCommand {
|
|
1
|
+
import { colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class ImportCommand {
|
|
7
4
|
command = 'database:import <file>';
|
|
8
5
|
describe = 'Imports the SQL file to the database';
|
|
9
6
|
/**
|
|
10
7
|
* @inheritDoc
|
|
11
8
|
*/
|
|
12
9
|
async handler(args) {
|
|
13
|
-
const orm = await
|
|
10
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config, { multipleStatements: true });
|
|
14
11
|
await orm.em.getConnection().loadFile(args.file);
|
|
15
|
-
|
|
12
|
+
CLIHelper.dump(colors.green(`File ${args.file} successfully imported`));
|
|
16
13
|
await orm.close(true);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.ImportCommand = ImportCommand;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class MigrationCommandFactory {
|
|
1
|
+
import { Utils, colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class MigrationCommandFactory {
|
|
7
4
|
static DESCRIPTIONS = {
|
|
8
5
|
create: 'Create new migration with current schema diff',
|
|
9
6
|
up: 'Migrate up to the latest version',
|
|
@@ -82,7 +79,7 @@ class MigrationCommandFactory {
|
|
|
82
79
|
static async handleMigrationCommand(args, method) {
|
|
83
80
|
// to be able to run have a master transaction, but run marked migrations outside of it, we need a second connection
|
|
84
81
|
const options = { pool: { min: 1, max: 2 } };
|
|
85
|
-
const orm = await
|
|
82
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config, options);
|
|
86
83
|
const migrator = orm.getMigrator();
|
|
87
84
|
switch (method) {
|
|
88
85
|
case 'create':
|
|
@@ -121,11 +118,11 @@ class MigrationCommandFactory {
|
|
|
121
118
|
const opts = MigrationCommandFactory.getUpDownOptions(args);
|
|
122
119
|
await migrator[method](opts);
|
|
123
120
|
const message = this.getUpDownSuccessMessage(method, opts);
|
|
124
|
-
|
|
121
|
+
CLIHelper.dump(colors.green(message));
|
|
125
122
|
}
|
|
126
123
|
static async handlePendingCommand(migrator) {
|
|
127
124
|
const pending = await migrator.getPendingMigrations();
|
|
128
|
-
|
|
125
|
+
CLIHelper.dumpTable({
|
|
129
126
|
columns: ['Name'],
|
|
130
127
|
rows: pending.map(row => [row.name]),
|
|
131
128
|
empty: 'No pending migrations',
|
|
@@ -133,10 +130,10 @@ class MigrationCommandFactory {
|
|
|
133
130
|
}
|
|
134
131
|
static async handleListCommand(migrator) {
|
|
135
132
|
const executed = await migrator.getExecutedMigrations();
|
|
136
|
-
|
|
133
|
+
CLIHelper.dumpTable({
|
|
137
134
|
columns: ['Name', 'Executed at'],
|
|
138
135
|
rows: executed.map(row => {
|
|
139
|
-
/*
|
|
136
|
+
/* v8 ignore next */
|
|
140
137
|
const executedAt = (row.executed_at ?? row.created_at)?.toISOString() ?? '';
|
|
141
138
|
return [row.name.replace(/\.[jt]s$/, ''), executedAt];
|
|
142
139
|
}),
|
|
@@ -146,44 +143,44 @@ class MigrationCommandFactory {
|
|
|
146
143
|
static async handleCreateCommand(migrator, args, config) {
|
|
147
144
|
const ret = await migrator.createMigration(args.path, args.blank, args.initial, args.name);
|
|
148
145
|
if (ret.diff.up.length === 0) {
|
|
149
|
-
return
|
|
146
|
+
return CLIHelper.dump(colors.green(`No changes required, schema is up-to-date`));
|
|
150
147
|
}
|
|
151
148
|
if (args.dump) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
/*
|
|
149
|
+
CLIHelper.dump(colors.green('Creating migration with following queries:'));
|
|
150
|
+
CLIHelper.dump(colors.green('up:'));
|
|
151
|
+
CLIHelper.dump(ret.diff.up.map(sql => ' ' + sql).join('\n'), config);
|
|
152
|
+
/* v8 ignore next 3 */
|
|
156
153
|
if (config.getDriver().getPlatform().supportsDownMigrations()) {
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
CLIHelper.dump(colors.green('down:'));
|
|
155
|
+
CLIHelper.dump(ret.diff.down.map(sql => ' ' + sql).join('\n'), config);
|
|
159
156
|
}
|
|
160
157
|
else {
|
|
161
|
-
|
|
158
|
+
CLIHelper.dump(colors.yellow(`(${config.getDriver().constructor.name} does not support automatic down migrations)`));
|
|
162
159
|
}
|
|
163
160
|
}
|
|
164
|
-
|
|
161
|
+
CLIHelper.dump(colors.green(`${ret.fileName} successfully created`));
|
|
165
162
|
}
|
|
166
163
|
static async handleCheckCommand(migrator, orm) {
|
|
167
|
-
if (!await migrator.checkMigrationNeeded()) {
|
|
168
|
-
return
|
|
164
|
+
if (!(await migrator.checkMigrationNeeded())) {
|
|
165
|
+
return CLIHelper.dump(colors.green(`No changes required, schema is up-to-date`));
|
|
169
166
|
}
|
|
170
167
|
await orm.close(true);
|
|
171
|
-
|
|
168
|
+
CLIHelper.dump(colors.yellow(`Changes detected. Please create migration to update schema.`));
|
|
172
169
|
process.exit(1);
|
|
173
170
|
}
|
|
174
171
|
static async handleFreshCommand(args, migrator, orm) {
|
|
175
172
|
const generator = orm.getSchemaGenerator();
|
|
176
173
|
await generator.dropSchema({ dropMigrationsTable: true, dropDb: args.dropDb });
|
|
177
|
-
|
|
174
|
+
CLIHelper.dump(colors.green('Dropped schema successfully'));
|
|
178
175
|
const opts = MigrationCommandFactory.getUpDownOptions(args);
|
|
179
176
|
await migrator.up(opts);
|
|
180
177
|
const message = this.getUpDownSuccessMessage('up', opts);
|
|
181
|
-
|
|
178
|
+
CLIHelper.dump(colors.green(message));
|
|
182
179
|
if (args.seed !== undefined) {
|
|
183
180
|
const seeder = orm.getSeeder();
|
|
184
181
|
const seederClass = args.seed || orm.config.get('seeder').defaultSeeder;
|
|
185
182
|
await seeder.seedString(seederClass);
|
|
186
|
-
|
|
183
|
+
CLIHelper.dump(colors.green(`Database seeded successfully with seeder class ${seederClass}`));
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
static getUpDownOptions(flags) {
|
|
@@ -196,17 +193,17 @@ class MigrationCommandFactory {
|
|
|
196
193
|
}
|
|
197
194
|
static getUpDownSuccessMessage(method, options) {
|
|
198
195
|
const msg = `Successfully migrated ${method}`;
|
|
199
|
-
if (method === 'down' &&
|
|
196
|
+
if (method === 'down' && Utils.isEmpty(options)) {
|
|
200
197
|
return msg + ' to previous version';
|
|
201
198
|
}
|
|
202
199
|
if (options.to === 0) {
|
|
203
200
|
const v = { down: 'first', up: 'latest' }[method];
|
|
204
201
|
return `${msg} to the ${v} version`;
|
|
205
202
|
}
|
|
206
|
-
if (method === 'up' &&
|
|
203
|
+
if (method === 'up' && Utils.isEmpty(options)) {
|
|
207
204
|
return msg + ' to the latest version';
|
|
208
205
|
}
|
|
209
|
-
if (
|
|
206
|
+
if (Utils.isString(options.to)) {
|
|
210
207
|
return msg + ' to version ' + options.to;
|
|
211
208
|
}
|
|
212
209
|
if (options.migrations && options.migrations.length === 1) {
|
|
@@ -215,4 +212,3 @@ class MigrationCommandFactory {
|
|
|
215
212
|
return msg;
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
|
-
exports.MigrationCommandFactory = MigrationCommandFactory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase, Argv } from 'yargs';
|
|
2
|
-
import type { BaseArgs } from '../CLIConfigurator';
|
|
2
|
+
import type { BaseArgs } from '../CLIConfigurator.js';
|
|
3
3
|
export declare class SchemaCommandFactory {
|
|
4
4
|
static readonly DESCRIPTIONS: {
|
|
5
5
|
readonly create: "Create database schema based on current metadata";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const CLIHelper_1 = require("../CLIHelper");
|
|
6
|
-
class SchemaCommandFactory {
|
|
1
|
+
import { colors } from '@mikro-orm/core';
|
|
2
|
+
import { CLIHelper } from '../CLIHelper.js';
|
|
3
|
+
export class SchemaCommandFactory {
|
|
7
4
|
static DESCRIPTIONS = {
|
|
8
5
|
create: 'Create database schema based on current metadata',
|
|
9
6
|
update: 'Update database schema based on current metadata',
|
|
@@ -80,17 +77,17 @@ class SchemaCommandFactory {
|
|
|
80
77
|
}
|
|
81
78
|
static async handleSchemaCommand(args, method, successMessage) {
|
|
82
79
|
if (!args.run && !args.dump) {
|
|
83
|
-
return
|
|
80
|
+
return CLIHelper.showHelp();
|
|
84
81
|
}
|
|
85
|
-
const orm = await
|
|
82
|
+
const orm = await CLIHelper.getORM(args.contextName, args.config);
|
|
86
83
|
const generator = orm.getSchemaGenerator();
|
|
87
84
|
const params = { wrap: args.fkChecks == null ? undefined : !args.fkChecks, ...args };
|
|
88
85
|
if (args.dump) {
|
|
89
86
|
const m = `get${method.substr(0, 1).toUpperCase()}${method.substr(1)}SchemaSQL`;
|
|
90
87
|
const dump = await generator[m](params);
|
|
91
|
-
/*
|
|
88
|
+
/* v8 ignore next 3 */
|
|
92
89
|
if (dump) {
|
|
93
|
-
|
|
90
|
+
CLIHelper.dump(dump, orm.config);
|
|
94
91
|
successMessage = '';
|
|
95
92
|
}
|
|
96
93
|
else {
|
|
@@ -109,8 +106,7 @@ class SchemaCommandFactory {
|
|
|
109
106
|
const seeder = orm.getSeeder();
|
|
110
107
|
await seeder.seedString(args.seed || orm.config.get('seeder').defaultSeeder);
|
|
111
108
|
}
|
|
112
|
-
|
|
109
|
+
CLIHelper.dump(colors.green(successMessage));
|
|
113
110
|
await orm.close(true);
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
|
-
exports.SchemaCommandFactory = SchemaCommandFactory;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
/**
|
|
18
2
|
* @packageDocumentation
|
|
19
3
|
* @module cli
|
|
20
4
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
export * from './CLIHelper.js';
|
|
6
|
+
export * from './CLIConfigurator.js';
|
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.0.0-dev.2",
|
|
4
5
|
"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
|
-
"main": "index.js",
|
|
6
|
-
"module": "index.mjs",
|
|
7
|
-
"typings": "index.d.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
"./package.json": "./package.json",
|
|
10
|
-
".":
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./index.d.ts",
|
|
13
|
-
"default": "./index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"require": "./index.js"
|
|
16
|
-
}
|
|
8
|
+
".": "./index.js"
|
|
17
9
|
},
|
|
18
10
|
"repository": {
|
|
19
11
|
"type": "git",
|
|
@@ -46,14 +38,13 @@
|
|
|
46
38
|
},
|
|
47
39
|
"homepage": "https://mikro-orm.io",
|
|
48
40
|
"bin": {
|
|
49
|
-
"mikro-orm": "./cli"
|
|
50
|
-
"mikro-orm-esm": "./esm"
|
|
41
|
+
"mikro-orm": "./cli"
|
|
51
42
|
},
|
|
52
43
|
"engines": {
|
|
53
44
|
"node": ">= 22.11.0"
|
|
54
45
|
},
|
|
55
46
|
"scripts": {
|
|
56
|
-
"build": "yarn clean && yarn compile && yarn copy
|
|
47
|
+
"build": "yarn clean && yarn compile && yarn copy",
|
|
57
48
|
"clean": "yarn run -T rimraf ./dist",
|
|
58
49
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
59
50
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -62,11 +53,8 @@
|
|
|
62
53
|
"access": "public"
|
|
63
54
|
},
|
|
64
55
|
"dependencies": {
|
|
65
|
-
"@
|
|
66
|
-
"@mikro-orm/
|
|
67
|
-
"@mikro-orm/knex": "7.0.0-dev.0",
|
|
68
|
-
"fs-extra": "11.3.0",
|
|
69
|
-
"tsconfig-paths": "4.2.0",
|
|
56
|
+
"@mikro-orm/core": "7.0.0-dev.2",
|
|
57
|
+
"@mikro-orm/knex": "7.0.0-dev.2",
|
|
70
58
|
"yargs": "17.7.2"
|
|
71
59
|
},
|
|
72
60
|
"devDependencies": {
|
package/esm
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
5
|
-
require('@jercle/yargonaut')
|
|
6
|
-
.style('blue')
|
|
7
|
-
.style('yellow', 'required')
|
|
8
|
-
.helpStyle('green')
|
|
9
|
-
.errorsStyle('red');
|
|
10
|
-
const CLIHelper_1 = require("./CLIHelper");
|
|
11
|
-
const CLIConfigurator_1 = require("./CLIConfigurator");
|
|
12
|
-
void (async () => {
|
|
13
|
-
const argv = CLIConfigurator_1.CLIConfigurator.configure();
|
|
14
|
-
const args = await argv.parse(process.argv.slice(2));
|
|
15
|
-
if (args._.length === 0) {
|
|
16
|
-
CLIHelper_1.CLIHelper.showHelp();
|
|
17
|
-
}
|
|
18
|
-
})();
|
package/esm.cmd
DELETED
package/esm.d.ts
DELETED
package/esm.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
5
|
-
require('@jercle/yargonaut')
|
|
6
|
-
.style('blue')
|
|
7
|
-
.style('yellow', 'required')
|
|
8
|
-
.helpStyle('green')
|
|
9
|
-
.errorsStyle('red');
|
|
10
|
-
const CLIHelper_1 = require("./CLIHelper");
|
|
11
|
-
const CLIConfigurator_1 = require("./CLIConfigurator");
|
|
12
|
-
void (async () => {
|
|
13
|
-
const argv = CLIConfigurator_1.CLIConfigurator.configure();
|
|
14
|
-
const args = await argv.parse(process.argv.slice(2));
|
|
15
|
-
if (args._.length === 0) {
|
|
16
|
-
CLIHelper_1.CLIHelper.showHelp();
|
|
17
|
-
}
|
|
18
|
-
})();
|