create-skybridge 0.0.0-dev.f561bc3 → 0.0.0-dev.ff23e30
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 +71 -6
- package/dist/index.test.js +1 -5
- package/package.json +1 -1
- package/template/server/package.json +0 -2
- package/template/server/src/index.ts +4 -3
- package/template/server/src/server.ts +0 -13
- package/template/web/src/widgets/magic-8-ball.tsx +3 -1
- package/template/server/src/env.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import * as prompts from "@clack/prompts";
|
|
5
6
|
import mri from "mri";
|
|
7
|
+
const minimumPnpmVersion = 10;
|
|
6
8
|
const defaultProjectName = "skybridge-project";
|
|
7
9
|
// prettier-ignore
|
|
8
10
|
const helpMessage = `\
|
|
@@ -13,20 +15,22 @@ Create a new Skybridge project by copying the starter template.
|
|
|
13
15
|
Options:
|
|
14
16
|
-h, --help show this help message
|
|
15
17
|
--overwrite remove existing files in target directory
|
|
18
|
+
--immediate install dependencies and start development server
|
|
16
19
|
|
|
17
20
|
Examples:
|
|
18
21
|
create-skybridge my-app
|
|
19
|
-
create-skybridge . --overwrite
|
|
22
|
+
create-skybridge . --overwrite --immediate
|
|
20
23
|
`;
|
|
21
24
|
export async function init(args = process.argv.slice(2)) {
|
|
22
25
|
const argv = mri(args, {
|
|
23
|
-
boolean: ["help", "overwrite"],
|
|
26
|
+
boolean: ["help", "overwrite", "immediate"],
|
|
24
27
|
alias: { h: "help" },
|
|
25
28
|
});
|
|
26
29
|
const argTargetDir = argv._[0]
|
|
27
30
|
? sanitizeTargetDir(String(argv._[0]))
|
|
28
31
|
: undefined;
|
|
29
32
|
const argOverwrite = argv.overwrite;
|
|
33
|
+
const argImmediate = argv.immediate;
|
|
30
34
|
const help = argv.help;
|
|
31
35
|
if (help) {
|
|
32
36
|
console.log(helpMessage);
|
|
@@ -48,8 +52,9 @@ export async function init(args = process.argv.slice(2)) {
|
|
|
48
52
|
: "Invalid project name";
|
|
49
53
|
},
|
|
50
54
|
});
|
|
51
|
-
if (prompts.isCancel(projectName))
|
|
55
|
+
if (prompts.isCancel(projectName)) {
|
|
52
56
|
return cancel();
|
|
57
|
+
}
|
|
53
58
|
targetDir = sanitizeTargetDir(projectName);
|
|
54
59
|
}
|
|
55
60
|
else {
|
|
@@ -77,8 +82,9 @@ export async function init(args = process.argv.slice(2)) {
|
|
|
77
82
|
},
|
|
78
83
|
],
|
|
79
84
|
});
|
|
80
|
-
if (prompts.isCancel(res))
|
|
85
|
+
if (prompts.isCancel(res)) {
|
|
81
86
|
return cancel();
|
|
87
|
+
}
|
|
82
88
|
overwrite = res;
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
@@ -102,7 +108,7 @@ export async function init(args = process.argv.slice(2)) {
|
|
|
102
108
|
// Copy template to target directory
|
|
103
109
|
fs.cpSync(templateDir, root, {
|
|
104
110
|
recursive: true,
|
|
105
|
-
filter: (src) => src
|
|
111
|
+
filter: (src) => !src.endsWith(".npmrc"),
|
|
106
112
|
});
|
|
107
113
|
// Rename _gitignore to .gitignore
|
|
108
114
|
fs.renameSync(path.join(root, "_gitignore"), path.join(root, ".gitignore"));
|
|
@@ -115,13 +121,72 @@ export async function init(args = process.argv.slice(2)) {
|
|
|
115
121
|
fs.writeFileSync(pkgPath, fixed);
|
|
116
122
|
}
|
|
117
123
|
prompts.log.success(`Project created in ${root}`);
|
|
118
|
-
prompts.outro(`Done! Next steps:\n\n cd ${targetDir}\n pnpm install\n pnpm dev`);
|
|
119
124
|
}
|
|
120
125
|
catch (error) {
|
|
121
126
|
prompts.log.error("Failed to copy repository");
|
|
122
127
|
console.error(error);
|
|
123
128
|
process.exit(1);
|
|
124
129
|
}
|
|
130
|
+
// 4. Ask about immediate installation
|
|
131
|
+
let immediate = argImmediate;
|
|
132
|
+
if (immediate === undefined) {
|
|
133
|
+
if (interactive) {
|
|
134
|
+
const immediateResult = await prompts.confirm({
|
|
135
|
+
message: `Install with pnpm and start now?`,
|
|
136
|
+
});
|
|
137
|
+
if (prompts.isCancel(immediateResult)) {
|
|
138
|
+
return cancel();
|
|
139
|
+
}
|
|
140
|
+
immediate = immediateResult;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
immediate = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const installCmd = ["pnpm", "install"];
|
|
147
|
+
const runCmd = ["pnpm", "dev"];
|
|
148
|
+
if (!immediate) {
|
|
149
|
+
prompts.outro(`Done! Next steps:
|
|
150
|
+
cd ${targetDir}
|
|
151
|
+
${installCmd.join(" ")}
|
|
152
|
+
${runCmd.join(" ")}
|
|
153
|
+
`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// check if pnpm is installed
|
|
157
|
+
const result = spawnSync("pnpm", ["--version"], { encoding: "utf-8" });
|
|
158
|
+
if (result.error || result.status !== 0) {
|
|
159
|
+
console.error("Error: pnpm is not installed. Please install pnpm first.");
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
// check if pnpm major is greater or equal to the one set in package.json packageManager, which should do the trick
|
|
163
|
+
const version = result.stdout.trim();
|
|
164
|
+
const major = Number(version.split(".")[0]);
|
|
165
|
+
if (Number.isNaN(major) || major < minimumPnpmVersion) {
|
|
166
|
+
console.error(`Error: pnpm version ${version} is too old. Minimum required version is ${minimumPnpmVersion}.`);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
prompts.log.step(`Installing dependencies with pnpm...`);
|
|
170
|
+
run(installCmd, {
|
|
171
|
+
stdio: "inherit",
|
|
172
|
+
cwd: root,
|
|
173
|
+
});
|
|
174
|
+
prompts.log.step("Starting dev server...");
|
|
175
|
+
run(runCmd, {
|
|
176
|
+
stdio: "inherit",
|
|
177
|
+
cwd: root,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function run([command, ...args], options) {
|
|
181
|
+
const { status, error } = spawnSync(command, args, options);
|
|
182
|
+
if (status != null && status > 0) {
|
|
183
|
+
process.exit(status);
|
|
184
|
+
}
|
|
185
|
+
if (error) {
|
|
186
|
+
console.error(`\n${command} ${args.join(" ")} error!`);
|
|
187
|
+
console.error(error);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
125
190
|
}
|
|
126
191
|
function sanitizeTargetDir(targetDir) {
|
|
127
192
|
return (targetDir
|
package/dist/index.test.js
CHANGED
|
@@ -18,10 +18,6 @@ describe("create-skybridge", () => {
|
|
|
18
18
|
const name = `../../${tempDirName}//project$`;
|
|
19
19
|
await init([name]);
|
|
20
20
|
await fs.access(path.join(process.cwd(), tempDirName, "project", ".gitignore"));
|
|
21
|
-
|
|
22
|
-
await fs.access(path.join(process.cwd(), tempDirName, "project", ".npmrc"));
|
|
23
|
-
expect.fail(".npmrc should not be copied");
|
|
24
|
-
}
|
|
25
|
-
catch { }
|
|
21
|
+
expect(fs.access(path.join(process.cwd(), tempDirName, "project", ".npmrc"))).rejects.toThrowError();
|
|
26
22
|
});
|
|
27
23
|
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,6 @@ import express, { type Express } from "express";
|
|
|
2
2
|
|
|
3
3
|
import { widgetsDevServer } from "skybridge/server";
|
|
4
4
|
import type { ViteDevServer } from "vite";
|
|
5
|
-
import { env } from "./env.js";
|
|
6
5
|
import { mcp } from "./middleware.js";
|
|
7
6
|
import server from "./server.js";
|
|
8
7
|
|
|
@@ -12,7 +11,9 @@ app.use(express.json());
|
|
|
12
11
|
|
|
13
12
|
app.use(mcp(server));
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
const env = process.env.NODE_ENV || "development";
|
|
15
|
+
|
|
16
|
+
if (env !== "production") {
|
|
16
17
|
app.use(await widgetsDevServer());
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -22,7 +23,7 @@ app.listen(3000, (error) => {
|
|
|
22
23
|
process.exit(1);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
console.log(`Server listening on port 3000 - ${env
|
|
26
|
+
console.log(`Server listening on port 3000 - ${env}`);
|
|
26
27
|
console.log(
|
|
27
28
|
"Make your local server accessible with 'ngrok http 3000' and connect to ChatGPT with URL https://xxxxxx.ngrok-free.app/mcp",
|
|
28
29
|
);
|
|
@@ -49,20 +49,7 @@ const server = new McpServer(
|
|
|
49
49
|
.reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
|
50
50
|
const answer = Answers[hash % Answers.length];
|
|
51
51
|
return {
|
|
52
|
-
/**
|
|
53
|
-
* Arbitrary JSON passed only to the component.
|
|
54
|
-
* Use it for data that should not influence the model’s reasoning, like the full set of locations that backs a dropdown.
|
|
55
|
-
* _meta is never shown to the model.
|
|
56
|
-
*/
|
|
57
|
-
_meta: {},
|
|
58
|
-
/**
|
|
59
|
-
* Structured data that is used to hydrate your component.
|
|
60
|
-
* ChatGPT injects this object into your iframe as window.openai.toolOutput
|
|
61
|
-
*/
|
|
62
52
|
structuredContent: { answer },
|
|
63
|
-
/**
|
|
64
|
-
* Optional free-form text that the model receives verbatim
|
|
65
|
-
*/
|
|
66
53
|
content: [],
|
|
67
54
|
isError: false,
|
|
68
55
|
};
|
|
@@ -5,7 +5,9 @@ import { useToolInfo } from "../helpers";
|
|
|
5
5
|
|
|
6
6
|
function Magic8Ball() {
|
|
7
7
|
const { input, output } = useToolInfo<"magic-8-ball">();
|
|
8
|
-
if (!output)
|
|
8
|
+
if (!output) {
|
|
9
|
+
return <div>Shaking...</div>;
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
return (
|
|
11
13
|
<div className="container">
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
2
|
-
|
|
3
|
-
import { createEnv } from "@t3-oss/env-core";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
|
|
6
|
-
export const env = createEnv({
|
|
7
|
-
server: {
|
|
8
|
-
NODE_ENV: z.enum(["development", "production"]).default("development"),
|
|
9
|
-
},
|
|
10
|
-
runtimeEnv: process.env,
|
|
11
|
-
emptyStringAsUndefined: true,
|
|
12
|
-
});
|