create-ely 0.1.1 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ely",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Scaffold production-ready ElysiaJS projects with ease using Bun - choose between backend-only or full-stack monorepo templates",
5
5
  "type": "module",
6
6
  "author": {
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ async function main() {
19
19
  const args = process.argv.slice(2);
20
20
  const projectNameArg = args[0];
21
21
 
22
+ // Step 1: Select project type
22
23
  const projectType = await clack.select({
23
24
  message: 'What would you like to create?',
24
25
  options: [
@@ -40,20 +41,29 @@ async function main() {
40
41
  process.exit(0);
41
42
  }
42
43
 
44
+ // Step 2: Get project name
43
45
  let projectName: string | symbol;
44
46
 
45
47
  // If project name was provided as argument and is valid, use it
46
48
  if (projectNameArg && /^[a-z0-9-]+$/.test(projectNameArg)) {
47
49
  projectName = projectNameArg;
48
50
  } else {
49
- // Otherwise, prompt for it
51
+ // Otherwise, prompt for it with default value
50
52
  projectName = await clack.text({
51
53
  message: 'Project name:',
52
- placeholder: 'my-elysia-app',
54
+ placeholder: 'my-ely-app',
55
+ initialValue: 'my-ely-app',
53
56
  validate: (value) => {
54
- if (!value) return 'Project name is required';
55
- if (!/^[a-z0-9-]+$/.test(value))
57
+ if (!value || value.trim() === '') {
58
+ return 'Project name is required';
59
+ }
60
+ const trimmed = value.trim();
61
+ if (!/^[a-z0-9-]+$/.test(trimmed)) {
56
62
  return 'Project name must contain only lowercase letters, numbers, and hyphens';
63
+ }
64
+ if (trimmed.startsWith('-') || trimmed.endsWith('-')) {
65
+ return 'Project name cannot start or end with a hyphen';
66
+ }
57
67
  return undefined;
58
68
  },
59
69
  });
@@ -62,22 +72,31 @@ async function main() {
62
72
  clack.cancel('Operation cancelled');
63
73
  process.exit(0);
64
74
  }
75
+
76
+ // Trim and normalize the project name
77
+ projectName = (projectName as string).trim();
65
78
  }
66
79
 
67
80
  const targetDir = join(process.cwd(), projectName as string);
68
81
 
69
- if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
70
- const shouldOverwrite = await clack.confirm({
71
- message: `Directory "${String(projectName)}" already exists and is not empty. Overwrite it?`,
72
- initialValue: false,
73
- });
82
+ // Step 3: Check if directory exists and handle it
83
+ if (existsSync(targetDir)) {
84
+ const dirContents = readdirSync(targetDir);
85
+ const isEmpty = dirContents.length === 0;
74
86
 
75
- if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {
76
- clack.cancel('Operation cancelled');
77
- process.exit(0);
78
- }
87
+ if (!isEmpty) {
88
+ const shouldOverwrite = await clack.confirm({
89
+ message: `Directory "${String(projectName)}" already exists and is not empty. Overwrite it?`,
90
+ initialValue: false,
91
+ });
79
92
 
80
- rmSync(targetDir, { recursive: true, force: true });
93
+ if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {
94
+ clack.cancel('Operation cancelled');
95
+ process.exit(0);
96
+ }
97
+
98
+ rmSync(targetDir, { recursive: true, force: true });
99
+ }
81
100
  }
82
101
 
83
102
  const spinner = clack.spinner();
@@ -137,7 +156,7 @@ async function main() {
137
156
  }
138
157
  }
139
158
 
140
- spinner.stop('Project created successfully!');
159
+ spinner.stop('Project structure created!');
141
160
 
142
161
  const s = clack.spinner();
143
162
  s.start('Installing dependencies...');
@@ -156,6 +175,97 @@ async function main() {
156
175
 
157
176
  s.stop('Dependencies installed!');
158
177
 
178
+ // Step 4: Ask if user wants to initialize git
179
+ const initGit = await clack.confirm({
180
+ message: 'Initialize git repository?',
181
+ initialValue: true,
182
+ });
183
+
184
+ if (clack.isCancel(initGit)) {
185
+ clack.cancel('Operation cancelled');
186
+ process.exit(0);
187
+ }
188
+
189
+ if (initGit) {
190
+ // Check if git is available
191
+ const gitCheckProc = Bun.spawn(['git', '--version'], {
192
+ stdout: 'pipe',
193
+ stderr: 'pipe',
194
+ });
195
+ await gitCheckProc.exited;
196
+
197
+ if (gitCheckProc.exitCode !== 0) {
198
+ clack.log.warn(
199
+ 'Git is not installed or not available. Skipping git initialization.',
200
+ );
201
+ } else {
202
+ const gitSpinner = clack.spinner();
203
+ gitSpinner.start('Initializing git repository...');
204
+
205
+ try {
206
+ const gitInitProc = Bun.spawn(['git', 'init'], {
207
+ cwd: targetDir,
208
+ stdout: 'pipe',
209
+ stderr: 'pipe',
210
+ });
211
+ await gitInitProc.exited;
212
+
213
+ if (gitInitProc.exitCode === 0) {
214
+ gitSpinner.stop('Git repository initialized');
215
+
216
+ // Make initial commit
217
+ gitSpinner.start('Creating initial commit...');
218
+
219
+ const gitAddProc = Bun.spawn(['git', 'add', '.'], {
220
+ cwd: targetDir,
221
+ stdout: 'pipe',
222
+ stderr: 'pipe',
223
+ });
224
+ await gitAddProc.exited;
225
+
226
+ if (gitAddProc.exitCode === 0) {
227
+ const gitCommitProc = Bun.spawn(
228
+ ['git', 'commit', '-m', 'Initial commit'],
229
+ {
230
+ cwd: targetDir,
231
+ stdout: 'pipe',
232
+ stderr: 'pipe',
233
+ },
234
+ );
235
+ await gitCommitProc.exited;
236
+
237
+ if (gitCommitProc.exitCode === 0) {
238
+ gitSpinner.stop('Initial commit created');
239
+ } else {
240
+ gitSpinner.stop('Git initialized (commit failed)');
241
+ clack.log.warn(
242
+ 'Failed to create initial commit. You can commit manually later.',
243
+ );
244
+ }
245
+ } else {
246
+ gitSpinner.stop('Git initialized (add failed)');
247
+ clack.log.warn(
248
+ 'Failed to stage files. You can add them manually later.',
249
+ );
250
+ }
251
+ } else {
252
+ gitSpinner.stop('Failed to initialize git');
253
+ clack.log.warn(
254
+ 'Git initialization failed. You can initialize manually later.',
255
+ );
256
+ }
257
+ } catch {
258
+ gitSpinner.stop('Git initialization failed');
259
+ clack.log.warn(
260
+ 'An error occurred during git initialization. You can initialize manually later.',
261
+ );
262
+ }
263
+ }
264
+ }
265
+
266
+ // Prepare next steps message
267
+ const projectTypeLabel =
268
+ projectType === 'monorepo' ? 'monorepo' : 'backend';
159
269
  const nextSteps =
160
270
  projectType === 'monorepo'
161
271
  ? ` cd ${String(projectName)}
@@ -165,12 +275,16 @@ async function main() {
165
275
  bun run dev # Start backend on http://localhost:3000`;
166
276
 
167
277
  clack.outro(`
168
- Success! Your ElysiaJS project is ready.
278
+ Success! Your ElysiaJS ${projectTypeLabel} project is ready.
279
+
280
+ 📁 Project created at: ${targetDir}
169
281
 
170
- Next steps:
282
+ 🚀 Next steps:
171
283
  ${nextSteps}
172
284
 
173
- Check out the README.md for more information.
285
+ 📚 Check out the README.md for more information.
286
+
287
+ Happy coding! 🎉
174
288
  `);
175
289
  } catch (error) {
176
290
  spinner.stop('Failed to create project');
@@ -0,0 +1,4 @@
1
+ telemetry = false
2
+
3
+ [test]
4
+ root = "src/tests"
@@ -1 +0,0 @@
1
- VITE_API_URL=http://localhost:3000