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

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/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "create-skybridge",
3
- "version": "0.0.0-dev.1",
3
+ "version": "0.0.0-dev.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Alpic",
7
7
  "bin": {
8
- "create-skybridge": "dist/index.js"
8
+ "create-skybridge": "index.js"
9
9
  },
10
10
  "files": [
11
11
  "index.js",
@@ -21,7 +21,7 @@
21
21
  "typescript": "^5.9.3"
22
22
  },
23
23
  "scripts": {
24
- "build": "tsc && echo '#!/usr/bin/env node' | cat - dist/index.js > temp && mv temp dist/index.js",
24
+ "build": "tsc",
25
25
  "test:type": "tsc --noEmit",
26
26
  "test:format": "biome ci"
27
27
  }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/index.js DELETED
@@ -1,157 +0,0 @@
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
- });