pg-mermaid
Version:
Mermaid diagram generator for PostgreSQL database schema
55 lines (54 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOptions = exports.createProgram = void 0;
const commander_1 = require("commander");
const common_tags_1 = require("common-tags");
const zod_1 = require("zod");
const handleCommaSeparatedExcludedTableList = (excludedTable, previousExcludedTables = []) => {
if (excludedTable.includes(',')) {
const excludedTables = excludedTable.split(',');
// eslint-disable-next-line no-console
console.warn(`warn: '--excluded-tables' flag with comma-separated list is deprecated, please use space-separated list instead ('--excluded-tables ${excludedTables.join(' ')}')`);
return excludedTables;
}
return previousExcludedTables.concat([excludedTable]);
};
const createProgram = () => {
const program = new commander_1.Command();
program
.requiredOption('-d, --dbname <dbname>', 'database name to connect to')
.requiredOption('-U, --username <username>', 'username to connect to the database')
.addOption(new commander_1.Option('--password <password>')
.makeOptionMandatory()
.env('PGPASSWORD')
.hideHelp())
.requiredOption('-h, --host <hostname>', 'host address of the database', '127.0.0.1')
.requiredOption('-p, --port <port>', 'port number at which the instance is listening', '5432')
.requiredOption('--schema <schema>', 'schema name to generate to', 'public')
.requiredOption('--output-path <outputPath>', 'output path to generate to', './database.md')
.option('--excluded-tables <tables...>', 'tables to exclude', handleCommaSeparatedExcludedTableList)
.addHelpText('after', '\n' +
(0, common_tags_1.stripIndent) `
Environment variables:
PGPASSWORD password to be used if the server demands password authentication
Example call:
$ PGPASSWORD=<password> npx pg-mermaid --dbname <dbname> --username <username>
`);
return program;
};
exports.createProgram = createProgram;
const getOptions = ({ program = (0, exports.createProgram)(), } = {}) => {
const OptionsSchema = zod_1.z.object({
dbname: zod_1.z.string(),
excludedTables: zod_1.z.union([zod_1.z.string().array(), zod_1.z.undefined()]),
host: zod_1.z.string(),
outputPath: zod_1.z.string(),
password: zod_1.z.string(),
port: zod_1.z.coerce.number(),
schema: zod_1.z.string(),
username: zod_1.z.string(),
});
return OptionsSchema.parse(program.parse().opts());
};
exports.getOptions = getOptions;
//# sourceMappingURL=command.js.map