Skip to content

Commit

Permalink
feat: esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Sep 18, 2021
1 parent 1c3f94c commit b8073c7
Show file tree
Hide file tree
Showing 24 changed files with 388 additions and 243 deletions.
31 changes: 31 additions & 0 deletions esbuild.cjs
@@ -0,0 +1,31 @@
let jisonPlugin = {
name: 'jison',
setup(build) {
const { Generator } = require('jison');
let fs = require('fs');

build.onLoad({ filter: /\.jison$/ }, async args => {
// Load the file from the file system
let source = await fs.promises.readFile(args.path, 'utf8');

try {
let contents = new Generator(source, {}).generate();
return { contents, warnings: [] };
} catch (e) {
return { errors: [] };
}
});
}
};

const { build } = require('esbuild');
build({
bundle: true,
minify: false,
keepNames: true,
globalName: 'mermaid',
platform: 'browser',
entryPoints: ['src/mermaid.js'],
outfile: 'dist/mermaid.js',
plugins: [jisonPlugin]
}).catch(() => process.exit(1));
10 changes: 8 additions & 2 deletions package.json
Expand Up @@ -27,8 +27,7 @@
"dev": "webpack serve --config webpack.config.e2e.js",
"test": "yarn lint && jest src/.*",
"test:watch": "jest --watch src",
"prepublishOnly": "yarn build && yarn test",
"prepare": "yarn build"
"prepublishOnly": "yarn build && yarn test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -71,6 +70,8 @@
"css-to-string-loader": "^0.1.3",
"cypress": "8.1.0",
"documentation": "13.2.0",
"esbuild": "^0.12.28",
"esbuild-loader": "^2.15.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
Expand All @@ -80,6 +81,7 @@
"jison": "^0.4.18",
"js-base64": "3.6.1",
"moment": "^2.23.0",
"path-browserify": "^1.0.1",
"prettier": "^2.3.2",
"start-server-and-test": "^1.12.6",
"terser-webpack-plugin": "^4.2.3",
Expand All @@ -99,5 +101,9 @@
"hooks": {
"pre-push": "yarn test"
}
},
"browser": {
"path": "path-browserify",
"fs": false
}
}
7 changes: 4 additions & 3 deletions src/diagrams/class/classDiagram-styles.spec.js
@@ -1,5 +1,5 @@
/* eslint-env jasmine */
import { parser } from './parser/classDiagram';
import { parser } from './parser/classDiagram.jison';
import classDb from './classDb';

describe('class diagram, ', function() {
Expand All @@ -17,7 +17,7 @@ describe('class diagram, ', function() {
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
});

it('should be possible to apply a css class to a class directly with struct', function () {
it('should be possible to apply a css class to a class directly with struct', function() {
const str =
'classDiagram\n' +
'class Class1:::exClass {\n' +
Expand Down Expand Up @@ -49,7 +49,8 @@ describe('class diagram, ', function() {
});

it('should be possible to apply a cssClass to a comma separated list of classes', function() {
const str = 'classDiagram\n' + 'class Class01\n class Class02\n cssClass "Class01,Class02" exClass';
const str =
'classDiagram\n' + 'class Class01\n class Class02\n cssClass "Class01,Class02" exClass';

parser.parse(str);

Expand Down

0 comments on commit b8073c7

Please sign in to comment.