From 76ce0b8fc7a41dc8488d30b60b7879d93a052d7e Mon Sep 17 00:00:00 2001 From: "guo.xu" Date: Wed, 24 Feb 2021 22:28:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9A=B4=E9=9C=B2getCmdArgs=E4=BE=9B?= =?UTF-8?q?=E7=BB=99api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/exports/pluginAPI.ts | 5 ++++- packages/core/src/cli/Service.ts | 20 ++++++++++++++++++- packages/plugin-build-lib/src/plugin/types.ts | 5 ++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/exports/pluginAPI.ts b/packages/cli/src/exports/pluginAPI.ts index e761288..c2f0bdb 100644 --- a/packages/cli/src/exports/pluginAPI.ts +++ b/packages/cli/src/exports/pluginAPI.ts @@ -3,7 +3,9 @@ import type { IPathManager, IConfigManager, IEnvManager, - IPluginManager + IPluginManager, + IArgs, + IRawArgs } from '@xus/core' import type { IConfig } from './create' import { IBuildLibMethods } from '@xus/plugin-build-lib' @@ -15,6 +17,7 @@ export interface IPluginAPI extends IPluginAPIBase { // service lifycycle onPluginReady: noopFn onRunCmd: noopFn + getCmdArgs: () => { args: IArgs; rawArgs: IRawArgs } // path manager cwd: IPathManager['cwd'] diff --git a/packages/core/src/cli/Service.ts b/packages/core/src/cli/Service.ts index 21dd198..3eec6a8 100644 --- a/packages/core/src/cli/Service.ts +++ b/packages/core/src/cli/Service.ts @@ -106,6 +106,17 @@ export class CliService { ;['onConfigReady', 'onPluginReady', 'onRunCmd'].forEach((methodName) => { api.registerMethod({ methodName, throwOnExist: false }) }) + // register cmd args getter + api.registerMethod({ + methodName: 'getCmdArgs', + throwOnExist: false, + fn: async () => { + return await this.HookManager.apply({ + name: 'cmd:args', + type: HookTypes.serial + }) + } + }) // only proxy get const managerProxyMap = { ConfigManager: ['projectConfig', 'cwdPkgJson', 'loadConfig'], @@ -181,7 +192,14 @@ export class CliService { name: 'runCmd', type: HookTypes.event }) - + // for api + this.HookManager.register({ + name: 'cmd:args', + pluginName: 'xus:service', + fn() { + return { args, rawArgs } + } + }) const { fn } = command return fn(args, rawArgs) } diff --git a/packages/plugin-build-lib/src/plugin/types.ts b/packages/plugin-build-lib/src/plugin/types.ts index 0f3495b..90d6b20 100644 --- a/packages/plugin-build-lib/src/plugin/types.ts +++ b/packages/plugin-build-lib/src/plugin/types.ts @@ -25,13 +25,12 @@ export type ILibBuildRes = { export interface ILibBuildOps { targets: ILibBuildTargets[] watch: boolean + pointPkg: string [key: string]: any } export interface IBundlerImp { - build: ( - ops: T - ) => Promise + build: (ops: ILibBuildOps) => Promise [key: string]: any }