Skip to content

Commit

Permalink
Example added for slaceforce testcase generation using edgechain
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh4902 committed Nov 30, 2023
1 parent 6b893a1 commit 706268c
Show file tree
Hide file tree
Showing 18 changed files with 9,147 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Examples/testGenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
45 changes: 45 additions & 0 deletions Examples/testGenerator/esbuild.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const esbuild = require("esbuild");
const path = require("path");
const fs = require("fs");
const { execSync } = require("child_process");

const outputDir = path.resolve(__dirname, "dist");

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}

const distPath = path.join(process.cwd(), "dist");

fs.promises.mkdir(distPath, { recursive: true });

esbuild
.build({
entryPoints: ["./src/index.ts"],
bundle: true,
minify: true,
platform: "node",
outfile: "./dist/index.js",
tsconfig: "./tsconfig.json",
target: "node21.1.0",
external: [
"express",
"tsx",
"typescript",
"typeorm",
"react",
"react-dom",
"pg",
"jsdom",
"hono",
"@hanazuki/node-jsonnet",
"readline/promises",
],
format: "cjs",
loader: {
".html": "text",
".css": "css",
".jsonnet": "text",
},
})
.catch(() => process.exit(1));
58 changes: 58 additions & 0 deletions Examples/testGenerator/htmljs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { html } from "hono/html";

// These functions form the basis of the html.js framework and will be moved to a separate lib

export const view = (viewToRender) => {
return async (c) => {
const newBody = await viewToRender({ context: c });
return c.html(newBody);
};
};

export const rootLayout = (layoutToApply) => {
return async (c, next) => {
await next();
if (c.req.header("HX-Request") !== "true") {
// Req is a normal request, so we render the whole page which means adding the root layout
const curBody = await c.res.text();
c.res = undefined; // To overwrite res, set it to undefined before setting new value https://github.com/honojs/hono/pull/970 released in https://github.com/honojs/hono/releases/tag/v3.1.0
const newBody = await layoutToApply({ context: c, children: html(curBody) });
c.res = c.html(newBody);
}
// Else do nothing and let the original response be sent
};
};

export const layout = (layoutToApply) => {
return async (c, next) => {
await next();
if (
(c.req.header("HX-Request") === "true" &&
(c.req.header("HX-Boosted") === "true" || !c.req.header("HX-Target"))) ||
c.req.header("HX-Request") !== "true"
) {
// Req is regular req or boosted link, so we apply layouts
const curBody = await c.res.text();
c.res = undefined; // To overwrite res, set it to undefined before setting new value https://github.com/honojs/hono/pull/970 released in https://github.com/honojs/hono/releases/tag/v3.1.0
const newBody = await layoutToApply({ context: c, children: html(curBody) });
c.res = c.html(newBody);
}
// Else do nothing and let the original response be sent, which will be a partial update applied to the page with hx-target
};
};

export const Link: any = ({ to, "hx-target": hxTarget, class: className, children }) => {
if (hxTarget) {
return html`<a
href="${to}"
class="${className}"
hx-get="${to}"
hx-target="${hxTarget}"
hx-push-url="true"
hx-swap="morph"
>${children}</a
>`;
} else {
return html`<a href="${to}" class="${className}" hx-boost="true">${children}</a>`;
}
};
11 changes: 11 additions & 0 deletions Examples/testGenerator/ormconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "postgres",
"host": "db.rmzqtepwnzoxgkkzjctt.supabase.co",
"port": 5432,
"username": "postgres",
"password": "xaX0MYcf1YiJlChK",
"database": "postgres",
"entities": ["dist/entities/**/*.js"],
"synchronize": false,
"logging": false
}
Loading

0 comments on commit 706268c

Please sign in to comment.