Skip to content

Commit 057384b

Browse files
authored
feat: ask to restore on failure (#410)
<!-- 👋 Hi, thanks for sending a PR to template-typescript-node-package! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #353 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview - Added the "skip-restore" flag - Added the restore changes prompt in case of failure. I'm not sure about the copy and the placement, but I'd appreciate your review :)
1 parent b1e8b54 commit 057384b

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

script/setup-test-e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const title = "New Title Test";
1010
const repository = "new-repository-test";
1111

1212
const result =
13-
await $`pnpm run setup --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api`;
13+
await $`pnpm run setup --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api --skip-restore`;
1414
console.log("Result from pnpm run setup:", result);
1515

1616
const newPackageJson = JSON.parse(

script/setup.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ import replace from "replace-in-file";
1212
import { titleCase } from "title-case";
1313

1414
let exitCode = 0;
15+
let skipRestore = true;
1516
const s = prompts.spinner();
1617

18+
function handlePromptCancel(value) {
19+
if (prompts.isCancel(value)) {
20+
prompts.cancel(
21+
"Operation cancelled. Exiting setup - maybe another time? 👋"
22+
);
23+
process.exit(0);
24+
}
25+
}
26+
1727
try {
1828
console.clear();
1929
console.log(
@@ -31,12 +41,15 @@ try {
3141
repository: { type: "string" },
3242
title: { type: "string" },
3343
"skip-api": { type: "boolean" },
44+
"skip-restore": { type: "boolean" },
3445
"skip-uninstalls": { type: "boolean" },
3546
},
3647
tokens: true,
3748
strict: false,
3849
});
3950

51+
skipRestore = values["skip-restore"];
52+
4053
async function getDefaultSettings() {
4154
let gitRemoteFetch;
4255
try {
@@ -90,12 +103,7 @@ try {
90103
},
91104
});
92105

93-
if (prompts.isCancel(value)) {
94-
prompts.cancel(
95-
"Operation cancelled. Exiting setup - maybe another time? 👋"
96-
);
97-
process.exit(0);
98-
}
106+
handlePromptCancel(value);
99107

100108
return value;
101109
}
@@ -571,7 +579,30 @@ try {
571579

572580
console.log();
573581
console.log(error);
574-
console.log();
582+
583+
if (skipRestore) {
584+
console.log();
585+
console.log(chalk.gray`Skipping restoring local repository, as requested.`);
586+
console.log();
587+
} else {
588+
const shouldRestore = await prompts.confirm({
589+
message:
590+
"Do you want to restore the repository to how it was before running setup?",
591+
});
592+
593+
handlePromptCancel(shouldRestore);
594+
595+
if (shouldRestore) {
596+
console.log();
597+
console.log(
598+
chalk.gray`Resetting repository using`,
599+
chalk.reset`git restore .`
600+
);
601+
await $`git restore .`;
602+
console.log("Repository is reset. Ready to try again?");
603+
console.log();
604+
}
605+
}
575606

576607
exitCode = 1;
577608
} finally {

0 commit comments

Comments
 (0)