create-skybridge 0.0.0-dev.b9ea588 → 0.0.0-dev.b9f85b3

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.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +442 -166
  3. package/package.json +15 -15
  4. package/templates/blank/.dockerignore +4 -0
  5. package/templates/blank/AGENTS.md +1 -0
  6. package/templates/blank/Dockerfile +53 -0
  7. package/templates/blank/README.md +93 -0
  8. package/templates/blank/_gitignore +7 -0
  9. package/templates/blank/alpic.json +3 -0
  10. package/templates/blank/node_modules/.bin/alpic +21 -0
  11. package/templates/blank/node_modules/.bin/sb +21 -0
  12. package/templates/blank/node_modules/.bin/skybridge +21 -0
  13. package/templates/blank/node_modules/.bin/tsc +21 -0
  14. package/templates/blank/node_modules/.bin/tsserver +21 -0
  15. package/templates/blank/node_modules/.bin/tsx +21 -0
  16. package/templates/blank/node_modules/.bin/vite +21 -0
  17. package/templates/blank/package.json +29 -0
  18. package/templates/blank/src/helpers.ts +4 -0
  19. package/templates/blank/src/index.ts +3 -0
  20. package/templates/blank/src/server.ts +17 -0
  21. package/templates/blank/tsconfig.json +5 -0
  22. package/templates/blank/vite.config.ts +12 -0
  23. package/templates/demo/.dockerignore +4 -0
  24. package/templates/demo/AGENTS.md +1 -0
  25. package/templates/demo/Dockerfile +53 -0
  26. package/templates/demo/README.md +96 -0
  27. package/templates/demo/_gitignore +7 -0
  28. package/templates/demo/alpic.json +3 -0
  29. package/templates/demo/evals/start.eval.ts +11 -0
  30. package/templates/demo/node_modules/.bin/alpic +21 -0
  31. package/templates/demo/node_modules/.bin/sb +21 -0
  32. package/templates/demo/node_modules/.bin/skybridge +21 -0
  33. package/templates/demo/node_modules/.bin/tsc +21 -0
  34. package/templates/demo/node_modules/.bin/tsserver +21 -0
  35. package/templates/demo/node_modules/.bin/tsx +21 -0
  36. package/templates/demo/node_modules/.bin/vite +21 -0
  37. package/templates/demo/node_modules/.bin/vitest +21 -0
  38. package/templates/demo/package.json +47 -0
  39. package/templates/demo/src/helpers.ts +4 -0
  40. package/templates/demo/src/index.css +59 -0
  41. package/templates/demo/src/index.ts +3 -0
  42. package/templates/demo/src/server.ts +97 -0
  43. package/templates/demo/src/views/components/doc-link.tsx +22 -0
  44. package/templates/demo/src/views/components/doc.tsx +21 -0
  45. package/templates/demo/src/views/components/nav.tsx +31 -0
  46. package/templates/demo/src/views/components/progress.tsx +35 -0
  47. package/templates/demo/src/views/components/steps/outro.tsx +68 -0
  48. package/templates/demo/src/views/components/steps/state.tsx +47 -0
  49. package/templates/demo/src/views/components/steps/tool-call.tsx +53 -0
  50. package/templates/demo/src/views/components/steps/tool-output.tsx +40 -0
  51. package/templates/demo/src/views/images/mascot/beret.png +0 -0
  52. package/templates/demo/src/views/images/mascot/chapka.png +0 -0
  53. package/templates/demo/src/views/images/mascot/cowboy-hat.png +0 -0
  54. package/templates/demo/src/views/images/mascot/fez.png +0 -0
  55. package/templates/demo/src/views/images/mascot/jester-hat.png +0 -0
  56. package/templates/demo/src/views/images/mascot/mitre.png +0 -0
  57. package/templates/demo/src/views/images/mascot/non-la.png +0 -0
  58. package/templates/demo/src/views/images/mascot/original.png +0 -0
  59. package/templates/demo/src/views/images/mascot/propeller-beanie.png +0 -0
  60. package/templates/demo/src/views/images/mascot/ski-mask.png +0 -0
  61. package/templates/demo/src/views/images/mascot/sombrero.png +0 -0
  62. package/templates/demo/src/views/images/mascot/top-hat.png +0 -0
  63. package/templates/demo/src/views/images/mascot/viking-helmet.png +0 -0
  64. package/templates/demo/src/views/onboarding.tsx +63 -0
  65. package/templates/demo/src/views/use-mascot.ts +60 -0
  66. package/templates/demo/tsconfig.evals.json +11 -0
  67. package/templates/demo/tsconfig.json +11 -0
  68. package/templates/demo/vite.config.ts +20 -0
  69. package/templates/ecom/.dockerignore +4 -0
  70. package/templates/ecom/.env.template +7 -0
  71. package/templates/ecom/.ladle/components.tsx +26 -0
  72. package/templates/ecom/.ladle/config.mjs +11 -0
  73. package/templates/ecom/.ladle/vite.config.ts +11 -0
  74. package/templates/ecom/AGENTS.md +2 -0
  75. package/templates/ecom/Dockerfile +53 -0
  76. package/templates/ecom/README.md +93 -0
  77. package/templates/ecom/_gitignore +9 -0
  78. package/templates/ecom/alpic.json +3 -0
  79. package/templates/ecom/node_modules/.bin/alpic +21 -0
  80. package/templates/ecom/node_modules/.bin/ladle +21 -0
  81. package/templates/ecom/node_modules/.bin/sb +21 -0
  82. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  83. package/templates/ecom/node_modules/.bin/tsc +21 -0
  84. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  85. package/templates/ecom/node_modules/.bin/tsx +21 -0
  86. package/templates/ecom/node_modules/.bin/vite +21 -0
  87. package/templates/ecom/package.json +42 -0
  88. package/templates/ecom/src/catalog/index.ts +19 -0
  89. package/templates/ecom/src/catalog/mock.ts +134 -0
  90. package/templates/ecom/src/catalog/shopify.ts +264 -0
  91. package/templates/ecom/src/components/chip.css.ts +63 -0
  92. package/templates/ecom/src/components/chip.stories.tsx +27 -0
  93. package/templates/ecom/src/components/chip.tsx +49 -0
  94. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  95. package/templates/ecom/src/components/empty-state.tsx +12 -0
  96. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  97. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  98. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  99. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  100. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  101. package/templates/ecom/src/components/image-gallery.tsx +163 -0
  102. package/templates/ecom/src/components/product-card.css.ts +159 -0
  103. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  104. package/templates/ecom/src/components/product-card.tsx +102 -0
  105. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  106. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  107. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  108. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  109. package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
  110. package/templates/ecom/src/components/variant-picker.tsx +70 -0
  111. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  112. package/templates/ecom/src/components/view-frame.tsx +27 -0
  113. package/templates/ecom/src/config.ts +12 -0
  114. package/templates/ecom/src/design/contract.css.ts +39 -0
  115. package/templates/ecom/src/design/fonts.css +15 -0
  116. package/templates/ecom/src/design/primitives.css.ts +101 -0
  117. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  118. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  119. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  120. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  121. package/templates/ecom/src/design/tokens.ts +8 -0
  122. package/templates/ecom/src/helpers.ts +4 -0
  123. package/templates/ecom/src/i18n.ts +35 -0
  124. package/templates/ecom/src/index.css +9 -0
  125. package/templates/ecom/src/index.ts +3 -0
  126. package/templates/ecom/src/lib/cx.ts +9 -0
  127. package/templates/ecom/src/lib/format.ts +9 -0
  128. package/templates/ecom/src/lib/variants.ts +150 -0
  129. package/templates/ecom/src/server.ts +43 -0
  130. package/templates/ecom/src/tools/render-carousel.ts +161 -0
  131. package/templates/ecom/src/tools/search-products.ts +196 -0
  132. package/templates/ecom/src/types.ts +87 -0
  133. package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
  134. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
  135. package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
  136. package/templates/ecom/src/views/carousel/index.tsx +233 -0
  137. package/templates/ecom/tsconfig.json +11 -0
  138. package/templates/ecom/vite.config.ts +8 -0
  139. package/dist/index.test.d.ts +0 -1
  140. package/dist/index.test.js +0 -23
  141. package/template/README.md +0 -66
  142. package/template/_gitignore +0 -4
  143. package/template/alpic.json +0 -4
  144. package/template/package.json +0 -21
  145. package/template/pnpm-workspace.yaml +0 -7
  146. package/template/server/nodemon.json +0 -5
  147. package/template/server/package.json +0 -32
  148. package/template/server/src/index.ts +0 -35
  149. package/template/server/src/middleware.ts +0 -54
  150. package/template/server/src/server.ts +0 -66
  151. package/template/server/tsconfig.json +0 -17
  152. package/template/web/package.json +0 -24
  153. package/template/web/src/helpers.ts +0 -4
  154. package/template/web/src/index.css +0 -30
  155. package/template/web/src/widgets/magic-8-ball.tsx +0 -24
  156. package/template/web/tsconfig.app.json +0 -34
  157. package/template/web/tsconfig.json +0 -13
  158. package/template/web/tsconfig.node.json +0 -26
  159. package/template/web/vite.config.ts +0 -15
