create-qwik 0.0.39-dev20220805031634 → 0.0.40

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 (25) hide show
  1. package/package.json +1 -1
  2. package/starters/apps/base/package.json +2 -2
  3. package/starters/apps/qwik-city/package.json +1 -1
  4. package/starters/apps/qwik-city/src/components/footer/footer.tsx +0 -3
  5. package/starters/apps/qwik-city/src/routes/{about-us.tsx → about-us/index.tsx} +0 -0
  6. package/starters/apps/qwik-city/src/routes/api/[org]/[user].json/index.ts +4 -10
  7. package/starters/apps/qwik-city/src/routes/api/{_layout-foo/api.css → api.css} +0 -0
  8. package/starters/apps/qwik-city/src/routes/api/data.json/index.ts +9 -0
  9. package/starters/apps/qwik-city/src/routes/api/{index@foo.tsx → index@api.tsx} +5 -10
  10. package/starters/apps/qwik-city/src/routes/api/{_layout-foo/index.tsx → layout-api.tsx} +5 -0
  11. package/starters/apps/qwik-city/src/routes/blog/{[...slug].tsx → [...slug]/index.tsx} +3 -3
  12. package/starters/apps/qwik-city/src/routes/blog/{_layout/index.tsx → layout.tsx} +0 -0
  13. package/starters/apps/qwik-city/src/routes/dashboard/dashboard.css +14 -0
  14. package/starters/apps/qwik-city/src/routes/dashboard/index.tsx +2 -4
  15. package/starters/apps/qwik-city/src/routes/dashboard/layout!.tsx +44 -0
  16. package/starters/apps/qwik-city/src/routes/dashboard/{profile@dashboard.tsx → profile/index.tsx} +5 -0
  17. package/starters/apps/qwik-city/src/routes/dashboard/settings/{index@dashboard.tsx → index.tsx} +5 -0
  18. package/starters/apps/qwik-city/src/routes/docs/{_layout!/index.css → docs.css} +0 -0
  19. package/starters/apps/qwik-city/src/routes/docs/{getting-started.md → getting-started/index.md} +0 -0
  20. package/starters/apps/qwik-city/src/routes/docs/{_layout!/index.tsx → layout!.tsx} +5 -5
  21. package/starters/apps/qwik-city/src/routes/docs/{_menu.md → menu.md} +1 -1
  22. package/starters/apps/qwik-city/src/routes/{_layout.tsx → layout.tsx} +0 -0
  23. package/starters/apps/qwik-city/src/routes/products/{[id].tsx → [id]/index.tsx} +24 -23
  24. package/starters/apps/qwik-city/src/routes/api/data.json.ts +0 -13
  25. package/starters/apps/qwik-city/src/routes/dashboard/_layout-dashboard.tsx +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-qwik",
3
- "version": "0.0.39-dev20220805031634",
3
+ "version": "0.0.40",
4
4
  "description": "Interactive CLI and API for generating Qwik projects.",
5
5
  "bin": "create-qwik",
6
6
  "main": "index.js",
@@ -15,12 +15,12 @@
15
15
  "typecheck": "tsc --incremental --noEmit"
16
16
  },
17
17
  "devDependencies": {
18
- "@builder.io/qwik": "0.0.39-dev20220805031634",
18
+ "@builder.io/qwik": "0.0.40",
19
19
  "@types/eslint": "8.4.5",
20
20
  "@types/node": "latest",
21
21
  "@typescript-eslint/eslint-plugin": "5.30.7",
22
22
  "@typescript-eslint/parser": "5.30.7",
23
- "eslint-plugin-qwik": "0.0.39-dev20220805031634",
23
+ "eslint-plugin-qwik": "0.0.40",
24
24
  "eslint": "8.20.0",
25
25
  "node-fetch": "3.2.9",
26
26
  "typescript": "4.7.4",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "type": "module",
16
16
  "devDependencies": {
17
- "@builder.io/qwik-city": "0.0.29",
17
+ "@builder.io/qwik-city": "0.0.30",
18
18
  "vite-tsconfig-paths": "3.5.0"
19
19
  }
20
20
  }
