Skip to content

Commit

Permalink
swagger init
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Mar 30, 2024
1 parent 63ce72e commit 034ed5e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
10 changes: 10 additions & 0 deletions components/SwaggerCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Card } from "react-bootstrap";

export const SwaggerCard = () => {
return (
<Card bg="primary">
<Card.Header>API Endpoints</Card.Header>
<Card.Body></Card.Body>
</Card>
);
};
25 changes: 16 additions & 9 deletions initializers/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Initializer } from "../classes/Initializer";
import path from "path";
import { Glob, type BuildConfig } from "bun";
import { watch } from "fs";
import { unlink } from "node:fs/promises";

const namespace = "react";

Expand Down Expand Up @@ -42,14 +43,7 @@ export class React extends Initializer {
pages.push(path.join(pagesDir, f));
}

const transpileAllPages = async () => {
await Bun.build({
...{ entrypoints: pages },
...transpilerOptions,
});
};

await transpileAllPages();
await transpileAllPages(pages);

logger.info(
`Transpiled ${pages.length} react pages to ${transpiledPagesDir}`,
Expand All @@ -74,7 +68,7 @@ export class React extends Initializer {

const fullFilename = path.join(pagesDir, filename);
logger.trace(`Detected ${event} in ${fullFilename}`);
await transpileAllPages(); // TODO: this can certainly be optimized by walking the react trees...
await transpileAllPages(pages); // TODO: this can certainly be optimized by walking the react trees...
},
);

Expand All @@ -91,3 +85,16 @@ export class React extends Initializer {
if (api.react.componentsDirWatcher) api.react.componentsDirWatcher.close();
}
}

const transpileAllPages = async (pages: string[]) => {
// we need to clear the directory to remove dangling pages that were deleted
const glob = new Glob("**/*.{js}");
for await (const f of glob.scan(transpiledPagesDir)) {
await unlink(path.join(transpiledPagesDir, f));
}

await Bun.build({
...{ entrypoints: pages },
...transpilerOptions,
});
};
7 changes: 7 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mount } from "../util/browser";
import { StatusCard } from "../components/StatusCard";
import { MainLayout } from "../layouts/main";
import { HelloCard } from "../components/HelloCard";
import { SwaggerCard } from "../components/SwaggerCard";

export default function Page() {
return (
Expand All @@ -20,6 +21,12 @@ export default function Page() {
<HelloCard />
</Col>
</Row>
<br />
<Row>
<Col md={12}>
<SwaggerCard />
</Col>
</Row>
</Container>
</MainLayout>
);
Expand Down
1 change: 0 additions & 1 deletion servers/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export class WebServer extends Server<ReturnType<typeof Bun.serve>> {
} catch {}
}

// TODO: fork for files vs actions vs pages
const { response, error } = await connection.act(
actionName,
params,
Expand Down

0 comments on commit 034ed5e

Please sign in to comment.