Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
emersonbottero committed Oct 3, 2022
2 parents 40a319f + 6191bb5 commit 9901a73
Show file tree
Hide file tree
Showing 56 changed files with 2,018 additions and 1,465 deletions.
20 changes: 0 additions & 20 deletions .esbuild/esbuild.cjs

This file was deleted.

79 changes: 0 additions & 79 deletions .esbuild/serve.cjs

This file was deleted.

94 changes: 0 additions & 94 deletions .esbuild/util.cjs

This file was deleted.

9 changes: 7 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ jobs:
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v3
# If CYPRESS_RECORD_KEY is set, run in parallel on all containers
# Otherwise (e.g. if running from fork), we run on a single container only
if: ${{ ( env.CYPRESS_RECORD_KEY != '' ) || ( matrix.containers == 1 ) }}
with:
start: yarn dev
wait-on: 'http://localhost:9000'
record: true
# Disable recording if we don't have an API key
# e.g. if this action was run from a fork
record: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
parallel: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
headless: true
parallel: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ token

package-lock.json

.vscode/
# ignore files in /.vscode/ except for launch.json and extensions.json
/.vscode/**
!/.vscode/launch.json
!/.vscode/extensions.json

cypress/platform/current.html
cypress/platform/experimental.html
local/
Expand Down
89 changes: 89 additions & 0 deletions .vite/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { build, InlineConfig } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
import pkg from '../package.json' assert { type: 'json' };
type OutputOptions = Exclude<
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
undefined
>['output'];

const { dependencies } = pkg;
const watch = process.argv.includes('--watch');
const __dirname = fileURLToPath(new URL('.', import.meta.url));

interface BuildOptions {
minify: boolean | 'esbuild';
core?: boolean;
watch?: boolean;
}

export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
const external = ['require', 'fs', 'path'];
let output: OutputOptions = [
{
name: 'mermaid',
format: 'esm',
sourcemap: true,
entryFileNames: `[name].esm${minify ? '.min' : ''}.mjs`,
},
{
name: 'mermaid',
format: 'umd',
sourcemap: true,
entryFileNames: `[name]${minify ? '.min' : ''}.js`,
},
];

if (core) {
// Core build is used to generate file without bundled dependencies.
// This is used by downstream projects to bundle dependencies themselves.
external.push(...Object.keys(dependencies));
// This needs to be an array. Otherwise vite will build esm & umd with same name and overwrite esm with umd.
output = [
{
format: 'esm',
sourcemap: true,
entryFileNames: `[name].core.mjs`,
},
];
}

const config: InlineConfig = {
configFile: false,
build: {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, '../src/mermaid.ts'),
name: 'mermaid',
// the proper extensions will be added
fileName: 'mermaid',
},
minify,
rollupOptions: {
external,
output,
},
},
resolve: {
extensions: ['.jison', '.js', '.ts', '.json'],
},
plugins: [jisonPlugin()],
};

if (watch && config.build) {
config.build.watch = {
include: 'src/**',
};
}

return config;
};

if (watch) {
build(getBuildConfig({ minify: false, watch }));
} else {
build(getBuildConfig({ minify: false }));
build(getBuildConfig({ minify: 'esbuild' }));
build(getBuildConfig({ minify: false, core: true }));
}
17 changes: 17 additions & 0 deletions .vite/jisonPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { transformJison } from './jisonTransformer.js';
const fileRegex = /\.(jison)$/;

export default function jison() {
return {
name: 'jison',

transform(src: string, id: string) {
if (fileRegex.test(id)) {
return {
code: transformJison(src),
map: null, // provide source map if available
};
}
},
};
}
9 changes: 6 additions & 3 deletions .esbuild/jisonTransformer.cjs → .vite/jisonTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { Generator } = require('jison');
exports.transformJison = (src) => {
const parser = new Generator(src, {
// @ts-ignore No typings for jison
import jison from 'jison';

export const transformJison = (src: string): string => {
// @ts-ignore No typings for jison
const parser = new jison.Generator(src, {
moduleType: 'js',
'token-stack': true,
});
Expand Down
26 changes: 26 additions & 0 deletions .vite/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import express from 'express';
import { createServer as createViteServer } from 'vite';
// import { getBuildConfig } from './build';

async function createServer() {
const app = express();

// Create Vite server in middleware mode
const vite = await createViteServer({
configFile: './vite.config.ts',
server: { middlewareMode: true },
appType: 'custom', // don't include Vite's default HTML handling middlewares
});

app.use(vite.middlewares);
app.use(express.static('dist'));
app.use(express.static('demos'));
app.use(express.static('cypress/platform'));

app.listen(9000, () => {
console.log(`Listening on http://localhost:9000`);
});
}

// build(getBuildConfig({ minify: false, watch: true }));
createServer();
6 changes: 6 additions & 0 deletions .vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "ES2022"
}
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"zixuanchen.vitest-explorer",
"luniclynx.bison"
]
}
Loading

0 comments on commit 9901a73

Please sign in to comment.