@midwayjs/typeorm 3.9.0 → 3.9.4

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.
Files changed (2) hide show
  1. package/cli.js +50 -0
  2. package/package.json +7 -3
package/cli.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { join } = require('path');
5
+ // eslint-disable-next-line node/no-unpublished-require
6
+ const { CommandUtils } = require('typeorm/commands/CommandUtils');
7
+ // eslint-disable-next-line node/no-unpublished-require
8
+ const ImportUtils = require('typeorm/util/ImportUtils');
9
+ // eslint-disable-next-line node/no-unpublished-require
10
+ const { DataSource } = require('typeorm');
11
+
12
+ const originLoadDataSource = CommandUtils.loadDataSource;
13
+
14
+ CommandUtils.loadDataSource = async function (dataSourceFilePath) {
15
+ try {
16
+ let dataSourceFileExports = await ImportUtils.importOrRequireFile(
17
+ dataSourceFilePath
18
+ );
19
+ if (dataSourceFileExports[0] && dataSourceFileExports[0].default) {
20
+ dataSourceFileExports = dataSourceFileExports[0].default;
21
+ if (typeof dataSourceFileExports === 'function') {
22
+ dataSourceFileExports = dataSourceFileExports({
23
+ appDir: process.cwd(),
24
+ baseDir: join(process.cwd(), 'src'),
25
+ });
26
+ }
27
+ if (dataSourceFileExports['typeorm']) {
28
+ dataSourceFileExports = dataSourceFileExports['typeorm'];
29
+ dataSourceFileExports =
30
+ dataSourceFileExports.dataSource[
31
+ dataSourceFileExports['defaultClientName'] || 'default'
32
+ ];
33
+
34
+ return new DataSource(dataSourceFileExports);
35
+ } else {
36
+ console.log(
37
+ '[midway:typeorm] Not found dataSource options and run origin loadDataSource method'
38
+ );
39
+ return originLoadDataSource(dataSourceFilePath);
40
+ }
41
+ }
42
+ } catch (err) {
43
+ throw new Error(
44
+ `Unable to open file: "${dataSourceFilePath}". ${err.message}`
45
+ );
46
+ }
47
+ };
48
+
49
+ // eslint-disable-next-line node/no-unpublished-require
50
+ require('typeorm/cli-ts-node-commonjs');
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@midwayjs/typeorm",
3
- "version": "3.9.0",
3
+ "version": "3.9.4",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
+ "bin": {
7
+ "mwtypeorm": "./cli.js"
8
+ },
6
9
  "files": [
7
10
  "dist/**/*.js",
8
11
  "dist/**/*.d.ts",
12
+ "cli.js",
9
13
  "index.d.ts"
10
14
  ],
11
15
  "devDependencies": {
12
16
  "@midwayjs/core": "^3.9.0",
13
17
  "@midwayjs/mock": "^3.9.0",
14
- "sqlite3": "5.1.2",
18
+ "sqlite3": "5.1.4",
15
19
  "typeorm": "0.3.11"
16
20
  },
17
21
  "author": {
@@ -31,5 +35,5 @@
31
35
  "type": "git",
32
36
  "url": "https://github.com/midwayjs/midway.git"
33
37
  },
34
- "gitHead": "5f6603d2c9606fc6fc7ece71f956e89e394efeee"
38
+ "gitHead": "b3daa4674afc965f147fc94b2801b4eefed87660"
35
39
  }