create-skybridge 0.0.0-dev.2 → 0.0.0-dev.4

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,156 @@
1
+ import * as prompts from "@clack/prompts";
2
+ import mri from "mri";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { spawnSync } from "node:child_process";
6
+ const argv = mri(process.argv.slice(2), {
7
+ boolean: ["help", "overwrite"],
8
+ alias: { h: "help" },
9
+ });
10
+ const cwd = process.cwd();
11
+ const TEMPLATE_REPO = "https://github.com/alpic-ai/apps-sdk-template";
12
+ const defaultProjectName = "skybridge-project";
13
+ // prettier-ignore
14
+ const helpMessage = `\
15
+ Usage: create-skybridge [OPTION]... [DIRECTORY]
16
+
17
+ Create a new Skybridge project by cloning the starter template.
18
+
19
+ Options:
20
+ -h, --help show this help message
21
+ --overwrite remove existing files in target directory
22
+
23
+ Examples:
24
+ create-skybridge my-app
25
+ create-skybridge . --overwrite
26
+ `;
27
+ function run([command, ...args], options) {
28
+ if (!command) {
29
+ throw new Error("Command is required");
30
+ }
31
+ const { status, error } = spawnSync(command, args, options);
32
+ if (status != null && status > 0) {
33
+ process.exit(status);
34
+ }
35
+ if (error) {
36
+ console.error(`\n${command} ${args.join(" ")} error!`);
37
+ console.error(error);
38
+ process.exit(1);
39
+ }
40
+ }
41
+ async function init() {
42
+ const argTargetDir = argv._[0]
43
+ ? formatTargetDir(String(argv._[0]))
44
+ : undefined;
45
+ const argOverwrite = argv.overwrite;
46
+ const help = argv.help;
47
+ if (help) {
48
+ console.log(helpMessage);
49
+ return;
50
+ }
51
+ const interactive = process.stdin.isTTY;
52
+ const cancel = () => prompts.cancel("Operation cancelled");
53
+ // 1. Get project name and target dir
54
+ let targetDir = argTargetDir;
55
+ if (!targetDir) {
56
+ if (interactive) {
57
+ const projectName = await prompts.text({
58
+ message: "Project name:",
59
+ defaultValue: defaultProjectName,
60
+ placeholder: defaultProjectName,
61
+ validate: (value) => {
62
+ return value.length === 0 || formatTargetDir(value).length > 0
63
+ ? undefined
64
+ : "Invalid project name";
65
+ },
66
+ });
67
+ if (prompts.isCancel(projectName))
68
+ return cancel();
69
+ targetDir = formatTargetDir(projectName);
70
+ }
71
+ else {
72
+ targetDir = defaultProjectName;
73
+ }
74
+ }
75
+ // 2. Handle directory if exist and not empty
76
+ if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
77
+ let overwrite = argOverwrite ? "yes" : undefined;
78
+ if (!overwrite) {
79
+ if (interactive) {
80
+ const res = await prompts.select({
81
+ message: (targetDir === "."
82
+ ? "Current directory"
83
+ : `Target directory "${targetDir}"`) +
84
+ ` is not empty. Please choose how to proceed:`,
85
+ options: [
86
+ {
87
+ label: "Cancel operation",
88
+ value: "no",
89
+ },
90
+ {
91
+ label: "Remove existing files and continue",
92
+ value: "yes",
93
+ },
94
+ ],
95
+ });
96
+ if (prompts.isCancel(res))
97
+ return cancel();
98
+ overwrite = res;
99
+ }
100
+ else {
101
+ overwrite = "no";
102
+ }
103
+ }
104
+ switch (overwrite) {
105
+ case "yes":
106
+ emptyDir(targetDir);
107
+ break;
108
+ case "no":
109
+ cancel();
110
+ return;
111
+ }
112
+ }
113
+ const root = path.join(cwd, targetDir);
114
+ // 3. Clone the repository
115
+ prompts.log.step(`Cloning template from ${TEMPLATE_REPO}...`);
116
+ try {
117
+ // Clone directly to target directory
118
+ run(["git", "clone", "--depth", "1", TEMPLATE_REPO, root], {
119
+ stdio: "inherit",
120
+ });
121
+ // Remove .git directory to start fresh
122
+ const gitDir = path.join(root, ".git");
123
+ if (fs.existsSync(gitDir)) {
124
+ fs.rmSync(gitDir, { recursive: true, force: true });
125
+ }
126
+ prompts.log.success(`Project created in ${root}`);
127
+ prompts.outro(`Done! Next steps:\n\n cd ${targetDir}\n pnpm install\n pnpm dev`);
128
+ }
129
+ catch (error) {
130
+ prompts.log.error("Failed to clone repository");
131
+ console.error(error);
132
+ process.exit(1);
133
+ }
134
+ }
135
+ function formatTargetDir(targetDir) {
136
+ return targetDir.trim().replace(/\/+$/g, "");
137
+ }
138
+ function isEmpty(path) {
139
+ const files = fs.readdirSync(path);
140
+ return files.length === 0 || (files.length === 1 && files[0] === ".git");
141
+ }
142
+ function emptyDir(dir) {
143
+ if (!fs.existsSync(dir)) {
144
+ return;
145
+ }
146
+ for (const file of fs.readdirSync(dir)) {
147
+ if (file === ".git") {
148
+ continue;
149
+ }
150
+ fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
151
+ }
152
+ }
153
+ init().catch((e) => {
154
+ console.error(e);
155
+ process.exit(1);
156
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-skybridge",
3
- "version": "0.0.0-dev.2",
3
+ "version": "0.0.0-dev.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Alpic",
@@ -11,11 +11,10 @@
11
11
  "index.js",
12
12
  "dist"
13
13
  ],
14
- "dependencies": {
15
- "@clack/prompts": "^0.11.0",
16
- "mri": "^1.2.0"
17
- },
14
+ "dependencies": {},
18
15
  "devDependencies": {
16
+ "@clack/prompts": "^0.11.0",
17
+ "mri": "^1.2.0",
19
18
  "@types/node": "^25.0.3",
20
19
  "picocolors": "^1.1.1",
21
20
  "typescript": "^5.9.3"