Skip to content

Commit bd62ca8

Browse files
committed
feat(cli): create initial commit after scaffold completes
1 parent 3c30e12 commit bd62ca8

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/cli/src/create/bin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
writeAgentInstructions,
2828
} from '../utils/agent.ts';
2929
import { detectExistingEditors, selectEditors, writeEditorConfigs } from '../utils/editor.ts';
30-
import { initGitRepository } from '../utils/git.ts';
30+
import { createInitialCommit, initGitRepository } from '../utils/git.ts';
3131
import { renderCliDoc } from '../utils/help.ts';
3232
import { displayRelative } from '../utils/path.ts';
3333
import {
@@ -831,6 +831,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
831831
});
832832
updateCreateProgress('Formatting code');
833833
await runViteFmt(fullPath, options.interactive, undefined, { silent: compactOutput });
834+
if (shouldSetupGit) {
835+
updateCreateProgress('Creating initial commit');
836+
await createInitialCommit(fullPath);
837+
}
834838
clearCreateProgress();
835839
showCreateSummary({
836840
description: describeScaffold(selectedTemplateName, selectedTemplateArgs),
@@ -1033,7 +1037,9 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
10331037
silent: compactOutput,
10341038
});
10351039
if (shouldSetupGit) {
1040+
updateCreateProgress('Creating initial commit');
10361041
await initGitRepository(workspaceInfo.rootDir);
1042+
await createInitialCommit(workspaceInfo.rootDir);
10371043
}
10381044
} else {
10391045
if (shouldMigrateLintFmtTools) {
@@ -1059,6 +1065,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
10591065
});
10601066
updateCreateProgress('Formatting code');
10611067
await runViteFmt(fullPath, options.interactive, undefined, { silent: compactOutput });
1068+
if (shouldSetupGit) {
1069+
updateCreateProgress('Creating initial commit');
1070+
await createInitialCommit(fullPath);
1071+
}
10621072
}
10631073

10641074
clearCreateProgress();

packages/cli/src/utils/git.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ export async function initGitRepository(cwd: string): Promise<boolean> {
99
});
1010
return result.exitCode === 0;
1111
}
12+
13+
export async function createInitialCommit(cwd: string): Promise<boolean> {
14+
await runCommandSilently({
15+
command: 'git',
16+
args: ['add', '-A'],
17+
cwd,
18+
envs: process.env,
19+
});
20+
const result = await runCommandSilently({
21+
command: 'git',
22+
args: ['commit', '-m', 'Initial commit from Vite+'],
23+
cwd,
24+
envs: process.env,
25+
});
26+
return result.exitCode === 0;
27+
}

0 commit comments

Comments
 (0)