From f9569275aeef1b152116cef729019dcef40b29de Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 5 Dec 2024 15:29:23 +0800 Subject: [PATCH] feat(app-tools): enable Rsbuild CLI shortcuts --- .changeset/afraid-socks-jam.md | 7 +++++++ packages/cli/uni-builder/src/shared/parseCommonConfig.ts | 4 ++-- packages/solutions/app-tools/src/config/default.ts | 6 ++++++ packages/toolkit/utils/src/cli/prettyInstructions.ts | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/afraid-socks-jam.md diff --git a/.changeset/afraid-socks-jam.md b/.changeset/afraid-socks-jam.md new file mode 100644 index 000000000000..38951651a0d9 --- /dev/null +++ b/.changeset/afraid-socks-jam.md @@ -0,0 +1,7 @@ +--- +'@modern-js/app-tools': patch +'@modern-js/uni-builder': patch +'@modern-js/utils': patch +--- + +feat(app-tools): enable Rsbuild CLI shortcuts diff --git a/packages/cli/uni-builder/src/shared/parseCommonConfig.ts b/packages/cli/uni-builder/src/shared/parseCommonConfig.ts index b1351d60ea42..adc490c0ef2c 100644 --- a/packages/cli/uni-builder/src/shared/parseCommonConfig.ts +++ b/packages/cli/uni-builder/src/shared/parseCommonConfig.ts @@ -316,14 +316,14 @@ export async function parseCommonConfig( }; } - const { dev: RsbuildDev, server } = transformToRsbuildServerOptions( + const { dev: rsbuildDev, server } = transformToRsbuildServerOptions( dev || {}, devServer || {}, ); rsbuildConfig.server = removeUndefinedKey(server); - rsbuildConfig.dev = removeUndefinedKey(RsbuildDev); + rsbuildConfig.dev = removeUndefinedKey(rsbuildDev); rsbuildConfig.html = html; rsbuildConfig.output = output; diff --git a/packages/solutions/app-tools/src/config/default.ts b/packages/solutions/app-tools/src/config/default.ts index c33b3d870b56..ab82f6025006 100644 --- a/packages/solutions/app-tools/src/config/default.ts +++ b/packages/solutions/app-tools/src/config/default.ts @@ -11,6 +11,12 @@ export function createDefaultConfig( // `dev.port` should not have a default value // because we will use `server.port` by default port: undefined, + cliShortcuts: { + help: false, + // does not support restart server and print urls yet + custom: (shortcuts = []) => + shortcuts.filter(({ key }) => key !== 'r' && key !== 'u'), + }, }; const output: AppUserConfig['output'] = { diff --git a/packages/toolkit/utils/src/cli/prettyInstructions.ts b/packages/toolkit/utils/src/cli/prettyInstructions.ts index bd024cf87afb..cb4a380e3273 100644 --- a/packages/toolkit/utils/src/cli/prettyInstructions.ts +++ b/packages/toolkit/utils/src/cli/prettyInstructions.ts @@ -142,5 +142,11 @@ export const prettyInstructions = (appContext: any, config: any) => { ); } + if (config.dev?.cliShortcuts) { + message += ` ${chalk.dim('> press')} ${chalk.bold( + 'h + enter', + )} ${chalk.dim('to show shortcuts')}\n`; + } + return message; };