diff --git a/.changeset/afraid-ligers-add.md b/.changeset/afraid-ligers-add.md new file mode 100644 index 000000000000..725c312ca102 --- /dev/null +++ b/.changeset/afraid-ligers-add.md @@ -0,0 +1,5 @@ +--- +"create-astro": patch +--- + +Improves seasonal message handling by automatically detecting the local date diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 8a9b8991e3f7..d4f84add5772 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -31,7 +31,7 @@ "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.", "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "dependencies": { - "@astrojs/cli-kit": "^0.4.0", + "@astrojs/cli-kit": "^0.4.1", "giget": "1.1.3" }, "devDependencies": { diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 7a401162544d..51ee6280bc89 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -4,6 +4,7 @@ import arg from 'arg'; import os from 'node:os'; import { getName, getVersion } from '../messages.js'; +import getSeasonalData from '../data/seasonal.js'; export interface Context { help: boolean; @@ -25,7 +26,9 @@ export interface Context { stdin?: typeof process.stdin; stdout?: typeof process.stdout; exit(code: number): never; + welcome?: string; hat?: string; + tie?: string; tasks: Task[]; } @@ -83,6 +86,8 @@ export async function getContext(argv: string[]): Promise { ((os.platform() === 'win32' && !fancy) || skipHouston) ?? [yes, no, install, git, typescript].some((v) => v !== undefined); + const { messages, hats, ties } = getSeasonalData({ fancy }); + const context: Context = { help, prompt, @@ -95,7 +100,9 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - hat: random(['โ„๏ธ', '๐ŸŽ„', '๐ŸŽ']), // fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined, + welcome: random(messages), + hat: hats ? random(hats) : undefined, + tie: ties ? random(ties) : undefined, yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), diff --git a/packages/create-astro/src/actions/intro.ts b/packages/create-astro/src/actions/intro.ts index 1781fb260109..526b8e5cca72 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -1,15 +1,15 @@ import type { Context } from './context.js'; import { color, label } from '@astrojs/cli-kit'; -import { random } from '@astrojs/cli-kit/utils'; -import { banner, say, welcome } from '../messages.js'; +import { banner, say } from '../messages.js'; export async function intro( - ctx: Pick + ctx: Pick ) { banner(); if (!ctx.skipHouston) { + const { welcome, hat, tie } = ctx; await say( [ [ @@ -21,9 +21,9 @@ export async function intro( ), Promise.resolve(ctx.username).then((username) => `${username}!`), ], - random(welcome), - ], - { clear: true, hat: ctx.hat } + welcome ?? 'Let\'s build something awesome!', + ] as string[], + { clear: true, hat, tie } ); } } diff --git a/packages/create-astro/src/actions/next-steps.ts b/packages/create-astro/src/actions/next-steps.ts index 86907abf54bc..5444020e4fa7 100644 --- a/packages/create-astro/src/actions/next-steps.ts +++ b/packages/create-astro/src/actions/next-steps.ts @@ -3,7 +3,7 @@ import type { Context } from './context.js'; import { nextSteps, say } from '../messages.js'; -export async function next(ctx: Pick) { +export async function next(ctx: Pick) { let projectDir = path.relative(process.cwd(), ctx.cwd); const commandMap: { [key: string]: string } = { @@ -17,7 +17,7 @@ export async function next(ctx: Pick 7) { + return 'spooky' + } + if (month === 12 && day > 7 && day < 25) { + return 'holiday' + } +} + +// Generates an array padded with empty strings to make decorations more rare +function rarity(frequency: number, emoji: string[]) { + if (frequency === 1) return emoji; + if (frequency === 0) return ['']; + const empty = Array.from({ length: Math.round(emoji.length * frequency) }, () => '') + return [...emoji, ...empty]; +} diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 31032fbabf33..a11f45acd0f7 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -24,8 +24,8 @@ export function setStdout(writable: typeof process.stdout) { stdout = writable; } -export async function say(messages: string | string[], { clear = false, hat = '' } = {}) { - return houston(messages, { clear, hat, stdout }); +export async function say(messages: string | string[], { clear = false, hat = '', tie = ''} = {}) { + return houston(messages, { clear, hat, tie, stdout }); } export async function spinner(args: { @@ -39,33 +39,6 @@ export async function spinner(args: { export const title = (text: string) => align(label(text), 'end', 7) + ' '; -export const welcome = [ - // `Let's claim your corner of the internet.`, - // `I'll be your assistant today.`, - // `Let's build something awesome!`, - // `Let's build something great!`, - // `Let's build something fast!`, - // `Let's build the web we want.`, - // `Let's make the web weird!`, - // `Let's make the web a better place!`, - // `Let's create a new project!`, - // `Let's create something unique!`, - // `Time to build a new website.`, - // `Time to build a faster website.`, - // `Time to build a sweet new website.`, - // `We're glad to have you on board.`, - // `Keeping the internet weird since 2021.`, - // `Initiating launch sequence...`, - // `Initiating launch sequence... right... now!`, - // `Awaiting further instructions.`, - `Ho, ho, ho! 'Tis the season to code and create.`, - `Jingle all the way through your web creation journey!`, - `Let's unwrap the magic of the web together!`, - `Bells are ringing, and so are your creative ideas!`, - `It's starting to look a lot like Christmas on the internet.`, - `It's time to decorate the web with your festive ideas!`, -]; - export const getName = () => new Promise((resolve) => { exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27e6037c8ee5..7dd02558ad6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3737,8 +3737,8 @@ importers: packages/create-astro: dependencies: '@astrojs/cli-kit': - specifier: ^0.4.0 - version: 0.4.0 + specifier: ^0.4.1 + version: 0.4.1 giget: specifier: 1.1.3 version: 1.1.3 @@ -5280,8 +5280,8 @@ packages: sisteransi: 1.0.5 dev: false - /@astrojs/cli-kit@0.4.0: - resolution: {integrity: sha512-M7R2Af/Gh13pwZ2zjTkTPt87x4IjRw/bSRCmjJGWEGeW3nLNzuEeRY8tleeIGbbfUsm3DJg+UF5rCrQGoviHgQ==} + /@astrojs/cli-kit@0.4.1: + resolution: {integrity: sha512-bVzyKzEpIwqjihBU/aUzt1LQckJuHK0agd3/ITdXhPUYculrc6K1/K7H+XG4rwjXtg+ikT3PM05V1MVYWiIvQw==} engines: {node: '>=18.14.1'} dependencies: chalk: 5.3.0