-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
package tree generation and load into showcase
- Loading branch information
Showing
12 changed files
with
192 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Showcase CLI | ||
|
||
## startup sequence | ||
|
||
#### cli.mjs | ||
|
||
- load index.html from templates | ||
- get config file from input args, default to 'showcase.config.json' | ||
- check config file exists | ||
- check ./.showcase folder exists | ||
if not - create ./.showcase - copy index.html to .showcase | ||
if ../dist folder exists (this will be part of published package) - copy build files from ../dist to .showcase | ||
- read config json from config file | ||
- validate that directory exists at `config.exhibits` | ||
- build exhibit structure from files at `config.exhibits` | ||
- write the packageTree structure out to .showcase | ||
- call (main.ts).start(config) | ||
|
||
## Next steps | ||
|
||
- once package tree is created, creat import maps | ||
- inject importmaps into index.html | ||
- update Tree to allow runtime node expansion | ||
- update showcase-standalone | ||
|
||
- integrate into vuu cli, using stricli. Parameter parsing will happen there | ||
- use jumpgen to monitor file system for new/edited exhibits in dev mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface ExhibitsJson { | ||
[key: string]: string | ExhibitsJson; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import ReactDOM from "react-dom"; | ||
import React from "react"; | ||
import { Showcase } from "./Showcase"; | ||
import { ExhibitsJson } from "./exhibit-utils"; | ||
|
||
const root = document.getElementById("root") as HTMLDivElement; | ||
// The full Showcase shell loads all examples in order to render the Navigation Tree. This can | ||
// be a bit slow in dev mode. | ||
ReactDOM.render(<Showcase exhibits={{}} />, root); | ||
export default (exhibits: ExhibitsJson) => { | ||
const root = document.getElementById("root") as HTMLDivElement; | ||
// The full Showcase shell loads all examples in order to render the Navigation Tree. This can | ||
// be a bit slow in dev mode. | ||
ReactDOM.render(<Showcase exhibits={exhibits} />, root); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { ShowcaseStandalone } from "@finos/vuu-showcase"; | ||
import ReactDOM from "react-dom"; | ||
|
||
const root = document.getElementById("root") as HTMLDivElement; | ||
|
||
ReactDOM.render(<ShowcaseStandalone />, root); | ||
export default (exhibits: unknown) => { | ||
const root = document.getElementById("root") as HTMLDivElement; | ||
ReactDOM.render(<ShowcaseStandalone />, root); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { hasUrlParameter } from "@finos/vuu-utils"; | ||
if (hasUrlParameter("standalone")) { | ||
import("./index-standalone"); | ||
} else { | ||
import("./index-main"); | ||
} | ||
import { ExhibitsJson } from "./exhibit-utils"; | ||
|
||
export default async (exhibits: ExhibitsJson) => { | ||
console.log("Showcase start", { | ||
exhibits, | ||
}); | ||
if (hasUrlParameter("standalone")) { | ||
const { default: start } = await import("./index-standalone"); | ||
start(exhibits); | ||
} else { | ||
const { default: start } = await import("./index-main"); | ||
start(exhibits); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { TreeSourceNode } from "@finos/vuu-ui-controls"; | ||
import { useCallback, useMemo } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { AppProps } from "./App"; | ||
import { ExhibitsJson } from "./exhibit-utils"; | ||
|
||
const sourceFromImports = ( | ||
exhibits: ExhibitsJson, | ||
prefix = "", | ||
icon = "folder", | ||
): TreeSourceNode[] => | ||
Object.entries(exhibits).map<TreeSourceNode>(([label, exhibits]) => { | ||
const id = `${prefix}${label}`; | ||
if (typeof exhibits === "string") { | ||
return { | ||
id, | ||
icon: "rings", | ||
label, | ||
}; | ||
} | ||
return { | ||
id, | ||
icon, | ||
label, | ||
childNodes: sourceFromImports(exhibits, `${id}/`, "box"), | ||
}; | ||
}); | ||
|
||
const getTargetExhibit = (exhibits: ExhibitsJson, path: string) => { | ||
const steps = path.split("/"); | ||
const root = steps.slice(0, -1).join("/"); | ||
|
||
let node: string | ExhibitsJson = exhibits; | ||
let pathRoot: string[] = []; | ||
while (steps.length) { | ||
const step = steps.shift() as string; | ||
node = node[step]; | ||
} | ||
if (typeof node === "string") { | ||
return `${root}/${node}`; | ||
} else { | ||
throw Error(`unexpected leaf node ${JSON.stringify(node)}`); | ||
} | ||
}; | ||
|
||
export const useShowcaseApp = ({ exhibits }: AppProps) => { | ||
const navigate = useNavigate(); | ||
|
||
const source = useMemo(() => sourceFromImports(exhibits), [exhibits]); | ||
|
||
const handleChange = async ([selected]: TreeSourceNode[]) => { | ||
console.log(JSON.stringify(selected, null, 2)); | ||
|
||
const sourceTarget = getTargetExhibit(exhibits, selected.id); | ||
if (sourceTarget?.endsWith(".tsx")) { | ||
const module = await import( | ||
/* @vite-ignore */ | ||
`exhibits:src/examples/${sourceTarget}` | ||
); | ||
console.log(module); | ||
} | ||
// navigate(selected.id); | ||
}; | ||
|
||
return { | ||
onSelectionChange: handleChange, | ||
source, | ||
}; | ||
}; |
Oops, something went wrong.