added option to skip generating config files closes #17
This commit is contained in:
parent
daf22e3cbe
commit
cd6c61bc5a
16
README.md
16
README.md
@ -5,7 +5,7 @@
|
||||
[![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
|
||||
@ -19,7 +19,7 @@ Suported db engines:
|
||||
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`
|
||||
>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
|
||||
@ -37,24 +37,26 @@ Options:
|
||||
-o, --output Where to place generated models.
|
||||
-s, --schema Schema name to create model from. Only for mssql and postgres.
|
||||
--ssl [boolean] [default: false]
|
||||
--noConfig Doesn't create tsconfig.json and ormconfig.json
|
||||
[boolean] [default: false]
|
||||
```
|
||||
### Examples
|
||||
|
||||
* Creating model from local MSSQL database
|
||||
* Global module
|
||||
* Global module
|
||||
```
|
||||
typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\
|
||||
````
|
||||
* Npx Way
|
||||
* Npx Way
|
||||
```
|
||||
npx typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\
|
||||
````
|
||||
* Creating model from local Postgres database, public schema with ssl connection
|
||||
* Global module
|
||||
* Global module
|
||||
```
|
||||
typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ -s public --ssl
|
||||
````
|
||||
* Npx Way
|
||||
* Npx Way
|
||||
```
|
||||
npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ -s public --ssl
|
||||
````
|
||||
````
|
||||
|
@ -30,14 +30,17 @@ export class Engine {
|
||||
let resultPath = this.Options.resultsPath
|
||||
if (!fs.existsSync(resultPath))
|
||||
fs.mkdirSync(resultPath);
|
||||
this.createTsConfigFile(resultPath)
|
||||
this.createTypeOrmConfig(resultPath)
|
||||
let entitesPath = path.resolve(resultPath, './entities')
|
||||
let entitesPath = resultPath
|
||||
if (!this.Options.noConfigs) {
|
||||
this.createTsConfigFile(resultPath)
|
||||
this.createTypeOrmConfig(resultPath)
|
||||
entitesPath = path.resolve(resultPath, './entities')
|
||||
if (!fs.existsSync(entitesPath))
|
||||
fs.mkdirSync(entitesPath);
|
||||
}
|
||||
Handlebars.registerHelper('toLowerCase', function (str) {
|
||||
return str.toLowerCase();
|
||||
});
|
||||
if (!fs.existsSync(entitesPath))
|
||||
fs.mkdirSync(entitesPath);
|
||||
let compliedTemplate = Handlebars.compile(template, { noEscape: true })
|
||||
databaseModel.entities.forEach(element => {
|
||||
let resultFilePath = path.resolve(entitesPath, element.EntityName + '.ts');
|
||||
@ -45,7 +48,7 @@ export class Engine {
|
||||
fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' })
|
||||
});
|
||||
}
|
||||
//TODO:Move to mustache template file
|
||||
//TODO:Move to mustache template file
|
||||
private createTsConfigFile(resultPath) {
|
||||
fs.writeFileSync(path.resolve(resultPath, 'tsconfig.json'), `{"compilerOptions": {
|
||||
"lib": ["es5", "es6"],
|
||||
@ -107,5 +110,6 @@ export interface EngineOptions {
|
||||
resultsPath: string,
|
||||
databaseType: string,
|
||||
schemaName: string,
|
||||
ssl: boolean
|
||||
ssl: boolean,
|
||||
noConfigs: boolean
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ var argv = Yargs
|
||||
boolean: true,
|
||||
default: false
|
||||
})
|
||||
.option('noConfig', {
|
||||
boolean: true,
|
||||
describe: `Doesn't create tsconfig.json and ormconfig.json`,
|
||||
default: false
|
||||
})
|
||||
.argv;
|
||||
|
||||
|
||||
@ -100,7 +105,8 @@ let engine = new Engine(
|
||||
databaseType: argv.e,
|
||||
resultsPath: argv.o,
|
||||
schemaName: argv.s || standardSchema,
|
||||
ssl: argv.ssl
|
||||
ssl: argv.ssl,
|
||||
noConfigs: argv.noConfig
|
||||
});
|
||||
|
||||
console.log(`[${new Date().toLocaleTimeString()}] Starting creation of model classes.`);
|
||||
|
@ -49,7 +49,8 @@ export async function createMSSQLModels(filesOrgPath: string, resultsPath: strin
|
||||
databaseType: 'mssql',
|
||||
resultsPath: resultsPath,
|
||||
schemaName: 'dbo',
|
||||
ssl: yn(process.env.MSSQL_SSL)
|
||||
ssl: yn(process.env.MSSQL_SSL),
|
||||
noConfigs: false
|
||||
});
|
||||
|
||||
|
||||
@ -92,7 +93,8 @@ export async function createPostgresModels(filesOrgPath: string, resultsPath: st
|
||||
databaseType: 'postgres',
|
||||
resultsPath: resultsPath,
|
||||
schemaName: 'public',
|
||||
ssl: yn(process.env.POSTGRES_SSL)
|
||||
ssl: yn(process.env.POSTGRES_SSL),
|
||||
noConfigs: false
|
||||
});
|
||||
|
||||
|
||||
@ -136,7 +138,8 @@ export async function createMysqlModels(filesOrgPath: string, resultsPath: strin
|
||||
databaseType: 'mysql',
|
||||
resultsPath: resultsPath,
|
||||
schemaName: 'ignored',
|
||||
ssl: yn(process.env.MYSQL_SSL)
|
||||
ssl: yn(process.env.MYSQL_SSL),
|
||||
noConfigs: false
|
||||
});
|
||||
|
||||
|
||||
@ -180,7 +183,8 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str
|
||||
databaseType: 'mariadb',
|
||||
resultsPath: resultsPath,
|
||||
schemaName: 'ignored',
|
||||
ssl: yn(process.env.MARIADB_SSL)
|
||||
ssl: yn(process.env.MARIADB_SSL),
|
||||
noConfigs: false
|
||||
});
|
||||
|
||||
|
||||
@ -226,7 +230,8 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st
|
||||
databaseType: 'oracle',
|
||||
resultsPath: resultsPath,
|
||||
schemaName: String(process.env.ORACLE_Username),
|
||||
ssl: yn(process.env.ORACLE_SSL)
|
||||
ssl: yn(process.env.ORACLE_SSL),
|
||||
noConfigs: false
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user