Skip to content

Commit

Permalink
refactor showcase to build source tree from sourcefiles, enable mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Nov 17, 2024
1 parent b32dc05 commit 06f5bda
Show file tree
Hide file tree
Showing 28 changed files with 269 additions and 291 deletions.
45 changes: 40 additions & 5 deletions vuu-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vuu-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"type-defs": "node ./scripts/build-all-type-defs.mjs",
"showcase": "cd showcase && npm run showcase",
"showcase:preview": "serve ./showcase/dist -p 4173",
"showcase:build": "npm run build:worker && cd showcase && node scripts/build.mjs",
"showcase:build": "npm run build:worker && cd showcase && tsx scripts/build.ts",
"test:cypress": "npm run build:worker && cypress run --component --browser chrome --headless",
"test:cypress:local": "cypress open --component --browser chrome",
"test:vite": "npm run build:worker && vitest run",
Expand Down
6 changes: 1 addition & 5 deletions vuu-ui/showcase/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<<<<<<< HEAD
!templates/index.html
=======
!templates/index.html
>>>>>>> 7590e3f973ef0c9b6070abaac9c592190cd65e6f
.showcase
21 changes: 15 additions & 6 deletions vuu-ui/showcase/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/manifest.json" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Vite Showcase</title>
<title>Vuu Showcase</title>
<script type="module">
import { hasUrlParameter } from "@finos/vuu-utils";
const { default: treeSource } = await import(
"/.showcase/treeSourceJson.js"
);
if (hasUrlParameter("standalone")) {
const { default: start } = await import("/src/index-standalone");
start(treeSource);
} else {
const { default: start } = await import("/src/index-main");
start(treeSource);
}
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions vuu-ui/showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"build": "node ./scripts/build.mjs",
"dev": "vite",
"docs": "node ./scripts/build-docs.mjs",
"showcase": "node ./scripts/showcase.mjs",
"stories": "node ./scripts/parse-stories.mjs"
"showcase": "tsx ./scripts/showcase.ts"
},
"keywords": [],
"author": "heswell",
Expand All @@ -33,9 +32,10 @@
"react-router-dom": "^6.2.1"
},
"devDependencies": {
"@mdx-js/esbuild": "^3.0.1",
"@mdx-js/rollup": "3.0.0",
"@mdx-js/esbuild": "3.1.0",
"@mdx-js/rollup": "3.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3"
"@rollup/plugin-node-resolve": "^15.2.3",
"tsx": "^4.19.1"
}
}
Binary file removed vuu-ui/showcase/public/favicon-16x16.png
Binary file not shown.
Binary file removed vuu-ui/showcase/public/favicon-32x32.png
Binary file not shown.
Binary file removed vuu-ui/showcase/public/favicon.ico
Binary file not shown.
19 changes: 0 additions & 19 deletions vuu-ui/showcase/public/manifest.json

This file was deleted.

43 changes: 0 additions & 43 deletions vuu-ui/showcase/scripts/build-docs.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ import {
formatDuration,
padRight,
readPackageJson,
writeFile,
writeMetaFile,
} from "../../scripts/utils.mjs";
import { build } from "../../scripts/esbuild.mjs";
import { buildFileList } from "./build-file-list.mjs";
import fs from "fs";
import path from "path";
import { treeSourceFromFileSystem } from "./treeSourceFromFileSystem";
import mdx from "@mdx-js/esbuild";

const indexFiles = buildFileList("./src/examples", /index.ts$/);
const examples = buildFileList("./src/examples", /examples.tsx$/);
const mdxFiles = buildFileList("./src/examples", /.mdx$/);
const features = buildFileList("./src/features", /feature.tsx$/);

console.log({ mdxFiles });

// TODO use a separate build call for each theme, without bundling
const themes = ["./src/themes/salt-theme.ts", "./src/themes/vuu-theme.ts"];

const entryPoints = ["src/main.tsx"]
const entryPoints = ["src/index-main.tsx", "src/index-standalone.tsx"]
.concat(indexFiles)
.concat(features)
.concat(examples)
.concat(mdxFiles)
.concat(themes);

const cssInlinePlugin = {
Expand All @@ -37,7 +44,7 @@ const cssInlinePlugin = {
const css = await fs.promises.readFile(args.path, "utf8");
// css = await esbuild.transform(css, { loader: "css", minify: true });
return { loader: "text", contents: css };
}
},
);
},
};
Expand All @@ -48,16 +55,25 @@ const HTML_TEMPLATE = `
<head>
<base href="/" />
<meta charset="UTF-8" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/main.css"/>
<link rel="stylesheet" href="/index-main.css"/>
<title>Vite Showcase</title>
<script type="module">
const hasUrlParameter = (paramName) => new URL(document.location.href).searchParams.has(paramName);
const { default: treeSource } = await import(
"/treeSourceJson.js"
);
if (hasUrlParameter("standalone")) {
const { default: start } = await import("/index-standalone.js");
start(treeSource);
} else {
const { default: start } = await import("/index-main.js");
start(treeSource);
}
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/main.js"></script>
</body>
</html>
`;
Expand All @@ -75,7 +91,7 @@ const esbuildConfig = {
"./themes/tar-theme.ts",
],
name: "showcase",
plugins: [cssInlinePlugin],
plugins: [cssInlinePlugin, mdx()],
outdir,
splitting: true,
target: "esnext",
Expand All @@ -87,7 +103,7 @@ function writeHtmlFile() {
if (err) {
reject(err);
} else {
resolve();
resolve(undefined);
}
});
});
Expand All @@ -111,6 +127,12 @@ async function main() {

await writeMetaFile(metafile, outdir);

const treeSourceJson = treeSourceFromFileSystem("./src/examples", "");
await writeFile(
`export default ${JSON.stringify(treeSourceJson)};`,
path.resolve(outdir, "treeSourceJson.js"),
);

console.log("[DEPLOY public assets]");
const publicContent = fs.readdirSync(`./public`);
publicContent.forEach((file) => {
Expand All @@ -121,7 +143,7 @@ async function main() {
{ recursive: true },
(err) => {
if (err) throw err;
}
},
);
}
});
Expand All @@ -146,11 +168,11 @@ async function main() {

console.log("\ncore");
outputs.core.sort(byFileName).forEach(({ fileName, bytes }) => {
console.log(`${padRight(fileName, 30)} ${formatBytes(bytes)}`);
console.log(`${padRight(fileName, 90)} ${formatBytes(bytes)}`);
});
console.log("\ncommon");
outputs.common.forEach(({ fileName, bytes }) => {
console.log(`${padRight(fileName, 30)} ${formatBytes(bytes)}`);
console.log(`${padRight(fileName, 90)} ${formatBytes(bytes)}`);
});

console.log(`\nbuild took ${formatDuration(duration)}`);
Expand Down
58 changes: 0 additions & 58 deletions vuu-ui/showcase/scripts/parse-stories.mjs

This file was deleted.

Loading

0 comments on commit 06f5bda

Please sign in to comment.