From cd6c61bc5a7ab2d6db5dbc571f52a84188731a81 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 16 Jan 2018 23:07:35 +0100 Subject: [PATCH] added option to skip generating config files closes #17 --- README.md | 16 +++++++++------- src/Engine.ts | 18 +++++++++++------- src/index.ts | 8 +++++++- test/utils/GeneralTestUtils.ts | 15 ++++++++++----- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bb90d0c..e8ab4e2 100644 --- a/README.md +++ b/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 - ```` \ No newline at end of file + ```` diff --git a/src/Engine.ts b/src/Engine.ts index 92cc2a2..7f7fb72 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -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 } diff --git a/src/index.ts b/src/index.ts index 32c4bdb..ebe42e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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.`); diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 68a88ad..fb00ae1 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -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 });