From 58b1b3089221703d8c4932fc9101ffc21ffe0973 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 20 Mar 2025 21:03:39 +0800 Subject: [PATCH] refactor: remove cli/prepare module --- packages/core/src/cli/index.ts | 28 ++++++++++++++++++++++++++-- packages/core/src/cli/prepare.ts | 30 ------------------------------ 2 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 packages/core/src/cli/prepare.ts diff --git a/packages/core/src/cli/index.ts b/packages/core/src/cli/index.ts index df6cfd7d9d..552293012f 100644 --- a/packages/core/src/cli/index.ts +++ b/packages/core/src/cli/index.ts @@ -1,9 +1,33 @@ import { logger } from '../logger'; import { setupCommands } from './commands'; -import { prepareCli } from './prepare'; + +function initNodeEnv() { + if (!process.env.NODE_ENV) { + const command = process.argv[2]; + process.env.NODE_ENV = ['build', 'preview'].includes(command) + ? 'production' + : 'development'; + } +} export async function runCLI(): Promise { - prepareCli(); + initNodeEnv(); + + // make it easier to identify the process via activity monitor or other tools + process.title = 'rsbuild-node'; + + // Print a blank line to keep the greet log nice. + // Some package managers automatically output a blank line, some do not. + const { npm_execpath } = process.env; + if ( + !npm_execpath || + npm_execpath.includes('npx-cli.js') || + npm_execpath.includes('.bun') + ) { + console.log(); + } + + logger.greet(` ${`Rsbuild v${RSBUILD_VERSION}`}\n`); try { setupCommands(); diff --git a/packages/core/src/cli/prepare.ts b/packages/core/src/cli/prepare.ts deleted file mode 100644 index 865fd1d2ec..0000000000 --- a/packages/core/src/cli/prepare.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { logger } from '../logger'; - -function initNodeEnv() { - if (!process.env.NODE_ENV) { - const command = process.argv[2]; - process.env.NODE_ENV = ['build', 'preview'].includes(command) - ? 'production' - : 'development'; - } -} - -export function prepareCli(): void { - initNodeEnv(); - - // make it easier to identify the process via activity monitor or other tools - process.title = 'rsbuild-node'; - - // Print a blank line to keep the greet log nice. - // Some package managers automatically output a blank line, some do not. - const { npm_execpath } = process.env; - if ( - !npm_execpath || - npm_execpath.includes('npx-cli.js') || - npm_execpath.includes('.bun') - ) { - console.log(); - } - - logger.greet(` ${`Rsbuild v${RSBUILD_VERSION}`}\n`); -}