From 5dcf522488134c6756b86d7ff75fda88e15eeacc Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Fri, 25 Oct 2024 20:36:37 -0400 Subject: [PATCH] lil tidy --- packages/cli/src/commands/init.ts | 42 ++++++--------------------- packages/cli/src/commands/update.ts | 12 ++------ packages/cli/src/utils/auto-detect.ts | 4 +-- 3 files changed, 13 insertions(+), 45 deletions(-) diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 4e05035b2..e35ee37e6 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -14,7 +14,7 @@ import { import { error, handleError } from "../utils/errors.js"; import type { Config } from "../utils/get-config.js"; import * as cliConfig from "../utils/get-config.js"; -import { intro, prettifyList } from "../utils/prompt-helpers.js"; +import { cancel, intro, prettifyList } from "../utils/prompt-helpers.js"; import * as p from "../utils/prompts.js"; import * as registry from "../utils/registry/index.js"; import { resolveImport } from "../utils/resolve-imports.js"; @@ -154,10 +154,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option })), }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); style = input; } @@ -175,10 +172,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option })), }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); tailwindBaseColor = input; } @@ -201,10 +195,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option }, }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); globalCss = input; } @@ -227,10 +218,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option }, }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); tailwindConfig = input; } @@ -245,10 +233,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option validate: (value) => validateImportAlias(value, langConfig), }); - if (p.isCancel(promptResult)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(promptResult)) cancel(); componentAlias = promptResult; } @@ -267,10 +252,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option validate: (value) => validateImportAlias(value, langConfig), }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); utilsAlias = input; } @@ -285,10 +267,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option validate: (value) => validateImportAlias(value, langConfig), }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); hooksAlias = input; } @@ -303,10 +282,7 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option validate: (value) => validateImportAlias(value, langConfig), }); - if (p.isCancel(input)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(input)) cancel(); uiAlias = input; } diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index 3d4ae3852..8712b3f57 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -9,7 +9,7 @@ import { detectPM } from "../utils/auto-detect.js"; import { error, handleError } from "../utils/errors.js"; import * as cliConfig from "../utils/get-config.js"; import { getEnvProxy } from "../utils/get-env-proxy.js"; -import { intro, prettifyList } from "../utils/prompt-helpers.js"; +import { cancel, intro, prettifyList } from "../utils/prompt-helpers.js"; import * as p from "../utils/prompts.js"; import * as registry from "../utils/registry/index.js"; import { UTILS, UTILS_JS } from "../utils/templates.js"; @@ -132,10 +132,7 @@ async function runUpdate(cwd: string, config: cliConfig.Config, options: UpdateO })), }); - if (p.isCancel(selected)) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(selected)) cancel(); selectedComponents = selected; } else { @@ -149,10 +146,7 @@ async function runUpdate(cwd: string, config: cliConfig.Config, options: UpdateO initialValue: true, }); - if (p.isCancel(proceed) || proceed === false) { - p.cancel("Operation cancelled."); - process.exit(0); - } + if (p.isCancel(proceed) || proceed === false) cancel(); } // `update utils` - update the utils.(ts|js) file diff --git a/packages/cli/src/utils/auto-detect.ts b/packages/cli/src/utils/auto-detect.ts index a5a24f628..2a31d9ac7 100644 --- a/packages/cli/src/utils/auto-detect.ts +++ b/packages/cli/src/utils/auto-detect.ts @@ -115,9 +115,7 @@ export async function detectPM(cwd: string, prompt: boolean): Promise