Skip to content

Commit 491ff8c

Browse files
authored
feat: add emoji prompt (#9)
1 parent 84865fe commit 491ff8c

File tree

8 files changed

+51
-5
lines changed

8 files changed

+51
-5
lines changed

.changeset/bright-bobcats-clap.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@hideoo/generator-starlight-plugin': minor
3+
---
4+
5+
Adds a new prompt asking for a single emoji representing the generated Starlight plugin.
6+
7+
The emoji will be used in the generated documentation and README files.

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Generator, { type BaseOptions } from 'yeoman-generator'
44

55
import { copy, copyTpl } from './libs/fs.js'
66
import { fetchDependencyVersions } from './libs/npm.js'
7-
import { promptForName, promptForText } from './libs/prompt.js'
7+
import { promptForEmoji, promptForName, promptForText } from './libs/prompt.js'
88

99
export default class StarlightPluginGenerator extends Generator<BaseOptions & Configuration> {
1010
configuration: Configuration
@@ -21,6 +21,10 @@ export default class StarlightPluginGenerator extends Generator<BaseOptions & Co
2121

2222
this.option('name', { type: String, description: 'Name of the Starlight plugin' })
2323
this.option('description', { type: String, description: 'Description of the Starlight plugin' })
24+
this.option('emoji', {
25+
type: String,
26+
description: 'Single emoji representing the Starlight plugin (used in the documentation)',
27+
})
2428
this.option('ghUsername', { type: String, description: 'GitHub username' })
2529
}
2630

@@ -36,6 +40,7 @@ export default class StarlightPluginGenerator extends Generator<BaseOptions & Co
3640
'What is the description of your Starlight plugin?',
3741
'My awesome Starlight plugin',
3842
)
43+
await promptForEmoji(this)
3944
await promptForText(this, 'ghUsername', 'What is your GitHub username?', 'ghost')
4045
}
4146

@@ -82,6 +87,7 @@ export default class StarlightPluginGenerator extends Generator<BaseOptions & Co
8287
export interface Configuration {
8388
name?: string
8489
description?: string
90+
emoji?: string
8591
ghUsername?: string
8692
year: string
8793
}

src/libs/prompt.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type StarlightPluginGenerator from '../index.js'
22
import type { Configuration } from '../index.js'
33

4-
import { validateName, validateNonEmptyString } from './validator.js'
4+
import { validateEmoji, validateName, validateNonEmptyString } from './validator.js'
55

66
export async function promptForName(generator: StarlightPluginGenerator) {
77
const name = generator.options.name
@@ -45,3 +45,23 @@ export async function promptForText(
4545

4646
generator.configuration[key] = answers[key]
4747
}
48+
49+
export async function promptForEmoji(generator: StarlightPluginGenerator) {
50+
const emoji = generator.options.emoji
51+
52+
if (emoji && validateEmoji(emoji) === true) {
53+
generator.configuration.emoji = emoji
54+
return
55+
}
56+
57+
const answers = await generator.prompt<{ emoji: string }>({
58+
type: 'input',
59+
name: 'emoji',
60+
message: 'What single emoji represents your Starlight plugin?',
61+
default: '🔋',
62+
suffix: '(used in the documentation)',
63+
validate: validateEmoji,
64+
})
65+
66+
generator.configuration.emoji = answers.emoji
67+
}

src/libs/validator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const nameValidationRegex = /^(?:@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*$/
2+
const emojiValidationRegex = /^\p{Emoji_Presentation}\p{Emoji_Modifier}*$/u
23

34
export function validateName(name: string) {
45
return nameValidationRegex.test(name) ? true : 'Invalid plugin name'
@@ -7,3 +8,7 @@ export function validateName(name: string) {
78
export function validateNonEmptyString(value: string) {
89
return value.trim().length > 0 ? true : 'Value cannot be empty'
910
}
11+
12+
export function validateEmoji(emoji: string) {
13+
return emojiValidationRegex.test(emoji) ? true : 'Invalid emoji'
14+
}

templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `<%= name %>`
1+
# `<%= name %>` <%= emoji %>
22

33
<%= description %>
44

templates/docs/public/favicon.svg

Lines changed: 1 addition & 1 deletion
Loading
-96.2 KB
Binary file not shown.

templates/docs/src/content/docs/index.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ description: <%= description %>
44
head:
55
- tag: title
66
content: <%= name %>
7+
- tag: style
8+
content: |
9+
.hero-html {
10+
--size: 12rem;
11+
font-size: var(--size);
12+
justify-content: center;
13+
line-height: var(--size);
14+
}
715
template: splash
816
editUrl: false
917
hero:
1018
tagline: <%= description %>
1119
image:
12-
file: ../../assets/houston.webp
20+
html: '<%= emoji %>'
1321
actions:
1422
- text: Get Started
1523
link: /getting-started/

0 commit comments

Comments
 (0)