diff --git a/.gitignore b/.gitignore index e4f7812..4236107 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ output/**/*.* .nyc_output/ coverage/ .env -dist \ No newline at end of file +dist +*.tgz diff --git a/.npmignore b/.npmignore index 63ff1d7..2619f63 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,22 @@ -tests/**/* \ No newline at end of file +node_modules/ +npm-debug.log +ormconfig.json +.vscode +typings/ +**/*.js.map +output/**/*.* +.nyc_output/ +coverage/ +.env +*.tgz + + +!src/ +src/* +!src/*.mst +test/ +.travis.yml +codecov.yml +tsconfig.json +typings.json +dist/test/ diff --git a/README.md b/README.md index f2e4d41..1ead668 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,51 @@ [![npm version](https://badge.fury.io/js/typeorm-model-generator.svg)](https://badge.fury.io/js/typeorm-model-generator) [![codecov](https://codecov.io/gh/Kononnable/typeorm-model-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/Kononnable/typeorm-model-generator) -Generates models for TypeORM from existing databases. +Generates models for TypeORM from existing databases. +Suported db engines: +* Microsoft SQL Server +* PostgreSQL -*Work in progress* \ No newline at end of file + + +## Installation +### Global module +To install module globally simply type `npm i -g typeorm-model-generator` in your console. +### Npx way +Thanks to npx you can use npm modules without polluting global installs. So nothing to do here :) +>To use `npx` you need to use npm at version at least 5.2.0. Try updating your npm by `npm i -g npm` +## Usage + +```shell +Usage: typeorm-model-generator -h -d -p [port] -u -x +[password] -e [engine] + +Options: + -h, --host IP adress/Hostname for database server. [required] + -d, --database Database name. [required] + -u, --user Username for database server. [required] + -x, --pass Password for database server. [required] + -p, --port Port number for database server. + -e, --engine Database engine. [choices: "mssql", "postgres"] + -o, --output Where to place generated models. +``` +### Examples + +* Creating model from local MSSQL database + * Global module + ``` + typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\ + ```` + * Npx Way + ``` + npx typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\ + ```` +* Creating model from local Postgres database + * Global module + ``` + typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ + ```` + * Npx Way + ``` + npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ + ```` \ No newline at end of file diff --git a/bin/typeorm-model-generator b/bin/typeorm-model-generator new file mode 100644 index 0000000..533cd31 --- /dev/null +++ b/bin/typeorm-model-generator @@ -0,0 +1,6 @@ +#!/usr/bin/env node +'use strict'; + + + +require('../dist/src/index'); \ No newline at end of file diff --git a/package.json b/package.json index 1f54e17..5b17e19 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "typeorm-model-generator", "version": "0.0.1", "description": "Generates models for TypeORM from existing databases.", + "bin": "bin/typeorm-model-generator", "scripts": { "tsc:w": "tsc -w", "tsc": "tsc", diff --git a/src/Engine.ts b/src/Engine.ts index 7259ad4..04cc383 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -25,7 +25,7 @@ export class Engine { } private createModelFromMetadata(databaseModel: DatabaseModel) { - let templatePath = path.resolve(process.cwd(), 'src/entity.mst') + let templatePath = path.resolve(__dirname, '../../src/entity.mst') let template = fs.readFileSync(templatePath, 'UTF-8'); let resultPath = this.Options.resultsPath if (!fs.existsSync(resultPath))