diff --git a/.gitignore b/.gitignore index c83f4e1..7b09b1c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ npm-debug.log ormconfig.json .vscode typings/ -**/*.js \ No newline at end of file +**/*.js +**/*.js.map \ No newline at end of file diff --git a/package.json b/package.json index 72eae56..a94df66 100644 --- a/package.json +++ b/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/src/Engine.ts b/src/Engine.ts index 38da424..d1f4526 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -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 } \ No newline at end of file diff --git a/src/drivers/AbstractDriver.ts b/src/drivers/AbstractDriver.ts index e74c0e4..cdee1a6 100644 --- a/src/drivers/AbstractDriver.ts +++ b/src/drivers/AbstractDriver.ts @@ -1,8 +1,6 @@ /** - * abstractDriver + * AbstractDriver */ -abstract class abstractDriver { - constructor(parameters) { - - } +export abstract class AbstractDriver { + } \ No newline at end of file diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index 083987f..ea9e85b 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -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(); } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 8f6fefc..d202316 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,70 @@ +import { MssqlDriver } from './drivers/MssqlDriver'; import * as Mustache from 'mustache' -var x = Mustache.render("{{a}}", {a:'test'}); -console.log(x); \ No newline at end of file +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 -d -p [port] -u -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(); + diff --git a/src/models/ColumnInfo.ts b/src/models/ColumnInfo.ts new file mode 100644 index 0000000..034f207 --- /dev/null +++ b/src/models/ColumnInfo.ts @@ -0,0 +1,6 @@ +/** + * ColumnInfo + */ +interface ColumnInfo { + +} \ No newline at end of file diff --git a/src/models/EntityInfo.ts b/src/models/EntityInfo.ts new file mode 100644 index 0000000..f3e57ec --- /dev/null +++ b/src/models/EntityInfo.ts @@ -0,0 +1,7 @@ +/** + * EntityInfo + */ +interface EntityInfo { + Columns:ColumnInfo[]; + Indexes:IndexInfo[]; +} \ No newline at end of file diff --git a/src/models/IndexInfo.ts b/src/models/IndexInfo.ts new file mode 100644 index 0000000..9358d74 --- /dev/null +++ b/src/models/IndexInfo.ts @@ -0,0 +1,6 @@ +/** + * IndexInfo + */ +interface IndexInfo { + +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index bb7a703..45b66b9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" } } \ No newline at end of file diff --git a/typings.json b/typings.json index 9add661..9ee9485 100644 --- a/typings.json +++ b/typings.json @@ -1,5 +1,8 @@ { "globalDevDependencies": { "mustache": "registry:dt/mustache#0.8.2+20160510002910" + }, + "dependencies": { + "yargs": "registry:npm/yargs#5.0.0+20160907000723" } }