From a0ebd7934327d6fad1f68a43368d9a56047f39b1 Mon Sep 17 00:00:00 2001 From: onsclom Date: Mon, 18 Dec 2023 19:35:41 -0800 Subject: [PATCH 1/7] Upgrade @astrojs/cli-kit --- 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 417ebc08447a..9a62aca78b63 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.3.1", + "@astrojs/cli-kit": "^0.4.0", "giget": "1.1.3" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ac3873c8215..58c3aa0cab09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3691,8 +3691,8 @@ importers: packages/create-astro: dependencies: '@astrojs/cli-kit': - specifier: ^0.3.1 - version: 0.3.1 + specifier: ^0.4.0 + version: 0.4.0 giget: specifier: 1.1.3 version: 1.1.3 @@ -5186,8 +5186,8 @@ packages: sisteransi: 1.0.5 dev: false - /@astrojs/cli-kit@0.3.1: - resolution: {integrity: sha512-BEzf3gudr4XrrrInJKD+GSS5O+GXRTukLUpOfgqdTSq6d48EWVhigNHobmlQGbpa9FEAw+sZmvmHmhS29QhnwA==} + /@astrojs/cli-kit@0.4.0: + resolution: {integrity: sha512-M7R2Af/Gh13pwZ2zjTkTPt87x4IjRw/bSRCmjJGWEGeW3nLNzuEeRY8tleeIGbbfUsm3DJg+UF5rCrQGoviHgQ==} engines: {node: '>=18.14.1'} dependencies: chalk: 5.3.0 From 0e64cd7c400c4deeec86948cf5a8020943692aa8 Mon Sep 17 00:00:00 2001 From: onsclom Date: Mon, 18 Dec 2023 20:33:30 -0800 Subject: [PATCH 2/7] Add tasks to context --- packages/create-astro/src/actions/context.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index a7f2e6d8c71d..7a401162544d 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -1,4 +1,4 @@ -import { prompt } from '@astrojs/cli-kit'; +import { prompt, type Task } from '@astrojs/cli-kit'; import { random } from '@astrojs/cli-kit/utils'; import arg from 'arg'; import os from 'node:os'; @@ -26,6 +26,7 @@ export interface Context { stdout?: typeof process.stdout; exit(code: number): never; hat?: string; + tasks: Task[]; } export async function getContext(argv: string[]): Promise { @@ -103,6 +104,7 @@ export async function getContext(argv: string[]): Promise { exit(code) { process.exit(code); }, + tasks: [], }; return context; } From 6403d9b5525805336d9bbe7f05d97c0b1efd2d13 Mon Sep 17 00:00:00 2001 From: onsclom Date: Mon, 18 Dec 2023 20:33:55 -0800 Subject: [PATCH 3/7] Change steps to use tasks --- packages/create-astro/src/actions/dependencies.ts | 7 ++++--- packages/create-astro/src/actions/git.ts | 9 ++++++--- packages/create-astro/src/actions/template.ts | 7 ++++--- packages/create-astro/src/actions/typescript.ts | 15 ++++++++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts index 26557d5a2f1d..d5f58a012a0a 100644 --- a/packages/create-astro/src/actions/dependencies.ts +++ b/packages/create-astro/src/actions/dependencies.ts @@ -1,12 +1,12 @@ import { color } from '@astrojs/cli-kit'; import fs from 'node:fs'; import path from 'node:path'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; import { shell } from '../shell.js'; import type { Context } from './context.js'; export async function dependencies( - ctx: Pick + ctx: Pick ) { let deps = ctx.install ?? ctx.yes; if (deps === undefined) { @@ -24,7 +24,8 @@ export async function dependencies( if (ctx.dryRun) { await info('--dry-run', `Skipping dependency installation`); } else if (deps) { - await spinner({ + ctx.tasks.push({ + pending: 'Install dependencies', start: `Installing dependencies with ${ctx.packageManager}...`, end: 'Dependencies installed', onError: (e) => { diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts index dd703b1f559c..d9b3f71d4975 100644 --- a/packages/create-astro/src/actions/git.ts +++ b/packages/create-astro/src/actions/git.ts @@ -3,10 +3,12 @@ import path from 'node:path'; import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; import { shell } from '../shell.js'; -export async function git(ctx: Pick) { +export async function git( + ctx: Pick +) { if (fs.existsSync(path.join(ctx.cwd, '.git'))) { await info('Nice!', `Git has already been initialized`); return; @@ -26,7 +28,8 @@ export async function git(ctx: Pick diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index bdb32607692b..7701eb616337 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -4,10 +4,10 @@ import { color } from '@astrojs/cli-kit'; import { downloadTemplate } from 'giget'; import fs from 'node:fs'; import path from 'node:path'; -import { error, info, spinner, title } from '../messages.js'; +import { error, info, title } from '../messages.js'; export async function template( - ctx: Pick + ctx: Pick ) { if (!ctx.template && ctx.yes) ctx.template = 'basics'; @@ -32,7 +32,8 @@ export async function template( if (ctx.dryRun) { await info('--dry-run', `Skipping template copying`); } else if (ctx.template) { - await spinner({ + ctx.tasks.push({ + pending: 'Copy template', start: 'Template copying...', end: 'Template copied', while: () => diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts index 2c0d21e89bcb..4989599fdd6c 100644 --- a/packages/create-astro/src/actions/typescript.ts +++ b/packages/create-astro/src/actions/typescript.ts @@ -4,12 +4,20 @@ import { color } from '@astrojs/cli-kit'; import { readFile, rm, writeFile } from 'node:fs/promises'; import path from 'node:path'; import stripJsonComments from 'strip-json-comments'; -import { error, info, spinner, title, typescriptByDefault } from '../messages.js'; +import { error, info, title, typescriptByDefault } from '../messages.js'; import { shell } from '../shell.js'; type PickedTypeScriptContext = Pick< Context, - 'typescript' | 'yes' | 'prompt' | 'dryRun' | 'cwd' | 'exit' | 'packageManager' | 'install' + | 'typescript' + | 'yes' + | 'prompt' + | 'dryRun' + | 'cwd' + | 'exit' + | 'packageManager' + | 'install' + | 'tasks' >; export async function typescript(ctx: PickedTypeScriptContext) { @@ -61,7 +69,8 @@ export async function typescript(ctx: PickedTypeScriptContext) { if (ts === 'relaxed' || ts === 'default') { ts = 'base'; } - await spinner({ + ctx.tasks.push({ + pending: 'Customize TypeScript', start: 'TypeScript customizing...', end: 'TypeScript customized', while: () => From 69c60a24e8f58c8e0b4470972960953ccc15d11c Mon Sep 17 00:00:00 2001 From: onsclom Date: Mon, 18 Dec 2023 20:36:03 -0800 Subject: [PATCH 4/7] Do tasks at end --- packages/create-astro/src/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index f641e876e414..b3c4817fa6c3 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -10,6 +10,7 @@ import { template } from './actions/template.js'; import { setupTypeScript, typescript } from './actions/typescript.js'; import { verify } from './actions/verify.js'; import { setStdout } from './messages.js'; +import { tasks } from '@astrojs/cli-kit'; const exit = () => process.exit(0); process.on('SIGINT', exit); @@ -43,12 +44,23 @@ export async function main() { // Steps which write to files need to go above git git, - next, ]; for (const step of steps) { await step(ctx); } + + // eslint-disable-next-line no-console + console.log(''); + + const labels = { + start: 'Initializing project...', + end: 'Project initialized!', + }; + await tasks(labels, ctx.tasks); + + await next(ctx); + process.exit(0); } From 7e798f36465cbfc19648b073f668bb158c9891d3 Mon Sep 17 00:00:00 2001 From: onsclom Date: Mon, 18 Dec 2023 20:47:51 -0800 Subject: [PATCH 5/7] Add changeset --- .changeset/chatty-penguins-sin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chatty-penguins-sin.md diff --git a/.changeset/chatty-penguins-sin.md b/.changeset/chatty-penguins-sin.md new file mode 100644 index 000000000000..e980cc38fffc --- /dev/null +++ b/.changeset/chatty-penguins-sin.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Defer async actions until after user input From 94cc24972c1e7f5ea0f7923ccce9f93e4b631006 Mon Sep 17 00:00:00 2001 From: Austin Merrick Date: Fri, 22 Dec 2023 09:49:26 -0800 Subject: [PATCH 6/7] Make labels more consistent Co-authored-by: Nate Moore --- packages/create-astro/src/actions/dependencies.ts | 4 ++-- packages/create-astro/src/actions/git.ts | 2 +- packages/create-astro/src/actions/template.ts | 2 +- packages/create-astro/src/actions/typescript.ts | 2 +- packages/create-astro/src/index.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts index d5f58a012a0a..e420fcb716e3 100644 --- a/packages/create-astro/src/actions/dependencies.ts +++ b/packages/create-astro/src/actions/dependencies.ts @@ -25,8 +25,8 @@ export async function dependencies( await info('--dry-run', `Skipping dependency installation`); } else if (deps) { ctx.tasks.push({ - pending: 'Install dependencies', - start: `Installing dependencies with ${ctx.packageManager}...`, + pending: 'Dependencies', + start: `Dependencies installing with ${ctx.packageManager}...`, end: 'Dependencies installed', onError: (e) => { error('error', e); diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts index d9b3f71d4975..bd038f3f5236 100644 --- a/packages/create-astro/src/actions/git.ts +++ b/packages/create-astro/src/actions/git.ts @@ -29,7 +29,7 @@ export async function git( await info('--dry-run', `Skipping Git initialization`); } else if (_git) { ctx.tasks.push({ - pending: 'Initialize git', + pending: 'Git', start: 'Git initializing...', end: 'Git initialized', while: () => diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 7701eb616337..fa88fd503044 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -33,7 +33,7 @@ export async function template( await info('--dry-run', `Skipping template copying`); } else if (ctx.template) { ctx.tasks.push({ - pending: 'Copy template', + pending: 'Template', start: 'Template copying...', end: 'Template copied', while: () => diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts index 4989599fdd6c..0ac1c753d50c 100644 --- a/packages/create-astro/src/actions/typescript.ts +++ b/packages/create-astro/src/actions/typescript.ts @@ -70,7 +70,7 @@ export async function typescript(ctx: PickedTypeScriptContext) { ts = 'base'; } ctx.tasks.push({ - pending: 'Customize TypeScript', + pending: 'TypeScript', start: 'TypeScript customizing...', end: 'TypeScript customized', while: () => diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index b3c4817fa6c3..2ffdd00b7dd3 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -54,7 +54,7 @@ export async function main() { console.log(''); const labels = { - start: 'Initializing project...', + start: 'Project initializing...', end: 'Project initialized!', }; await tasks(labels, ctx.tasks); From 60ff4e6d1cc8201583efd921f377d6a2ccb2cdf8 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 2 Jan 2024 15:18:31 -0600 Subject: [PATCH 7/7] Update .changeset/chatty-penguins-sin.md Co-authored-by: Sarah Rainsberger --- .changeset/chatty-penguins-sin.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/chatty-penguins-sin.md b/.changeset/chatty-penguins-sin.md index e980cc38fffc..5c6a1bdf0d72 100644 --- a/.changeset/chatty-penguins-sin.md +++ b/.changeset/chatty-penguins-sin.md @@ -2,4 +2,4 @@ 'create-astro': minor --- -Defer async actions until after user input +Improves the `create astro` CLI experience by asking all the questions upfront, then creating your new Astro project based on your responses.