create-shiftapi 0.0.5 → 0.0.6

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/index.js CHANGED
@@ -78,12 +78,12 @@ function getGitHubUser() {
78
78
  }
79
79
  }
80
80
  async function main() {
81
- const positionalName = process.argv[2];
81
+ const positionalArg = process.argv[2];
82
82
  const ghUser = getGitHubUser();
83
83
  p.intro("create-shiftapi");
84
84
  const project = await p.group(
85
85
  {
86
- name: () => positionalName ? Promise.resolve(positionalName) : p.text({
86
+ rawName: () => positionalArg ? Promise.resolve(positionalArg) : p.text({
87
87
  message: "Project name",
88
88
  placeholder: "my-app",
89
89
  defaultValue: "my-app"
@@ -97,14 +97,18 @@ async function main() {
97
97
  }),
98
98
  directory: ({ results }) => p.text({
99
99
  message: "Directory",
100
- placeholder: `./${results.name}`,
101
- defaultValue: `./${results.name}`
102
- }),
103
- module: ({ results }) => p.text({
104
- message: "Go module path",
105
- placeholder: ghUser ? `github.com/${ghUser}/${results.name}` : results.name,
106
- defaultValue: ghUser ? `github.com/${ghUser}/${results.name}` : results.name
100
+ placeholder: `./${results.rawName}`,
101
+ defaultValue: `./${results.rawName}`
107
102
  }),
103
+ module: ({ results }) => {
104
+ const name = path2.basename(results.rawName);
105
+ const defaultModule = ghUser ? `github.com/${ghUser}/${name}` : name;
106
+ return p.text({
107
+ message: "Go module path",
108
+ placeholder: defaultModule,
109
+ defaultValue: defaultModule
110
+ });
111
+ },
108
112
  port: () => p.text({
109
113
  message: "Server port",
110
114
  placeholder: "8080",
@@ -126,7 +130,7 @@ async function main() {
126
130
  const s = p.spinner();
127
131
  s.start("Scaffolding project");
128
132
  await scaffold({
129
- name: project.name,
133
+ name: path2.basename(project.rawName),
130
134
  modulePath: project.module,
131
135
  port: project.port,
132
136
  framework: project.framework,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-shiftapi",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Scaffold a new ShiftAPI fullstack app",
5
5
  "author": "Frank Chiarulli Jr. <frank@frankchiarulli.com>",
6
6
  "license": "MIT",
@@ -8,6 +8,8 @@
8
8
  "typecheck": "tsc --noEmit"
9
9
  },
10
10
  "dependencies": {
11
+ "@tanstack/react-query": "^5.0.0",
12
+ "openapi-react-query": "^0.2.0",
11
13
  "react": "^19.0.0",
12
14
  "react-dom": "^19.0.0"
13
15
  },
@@ -1,42 +1,27 @@
1
- import { useEffect, useState } from "react";
2
- import type { FormEvent } from "react";
3
- import { client } from "@shiftapi/client";
1
+ import { useState } from "react";
2
+ import { $api } from "./api";
4
3
 
5
4
  export default function App() {
6
- const [output, setOutput] = useState("");
5
+ const [message, setMessage] = useState("");
6
+ const health = $api.useQuery("get", "/health");
7
+ const echo = $api.useMutation("post", "/echo");
7
8
 
8
- useEffect(() => {
9
- client.GET("/health").then(({ error }) => {
10
- if (error) {
11
- setOutput(`Health check failed: ${error.message}`);
12
- } else {
13
- setOutput("Health check passed. Try sending a message.");
14
- }
15
- });
16
- }, []);
17
-
18
- async function handleSubmit(e: FormEvent<HTMLFormElement>) {
19
- e.preventDefault();
20
- const formData = new FormData(e.currentTarget);
21
- const message = (formData.get("message") as string).trim();
22
- if (!message) return;
23
- setOutput("Loading...");
24
- const { data, error } = await client.POST("/echo", { body: { message } });
25
- if (error) {
26
- setOutput(`Error: ${error.message}`);
27
- } else {
28
- setOutput(`Echo: ${data.message}`);
29
- }
30
- }
9
+ if (health.isLoading) return <p>Loading...</p>;
10
+ if (health.error) return <p>Health check failed: {health.error.message}</p>;
31
11
 
32
12
  return (
33
13
  <div>
34
14
  <h1>{{name}}</h1>
35
- <form onSubmit={handleSubmit}>
36
- <input type="text" name="message" placeholder="Enter a message" />
37
- <button type="submit">Send</button>
38
- </form>
39
- <pre>{output}</pre>
15
+ <input
16
+ type="text"
17
+ value={message}
18
+ onChange={(e) => setMessage(e.target.value)}
19
+ placeholder="Enter a message"
20
+ />
21
+ <button onClick={() => echo.mutate({ body: { message } })}>Send</button>
22
+ {echo.isPending && <p>Loading...</p>}
23
+ {echo.error && <p>Error: {echo.error.message}</p>}
24
+ {echo.data && <pre>Echo: {echo.data.message}</pre>}
40
25
  </div>
41
26
  );
42
27
  }
@@ -0,0 +1,4 @@
1
+ import createClient from "openapi-react-query";
2
+ import { client } from "@shiftapi/client";
3
+
4
+ export const $api = createClient(client);
@@ -1,9 +1,14 @@
1
1
  import { StrictMode } from "react";
2
2
  import { createRoot } from "react-dom/client";
3
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
4
  import App from "./App";
4
5
 
6
+ const queryClient = new QueryClient();
7
+
5
8
  createRoot(document.getElementById("root")!).render(
6
9
  <StrictMode>
7
- <App />
10
+ <QueryClientProvider client={queryClient}>
11
+ <App />
12
+ </QueryClientProvider>
8
13
  </StrictMode>,
9
14
  );