tsplot
Version:
A CLI and tooling library to plot Typescript project information to different template targets.
82 lines • 4.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.diagram = exports.getDiagramRenderer = exports.setupDiagramCommand = void 0;
const tslib_1 = require("tslib");
const commander_1 = require("commander");
const consola_1 = require("consola");
const lib_1 = require("../../lib");
const utils_1 = require("../utils");
/**
* @deprecated
* @internal
*/
function setupDiagramCommand(program) {
return (0, utils_1.setupSharedOptions)(program
.command('diagram')
.description('DEPRECATED! use "render <template>" command instead')
.option('-e, --edgeless', 'indicates whether nodes without any edges shall be rendered or not', false)
.option('--fields', 'indicates whether fields shall be included in the diagram or not', true)
.option('--no-fields', "don't include fields in the diagram")
.option('--methods', 'indicates whether methods shall be included in the diagram or not', true)
.option('--no-methods', "don't include methods in the diagram")
.addOption(new commander_1.Option('-r, --renderer <name>, --target <name>', 'the type of the renderer to be used')
.choices(['plant-uml', 'mermaid'])
.default('plant-uml'))).action(diagram);
}
exports.setupDiagramCommand = setupDiagramCommand;
/**
* @deprecated
* @internal
*/
function getDiagramRenderer(options) {
switch (options.renderer) {
case 'plant-uml':
return (members) => new lib_1.PlantUMLClassDiagram(members).render(options);
case 'mermaid':
return (members) => {
const diagram = new lib_1.MermaidClassDiagram(members);
const output = new lib_1.MermaidClassDiagram(members).render(options);
(0, utils_1.logSizeWarningIfExceeding)({
output,
edges: diagram.getEdges().length,
maxOutputSize: 50000,
maxEdges: 500,
description: 'These are defaults set by Mermaid. To allow rendering of larger diagrams ' +
'you can adjust the configuration (see https://mermaid.js.org/config/schema-docs/config.html)',
});
return output;
};
default:
throw new Error(`unknown renderer: ${options.renderer}`);
}
}
exports.getDiagramRenderer = getDiagramRenderer;
/** @deprecated */
function diagram(options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
(0, utils_1.setupConsola)(options);
(0, utils_1.logSharedOptions)(options);
(0, utils_1.logDeprecationWarning)('"diagram" command', {
replaceWith: '"render <template>" command',
});
const projectView = (0, utils_1.getProjectView)(options);
const render = getDiagramRenderer(options);
if (options.debug) {
const s = yield (0, utils_1.collectStats)(Object.assign(Object.assign({}, options), { silent: true }));
consola_1.consola.debug('stats:', JSON.stringify(s, null, 2));
}
if (!options.split || !(options === null || options === void 0 ? void 0 : options.from)) {
const confinedView = yield (0, utils_1.getConfinedProjectViewFromMemberOrDefault)(projectView, options);
yield (0, utils_1.output)(render(confinedView.members, options), options);
}
else {
const memberBatch = yield Promise.all(options.from.map((m) => (0, utils_1.getConfinedProjectViewFromMemberOrDefault)(projectView, Object.assign(Object.assign({}, options), { from: [m] }))));
yield Promise.all(memberBatch.map((confinedView, index) => (0, utils_1.output)(render(confinedView.members, options), Object.assign(Object.assign({}, options), { output: (0, utils_1.interpolateOutputPath)(options.output, {
memberName: options.from[index],
index,
}) }))));
}
});
}
exports.diagram = diagram;
//# sourceMappingURL=diagram.js.map
;