Skip to content

Commit 7daf7e4

Browse files
committed
fix(release): exit process when ctrl+c is pressed on github release recovery
1 parent def8a4f commit 7daf7e4

File tree

1 file changed

+47
-38
lines changed
  • packages/nx/src/command-line/release/utils

1 file changed

+47
-38
lines changed

packages/nx/src/command-line/release/utils/github.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,45 +103,27 @@ export async function createOrUpdateGithubRelease(
103103
}
104104
}
105105

106-
const reply = await prompt<{ open: 'Yes' | 'No' }>([
107-
{
108-
name: 'open',
109-
message:
110-
'Do you want to finish creating the release manually in your browser?',
111-
type: 'autocomplete',
112-
choices: [
113-
{
114-
name: 'Yes',
115-
hint: 'It will pre-populate the form for you',
116-
},
117-
{
118-
name: 'No',
119-
},
120-
],
121-
initial: 0,
122-
},
123-
]).catch(() => {
124-
return { open: 'No' };
125-
});
126-
127-
if (reply.open === 'Yes') {
128-
const open = require('open');
129-
await open(result.url)
130-
.then(() => {
131-
console.info(
132-
`\nFollow up in the browser to manually create the release:\n\n` +
133-
chalk.underline(chalk.cyan(result.url)) +
134-
`\n`
135-
);
136-
})
137-
.catch(() => {
138-
console.info(
139-
`Open this link to manually create a release: \n` +
140-
chalk.underline(chalk.cyan(result.url)) +
141-
'\n'
142-
);
143-
});
106+
const shouldContinueInGitHub = await promptForContinueInGitHub();
107+
if (!shouldContinueInGitHub) {
108+
return;
144109
}
110+
111+
const open = require('open');
112+
await open(result.url)
113+
.then(() => {
114+
console.info(
115+
`\nFollow up in the browser to manually create the release:\n\n` +
116+
chalk.underline(chalk.cyan(result.url)) +
117+
`\n`
118+
);
119+
})
120+
.catch(() => {
121+
console.info(
122+
`Open this link to manually create a release: \n` +
123+
chalk.underline(chalk.cyan(result.url)) +
124+
'\n'
125+
);
126+
});
145127
}
146128

147129
/**
@@ -170,6 +152,33 @@ export async function createOrUpdateGithubRelease(
170152
}
171153
}
172154

155+
async function promptForContinueInGitHub(): Promise<boolean> {
156+
try {
157+
const reply = await prompt<{ open: 'Yes' | 'No' }>([
158+
{
159+
name: 'open',
160+
message:
161+
'Do you want to finish creating the release manually in your browser?',
162+
type: 'autocomplete',
163+
choices: [
164+
{
165+
name: 'Yes',
166+
hint: 'It will pre-populate the form for you',
167+
},
168+
{
169+
name: 'No',
170+
},
171+
],
172+
initial: 0,
173+
},
174+
]);
175+
return reply.open === 'Yes';
176+
} catch (e) {
177+
// Handle the case where the user exits the prompt with ctrl+c
178+
process.exit(1);
179+
}
180+
}
181+
173182
async function syncGithubRelease(
174183
githubRequestConfig: GithubRequestConfig,
175184
release: GithubReleaseOptions,

0 commit comments

Comments
 (0)