@quilted/create 0.2.29 → 0.2.31

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/templates/app-basic/App.tsx +22 -16
  4. package/templates/{app-graphql/features/start/Start.module.css → app-basic/features/home/Home.module.css} +1 -1
  5. package/templates/app-basic/features/home/Home.tsx +5 -0
  6. package/templates/app-basic/features/home/tests/Home.test.tsx +12 -0
  7. package/templates/app-basic/features/home.ts +3 -0
  8. package/templates/app-graphql/App.tsx +26 -17
  9. package/templates/app-graphql/browser.tsx +6 -4
  10. package/templates/{app-basic/features/start/Start.module.css → app-graphql/features/home/Home.module.css} +1 -1
  11. package/templates/app-graphql/features/home/Home.tsx +13 -0
  12. package/templates/app-graphql/features/{start/StartQuery.graphql → home/HomeQuery.graphql} +1 -1
  13. package/templates/app-graphql/features/home/tests/Home.test.tsx +21 -0
  14. package/templates/app-graphql/features/home.ts +5 -0
  15. package/templates/app-graphql/server.tsx +12 -11
  16. package/templates/app-graphql/shared/graphql.ts +4 -2
  17. package/templates/app-trpc/App.tsx +26 -23
  18. package/templates/app-trpc/features/{start/Start.module.css → home/Home.module.css} +1 -1
  19. package/templates/app-trpc/features/home/Home.tsx +9 -0
  20. package/templates/app-trpc/features/home/tests/Home.test.tsx +12 -0
  21. package/templates/app-trpc/features/home.ts +3 -0
  22. package/templates/app-basic/features/start/Start.tsx +0 -5
  23. package/templates/app-basic/features/start/tests/Start.test.tsx +0 -12
  24. package/templates/app-basic/features/start.ts +0 -3
  25. package/templates/app-graphql/features/start/Start.tsx +0 -13
  26. package/templates/app-graphql/features/start/tests/Start.test.tsx +0 -21
  27. package/templates/app-graphql/features/start.ts +0 -3
  28. package/templates/app-trpc/features/start/Start.tsx +0 -9
  29. package/templates/app-trpc/features/start/tests/Start.test.tsx +0 -12
  30. package/templates/app-trpc/features/start.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.2.31
