Skip to content

Commit 18f465b

Browse files
chore: switch from enquirer to clack (#278)
* switched from enquirer to clack * removed intro outro msg * placed import in correct order * completed requested changes * removed script from vitest config inclusion * fixed typo * added enquirer * uninstalled enquirer * replaced remove enquirer with remove clack * merge main into local * clack/core was unused and causeing Lint Knip to fail * Update kebab-case Co-authored-by: Josh Goldberg <[email protected]> * Update Title Co-authored-by: Josh Goldberg <[email protected]> * Update package name placeholder Co-authored-by: Josh Goldberg <[email protected]> * Update value to not be an object Co-authored-by: Josh Goldberg <[email protected]> * Corrected prefill setup values * nit: brackets --------- Co-authored-by: Josh Goldberg <[email protected]>
1 parent 2088af2 commit 18f465b

File tree

3 files changed

+61
-39
lines changed

3 files changed

+61
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
"*": "prettier --ignore-unknown --write"
3737
},
3838
"devDependencies": {
39+
"@clack/prompts": "^0.6.3",
3940
"@types/eslint": "^8.21.1",
4041
"@typescript-eslint/eslint-plugin": "^5.48.2",
4142
"@typescript-eslint/parser": "^5.48.2",
4243
"@vitest/coverage-istanbul": "^0.29.0",
4344
"chalk": "^5.2.0",
4445
"cspell": "^6.19.2",
45-
"enquirer": "^2.3.6",
4646
"eslint": "^8.32.0",
4747
"eslint-config-prettier": "^8.6.0",
4848
"eslint-plugin-deprecation": "^1.3.3",

pnpm-lock.yaml

Lines changed: 30 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/setup.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import { EOL } from "node:os";
33
import { parseArgs } from "node:util";
44

5+
import { cancel, isCancel, text } from "@clack/prompts";
56
import chalk from "chalk";
67
import { promises as fs } from "fs";
78
import { Octokit } from "octokit";
89
import prettier from "prettier";
910
import replace from "replace-in-file";
1011

11-
const { prompt } = require("enquirer");
12-
1312
let caughtError;
1413

1514
try {
@@ -37,37 +36,52 @@ try {
3736
strict: false,
3837
});
3938

40-
async function getPrefillOrPromptedValue(key, message) {
41-
const { [key]: value } = values[key]
42-
? (console.log(chalk.grey(`Pre-filling ${key} to ${values[key]}.`)),
43-
values)
44-
: await prompt({
45-
message,
46-
name: key,
47-
type: "input",
48-
});
39+
async function getPrefillOrPromptedValue(key, message, placeholder) {
40+
if (values[key]) {
41+
console.log(chalk.grey(`Pre-filling ${key} to ${values[key]}.`));
42+
return values[key];
43+
}
44+
45+
const value = await text({
46+
message,
47+
placeholder,
48+
validate: (val) => {
49+
if (val.length === 0) {
50+
return "Please enter a value.";
51+
}
52+
},
53+
});
54+
55+
if (isCancel(value)) {
56+
cancel("Operation cancelled. Exiting setup - maybe another time? 👋");
57+
process.exit(0);
58+
}
4959

5060
return value;
5161
}
5262

5363
const repository = await getPrefillOrPromptedValue(
5464
"repository",
55-
"What will the kebab-case name of the repository be?"
65+
"What will the kebab-case name of the repository be?",
66+
"my-lovely-repository"
5667
);
5768

5869
const title = await getPrefillOrPromptedValue(
5970
"title",
60-
"What will the Title Case title of the repository be?"
71+
"What will the Title Case title of the repository be?",
72+
"My Lovely Repository"
6173
);
6274

6375
const owner = await getPrefillOrPromptedValue(
6476
"owner",
65-
"What owner or user will the repository be under?"
77+
"What owner or user will the repository be under?",
78+
"UserName"
6679
);
6780

6881
const description = await getPrefillOrPromptedValue(
6982
"description",
70-
"How would you describe the new package?"
83+
"How would you describe the new package?",
84+
"A very lovely package. Hooray!"
7185
);
7286

7387
const skipApi = await getPrefillOrPromptedValue(
@@ -288,7 +302,7 @@ try {
288302
console.log(
289303
chalk.gray`Removing devDependency packages only used for setup...`
290304
);
291-
await $`pnpm remove chalk enquirer octokit replace-in-file -D`;
305+
await $`pnpm remove @clack/prompts chalk octokit replace-in-file -D`;
292306
console.log(chalk.gray`✔️ Done.`);
293307
}
294308

0 commit comments

Comments
 (0)