Skip to content

Commit

Permalink
Add examples app with React Vanilla and Material UI renderers
Browse files Browse the repository at this point in the history
This introduces a new private package `examples-app` to create a simple web page
that ultimately has child pages for every example.

In this initial commit, only the react vanilla and material renderers are added.
Therefore, they are bundled with rollup to be able to run as standalone pages.

- Add rollup configs to bundle react vanilla and material examples
- Add required dev deps and upgrade rollup dev dep to ^2.78.0 for all packages
- change material deps to ~5.2.2 because latest 5.x versions break api for Autocomplete
- Add private package `examples-app` with a script to aggregate the examples
- Add root level npm script to create the examples app
- regenerate package-lock.json

Part of #1706
  • Loading branch information
lucas-koehler committed Jan 4, 2023
1 parent 187b2b8 commit 5a84cd3
Show file tree
Hide file tree
Showing 22 changed files with 4,966 additions and 3,634 deletions.
8,321 changes: 4,706 additions & 3,615 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"clean": "lerna run clean",
"test": "lerna run test",
"test-cov": "lerna run test-cov",
"lint": "tslint 'packages/**/*.{ts,tsx}' -c ./tslint.json"
"lint": "tslint 'packages/**/*.{ts,tsx}' -c ./tslint.json",
"build:examples-app": "lerna run build:examples-app && node packages/examples-app/prepare-examples-app.js"
},
"devDependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"redux": "^4.0.4",
"redux-mock-store": "1.5.3",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.4.1",
Expand Down
12 changes: 12 additions & 0 deletions packages/examples-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# JSON Forms - More Forms. Less Code

*Complex forms in the blink of an eye*

JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript.

## Examples App

This package aggregates JSON Forms examples and makes them reachable via single `index.html` file.

Aggregating the examples assumes that packages were built and their examples bundled.
Afterwards, the examples app can be aggregated with [prepare-examples-app.js](./prepare-examples-app.js) into folder `dist`.
17 changes: 17 additions & 0 deletions packages/examples-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>JSON Forms Examples</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<h1>JSON Forms Examples</h1>
<ul>
<li><a href="react-vanilla">React Vanilla Renderers</a></li>
<li><a href="react-material">React Material Renderers</a></li>
</ul>
</body>
</html>
13 changes: 13 additions & 0 deletions packages/examples-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@jsonforms/examples-app",
"version": "3.1.0-alpha.0",
"private": true,
"license": "MIT",
"type": "module",
"scripts": {
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"fs-extra": "^11.1.0"
}
}
33 changes: 33 additions & 0 deletions packages/examples-app/prepare-examples-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

import { copySync } from 'fs-extra/esm';
import { copyFileSync, mkdirSync, rmdirSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const distDir = join(__dirname, 'dist');
const packagesDir = join(__dirname, '..');
const examples = {
'react-vanilla': join(packagesDir, 'vanilla-renderers', 'example', 'dist'),
'react-material': join(packagesDir, 'material-renderers', 'example', 'dist')
}

// Clean and recreate dist dir
console.log('Clean and recreate dist dir...');
rmdirSync(distDir, { recursive: true, force: true });
mkdirSync(distDir, { recursive: true });

// Copy index and built examples
console.log('Copy index.html...');
console.log('Copy example apps...');
copyFileSync(join(__dirname, 'index.html'), join(distDir, 'index.html'));
Object.keys(examples).forEach(key => {
console.log(`Copying example ${key}...`);
const path = examples[key];
copySync(path, join(distDir, key));
});

console.log('...finished');
2 changes: 1 addition & 1 deletion packages/examples-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@jsonforms/core": "^3.1.0-alpha.0",
"@jsonforms/examples": "^3.1.0-alpha.0",
"@jsonforms/react": "^3.1.0-alpha.0",
"@mui/material": "^5.2.2",
"@mui/material": "~5.2.2",
"@types/react-highlight": "^0.12.5",
"@types/react-tabs": "^2.3.3",
"highlight.js": "^11.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"@jsonforms/core": "^3.1.0-alpha.0",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.4.1",
Expand Down
16 changes: 16 additions & 0 deletions packages/material-renderers/example/index.bundled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>JSON Forms React Material RendererSet</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bundle.css">
</head>

<body>
<div id="root"></div>
</body>
<script src="bundle.js"></script>

</html>
2 changes: 1 addition & 1 deletion packages/material-renderers/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="utf-8">
<title>ReactiveForms Material RendererSet</title>
<title>JSON Forms React Material RendererSet</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
Expand Down
19 changes: 13 additions & 6 deletions packages/material-renderers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"typings": "lib/index.d.ts",
"scripts": {
"build": "rollup -c rollup.config.js",
"build:examples-app": "rollup -c rollup.example.config.js",
"dev": "webpack --config webpack/webpack.dev.js && webpack-dev-server --config webpack/webpack.dev.js --env=dev --inline",
"clean": "rimraf lib coverage dist .nyc_output 2> /dev/null",
"clean": "rimraf lib coverage dist .nyc_output example/dist 2> /dev/null",
"lint": "tslint --project tsconfig.json --exclude src/models/jsonSchema.ts",
"test": "jest --no-cache",
"test-cov": "jest --no-cache --coverage",
Expand Down Expand Up @@ -78,18 +79,22 @@
"@emotion/styled": "^11.3.0",
"@jsonforms/core": "3.1.0-alpha.0",
"@jsonforms/react": "3.1.0-alpha.0",
"@mui/icons-material": "^5.0.0",
"@mui/material": "^5.0.0",
"@mui/icons-material": "~5.2.2",
"@mui/material": "~5.2.2",
"@mui/x-date-pickers": "^5.0.0-beta.5"
},
"devDependencies": {
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
"@jsonforms/core": "^3.1.0-alpha.0",
"@jsonforms/react": "^3.1.0-alpha.0",
"@mui/icons-material": "^5.2.0",
"@mui/material": "^5.2.2",
"@mui/icons-material": "~5.2.0",
"@mui/material": "~5.2.2",
"@mui/x-date-pickers": "^5.0.0-beta.5",
"@rollup/plugin-commonjs": "^23.0.3",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@types/enzyme": "^3.10.3",
"@types/react-dom": "^17.0.9",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
Expand All @@ -99,8 +104,10 @@
"nyc": "^15.1.0",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-import-css": "^3.1.0",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.4.1",
"source-map-loader": "^0.2.4",
Expand Down
52 changes: 52 additions & 0 deletions packages/material-renderers/rollup.example.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import copy from 'rollup-plugin-copy';
import css from 'rollup-plugin-import-css';
import typescript from 'rollup-plugin-typescript2';

/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: 'example/index.ts',
output: {
file: 'example/dist/bundle.js',
format: 'iife',
sourcemap: true
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true, // recommended to be set by library to be forward compatible
}),
nodeResolve({ browser: true }),
// Transform mixed because some JsonForms modules use import and require
commonjs({ transformMixedEsModules: true }),
css(),
json(),
typescript({
tsconfigOverride: {
compilerOptions: {
// Do not emit typescript declarations for our bundled example app
declaration: false
}
}}),
copy({
targets: [
{
src: 'example/index.bundled.html',
dest: 'example/dist',
rename: () => 'index.html'
},
{
src: '../examples-react/src/logo.svg',
dest: 'example/dist/assets'
}
]
}),
]
}

