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 }