Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global npm run dev #56

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm ci
# dev

```sh
$ npm run -w demos/cards-with-border-radius dev
$ npm run dev
```

# build
Expand Down
44 changes: 44 additions & 0 deletions apps/website/app/demos/[demoname]/Dev.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";

import { useRouter } from "next/navigation";

export function Dev({ demoname }: { demoname: string }) {
const { refresh } = useRouter();

const cmd = `npm run -w demos/${demoname} dev3`;

return (
<div>
<style
dangerouslySetInnerHTML={{
__html: `
@scope {
pre {background:rgb(13,13,13); padding:1rem; border-radius:.35rem;}
code {color:white;}
code:before {content:"$ ";}
pre {
position:relative;
a {position:absolute; bottom:100%; right:0; cursor:pointer;}
}
}
`,
}}
/>

<p>Start this demo with :</p>
<pre
onClick={(e) => {
navigator.clipboard.writeText(cmd);
}}
>
<code>{cmd}</code>
<a>copy</a>
</pre>
<p>
Then <a onClick={(e) => refresh()}>refresh</a>
</p>
</div>
);
}
38 changes: 33 additions & 5 deletions apps/website/app/demos/[demoname]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notFound } from "next/navigation";

import { getDemos } from "@/lib/helper";
import { Dev } from "./Dev";

const demos = getDemos();

Expand Down Expand Up @@ -41,7 +42,18 @@ export async function generateStaticParams() {
}));
}

export default function Page(props: Props) {
async function checkUrlIsUp(url: string) {
const response = await fetch(url, {
method: "GET",
next: { revalidate: 0 },
}).catch(() => {});

return response?.ok || false;
}

const isDev = process.env.NODE_ENV === "development";

export default async function Page(props: Props) {
const { params } = props;

const { demoname } = params;
Expand All @@ -50,16 +62,32 @@ export default function Page(props: Props) {

const { embed_url } = demo;

let isUp;
if (isDev) {
isUp = await checkUrlIsUp(embed_url);
}
// console.log("isUp=", isUp);

return (
<>
<div>
<style
dangerouslySetInnerHTML={{
__html: `
iframe {width:100%; min-height:100dvh;}
@scope {
:scope {
height:100%;
display:flex; align-items:center; justify-content:center;
}
iframe {width:100%; min-height:100dvh;}
}
`,
}}
/>
<iframe src={embed_url} />;
</>
{isDev && !isUp ? (
<Dev demoname={demoname} />
) : (
<iframe src={embed_url} />
)}
</div>
);
}
6 changes: 6 additions & 0 deletions apps/website/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@

@import "open-props/normalize/dark";
@import "open-props/normalize/light";

a {
color: inherit;
text-decoration: underline;
cursor: pointer;
}
5 changes: 4 additions & 1 deletion apps/website/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export default function RootLayout({
__html: `
@scope {
:scope {background:#eee;}
main {position:fixed; width:100%; height:100dvh;}
main {
position:fixed; width:100%; height:100dvh;
}
}
`,
}}
Expand Down
9 changes: 6 additions & 3 deletions apps/website/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Nav({
}, [demoname, demos]);

return (
<>
<div>
<style
dangerouslySetInnerHTML={{
__html: `
Expand Down Expand Up @@ -76,7 +76,10 @@ export default function Nav({
a img {
object-fit:cover; aspect-ratio:16/9; width:auto; height:7rem;
color:inherit!important; font-size:.8rem;
background:none;
}
a img:after {content:"";}
}
`,
}}
Expand All @@ -91,13 +94,13 @@ export default function Nav({
href={`/demos/${name}`}
className={clsx({ active: demoname === name })}
>
<Image src={thumb} width={16} height={9} alt="" />
<Image src={thumb} width={16} height={9} alt={name} />
</Link>
</li>
);
})}
</ul>
</nav>
</>
</div>
);
}
2 changes: 1 addition & 1 deletion demos/aquarium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"dev": "vite --host",
"dev2": "e2e-dev $npm_package_name",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview",
Expand Down
3 changes: 2 additions & 1 deletion demos/arkanoid-under-60-loc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/arkanoid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"zustand": "^3.4.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/audio-analyser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/backdrop-and-cables/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview",
Expand Down
3 changes: 2 additions & 1 deletion demos/baking-soft-shadows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview",
Expand Down
3 changes: 2 additions & 1 deletion demos/basic-ballpit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/basic-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bestservedbold-christmas-baubles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bezier-curves-and-nodes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bloom-hdr-workflow-gltf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bouncy-watch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bounds-and-makedefault/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bruno-simons-20k-challenge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/building-dynamic-envmaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/building-live-envmaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"vite": "^5.3.3"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/bvh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"bbuild2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/camera-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/camera-shake/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/canvas-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/cards-with-border-radius/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"three": "^0.165.0"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
3 changes: 2 additions & 1 deletion demos/cards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"vite": "^5.3.1"
},
"scripts": {
"dev": "vite --host --open",
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
Expand Down
Loading
Loading