generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e9bbf7
commit ace05eb
Showing
40 changed files
with
545 additions
and
123 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
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,18 @@ | ||
--- | ||
title: React | ||
aside: false | ||
--- | ||
|
||
<iframe | ||
src="https://codesandbox.io/embed/github/kubb-labs/kubb/tree/main/examples/react?fontsize=14&module=%2Fsrc%2Fgen%2Fmodels%2FPerson.ts&theme=dark&view=editor" | ||
:style="{ | ||
width: '100%', | ||
height: '700px', | ||
border: 0, | ||
borderRadius: '4px', | ||
overflow: 'hidden' | ||
}" | ||
title="React" | ||
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" | ||
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" | ||
/> |
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,2 @@ | ||
FROM node:20-bullseye | ||
RUN npm i -g pnpm |
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,20 @@ | ||
import fs from 'node:fs' | ||
|
||
const pkgJsonPaths = ['package.json'] | ||
try { | ||
for (const pkgJsonPath of pkgJsonPaths) { | ||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')) | ||
const oldVersion = 'workspace:*' | ||
const newVersion = 'alpha' | ||
|
||
const content = JSON.stringify(pkg, null, '\t') + '\n' | ||
const newContent = content | ||
// @ts-ignore | ||
.replaceAll(`"${oldVersion}"`, `"${newVersion}"`) | ||
|
||
fs.writeFileSync(pkgJsonPath, newContent) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
process.exit(1) | ||
} |
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,33 @@ | ||
{ | ||
"$schema": "https://codesandbox.io/schemas/tasks.json", | ||
"setupTasks": [ | ||
{ | ||
"name": "Replace workspace:* by latest", | ||
"command": "node ./.codesandbox/build.js" | ||
}, | ||
{ | ||
"name": "Install Dependencies", | ||
"command": "pnpm install" | ||
} | ||
], | ||
"tasks": { | ||
"dev": { | ||
"name": "dev", | ||
"command": "pnpm dev", | ||
"runAtStart": true, | ||
"preview": { | ||
"port": 5173 | ||
} | ||
}, | ||
"build": { | ||
"name": "build", | ||
"command": "pnpm build", | ||
"runAtStart": false | ||
}, | ||
"update": { | ||
"name": "update", | ||
"command": "pnpm update", | ||
"runAtStart": false | ||
} | ||
} | ||
} |
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,43 @@ | ||
import { useEffect, useRef, useState } from 'react' | ||
|
||
import { Text, createRoot, useLifecycle } from '@kubb/react' | ||
|
||
// attach node stdout with Kubb's internal one | ||
const root = createRoot({ stdout: process.stdout }) | ||
|
||
/** | ||
* Render component that will count down from 5 | ||
*/ | ||
function Component() { | ||
const timer = useRef<NodeJS.Timer>() | ||
const [counter, setCounter] = useState(5) | ||
const { exit } = useLifecycle() | ||
|
||
useEffect(() => { | ||
timer.current = setInterval(() => { | ||
setCounter((previousCounter) => { | ||
return previousCounter - 1 | ||
}) | ||
}, 1000) | ||
|
||
return () => { | ||
clearInterval(timer.current) | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (counter === 0) { | ||
// trigger unmount | ||
exit() | ||
clearInterval(timer.current) | ||
} | ||
}, [counter, exit]) | ||
|
||
if (counter === 0) { | ||
return <Text indentSize={2}>Finished</Text> | ||
} | ||
|
||
return <Text>Counter: {counter}</Text> | ||
} | ||
|
||
root.render(<Component />) |
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,28 @@ | ||
import process from 'node:process' | ||
import React from 'react' | ||
|
||
import path from 'node:path' | ||
import { Const, File, createRoot } from '@kubb/react' | ||
|
||
const root = createRoot({ stdout: process.stdout }) | ||
|
||
/** | ||
* Create a simple file and write it to the file-system | ||
*/ | ||
function Component() { | ||
return ( | ||
<File path={path.resolve(__dirname, 'result.ts')} baseName={'result.ts'}> | ||
<File.Source> | ||
<Const name={'hello'}>"World!"</Const> | ||
</File.Source> | ||
</File> | ||
) | ||
} | ||
|
||
async function start() { | ||
root.render(<Component />) | ||
console.log('\nFiles: ', root.files.length) | ||
await root.write() | ||
} | ||
|
||
start() |
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 @@ | ||
const hello = "World!"; |
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,42 @@ | ||
import process from 'node:process' | ||
import React from 'react' | ||
|
||
import path from 'node:path' | ||
import { Const, File, createRoot } from '@kubb/react' | ||
|
||
const root = createRoot({ stdout: process.stdout }) | ||
|
||
/** | ||
* Create 2 files and write them to the file-system | ||
*/ | ||
function Component() { | ||
const namesPath = path.resolve(__dirname, 'name.ts') | ||
const helloWorldPath = path.resolve(__dirname, 'result.ts') | ||
|
||
return ( | ||
<> | ||
<File path={namesPath} baseName={'name.ts'}> | ||
<File.Source> | ||
<Const export asConst name={'name'}> | ||
"Lily" | ||
</Const> | ||
</File.Source> | ||
</File> | ||
|
||
<File path={helloWorldPath} baseName={'result.ts'}> | ||
<File.Import root={helloWorldPath} name={['name']} path={namesPath} /> | ||
<File.Source> | ||
<Const name={'hello'}>name</Const> | ||
</File.Source> | ||
</File> | ||
</> | ||
) | ||
} | ||
|
||
async function start() { | ||
root.render(<Component />) | ||
console.log('\nFiles: ', root.files.length) | ||
await root.write() | ||
} | ||
|
||
start() |
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 @@ | ||
export const name = "Lily" as const; |
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 @@ | ||
import { name } from "./name"; | ||
|
||
const hello = name; |
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,67 @@ | ||
import process from 'node:process' | ||
import React, { useEffect, useState } from 'react' | ||
|
||
import path from 'node:path' | ||
import { Const, File, Function, createRoot, useLifecycle } from '@kubb/react' | ||
|
||
const root = createRoot({ stdout: process.stdout }) | ||
|
||
const fetchNames = async (): Promise<string[]> => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(['Lily', 'Jan']) | ||
}, 2000) | ||
}) | ||
} | ||
|
||
/** | ||
* Create a file and append data based on a promise | ||
*/ | ||
function Component() { | ||
const [names, setNames] = useState<string[]>([]) | ||
const { exit } = useLifecycle() | ||
|
||
useEffect(() => { | ||
fetchNames().then((newNames) => { | ||
setNames(newNames) | ||
exit() | ||
}) | ||
}, [exit]) | ||
|
||
return ( | ||
<File path={path.resolve(__dirname, 'result.ts')} baseName={'result.ts'}> | ||
<File.Source> | ||
<Const name={'names'}>"{names.join(' and ')}"</Const> | ||
<br /> | ||
<Function.Arrow name={'getNames'} export singleLine> | ||
names | ||
</Function.Arrow> | ||
<Function.Arrow name={'getFirstChar'} export> | ||
return names.charAt(0) | ||
</Function.Arrow> | ||
<br /> | ||
<Function | ||
name={'getNamesTyped'} | ||
export | ||
returnType={'TNames'} | ||
JSDoc={{ | ||
comments: ['Returns the names'], | ||
}} | ||
generics={['TNames extends string']} | ||
> | ||
return names as TNames | ||
</Function> | ||
</File.Source> | ||
</File> | ||
) | ||
} | ||
|
||
async function start() { | ||
root.render(<Component />) | ||
|
||
await root.waitUntilExit() | ||
console.log('\nFiles: ', root.files.length) | ||
await root.write() | ||
} | ||
|
||
start() |
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,12 @@ | ||
const names = "Lily and Jan"; | ||
export const getNames = () => names; | ||
export const getFirstChar = () => { | ||
return names.charAt(0); | ||
}; | ||
|
||
/** | ||
* Returns the names | ||
*/ | ||
export function getNamesTyped<TNames extends string>(): TNames { | ||
return names as TNames; | ||
} |
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 function Users() { | ||
return (<div className="test"/>); | ||
} |
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,34 @@ | ||
import process from 'node:process' | ||
import React from 'react' | ||
|
||
import path from 'node:path' | ||
import { File, Function, createRoot } from '@kubb/react' | ||
|
||
const root = createRoot({ stdout: process.stdout }) | ||
|
||
/** | ||
* Create a file and append JSX | ||
*/ | ||
function Component() { | ||
return ( | ||
<File path={path.resolve(__dirname, 'App.tsx')} baseName={'App.tsx'}> | ||
<File.Source> | ||
<Function export name={'Users'}> | ||
{` | ||
return ( | ||
<div className="test" /> | ||
) | ||
`} | ||
</Function> | ||
</File.Source> | ||
</File> | ||
) | ||
} | ||
|
||
async function start() { | ||
root.render(<Component />) | ||
|
||
await root.write() | ||
} | ||
|
||
start() |
Oops, something went wrong.