Feat: Add support for creating git prototypes to cli. #12
Conversation
| 'repo', | ||
| 'create', | ||
| options.repoName, | ||
| '--public', |
There was a problem hiding this comment.
Do we want to provide an option to make a private project?
There was a problem hiding this comment.
We could have a default...and maybe the default is public, but I would think maybe the opposite actually.
There was a problem hiding this comment.
Good point let me update this to be private by default.
| } | ||
|
|
||
| try { | ||
| await execa('git', ['add', '.'], { cwd, stdio: 'inherit' }); |
There was a problem hiding this comment.
Is there no selective adding ability? What if they only want to push a particular file or directory within the project?
There was a problem hiding this comment.
After our meeting yesterday probably best to leave this out initially for the designer profile.
| ]); | ||
|
|
||
| const commitMessage = (message as string).trim(); | ||
| if (!commitMessage) { |
There was a problem hiding this comment.
It seems this condition won't even be reached due to the validate function for the commit message above requiring a string, right? I think it can be removed, but maybe I'm misunderstanding.
There was a problem hiding this comment.
yeah you're correct.
There was a problem hiding this comment.
Was this updated with the latest changes? I think this problem still exists.
| if (err && typeof err === 'object' && 'exitCode' in err) { | ||
| const code = (err as { exitCode?: number }).exitCode; | ||
| if (code === 128) { | ||
| console.error( | ||
| '\n❌ Pull failed. You may need to set a remote (e.g. "git remote add origin <url>") or run "gh auth login".\n', | ||
| ); | ||
| } else { | ||
| console.error('\n❌ Pull failed. See the output above for details.\n'); | ||
| } | ||
| } else { | ||
| console.error('\n❌ An error occurred:'); | ||
| if (err instanceof Error) console.error(` ${err.message}\n`); | ||
| else console.error(` ${String(err)}\n`); | ||
| } | ||
| throw err; |
There was a problem hiding this comment.
Seems this is duplicated in the save.ts file...instead of repeating the code here, maybe make a helper called something like handleGitError?
| console.log('\n✅ Changes saved and pushed to GitHub successfully.\n'); | ||
| } catch (err) { | ||
| if (err && typeof err === 'object' && 'exitCode' in err) { | ||
| const code = (err as { exitCode?: number }).exitCode; |
There was a problem hiding this comment.
I think you can remove this casting if you update the condition above to something like if (err instanceof ExecaError) instead of if (err && typeof err === 'object' && 'exitCode' in err)
There was a problem hiding this comment.
Looks like it could be other types of errors so updated to Error instead of ExecaError.
| { | ||
| type: 'confirm', | ||
| name: 'useSSH', | ||
| message: 'Use SSH URL for cloning?', |
There was a problem hiding this comment.
Will non-devs understand this question and how to answer it?
There was a problem hiding this comment.
removed the question you have to pass it in now.
src/cli.ts
Outdated
There was a problem hiding this comment.
Maybe the create logic could be separated into its own function to make the CLI more readable here, and could be unit tested separately.
| } | ||
|
|
||
| await execa('git', ['push'], { cwd, stdio: 'inherit' }); | ||
| console.log('\n✅ Changes saved and pushed to GitHub successfully.\n'); |
There was a problem hiding this comment.
If the commit succeeds on line 64 but push fails here, the user sees an error and might think nothing was saved. Worth letting them know their changes were committed locally?
| } else { | ||
| console.error('\n❌ Save or push failed. See the output above for details.\n'); | ||
| } | ||
| } else if (!(err instanceof Error && err.message === 'No remote origin')) { |
There was a problem hiding this comment.
This couples the catch to the exact string 'No remote origin' — if someone changes the message on line 80, the catch silently starts double-logging. Would a custom error class make this safer?
| await execa('git', ['push'], { cwd, stdio: 'inherit' }); | ||
| console.log('\n✅ Changes saved and pushed to GitHub successfully.\n'); | ||
| } catch (err) { | ||
| if (err && typeof err === 'object' && 'exitCode' in err) { |
There was a problem hiding this comment.
This error narrowing pattern is duplicated in load.ts too — maybe a shared isExecaError helper?
| try { | ||
| await execa('gh', ['api', `repos/${owner}/${repoName}`], { reject: true }); | ||
| return true; | ||
| } catch { |
There was a problem hiding this comment.
repoExists returns false for any error, not just "repo doesn't exist." A network timeout or auth failure would silently proceed to create a repo that might already exist. Should non-404 errors be surfaced?
| } | ||
|
|
||
| const pkgJson = await fs.readJson(pkgJsonPath); | ||
| const projectName = (pkgJson.name as string) ?? 'my-project'; |
There was a problem hiding this comment.
?? 'my-project' only catches null/undefined — if name is an empty string in a bad package.json, sanitizeRepoName gets it. Worth a more defensive check?
| '--public', | ||
| `--source=${options.projectPath}`, | ||
| '--remote=origin', | ||
| '--push', |
There was a problem hiding this comment.
createRepo passes --push here, but when called from save, the flow also does git push after. Isn't the second push redundant?
|
|
||
| try { | ||
| console.log('📥 Pulling latest updates from GitHub...\n'); | ||
| await execa('git', ['pull'], { cwd, stdio: 'inherit' }); |
There was a problem hiding this comment.
Will beginners understand git's error when no upstream tracking branch is set? Might be worth a friendlier message.
| ]); | ||
|
|
||
| const commitMessage = (message as string).trim(); | ||
| if (!commitMessage) { |
There was a problem hiding this comment.
Was this updated with the latest changes? I think this problem still exists.
|
Capturing outstanding comments in follow up issue and merging this issue. |
Closes issue #7 :