eugene-manuilov/typeorm-uml

Allow the configuration to be given as a json object

raphael-leger opened this issue · 2 comments

Hi,

Currently, TypeormUml exposes a method build that has the following signature:

public async build( configName: string, flags: Flags )

where configName is the path of the orm config file, usually something called ormconfig.json

However, there are projects where the json orm configuration is not into a json file as it is built during runtime, for instance to allow the use of environment variables into the configuration.

It would be nice if typeorm-url could accept an orm config as json instead of a path to a json file.

The signature could become:

public async build( flags: Flags )

There would be two new flags :

  • jsonConfigPath: string
  • jsonConfig: any

And users of this library would be required to either use jsonConfigPath that is a path to a json config file or jsonConfig that is the raw json object, not stored into any file

Thanks for the suggestion, @raphael-leger!

I have updated the TypeormUml::build method to accept a connection instance itself. Here is a small example:

import { EOL } from 'os';
import { join } from 'path';

import { Direction, Flags, Format, TypeormUml } from 'typeorm-uml';
import { createConnection } from 'typeorm';

createConnection().then( async ( connection ) => {
    const flags: Flags = {
        direction: Direction.LR,
        format: Format.SVG,
        handwritten: true,
    };

    const typeormUml = new TypeormUml();
    const url = await typeormUml.build( connection, flags );

    process.stdout.write( 'Diagram URL: ' + url + EOL );
} );

Does it look good to you? Published it as @next for now. If everything works, I'll publish a new version.

Ok, it has been shipped with the new version 1.6.0. Closing this ticket.