From 18070e8f4df5dabc914d3a0e825f2846c0268d9f Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 14:18:30 +0100 Subject: [PATCH 01/15] feat: allow Houston to wear Scarfs --- packages/create-astro/src/actions/context.ts | 2 ++ packages/create-astro/src/actions/intro.ts | 4 ++-- packages/create-astro/src/messages.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index a7f2e6d8c71d..b17f8917ded3 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -26,6 +26,7 @@ export interface Context { stdout?: typeof process.stdout; exit(code: number): never; hat?: string; + scarf?: string; } export async function getContext(argv: string[]): Promise { @@ -95,6 +96,7 @@ export async function getContext(argv: string[]): Promise { template, ref: ref ?? 'latest', hat: random(['โ„๏ธ', '๐ŸŽ„', '๐ŸŽ']), // fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined, + scarf: fancy ? '๐Ÿงฃ' : 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..451094937415 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -5,7 +5,7 @@ import { random } from '@astrojs/cli-kit/utils'; import { banner, say, welcome } from '../messages.js'; export async function intro( - ctx: Pick + ctx: Pick ) { banner(); @@ -23,7 +23,7 @@ export async function intro( ], random(welcome), ], - { clear: true, hat: ctx.hat } + { clear: true, hat: ctx.hat, scarf: ctx.scarf } ); } } diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 31032fbabf33..544b9ee0adea 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 = '', scarf = '' } = {}) { + return houston(messages, { clear, hat, scarf, stdout }); } export async function spinner(args: { From e55abc85fafb6966d87b19921622a25000fb9f8c Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 14:53:40 +0100 Subject: [PATCH 02/15] refactor: allow 1 object to be passed instead of separate --- packages/create-astro/src/actions/context.ts | 12 ++++++++---- packages/create-astro/src/actions/intro.ts | 4 ++-- packages/create-astro/src/actions/next-steps.ts | 4 ++-- packages/create-astro/src/messages.ts | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index b17f8917ded3..c982723cec7f 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -25,8 +25,10 @@ export interface Context { stdin?: typeof process.stdin; stdout?: typeof process.stdout; exit(code: number): never; - hat?: string; - scarf?: string; + clothes: { + hat: string; + tie: string; + }; } export async function getContext(argv: string[]): Promise { @@ -95,8 +97,10 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - hat: random(['โ„๏ธ', '๐ŸŽ„', '๐ŸŽ']), // fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined, - scarf: fancy ? '๐Ÿงฃ' : undefined, + clothes: { + hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', + tie: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', + }, 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 451094937415..ed45a7154636 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -5,7 +5,7 @@ import { random } from '@astrojs/cli-kit/utils'; import { banner, say, welcome } from '../messages.js'; export async function intro( - ctx: Pick + ctx: Pick ) { banner(); @@ -23,7 +23,7 @@ export async function intro( ], random(welcome), ], - { clear: true, hat: ctx.hat, scarf: ctx.scarf } + { clear: true, clothes: { hat: ctx.clothes.hat, tie: ctx.clothes.tie } } ); } } diff --git a/packages/create-astro/src/actions/next-steps.ts b/packages/create-astro/src/actions/next-steps.ts index 86907abf54bc..d5f5482479b1 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 Date: Tue, 19 Dec 2023 14:58:58 +0100 Subject: [PATCH 03/15] set messages back to original state / add ties --- packages/create-astro/src/actions/context.ts | 2 +- packages/create-astro/src/messages.ts | 42 +++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index c982723cec7f..d3c26d858a3e 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -99,7 +99,7 @@ export async function getContext(argv: string[]): Promise { ref: ref ?? 'latest', clothes: { hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', - tie: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', + tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', }, yes, install: install ?? (noInstall ? false : undefined), diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index b23105c2f616..fa0c9b60407d 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -40,30 +40,24 @@ 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!`, + `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.`, ]; export const getName = () => From 25328102144132b2cc233b11a664ed82792daced Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 15:00:25 +0100 Subject: [PATCH 04/15] refactor to getClothes method --- packages/create-astro/src/actions/context.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index d3c26d858a3e..38f19e2ac345 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -97,10 +97,7 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - clothes: { - hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', - tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', - }, + clothes: getClothes(fancy), yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), @@ -113,6 +110,13 @@ export async function getContext(argv: string[]): Promise { return context; } +function getClothes(fancy?: boolean) { + return { + hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', + tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', + }; +} + function detectPackageManager() { if (!process.env.npm_config_user_agent) return; const specifier = process.env.npm_config_user_agent.split(' ')[0]; From afc9c9f9b3f2f2f0da453e6262da3371162a8cd5 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 15:10:44 +0100 Subject: [PATCH 05/15] refactor: add clothes per season --- packages/create-astro/src/actions/context.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 38f19e2ac345..b292b5ee8764 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -111,6 +111,19 @@ export async function getContext(argv: string[]): Promise { } function getClothes(fancy?: boolean) { + const date = new Date() + if(date.getMonth() === 11) { + return { + hat: random(['๐ŸŽ', '๐ŸŽ„', '๐ŸŒฒ']), + tie: '๐Ÿงฃ' + } + } + else if (date.getMonth() === 9) { + return { + hat: random(['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€']), + tie: '๐Ÿฆด' + } + } return { hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', From c5e4be33e4a6dd7e463bf79dad5b2d1c2fd51dd8 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 15:18:18 +0100 Subject: [PATCH 06/15] refactor: add messages with timing too --- packages/create-astro/src/actions/context.ts | 2 +- packages/create-astro/src/messages.ts | 64 ++++++++++++++------ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index b292b5ee8764..2f0fd1fd03ee 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -121,7 +121,7 @@ function getClothes(fancy?: boolean) { else if (date.getMonth() === 9) { return { hat: random(['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€']), - tie: '๐Ÿฆด' + tie: random(['๐Ÿฆด', '']) } } return { diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index fa0c9b60407d..43c765a2552c 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -39,26 +39,50 @@ 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.`, -]; +export const welcome = (() => { + const date = new Date(); + if (date.getMonth() === 11) { + return [ + `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!`, + ] + } + if (date.getMonth() === 9) { + return [ + `Booo! Let's scare the interwebs!`, + `Get ready to haunt the internet with Halloween vibes.`, + `Harness the power of the web for your frightful ideas.`, + `It's time to conjure up an online spooktacular masterpiece.`, + `Prepare for a web of Halloween wonders to be woven.`, + `Chills and thrills await as you embark on your web journey`, + `The internet is about to get a whole lot creepier thanks to your new project.` + ] + } + return [ + `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.`, + ]; +})(); export const getName = () => new Promise((resolve) => { From dc3036004e6ff63777940cdf9c59d88722562ce1 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Tue, 19 Dec 2023 16:09:47 +0100 Subject: [PATCH 07/15] refactor to new file --- packages/create-astro/src/actions/context.ts | 24 +------ packages/create-astro/src/data/festive.ts | 66 ++++++++++++++++++++ packages/create-astro/src/data/index.ts | 1 + packages/create-astro/src/messages.ts | 46 +------------- 4 files changed, 71 insertions(+), 66 deletions(-) create mode 100644 packages/create-astro/src/data/festive.ts create mode 100644 packages/create-astro/src/data/index.ts diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 2f0fd1fd03ee..9130a7ffa620 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -1,9 +1,9 @@ import { prompt } from '@astrojs/cli-kit'; -import { random } from '@astrojs/cli-kit/utils'; import arg from 'arg'; import os from 'node:os'; import { getName, getVersion } from '../messages.js'; +import getFestiveHouston from '../data/festive.js'; export interface Context { help: boolean; @@ -97,7 +97,7 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - clothes: getClothes(fancy), + clothes: getFestiveHouston(fancy).clothes, yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), @@ -110,26 +110,6 @@ export async function getContext(argv: string[]): Promise { return context; } -function getClothes(fancy?: boolean) { - const date = new Date() - if(date.getMonth() === 11) { - return { - hat: random(['๐ŸŽ', '๐ŸŽ„', '๐ŸŒฒ']), - tie: '๐Ÿงฃ' - } - } - else if (date.getMonth() === 9) { - return { - hat: random(['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€']), - tie: random(['๐Ÿฆด', '']) - } - } - return { - hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', - tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', - }; -} - function detectPackageManager() { if (!process.env.npm_config_user_agent) return; const specifier = process.env.npm_config_user_agent.split(' ')[0]; diff --git a/packages/create-astro/src/data/festive.ts b/packages/create-astro/src/data/festive.ts new file mode 100644 index 000000000000..b7f2e47a4c64 --- /dev/null +++ b/packages/create-astro/src/data/festive.ts @@ -0,0 +1,66 @@ +import { random } from '@astrojs/cli-kit/utils'; + +export default function getFestiveHouston(fancy?: boolean) { + const date = new Date(); + if (date.getMonth() === 11) { + // Christmas season + return { + clothes: { + hat: random(['๐ŸŽ', '๐ŸŽ„', '๐ŸŒฒ']), + tie: '๐Ÿงฃ' + }, + messages: [ + `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!`, + ] + } + } else if (date.getMonth() === 9) { + // Spooky season + return { + clothes: { + hat: random(['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€']), + tie: random(['๐Ÿฆด', '']) + }, + messages: [ + `Booo! Let's scare the interwebs!`, + `Get ready to haunt the internet with Halloween vibes.`, + `Harness the power of the web for your frightful ideas.`, + `It's time to conjure up an online spooktacular masterpiece.`, + `Prepare for a web of Halloween wonders to be woven.`, + `Chills and thrills await as you embark on your web journey`, + `The internet is about to get a whole lot creepier thanks to your new project.` + ] + } + } + // default state + return { + clothes: { + hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', + tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', + }, + messages: [ + `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.`, + ] + } +} diff --git a/packages/create-astro/src/data/index.ts b/packages/create-astro/src/data/index.ts new file mode 100644 index 000000000000..2252d3c21f05 --- /dev/null +++ b/packages/create-astro/src/data/index.ts @@ -0,0 +1 @@ +export {default as getFestiveMessages} from './festive.js' diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 43c765a2552c..3caf32a05755 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -4,6 +4,7 @@ import { align, sleep } from '@astrojs/cli-kit/utils'; import { exec } from 'node:child_process'; import stripAnsi from 'strip-ansi'; import { shell } from './shell.js'; +import getFestiveHouston from './data/festive.js'; // Users might lack access to the global npm registry, this function // checks the user's project type and will return the proper npm registry @@ -39,50 +40,7 @@ export async function spinner(args: { export const title = (text: string) => align(label(text), 'end', 7) + ' '; -export const welcome = (() => { - const date = new Date(); - if (date.getMonth() === 11) { - return [ - `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!`, - ] - } - if (date.getMonth() === 9) { - return [ - `Booo! Let's scare the interwebs!`, - `Get ready to haunt the internet with Halloween vibes.`, - `Harness the power of the web for your frightful ideas.`, - `It's time to conjure up an online spooktacular masterpiece.`, - `Prepare for a web of Halloween wonders to be woven.`, - `Chills and thrills await as you embark on your web journey`, - `The internet is about to get a whole lot creepier thanks to your new project.` - ] - } - return [ - `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.`, - ]; -})(); +export const welcome = getFestiveHouston().messages export const getName = () => new Promise((resolve) => { From 30d68625eead1fef7540c51315aa5b357f5d2442 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Thu, 4 Jan 2024 13:07:36 +0100 Subject: [PATCH 08/15] refactor: use `hat` & `tie` instead of `clothes` --- packages/create-astro/src/actions/context.ts | 11 +++---- packages/create-astro/src/actions/intro.ts | 4 +-- .../create-astro/src/actions/next-steps.ts | 4 +-- packages/create-astro/src/data/index.ts | 2 +- .../src/data/{festive.ts => seasonal.ts} | 31 ++++++++++--------- packages/create-astro/src/messages.ts | 9 +++--- 6 files changed, 32 insertions(+), 29 deletions(-) rename packages/create-astro/src/data/{festive.ts => seasonal.ts} (73%) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 9130a7ffa620..2533d7df5aa2 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -3,7 +3,7 @@ import arg from 'arg'; import os from 'node:os'; import { getName, getVersion } from '../messages.js'; -import getFestiveHouston from '../data/festive.js'; +import getSeasonalHouston from '../data/seasonal.js'; export interface Context { help: boolean; @@ -25,10 +25,8 @@ export interface Context { stdin?: typeof process.stdin; stdout?: typeof process.stdout; exit(code: number): never; - clothes: { - hat: string; - tie: string; - }; + hat?: string; + tie?: string; } export async function getContext(argv: string[]): Promise { @@ -97,7 +95,8 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - clothes: getFestiveHouston(fancy).clothes, + hat: getSeasonalHouston(fancy).hat, + tie: getSeasonalHouston(fancy).tie, 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 ed45a7154636..2f58e247d788 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -5,7 +5,7 @@ import { random } from '@astrojs/cli-kit/utils'; import { banner, say, welcome } from '../messages.js'; export async function intro( - ctx: Pick + ctx: Pick ) { banner(); @@ -23,7 +23,7 @@ export async function intro( ], random(welcome), ], - { clear: true, clothes: { hat: ctx.clothes.hat, tie: ctx.clothes.tie } } + { clear: true, hat: ctx.hat, tie: ctx.tie } ); } } diff --git a/packages/create-astro/src/actions/next-steps.ts b/packages/create-astro/src/actions/next-steps.ts index d5f5482479b1..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 align(label(text), 'end', 7) + ' '; -export const welcome = getFestiveHouston().messages +export const seasonalHouston = getSeasonalHouston(); +export const welcome = seasonalHouston.messages; export const getName = () => new Promise((resolve) => { From 30af23ec502cc1a9afb0584298f0eb8f084bc172 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Thu, 4 Jan 2024 13:10:18 +0100 Subject: [PATCH 09/15] refactor: use `getSeasonalHouston` only once --- packages/create-astro/src/actions/context.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 2533d7df5aa2..894a88b08c07 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -83,6 +83,8 @@ export async function getContext(argv: string[]): Promise { ((os.platform() === 'win32' && !fancy) || skipHouston) ?? [yes, no, install, git, typescript].some((v) => v !== undefined); + const seasonalHouston = getSeasonalHouston(fancy); + const context: Context = { help, prompt, @@ -95,8 +97,8 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - hat: getSeasonalHouston(fancy).hat, - tie: getSeasonalHouston(fancy).tie, + hat: seasonalHouston.hat, + tie: seasonalHouston.tie, yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), From 3070b46cd02be32e5364ae1c80003c195f593256 Mon Sep 17 00:00:00 2001 From: Elian Van Cutsem Date: Fri, 5 Jan 2024 20:15:09 +0100 Subject: [PATCH 10/15] chore: upgrade dependencies --- packages/create-astro/package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 9a62aca78b63..85bd582d942e 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/pnpm-lock.yaml b/pnpm-lock.yaml index f4e7679b7afb..602d75754ba5 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 @@ -5262,8 +5262,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 From bfbdbcb00604162a0569dfd1be02aa763be1c065 Mon Sep 17 00:00:00 2001 From: Elian Date: Fri, 5 Jan 2024 20:31:11 +0100 Subject: [PATCH 11/15] fix mistake in date --- packages/create-astro/src/data/seasonal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-astro/src/data/seasonal.ts b/packages/create-astro/src/data/seasonal.ts index 91bd0f41f423..0751767401b7 100644 --- a/packages/create-astro/src/data/seasonal.ts +++ b/packages/create-astro/src/data/seasonal.ts @@ -2,7 +2,7 @@ import { random } from '@astrojs/cli-kit/utils'; export default function getSeasonalHouston(fancy?: boolean) { const date = new Date(); - if ((date.getMonth() === 11 && date.getDate() === 21) || (date.getMonth() === 0 && date.getDate() === 1)) { + if (date.getMonth() === 0 && date.getDate() === 1) { // New Year return { hat: '๐ŸŽฉ', From 2cf62237069651d64301b396eccdbfd22e03db03 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jan 2024 14:36:24 -0600 Subject: [PATCH 12/15] feat(create-astro): refactor seasonal logic --- packages/create-astro/src/actions/context.ts | 8 +- packages/create-astro/src/actions/intro.ts | 12 +- packages/create-astro/src/data/seasonal.ts | 151 ++++++++++++------- packages/create-astro/src/messages.ts | 4 - 4 files changed, 106 insertions(+), 69 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index f87ac4886dc9..cbd4440764c9 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -26,6 +26,7 @@ export interface Context { stdin?: typeof process.stdin; stdout?: typeof process.stdout; exit(code: number): never; + welcome?: string; hat?: string; tie?: string; tasks: Task[]; @@ -85,7 +86,7 @@ export async function getContext(argv: string[]): Promise { ((os.platform() === 'win32' && !fancy) || skipHouston) ?? [yes, no, install, git, typescript].some((v) => v !== undefined); - const seasonalHouston = getSeasonalHouston(fancy); + const { messages, hats = [], ties = [] } = getSeasonalHouston({ fancy }); const context: Context = { help, @@ -99,8 +100,9 @@ export async function getContext(argv: string[]): Promise { projectName, template, ref: ref ?? 'latest', - hat: seasonalHouston.hat, - tie: seasonalHouston.tie, + welcome: random(messages), + hat: hats.length > 0 ? random(hats) : '', + tie: ties.length > 0 ? random(ties) : '', 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 2f58e247d788..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, tie: ctx.tie } + welcome ?? 'Let\'s build something awesome!', + ] as string[], + { clear: true, hat, tie } ); } } diff --git a/packages/create-astro/src/data/seasonal.ts b/packages/create-astro/src/data/seasonal.ts index 0751767401b7..bd36ac1592fa 100644 --- a/packages/create-astro/src/data/seasonal.ts +++ b/packages/create-astro/src/data/seasonal.ts @@ -1,69 +1,108 @@ -import { random } from '@astrojs/cli-kit/utils'; +interface SeasonalHouston { + hats?: string[]; + ties?: string[]; + messages: string[] +} -export default function getSeasonalHouston(fancy?: boolean) { - const date = new Date(); - if (date.getMonth() === 0 && date.getDate() === 1) { - // New Year - return { - hat: '๐ŸŽฉ', - tie: '๐Ÿ‘”', +export default function getSeasonalHouston({ fancy }: { fancy?: boolean }): SeasonalHouston { + const season = getSeason(); + switch (season) { + case 'new-year': { + const year = new Date().getFullYear(); + return { + hats: rarity(0.5, ['๐ŸŽฉ']), + ties: rarity(0.25, ['๐ŸŽŠ', '๐ŸŽ€', '๐ŸŽ‰']), + messages: [ + `New year, new Astro site!`, + `Kicking ${year} off with Astro?! What an honor!`, + `Happy ${year}! Let's make something cool.`, + `${year} is your year! Let's build something awesome.`, + `${year} is the year of Astro!`, + `${year} is clearly off to a great start!`, + `Thanks for starting ${year} with Astro!` + ] + } + } + case 'spooky': return { + hats: rarity(0.5, ['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€', '๐Ÿ•ท๏ธ', '๐Ÿ”ฎ']), + ties: rarity(0.25, ['๐Ÿฆด', '๐Ÿฌ', '๐Ÿซ']), messages: [ - `Hey there! It's new year and you're working! Pretty cool!` + `I'm afraid I can't help you... Just kidding!`, + `Boo! Just kidding. Let's make a website!`, + `Let's haunt the internet. OooOooOOoo!`, + `No tricks here. Seeing you is always treat!`, + `Spiders aren't the only ones building the web!`, + `Let's conjure up some web magic!`, + `Let's harness the power of Astro to build a frightful new site!`, + `We're conjuring up a spooktacular website!`, + `Prepare for a web of spooky wonders to be woven.`, + `Chills and thrills await you on your new project!`, ] } - } else if (date.getMonth() === 11) { - // Christmas season - return { - hat: random(['๐ŸŽ', '๐ŸŽ„', '๐ŸŒฒ']), - tie: '๐Ÿงฃ', + case 'holiday': return { + hats: rarity(0.75, ['๐ŸŽ', '๐ŸŽ„', '๐ŸŒฒ']), + ties: rarity(0.75, ['๐Ÿงฃ']), messages: [ - `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!`, + `'Tis the season to code and create.`, + `Jingle all the way through your web creation journey!`, + `Bells are ringing, and so are your creative ideas!`, + `Let's make the internet our own winter wonderland!`, + `It's time to decorate a brand new website!`, + `Let's unwrap the magic of the web together!`, + `Hope you're enjoying the holiday season!`, + `I'm dreaming of a brand new website!`, + `No better holiday gift than a new site!`, + `Your creativity is the gift that keeps on giving!`, ] } - } else if (date.getMonth() === 9) { - // Spooky season - return { - hat: random(['๐ŸŽƒ', '๐Ÿ‘ป', 'โ˜ ๏ธ', '๐Ÿ’€']), - tie: random(['๐Ÿฆด', '']), + default: return { + hats: fancy ? ['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ'] : undefined, + ties: fancy ? rarity(0.33, ['๐ŸŽ€', '๐Ÿงฃ']) : undefined, messages: [ - `Booo! Let's scare the interwebs!`, - `Get ready to haunt the internet with Halloween vibes.`, - `Harness the power of the web for your frightful ideas.`, - `It's time to conjure up an online spooktacular masterpiece.`, - `Prepare for a web of Halloween wonders to be woven.`, - `Chills and thrills await as you embark on your web journey`, - `The internet is about to get a whole lot creepier thanks to your new project.` + `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.`, ] } } - // default state - return { - hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : '', - tie: fancy ? random(['๐ŸŽ€', '๐Ÿงฃ']) : '', - messages: [ - `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.`, - ] +} + +type Season = 'spooky' | 'holiday' | 'new-year'; +function getSeason(): Season | undefined { + const date = new Date(); + const month = date.getMonth() + 1; + const day = date.getDate() + 1; + + if (month === 1 && day <= 7) { + return 'new-year'; + } + if (month === 10 && day > 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 1e9fda95668f..a11f45acd0f7 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -4,7 +4,6 @@ import { align, sleep } from '@astrojs/cli-kit/utils'; import { exec } from 'node:child_process'; import stripAnsi from 'strip-ansi'; import { shell } from './shell.js'; -import getSeasonalHouston from './data/seasonal.js'; // Users might lack access to the global npm registry, this function // checks the user's project type and will return the proper npm registry @@ -40,9 +39,6 @@ export async function spinner(args: { export const title = (text: string) => align(label(text), 'end', 7) + ' '; -export const seasonalHouston = getSeasonalHouston(); -export const welcome = seasonalHouston.messages; - export const getName = () => new Promise((resolve) => { exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName) => { From 146450a0f31b40bb6ee7193186215363b6735c5e Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jan 2024 14:39:39 -0600 Subject: [PATCH 13/15] chore: remove unused entrypoint --- packages/create-astro/src/data/index.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/create-astro/src/data/index.ts diff --git a/packages/create-astro/src/data/index.ts b/packages/create-astro/src/data/index.ts deleted file mode 100644 index 04b79710c37a..000000000000 --- a/packages/create-astro/src/data/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {default as getSeasonalHouston} from './seasonal.js' From da9479834962cdfb01c93f274552e0f2d4efa329 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jan 2024 14:39:50 -0600 Subject: [PATCH 14/15] refactor: simplify seasonal data --- packages/create-astro/src/actions/context.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index cbd4440764c9..51ee6280bc89 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -4,7 +4,7 @@ import arg from 'arg'; import os from 'node:os'; import { getName, getVersion } from '../messages.js'; -import getSeasonalHouston from '../data/seasonal.js'; +import getSeasonalData from '../data/seasonal.js'; export interface Context { help: boolean; @@ -86,7 +86,7 @@ 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 = [] } = getSeasonalHouston({ fancy }); + const { messages, hats, ties } = getSeasonalData({ fancy }); const context: Context = { help, @@ -101,8 +101,8 @@ export async function getContext(argv: string[]): Promise { template, ref: ref ?? 'latest', welcome: random(messages), - hat: hats.length > 0 ? random(hats) : '', - tie: ties.length > 0 ? random(ties) : '', + hat: hats ? random(hats) : undefined, + tie: ties ? random(ties) : undefined, yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), From 38542227ee68fb831c93b7e8b8bec6443f61ac38 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jan 2024 14:44:47 -0600 Subject: [PATCH 15/15] chore: add changeset --- .changeset/afraid-ligers-add.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/afraid-ligers-add.md 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