Added reading passed arguments;

some base classes
This commit is contained in:
Kononnable 2017-03-26 03:38:09 +02:00
parent 276720e5e5
commit a93b972f41
11 changed files with 139 additions and 19 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ npm-debug.log
ormconfig.json
.vscode
typings/
**/*.js
**/*.js
**/*.js.map

View File

@ -6,7 +6,7 @@
"tsc:w": "tsc -w",
"typings-install": "typings install",
"setup": "npm install && npm run typings-install",
"start": "tsc && node ./index.js"
"start": "tsc && node ./src/index.js"
},
"repository": {
"type": "git",
@ -23,9 +23,10 @@
"mssql": "^3.3.0",
"mustache": "^2.3.0",
"reflect-metadata": "^0.1.10",
"typeorm": "0.0.10"
"typeorm": "0.0.10",
"yargs": "^7.0.2"
},
"devDependencies": {
"typings": "^2.1.0"
}
}
}

View File

@ -1,8 +1,32 @@
import { MssqlDriver } from './drivers/MssqlDriver'
import { AbstractDriver } from "./drivers/AbstractDriver";
/**
* Engine
*/
class Engine {
constructor(parameters) {
export class Engine {
constructor(public Options: EngineOptions, private driver:AbstractDriver) {
}
public createModelFromDatabase(): boolean {
let entities = this.getEntitiesInfo();
if (entities.length>0) {
this.createModelFromMetadata(entities);
} else {
console.error('Tables not found in selected database. Skipping creation of typeorm model.');
}
return true;
}
private getEntitiesInfo(): EntityInfo[] {
return [];
}
private createModelFromMetadata(entities: EntityInfo[]) {
}
}
export interface EngineOptions {
host:string,
port:string,
databaseName:string,
user:string,
password:string
}

View File

@ -1,8 +1,6 @@
/**
* abstractDriver
* AbstractDriver
*/
abstract class abstractDriver {
constructor(parameters) {
}
export abstract class AbstractDriver {
}

View File

@ -1,9 +1,10 @@
import {AbstractDriver} from './abstractDriver'
/**
* mssqlDriver
* MssqlDriver
*/
class mssqlDriver extends abstractDriver {
constructor(parameters) {
super(parameters);
export class MssqlDriver extends AbstractDriver {
constructor() {
super();
}
}

View File

@ -1,3 +1,70 @@
import { MssqlDriver } from './drivers/MssqlDriver';
import * as Mustache from 'mustache'
var x = Mustache.render("{{a}}", {a:'test'});
console.log(x);
import { Engine } from './Engine'
import * as Yargs from 'yargs'
import { AbstractDriver } from "./drivers/abstractDriver";
// var x = Mustache.render("{{a}}", { a: 'test' });
// console.log(x);
var argv = Yargs
.usage('Usage: typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x [password] -e [engine]')
.option('h', {
alias: 'host',
describe: 'IP adress/Hostname for database server.',
demand: true
})
.option('d', {
alias: 'database',
describe: 'Database name.',
demand: true
})
.option('u', {
alias: 'user',
describe: 'Username for database server.',
demand: true
})
.option('x', {
alias: 'pass',
describe: 'Password for database server.',
demand: true
})
.option('p', {
alias: 'port',
describe: 'Port number for database server.',
})
.option('e', {
alias: 'engine',
describe: 'Database engine.',
choices: ['mssql'],
default: 'mssql'
})
.argv;
var driver: AbstractDriver;
var standardPort:string;
switch (argv.e) {
case 'mssql':
driver = new MssqlDriver();
standardPort=''
break;
default:
driver = new MssqlDriver();
standardPort=''
break;
}
let engine = new Engine(
{
host:argv.h,
port:argv.p || standardPort,
databaseName:argv.d,
user:argv.u,
password:argv.x
}, driver);
// if(Yargs.)
engine.createModelFromDatabase();

6
src/models/ColumnInfo.ts Normal file
View File

@ -0,0 +1,6 @@
/**
* ColumnInfo
*/
interface ColumnInfo {
}

7
src/models/EntityInfo.ts Normal file
View File

@ -0,0 +1,7 @@
/**
* EntityInfo
*/
interface EntityInfo {
Columns:ColumnInfo[];
Indexes:IndexInfo[];
}

6
src/models/IndexInfo.ts Normal file
View File

@ -0,0 +1,6 @@
/**
* IndexInfo
*/
interface IndexInfo {
}

View File

@ -5,6 +5,12 @@
"noImplicitAny": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": false
"sourceMap": true,
"declaration": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"stripInternal": true,
"strictNullChecks": true,
"moduleResolution": "node"
}
}

View File

@ -1,5 +1,8 @@
{
"globalDevDependencies": {
"mustache": "registry:dt/mustache#0.8.2+20160510002910"
},
"dependencies": {
"yargs": "registry:npm/yargs#5.0.0+20160907000723"
}
}