package/dist/index.js CHANGED
@@ -1,217 +1,493 @@
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 spawn from "cross-spawn";
6
7
  import mri from "mri";
7
- const minimumPnpmVersion = 10;
8
- const defaultProjectName = "skybridge-project";
9
- // prettier-ignore
10
- const helpMessage = `\
11
- Usage: create-skybridge [OPTION]... [DIRECTORY]
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
- Create a new Skybridge project by copying the starter template.
18
+ ⛰ Skybridge v${version} - the fullstack framework for building MCP Apps
19
+
20
+ Arguments:
21
+ path Where the project will be created. Prompted when omitted.
14
22
 
15
23
  Options:
16
- -h, --help show this help message
17
- --overwrite remove existing files in target directory
18
- --immediate install dependencies and start development server
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
19
33
 
20
- Examples:
21
- create-skybridge my-app
22
- create-skybridge . --overwrite --immediate
23
- `;
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
+ };
24
66
  export async function init(args = process.argv.slice(2)) {
25
67
  const argv = mri(args, {
26
- boolean: ["help", "overwrite", "immediate"],
68
+ boolean: [
69
+ "help",
70
+ "blank",
71
+ "ecom",
72
+ "overwrite",
73
+ "skip-skills",
74
+ "start",
75
+ "yes",
76
+ ],
77
+ string: ["pm", "example"],
27
78
  alias: { h: "help" },
28
79
  });
29
- const argTargetDir = argv._[0]
30
- ? sanitizeTargetDir(String(argv._[0]))
31
- : undefined;
32
- const argOverwrite = argv.overwrite;
33
- const argImmediate = argv.immediate;
34
- const help = argv.help;
35
- if (help) {
36
- console.log(helpMessage);
80
+ if (argv.help) {
81
+ console.log(HELP_MESSAGE);
37
82
  return;
38
83
  }
39
- const interactive = process.stdin.isTTY;
40
- const cancel = () => prompts.cancel("Operation cancelled");
41
- // 1. Get project name and target dir
42
- let targetDir = argTargetDir;
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
+ const example = argv.example;
96
+ let pm = parsePackageManager(argv.pm || "");
97
+ if (argv.pm && !pm) {
98
+ abort(`Invalid --pm value "${argv.pm}". Expected one of: ${PACKAGE_MANAGERS.join(", ")}.`);
99
+ }
100
+ console.log(); // cosmetic line break
101
+ prompts.intro(`\x1b[1;36m⛰ Welcome to Skybridge v${version} \x1b[22m- the fullstack framework for building MCP Apps\x1b[0m`);
102
+ // 1. Target directory
43
103
  if (!targetDir) {
44
- if (interactive) {
45
- const projectName = await prompts.text({
46
- message: "Project name:",
47
- defaultValue: defaultProjectName,
48
- placeholder: defaultProjectName,
49
- validate: (value) => {
50
- return value.length === 0 || sanitizeTargetDir(value).length > 0
51
- ? undefined
52
- : "Invalid project name";
53
- },
104
+ const choice = await prompts.text({
105
+ message: "Project directory:",
106
+ placeholder: DEFAULT_PROJECT_NAME,
107
+ defaultValue: DEFAULT_PROJECT_NAME,
108
+ validate: (value) => !value || sanitizeTargetDir(value).length > 0
109
+ ? undefined
110
+ : "Invalid project name",
111
+ });
112
+ if (prompts.isCancel(choice)) {
113
+ return cancel();
114
+ }
115
+ targetDir = sanitizeTargetDir(choice);
116
+ }
117
+ // 2. Existing-directory handling
118
+ let downloaded;
119
+ if (example) {
120
+ Spinner.start(`Downloading ${example} example`);
121
+ try {
122
+ downloaded = await downloadExample(example);
123
+ Spinner.stop(`Downloaded ${example} example`);
124
+ }
125
+ catch (error) {
126
+ Spinner.error(`Failed to download ${example} example`);
127
+ abort(error instanceof Error ? error.message : String(error));
128
+ }
129
+ }
130
+ if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
131
+ if (argv.overwrite) {
132
+ emptyDir(targetDir);
133
+ }
134
+ else if (yes) {
135
+ prompts.log.error(`Target directory "${targetDir}" is not empty. Use --overwrite to remove existing files.`);
136
+ process.exit(1);
137
+ }
138
+ else {
139
+ const ok = await prompts.confirm({
140
+ message: `Target directory "${targetDir}" is not empty. Remove existing files?`,
141
+ initialValue: true,
54
142
  });
55
- if (prompts.isCancel(projectName)) {
143
+ if (prompts.isCancel(ok) || !ok) {
56
144
  return cancel();
57
145
  }
58
- targetDir = sanitizeTargetDir(projectName);
146
+ Spinner.start(`Cleaning up ${targetDir}`);
147
+ emptyDir(targetDir);
148
+ Spinner.stop(`Cleaned up ${targetDir}`);
59
149
  }
60
- else {
61
- targetDir = defaultProjectName;
150
+ }
151
+ // 3. Template
152
+ let template;
153
+ if (argv.blank) {
154
+ template = "blank";
155
+ }
156
+ if (argv.ecom) {
157
+ if (template) {
158
+ abort("Cannot specify both --blank and --ecom.");
62
159
  }
160
+ template = "ecom";
63
161
  }
64
- // 2. Handle directory if exist and not empty
65
- if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
66
- let overwrite = argOverwrite ? "yes" : undefined;
67
- if (!overwrite) {
68
- if (interactive) {
69
- const res = await prompts.select({
70
- message: (targetDir === "."
71
- ? "Current directory"
72
- : `Target directory "${targetDir}"`) +
73
- ` is not empty. Please choose how to proceed:`,
74
- options: [
75
- {
76
- label: "Cancel operation",
77
- value: "no",
78
- },
79
- {
80
- label: "Remove existing files and continue",
81
- value: "yes",
82
- },
83
- ],
84
- });
85
- if (prompts.isCancel(res)) {
86
- return cancel();
87
- }
88
- overwrite = res;
89
- }
90
- else {
91
- overwrite = "no";
92
- }
162
+ if (!template && !example) {
163
+ if (yes) {
164
+ template = "demo";
93
165
  }
94
- switch (overwrite) {
95
- case "yes":
96
- emptyDir(targetDir);
97
- break;
98
- case "no":
99
- cancel();
100
- return;
166
+ else {
167
+ const choice = await prompts.select({
168
+ message: "Choose a template:",
169
+ options: [
170
+ {
171
+ value: "demo",
172
+ label: "demo",
173
+ hint: "starter code with tools and UI",
174
+ },
175
+ {
176
+ value: "blank",
177
+ label: "blank",
178
+ hint: "minimal boilerplate without tools",
179
+ },
180
+ {
181
+ value: "ecom",
182
+ label: "ecom",
183
+ hint: "ecommerce template with product search tool and carousel view",
184
+ },
185
+ ],
186
+ initialValue: "demo",
187
+ });
188
+ if (prompts.isCancel(choice)) {
189
+ return cancel();
190
+ }
191
+ template = choice;
101
192
  }
102
193
  }
103
- const root = path.join(process.cwd(), targetDir);
104
- // 3. Copy the repository
105
- prompts.log.step(`Copying template...`);
194
+ // 4. Copy template
195
+ const root = path.resolve(targetDir);
196
+ const templatesDir = fileURLToPath(new URL("../templates", import.meta.url));
197
+ const source = downloaded?.source ?? path.join(templatesDir, template ?? "demo");
198
+ Spinner.start(`Copying ${example ?? template} template`);
106
199
  try {
107
- const templateDir = fileURLToPath(new URL("../template", import.meta.url));
108
- // Copy template to target directory
109
- fs.cpSync(templateDir, root, {
200
+ fs.cpSync(source, root, {
110
201
  recursive: true,
111
- filter: (src) => !src.endsWith(".npmrc"),
202
+ filter: (src) => [".npmrc"].every((file) => !src.endsWith(file)),
112
203
  });
113
- // Rename _gitignore to .gitignore
114
- fs.renameSync(path.join(root, "_gitignore"), path.join(root, ".gitignore"));
115
- // Update project name in package.json
116
- const name = path.basename(root);
117
- for (const dir of ["", "server", "web"]) {
118
- const pkgPath = path.join(root, dir, "package.json");
119
- const pkg = fs.readFileSync(pkgPath, "utf-8");
120
- const fixed = pkg.replace(/apps-sdk-template/g, name);
121
- fs.writeFileSync(pkgPath, fixed);
122
- }
123
- prompts.log.success(`Project created in ${root}`);
204
+ const gitignore = path.join(root, ".gitignore");
205
+ const gitignoreSource = path.join(root, "_gitignore");
206
+ if (fs.existsSync(gitignoreSource)) {
207
+ fs.renameSync(gitignoreSource, gitignore);
208
+ }
209
+ else if (!fs.existsSync(gitignore)) {
210
+ fs.copyFileSync(path.join(templatesDir, "demo", "_gitignore"), gitignore);
211
+ }
212
+ Spinner.stop(`Copied ${example ?? template} template`);
124
213
  }
125
214
  catch (error) {
126
- prompts.log.error("Failed to copy repository");
127
- console.error(error);
128
- process.exit(1);
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?`,
215
+ Spinner.error("Failed to copy template");
216
+ abort(String(error));
217
+ }
218
+ finally {
219
+ downloaded?.cleanup();
220
+ }
221
+ // 5. Set package.json name to the project dir basename
222
+ try {
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`);
227
+ }
228
+ catch (error) {
229
+ abort("Failed to update project name in package.json.", String(error));
230
+ }
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,
136
242
  });
137
- if (prompts.isCancel(immediateResult)) {
138
- return cancel();
139
- }
140
- immediate = immediateResult;
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)",
279
+ initialValue: true,
280
+ });
281
+ if (prompts.isCancel(choice)) {
282
+ return cancel();
283
+ }
284
+ installSkills = choice;
285
+ }
286
+ if (installSkills) {
287
+ Spinner.start("Installing coding agent skills");
288
+ const { status, output } = await spawnAsync("npx", [
289
+ "--yes",
290
+ "skills",
291
+ "add",
292
+ "alpic-ai/skybridge",
293
+ "--skill",
294
+ "chatgpt-app-builder",
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`);
141
304
  }
142
305
  else {
143
- immediate = false;
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`.");
144
309
  }
145
310
  }
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;
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"), {
359
+ stdio: "inherit",
360
+ cwd: root,
361
+ });
362
+ process.exit(devResult.status ?? 0);
363
+ }
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", (error) => reject(error.code === "ENOENT"
392
+ ? new Error("`tar` is required to extract the example.")
393
+ : error));
394
+ tar.on("close", (status) => status === 0
395
+ ? resolve()
396
+ : reject(new Error(`tar exited with ${status}: ${stderr.trim()}`)));
397
+ });
398
+ tar.stdin?.on("error", () => { });
399
+ tar.stdin?.end(archive);
400
+ await exit;
401
+ const [extracted] = fs.readdirSync(tmp);
402
+ if (!extracted) {
403
+ throw new Error("Downloaded archive is empty.");
404
+ }
405
+ const examplesDir = path.join(tmp, extracted, "examples");
406
+ const available = fs
407
+ .readdirSync(examplesDir, { withFileTypes: true })
408
+ .filter((entry) => entry.isDirectory() &&
409
+ fs.existsSync(path.join(examplesDir, entry.name, "package.json")))
410
+ .map((entry) => entry.name);
411
+ if (!available.includes(name)) {
412
+ throw new Error(`Unknown example "${name}". Available examples:\n ${available.join("\n ")}`);
413
+ }
414
+ return { source: path.join(examplesDir, name), cleanup };
415
+ }
416
+ catch (error) {
417
+ cleanup();
418
+ throw error;
155
419
  }
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
420
  }