4
+
5
+ ### Patch Changes
6
+
7
+ - [`36ad8b1`](https://github.com/lemonmade/quilt/commit/36ad8b15df3dbad465b4f324dcaa26ea9892f234) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix incorrect style import in basic app template
8
+
9
+ - [#757](https://github.com/lemonmade/quilt/pull/757) [`00cac4b`](https://github.com/lemonmade/quilt/commit/00cac4b4d01831ba654e94152d7a67a0ef75043b) Thanks [@lemonmade](https://github.com/lemonmade)! - Simplify routing library
10
+
11
+ ## 0.2.30
12
+
13
+ ### Patch Changes
14
+
15
+ - [`f5981c1`](https://github.com/lemonmade/quilt/commit/f5981c1a28c91ffed11536b1ab6274c3d945bdf8) Thanks [@lemonmade](https://github.com/lemonmade)! - Improve app context in GraphQL template
16
+
17
+ - [`a70f378`](https://github.com/lemonmade/quilt/commit/a70f378463b7c951654e6ff44b4bf5aaeda3a386) Thanks [@lemonmade](https://github.com/lemonmade)! - Rename `Start` to `Home` in app templates
18
+
3
19
  ## 0.2.29
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/create",
3
3
  "type": "module",
4
- "version": "0.2.29",
4
+ "version": "0.2.31",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,12 +1,13 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
- import {Routing, useRoutes} from '@quilted/quilt/navigate';
3
+ import {NotFound} from '@quilted/quilt/server';
4
+ import {Navigation, route} from '@quilted/quilt/navigate';
4
5
  import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
5
6
 
6
7
  import {HTML} from './foundation/html.ts';
7
8
  import {Frame} from './foundation/frame.ts';
8
9
 
9
- import {Start} from './features/start.ts';
10
+ import {Home} from './features/home.ts';
10
11
 
11
12
  import {
12
13
  AppContextReact,
@@ -17,15 +18,30 @@ export interface AppProps {
17
18
  context: AppContextType;
18
19
  }
19
20
 
21
+ // Define the routes for your application. If you have a lot of routes, you
22
+ // might want to split this into a separate file.
23
+ const routes = [
24
+ route('*', {
25
+ render: (children) => <Frame>{children}</Frame>,
26
+ children: [
27
+ route('/', {
28
+ async load() {
29
+ await Promise.all([Home.load()]);
30
+ },
31
+ render: <Home />,
32
+ }),
33
+ route('*', {render: <NotFound />}),
34
+ ],
35
+ }),
36
+ ];
37
+
20
38
  // The root component for your application. You will typically render any
21
39
  // app-wide context in this component.
22
40
  export function App({context}: AppProps) {
23
41
  return (
24
42
  <AppContext context={context}>
25
43
  <HTML>
26
- <Frame>
27
- <Routes />
28
- </Frame>
44
+ <Navigation routes={routes} context={context} />
29
45
  </HTML>
30
46
  </AppContext>
31
47
  );
@@ -33,23 +49,13 @@ export function App({context}: AppProps) {
33
49
 
34
50
  export default App;
35
51
 
36
- // This component renders the routes for your application. If you have a lot
37
- // of routes, you may want to split this component into its own file.
38
- function Routes() {
39
- return useRoutes([
40
- {match: '/', render: <Start />, renderPreload: <Start.Preload />},
41
- ]);
42
- }
43
-
44
52
  // This component renders any app-wide context.
45
53
  function AppContext({children, context}: RenderableProps<AppProps>) {
46
54
  const locale = useLocaleFromEnvironment() ?? 'en';
47
55
 
48
56
  return (
49
57
  <AppContextReact.Provider value={context}>
50
- <Localization locale={locale}>
51
- <Routing>{children}</Routing>
52
- </Localization>
58
+ <Localization locale={locale}>{children}</Localization>
53
59
  </AppContextReact.Provider>
54
60
  );
55
61
  }
@@ -1,3 +1,3 @@
1
- .Start {
1
+ .Home {
2
2
  font-weight: 900;
3
3
  }
@@ -0,0 +1,5 @@
1
+ import styles from './Home.module.css';
2
+
3
+ export default function Home() {
4
+ return <div className={styles.Home}>Hello world!</div>;
5
+ }
@@ -0,0 +1,12 @@
1
+ import {describe, it, expect} from 'vitest';
2
+
3
+ import {renderApp} from '~/tests/render.ts';
4
+
5
+ import Home from '../Home.tsx';
6
+
7
+ describe('<Home />', () => {
8
+ it('includes a welcome message', async () => {
9
+ const home = await renderApp(<Home />);
10
+ expect(home).toContainPreactText('Hello world!');
11
+ });
12
+ });
@@ -0,0 +1,3 @@
1
+ import {AsyncComponent} from '@quilted/quilt/async';
2
+
3
+ export const Home = AsyncComponent.from(() => import('./home/Home.tsx'));
@@ -1,13 +1,14 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
+ import {NotFound} from '@quilted/quilt/server';
3
4
  import {GraphQLContext} from '@quilted/quilt/graphql';
4
- import {Routing, useRoutes} from '@quilted/quilt/navigate';
5
+ import {Navigation, route} from '@quilted/quilt/navigate';
5
6
  import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
6
7
 
7
8
  import {HTML} from './foundation/html.ts';
8
9
  import {Frame} from './foundation/frame.ts';
9
10
 
10
- import {Start} from './features/start.ts';
11
+ import {Home, homeQuery} from './features/home.ts';
11
12
 
12
13
  import {
13
14
  AppContextReact,
@@ -18,15 +19,30 @@ export interface AppProps {
18
19
  context: AppContextType;
19
20
  }
20
21
 
22
+ // Define the routes for your application. If you have a lot of routes, you
23
+ // might want to split this into a separate file.
24
+ const routes = [
25
+ route('*', {
26
+ render: (children) => <Frame>{children}</Frame>,
27
+ children: [
28
+ route('/', {
29
+ async load(_navigation, {graphql}: AppContextType) {
30
+ await Promise.all([Home.load(), graphql.cache.query(homeQuery)]);
31
+ },
32
+ render: <Home />,
33
+ }),
34
+ route('*', {render: <NotFound />}),
35
+ ],
36
+ }),
37
+ ];
38
+
21
39
  // The root component for your application. You will typically render any
22
40
  // app-wide context in this component.
23
41
  export function App({context}: AppProps) {
24
42
  return (
25
43
  <AppContext context={context}>
26
44
  <HTML>
27
- <Frame>
28
- <Routes />
29
- </Frame>
45
+ <Navigation routes={routes} context={context} />
30
46
  </HTML>
31
47
  </AppContext>
32
48
  );
@@ -34,24 +50,17 @@ export function App({context}: AppProps) {
34
50
 
35
51
  export default App;
36
52
 
37
- // This component renders the routes for your application. If you have a lot
38
- // of routes, you may want to split this component into its own file.
39
- function Routes() {
40
- return useRoutes([
41
- {match: '/', render: <Start />, renderPreload: <Start.Preload />},
42
- ]);
43
- }
44
-
45
53
  // This component renders any app-wide context.
46
54
  function AppContext({children, context}: RenderableProps<AppProps>) {
47
55
  const locale = useLocaleFromEnvironment() ?? 'en';
48
56
 
49
57
  return (
50
58
  <AppContextReact.Provider value={context}>
51
- <GraphQLContext fetch={context.fetchGraphQL} cache={context.graphQLCache}>
52
- <Localization locale={locale}>
53
- <Routing>{children}</Routing>
54
- </Localization>
59
+ <GraphQLContext
60
+ fetch={context.graphql.fetch}
61
+ cache={context.graphql.cache}
62
+ >
63
+ <Localization locale={locale}>{children}</Localization>
55
64
  </GraphQLContext>
56
65
  </AppContextReact.Provider>
57
66
  );
@@ -11,12 +11,14 @@ import {App} from './App.tsx';
11
11
  const element = document.querySelector('#app')!;
12
12
  const browser = new Browser();
13
13
 
14
- const fetchGraphQL = createGraphQLFetch({url: '/api/graphql'});
15
- const graphQLCache = new GraphQLCache({fetch: fetchGraphQL});
14
+ const graphQLFetch = createGraphQLFetch({url: '/api/graphql'});
15
+ const graphQLCache = new GraphQLCache({fetch: graphQLFetch});
16
16
 
17
17
  const context = {
18
- fetchGraphQL,
19
- graphQLCache,
18
+ graphql: {
19
+ fetch: graphQLFetch,
20
+ cache: graphQLCache,
21
+ },
20
22
  } satisfies AppContext;
21
23
 
22
24
  // Makes key parts of the app available in the browser console
@@ -1,3 +1,3 @@
1
- .Start {
1
+ .Home {
2
2
  font-weight: 900;
3
3
  }
@@ -0,0 +1,13 @@
1
+ import {useGraphQLQuery} from '@quilted/quilt/graphql';
2
+
3
+ import styles from './Home.module.css';
4
+ import homeQuery from './HomeQuery.graphql';
5
+
6
+ export default function Home() {
7
+ const query = useGraphQLQuery(homeQuery);
8
+
9
+ const me = query.result?.data?.me;
10
+ const greeting = me ? `Hello ${me.name}!` : 'Hello!';
11
+
12
+ return <div className={styles.Home}>{greeting}</div>;
13
+ }
@@ -1,4 +1,4 @@
1
- query Start {
1
+ query Home {
2
2
  me {
3
3
  name
4
4
  }
@@ -0,0 +1,21 @@
1
+ import {describe, it, expect} from 'vitest';
2
+
3
+ import {renderApp} from '~/tests/render.ts';
4
+ import {fillGraphQL, GraphQLController} from '~/tests/graphql.ts';
5
+
6
+ import Home from '../Home.tsx';
7
+ import homeQuery from '../HomeQuery.graphql';
8
+
9
+ describe('<Home />', () => {
10
+ it('welcomes the user with their name', async () => {
11
+ const name = 'Winston';
12
+ const graphql = new GraphQLController([
13
+ fillGraphQL(homeQuery, {me: {name}}),
14
+ ]);
15
+
16
+ const home = await renderApp(<Home />, {graphql});
17
+
18
+ expect(graphql).toHavePerformedGraphQLQuery(homeQuery);
19
+ expect(home).toContainPreactText(`Hello ${name}!`);
20
+ });
21
+ });
@@ -0,0 +1,5 @@
1
+ import {AsyncComponent} from '@quilted/quilt/async';
2
+
3
+ export {default as homeQuery} from './home/HomeQuery.graphql';
4
+
5
+ export const Home = AsyncComponent.from(() => import('./home/Home.tsx'));
@@ -3,6 +3,8 @@ import '@quilted/quilt/globals';
3
3
  import {RequestRouter, JSONResponse} from '@quilted/quilt/request-router';
4
4
  import {BrowserAssets} from 'quilt:module/assets';
5
5
 
6
+ import type {AppContext} from '~/shared/context.ts';
7
+
6
8
  const router = new RequestRouter();
7
9
  const assets = new BrowserAssets();
8
10
 
@@ -29,18 +31,17 @@ router.get(async (request) => {
29
31
  import('@quilted/quilt/server'),
30
32
  ]);
31
33
 
32
- const response = await renderToResponse(
33
- <App
34
- context={{
35
- fetchGraphQL: performGraphQLOperation,
36
- graphQLCache: new GraphQLCache(),
37
- }}
38
- />,
39
- {
40
- request,
41
- assets,
34
+ const context = {
35
+ graphql: {
36
+ fetch: performGraphQLOperation,
37
+ cache: new GraphQLCache(),
42
38
  },
43
- );
39
+ } satisfies AppContext;
40
+
41
+ const response = await renderToResponse(<App context={context} />, {
42
+ request,
43
+ assets,
44
+ });
44
45
 
45
46
  return response;
46
47
  });
@@ -2,8 +2,10 @@ import type {GraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
2
2
 
3
3
  declare module '~/shared/context.ts' {
4
4
  interface AppContext {
5
- readonly fetchGraphQL: GraphQLFetch;
6
- readonly graphQLCache: GraphQLCache;
5
+ readonly graphql: {
6
+ readonly fetch: GraphQLFetch;
7
+ readonly cache: GraphQLCache;
8
+ };
7
9
  }
8
10
  }
9
11
 
@@ -1,6 +1,7 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
- import {Routing, useRoutes} from '@quilted/quilt/navigate';
3
+ import {NotFound} from '@quilted/quilt/server';
4
+ import {Navigation, route} from '@quilted/quilt/navigate';
4
5
  import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
5
6
 
6
7
  import {ReactQueryContext} from '@quilted/react-query';
@@ -8,7 +9,7 @@ import {ReactQueryContext} from '@quilted/react-query';
8
9
  import {HTML} from './foundation/html.ts';
9
10
  import {Frame} from './foundation/frame.ts';
10
11
 
11
- import {Start} from './features/start.ts';
12
+ import {Home} from './features/home.ts';
12
13
 
13
14
  import {trpc} from './shared/trpc.ts';
14
15
  import {
@@ -20,15 +21,30 @@ export interface AppProps {
20
21
  context: AppContextType;
21
22
  }
22
23
 
24
+ // Define the routes for your application. If you have a lot of routes, you
25
+ // might want to split this into a separate file.
26
+ const routes = [
27
+ route('*', {
28
+ render: (children) => <Frame>{children}</Frame>,
29
+ children: [
30
+ route('/', {
31
+ async load() {
32
+ await Promise.all([Home.load()]);
33
+ },
34
+ render: <Home />,
35
+ }),
36
+ route('*', {render: <NotFound />}),
37
+ ],
38
+ }),
39
+ ];
40
+
23
41
  // The root component for your application. You will typically render any
24
42
  // app-wide context in this component.
25
43
  export function App({context}: AppProps) {
26
44
  return (
27
45
  <AppContext context={context}>
28
46
  <HTML>
29
- <Frame>
30
- <Routes />
31
- </Frame>
47
+ <Navigation routes={routes} context={context} />
32
48
  </HTML>
33
49
  </AppContext>
34
50
  );
@@ -36,14 +52,6 @@ export function App({context}: AppProps) {
36
52
 
37
53
  export default App;
38
54
 
39
- // This component renders the routes for your application. If you have a lot
40
- // of routes, you may want to split this component into its own file.
41
- function Routes() {
42
- return useRoutes([
43
- {match: '/', render: <Start />, renderPreload: <Start.Preload />},
44
- ]);
45
- }
46
-
47
55
  // This component renders any app-wide context.
48
56
  function AppContext({children, context}: RenderableProps<AppProps>) {
49
57
  const locale = useLocaleFromEnvironment() ?? 'en';
@@ -51,16 +59,11 @@ function AppContext({children, context}: RenderableProps<AppProps>) {
51
59
  return (
52
60
  <AppContextReact.Provider value={context}>
53
61
  <Localization locale={locale}>
54
- <Routing>
55
- <trpc.Provider
56
- client={context.trpc}
57
- queryClient={context.queryClient}
58
- >
59
- <ReactQueryContext client={context.queryClient}>
60
- {children}
61
- </ReactQueryContext>
62
- </trpc.Provider>
63
- </Routing>
62
+ <trpc.Provider client={context.trpc} queryClient={context.queryClient}>
63
+ <ReactQueryContext client={context.queryClient}>
64
+ {children}
65
+ </ReactQueryContext>
66
+ </trpc.Provider>
64
67
  </Localization>
65
68
  </AppContextReact.Provider>
66
69
  );
@@ -1,3 +1,3 @@
1
- .Start {
1
+ .Home {
2
2
  font-weight: 900;
3
3
  }
@@ -0,0 +1,9 @@
1
+ import {trpc} from '~/shared/trpc.ts';
2
+
3
+ import styles from './Home.module.css';
4
+
5
+ export default function Home() {
6
+ const [data] = trpc.message.useSuspenseQuery('world');
7
+
8
+ return <div className={styles.Home}>{data}</div>;
9
+ }
@@ -0,0 +1,12 @@
1
+ import {describe, it, expect} from 'vitest';
2
+
3
+ import {renderApp} from '~/tests/render.ts';
4
+
5
+ import Home from '../Home.tsx';
6
+
7
+ describe('<Home />', () => {
8
+ it('includes a welcome message', async () => {
9
+ const home = await renderApp(<Home />);
10
+ expect(home).toContainPreactText('Hello world!');
11
+ });
12
+ });
@@ -0,0 +1,3 @@
1
+ import {AsyncComponent} from '@quilted/quilt/async';
2
+
3
+ export const Home = AsyncComponent.from(() => import('./home/Home.tsx'));
@@ -1,5 +0,0 @@
1
- import styles from './Start.module.css';
2
-
3
- export default function Start() {
4
- return <div className={styles.Start}>Hello world!</div>;
5
- }
@@ -1,12 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
-
3
- import {renderApp} from '~/tests/render.ts';
4
-
5
- import Start from '../Start.tsx';
6
-
7
- describe('<Start />', () => {
8
- it('includes a welcome message', async () => {
9
- const start = await renderApp(<Start />);
10
- expect(start).toContainPreactText('Hello world!');
11
- });
12
- });
@@ -1,3 +0,0 @@
1
- import {AsyncComponent} from '@quilted/quilt/async';
2
-
3
- export const Start = AsyncComponent.from(() => import('./start/Start.tsx'));
@@ -1,13 +0,0 @@
1
- import {useGraphQLQuery} from '@quilted/quilt/graphql';
2
-
3
- import styles from './Start.module.css';
4
- import startQuery from './StartQuery.graphql';
5
-
6
- export default function Start() {
7
- const query = useGraphQLQuery(startQuery);
8
-
9
- const me = query.result?.data?.me;
10
- const greeting = me ? `Hello ${me.name}!` : 'Hello!';
11
-
12
- return <div className={styles.Start}>{greeting}</div>;
13
- }
@@ -1,21 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
-
3
- import {renderApp} from '~/tests/render.ts';
4
- import {fillGraphQL, GraphQLController} from '~/tests/graphql.ts';
5
-
6
- import Start from '../Start.tsx';
7
- import startQuery from '../StartQuery.graphql';
8
-
9
- describe('<Start />', () => {
10
- it('welcomes the user with their name', async () => {
11
- const name = 'Winston';
12
- const graphql = new GraphQLController([
13
- fillGraphQL(startQuery, {me: {name}}),
14
- ]);
15
-
16
- const start = await renderApp(<Start />, {graphql});
17
-
18
- expect(graphql).toHavePerformedGraphQLQuery(startQuery);
19
- expect(start).toContainPreactText(`Hello ${name}!`);
20
- });
21
- });
@@ -1,3 +0,0 @@
1
- import {AsyncComponent} from '@quilted/quilt/async';
2
-
3
- export const Start = AsyncComponent.from(() => import('./start/Start.tsx'));
@@ -1,9 +0,0 @@
1
- import {trpc} from '~/shared/trpc.ts';
2
-
3
- import styles from './Start.module.css';
4
-
5
- export default function Start() {
6
- const [data] = trpc.message.useSuspenseQuery('world');
7
-
8
- return <div className={styles.Start}>{data}</div>;
9
- }
@@ -1,12 +0,0 @@
1
- import {describe, it, expect} from 'vitest';
2
-
3
- import {renderApp} from '~/tests/render.ts';
4
-
5
- import Start from '../Start.tsx';
6
-
7
- describe('<Start />', () => {
8
- it('includes a welcome message', async () => {
9
- const start = await renderApp(<Start />);
10
- expect(start).toContainPreactText('Hello world!');
11
- });
12
- });
@@ -1,5 +0,0 @@
1
- import {AsyncComponent} from '@quilted/quilt/async';
2
-
3
- export const Start = AsyncComponent.from(
4
- () => import('./start/Start/Start.tsx'),
5
- );