export default config;
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"redux": "^4.0.4",
"redux-mock-store": "1.5.3",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.4.1",
Expand Down
27 changes: 27 additions & 0 deletions packages/vanilla-renderers/example/index.bundled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>JSON Forms React Vanilla RendererSet</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="example.css">
<link rel="stylesheet" href="example.dark.css">
<link rel="stylesheet" href="bundle.css">
<style type="text/css">
#theme {
position: absolute;
color: whitesmoke;
top: 0.25em;
left: 0.25em;
}
</style>
</head>

<body>
<div id="theme"></div>
<div id="root"></div>
</body>
<script src="bundle.js"></script>

</html>
2 changes: 1 addition & 1 deletion packages/vanilla-renderers/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="utf-8">
<title>ReactiveForms Default RendererSet</title>
<title>JSON Forms React Vanilla RendererSet</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/example.css">
Expand Down
11 changes: 9 additions & 2 deletions packages/vanilla-renderers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"typings": "lib/index.d.ts",
"scripts": {
"build": "rollup -c rollup.config.js",
"build:examples-app": "rollup -c rollup.example.config.js",
"dev": "webpack --config ./webpack/webpack.dev.js && webpack-dev-server --config webpack/webpack.dev.js --env=dev --inline",
"clean": "rimraf lib coverage dist .nyc_output 2> /dev/null",
"clean": "rimraf lib coverage dist .nyc_output example/dist 2> /dev/null",
"lint": "tslint --project tsconfig.json --exclude src/models/jsonSchema.ts",
"report": "nyc report --reporter=html",
"test": "jest --no-cache",
Expand Down Expand Up @@ -44,6 +45,10 @@
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@jsonforms/core": "^3.1.0-alpha.0",
"@jsonforms/react": "^3.1.0-alpha.0",
"@rollup/plugin-commonjs": "^23.0.3",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@types/enzyme": "^3.10.3",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"copy-webpack-plugin": "^5.0.5",
Expand All @@ -54,8 +59,10 @@
"nyc": "^15.1.0",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-import-css": "^3.1.0",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.4.1",
"source-map-loader": "^0.2.4",
Expand Down
56 changes: 56 additions & 0 deletions packages/vanilla-renderers/rollup.example.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import copy from 'rollup-plugin-copy';
import css from 'rollup-plugin-import-css';
import typescript from 'rollup-plugin-typescript2';

/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: 'example/index.ts',
output: {
file: 'example/dist/bundle.js',
format: 'iife',
sourcemap: true
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true, // recommended to be set by library to be forward compatible
}),
nodeResolve({ browser: true }),
// Transform mixed because some JsonForms modules use import and require
commonjs({ transformMixedEsModules: true }),
css(),
json(),
typescript({
tsconfigOverride: {
compilerOptions: {
// Do not emit typescript declarations for our bundled example app
declaration: false
}
}}),
copy({
targets: [
{
src: 'example/example*.css',
dest: 'example/dist'
},
{
src: 'example/index.bundled.html',
dest: 'example/dist',
rename: () => 'index.html'
},
{
src: '../examples-react/src/logo.svg',
dest: 'example/dist/assets'
}
]
}),
]
}

export default config;
2 changes: 1 addition & 1 deletion packages/vue/vue-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"cross-env": "^7.0.2",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rollup": "^2.7.3",
"rollup": "^2.78.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-typescript2": "^0.31.1",
Expand Down
Loading

0 comments on commit 5a84cd3

Please sign in to comment.