Skip to content

Commit

Permalink
refactor: keep prompt styles (cont. #332)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 13, 2025
1 parent c5c1534 commit b5f5414
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
24 changes: 24 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ export default defineBuildConfig({
output.exports = "named";
}

// Prompts theme
// https://github.com/bombshell-dev/clack/issues/36
options.plugins.push({
name: "@clack/prompts",
transform(code, id) {
if (id.endsWith("@clack/prompts/dist/index.mjs")) {
const replaces = [
["} $", "} $"],
[String.raw`"\u25C6","*"`, '"❯", ">"'],
[String.raw`"\u25A0","x"`, '"■", "x"'],
[String.raw`"\u25B2","x"`, '"▲", "x"'],
[String.raw`"\u25C7","o"`, '"✔", "√"'],
[String.raw`"\u250C","T"`, '""'],
[String.raw`"\u2502","|"`, '""'],
[String.raw`"\u2514","\u2014"`, '""'],
] as const;
for (const [from, to] of replaces) {
code = code.replaceAll(from, to);
}
return code;
}
},
});

// Node.js 14 support
// https://github.com/unjs/consola/issues/204
options.plugins.push({
Expand Down
50 changes: 50 additions & 0 deletions examples/prompt.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

import { consola } from "../dist/index.mjs";

const name = await consola.prompt("What is your name?", {
placeholder: "Not sure",
initial: "java",
cancel: 'undefined'
});

if (!name) { process.exit(1) }

const confirmed = await consola.prompt("Do you want to continue?", {
type: "confirm",
cancel: 'undefined'
});

if (!confirmed) { process.exit(1) }

const projectType = await consola.prompt("Pick a project type.", {
type: "select",
options: [
"JavaScript",
"TypeScript",
{ label: "CoffeeScript", value: "CoffeeScript", hint: "oh no" },
],
cancel: 'undefined',
initial: "TypeScript",
});

if (!projectType) { process.exit(1) }

const tools = await consola.prompt("Select additional tools.", {
type: "multiselect",
required: false,
options: [
{ value: "eslint", label: "ESLint", hint: "recommended" },
{ value: "prettier", label: "Prettier" },
{ value: "gh-action", label: "GitHub Action" },
],
cancel: 'undefined',
initial: ["eslint", "prettier"],
});

if (!tools) { process.exit(1) }


consola.start("Creating project...");
await new Promise((resolve) => setTimeout(resolve, 1000));
consola.success("Project created!");

0 comments on commit b5f5414

Please sign in to comment.