create-skybridge 0.36.3 → 1.0.2
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 +315 -214
- package/package.json +4 -3
- package/templates/blank/README.md +92 -0
- package/templates/blank/package.json +28 -0
- package/templates/blank/src/server.ts +21 -0
- package/templates/blank/tsconfig.json +5 -0
- package/templates/blank/vite.config.ts +6 -0
- package/templates/demo/.dockerignore +4 -0
- package/templates/demo/AGENTS.md +1 -0
- package/templates/demo/Dockerfile +53 -0
- package/{template → templates/demo}/README.md +16 -15
- package/templates/demo/_gitignore +6 -0
- package/templates/demo/alpic.json +3 -0
- package/templates/demo/node_modules/.bin/alpic +21 -0
- package/templates/demo/node_modules/.bin/sb +21 -0
- package/templates/demo/node_modules/.bin/skybridge +21 -0
- package/templates/demo/node_modules/.bin/tsc +21 -0
- package/templates/demo/node_modules/.bin/tsserver +21 -0
- package/templates/demo/node_modules/.bin/vite +21 -0
- package/{template → templates/demo}/package.json +2 -2
- package/templates/demo/src/helpers.ts +4 -0
- package/{template → templates/demo}/src/views/onboarding.tsx +1 -1
- package/templates/demo/src/vite-manifest.d.ts +4 -0
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -35
- /package/{template → templates/blank}/.dockerignore +0 -0
- /package/{template → templates/blank}/AGENTS.md +0 -0
- /package/{template → templates/blank}/Dockerfile +0 -0
- /package/{template → templates/blank}/_gitignore +0 -0
- /package/{template → templates/blank}/alpic.json +0 -0
- /package/{template → templates/blank}/node_modules/.bin/alpic +0 -0
- /package/{template → templates/blank}/node_modules/.bin/sb +0 -0
- /package/{template → templates/blank}/node_modules/.bin/skybridge +0 -0
- /package/{template → templates/blank}/node_modules/.bin/tsc +0 -0
- /package/{template → templates/blank}/node_modules/.bin/tsserver +0 -0
- /package/{template → templates/blank}/node_modules/.bin/vite +0 -0
- /package/{template → templates/blank}/src/helpers.ts +0 -0
- /package/{template → templates/blank}/src/vite-manifest.d.ts +0 -0
- /package/{template → templates/demo}/node_modules/.bin/tsx +0 -0
- /package/{template → templates/demo}/src/index.css +0 -0
- /package/{template → templates/demo}/src/server.ts +0 -0
- /package/{template → templates/demo}/src/views/components/doc-link.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/doc.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/nav.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/progress.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/steps/outro.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/steps/state.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/steps/tool-call.tsx +0 -0
- /package/{template → templates/demo}/src/views/components/steps/tool-output.tsx +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/beret.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/chapka.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/cowboy-hat.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/fez.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/jester-hat.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/mitre.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/non-la.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/original.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/propeller-beanie.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/ski-mask.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/sombrero.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/top-hat.png +0 -0
- /package/{template → templates/demo}/src/views/images/mascot/viking-helmet.png +0 -0
- /package/{template → templates/demo}/src/views/use-mascot.ts +0 -0
- /package/{template → templates/demo}/tsconfig.json +0 -0
- /package/{template → templates/demo}/vite.config.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,256 +1,371 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
import * as prompts from "@clack/prompts";
|
|
6
|
-
import
|
|
5
|
+
import spawn from "cross-spawn";
|
|
7
6
|
import mri from "mri";
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
7
|
+
const OUTPUT_TAIL_LINES = 10;
|
|
8
|
+
const DEFAULT_PROJECT_NAME = "skybridge-project";
|
|
9
|
+
const PACKAGE_MANAGERS = ["bun", "deno", "npm", "pnpm", "yarn"];
|
|
10
|
+
const TEMPLATES = ["demo", "blank"];
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf-8"));
|
|
12
|
+
const version = pkg.version;
|
|
13
|
+
const HELP_MESSAGE = `Usage: skybridge create [path] [options]
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
⛰ Skybridge v${version} - the fullstack framework for building MCP Apps
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
--repo <uri> use a git repository instead of the built-in template
|
|
18
|
-
--overwrite remove existing files in target directory
|
|
19
|
-
--immediate install dependencies and start development server
|
|
17
|
+
Arguments:
|
|
18
|
+
path Where the project will be created. Prompted when omitted.
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
Options:
|
|
21
|
+
--blank scaffold a minimal project without demo tools and views
|
|
22
|
+
--overwrite remove existing files if target directory is not empty
|
|
23
|
+
--pm <choice> package manager to use (choices: ${PACKAGE_MANAGERS.join(", ")}. default to npm when none is provided or infered)
|
|
24
|
+
--skip-skills skip installing coding agent skills
|
|
25
|
+
--start start dev server
|
|
26
|
+
--yes skip prompts and use default values for unprovided options
|
|
27
|
+
--help display this help message
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
Non-interactive usage:
|
|
30
|
+
Mandatory: path argument and --yes option
|
|
31
|
+
Example: skybridge create my-app --yes`;
|
|
32
|
+
const isTTY = process.stdout.isTTY;
|
|
33
|
+
const _spinner = prompts.spinner();
|
|
34
|
+
const Spinner = {
|
|
35
|
+
start(msg) {
|
|
36
|
+
if (!isTTY) {
|
|
37
|
+
prompts.log.info(msg);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
_spinner.clear();
|
|
41
|
+
_spinner.start(msg);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
stop(msg) {
|
|
45
|
+
if (!isTTY) {
|
|
46
|
+
prompts.log.success(msg);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
_spinner.stop(msg);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
error(msg) {
|
|
53
|
+
if (!isTTY) {
|
|
54
|
+
prompts.log.error(msg);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
_spinner.error(msg);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
31
61
|
export async function init(args = process.argv.slice(2)) {
|
|
32
62
|
const argv = mri(args, {
|
|
33
|
-
boolean: ["help", "overwrite", "
|
|
34
|
-
string: ["
|
|
63
|
+
boolean: ["help", "blank", "overwrite", "skip-skills", "start", "yes"],
|
|
64
|
+
string: ["pm"],
|
|
35
65
|
alias: { h: "help" },
|
|
36
66
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
: undefined;
|
|
40
|
-
const argRepo = argv.repo;
|
|
41
|
-
const argOverwrite = argv.overwrite;
|
|
42
|
-
const argImmediate = argv.immediate;
|
|
43
|
-
const help = argv.help;
|
|
44
|
-
if (help) {
|
|
45
|
-
console.log(helpMessage);
|
|
67
|
+
if (argv.help) {
|
|
68
|
+
console.log(HELP_MESSAGE);
|
|
46
69
|
return;
|
|
47
70
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
const { yes } = argv;
|
|
72
|
+
let targetDir = argv._[0] ? sanitizeTargetDir(String(argv._[0])) : undefined;
|
|
73
|
+
if (yes && !targetDir) {
|
|
74
|
+
abort("The target directory is required in non-interactive mode.", "Example: skybridge create my-app --yes");
|
|
75
|
+
}
|
|
76
|
+
let pm = parsePackageManager(argv.pm || "");
|
|
77
|
+
if (argv.pm && !pm) {
|
|
78
|
+
abort(`Invalid --pm value "${argv.pm}". Expected one of: ${PACKAGE_MANAGERS.join(", ")}.`);
|
|
79
|
+
}
|
|
80
|
+
console.log(); // cosmetic line break
|
|
81
|
+
prompts.intro(`\x1b[1;36m⛰ Welcome to Skybridge v${version} \x1b[22m- the fullstack framework for building MCP Apps\x1b[0m`);
|
|
82
|
+
// 1. Target directory
|
|
52
83
|
if (!targetDir) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
if (prompts.isCancel(projectName)) {
|
|
65
|
-
return cancel();
|
|
66
|
-
}
|
|
67
|
-
targetDir = sanitizeTargetDir(projectName);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
targetDir = defaultProjectName;
|
|
84
|
+
const choice = await prompts.text({
|
|
85
|
+
message: "Project directory:",
|
|
86
|
+
placeholder: DEFAULT_PROJECT_NAME,
|
|
87
|
+
defaultValue: DEFAULT_PROJECT_NAME,
|
|
88
|
+
validate: (value) => !value || sanitizeTargetDir(value).length > 0
|
|
89
|
+
? undefined
|
|
90
|
+
: "Invalid project name",
|
|
91
|
+
});
|
|
92
|
+
if (prompts.isCancel(choice)) {
|
|
93
|
+
return cancel();
|
|
71
94
|
}
|
|
95
|
+
targetDir = sanitizeTargetDir(choice);
|
|
72
96
|
}
|
|
73
|
-
// 2.
|
|
97
|
+
// 2. Existing-directory handling
|
|
74
98
|
if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
label: "Remove existing files and continue",
|
|
90
|
-
value: "yes",
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
if (prompts.isCancel(res)) {
|
|
95
|
-
return cancel();
|
|
96
|
-
}
|
|
97
|
-
overwrite = res;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
overwrite = "no";
|
|
99
|
+
if (argv.overwrite) {
|
|
100
|
+
emptyDir(targetDir);
|
|
101
|
+
}
|
|
102
|
+
else if (yes) {
|
|
103
|
+
prompts.log.error(`Target directory "${targetDir}" is not empty. Use --overwrite to remove existing files.`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const ok = await prompts.confirm({
|
|
108
|
+
message: `Target directory "${targetDir}" is not empty. Remove existing files?`,
|
|
109
|
+
initialValue: true,
|
|
110
|
+
});
|
|
111
|
+
if (prompts.isCancel(ok) || !ok) {
|
|
112
|
+
return cancel();
|
|
101
113
|
}
|
|
114
|
+
Spinner.start(`Cleaning up ${targetDir}`);
|
|
115
|
+
emptyDir(targetDir);
|
|
116
|
+
Spinner.stop(`Cleaned up ${targetDir}`);
|
|
102
117
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
}
|
|
119
|
+
// 3. Template
|
|
120
|
+
let template;
|
|
121
|
+
if (argv.blank) {
|
|
122
|
+
template = "blank";
|
|
123
|
+
}
|
|
124
|
+
else if (yes) {
|
|
125
|
+
template = "demo";
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const choice = await prompts.select({
|
|
129
|
+
message: "Choose a template:",
|
|
130
|
+
options: [
|
|
131
|
+
{
|
|
132
|
+
value: "demo",
|
|
133
|
+
label: "demo",
|
|
134
|
+
hint: "starter code with tools and UI",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value: "blank",
|
|
138
|
+
label: "blank",
|
|
139
|
+
hint: "minimal boilerplate without tools",
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
initialValue: "demo",
|
|
143
|
+
});
|
|
144
|
+
if (prompts.isCancel(choice)) {
|
|
145
|
+
return cancel();
|
|
110
146
|
}
|
|
147
|
+
template = choice;
|
|
111
148
|
}
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
// 4. Copy template
|
|
150
|
+
const root = path.resolve(targetDir);
|
|
151
|
+
Spinner.start(`Copying ${template} template`);
|
|
114
152
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// Copy template to target directory
|
|
124
|
-
fs.cpSync(templateDir, root, {
|
|
125
|
-
recursive: true,
|
|
126
|
-
filter: (src) => [".npmrc"].every((file) => !src.endsWith(file)),
|
|
127
|
-
});
|
|
128
|
-
// Rename _gitignore to .gitignore
|
|
129
|
-
fs.renameSync(path.join(root, "_gitignore"), path.join(root, ".gitignore"));
|
|
130
|
-
prompts.log.success(`Project created in ${root}`);
|
|
153
|
+
const templateDir = fileURLToPath(new URL(`../templates/${template}`, import.meta.url));
|
|
154
|
+
fs.cpSync(templateDir, root, {
|
|
155
|
+
recursive: true,
|
|
156
|
+
filter: (src) => [".npmrc"].every((file) => !src.endsWith(file)),
|
|
157
|
+
});
|
|
158
|
+
const gitignoreSource = path.join(root, "_gitignore");
|
|
159
|
+
if (fs.existsSync(gitignoreSource)) {
|
|
160
|
+
fs.renameSync(gitignoreSource, path.join(root, ".gitignore"));
|
|
131
161
|
}
|
|
162
|
+
Spinner.stop(`Copied ${template} template`);
|
|
132
163
|
}
|
|
133
164
|
catch (error) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
// Update project name in package.json
|
|
139
|
-
const pkgPath = path.join(root, "package.json");
|
|
140
|
-
if (!fs.existsSync(pkgPath)) {
|
|
141
|
-
prompts.log.error("No package.json found in project");
|
|
142
|
-
process.exit(1);
|
|
165
|
+
Spinner.error("Failed to copy template");
|
|
166
|
+
abort(String(error));
|
|
143
167
|
}
|
|
168
|
+
// 5. Set package.json name to the project dir basename
|
|
144
169
|
try {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
170
|
+
const pkgPath = path.join(root, "package.json");
|
|
171
|
+
const projectPkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
172
|
+
projectPkg.name = path.basename(root);
|
|
173
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(projectPkg, null, 2)}\n`);
|
|
148
174
|
}
|
|
149
175
|
catch (error) {
|
|
150
|
-
|
|
151
|
-
console.error(error);
|
|
152
|
-
process.exit(1);
|
|
176
|
+
abort("Failed to update project name in package.json.", String(error));
|
|
153
177
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
178
|
+
// Async spawn wrapper so a spinner can keep animating during the subprocess
|
|
179
|
+
// (cross-spawn.sync would block the event loop). Captures stdout/stderr to
|
|
180
|
+
// `output` when stdio is "pipe", trimmed to the last OUTPUT_TAIL_LINES lines
|
|
181
|
+
// — install errors land at the tail, so we keep that and prefix with an
|
|
182
|
+
// ellipsis when content gets dropped.
|
|
183
|
+
function spawnAsync(command, args) {
|
|
184
|
+
return new Promise((resolve) => {
|
|
185
|
+
let raw = "";
|
|
186
|
+
const child = spawn(command, args, {
|
|
187
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
188
|
+
cwd: root,
|
|
189
|
+
});
|
|
190
|
+
child.stdout?.on("data", (chunk) => {
|
|
191
|
+
raw += chunk.toString();
|
|
192
|
+
});
|
|
193
|
+
child.stderr?.on("data", (chunk) => {
|
|
194
|
+
raw += chunk.toString();
|
|
195
|
+
});
|
|
196
|
+
const done = (status) => {
|
|
197
|
+
const tail = [];
|
|
198
|
+
for (const part of raw.split("\n").reverse()) {
|
|
199
|
+
const line = part.trim();
|
|
200
|
+
if (!line) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (tail.length >= OUTPUT_TAIL_LINES) {
|
|
204
|
+
tail.push(`… (truncated, showing last ${OUTPUT_TAIL_LINES} lines)`);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
tail.push(line);
|
|
208
|
+
}
|
|
209
|
+
resolve({ status, output: tail.reverse().join("\n") });
|
|
210
|
+
};
|
|
211
|
+
child.on("close", done);
|
|
212
|
+
child.on("error", () => done(1));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// 6. Skills install (single Y/n prompt)
|
|
216
|
+
let installSkills;
|
|
217
|
+
if (argv["skip-skills"]) {
|
|
218
|
+
installSkills = false;
|
|
219
|
+
}
|
|
220
|
+
else if (yes) {
|
|
221
|
+
installSkills = true;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
const choice = await prompts.confirm({
|
|
225
|
+
message: "Install coding agent skills? (recommended)",
|
|
161
226
|
initialValue: true,
|
|
162
227
|
});
|
|
163
|
-
if (prompts.isCancel(
|
|
228
|
+
if (prompts.isCancel(choice)) {
|
|
164
229
|
return cancel();
|
|
165
230
|
}
|
|
166
|
-
|
|
231
|
+
installSkills = choice;
|
|
167
232
|
}
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
233
|
+
if (installSkills) {
|
|
234
|
+
Spinner.start("Installing coding agent skills");
|
|
235
|
+
const { status, output } = await spawnAsync("npx", [
|
|
236
|
+
"--yes",
|
|
237
|
+
"skills",
|
|
171
238
|
"add",
|
|
172
239
|
"alpic-ai/skybridge",
|
|
173
|
-
"
|
|
240
|
+
"--skill",
|
|
174
241
|
"chatgpt-app-builder",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
let immediate = argImmediate;
|
|
185
|
-
if (immediate === undefined) {
|
|
186
|
-
if (interactive) {
|
|
187
|
-
const immediateResult = await prompts.confirm({
|
|
188
|
-
message: `Install with ${pkgManager} and start now?`,
|
|
189
|
-
});
|
|
190
|
-
if (prompts.isCancel(immediateResult)) {
|
|
191
|
-
return cancel();
|
|
192
|
-
}
|
|
193
|
-
immediate = immediateResult;
|
|
242
|
+
"--agent",
|
|
243
|
+
"universal",
|
|
244
|
+
"claude-code",
|
|
245
|
+
"--copy", // something the symlink fails for some reason
|
|
246
|
+
"--yes",
|
|
247
|
+
]);
|
|
248
|
+
// skills cli always returns 0 so we look for the success message
|
|
249
|
+
if (status === 0 && output.includes("Done!")) {
|
|
250
|
+
Spinner.stop(`Installed coding agent skills`);
|
|
194
251
|
}
|
|
195
252
|
else {
|
|
196
|
-
|
|
253
|
+
Spinner.error(`Failed to install coding agent skills:
|
|
254
|
+
\x1b[2m${output}\x1b[0m`);
|
|
255
|
+
prompts.log.error("Try manually: `npx skills add alpic-ai/skybridge`.");
|
|
197
256
|
}
|
|
198
257
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
258
|
+
// 7. Package manager — autodetect, prompt only if detection fails (interactive)
|
|
259
|
+
if (!pm) {
|
|
260
|
+
pm = detectPackageManager() || "npm";
|
|
261
|
+
}
|
|
262
|
+
if (!yes) {
|
|
263
|
+
const choice = await prompts.select({
|
|
264
|
+
message: "Choose a package manager:",
|
|
265
|
+
options: PACKAGE_MANAGERS.map((value) => ({ value })),
|
|
266
|
+
initialValue: pm,
|
|
267
|
+
});
|
|
268
|
+
if (prompts.isCancel(choice)) {
|
|
269
|
+
return cancel();
|
|
270
|
+
}
|
|
271
|
+
pm = choice;
|
|
272
|
+
}
|
|
273
|
+
// 8. Always install dependencies
|
|
274
|
+
Spinner.start(`Installing dependencies with ${pm}`);
|
|
275
|
+
const { status, output } = await spawnAsync(pm, ["install"]);
|
|
276
|
+
if (status === 0) {
|
|
277
|
+
Spinner.stop(`Installed dependencies with ${pm}`);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
Spinner.error(`Dependency installation failed:
|
|
281
|
+
\x1b[2m${output}\x1b[0m`);
|
|
282
|
+
abort(`Try manually: cd ${targetDir} && ${pm} install`);
|
|
283
|
+
}
|
|
284
|
+
// 9. Start dev server?
|
|
285
|
+
let start = false;
|
|
286
|
+
if (argv.start) {
|
|
287
|
+
start = true;
|
|
288
|
+
}
|
|
289
|
+
else if (!yes) {
|
|
290
|
+
const choice = await prompts.confirm({
|
|
291
|
+
message: "Start dev server now?",
|
|
292
|
+
initialValue: true,
|
|
293
|
+
});
|
|
294
|
+
if (prompts.isCancel(choice)) {
|
|
295
|
+
return cancel();
|
|
296
|
+
}
|
|
297
|
+
start = choice;
|
|
298
|
+
}
|
|
299
|
+
if (start) {
|
|
300
|
+
prompts.outro(`Starting dev server in ${targetDir}…`);
|
|
301
|
+
const devResult = spawn.sync(pm, scriptArgs(pm, "dev"), {
|
|
302
|
+
stdio: "inherit",
|
|
303
|
+
cwd: root,
|
|
304
|
+
});
|
|
305
|
+
process.exit(devResult.status ?? 0);
|
|
306
|
+
}
|
|
307
|
+
prompts.log.success("All set! Next steps:");
|
|
308
|
+
prompts.log.info(`Start:
|
|
309
|
+
cd ${targetDir}
|
|
310
|
+
${scriptCommand(pm, "dev")}`);
|
|
311
|
+
prompts.log.info(`Deploy:
|
|
312
|
+
${scriptCommand(pm, "deploy")}`);
|
|
313
|
+
prompts.outro(`🛟 Need help?
|
|
314
|
+
Chat: https://discord.alpic.ai
|
|
315
|
+
Docs: https://docs.skybridge.tech`);
|
|
316
|
+
}
|
|
317
|
+
function cancel() {
|
|
318
|
+
prompts.cancel("Operation cancelled");
|
|
319
|
+
process.exit(0);
|
|
320
|
+
}
|
|
321
|
+
function abort(...lines) {
|
|
322
|
+
for (const line of lines) {
|
|
323
|
+
prompts.log.error(line);
|
|
324
|
+
}
|
|
325
|
+
prompts.outro("Aborted");
|
|
326
|
+
process.exit(1);
|
|
327
|
+
}
|
|
328
|
+
function parsePackageManager(value) {
|
|
329
|
+
switch (value) {
|
|
204
330
|
case "bun":
|
|
205
|
-
|
|
331
|
+
return "bun";
|
|
206
332
|
case "deno":
|
|
207
|
-
|
|
208
|
-
|
|
333
|
+
return "deno";
|
|
334
|
+
case "npm":
|
|
335
|
+
return "npm";
|
|
336
|
+
case "pnpm":
|
|
337
|
+
return "pnpm";
|
|
338
|
+
case "yarn":
|
|
339
|
+
return "yarn";
|
|
209
340
|
default:
|
|
210
|
-
|
|
341
|
+
return undefined;
|
|
211
342
|
}
|
|
212
|
-
runCmd.push("dev");
|
|
213
|
-
if (!immediate) {
|
|
214
|
-
prompts.outro(`Done! Next steps:
|
|
215
|
-
cd ${targetDir}
|
|
216
|
-
${installCmd.join(" ")}
|
|
217
|
-
${runCmd.join(" ")}
|
|
218
|
-
`);
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
prompts.log.step(`Installing dependencies with ${pkgManager}...`);
|
|
222
|
-
run(installCmd, {
|
|
223
|
-
stdio: "inherit",
|
|
224
|
-
cwd: root,
|
|
225
|
-
});
|
|
226
|
-
prompts.log.step("Starting dev server...");
|
|
227
|
-
run(runCmd, {
|
|
228
|
-
stdio: "inherit",
|
|
229
|
-
cwd: root,
|
|
230
|
-
});
|
|
231
343
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
|
|
344
|
+
function detectPackageManager() {
|
|
345
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
346
|
+
if (!userAgent) {
|
|
347
|
+
return undefined;
|
|
236
348
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
349
|
+
const name = userAgent.split(" ")[0]?.split("/")[0];
|
|
350
|
+
return parsePackageManager(name);
|
|
351
|
+
}
|
|
352
|
+
function scriptArgs(pm, script) {
|
|
353
|
+
switch (pm) {
|
|
354
|
+
case "yarn":
|
|
355
|
+
case "pnpm":
|
|
356
|
+
case "bun":
|
|
357
|
+
return [script];
|
|
358
|
+
case "deno":
|
|
359
|
+
return ["task", script];
|
|
360
|
+
case "npm":
|
|
361
|
+
return ["run", script];
|
|
241
362
|
}
|
|
242
363
|
}
|
|
364
|
+
function scriptCommand(pm, script) {
|
|
365
|
+
return [pm, ...scriptArgs(pm, script)].join(" ");
|
|
366
|
+
}
|
|
243
367
|
function sanitizeTargetDir(targetDir) {
|
|
244
|
-
return (
|
|
245
|
-
.trim()
|
|
246
|
-
// Only keep alphanumeric, dash, underscore, dot, @, /
|
|
247
|
-
.replace(/[^a-zA-Z0-9\-_.@/]/g, "")
|
|
248
|
-
// Prevent path traversal
|
|
249
|
-
.replace(/\.\./g, "")
|
|
250
|
-
// Collapse multiple slashes
|
|
251
|
-
.replace(/\/+/g, "/")
|
|
252
|
-
// Remove leading/trailing slashes
|
|
253
|
-
.replace(/^\/+|\/+$/g, ""));
|
|
368
|
+
return targetDir.trim().replace(/\/+$/g, "");
|
|
254
369
|
}
|
|
255
370
|
// Skip user's SPEC.md and IDE/agent preferences (.idea, .claude, etc.)
|
|
256
371
|
function isSkippedEntry(entry) {
|
|
@@ -272,17 +387,3 @@ function emptyDir(dir) {
|
|
|
272
387
|
fs.rmSync(path.join(dir, entry.name), { recursive: true, force: true });
|
|
273
388
|
}
|
|
274
389
|
}
|
|
275
|
-
function getPkgExecCmd(pkgManager, cmd) {
|
|
276
|
-
switch (pkgManager) {
|
|
277
|
-
case "yarn":
|
|
278
|
-
return ["yarn", "dlx", cmd];
|
|
279
|
-
case "pnpm":
|
|
280
|
-
return ["pnpm", "dlx", cmd];
|
|
281
|
-
case "bun":
|
|
282
|
-
return ["bunx", cmd];
|
|
283
|
-
case "deno":
|
|
284
|
-
return ["deno", "run", "-A", `npm:${cmd}`];
|
|
285
|
-
default:
|
|
286
|
-
return ["npx", "--yes", cmd];
|
|
287
|
-
}
|
|
288
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-skybridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alpic",
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"index.js",
|
|
16
16
|
"dist",
|
|
17
|
-
"
|
|
17
|
+
"templates"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@clack/prompts": "^1.1.0",
|
|
21
|
-
"
|
|
21
|
+
"cross-spawn": "^7.0.6",
|
|
22
22
|
"mri": "^1.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/cross-spawn": "^6.0.6",
|
|
25
26
|
"typescript": "^6.0.2",
|
|
26
27
|
"vitest": "^4.1.4"
|
|
27
28
|
},
|