|
2 | 2 | import { EOL } from "node:os";
|
3 | 3 | import { parseArgs } from "node:util";
|
4 | 4 |
|
| 5 | +import { cancel, isCancel, text } from "@clack/prompts"; |
5 | 6 | import chalk from "chalk";
|
6 | 7 | import { promises as fs } from "fs";
|
7 | 8 | import { Octokit } from "octokit";
|
8 | 9 | import prettier from "prettier";
|
9 | 10 | import replace from "replace-in-file";
|
10 | 11 |
|
11 |
| -const { prompt } = require("enquirer"); |
12 |
| - |
13 | 12 | let caughtError;
|
14 | 13 |
|
15 | 14 | try {
|
@@ -37,37 +36,52 @@ try {
|
37 | 36 | strict: false,
|
38 | 37 | });
|
39 | 38 |
|
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 | + } |
49 | 59 |
|
50 | 60 | return value;
|
51 | 61 | }
|
52 | 62 |
|
53 | 63 | const repository = await getPrefillOrPromptedValue(
|
54 | 64 | "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" |
56 | 67 | );
|
57 | 68 |
|
58 | 69 | const title = await getPrefillOrPromptedValue(
|
59 | 70 | "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" |
61 | 73 | );
|
62 | 74 |
|
63 | 75 | const owner = await getPrefillOrPromptedValue(
|
64 | 76 | "owner",
|
65 |
| - "What owner or user will the repository be under?" |
| 77 | + "What owner or user will the repository be under?", |
| 78 | + "UserName" |
66 | 79 | );
|
67 | 80 |
|
68 | 81 | const description = await getPrefillOrPromptedValue(
|
69 | 82 | "description",
|
70 |
| - "How would you describe the new package?" |
| 83 | + "How would you describe the new package?", |
| 84 | + "A very lovely package. Hooray!" |
71 | 85 | );
|
72 | 86 |
|
73 | 87 | const skipApi = await getPrefillOrPromptedValue(
|
@@ -288,7 +302,7 @@ try {
|
288 | 302 | console.log(
|
289 | 303 | chalk.gray`Removing devDependency packages only used for setup...`
|
290 | 304 | );
|
291 |
| - await $`pnpm remove chalk enquirer octokit replace-in-file -D`; |
| 305 | + await $`pnpm remove @clack/prompts chalk octokit replace-in-file -D`; |
292 | 306 | console.log(chalk.gray`✔️ Done.`);
|
293 | 307 | }
|
294 | 308 |
|
|
0 commit comments