Skip to content

Commit

Permalink
Merge branch 'sidv/mergeRelease' into sidv/esbuildFail
Browse files Browse the repository at this point in the history
* sidv/mergeRelease:
  chore(deps-dev): bump eslint-plugin-jest from 27.0.1 to 27.0.4 (#3458)
  chore(deps-dev): bump @typescript-eslint/eslint-plugin (#3457)
  chore(deps-dev): bump concurrently from 7.3.0 to 7.4.0 (#3445)
  chore(deps-dev): bump @babel/preset-env from 7.18.10 to 7.19.0 (#3442)
  chore(deps-dev): bump @typescript-eslint/parser from 5.36.1 to 5.37.0 (#3451)
  chore(deps-dev): bump @babel/core from 7.18.13 to 7.19.0 (#3447)
  chore(deps-dev): bump jest-environment-jsdom from 29.0.2 to 29.0.3 (#3441)
  chore(deps-dev): bump babel-jest from 29.0.2 to 29.0.3 (#3448)
  chore(deps-dev): bump eslint from 8.23.0 to 8.23.1
  Release 9.1.7
  Fix for broken rendering test
  Fix for issue #3428, load the configured diagrams even when initialize has not been called.
  • Loading branch information
sidharthv96 committed Sep 14, 2022
2 parents a7f0b2b + 539ee49 commit d83c9f5
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 289 deletions.
39 changes: 38 additions & 1 deletion cypress/platform/knsv.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
</style>
</head>
<body>
<pre class="mermaid2" style="width: 50%">
flowchart LR
a ---
</pre>
<pre class="mermaid" style="width: 50%">
flowchart LR
a2 ---
</pre>
<pre class="mermaid2" style="width: 50%">
flowchart LR
classDef aPID stroke:#4e4403,fill:#fdde29,color:#4e4403,rx:5px,ry:5px;
classDef crm stroke:#333333,fill:#DCDCDC,color:#333333,rx:5px,ry:5px;
Expand Down Expand Up @@ -73,7 +81,31 @@
</pre>
<pre class="mermaid" style="width: 50%">
flowchart TD
id

release-branch[Create Release Branch]:::relClass
develop-branch[Update Develop Branch]:::relClass
github-release-draft[GitHub Release Draft]:::relClass
trigger-pipeline[Trigger Jenkins pipeline]:::fixClass
github-release[GitHub Release]:::postClass

build-ready --> release-branch
build-ready --> develop-branch
release-branch --> jenkins-release-build
jenkins-release-build --> github-release-draft
jenkins-release-build --> install-release
install-release --> verify-release
jenkins-release-build --> announce
github-release-draft --> github-release
verify-release --> verify-check
verify-check -- Yes --> github-release
verify-check -- No --> release-fix
release-fix --> release-branch-pr
verify-check -- No --> delete-artifacts
release-branch-pr --> trigger-pipeline
delete-artifacts --> trigger-pipeline
trigger-pipeline --> jenkins-release-build


</pre>
<pre class="mermaid2" style="width: 50%">
flowchart LR
Expand Down Expand Up @@ -357,6 +389,11 @@

document.getElementsByTagName('body')[0].appendChild(div);
}

mermaid.parseError = function (err, hash) {
console.error('In parse error:');
console.error(err);
};
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css"
/>
<script src="//cdn.jsdelivr.net/npm/mermaid@9.1.6/dist/mermaid.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script>
<!-- <script src="http://localhost:9000/mermaid.js"></script> -->
<script>
// prettier-ignore
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@
"@types/jest": "^28.1.7",
"@types/lodash": "^4.14.184",
"@types/stylis": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"concurrently": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"concurrently": "^7.4.0",
"coveralls": "^3.0.2",
"cypress": "9.7.0",
"cypress-image-snapshot": "^4.0.1",
"documentation": "13.2.0",
"esbuild": "^0.15.6",
"esbuild-loader": "^2.19.0",
"eslint": "^8.23.0",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-jest": "^27.0.1",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-markdown": "^3.0.0",
Expand All @@ -111,7 +111,7 @@
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.0.3",
"jest-environment-jsdom": "^29.0.2",
"jest-environment-jsdom": "^29.0.3",
"jest-esbuild": "^0.2.9",
"jison": "^0.4.18",
"js-base64": "3.7.2",
Expand Down
22 changes: 22 additions & 0 deletions src/diagram-api/diagram-orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,29 @@ import journeyDb from '../diagrams/user-journey/journeyDb';
import journeyRenderer from '../diagrams/user-journey/journeyRenderer';
import journeyStyles from '../diagrams/user-journey/styles';

import errorRenderer from '../diagrams/error/errorRenderer';
import errorStyles from '../diagrams/error/styles';

export const addDiagrams = () => {
registerDiagram(
'error',
// Special diagram with error messages but setup as a regular diagram
{
db: {},
styles: errorStyles,
renderer: errorRenderer,
parser: {
parser: { yy: {} },
parse: () => {
// no op
},
},
init: () => {
// no op
},
},
(text) => text.toLowerCase().trim() === 'error'
);
registerDiagram(
'c4',
{
Expand Down
12 changes: 6 additions & 6 deletions src/errorRenderer.ts → src/diagrams/error/errorRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Created by knut on 14-12-11. */
import { select } from 'd3';
import { log } from './logger';
import { getErrorMessage } from './utils';
import { log } from '../../logger';
import { getErrorMessage } from '../../utils';

let conf = {};

Expand Down Expand Up @@ -72,22 +72,22 @@ export const draw = (id: string, mermaidVersion: string) => {

g.append('text') // text label for the x axis
.attr('class', 'error-text')
.attr('x', 1240)
.attr('x', 1440)
.attr('y', 250)
.attr('font-size', '150px')
.style('text-anchor', 'middle')
.text('Syntax error in graph');
g.append('text') // text label for the x axis
.attr('class', 'error-text')
.attr('x', 1050)
.attr('x', 1250)
.attr('y', 400)
.attr('font-size', '100px')
.style('text-anchor', 'middle')
.text('mermaid version ' + mermaidVersion);

svg.attr('height', 100);
svg.attr('width', 400);
svg.attr('viewBox', '768 0 512 512');
svg.attr('width', 500);
svg.attr('viewBox', '768 0 912 512');
} catch (e) {
log.error('Error while rendering info diagram');
log.error(getErrorMessage(e));
Expand Down
3 changes: 3 additions & 0 deletions src/diagrams/error/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const getStyles = () => ``;

export default getStyles;
4 changes: 3 additions & 1 deletion src/diagrams/git/gitGraphRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ const drawCommits = (svg, commits, modifyGraph) => {
if (modifyGraph) {
let typeClass;
let commitSymbolType =
typeof commit.customType !== 'undefined' ? commit.customType : commit.type;
typeof commit.customType !== 'undefined' && commit.customType !== ''
? commit.customType
: commit.type;
switch (commitSymbolType) {
case commitType.NORMAL:
typeClass = 'commit-normal';
Expand Down
13 changes: 11 additions & 2 deletions src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ const initThrowsErrors = function (
const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed);

let txt;
const errors = [];

// element is the current div with mermaid class
for (const element of Array.from(nodesToProcess)) {
log.info('Rendering diagram: ' + element.id);
/*! Check if previously processed */
if (element.getAttribute('data-processed')) {
continue;
Expand Down Expand Up @@ -135,10 +137,17 @@ const initThrowsErrors = function (
} catch (error) {
log.warn('Catching Error (bootstrap)', error);
// @ts-ignore: TODO Fix ts errors
// TODO: We should be throwing an error object.
throw { error, message: error.str };
const mermaidError = { error, str: error.str, hash: error.hash, message: error.str };
if (typeof mermaid.parseError === 'function') {
mermaid.parseError(mermaidError);
}
errors.push(mermaidError);
}
}
if (errors.length > 0) {
// TODO: We should be throwing an error object.
throw errors[0];
}
};

const initialize = function (config: MermaidConfig) {
Expand Down
19 changes: 17 additions & 2 deletions src/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import flowDb from './diagrams/flowchart/flowDb';
import flowRenderer from './diagrams/flowchart/flowRenderer';
import ganttDb from './diagrams/gantt/ganttDb';
import Diagram from './Diagram';
import errorRenderer from './errorRenderer';
import errorRenderer from './diagrams/error/errorRenderer';
import { attachFunctions } from './interactionDb';
import { log, setLogLevel } from './logger';
import getStyles from './styles';
Expand Down Expand Up @@ -124,6 +124,10 @@ const render = function (
cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void,
container?: Element
): void {
if (!hasLoadedDiagrams) {
addDiagrams();
hasLoadedDiagrams = true;
}
configApi.reset();
text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;;
const graphInit = utils.detectInit(text);
Expand Down Expand Up @@ -228,7 +232,14 @@ const render = function (
text = encodeEntities(text);

// Important that we do not create the diagram until after the directives have been included
const diag = new Diagram(text);
let diag;
let parseEncounteredException;
try {
diag = new Diagram(text);
} catch (error) {
diag = new Diagram('error');
parseEncounteredException = error;
}
// Get the tmp element containing the the svg
const element = root.select('#d' + id).node();
const graphType = diag.type;
Expand Down Expand Up @@ -371,6 +382,10 @@ const render = function (
node.remove();
}

if (parseEncounteredException) {
throw parseEncounteredException;
}

return svgCode;
};

Expand Down
2 changes: 2 additions & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classDiagram from './diagrams/class/styles';
import er from './diagrams/er/styles';
import error from './diagrams/error/styles';
import flowchart from './diagrams/flowchart/styles';
import gantt from './diagrams/gantt/styles';
// import gitGraph from './diagrams/git/styles';
Expand Down Expand Up @@ -28,6 +29,7 @@ const themes: Record<string, any> = {
info,
pie,
er,
error,
journey,
requirement,
c4,
Expand Down
Loading

0 comments on commit d83c9f5

Please sign in to comment.