@@ -17,9 +17,6 @@ export default component$(
17
17
  <li>
18
18
  <a href="/about-us">About Us</a>
19
19
  </li>
20
- <li>
21
- <a href="/sign-in">Sign In</a>
22
- </li>
23
20
  <li>
24
21
  <a class="footer-home" href="/">
25
22
  Home
@@ -1,21 +1,15 @@
1
- import type { EndpointHandler } from '@builder.io/qwik-city';
2
- import os from 'os';
1
+ import type { RequestHandler } from '@builder.io/qwik-city';
3
2
 
4
- export const onGet: EndpointHandler = ({ request, params }) => {
3
+ export const onGet: RequestHandler = ({ request, params }) => {
5
4
  return {
6
5
  timestamp: Date.now(),
7
6
  method: request.method,
8
7
  url: request.url,
9
8
  params,
10
- os: os.platform(),
11
- arch: os.arch(),
12
- node: process.versions.node,
13
9
  };
14
10
  };
15
11
 
16
- export const onPost: EndpointHandler = async ({ request, response }) => {
12
+ export const onPost: RequestHandler = async ({ request, response }) => {
17
13
  response.headers.set('Content-Type', 'text/plain');
18
- return `Platform: ${os.platform()}, Node: ${process.versions.node}, HTTP Method: ${
19
- request.method
20
- }`;
14
+ return `HTTP Method: ${request.method}`;
21
15
  };
@@ -0,0 +1,9 @@
1
+ import type { RequestHandler } from '@builder.io/qwik-city';
2
+
3
+ export const onGet: RequestHandler = ({ request }) => {
4
+ return {
5
+ timestamp: Date.now(),
6
+ method: request.method,
7
+ url: request.url,
8
+ };
9
+ };
@@ -1,7 +1,11 @@
1
1
  import { component$, Host, useClientEffect$, useStore } from '@builder.io/qwik';
2
2
 
3
+ /**
4
+ * Uses named layout `foo`
5
+ */
6
+
3
7
  export default component$(() => {
4
- const store = useStore({ timestamp: '', os: '', arch: '', node: '' });
8
+ const store = useStore({ timestamp: '' });
5
9
 
6
10
  useClientEffect$(async () => {
7
11
  const url = `/api/builder.io/oss.json`;
@@ -9,9 +13,6 @@ export default component$(() => {
9
13
  const data: any = await rsp.json();
10
14
 
11
15
  store.timestamp = data.timestamp;
12
- store.os = data.os;
13
- store.arch = data.arch;
14
- store.node = data.node;
15
16
  });
16
17
 
17
18
  return (
@@ -28,12 +29,6 @@ export default component$(() => {
28
29
  </ul>
29
30
 
30
31
  <p>Timestamp: {store.timestamp}</p>
31
- <p>
32
- Node: <span>{store.node}</span>
33
- </p>
34
- <p>
35
- OS: <span>{store.os}</span>
36
- </p>
37
32
  </Host>
38
33
  );
39
34
  });
@@ -2,6 +2,11 @@ import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
2
  import type { DocumentHead } from '@builder.io/qwik-city';
3
3
  import styles from './api.css?inline';
4
4
 
5
+ /**
6
+ * Named layout `foo`
7
+ * Any index files named `index@foo.tsx` will use this layout
8
+ */
9
+
5
10
  export default component$(() => {
6
11
  useStyles$(styles);
7
12
 
@@ -1,5 +1,5 @@
1
1
  import { component$, Host, Resource } from '@builder.io/qwik';
2
- import { useEndpoint, DocumentHead, EndpointHandler } from '@builder.io/qwik-city';
2
+ import { useEndpoint, DocumentHead, RequestHandler } from '@builder.io/qwik-city';
3
3
 
4
4
  export default component$(() => {
5
5
  const resource = useEndpoint<typeof onGet>();
@@ -19,10 +19,10 @@ export default component$(() => {
19
19
  );
20
20
  });
21
21
 
22
- export const onGet: EndpointHandler<EndpointData> = async ({ params, request }) => {
22
+ export const onGet: RequestHandler<EndpointData> = async ({ params, url }) => {
23
23
  return {
24
24
  blogTitle: `Blog: ${params.slug}`,
25
- blogContent: `${params.slug}, ${request.url}`,
25
+ blogContent: `${params.slug}, ${url.pathname}`,
26
26
  };
27
27
  };
28
28
 
@@ -0,0 +1,14 @@
1
+ .dashboard {
2
+ display: grid;
3
+ grid-template-columns: 200px 1fr;
4
+ padding: 0;
5
+ }
6
+
7
+ .dashboard-menu {
8
+ background: #eee;
9
+ padding-left: 20px;
10
+ }
11
+
12
+ .dashboard-content {
13
+ padding-left: 20px;
14
+ }
@@ -5,13 +5,11 @@ export default component$(() => {
5
5
  return (
6
6
  <Host>
7
7
  <h1>Dashboard</h1>
8
- <p>
9
- <a href="/sign-out">Sign Out</a>
10
- </p>
8
+ <p>Welcome to the dashboard.</p>
11
9
  </Host>
12
10
  );
13
11
  });
14
12
 
15
13
  export const head: DocumentHead = {
16
- title: 'Dashboard',
14
+ title: 'Home',
17
15
  };
@@ -0,0 +1,44 @@
1
+ import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
+ import Footer from '../../components/footer/footer';
4
+ import Header from '../../components/header/header';
5
+ import styles from './dashboard.css?inline';
6
+
7
+ /**
8
+ * `layout!` means this is the top level layout. Because of the
9
+ * `!` at the end of the filename, it stops at this layout and does
10
+ * not keep crawling up the directories making more nested layouts.
11
+ */
12
+
13
+ export default component$(() => {
14
+ useStyles$(styles);
15
+
16
+ return (
17
+ <Host>
18
+ <Header />
19
+ <main class="dashboard">
20
+ <aside class="dashboard-menu">
21
+ <h5>Dashboard Menu</h5>
22
+ <ul>
23
+ <li>
24
+ <a href="/dashboard/profile">Profile</a>
25
+ </li>
26
+ <li>
27
+ <a href="/dashboard/settings">Settings</a>
28
+ </li>
29
+ </ul>
30
+ </aside>
31
+ <section class="dashboard-content">
32
+ <Slot />
33
+ </section>
34
+ </main>
35
+ <Footer />
36
+ </Host>
37
+ );
38
+ });
39
+
40
+ export const head: DocumentHead = ({ head }) => {
41
+ return {
42
+ title: `Dashboard ${head.title}`,
43
+ };
44
+ };
@@ -1,4 +1,5 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
2
3
 
3
4
  export default component$(() => {
4
5
  return (
@@ -8,3 +9,7 @@ export default component$(() => {
8
9
  </Host>
9
10
  );
10
11
  });
12
+
13
+ export const head: DocumentHead = {
14
+ title: 'Profile',
15
+ };
@@ -1,4 +1,5 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
2
3
 
3
4
  export default component$(() => {
4
5
  return (
@@ -8,3 +9,7 @@ export default component$(() => {
8
9
  </Host>
9
10
  );
10
11
  });
12
+
13
+ export const head: DocumentHead = {
14
+ title: 'Settings',
15
+ };
@@ -1,10 +1,10 @@
1
1
  import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
2
  import type { DocumentHead } from '@builder.io/qwik-city';
3
- import { Breadcrumbs } from '../../../components/breadcrumbs/breadcrumbs';
4
- import Footer from '../../../components/footer/footer';
5
- import Header from '../../../components/header/header';
6
- import { Menu } from '../../../components/menu/menu';
7
- import styles from './index.css?inline';
3
+ import { Breadcrumbs } from '../../components/breadcrumbs/breadcrumbs';
4
+ import Footer from '../../components/footer/footer';
5
+ import Header from '../../components/header/header';
6
+ import { Menu } from '../../components/menu/menu';
7
+ import styles from './docs.css?inline';
8
8
 
9
9
  export default component$(() => {
10
10
  useStyles$(styles);
@@ -3,7 +3,7 @@
3
3
  ## Introduction
4
4
 
5
5
  - [Overview](overview/index.md)
6
- - [Getting Started](getting-started.md)
6
+ - [Getting Started](getting-started/index.md)
7
7
 
8
8
  ## Components
9
9
 
@@ -1,6 +1,5 @@
1
1
  import { Resource, component$, Host } from '@builder.io/qwik';
2
- import { useEndpoint, useLocation, EndpointHandler, DocumentHead } from '@builder.io/qwik-city';
3
- import os from 'os';
2
+ import { useEndpoint, useLocation, RequestHandler, DocumentHead } from '@builder.io/qwik-city';
4
3
 
5
4
  export default component$(() => {
6
5
  const { params } = useLocation();
@@ -49,13 +48,18 @@ export default component$(() => {
49
48
  );
50
49
  });
51
50
 
52
- export const head: DocumentHead<ProductData> = ({ data }) => {
51
+ export const head: DocumentHead<EndpointData> = ({ data }) => {
52
+ if (!data) {
53
+ return {
54
+ title: `Product not found`,
55
+ };
56
+ }
53
57
  return {
54
58
  title: `Product ${data.productId}, ${data.price}`,
55
59
  };
56
60
  };
57
61
 
58
- export const onGet: EndpointHandler<EndpointData> = async ({ params, response }) => {
62
+ export const onGet: RequestHandler<EndpointData> = async ({ params, response }) => {
59
63
  // Serverside Endpoint
60
64
  // During SSR, this method is called directly on the server and returns the data object
61
65
  // On the client, this same data can be requested with fetch() at the same URL, but also
@@ -63,18 +67,16 @@ export const onGet: EndpointHandler<EndpointData> = async ({ params, response })
63
67
 
64
68
  if (params.id === 'shirt') {
65
69
  // Redirect, which will skip any rendering and the server will immediately redirect
66
- response.redirect('/products/tshirt');
67
- return;
70
+ throw response.redirect('/products/tshirt');
68
71
  }
69
72
 
70
73
  // artificially slow database call
71
74
  const productData = await loadProduct(params.id);
72
-
73
75
  if (!productData) {
74
- // Product data not found
75
- // but the data is still given to the renderer to decide what to do
76
+ // Product data not found, but the data is still
77
+ // given to the renderer to decide how to render
76
78
  response.status = 404;
77
- return;
79
+ return productData;
78
80
  }
79
81
 
80
82
  // Found the product data
@@ -89,19 +91,18 @@ const loadProduct = (productId: string) => {
89
91
  return new Promise<ProductData | null>((resolve) =>
90
92
  setTimeout(() => {
91
93
  const productPrice = PRODUCT_DB[productId];
92
- if (!productPrice) {
93
- return null;
94
+ if (productPrice) {
95
+ // awesome product database found product data
96
+ const productData: ProductData = {
97
+ productId,
98
+ price: productPrice,
99
+ description: `Product description here.`,
100
+ };
101
+ resolve(productData);
102
+ } else {
103
+ // awesome product database did not find product data
104
+ resolve(null);
94
105
  }
95
-
96
- const productData: ProductData = {
97
- productId,
98
- price: productPrice,
99
- description: `Node ${process.versions.node} ${os.platform()} ${os.arch()} ${
100
- os.cpus()[0].model
101
- }`,
102
- };
103
-
104
- resolve(productData);
105
106
  }, 250)
106
107
  );
107
108
  };
@@ -113,7 +114,7 @@ const PRODUCT_DB: Record<string, string> = {
113
114
  tshirt: '$18.96',
114
115
  };
115
116
 
116
- type EndpointData = ProductData;
117
+ type EndpointData = ProductData | null;
117
118
 
118
119
  interface ProductData {
119
120
  productId: string;
@@ -1,13 +0,0 @@
1
- import type { EndpointHandler } from '@builder.io/qwik-city';
2
- import os from 'os';
3
-
4
- export const onGet: EndpointHandler = ({ request }) => {
5
- return {
6
- timestamp: Date.now(),
7
- method: request.method,
8
- url: request.url,
9
- os: os.platform(),
10
- arch: os.arch(),
11
- node: process.versions.node,
12
- };
13
- };
@@ -1,18 +0,0 @@
1
- import { component$, Host, Slot } from '@builder.io/qwik';
2
- import Footer from '../../components/footer/footer';
3
- import Header from '../../components/header/header';
4
-
5
- export default component$(() => {
6
- return (
7
- <Host>
8
- <Header />
9
- <main class="dashboard">
10
- <aside class="dashboard-menu">Dashboard Menu</aside>
11
- <section class="dashboard-content">
12
- <Slot />
13
- </section>
14
- </main>
15
- <Footer />
16
- </Host>
17
- );
18
- });