mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
000b432bb2
* develop: (70 commits) build(deps-dev): bump vite from 4.4.9 to 4.4.12 Changes to .prettierignore 1. Added 'demos/dev/**' to be ignored by Prettier. 2. Added '!/demos/dev/example.html' so that Prettier ensures no one changes the example.html in a way that doesn't obey the Prettier code formatting rules. build: use `tsx` instead of `ts-node-esm` chore: Downgrade node to 18.18.2 fix: #5100 Add viewbox to sankey chore(deps): update all minor dependencies chore: Rename test test: Add unit test for generic classname and namespace fix: Check if parentCommit is provided Split type from generic class name Condition of Parent Id Without Merge Commit Added Referenced the PmWiki's Cookbook recipe enabling MermaidJs schematics in wiki pages test(e2e): fix pie chart E2E tests for PR #4288 Add dummy commit to trigger GH checks chore: Revert unnecessary export refactor: Remove unnecessary calculations chore: Fix computeWidth function chore: Cleanup setupGraphViewbox Update docs update mermaidAPI to cleanup the text before passing to getDiagramFromText ...
136 lines
4.3 KiB
TypeScript
136 lines
4.3 KiB
TypeScript
import { build, InlineConfig, type PluginOption } from 'vite';
|
|
import { resolve } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import jisonPlugin from './jisonPlugin.js';
|
|
import jsonSchemaPlugin from './jsonSchemaPlugin.js';
|
|
import typescript from '@rollup/plugin-typescript';
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
import type { TemplateType } from 'rollup-plugin-visualizer/dist/plugin/template-types.js';
|
|
import istanbul from 'vite-plugin-istanbul';
|
|
import { packageOptions } from '../.build/common.js';
|
|
import { generateLangium } from '../.build/generateLangium.js';
|
|
|
|
const visualize = process.argv.includes('--visualize');
|
|
const watch = process.argv.includes('--watch');
|
|
const mermaidOnly = process.argv.includes('--mermaid');
|
|
const coverage = process.env.VITE_COVERAGE === 'true';
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
const sourcemap = false;
|
|
|
|
type OutputOptions = Exclude<
|
|
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
|
|
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,
|
|
}) as PluginOption
|
|
);
|
|
};
|
|
|
|
interface BuildOptions {
|
|
minify: boolean | 'esbuild';
|
|
core?: boolean;
|
|
watch?: boolean;
|
|
entryName: keyof typeof packageOptions;
|
|
}
|
|
|
|
export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions): InlineConfig => {
|
|
const external: (string | RegExp)[] = ['require', 'fs', 'path'];
|
|
console.log(entryName, packageOptions[entryName]);
|
|
const { name, file, packageName } = packageOptions[entryName];
|
|
let output: OutputOptions = [
|
|
{
|
|
name,
|
|
format: 'esm',
|
|
sourcemap,
|
|
entryFileNames: `${name}.esm${minify ? '.min' : ''}.mjs`,
|
|
},
|
|
];
|
|
|
|
const config: InlineConfig = {
|
|
configFile: false,
|
|
build: {
|
|
emptyOutDir: false,
|
|
outDir: resolve(__dirname, `../packages/${packageName}/dist`),
|
|
lib: {
|
|
entry: resolve(__dirname, `../packages/${packageName}/src/${file}`),
|
|
name,
|
|
// the proper extensions will be added
|
|
fileName: name,
|
|
},
|
|
minify,
|
|
rollupOptions: {
|
|
external,
|
|
output,
|
|
},
|
|
},
|
|
define: {
|
|
'import.meta.vitest': 'undefined',
|
|
},
|
|
resolve: {
|
|
extensions: [],
|
|
},
|
|
plugins: [
|
|
jisonPlugin(),
|
|
jsonSchemaPlugin(), // handles `.schema.yaml` files
|
|
// @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite
|
|
typescript({ compilerOptions: { declaration: false } }),
|
|
istanbul({
|
|
exclude: ['node_modules', 'test/', '__mocks__', 'generated'],
|
|
extension: ['.js', '.ts'],
|
|
requireEnv: true,
|
|
forceBuildInstrument: coverage,
|
|
}),
|
|
...visualizerOptions(packageName, core),
|
|
],
|
|
};
|
|
|
|
if (watch && config.build) {
|
|
config.build.watch = {
|
|
include: ['packages/mermaid-example-diagram/src/**', 'packages/mermaid/src/**'],
|
|
};
|
|
}
|
|
|
|
return config;
|
|
};
|
|
|
|
const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
|
await build(getBuildConfig({ minify: false, entryName }));
|
|
};
|
|
|
|
const main = async () => {
|
|
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
|
|
for (const pkg of packageNames.filter(
|
|
(pkg) => !mermaidOnly || pkg === 'mermaid' || pkg === 'parser'
|
|
)) {
|
|
await buildPackage(pkg);
|
|
}
|
|
};
|
|
|
|
await generateLangium();
|
|
|
|
if (watch) {
|
|
await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' }));
|
|
build(getBuildConfig({ minify: false, watch, core: false, entryName: 'mermaid' }));
|
|
if (!mermaidOnly) {
|
|
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
|
|
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-zenuml' }));
|
|
}
|
|
} else if (visualize) {
|
|
await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' }));
|
|
await build(getBuildConfig({ minify: false, core: true, entryName: 'mermaid' }));
|
|
await build(getBuildConfig({ minify: false, core: false, entryName: 'mermaid' }));
|
|
} else {
|
|
void main();
|
|
}
|