FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(create): initialize git once for new monorepos by jong-kyung · Pull Request #2417 · voidzero-dev/vite-plus · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
42 changes: 5 additions & 37 deletions packages/cli/src/create/bin.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'node:path';
import { styleText } from 'node:util';

import * as prompts from '@voidzero-dev/vite-plus-prompts';
import spawn from 'cross-spawn';
import mri from 'mri';

import { vitePlusHeader } from '../../binding/index.js';
Expand Down Expand Up @@ -1010,25 +1009,6 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h

// #region Handle monorepo template
if (templateInfo.command === BuiltinTemplate.monorepo || isBundledMonorepo) {
// Ask up-front so the prompt isn't buried under scaffold output.
let shouldInitGit = shouldSetupGit;
if (options.interactive && !compactOutput && options.git === undefined) {
pauseCreateProgress();
const selected = await prompts.confirm({
message: 'Initialize git repository:',
initialValue: true,
});
resumeCreateProgress();
if (prompts.isCancel(selected)) {
prompts.log.info('Operation cancelled. Skipping git initialization');
shouldInitGit = false;
} else {
shouldInitGit = selected;
}
} else if (shouldInitGit && !compactOutput) {
prompts.log.info('Initializing git repository (default: yes)');
}

updateCreateProgress('Creating monorepo');
await checkProjectDirExists(path.join(workspaceInfo.rootDir, targetDir), options.interactive);
const result = isBundledMonorepo
Expand All @@ -1055,18 +1035,12 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
workspaceInfo.workspacePatterns = scaffoldedWorkspace.workspacePatterns;
workspaceInfo.parentDirs = scaffoldedWorkspace.parentDirs;
workspaceInfo.packages = scaffoldedWorkspace.packages;
if (shouldInitGit) {
const gitResult = spawn.sync('git', ['init'], { stdio: 'pipe', cwd: fullPath });
if (gitResult.status === 0) {
if (!compactOutput) {
prompts.log.success('Git repository initialized');
}
// Establish the destination's intended Git root before hook preflight,
// matching the standalone path below.
if (shouldSetupGit) {
updateCreateProgress('Initializing git repository');
if (await initGitRepository(fullPath)) {
ensureDefaultGitignoreEntries(fullPath);
} else {
prompts.log.warn('Failed to initialize git repository');
if (gitResult.stderr) {
prompts.log.info(gitResult.stderr.toString());
}
}
}
updateCreateProgress('Writing agent instructions');
Expand Down Expand Up @@ -1104,12 +1078,6 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
workspaceInfo.packages,
);
rewriteMonorepo(workspaceInfo, skipStagedMigration, compactOutput);
if (shouldSetupGit) {
updateCreateProgress('Initializing git repository');
if (await initGitRepository(fullPath)) {
ensureDefaultGitignoreEntries(fullPath);
}
}
if (bundled?.monorepo) {
// Wire `create.defaultTemplate: '<scope>'` into the new workspace's
// vite.config.ts so a bare `vp create` from inside it opens the
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/utils/git.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'node:fs';
import path from 'node:path';

import * as prompts from '@voidzero-dev/vite-plus-prompts';

import { runCommandSilently } from './command.ts';

/**
Expand Down Expand Up @@ -28,5 +30,13 @@ export async function initGitRepository(cwd: string): Promise<boolean> {
cwd,
envs: process.env,
});
return result.exitCode === 0;
if (result.exitCode !== 0) {
prompts.log.warn('Failed to initialize git repository');
const stderr = result.stderr.toString().trim();
if (stderr) {
prompts.log.info(stderr);
}
return false;
}
return true;
}
Loading

Back | FazBrowse Home | New Git URL