@soroush.design/cli 0.2.0-alpha.3 → 0.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +2 -15
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/{io-Bybgct-f.mjs → io-CqI2BTaP.mjs} +430 -1032
- package/package.json +14 -5
- package/templates/astro/js/base/README.md +93 -0
- package/templates/astro/js/base/_gitignore +5 -0
- package/templates/astro/js/base/astro.config.mjs +23 -0
- package/templates/astro/js/base/src/components/About.jsx +24 -0
- package/templates/astro/js/base/src/components/Counter.jsx +26 -0
- package/templates/astro/js/base/src/components/Greeting.jsx +60 -0
- package/templates/astro/js/base/src/components/Header.jsx +99 -0
- package/templates/astro/js/base/src/components/Home.jsx +32 -0
- package/templates/astro/js/base/src/components/Home.test.jsx +39 -0
- package/templates/astro/js/base/src/components/NotFound.jsx +17 -0
- package/templates/astro/js/base/src/data/api.js +84 -0
- package/templates/astro/js/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/js/base/src/pages/404.astro +12 -0
- package/templates/astro/js/base/src/pages/about.astro +12 -0
- package/templates/astro/js/base/src/pages/index.astro +23 -0
- package/templates/astro/js/base/src/theme/Island.jsx +89 -0
- package/templates/astro/js/base/src/theme/scheme.js +32 -0
- package/templates/astro/js/base/vitest.config.js +12 -0
- package/templates/astro/js/sample-data/src/components/ItemDetails.jsx +64 -0
- package/templates/astro/js/sample-data/src/components/ItemList.jsx +100 -0
- package/templates/astro/js/sample-data/src/components/StatusChip.jsx +8 -0
- package/templates/astro/js/sample-data/src/data/items.js +65 -0
- package/templates/astro/js/sample-data/src/pages/items/[id].astro +37 -0
- package/templates/astro/js/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/js/with/jotai/src/components/Counter.jsx +26 -0
- package/templates/astro/js/with/jotai/src/state/counter.js +4 -0
- package/templates/astro/js/with/msw/_env +3 -0
- package/templates/astro/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/astro/js/with/msw/src/mocks/server.js +5 -0
- package/templates/astro/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/astro/js/with/msw/src/mocks/start.js +14 -0
- package/templates/astro/js/with/react-hook-form/src/components/Form.jsx +313 -0
- package/templates/astro/js/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/js/with/redux-toolkit/src/components/Counter.jsx +27 -0
- package/templates/astro/js/with/redux-toolkit/src/state/store.js +18 -0
- package/templates/astro/js/with/tanstack-query/src/data/queryClient.js +13 -0
- package/templates/astro/js/with/zustand/src/components/Counter.jsx +24 -0
- package/templates/astro/js/with/zustand/src/state/counter.js +14 -0
- package/templates/astro/ts/base/README.md +93 -0
- package/templates/astro/ts/base/_gitignore +5 -0
- package/templates/astro/ts/base/astro.config.mjs +23 -0
- package/templates/astro/ts/base/src/components/About.tsx +24 -0
- package/templates/astro/ts/base/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/base/src/components/Greeting.tsx +61 -0
- package/templates/astro/ts/base/src/components/Header.tsx +99 -0
- package/templates/astro/ts/base/src/components/Home.test.tsx +39 -0
- package/templates/astro/ts/base/src/components/Home.tsx +33 -0
- package/templates/astro/ts/base/src/components/NotFound.tsx +17 -0
- package/templates/astro/ts/base/src/data/api.ts +92 -0
- package/templates/astro/ts/base/src/layouts/Layout.astro +52 -0
- package/templates/astro/ts/base/src/pages/404.astro +12 -0
- package/templates/astro/ts/base/src/pages/about.astro +12 -0
- package/templates/astro/ts/base/src/pages/index.astro +23 -0
- package/templates/astro/ts/base/src/theme/Island.tsx +90 -0
- package/templates/astro/ts/base/src/theme/scheme.ts +34 -0
- package/templates/astro/ts/base/tsconfig.json +9 -0
- package/templates/astro/ts/base/vitest.config.ts +12 -0
- package/templates/astro/ts/sample-data/src/components/ItemDetails.tsx +65 -0
- package/templates/astro/ts/sample-data/src/components/ItemList.tsx +109 -0
- package/templates/astro/ts/sample-data/src/components/StatusChip.tsx +9 -0
- package/templates/astro/ts/sample-data/src/data/items.ts +71 -0
- package/templates/astro/ts/sample-data/src/pages/items/[id].astro +39 -0
- package/templates/astro/ts/sample-data/src/pages/items/index.astro +20 -0
- package/templates/astro/ts/with/jotai/src/components/Counter.tsx +26 -0
- package/templates/astro/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/astro/ts/with/msw/_env +3 -0
- package/templates/astro/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/astro/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/astro/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/astro/ts/with/msw/src/mocks/start.ts +14 -0
- package/templates/astro/ts/with/react-hook-form/src/components/Form.tsx +317 -0
- package/templates/astro/ts/with/react-hook-form/src/pages/form.astro +8 -0
- package/templates/astro/ts/with/redux-toolkit/src/components/Counter.tsx +27 -0
- package/templates/astro/ts/with/redux-toolkit/src/state/store.ts +19 -0
- package/templates/astro/ts/with/tanstack-query/src/data/queryClient.ts +13 -0
- package/templates/astro/ts/with/zustand/src/components/Counter.tsx +24 -0
- package/templates/astro/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/react-router/js/base/README.md +67 -0
- package/templates/react-router/js/base/_gitignore +4 -0
- package/templates/react-router/js/base/index.html +12 -0
- package/templates/react-router/js/base/src/components/RouterLink.jsx +12 -0
- package/templates/react-router/js/base/src/data/api.js +76 -0
- package/templates/react-router/js/base/src/main.jsx +38 -0
- package/templates/react-router/js/base/src/pages/ErrorPage.jsx +14 -0
- package/templates/react-router/js/base/src/pages/Layout.jsx +141 -0
- package/templates/react-router/js/base/src/pages/about/Page.jsx +14 -0
- package/templates/react-router/js/base/src/pages/index/Counter.jsx +18 -0
- package/templates/react-router/js/base/src/pages/index/Greeting.jsx +48 -0
- package/templates/react-router/js/base/src/pages/index/Page.jsx +29 -0
- package/templates/react-router/js/base/src/pages/index/Page.test.jsx +61 -0
- package/templates/react-router/js/base/src/routes.jsx +46 -0
- package/templates/react-router/js/base/vite.config.js +13 -0
- package/templates/react-router/js/base/vitest.config.js +13 -0
- package/templates/react-router/js/sample-data/src/data/items.js +55 -0
- package/templates/react-router/js/sample-data/src/pages/item/Page.jsx +49 -0
- package/templates/react-router/js/sample-data/src/pages/item/loader.js +14 -0
- package/templates/react-router/js/sample-data/src/pages/items/Page.jsx +48 -0
- package/templates/react-router/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
- package/templates/react-router/js/sample-data/src/pages/items/loader.js +11 -0
- package/templates/react-router/js/with/jotai/src/pages/index/Counter.jsx +19 -0
- package/templates/react-router/js/with/jotai/src/state/counter.js +4 -0
- package/templates/react-router/js/with/jotai/src/state/scheme.js +4 -0
- package/templates/react-router/js/with/msw/_env +3 -0
- package/templates/react-router/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/react-router/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/react-router/js/with/msw/src/mocks/server.js +5 -0
- package/templates/react-router/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/react-router/js/with/msw/src/mocks/start.js +10 -0
- package/templates/react-router/js/with/react-hook-form/src/pages/form/Page.jsx +294 -0
- package/templates/react-router/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
- package/templates/react-router/js/with/redux-toolkit/src/state/store.js +27 -0
- package/templates/react-router/js/with/zustand/src/pages/index/Counter.jsx +17 -0
- package/templates/react-router/js/with/zustand/src/state/counter.js +14 -0
- package/templates/react-router/js/with/zustand/src/state/scheme.js +14 -0
- package/templates/react-router/ts/base/README.md +67 -0
- package/templates/react-router/ts/base/_gitignore +4 -0
- package/templates/react-router/ts/base/index.html +12 -0
- package/templates/react-router/ts/base/src/components/RouterLink.tsx +12 -0
- package/templates/react-router/ts/base/src/data/api.ts +84 -0
- package/templates/react-router/ts/base/src/main.tsx +38 -0
- package/templates/react-router/ts/base/src/pages/ErrorPage.tsx +14 -0
- package/templates/react-router/ts/base/src/pages/Layout.tsx +141 -0
- package/templates/react-router/ts/base/src/pages/about/Page.tsx +14 -0
- package/templates/react-router/ts/base/src/pages/index/Counter.tsx +18 -0
- package/templates/react-router/ts/base/src/pages/index/Greeting.tsx +49 -0
- package/templates/react-router/ts/base/src/pages/index/Page.test.tsx +61 -0
- package/templates/react-router/ts/base/src/pages/index/Page.tsx +29 -0
- package/templates/react-router/ts/base/src/routes.tsx +47 -0
- package/templates/react-router/ts/base/tsconfig.json +18 -0
- package/templates/react-router/ts/base/vite.config.ts +13 -0
- package/templates/react-router/ts/base/vitest.config.ts +13 -0
- package/templates/react-router/ts/sample-data/src/data/items.ts +61 -0
- package/templates/react-router/ts/sample-data/src/pages/item/Page.tsx +50 -0
- package/templates/react-router/ts/sample-data/src/pages/item/loader.ts +14 -0
- package/templates/react-router/ts/sample-data/src/pages/items/Page.tsx +49 -0
- package/templates/react-router/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
- package/templates/react-router/ts/sample-data/src/pages/items/loader.ts +11 -0
- package/templates/react-router/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
- package/templates/react-router/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/react-router/ts/with/jotai/src/state/scheme.ts +4 -0
- package/templates/react-router/ts/with/msw/_env +3 -0
- package/templates/react-router/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/react-router/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/react-router/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/react-router/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/react-router/ts/with/msw/src/mocks/start.ts +10 -0
- package/templates/react-router/ts/with/react-hook-form/src/pages/form/Page.tsx +298 -0
- package/templates/react-router/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
- package/templates/react-router/ts/with/redux-toolkit/src/state/store.ts +29 -0
- package/templates/react-router/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
- package/templates/react-router/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/react-router/ts/with/zustand/src/state/scheme.ts +19 -0
- package/templates/templates.md +67 -0
- package/templates/vike/js/base/README.md +83 -0
- package/templates/vike/js/base/_gitignore +4 -0
- package/templates/vike/js/base/src/data/api.js +76 -0
- package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
- package/templates/vike/js/base/src/pages/+config.js +12 -0
- package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
- package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
- package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
- package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
- package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
- package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
- package/templates/vike/js/base/vite.config.js +14 -0
- package/templates/vike/js/base/vitest.config.js +13 -0
- package/templates/vike/js/sample-data/src/data/items.js +58 -0
- package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
- package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
- package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
- package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
- package/templates/vike/js/ssg/src/pages/+config.js +11 -0
- package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
- package/templates/vike/js/ssr/src/pages/+config.js +12 -0
- package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
- package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
- package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
- package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
- package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
- package/templates/vike/js/with/msw/_env +3 -0
- package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
- package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
- package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
- package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
- package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
- package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
- package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
- package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
- package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
- package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
- package/templates/vike/ts/base/README.md +83 -0
- package/templates/vike/ts/base/_gitignore +4 -0
- package/templates/vike/ts/base/src/data/api.ts +84 -0
- package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
- package/templates/vike/ts/base/src/pages/+config.ts +14 -0
- package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
- package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
- package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
- package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
- package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
- package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
- package/templates/vike/ts/base/src/vike.d.ts +20 -0
- package/templates/vike/ts/base/tsconfig.json +18 -0
- package/templates/vike/ts/base/vite.config.ts +14 -0
- package/templates/vike/ts/base/vitest.config.ts +13 -0
- package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
- package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
- package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
- package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
- package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
- package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
- package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
- package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
- package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
- package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
- package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
- package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
- package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
- package/templates/vike/ts/with/msw/_env +3 -0
- package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
- package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
- package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
- package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
- package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
- package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
- package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
- package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
- package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
- package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { RouteObject } from 'react-router'
|
|
2
|
+
import { ErrorPage } from './pages/ErrorPage'
|
|
3
|
+
import { Layout } from './pages/Layout'
|
|
4
|
+
import AboutPage from './pages/about/Page'
|
|
5
|
+
// @if react-hook-form
|
|
6
|
+
import FormPage from './pages/form/Page'
|
|
7
|
+
// @endif
|
|
8
|
+
import HomePage from './pages/index/Page'
|
|
9
|
+
// @if sample-data
|
|
10
|
+
import ItemPage from './pages/item/Page'
|
|
11
|
+
import ItemsPage from './pages/items/Page'
|
|
12
|
+
// @endif
|
|
13
|
+
// @if sample-data && !tanstack-query && !swr
|
|
14
|
+
import { loader as itemLoader } from './pages/item/loader'
|
|
15
|
+
import { loader as itemsLoader } from './pages/items/loader'
|
|
16
|
+
// @endif
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The app's pages, by path, each in the Layout. A path with no page, and a page that fails, show
|
|
20
|
+
* the error page in its place. https://reactrouter.com/start/data/routing
|
|
21
|
+
*/
|
|
22
|
+
export const routes: RouteObject[] = [
|
|
23
|
+
{
|
|
24
|
+
path: '/',
|
|
25
|
+
element: <Layout />,
|
|
26
|
+
children: [
|
|
27
|
+
{
|
|
28
|
+
errorElement: <ErrorPage />,
|
|
29
|
+
children: [
|
|
30
|
+
{ index: true, element: <HomePage /> },
|
|
31
|
+
{ path: 'about', element: <AboutPage /> },
|
|
32
|
+
// @if sample-data && (tanstack-query || swr)
|
|
33
|
+
{ path: 'items', element: <ItemsPage /> },
|
|
34
|
+
{ path: 'items/:id', element: <ItemPage /> },
|
|
35
|
+
// @elif sample-data
|
|
36
|
+
{ path: 'items', loader: itemsLoader, element: <ItemsPage /> },
|
|
37
|
+
{ path: 'items/:id', loader: itemLoader, element: <ItemPage /> },
|
|
38
|
+
// @endif
|
|
39
|
+
// @if react-hook-form
|
|
40
|
+
{ path: 'form', element: <FormPage /> },
|
|
41
|
+
// @endif
|
|
42
|
+
{ path: '*', element: <ErrorPage /> },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"verbatimModuleSyntax": true,
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"jsx": "react-jsx",
|
|
15
|
+
"types": ["vite/client"]
|
|
16
|
+
},
|
|
17
|
+
"include": ["src", "vite.config.ts"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react'
|
|
2
|
+
// @if msw
|
|
3
|
+
import { msw } from 'msw/vite'
|
|
4
|
+
// @endif
|
|
5
|
+
import { defineConfig } from 'vite'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
// @if msw
|
|
9
|
+
plugins: [react(), msw({ mode: 'worker-only' })],
|
|
10
|
+
// @else
|
|
11
|
+
plugins: [react()],
|
|
12
|
+
// @endif
|
|
13
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react'
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
// The tests render components in jsdom, with no router: a page is a component like any other.
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
// @if msw
|
|
8
|
+
// The mock API answers the tests' requests, from Node, as it answers the app's in the browser.
|
|
9
|
+
test: { environment: 'jsdom', setupFiles: ['./src/mocks/setupTests.ts'] },
|
|
10
|
+
// @else
|
|
11
|
+
test: { environment: 'jsdom' },
|
|
12
|
+
// @endif
|
|
13
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @if ts
|
|
2
|
+
/** One sample item. */
|
|
3
|
+
export interface Item {
|
|
4
|
+
id: string
|
|
5
|
+
title: string
|
|
6
|
+
summary: string
|
|
7
|
+
status: 'todo' | 'doing' | 'done'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// @endif
|
|
11
|
+
/**
|
|
12
|
+
// @if tanstack-query || swr
|
|
13
|
+
* Sample data, so the items pages have something to show: src/data/api.ts answers with it. Make
|
|
14
|
+
* src/data/api.ts fetch from your API instead, and remove this file.
|
|
15
|
+
// @else
|
|
16
|
+
* Sample data, so the items pages have something to show: their loaders read it. Make the loaders
|
|
17
|
+
* fetch your own data instead, and remove this file.
|
|
18
|
+
// @endif
|
|
19
|
+
*/
|
|
20
|
+
export const items: readonly Item[] = [
|
|
21
|
+
{
|
|
22
|
+
id: 'theme',
|
|
23
|
+
title: 'Make the theme your own',
|
|
24
|
+
summary: 'Change the colors and fonts of both themes in src/theme/themes.ts.',
|
|
25
|
+
status: 'doing',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'fonts',
|
|
29
|
+
title: 'Load the fonts',
|
|
30
|
+
summary: 'The theme names Space Grotesk and JetBrains Mono, and does not load them.',
|
|
31
|
+
status: 'todo',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'pages',
|
|
35
|
+
title: 'Add a page',
|
|
36
|
+
summary: 'A component in src/pages, and a route for it in src/routes.tsx, is a new page.',
|
|
37
|
+
status: 'todo',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'data',
|
|
41
|
+
title: 'Read your own data',
|
|
42
|
+
// @if tanstack-query || swr
|
|
43
|
+
summary: 'src/data/api.ts answers with this file. Make it fetch from your API.',
|
|
44
|
+
// @else
|
|
45
|
+
summary: 'Each loader here reads this file. Make it fetch from your API.',
|
|
46
|
+
// @endif
|
|
47
|
+
status: 'todo',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'build',
|
|
51
|
+
title: 'Build it',
|
|
52
|
+
summary: 'The build writes the app to dist: one HTML page, and the scripts that render it.',
|
|
53
|
+
status: 'done',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'deploy',
|
|
57
|
+
title: 'Deploy it',
|
|
58
|
+
summary: 'Any static host serves dist, once it answers every path with index.html.',
|
|
59
|
+
status: 'todo',
|
|
60
|
+
},
|
|
61
|
+
]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
3
|
+
// @if tanstack-query
|
|
4
|
+
import { useQuery } from '@tanstack/react-query'
|
|
5
|
+
import { useParams } from 'react-router'
|
|
6
|
+
// @elif swr
|
|
7
|
+
import { useParams } from 'react-router'
|
|
8
|
+
import useSWR from 'swr'
|
|
9
|
+
// @else
|
|
10
|
+
import { useLoaderData } from 'react-router'
|
|
11
|
+
// @endif
|
|
12
|
+
import { RouterLink } from '../../components/RouterLink'
|
|
13
|
+
// @if tanstack-query || swr
|
|
14
|
+
import { fetchItem } from '../../data/api'
|
|
15
|
+
// @endif
|
|
16
|
+
import { StatusChip } from '../items/StatusChip'
|
|
17
|
+
// @if !tanstack-query && !swr
|
|
18
|
+
import type { loader } from './loader'
|
|
19
|
+
// @endif
|
|
20
|
+
|
|
21
|
+
export default function Page() {
|
|
22
|
+
// @if tanstack-query
|
|
23
|
+
const id = useParams().id!
|
|
24
|
+
const { data: item, error } = useQuery({
|
|
25
|
+
queryKey: ['items', id],
|
|
26
|
+
queryFn: () => fetchItem(id),
|
|
27
|
+
// An id with no item has none on a second try either: the error page shows at once.
|
|
28
|
+
retry: false,
|
|
29
|
+
})
|
|
30
|
+
// An id with no item: the error page shows in this page's place.
|
|
31
|
+
if (error) throw error
|
|
32
|
+
if (!item) return <Typography color="secondary">Asking the API for the item...</Typography>
|
|
33
|
+
// @elif swr
|
|
34
|
+
const id = useParams().id!
|
|
35
|
+
const { data: item, error } = useSWR(['items', id], () => fetchItem(id))
|
|
36
|
+
// An id with no item: the error page shows in this page's place.
|
|
37
|
+
if (error) throw error
|
|
38
|
+
if (!item) return <Typography color="secondary">Asking the API for the item...</Typography>
|
|
39
|
+
// @else
|
|
40
|
+
const item = useLoaderData<typeof loader>()
|
|
41
|
+
// @endif
|
|
42
|
+
return (
|
|
43
|
+
<Flex gap={2} alignItems="flex-start">
|
|
44
|
+
<Typography variant="h2">{item.title}</Typography>
|
|
45
|
+
<StatusChip status={item.status} />
|
|
46
|
+
<Typography color="secondary">{item.summary}</Typography>
|
|
47
|
+
<RouterLink to="/items">All items</RouterLink>
|
|
48
|
+
</Flex>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @if !tanstack-query && !swr
|
|
2
|
+
import { data, type LoaderFunctionArgs } from 'react-router'
|
|
3
|
+
import { items } from '../../data/items'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One item's data, by the id in the URL, or the error page for an id with no item. The router
|
|
7
|
+
* runs it before it shows the page. https://reactrouter.com/start/data/data-loading
|
|
8
|
+
*/
|
|
9
|
+
export function loader({ params }: LoaderFunctionArgs) {
|
|
10
|
+
const item = items.find(({ id }) => id === params.id)
|
|
11
|
+
if (!item) throw data(`There is no item ${params.id}.`, { status: 404 })
|
|
12
|
+
return item
|
|
13
|
+
}
|
|
14
|
+
// @endif
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
2
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
3
|
+
// @if tanstack-query
|
|
4
|
+
import { useQuery } from '@tanstack/react-query'
|
|
5
|
+
// @elif swr
|
|
6
|
+
import useSWR from 'swr'
|
|
7
|
+
// @else
|
|
8
|
+
import { useLoaderData } from 'react-router'
|
|
9
|
+
// @endif
|
|
10
|
+
import { RouterLink } from '../../components/RouterLink'
|
|
11
|
+
// @if tanstack-query || swr
|
|
12
|
+
import { fetchItems } from '../../data/api'
|
|
13
|
+
// @else
|
|
14
|
+
import type { loader } from './loader'
|
|
15
|
+
// @endif
|
|
16
|
+
import { StatusChip } from './StatusChip'
|
|
17
|
+
|
|
18
|
+
export default function Page() {
|
|
19
|
+
// @if tanstack-query
|
|
20
|
+
const { data: items = [] } = useQuery({ queryKey: ['items'], queryFn: fetchItems })
|
|
21
|
+
// @elif swr
|
|
22
|
+
const { data: items = [] } = useSWR('items', fetchItems)
|
|
23
|
+
// @else
|
|
24
|
+
const items = useLoaderData<typeof loader>()
|
|
25
|
+
// @endif
|
|
26
|
+
return (
|
|
27
|
+
<Flex gap={2}>
|
|
28
|
+
<Typography variant="h2">Items</Typography>
|
|
29
|
+
<Typography color="secondary">
|
|
30
|
+
{/* @if tanstack-query */}
|
|
31
|
+
Sample data from src/data/items.ts, which this page reads through src/data/api.ts with a
|
|
32
|
+
query of TanStack Query.
|
|
33
|
+
{/* @elif swr */}
|
|
34
|
+
Sample data from src/data/items.ts, which this page reads through src/data/api.ts with SWR.
|
|
35
|
+
{/* @else */}
|
|
36
|
+
Sample data from src/data/items.ts, which this page's loader reads before it is shown.
|
|
37
|
+
{/* @endif */}
|
|
38
|
+
</Typography>
|
|
39
|
+
<Flex gap={1}>
|
|
40
|
+
{items.map((item) => (
|
|
41
|
+
<Flex key={item.id} flexDirection="row" alignItems="center" gap={2}>
|
|
42
|
+
<RouterLink to={`/items/${item.id}`}>{item.title}</RouterLink>
|
|
43
|
+
<StatusChip status={item.status} />
|
|
44
|
+
</Flex>
|
|
45
|
+
))}
|
|
46
|
+
</Flex>
|
|
47
|
+
</Flex>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Chip } from '@soroush.tech/design-system/Chip'
|
|
2
|
+
import type { Item } from '../../data/items'
|
|
3
|
+
|
|
4
|
+
const COLORS = { todo: 'default', doing: 'primary', done: 'success' } as const
|
|
5
|
+
|
|
6
|
+
/** An item's status, in its palette color. */
|
|
7
|
+
export function StatusChip({ status }: { readonly status: Item['status'] }) {
|
|
8
|
+
return <Chip label={status} size="sm" variant="outlined" color={COLORS[status]} />
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @if !tanstack-query && !swr
|
|
2
|
+
import { items } from '../../data/items'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The list page's data: what it shows of each item. The router runs it before it shows the page.
|
|
6
|
+
* https://reactrouter.com/start/data/data-loading
|
|
7
|
+
*/
|
|
8
|
+
export function loader() {
|
|
9
|
+
return items.map(({ id, title, status }) => ({ id, title, status }))
|
|
10
|
+
}
|
|
11
|
+
// @endif
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Button } from '@soroush.tech/design-system/Button'
|
|
2
|
+
import { Flex } from '@soroush.tech/design-system/Flex'
|
|
3
|
+
import { Typography } from '@soroush.tech/design-system/Typography'
|
|
4
|
+
import { useAtom } from 'jotai'
|
|
5
|
+
import { countAtom } from '../../state/counter'
|
|
6
|
+
|
|
7
|
+
/** A count, held in a Jotai atom, src/state/counter, and the button that adds to it. */
|
|
8
|
+
export function Counter() {
|
|
9
|
+
const [count, setCount] = useAtom(countAtom)
|
|
10
|
+
const increment = () => setCount(count + 1)
|
|
11
|
+
return (
|
|
12
|
+
<Flex flexDirection="row" alignItems="center" gap={2}>
|
|
13
|
+
<Button size="sm" variant="outlined" onClick={increment}>
|
|
14
|
+
Count
|
|
15
|
+
</Button>
|
|
16
|
+
<Typography>Count: {count}</Typography>
|
|
17
|
+
</Flex>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { http, HttpResponse } from 'msw'
|
|
2
|
+
// @if sample-data && (tanstack-query || swr)
|
|
3
|
+
import { items } from '../data/items'
|
|
4
|
+
// @endif
|
|
5
|
+
|
|
6
|
+
/** The mock API: what it answers, by method and path. Add a handler for each call the app makes. */
|
|
7
|
+
export const handlers = [
|
|
8
|
+
http.get('/api/greeting', () => HttpResponse.json({ message: 'Hello from the mock API' })),
|
|
9
|
+
// @if react-hook-form
|
|
10
|
+
http.post<never, { name: string }>('/api/messages', async ({ request }) => {
|
|
11
|
+
const { name } = await request.json()
|
|
12
|
+
return HttpResponse.json({ message: `Thanks, ${name}: the mock API took your message.` })
|
|
13
|
+
}),
|
|
14
|
+
// @endif
|
|
15
|
+
// @if sample-data && (tanstack-query || swr)
|
|
16
|
+
http.get('/api/items', () =>
|
|
17
|
+
HttpResponse.json(items.map(({ id, title, status }) => ({ id, title, status })))
|
|
18
|
+
),
|
|
19
|
+
http.get('/api/items/:id', ({ params }) => {
|
|
20
|
+
const item = items.find(({ id }) => id === params.id)
|
|
21
|
+
return item ? HttpResponse.json(item) : new HttpResponse(null, { status: 404 })
|
|
22
|
+
}),
|
|
23
|
+
// @endif
|
|
24
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeAll } from 'vitest'
|
|
2
|
+
import { server } from './server'
|
|
3
|
+
|
|
4
|
+
// The mock API answers every request a test makes; one it has no handler for fails the test.
|
|
5
|
+
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
|
|
6
|
+
afterEach(() => server.resetHandlers())
|
|
7
|
+
afterAll(() => server.close())
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starts the mock API in the browser while VITE_MSW, in .env, is true. Set it to false once the
|
|
3
|
+
* app's own API answers.
|
|
4
|
+
*/
|
|
5
|
+
export async function startMocks() {
|
|
6
|
+
if (import.meta.env.VITE_MSW !== 'true') return
|
|
7
|
+
const { worker } = await import('./browser')
|
|
8
|
+
// A request the mock API has no handler for - a module, an image - goes to the network.
|
|
9
|
+
await worker.start({ onUnhandledFrame: 'bypass' })
|
|
10
|
+
}
|