Skip to content

Commit

Permalink
integrate with TreeTable, generate treeSource in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Nov 10, 2024
1 parent 93e887b commit 2293a5c
Show file tree
Hide file tree
Showing 32 changed files with 305 additions and 140 deletions.
63 changes: 59 additions & 4 deletions vuu-ui/package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class TreeDataSource extends BaseDataSource {
};
}

console.log({ selectedKeyValues });

if (this.#status !== "initialising") {
//TODO check if subscription details are still the same
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

.vuuSplitButton-cta {
--split-background: var(--background, var(--salt-actionable-accented-bold-background));
--split-background-active: var(--salt-actionable-accented-bold-background-active;
--split-background-active: var(--salt-actionable-accented-bold-background-active);
--split-color-active: var(--salt-actionable-bold-foreground-active);
}
.vuuSplitButton-cta:hover:not(.vuuSplitButton-disabled) {
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/showcase/showcase.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"port": 3100
},
"version": "1.0.0",
"exhibits": "./src/examples"
"exhibitsPath": "./src/examples"
}
19 changes: 18 additions & 1 deletion vuu-ui/tools/showcase-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## startup sequence

#### cli.mjs
#### cli.js

- load index.html from templates
- get config file from input args, default to 'showcase.config.json'
Expand All @@ -25,3 +25,20 @@

- integrate into vuu cli, using stricli. Parameter parsing will happen there
- use jumpgen to monitor file system for new/edited exhibits in dev mode

## Running

run npm script from showcase

showcase config file `showcase.config.json` defines following

- http-server
- port
- version
- exhibits ' ./src/examples'

```
npm run showcase-cli
```

runs showcase-cli/cli.js
6 changes: 4 additions & 2 deletions vuu-ui/tools/showcase-cli/cli/buildPackageTree.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import fs from "fs";
import path from "path";

const OUT = "./src/generated/stories.json";
export interface ExhibitsJson {
[key: string]: string | ExhibitsJson;
}

export const buildPackageTree = (dir: string, tree = {}) => {
export const buildPackageTree = (dir: string, tree = {}): ExhibitsJson => {
fs.readdirSync(dir).forEach((fileName) => {
const filePath = path.join(dir, fileName);
if (fs.lstatSync(filePath).isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

import fs from "fs";
import path from "path";
import {
copyFiles,
createFolder,
readJson,
writeFile,
} from "./cli/cli-utils.ts";
import indexHtml from "./templates/index.html.ts";
import { copyFiles, createFolder, readJson, writeFile } from "./cli-utils.ts";
import indexHtml from "../templates/index.html.ts";
import { fileURLToPath } from "url";
import start from "./cli/main.ts";
import { buildPackageTree } from "./cli/buildPackageTree";
import prepare from "./prepare.ts";
import start from "./main.ts";

/** Parse the command line */
var args = process.argv.slice(2);
Expand All @@ -37,36 +32,36 @@ if (args.length === 0) {
}
}

const distFolder = path.resolve(fileURLToPath(import.meta.url), "../dist");
const distFolder = path.resolve(fileURLToPath(import.meta.url), "../../dist");

if (!fs.existsSync(".showcase")) {
createFolder(".showcase");
// DOn't do this until we create importmaps
// Don't do this until we create importmaps
await writeFile(indexHtml, "./.showcase/index.html");
} else {
console.log(".showcase folder present and correct");
}

// TODO check whether dist files already present in .showcase
if (fs.existsSync(distFolder)) {
console.log(`copy dist files from dist folder ${distFolder} to .showcase `);
copyFiles(distFolder, "./.showcase");
} else {
console.log(`no dist folder ${distFolder}`);
}

const config = readJson(configFilePath);

//TODO use type validator to check config file
const { exhibits } = config;
if (!fs.existsSync(exhibits)) {
console.log("Error: Exhibits location doesn't exist. Given: ", exhibits);
process.exit();
}
const [exhibitsJson, treeSourceJson] = await prepare(config);

const stories = buildPackageTree(exhibits);
await writeFile(
`export default ${JSON.stringify(stories, null, 2)};`,
`export default ${JSON.stringify(exhibitsJson, null, 2)};`,
"./.showcase/exhibits.js",
);

console.log(JSON.stringify(stories, null, 2));
await writeFile(
`export default ${JSON.stringify(treeSourceJson, null, 2)};`,
"./.showcase/treeSourceJson.js",
);

start(config);
start(config, exhibitsJson, treeSourceJson);
6 changes: 0 additions & 6 deletions vuu-ui/tools/showcase-cli/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export type ShowcaseConfig = {
};

export default async (config: ShowcaseConfig) => {
// fs.writeFile(OUT, JSON.stringify(stories, null, 2), (err) => {
// if (err) {
// console.log(err);
// }
// });

const server = await createServer({
build: {
manifest: true,
Expand Down
24 changes: 24 additions & 0 deletions vuu-ui/tools/showcase-cli/cli/prepare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from "fs";
import { buildPackageTree, ExhibitsJson } from "./buildPackageTree.ts";
import { writeFile } from "./cli-utils.ts";
import { treeSourceFromFileSystem } from "./treeSourceFromFileSystem.ts";
import { TreeSourceNode } from "@finos/vuu-utils";

export default async (config): Promise<[ExhibitsJson, TreeSourceNode[]]> => {
console.log("prepare");

//TODO use type validator to check config file
const { exhibitsPath } = config;
if (!fs.existsSync(exhibitsPath)) {
console.log(
"Error: Exhibits location doesn't exist. Given: ",
exhibitsPath,
);
process.exit();
}

const exhibits = buildPackageTree(exhibitsPath);
const treeSource = treeSourceFromFileSystem(exhibits);

return [exhibits, treeSource];
};
46 changes: 46 additions & 0 deletions vuu-ui/tools/showcase-cli/cli/treeSourceFromFileSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Module, TreeSourceNode } from "@finos/vuu-utils";
import { ExhibitsJson } from "./buildPackageTree";

export type VuuExample = {
(props?: any): JSX.Element;
displaySequence: number;
};

export type ExamplesModule = Module<VuuExample>;

const getFileType = (filePath: string) => {
const pos = filePath.lastIndexOf(".");
if (pos === -1) {
throw Error(`file path ${filePath} has no file type suffix`);
}
return filePath.slice(pos + 1);
};

export const treeSourceFromFileSystem = (
exhibits: ExhibitsJson,
prefix = "",
icon = "folder",
): TreeSourceNode[] => {
const entries = Object.entries(exhibits);
return entries.map<TreeSourceNode>(([label, nestedExhibits]) => {
const id = `${prefix}${label}`;
// TODO how can we know when a potential docs node has docs
// console.log(`id=${id}`);
if (typeof nestedExhibits === "string") {
const fileType = getFileType(nestedExhibits);
return {
fileType,
id,
icon: "rings",
label,
loaded: false,
};
}
return {
id,
icon,
label,
childNodes: treeSourceFromFileSystem(nestedExhibits, `${id}/`, "box"),
};
});
};
2 changes: 1 addition & 1 deletion vuu-ui/tools/showcase-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": "./cli.js",
"bin": "./cli/cli.js",
"scripts": {
"build": "node ./scripts/build.mjs"
},
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/tools/showcase-cli/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { build } from "../../../scripts/esbuild.mjs";
// 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.ts"];
const entryPoints = ["showcase-ui/main.ts"];

const outdir = "dist";

Expand Down
File renamed without changes.
Loading

0 comments on commit 2293a5c

Please sign in to comment.