extract-mysql-schema 0.0.8 → 0.0.10

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 (3) hide show
  1. package/example.js +10 -0
  2. package/package.json +2 -1
  3. package/run.js +44 -10
package/example.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ connection: {
3
+ engine: 'mysql',
4
+ host: '127.0.0.1',
5
+ user: 'root',
6
+ password: 'password',
7
+ database: 'db',
8
+ charset: 'utf8'
9
+ }
10
+ };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "extract-mysql-schema",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "bin": "./run.js",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/cdotyone/extract-mysql-schema.git"
package/run.js CHANGED
@@ -1,16 +1,50 @@
1
+ const fs = require("fs");
1
2
  const { extractSchemas } = require('./index.js');
2
3
 
3
- async function run() {
4
- const connection = {
5
- host: '127.0.0.1',
6
- database: 'db',
7
- user: 'root',
8
- password: 'password',
9
- };
4
+ async function main(options) {
5
+ const config = require(options.configFile);
6
+ const result = await extractSchemas(config.connection);
7
+ if(options.outputFile) {
8
+ fs.writeFileSync(options.outputFile, JSON.stringify(result,null,2) ,"utf8")
9
+ } else console.log(JSON.stringify(result,null,2));
10
+ }
11
+
12
+ let options = {
13
+ configFile:"",
14
+ outputFile:"",
15
+ }
10
16
 
11
- const result = await extractSchemas(connection);
17
+ if (process.argv.length === 2) {
18
+ console.error('Expected at least one argument!');
19
+ process.exit(1);
20
+ } else {
21
+ let argv = process.argv;
12
22
 
13
- console.log(JSON.stringify(result,null,2));
23
+ for(let i=2;i<argv.length;i++) {
24
+ if(argv[i].substring(0,2)==="--") {
25
+ let name = argv[i].substring(2);
26
+ if(options[name]!==undefined) {
27
+ options[name] = argv[i+1];
28
+ i++;
29
+ } else {
30
+ console.error('Expected a known option');
31
+ process.exit(1);
32
+ }
33
+ }
34
+ }
14
35
  }
15
36
 
16
- run();
37
+ (async () => {
38
+ try {
39
+ console.log('\x1b[32m%s\x1b[0m',"Running with options:\n",JSON.stringify(options,null,2));
40
+ main(options).then(()=>{
41
+ if(options.debug) console.log("DONE");
42
+ process.exit(0);
43
+ },()=>{
44
+ if(options.debug) console.log("ERROR");
45
+ process.exit(1);
46
+ })
47
+ } catch (e) {
48
+ process.exit(1);
49
+ }
50
+ })();