Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package visualizations #3823

Merged
merged 6 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -35,3 +35,4 @@ tsconfig.tsbuildinfo

knsv*.html
local*.html
stats/
26 changes: 23 additions & 3 deletions .vite/build.ts
@@ -1,9 +1,12 @@
import { build, InlineConfig } from 'vite';
import { build, InlineConfig, type PluginOption } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
import { readFileSync } from 'fs';
import { visualizer } from 'rollup-plugin-visualizer';
import type { TemplateType } from 'rollup-plugin-visualizer/dist/plugin/template-types.js';

const visualize = process.argv.includes('--visualize');
const watch = process.argv.includes('--watch');
const mermaidOnly = process.argv.includes('--mermaid');
const __dirname = fileURLToPath(new URL('.', import.meta.url));
Expand All @@ -13,6 +16,20 @@ type OutputOptions = Exclude<
undefined
>['output'];

const visualizerOptions = (packageName: string, core = false): PluginOption[] => {
if (packageName !== 'mermaid' || !visualize) {
return [];
}
return ['network', 'treemap', 'sunburst'].map((chartType) =>
visualizer({
filename: `./stats/${chartType}${core ? '.core' : ''}.html`,
template: chartType as TemplateType,
gzipSize: true,
brotliSize: true,
})
);
};

const packageOptions = {
mermaid: {
name: 'mermaid',
Expand Down Expand Up @@ -95,7 +112,7 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
resolve: {
extensions: ['.jison', '.js', '.ts', '.json'],
},
plugins: [jisonPlugin()],
plugins: [jisonPlugin(), ...visualizerOptions(packageName, core)],
};

if (watch && config.build) {
Expand All @@ -121,7 +138,7 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {

const main = async () => {
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
for (const pkg of packageNames) {
for (const pkg of packageNames.filter((pkg) => !mermaidOnly || pkg === 'mermaid')) {
await buildPackage(pkg);
}
};
Expand All @@ -132,6 +149,9 @@ if (watch) {
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-mindmap' }));
// build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
}
} else if (visualize) {
await build(getBuildConfig({ minify: false, core: true, entryName: 'mermaid' }));
await build(getBuildConfig({ minify: false, core: false, entryName: 'mermaid' }));
} else {
void main();
}
2 changes: 2 additions & 0 deletions cSpell.json
Expand Up @@ -14,6 +14,7 @@
"bilkent",
"bisheng",
"brolin",
"brotli",
"codedoc",
"colour",
"cpettitt",
Expand Down Expand Up @@ -70,6 +71,7 @@
"substate",
"sveidqvist",
"techn",
"treemap",
"ts-nocheck",
"tuleap",
"verdana",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -15,8 +15,9 @@
"git graph"
],
"scripts": {
"build:mermaid": "ts-node-esm --transpileOnly .vite/build.ts --mermaid",
"build:vite": "ts-node-esm --transpileOnly .vite/build.ts",
"build:mermaid": "pnpm build:vite --mermaid",
"build:viz": "pnpm build:mermaid --visualize",
"build:types": "tsc -p ./packages/mermaid/tsconfig.json --emitDeclarationOnly && tsc -p ./packages/mermaid-mindmap/tsconfig.json --emitDeclarationOnly",
"build:watch": "pnpm build:vite --watch",
"build": "pnpm run -r clean && concurrently \"pnpm build:vite\" \"pnpm build:types\"",
Expand Down Expand Up @@ -64,6 +65,7 @@
"@types/mdast": "^3.0.10",
"@types/node": "^18.11.9",
"@types/prettier": "^2.7.1",
"@types/rollup-plugin-visualizer": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"@vitest/coverage-c8": "^0.25.1",
Expand Down Expand Up @@ -96,6 +98,7 @@
"prettier": "^2.7.1",
"prettier-plugin-jsdoc": "^0.4.2",
"rimraf": "^3.0.2",
"rollup-plugin-visualizer": "^5.8.3",
"start-server-and-test": "^1.14.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaidAPI.ts
Expand Up @@ -29,7 +29,7 @@ import utils, { directiveSanitizer } from './utils';
import DOMPurify from 'dompurify';
import { MermaidConfig } from './config.type';
import { evaluate } from './diagrams/common/common';
import { isEmpty } from 'lodash';
import isEmpty from 'lodash/isEmpty';

// diagram names that support classDef statements
const CLASSDEF_DIAGRAMS = ['graph', 'flowchart', 'flowchart-v2', 'stateDiagram', 'stateDiagram-v2'];
Expand Down
48 changes: 47 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.