create-skybridge 0.0.0-dev.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alpic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import * as prompts from "@clack/prompts";
3
+ import mri from "mri";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { spawnSync } from "node:child_process";
7
+ const argv = mri(process.argv.slice(2), {
8
+ boolean: ["help", "overwrite"],
9
+ alias: { h: "help" },
10
+ });
11
+ const cwd = process.cwd();
12
+ const TEMPLATE_REPO = "https://github.com/alpic-ai/apps-sdk-template";
13
+ const defaultTargetDir = "skybridge-project";
14
+ // prettier-ignore
15
+ const helpMessage = `\
16
+ Usage: create-skybridge [OPTION]... [DIRECTORY]
17
+
18
+ Create a new Skybridge project by cloning the starter template.
19
+
20
+ Options:
21
+ -h, --help show this help message
22
+ --overwrite remove existing files in target directory
23
+
24
+ Examples:
25
+ create-skybridge my-app
26
+ create-skybridge . --overwrite
27
+ `;
28
+ function run([command, ...args], options) {
29
+ if (!command) {
30
+ throw new Error("Command is required");
31
+ }
32
+ const { status, error } = spawnSync(command, args, options);
33
+ if (status != null && status > 0) {
34
+ process.exit(status);
35
+ }
36
+ if (error) {
37
+ console.error(`\n${command} ${args.join(" ")} error!`);
38
+ console.error(error);
39
+ process.exit(1);
40
+ }
41
+ }
42
+ async function init() {
43
+ const argTargetDir = argv._[0]
44
+ ? formatTargetDir(String(argv._[0]))
45
+ : undefined;
46
+ const argOverwrite = argv.overwrite;
47
+ const help = argv.help;
48
+ if (help) {
49
+ console.log(helpMessage);
50
+ return;
51
+ }
52
+ const interactive = process.stdin.isTTY;
53
+ const cancel = () => prompts.cancel("Operation cancelled");
54
+ // 1. Get project name and target dir
55
+ let targetDir = argTargetDir;
56
+ if (!targetDir) {
57
+ if (interactive) {
58
+ const projectName = await prompts.text({
59
+ message: "Project name:",
60
+ defaultValue: defaultTargetDir,
61
+ placeholder: defaultTargetDir,
62
+ validate: (value) => {
63
+ return value.length === 0 || formatTargetDir(value).length > 0
64
+ ? undefined
65
+ : "Invalid project name";
66
+ },
67
+ });
68
+ if (prompts.isCancel(projectName))
69
+ return cancel();
70
+ targetDir = formatTargetDir(projectName);
71
+ }
72
+ else {
73
+ targetDir = defaultTargetDir;
74
+ }
75
+ }
76
+ // 2. Handle directory if exist and not empty
77
+ if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
78
+ let overwrite = argOverwrite ? "yes" : undefined;
79
+ if (!overwrite) {
80
+ if (interactive) {
81
+ const res = await prompts.select({
82
+ message: (targetDir === "."
83
+ ? "Current directory"
84
+ : `Target directory "${targetDir}"`) +
85
+ ` is not empty. Please choose how to proceed:`,
86
+ options: [
87
+ {
88
+ label: "Cancel operation",
89
+ value: "no",
90
+ },
91
+ {
92
+ label: "Remove existing files and continue",
93
+ value: "yes",
94
+ },
95
+ ],
96
+ });
97
+ if (prompts.isCancel(res))
98
+ return cancel();
99
+ overwrite = res;
100
+ }
101
+ else {
102
+ overwrite = "no";
103
+ }
104
+ }
105
+ switch (overwrite) {
106
+ case "yes":
107
+ emptyDir(targetDir);
108
+ break;
109
+ case "no":
110
+ cancel();
111
+ return;
112
+ }
113
+ }
114
+ const root = path.join(cwd, targetDir);
115
+ // 3. Clone the repository
116
+ prompts.log.step(`Cloning template from ${TEMPLATE_REPO}...`);
117
+ try {
118
+ // Clone directly to target directory
119
+ run(["git", "clone", "--depth", "1", TEMPLATE_REPO, root], {
120
+ stdio: "inherit",
121
+ });
122
+ // Remove .git directory to start fresh
123
+ const gitDir = path.join(root, ".git");
124
+ if (fs.existsSync(gitDir)) {
125
+ fs.rmSync(gitDir, { recursive: true, force: true });
126
+ }
127
+ prompts.log.success(`Project created in ${root}`);
128
+ prompts.outro(`Done! Next steps:\n\n cd ${targetDir}\n pnpm install\n pnpm dev`);
129
+ }
130
+ catch (error) {
131
+ prompts.log.error("Failed to clone repository");
132
+ console.error(error);
133
+ process.exit(1);
134
+ }
135
+ }
136
+ function formatTargetDir(targetDir) {
137
+ return targetDir.trim().replace(/\/+$/g, "");
138
+ }
139
+ function isEmpty(path) {
140
+ const files = fs.readdirSync(path);
141
+ return files.length === 0 || (files.length === 1 && files[0] === ".git");
142
+ }
143
+ function emptyDir(dir) {
144
+ if (!fs.existsSync(dir)) {
145
+ return;
146
+ }
147
+ for (const file of fs.readdirSync(dir)) {
148
+ if (file === ".git") {
149
+ continue;
150
+ }
151
+ fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
152
+ }
153
+ }
154
+ init().catch((e) => {
155
+ console.error(e);
156
+ process.exit(1);
157
+ });
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "./dist/index.js";
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "create-skybridge",
3
+ "version": "0.0.0-dev.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "author": "Alpic",
7
+ "bin": {
8
+ "create-skybridge": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "dist"
13
+ ],
14
+ "dependencies": {
15
+ "@clack/prompts": "^0.11.0",
16
+ "mri": "^1.2.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^25.0.3",
20
+ "picocolors": "^1.1.1",
21
+ "typescript": "^5.9.3"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc && echo '#!/usr/bin/env node' | cat - dist/index.js > temp && mv temp dist/index.js",
25
+ "test:type": "tsc --noEmit",
26
+ "test:format": "biome ci"
27
+ }
28
+ }