Skip to content

Commit e15961a

Browse files
gracefullightclaude
andcommitted
refactor(create-fullstack-starter): extract gh install/auth into separate functions
Reduce cognitive complexity of maybePromptToStarRepository by extracting ensureGhInstalled and ensureGhAuthenticated helper functions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 007e6b9 commit e15961a

1 file changed

Lines changed: 40 additions & 30 deletions

File tree

  • packages/create-fullstack-starter/src

packages/create-fullstack-starter/src/index.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,45 +82,55 @@ function ensureTargetDirectoryIsAvailable(targetDir: string, resolvedPath: strin
8282
}
8383
}
8484

85-
async function maybePromptToStarRepository(): Promise<void> {
86-
if (!isGhInstalled()) {
87-
const installCmd = getGhInstallCommand();
88-
const shouldInstall = await p.confirm({
89-
message: `GitHub CLI (gh) is not installed. Install with ${chalk.cyan(installCmd)}?`,
90-
initialValue: false,
91-
});
85+
async function ensureGhInstalled(): Promise<boolean> {
86+
if (isGhInstalled()) {
87+
return true;
88+
}
9289

93-
if (p.isCancel(shouldInstall) || !shouldInstall) {
94-
return;
95-
}
90+
const installCmd = getGhInstallCommand();
91+
const shouldInstall = await p.confirm({
92+
message: `GitHub CLI (gh) is not installed. Install with ${chalk.cyan(installCmd)}?`,
93+
initialValue: false,
94+
});
9695

97-
const s = p.spinner();
98-
s.start("Installing GitHub CLI...");
99-
const result = spawnSync(installCmd, { shell: true, stdio: "pipe" });
96+
if (p.isCancel(shouldInstall) || !shouldInstall) {
97+
return false;
98+
}
10099

101-
if (result.status !== 0) {
102-
s.stop("Installation failed.");
103-
return;
104-
}
100+
const s = p.spinner();
101+
s.start("Installing GitHub CLI...");
102+
const result = spawnSync(installCmd, { shell: true, stdio: "pipe" });
105103

106-
s.stop("GitHub CLI installed!");
104+
if (result.status !== 0) {
105+
s.stop("Installation failed.");
106+
return false;
107107
}
108108

109-
if (!isGhAuthenticated()) {
110-
const shouldAuth = await p.confirm({
111-
message: `GitHub CLI is not authenticated. Run ${chalk.cyan("gh auth login")}?`,
112-
initialValue: false,
113-
});
109+
s.stop("GitHub CLI installed!");
110+
return true;
111+
}
114112

115-
if (p.isCancel(shouldAuth) || !shouldAuth) {
116-
return;
117-
}
113+
async function ensureGhAuthenticated(): Promise<boolean> {
114+
if (isGhAuthenticated()) {
115+
return true;
116+
}
117+
118+
const shouldAuth = await p.confirm({
119+
message: `GitHub CLI is not authenticated. Run ${chalk.cyan("gh auth login")}?`,
120+
initialValue: false,
121+
});
122+
123+
if (p.isCancel(shouldAuth) || !shouldAuth) {
124+
return false;
125+
}
118126

119-
spawnSync("gh", ["auth", "login"], { stdio: "inherit" });
127+
spawnSync("gh", ["auth", "login"], { stdio: "inherit" });
128+
return isGhAuthenticated();
129+
}
120130

121-
if (!isGhAuthenticated()) {
122-
return;
123-
}
131+
async function maybePromptToStarRepository(): Promise<void> {
132+
if (!(await ensureGhInstalled()) || !(await ensureGhAuthenticated())) {
133+
return;
124134
}
125135

126136
if (isAlreadyStarred()) {

0 commit comments

Comments
 (0)