Skip to content

Commit 2d39f95

Browse files
authored
feat: add option to initialize git repository (#1)
1 parent f329cb2 commit 2d39f95

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/create/prompts.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ProjectConfig {
1313
description: string
1414
username: string
1515
repoName: string
16+
initGit: boolean
1617
}
1718

1819
export async function collectUserInputs(): Promise<ProjectConfig> {
@@ -180,6 +181,19 @@ export async function collectUserInputs(): Promise<ProjectConfig> {
180181

181182
const [username, repoName] = (githubInfo as string).split('/')
182183

184+
let initGit = false
185+
const initGitChoice = await p.confirm({
186+
message: 'Initialize a new git repository?',
187+
initialValue: false,
188+
})
189+
190+
if (p.isCancel(initGitChoice)) {
191+
p.cancel('Operation cancelled')
192+
process.exit(0)
193+
}
194+
195+
initGit = initGitChoice as boolean
196+
183197
return {
184198
variant: variant,
185199
libraryType: libraryType,
@@ -190,6 +204,7 @@ export async function collectUserInputs(): Promise<ProjectConfig> {
190204
description: description,
191205
username,
192206
repoName,
207+
initGit,
193208
}
194209
}
195210

src/create/scaffold.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ export async function scaffoldProject(config: ProjectConfig): Promise<void> {
8282

8383
await $`cd ${projectPath} && bun run build`.nothrow().quiet()
8484

85+
if (config.initGit) {
86+
s.message('Git initializing...')
87+
88+
await $`cd ${projectPath} && git init`.nothrow().quiet()
89+
await $`cd ${projectPath} && git add -A`.nothrow().quiet()
90+
await $`cd ${projectPath} && git commit -m "Initial commit from Bunup"`
91+
.nothrow()
92+
.quiet()
93+
}
94+
8595
s.stop(`${pc.green('✓')} Project scaffolded successfully!`)
8696
} catch (error) {
8797
s.stop(`${pc.red('✗')} Failed to scaffold project`)

0 commit comments

Comments
 (0)