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