Skip to content

Commit 3d0a15c

Browse files
committed
fix: updated code with removal of duplicate code, and comments from usability testing.
1 parent b823509 commit 3d0a15c

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/__tests__/create.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('runCreate', () => {
117117
type: 'input',
118118
name: 'projectDirectory',
119119
message: expect.stringContaining('directory where you want to create the project'),
120-
default: 'my-app',
120+
default: path.resolve('my-app'),
121121
}),
122122
])
123123
);
@@ -136,7 +136,7 @@ describe('runCreate', () => {
136136
expect.objectContaining({
137137
type: 'list',
138138
name: 'templateName',
139-
message: 'Select a template:',
139+
message: 'Select a project template that will be used to create your project:',
140140
choices: expect.any(Array),
141141
}),
142142
])
@@ -261,7 +261,7 @@ describe('runCreate', () => {
261261
await runCreate(projectDir, 'starter');
262262

263263
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Project created successfully'));
264-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining(`cd ${projectDir}`));
264+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining(`cd ${projectPath}`));
265265
});
266266

267267
it('cleans up project directory and rethrows when clone fails', async () => {

src/create.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,22 @@ export async function runCreate(
4141
type: 'input',
4242
name: 'projectDirectory',
4343
message: 'Please provide the directory where you want to create the project?',
44-
default: 'my-app',
44+
default: path.resolve('my-app'),
4545
},
4646
]);
4747
projectDirectory = projectDirAnswer.projectDirectory;
4848
}
4949

50+
const projectPath = path.resolve(projectDirectory?.trim() || 'my-app');
51+
5052
// If template name is not provided, show available templates and let user select
5153
if (!templateName) {
52-
console.log('\n📋 Available templates:\n');
53-
templatesToUse.forEach(t => {
54-
console.log(` ${t.name.padEnd(12)} - ${t.description}`);
55-
});
56-
console.log('');
57-
54+
5855
const templateQuestion = [
5956
{
6057
type: 'list',
6158
name: 'templateName',
62-
message: 'Select a template:',
59+
message: 'Select a project template that will be used to create your project:',
6360
choices: templatesToUse.map(t => ({
6461
name: `${t.name} - ${t.description}`,
6562
value: t.name,
@@ -85,9 +82,6 @@ export async function runCreate(
8582

8683
const templateRepoUrl = options?.ssh && template.repoSSH ? template.repoSSH : template.repo;
8784

88-
// Define the full path for the new project (projectDirectory is set above via arg or prompt)
89-
const dir = projectDirectory ?? 'my-app';
90-
const projectPath = path.resolve(dir);
9185
console.log(`Cloning template "${templateName}" from ${templateRepoUrl} into ${projectPath}...`);
9286

9387
try {
@@ -165,7 +159,7 @@ export async function runCreate(
165159
// Let the user know the project was created successfully
166160
console.log('\n✨ Project created successfully! ✨\n');
167161
console.log(`To get started:`);
168-
console.log(` cd ${dir}`);
162+
console.log(` cd ${projectPath}`);
169163
console.log(' Happy coding! 🚀');
170164
} catch (error) {
171165
console.error('❌ An error occurred:');

src/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async function ensureInitialCommit(projectPath: string): Promise<void> {
8282
'Could not create the initial git commit. Set your git identity, then try again:\n' +
8383
' git config --global user.name "Your Name"\n' +
8484
' git config --global user.email "you@example.com"',
85+
{ cause: err },
8586
);
8687
}
8788
throw err;

0 commit comments

Comments
 (0)