Skip to content

Commit

Permalink
Propagate changes (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
escottalexander authored Dec 12, 2024
2 parents ad9f635 + 01f34bd commit 1b4603f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-keys-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eth-tech-tree": patch
---

Ask user for confirmation before resetting their challenge
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Submit a challenge:
npx eth-tech-tree submit CHALLENGE_NAME CONTRACT_ADDRESS
```

Reset your user state (it will re-prompt you for your address and install location):
```bash
npx eth-tech-tree reset
```

## Development
Clone and `cd` into the repo then run this CLI application with the following commands
- `yarn install`
Expand Down
36 changes: 21 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ export class TechTree {

getChallengeMessage(node: TreeNode): string {
const { installLocation } = this.userState;
return `${chalk.bold(node.label)}
${node.message}
return `${node.message}
${node.completed ? `
🏆 Challenge Completed` : node.installed ? `
Open up the challenge in your favorite code editor and follow the instructions in the README:
Expand Down Expand Up @@ -303,17 +302,22 @@ Open up the challenge in your favorite code editor and follow the instructions i
} else {
actions["Reset Challenge"] = async () => {
this.clearView();
const targetDir = `${installLocation}/${name}`;
console.log(`Removing ${targetDir}...`);
rmSync(targetDir, { recursive: true, force: true });
console.log(`Installing fresh copy of challenge...`);
await setupChallenge(name, installLocation);
this.globalTree = this.buildTree();
await this.pressEnterToContinue();
this.history.pop(); // Remove the old node from history since it has different actions
// Return to challenge menu
const challengeNode = this.findNode(this.globalTree, name) as TreeNode;
await this.navigate(challengeNode);
const confirmReset = await this.pressEnterToContinue("Are you sure you want to reset this challenge? This will remove the challenge from your local machine and re-install it.", false);
if (!confirmReset) {
await this.goBack();
} else {
const targetDir = `${installLocation}/${name}`;
console.log(`Removing ${targetDir}...`);
rmSync(targetDir, { recursive: true, force: true });
console.log(`Installing fresh copy of challenge...`);
await setupChallenge(name, installLocation);
this.globalTree = this.buildTree();
await this.pressEnterToContinue();
this.history.pop(); // Remove the old node from history since it has different actions
// Return to challenge menu
const challengeNode = this.findNode(this.globalTree, name) as TreeNode;
await this.navigate(challengeNode);
}
};
actions["Submit Completed Challenge"] = async () => {
this.clearView();
Expand All @@ -337,13 +341,15 @@ Open up the challenge in your favorite code editor and follow the instructions i
return actions;
};

async pressEnterToContinue(customMessage?: string) {
await confirm({
async pressEnterToContinue(customMessage?: string, defaultAnswer: boolean = true) {
const answer = await confirm({
message: typeof customMessage === "string" ? customMessage : 'Press Enter to continue...',
default: defaultAnswer,
theme: {
prefix: "",
}
});
return answer;
}

private clearView(): void {
Expand Down

0 comments on commit 1b4603f

Please sign in to comment.