mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-19 08:16:42 +02:00
Build Visualization
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
import { build } from 'esbuild';
|
import { build, context } from 'esbuild';
|
||||||
|
import { mkdir, writeFile } from 'node:fs/promises';
|
||||||
import { getBuildConfig, packageOptions } from './util.js';
|
import { getBuildConfig, packageOptions } from './util.js';
|
||||||
import { context } from 'esbuild';
|
|
||||||
|
|
||||||
const shouldWatch = process.argv.includes('--watch');
|
const shouldWatch = process.argv.includes('--watch');
|
||||||
|
const shouldVisualize = process.argv.includes('--visualize');
|
||||||
|
|
||||||
const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
||||||
await build(getBuildConfig({ entryName, minify: false }));
|
await build(getBuildConfig({ entryName, minify: false }));
|
||||||
await build(getBuildConfig({ entryName, minify: true }));
|
const { metafile } = await build(
|
||||||
|
getBuildConfig({ entryName, minify: true, metafile: shouldVisualize })
|
||||||
|
);
|
||||||
|
if (metafile) {
|
||||||
|
await writeFile(`stats/meta-${entryName}.json`, JSON.stringify(metafile));
|
||||||
|
}
|
||||||
await build(getBuildConfig({ entryName, minify: false, core: true }));
|
await build(getBuildConfig({ entryName, minify: false, core: true }));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,6 +22,7 @@ const handler = (e) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
await mkdir('stats');
|
||||||
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
|
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
|
||||||
for (const pkg of packageNames) {
|
for (const pkg of packageNames) {
|
||||||
await buildPackage(pkg).catch(handler);
|
await buildPackage(pkg).catch(handler);
|
||||||
|
@@ -23,6 +23,7 @@ export const packageOptions = {
|
|||||||
interface MermaidBuildOptions {
|
interface MermaidBuildOptions {
|
||||||
minify: boolean;
|
minify: boolean;
|
||||||
core?: boolean;
|
core?: boolean;
|
||||||
|
metafile?: boolean;
|
||||||
entryName: keyof typeof packageOptions;
|
entryName: keyof typeof packageOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +59,12 @@ const jisonPlugin = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBuildConfig = ({ minify, core, entryName }: MermaidBuildOptions): BuildOptions => {
|
export const getBuildConfig = ({
|
||||||
|
minify,
|
||||||
|
core,
|
||||||
|
entryName,
|
||||||
|
metafile,
|
||||||
|
}: MermaidBuildOptions): BuildOptions => {
|
||||||
const external: string[] = ['require', 'fs', 'path'];
|
const external: string[] = ['require', 'fs', 'path'];
|
||||||
const { name, file, packageName } = packageOptions[entryName];
|
const { name, file, packageName } = packageOptions[entryName];
|
||||||
let output: BuildOptions = buildOptions({
|
let output: BuildOptions = buildOptions({
|
||||||
@@ -66,6 +72,7 @@ export const getBuildConfig = ({ minify, core, entryName }: MermaidBuildOptions)
|
|||||||
entryPoints: {
|
entryPoints: {
|
||||||
[`${name}.esm${core ? '.core' : ''}${minify ? '.min' : ''}`]: `src/${file}`,
|
[`${name}.esm${core ? '.core' : ''}${minify ? '.min' : ''}`]: `src/${file}`,
|
||||||
},
|
},
|
||||||
|
metafile,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (core) {
|
if (core) {
|
||||||
@@ -78,12 +85,5 @@ export const getBuildConfig = ({ minify, core, entryName }: MermaidBuildOptions)
|
|||||||
external.push(...Object.keys(dependencies));
|
external.push(...Object.keys(dependencies));
|
||||||
output.external = external;
|
output.external = external;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (watch && config.build) {
|
|
||||||
// config.build.watch = {
|
|
||||||
// include: ['packages/mermaid-example-diagram/src/**', 'packages/mermaid/src/**'],
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user