Skip to content

Commit

Permalink
Merge branch 'develop' into fix/RequirementDiagramOverflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Aug 20, 2024
2 parents a4bbaf0 + 6205ddd commit 22168ed
Show file tree
Hide file tree
Showing 366 changed files with 30,020 additions and 17,431 deletions.
8 changes: 4 additions & 4 deletions .build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const packageOptions = {
packageName: 'mermaid-zenuml',
file: 'detector.ts',
},
'mermaid-flowchart-elk': {
name: 'mermaid-flowchart-elk',
packageName: 'mermaid-flowchart-elk',
file: 'detector.ts',
'mermaid-layout-elk': {
name: 'mermaid-layout-elk',
packageName: 'mermaid-layout-elk',
file: 'layouts.ts',
},
} as const;
1 change: 1 addition & 0 deletions .build/jisonTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import jison from 'jison';

export const transformJison = (src: string): string => {
// @ts-ignore - Jison is not typed properly
const parser = new jison.Generator(src, {
moduleType: 'js',
'token-stack': true,
Expand Down
13 changes: 10 additions & 3 deletions .build/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/* eslint-disable no-console */
import { packageOptions } from './common.js';
import { execSync } from 'child_process';

const buildType = (packageName: string) => {
console.log(`Building types for ${packageName}`);
try {
const out = execSync(`tsc -p ./packages/${packageName}/tsconfig.json --emitDeclarationOnly`);
out.length > 0 && console.log(out.toString());
if (out.length > 0) {
console.log(out.toString());
}
} catch (e) {
console.error(e);
e.stdout.length > 0 && console.error(e.stdout.toString());
e.stderr.length > 0 && console.error(e.stderr.toString());
if (e.stdout.length > 0) {
console.error(e.stdout.toString());
}
if (e.stderr.length > 0) {
console.error(e.stderr.toString());
}
}
};

Expand Down
6 changes: 6 additions & 0 deletions .cspell/code-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bqstring
BQUOTE
bramp
BRKT
brotli
callbackargs
callbackname
classdef
Expand All @@ -27,6 +28,7 @@ controly
CSSCLASS
CYLINDEREND
CYLINDERSTART
DAGA
datakey
DEND
descr
Expand Down Expand Up @@ -89,6 +91,7 @@ reqs
rewritelinks
rgba
RIGHTOF
roughjs
sankey
sequencenumber
shrc
Expand All @@ -108,9 +111,11 @@ strikethrough
stringifying
struct
STYLECLASS
STYLEDEF
STYLEOPTS
subcomponent
subcomponents
subconfig
SUBROUTINEEND
SUBROUTINESTART
Subschemas
Expand All @@ -125,6 +130,7 @@ titlevalue
topbar
TRAPEND
TRAPSTART
treemap
ts-nocheck
tsdoc
typeof
Expand Down
1 change: 1 addition & 0 deletions .cspell/contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ cpettitt
Dong Cai
Nikolay Rozhkov
Peng Xiao
Per Brolin
subhash-halder
Vinod Sidharth
4 changes: 4 additions & 0 deletions .cspell/libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dagre-d3
Deepdwn
Docsify
Docsy
Doctave
DokuWiki
dompurify
elkjs
Expand Down Expand Up @@ -54,13 +55,16 @@ presetAttributify
pyplot
redmine
rehype
roughjs
rscratch
shiki
sparkline
sphinxcontrib
ssim
stylis
Swimm
tsbuildinfo
tseslint
Tuleap
Typora
unocss
Expand Down
2 changes: 2 additions & 0 deletions .cspell/mermaid-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ elems
gantt
gitgraph
gzipped
handDrawn
knsv
Knut
marginx
Expand All @@ -17,6 +18,7 @@ Markdownish
mermaidjs
mindmap
mindmaps
mrtree
multigraph
nodesep
NOTEGROUP
Expand Down
5 changes: 5 additions & 0 deletions .cspell/misc-terms.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
BRANDES
circo
handDrawn
KOEPF
neato
newbranch
14 changes: 8 additions & 6 deletions .esbuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { build } from 'esbuild';
import { mkdir, writeFile } from 'node:fs/promises';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';
import type { MermaidBuildOptions } from './util.js';
import { defaultOptions, getBuildConfig } from './util.js';

const shouldVisualize = process.argv.includes('--visualize');

const buildPackage = async (entryName: keyof typeof packageOptions) => {
const commonOptions = { ...defaultOptions, entryName } as const;
const buildConfigs = [
const commonOptions: MermaidBuildOptions = { ...defaultOptions, entryName } as const;
const buildConfigs: MermaidBuildOptions[] = [
// package.mjs
{ ...commonOptions },
// package.min.mjs
Expand All @@ -35,11 +36,11 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {

if (shouldVisualize) {
for (const { metafile } of results) {
if (!metafile) {
if (!metafile?.outputs) {
continue;
}
const fileName = Object.keys(metafile.outputs)
.filter((file) => !file.includes('chunks') && file.endsWith('js'))[0]
.find((file) => !file.includes('chunks') && file.endsWith('js'))
.replace('dist/', '');
// Upload metafile into https://esbuild.github.io/analyze/
await writeFile(`stats/${fileName}.meta.json`, JSON.stringify(metafile));
Expand All @@ -48,13 +49,14 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
};

const handler = (e) => {
// eslint-disable-next-line no-console
console.error(e);
process.exit(1);
};

const main = async () => {
await generateLangium();
await mkdir('stats').catch(() => {});
await mkdir('stats', { recursive: true });
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
// it should build `parser` before `mermaid` because it's a dependency
for (const pkg of packageNames) {
Expand Down
2 changes: 1 addition & 1 deletion .esbuild/jisonPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';
import { transformJison } from '../.build/jisonTransformer.js';
import { Plugin } from 'esbuild';
import type { Plugin } from 'esbuild';

export const jisonPlugin: Plugin = {
name: 'jison',
Expand Down
51 changes: 33 additions & 18 deletions .esbuild/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import express from 'express';
import type { NextFunction, Request, Response } from 'express';
/* eslint-disable no-console */
import chokidar from 'chokidar';
import cors from 'cors';
import { getBuildConfig, defaultOptions } from './util.js';
import { context } from 'esbuild';
import chokidar from 'chokidar';
import { generateLangium } from '../.build/generateLangium.js';
import type { Request, Response } from 'express';
import express from 'express';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { defaultOptions, getBuildConfig } from './util.js';

const configs = Object.values(packageOptions).map(({ packageName }) =>
getBuildConfig({ ...defaultOptions, minify: false, core: false, entryName: packageName })
Expand All @@ -19,16 +20,28 @@ const mermaidIIFEConfig = getBuildConfig({
});
configs.push(mermaidIIFEConfig);

const contexts = await Promise.all(configs.map((config) => context(config)));
const contexts = await Promise.all(
configs.map(async (config) => ({ config, context: await context(config) }))
);

let rebuildCounter = 1;
const rebuildAll = async () => {
console.time('Rebuild time');
await Promise.all(contexts.map((ctx) => ctx.rebuild())).catch((e) => console.error(e));
console.timeEnd('Rebuild time');
const buildNumber = rebuildCounter++;
const timeLabel = `Rebuild ${buildNumber} Time (total)`;
console.time(timeLabel);
await Promise.all(
contexts.map(async ({ config, context }) => {
const buildVariant = `Rebuild ${buildNumber} Time (${Object.keys(config.entryPoints!)[0]} ${config.format})`;
console.time(buildVariant);
await context.rebuild();
console.timeEnd(buildVariant);
})
).catch((e) => console.error(e));
console.timeEnd(timeLabel);
};

let clients: { id: number; response: Response }[] = [];
function eventsHandler(request: Request, response: Response, next: NextFunction) {
function eventsHandler(request: Request, response: Response) {
const headers = {
'Content-Type': 'text/event-stream',
Connection: 'keep-alive',
Expand All @@ -45,19 +58,20 @@ function eventsHandler(request: Request, response: Response, next: NextFunction)
});
}

let timeoutId: NodeJS.Timeout | undefined = undefined;
let timeoutID: NodeJS.Timeout | undefined = undefined;

/**
* Debounce file change events to avoid rebuilding multiple times.
*/
function handleFileChange() {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
if (timeoutID !== undefined) {
clearTimeout(timeoutID);
}
timeoutId = setTimeout(async () => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
timeoutID = setTimeout(async () => {
await rebuildAll();
sendEventsToAll();
timeoutId = undefined;
timeoutID = undefined;
}, 100);
}

Expand All @@ -74,15 +88,16 @@ async function createServer() {
ignoreInitial: true,
ignored: [/node_modules/, /dist/, /docs/, /coverage/],
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
.on('all', async (event, path) => {
// Ignore other events.
if (!['add', 'change'].includes(event)) {
return;
}
if (/\.langium$/.test(path)) {
console.log(`${path} changed. Rebuilding...`);
if (path.endsWith('.langium')) {
await generateLangium();
}
console.log(`${path} changed. Rebuilding...`);
handleFileChange();
});

Expand All @@ -99,4 +114,4 @@ async function createServer() {
});
}

createServer();
void createServer();
4 changes: 2 additions & 2 deletions .esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { jisonPlugin } from './jisonPlugin.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

export interface MermaidBuildOptions {
export interface MermaidBuildOptions extends BuildOptions {
minify: boolean;
core: boolean;
metafile: boolean;
Expand Down Expand Up @@ -56,7 +56,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
const external: string[] = ['require', 'fs', 'path'];
const { name, file, packageName } = packageOptions[entryName];
const outFileName = getFileName(name, options);
let output: BuildOptions = buildOptions({
const output: BuildOptions = buildOptions({
absWorkingDir: resolve(__dirname, `../packages/${packageName}`),
entryPoints: {
[outFileName]: `src/${file}`,
Expand Down
11 changes: 0 additions & 11 deletions .eslintignore

This file was deleted.

Loading

0 comments on commit 22168ed

Please sign in to comment.