180
- function run([command, ...args], options) {
181
- const { status, error } = spawnSync(command, args, options);
182
- if (status != null && status > 0) {
183
- process.exit(status);
421
+ function cancel() {
422
+ prompts.cancel("Operation cancelled");
423
+ process.exit(0);
424
+ }
425
+ function abort(...lines) {
426
+ for (const line of lines) {
427
+ prompts.log.error(line);
184
428
  }
185
- if (error) {
186
- console.error(`\n${command} ${args.join(" ")} error!`);
187
- console.error(error);
188
- process.exit(1);
429
+ prompts.outro("Aborted");
430
+ process.exit(1);
431
+ }
432
+ function parsePackageManager(value) {
433
+ switch (value) {
434
+ case "bun":
435
+ return "bun";
436
+ case "deno":
437
+ return "deno";
438
+ case "npm":
439
+ return "npm";
440
+ case "pnpm":
441
+ return "pnpm";
442
+ case "yarn":
443
+ return "yarn";
444
+ default:
445
+ return undefined;
189
446
  }
190
447
  }
448
+ function detectPackageManager() {
449
+ const userAgent = process.env.npm_config_user_agent;
450
+ if (!userAgent) {
451
+ return undefined;
452
+ }
453
+ const name = userAgent.split(" ")[0]?.split("/")[0];
454
+ return parsePackageManager(name);
455
+ }
456
+ function scriptArgs(pm, script) {
457
+ switch (pm) {
458
+ case "yarn":
459
+ case "pnpm":
460
+ case "bun":
461
+ return [script];
462
+ case "deno":
463
+ return ["task", script];
464
+ case "npm":
465
+ return ["run", script];
466
+ }
467
+ }
468
+ function scriptCommand(pm, script) {
469
+ return [pm, ...scriptArgs(pm, script)].join(" ");
470
+ }
191
471
  function sanitizeTargetDir(targetDir) {
192
- return (targetDir
193
- .trim()
194
- // Only keep alphanumeric, dash, underscore, dot, @, /
195
- .replace(/[^a-zA-Z0-9\-_.@/]/g, "")
196
- // Prevent path traversal
197
- .replace(/\.\./g, "")
198
- // Collapse multiple slashes
199
- .replace(/\/+/g, "/")
200
- // Remove leading/trailing slashes
201
- .replace(/^\/+|\/+$/g, ""));
472
+ return targetDir.trim().replace(/\/+$/g, "");
473
+ }
474
+ // Skip user's SPEC.md and IDE/agent preferences (.idea, .claude, etc.)
475
+ function isSkippedEntry(entry) {
476
+ return ((entry.name.startsWith(".") && entry.isDirectory()) ||
477
+ entry.name === "SPEC.md");
202
478
  }
203
- function isEmpty(path) {
204
- const files = fs.readdirSync(path);
205
- return files.length === 0 || (files.length === 1 && files[0] === ".git");
479
+ function isEmpty(dirPath) {
480
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
481
+ return entries.every(isSkippedEntry);
206
482
  }
207
483
  function emptyDir(dir) {
208
484
  if (!fs.existsSync(dir)) {
209
485
  return;
210
486
  }
211
- for (const file of fs.readdirSync(dir)) {
212
- if (file === ".git") {
487
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
488
+ if (isSkippedEntry(entry)) {
213
489
  continue;
214
490
  }
215
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
491
+ fs.rmSync(path.join(dir, entry.name), { recursive: true, force: true });
216
492
  }
217
493
  }