create-shiftapi 0.0.4 → 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/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/fcjr/shiftapi/main/assets/logo-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/fcjr/shiftapi/main/assets/logo.svg" alt="ShiftAPI Logo">
|
|
5
|
+
</picture>
|
|
3
6
|
</p>
|
|
4
7
|
|
|
5
8
|
# create-shiftapi
|
package/dist/index.js
CHANGED
|
@@ -78,12 +78,12 @@ function getGitHubUser() {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
async function main() {
|
|
81
|
-
const
|
|
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
|
-
|
|
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.
|
|
101
|
-
defaultValue: `./${results.
|
|
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.
|
|
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,42 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
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 [
|
|
5
|
+
const [message, setMessage] = useState("");
|
|
6
|
+
const health = $api.useQuery("get", "/health");
|
|
7
|
+
const echo = $api.useMutation("post", "/echo");
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
}
|
|
@@ -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
|
-
<
|
|
10
|
+
<QueryClientProvider client={queryClient}>
|
|
11
|
+
<App />
|
|
12
|
+
</QueryClientProvider>
|
|
8
13
|
</StrictMode>,
|
|
9
14
|
);
|