create-skybridge 0.0.0-dev.bffc31c → 0.0.0-dev.c006b0b
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 +410 -207
- package/package.json +8 -8
- package/templates/blank/.dockerignore +4 -0
- package/templates/blank/Dockerfile +53 -0
- package/templates/blank/README.md +93 -0
- package/{template → templates/blank}/_gitignore +3 -1
- package/templates/blank/node_modules/.bin/alpic +21 -0
- package/templates/blank/node_modules/.bin/sb +21 -0
- package/templates/blank/node_modules/.bin/skybridge +21 -0
- package/{template → templates/blank}/node_modules/.bin/tsc +2 -2
- package/{template → templates/blank}/node_modules/.bin/tsserver +2 -2
- package/{template → templates/blank}/node_modules/.bin/tsx +2 -2
- package/{template → templates/blank}/node_modules/.bin/vite +2 -2
- package/templates/blank/package.json +29 -0
- package/templates/blank/src/helpers.ts +4 -0
- package/templates/blank/src/index.ts +3 -0
- package/templates/blank/src/server.ts +17 -0
- package/templates/blank/tsconfig.json +5 -0
- package/templates/blank/vite.config.ts +12 -0
- package/templates/demo/.dockerignore +4 -0
- package/templates/demo/AGENTS.md +1 -0
- package/templates/demo/Dockerfile +53 -0
- package/templates/demo/README.md +96 -0
- package/templates/demo/_gitignore +7 -0
- package/templates/demo/alpic.json +3 -0
- package/templates/demo/evals/start.eval.ts +11 -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/tsx +21 -0
- package/templates/demo/node_modules/.bin/vite +21 -0
- package/templates/demo/node_modules/.bin/vitest +21 -0
- package/templates/demo/package.json +47 -0
- package/templates/demo/src/helpers.ts +4 -0
- package/templates/demo/src/index.css +59 -0
- package/templates/demo/src/index.ts +3 -0
- package/templates/demo/src/server.ts +97 -0
- package/templates/demo/src/views/components/doc-link.tsx +22 -0
- package/templates/demo/src/views/components/doc.tsx +21 -0
- package/templates/demo/src/views/components/nav.tsx +31 -0
- package/templates/demo/src/views/components/progress.tsx +35 -0
- package/templates/demo/src/views/components/steps/outro.tsx +68 -0
- package/templates/demo/src/views/components/steps/state.tsx +47 -0
- package/templates/demo/src/views/components/steps/tool-call.tsx +53 -0
- package/templates/demo/src/views/components/steps/tool-output.tsx +40 -0
- package/templates/demo/src/views/images/mascot/beret.png +0 -0
- package/templates/demo/src/views/images/mascot/chapka.png +0 -0
- package/templates/demo/src/views/images/mascot/cowboy-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/fez.png +0 -0
- package/templates/demo/src/views/images/mascot/jester-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/mitre.png +0 -0
- package/templates/demo/src/views/images/mascot/non-la.png +0 -0
- package/templates/demo/src/views/images/mascot/original.png +0 -0
- package/templates/demo/src/views/images/mascot/propeller-beanie.png +0 -0
- package/templates/demo/src/views/images/mascot/ski-mask.png +0 -0
- package/templates/demo/src/views/images/mascot/sombrero.png +0 -0
- package/templates/demo/src/views/images/mascot/top-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/viking-helmet.png +0 -0
- package/templates/demo/src/views/onboarding.tsx +63 -0
- package/templates/demo/src/views/use-mascot.ts +60 -0
- package/templates/demo/tsconfig.evals.json +11 -0
- package/templates/demo/tsconfig.json +11 -0
- package/templates/demo/vite.config.ts +20 -0
- package/templates/ecom/.dockerignore +4 -0
- package/templates/ecom/.env.template +7 -0
- package/templates/ecom/.ladle/components.tsx +26 -0
- package/templates/ecom/.ladle/config.mjs +11 -0
- package/templates/ecom/.ladle/vite.config.ts +11 -0
- package/templates/ecom/AGENTS.md +2 -0
- package/templates/ecom/Dockerfile +53 -0
- package/templates/ecom/README.md +93 -0
- package/templates/ecom/_gitignore +9 -0
- package/templates/ecom/alpic.json +3 -0
- package/templates/ecom/node_modules/.bin/alpic +21 -0
- package/templates/ecom/node_modules/.bin/ladle +21 -0
- package/templates/ecom/node_modules/.bin/sb +21 -0
- package/templates/ecom/node_modules/.bin/skybridge +21 -0
- package/templates/ecom/node_modules/.bin/tsc +21 -0
- package/templates/ecom/node_modules/.bin/tsserver +21 -0
- package/templates/ecom/node_modules/.bin/tsx +21 -0
- package/templates/ecom/node_modules/.bin/vite +21 -0
- package/templates/ecom/package.json +42 -0
- package/templates/ecom/src/catalog/index.ts +19 -0
- package/templates/ecom/src/catalog/mock.ts +134 -0
- package/templates/ecom/src/catalog/shopify.ts +264 -0
- package/templates/ecom/src/components/chip.css.ts +63 -0
- package/templates/ecom/src/components/chip.stories.tsx +27 -0
- package/templates/ecom/src/components/chip.tsx +49 -0
- package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
- package/templates/ecom/src/components/empty-state.tsx +12 -0
- package/templates/ecom/src/components/expandable-text.css.ts +49 -0
- package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
- package/templates/ecom/src/components/expandable-text.tsx +53 -0
- package/templates/ecom/src/components/image-gallery.css.ts +172 -0
- package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
- package/templates/ecom/src/components/image-gallery.tsx +163 -0
- package/templates/ecom/src/components/product-card.css.ts +159 -0
- package/templates/ecom/src/components/product-card.stories.tsx +58 -0
- package/templates/ecom/src/components/product-card.tsx +102 -0
- package/templates/ecom/src/components/product-carousel.css.ts +134 -0
- package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
- package/templates/ecom/src/components/product-carousel.tsx +202 -0
- package/templates/ecom/src/components/variant-picker.css.ts +27 -0
- package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
- package/templates/ecom/src/components/variant-picker.tsx +70 -0
- package/templates/ecom/src/components/view-frame.css.ts +22 -0
- package/templates/ecom/src/components/view-frame.tsx +27 -0
- package/templates/ecom/src/config.ts +12 -0
- package/templates/ecom/src/design/contract.css.ts +39 -0
- package/templates/ecom/src/design/fonts.css +15 -0
- package/templates/ecom/src/design/primitives.css.ts +101 -0
- package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
- package/templates/ecom/src/design/sprinkles.css.ts +128 -0
- package/templates/ecom/src/design/themes/dark.css.ts +36 -0
- package/templates/ecom/src/design/themes/light.css.ts +36 -0
- package/templates/ecom/src/design/tokens.ts +8 -0
- package/templates/ecom/src/helpers.ts +4 -0
- package/templates/ecom/src/i18n.ts +35 -0
- package/templates/ecom/src/index.css +9 -0
- package/templates/ecom/src/index.ts +3 -0
- package/templates/ecom/src/lib/cx.ts +9 -0
- package/templates/ecom/src/lib/format.ts +9 -0
- package/templates/ecom/src/lib/variants.ts +150 -0
- package/templates/ecom/src/server.ts +43 -0
- package/templates/ecom/src/tools/render-carousel.ts +161 -0
- package/templates/ecom/src/tools/search-products.ts +196 -0
- package/templates/ecom/src/types.ts +87 -0
- package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
- package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
- package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
- package/templates/ecom/src/views/carousel/index.tsx +233 -0
- package/templates/ecom/tsconfig.json +11 -0
- package/templates/ecom/vite.config.ts +8 -0
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -33
- package/template/README.md +0 -97
- package/template/node_modules/.bin/alpic +0 -21
- package/template/node_modules/.bin/sb +0 -21
- package/template/node_modules/.bin/skybridge +0 -21
- package/template/package.json +0 -35
- package/template/server/src/index.ts +0 -62
- package/template/tsconfig.json +0 -13
- package/template/web/src/helpers.ts +0 -4
- package/template/web/src/index.css +0 -152
- package/template/web/src/widgets/magic-8-ball.tsx +0 -27
- package/template/web/vite.config.ts +0 -15
- /package/{template → templates/blank}/AGENTS.md +0 -0
- /package/{template → templates/blank}/alpic.json +0 -0
package/dist/index.js
CHANGED
|
@@ -1,256 +1,473 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import * as prompts from "@clack/prompts";
|
|
6
|
-
import
|
|
6
|
+
import spawn from "cross-spawn";
|
|
7
7
|
import mri from "mri";
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
8
|
+
const OUTPUT_TAIL_LINES = 10;
|
|
9
|
+
const DEFAULT_PROJECT_NAME = "skybridge-project";
|
|
10
|
+
const PACKAGE_MANAGERS = ["bun", "deno", "npm", "pnpm", "yarn"];
|
|
11
|
+
const TEMPLATES = ["demo", "blank", "ecom"];
|
|
12
|
+
const REPO = "alpic-ai/skybridge";
|
|
13
|
+
const REPO_REF = "main";
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf-8"));
|
|
15
|
+
const version = pkg.version;
|
|
16
|
+
const HELP_MESSAGE = `Usage: skybridge create [path] [options]
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
⛰ Skybridge v${version} - the fullstack framework for building MCP Apps
|
|
14
19
|
|
|
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
|
|
20
|
+
Arguments:
|
|
21
|
+
path Where the project will be created. Prompted when omitted.
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
Options:
|
|
24
|
+
--blank scaffold a minimal project without demo tools and views
|
|
25
|
+
--ecom scaffold the ecommerce template (search products, render carousel)
|
|
26
|
+
--example <name> scaffold a copy of github.com/${REPO}/tree/${REPO_REF}/examples/<name>
|
|
27
|
+
--overwrite remove existing files if target directory is not empty
|
|
28
|
+
--pm <choice> package manager to use (choices: ${PACKAGE_MANAGERS.join(", ")}. default to npm when none is provided or infered)
|
|
29
|
+
--skip-skills skip installing coding agent skills
|
|
30
|
+
--start start dev server
|
|
31
|
+
--yes skip prompts and use default values for unprovided options
|
|
32
|
+
--help display this help message
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
Non-interactive usage:
|
|
35
|
+
Mandatory: path argument and --yes option
|
|
36
|
+
Example: skybridge create my-app --yes`;
|
|
37
|
+
const isTTY = process.stdout.isTTY;
|
|
38
|
+
const _spinner = prompts.spinner();
|
|
39
|
+
const Spinner = {
|
|
40
|
+
start(msg) {
|
|
41
|
+
if (!isTTY) {
|
|
42
|
+
prompts.log.info(msg);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
_spinner.clear();
|
|
46
|
+
_spinner.start(msg);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
stop(msg) {
|
|
50
|
+
if (!isTTY) {
|
|
51
|
+
prompts.log.success(msg);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
_spinner.stop(msg);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
error(msg) {
|
|
58
|
+
if (!isTTY) {
|
|
59
|
+
prompts.log.error(msg);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
_spinner.error(msg);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
31
66
|
export async function init(args = process.argv.slice(2)) {
|
|
32
67
|
const argv = mri(args, {
|
|
33
|
-
boolean: [
|
|
34
|
-
|
|
68
|
+
boolean: [
|
|
69
|
+
"help",
|
|
70
|
+
"blank",
|
|
71
|
+
"ecom",
|
|
72
|
+
"overwrite",
|
|
73
|
+
"skip-skills",
|
|
74
|
+
"start",
|
|
75
|
+
"yes",
|
|
76
|
+
],
|
|
77
|
+
string: ["pm", "example"],
|
|
35
78
|
alias: { h: "help" },
|
|
36
79
|
});
|
|
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);
|
|
80
|
+
if (argv.help) {
|
|
81
|
+
console.log(HELP_MESSAGE);
|
|
46
82
|
return;
|
|
47
83
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
const { yes } = argv;
|
|
85
|
+
let targetDir = argv._[0] ? sanitizeTargetDir(String(argv._[0])) : undefined;
|
|
86
|
+
if (yes && !targetDir) {
|
|
87
|
+
abort("The target directory is required in non-interactive mode.", "Example: skybridge create my-app --yes");
|
|
88
|
+
}
|
|
89
|
+
if (argv.example !== undefined && !/^[\w.-]+$/.test(argv.example)) {
|
|
90
|
+
abort("--example requires a name, e.g. --example auth-descope.");
|
|
91
|
+
}
|
|
92
|
+
if (argv.example && (argv.blank || argv.ecom)) {
|
|
93
|
+
abort("Cannot combine --example with --blank or --ecom.");
|
|
94
|
+
}
|
|
95
|
+
let pm = parsePackageManager(argv.pm || "");
|
|
96
|
+
if (argv.pm && !pm) {
|
|
97
|
+
abort(`Invalid --pm value "${argv.pm}". Expected one of: ${PACKAGE_MANAGERS.join(", ")}.`);
|
|
98
|
+
}
|
|
99
|
+
console.log(); // cosmetic line break
|
|
100
|
+
prompts.intro(`\x1b[1;36m⛰ Welcome to Skybridge v${version} \x1b[22m- the fullstack framework for building MCP Apps\x1b[0m`);
|
|
101
|
+
// 1. Target directory
|
|
52
102
|
if (!targetDir) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
103
|
+
const choice = await prompts.text({
|
|
104
|
+
message: "Project directory:",
|
|
105
|
+
placeholder: DEFAULT_PROJECT_NAME,
|
|
106
|
+
defaultValue: DEFAULT_PROJECT_NAME,
|
|
107
|
+
validate: (value) => !value || sanitizeTargetDir(value).length > 0
|
|
108
|
+
? undefined
|
|
109
|
+
: "Invalid project name",
|
|
110
|
+
});
|
|
111
|
+
if (prompts.isCancel(choice)) {
|
|
112
|
+
return cancel();
|
|
113
|
+
}
|
|
114
|
+
targetDir = sanitizeTargetDir(choice);
|
|
115
|
+
}
|
|
116
|
+
// 2. Existing-directory handling
|
|
117
|
+
if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
|
|
118
|
+
if (argv.overwrite) {
|
|
119
|
+
emptyDir(targetDir);
|
|
120
|
+
}
|
|
121
|
+
else if (yes) {
|
|
122
|
+
prompts.log.error(`Target directory "${targetDir}" is not empty. Use --overwrite to remove existing files.`);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const ok = await prompts.confirm({
|
|
127
|
+
message: `Target directory "${targetDir}" is not empty. Remove existing files?`,
|
|
128
|
+
initialValue: true,
|
|
63
129
|
});
|
|
64
|
-
if (prompts.isCancel(
|
|
130
|
+
if (prompts.isCancel(ok) || !ok) {
|
|
65
131
|
return cancel();
|
|
66
132
|
}
|
|
67
|
-
|
|
133
|
+
Spinner.start(`Cleaning up ${targetDir}`);
|
|
134
|
+
emptyDir(targetDir);
|
|
135
|
+
Spinner.stop(`Cleaned up ${targetDir}`);
|
|
68
136
|
}
|
|
69
|
-
|
|
70
|
-
|
|
137
|
+
}
|
|
138
|
+
// 3. Template
|
|
139
|
+
let template;
|
|
140
|
+
const example = argv.example;
|
|
141
|
+
if (argv.blank) {
|
|
142
|
+
template = "blank";
|
|
143
|
+
}
|
|
144
|
+
if (argv.ecom) {
|
|
145
|
+
if (template) {
|
|
146
|
+
abort("Cannot specify both --blank and --ecom.");
|
|
71
147
|
}
|
|
148
|
+
template = "ecom";
|
|
72
149
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
150
|
+
if (!template && !example) {
|
|
151
|
+
if (yes) {
|
|
152
|
+
template = "demo";
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const choice = await prompts.select({
|
|
156
|
+
message: "Choose a template:",
|
|
157
|
+
options: [
|
|
158
|
+
{
|
|
159
|
+
value: "demo",
|
|
160
|
+
label: "demo",
|
|
161
|
+
hint: "starter code with tools and UI",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
value: "blank",
|
|
165
|
+
label: "blank",
|
|
166
|
+
hint: "minimal boilerplate without tools",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
value: "ecom",
|
|
170
|
+
label: "ecom",
|
|
171
|
+
hint: "ecommerce template with product search tool and carousel view",
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
initialValue: "demo",
|
|
175
|
+
});
|
|
176
|
+
if (prompts.isCancel(choice)) {
|
|
177
|
+
return cancel();
|
|
101
178
|
}
|
|
179
|
+
template = choice;
|
|
102
180
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
181
|
+
}
|
|
182
|
+
// 4. Copy template
|
|
183
|
+
const root = path.resolve(targetDir);
|
|
184
|
+
const templatesDir = fileURLToPath(new URL("../templates", import.meta.url));
|
|
185
|
+
let source = path.join(templatesDir, template ?? "demo");
|
|
186
|
+
let cleanup = () => { };
|
|
187
|
+
if (example) {
|
|
188
|
+
Spinner.start(`Downloading ${example} example`);
|
|
189
|
+
try {
|
|
190
|
+
({ source, cleanup } = await downloadExample(example));
|
|
191
|
+
Spinner.stop(`Downloaded ${example} example`);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
Spinner.error(`Failed to download ${example} example`);
|
|
195
|
+
abort(error instanceof Error ? error.message : String(error));
|
|
110
196
|
}
|
|
111
197
|
}
|
|
112
|
-
|
|
113
|
-
// 3. Download from repo or copy template
|
|
198
|
+
Spinner.start(`Copying ${example ?? template} template`);
|
|
114
199
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
200
|
+
fs.cpSync(source, root, {
|
|
201
|
+
recursive: true,
|
|
202
|
+
filter: (src) => [".npmrc"].every((file) => !src.endsWith(file)),
|
|
203
|
+
});
|
|
204
|
+
const gitignore = path.join(root, ".gitignore");
|
|
205
|
+
const gitignoreSource = path.join(root, "_gitignore");
|
|
206
|
+
if (fs.existsSync(gitignoreSource)) {
|
|
207
|
+
fs.renameSync(gitignoreSource, gitignore);
|
|
119
208
|
}
|
|
120
|
-
else {
|
|
121
|
-
|
|
122
|
-
const templateDir = fileURLToPath(new URL("../template", import.meta.url));
|
|
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}`);
|
|
209
|
+
else if (!fs.existsSync(gitignore)) {
|
|
210
|
+
fs.copyFileSync(path.join(templatesDir, "demo", "_gitignore"), gitignore);
|
|
131
211
|
}
|
|
212
|
+
Spinner.stop(`Copied ${example ?? template} template`);
|
|
132
213
|
}
|
|
133
214
|
catch (error) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
process.exit(1);
|
|
215
|
+
Spinner.error("Failed to copy template");
|
|
216
|
+
abort(String(error));
|
|
137
217
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!fs.existsSync(pkgPath)) {
|
|
141
|
-
prompts.log.error("No package.json found in project");
|
|
142
|
-
process.exit(1);
|
|
218
|
+
finally {
|
|
219
|
+
cleanup();
|
|
143
220
|
}
|
|
221
|
+
// 5. Set package.json name to the project dir basename
|
|
144
222
|
try {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
223
|
+
const pkgPath = path.join(root, "package.json");
|
|
224
|
+
const projectPkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
225
|
+
projectPkg.name = path.basename(root);
|
|
226
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(projectPkg, null, 2)}\n`);
|
|
148
227
|
}
|
|
149
228
|
catch (error) {
|
|
150
|
-
|
|
151
|
-
console.error(error);
|
|
152
|
-
process.exit(1);
|
|
229
|
+
abort("Failed to update project name in package.json.", String(error));
|
|
153
230
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
231
|
+
// Async spawn wrapper so a spinner can keep animating during the subprocess
|
|
232
|
+
// (cross-spawn.sync would block the event loop). Captures stdout/stderr to
|
|
233
|
+
// `output` when stdio is "pipe", trimmed to the last OUTPUT_TAIL_LINES lines
|
|
234
|
+
// — install errors land at the tail, so we keep that and prefix with an
|
|
235
|
+
// ellipsis when content gets dropped.
|
|
236
|
+
function spawnAsync(command, args) {
|
|
237
|
+
return new Promise((resolve) => {
|
|
238
|
+
let raw = "";
|
|
239
|
+
const child = spawn(command, args, {
|
|
240
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
241
|
+
cwd: root,
|
|
242
|
+
});
|
|
243
|
+
child.stdout?.on("data", (chunk) => {
|
|
244
|
+
raw += chunk.toString();
|
|
245
|
+
});
|
|
246
|
+
child.stderr?.on("data", (chunk) => {
|
|
247
|
+
raw += chunk.toString();
|
|
248
|
+
});
|
|
249
|
+
const done = (status) => {
|
|
250
|
+
const tail = [];
|
|
251
|
+
for (const part of raw.split("\n").reverse()) {
|
|
252
|
+
const line = part.trim();
|
|
253
|
+
if (!line) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (tail.length >= OUTPUT_TAIL_LINES) {
|
|
257
|
+
tail.push(`… (truncated, showing last ${OUTPUT_TAIL_LINES} lines)`);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
tail.push(line);
|
|
261
|
+
}
|
|
262
|
+
resolve({ status, output: tail.reverse().join("\n") });
|
|
263
|
+
};
|
|
264
|
+
child.on("close", done);
|
|
265
|
+
child.on("error", () => done(1));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// 6. Skills install (single Y/n prompt)
|
|
269
|
+
let installSkills;
|
|
270
|
+
if (argv["skip-skills"]) {
|
|
271
|
+
installSkills = false;
|
|
272
|
+
}
|
|
273
|
+
else if (yes) {
|
|
274
|
+
installSkills = true;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const choice = await prompts.confirm({
|
|
278
|
+
message: "Install coding agent skills? (recommended)",
|
|
161
279
|
initialValue: true,
|
|
162
280
|
});
|
|
163
|
-
if (prompts.isCancel(
|
|
281
|
+
if (prompts.isCancel(choice)) {
|
|
164
282
|
return cancel();
|
|
165
283
|
}
|
|
166
|
-
|
|
284
|
+
installSkills = choice;
|
|
167
285
|
}
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
286
|
+
if (installSkills) {
|
|
287
|
+
Spinner.start("Installing coding agent skills");
|
|
288
|
+
const { status, output } = await spawnAsync("npx", [
|
|
289
|
+
"--yes",
|
|
290
|
+
"skills",
|
|
171
291
|
"add",
|
|
172
292
|
"alpic-ai/skybridge",
|
|
173
|
-
"
|
|
293
|
+
"--skill",
|
|
174
294
|
"chatgpt-app-builder",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
295
|
+
"--agent",
|
|
296
|
+
"universal",
|
|
297
|
+
"claude-code",
|
|
298
|
+
"--copy", // something the symlink fails for some reason
|
|
299
|
+
"--yes",
|
|
300
|
+
]);
|
|
301
|
+
// skills cli always returns 0 so we look for the success message
|
|
302
|
+
if (status === 0 && output.includes("Done!")) {
|
|
303
|
+
Spinner.stop(`Installed coding agent skills`);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
Spinner.error(`Failed to install coding agent skills:
|
|
307
|
+
\x1b[2m${output}\x1b[0m`);
|
|
308
|
+
prompts.log.error("Try manually: `npx skills add alpic-ai/skybridge`.");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// 7. Package manager — autodetect, prompt only if detection fails (interactive)
|
|
312
|
+
if (!pm) {
|
|
313
|
+
pm = detectPackageManager() || "npm";
|
|
314
|
+
}
|
|
315
|
+
if (!yes) {
|
|
316
|
+
const choice = await prompts.select({
|
|
317
|
+
message: "Choose a package manager:",
|
|
318
|
+
options: PACKAGE_MANAGERS.map((value) => ({ value })),
|
|
319
|
+
initialValue: pm,
|
|
320
|
+
});
|
|
321
|
+
if (prompts.isCancel(choice)) {
|
|
322
|
+
return cancel();
|
|
323
|
+
}
|
|
324
|
+
pm = choice;
|
|
325
|
+
}
|
|
326
|
+
// 8. pnpm ≥10 fails installs unless esbuild's build script is allow-listed
|
|
327
|
+
if (pm === "pnpm") {
|
|
328
|
+
fs.writeFileSync(path.join(root, "pnpm-workspace.yaml"), 'packages:\n - "."\nonlyBuiltDependencies:\n - esbuild\nallowBuilds:\n esbuild: true\n');
|
|
329
|
+
}
|
|
330
|
+
// 9. Always install dependencies
|
|
331
|
+
Spinner.start(`Installing dependencies with ${pm}`);
|
|
332
|
+
const { status, output } = await spawnAsync(pm, ["install"]);
|
|
333
|
+
if (status === 0) {
|
|
334
|
+
Spinner.stop(`Installed dependencies with ${pm}`);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
Spinner.error(`Dependency installation failed:
|
|
338
|
+
\x1b[2m${output}\x1b[0m`);
|
|
339
|
+
abort(`Try manually: cd ${targetDir} && ${pm} install`);
|
|
340
|
+
}
|
|
341
|
+
// 10. Start dev server?
|
|
342
|
+
let start = false;
|
|
343
|
+
if (argv.start) {
|
|
344
|
+
start = true;
|
|
345
|
+
}
|
|
346
|
+
else if (!yes) {
|
|
347
|
+
const choice = await prompts.confirm({
|
|
348
|
+
message: "Start dev server now?",
|
|
349
|
+
initialValue: true,
|
|
350
|
+
});
|
|
351
|
+
if (prompts.isCancel(choice)) {
|
|
352
|
+
return cancel();
|
|
353
|
+
}
|
|
354
|
+
start = choice;
|
|
355
|
+
}
|
|
356
|
+
if (start) {
|
|
357
|
+
prompts.outro(`Starting dev server in ${targetDir}…`);
|
|
358
|
+
const devResult = spawn.sync(pm, scriptArgs(pm, "dev"), {
|
|
179
359
|
stdio: "inherit",
|
|
180
|
-
cwd:
|
|
360
|
+
cwd: root,
|
|
181
361
|
});
|
|
362
|
+
process.exit(devResult.status ?? 0);
|
|
182
363
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
364
|
+
prompts.log.success("All set! Next steps:");
|
|
365
|
+
prompts.log.info(`Start:
|
|
366
|
+
cd ${targetDir}
|
|
367
|
+
${scriptCommand(pm, "dev")}`);
|
|
368
|
+
prompts.log.info(`Deploy:
|
|
369
|
+
${scriptCommand(pm, "deploy")}`);
|
|
370
|
+
prompts.outro(`🛟 Need help?
|
|
371
|
+
Chat: https://discord.alpic.ai
|
|
372
|
+
Docs: https://docs.skybridge.tech`);
|
|
373
|
+
}
|
|
374
|
+
async function downloadExample(name) {
|
|
375
|
+
const res = await fetch(`https://codeload.github.com/${REPO}/tar.gz/${REPO_REF}`);
|
|
376
|
+
if (!res.ok) {
|
|
377
|
+
throw new Error(`GitHub returned ${res.status} while fetching ${REPO}.`);
|
|
378
|
+
}
|
|
379
|
+
const archive = Buffer.from(await res.arrayBuffer());
|
|
380
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "skybridge-example-"));
|
|
381
|
+
const cleanup = () => fs.rmSync(tmp, { recursive: true, force: true });
|
|
382
|
+
try {
|
|
383
|
+
const tar = spawn("tar", ["-xz", "-C", tmp], {
|
|
384
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
385
|
+
});
|
|
386
|
+
let stderr = "";
|
|
387
|
+
tar.stderr?.on("data", (chunk) => {
|
|
388
|
+
stderr += chunk.toString();
|
|
389
|
+
});
|
|
390
|
+
const exit = new Promise((resolve, reject) => {
|
|
391
|
+
tar.on("error", reject);
|
|
392
|
+
tar.on("close", (status) => status === 0
|
|
393
|
+
? resolve()
|
|
394
|
+
: reject(new Error(`tar exited with ${status}: ${stderr.trim()}`)));
|
|
395
|
+
});
|
|
396
|
+
tar.stdin?.on("error", () => { });
|
|
397
|
+
tar.stdin?.end(archive);
|
|
398
|
+
await exit;
|
|
399
|
+
const [extracted] = fs.readdirSync(tmp);
|
|
400
|
+
if (!extracted) {
|
|
401
|
+
throw new Error("Downloaded archive is empty.");
|
|
194
402
|
}
|
|
195
|
-
|
|
196
|
-
|
|
403
|
+
const examplesDir = path.join(tmp, extracted, "examples");
|
|
404
|
+
const available = fs
|
|
405
|
+
.readdirSync(examplesDir, { withFileTypes: true })
|
|
406
|
+
.filter((entry) => entry.isDirectory() &&
|
|
407
|
+
fs.existsSync(path.join(examplesDir, entry.name, "package.json")))
|
|
408
|
+
.map((entry) => entry.name);
|
|
409
|
+
if (!available.includes(name)) {
|
|
410
|
+
throw new Error(`Unknown example "${name}". Available examples:\n ${available.join("\n ")}`);
|
|
197
411
|
}
|
|
412
|
+
return { source: path.join(examplesDir, name), cleanup };
|
|
198
413
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
414
|
+
catch (error) {
|
|
415
|
+
cleanup();
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function cancel() {
|
|
420
|
+
prompts.cancel("Operation cancelled");
|
|
421
|
+
process.exit(0);
|
|
422
|
+
}
|
|
423
|
+
function abort(...lines) {
|
|
424
|
+
for (const line of lines) {
|
|
425
|
+
prompts.log.error(line);
|
|
426
|
+
}
|
|
427
|
+
prompts.outro("Aborted");
|
|
428
|
+
process.exit(1);
|
|
429
|
+
}
|
|
430
|
+
function parsePackageManager(value) {
|
|
431
|
+
switch (value) {
|
|
204
432
|
case "bun":
|
|
205
|
-
|
|
433
|
+
return "bun";
|
|
206
434
|
case "deno":
|
|
207
|
-
|
|
208
|
-
|
|
435
|
+
return "deno";
|
|
436
|
+
case "npm":
|
|
437
|
+
return "npm";
|
|
438
|
+
case "pnpm":
|
|
439
|
+
return "pnpm";
|
|
440
|
+
case "yarn":
|
|
441
|
+
return "yarn";
|
|
209
442
|
default:
|
|
210
|
-
|
|
211
|
-
}
|
|
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;
|
|
443
|
+
return undefined;
|
|
220
444
|
}
|
|
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
445
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
|
|
446
|
+
function detectPackageManager() {
|
|
447
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
448
|
+
if (!userAgent) {
|
|
449
|
+
return undefined;
|
|
236
450
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
451
|
+
const name = userAgent.split(" ")[0]?.split("/")[0];
|
|
452
|
+
return parsePackageManager(name);
|
|
453
|
+
}
|
|
454
|
+
function scriptArgs(pm, script) {
|
|
455
|
+
switch (pm) {
|
|
456
|
+
case "yarn":
|
|
457
|
+
case "pnpm":
|
|
458
|
+
case "bun":
|
|
459
|
+
return [script];
|
|
460
|
+
case "deno":
|
|
461
|
+
return ["task", script];
|
|
462
|
+
case "npm":
|
|
463
|
+
return ["run", script];
|
|
241
464
|
}
|
|
242
465
|
}
|
|
466
|
+
function scriptCommand(pm, script) {
|
|
467
|
+
return [pm, ...scriptArgs(pm, script)].join(" ");
|
|
468
|
+
}
|
|
243
469
|
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, ""));
|
|
470
|
+
return targetDir.trim().replace(/\/+$/g, "");
|
|
254
471
|
}
|
|
255
472
|
// Skip user's SPEC.md and IDE/agent preferences (.idea, .claude, etc.)
|
|
256
473
|
function isSkippedEntry(entry) {
|
|
@@ -272,17 +489,3 @@ function emptyDir(dir) {
|
|
|
272
489
|
fs.rmSync(path.join(dir, entry.name), { recursive: true, force: true });
|
|
273
490
|
}
|
|
274
491
|
}
|
|
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
|
-
}
|