Skip to content

Commit

Permalink
feat: 暴露getCmdArgs供给api
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Feb 24, 2021
1 parent e5714e0 commit 76ce0b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/exports/pluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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']
Expand Down
20 changes: 19 additions & 1 deletion packages/core/src/cli/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-build-lib/src/plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export type ILibBuildRes = {
export interface ILibBuildOps {
targets: ILibBuildTargets[]
watch: boolean
pointPkg: string
[key: string]: any
}

export interface IBundlerImp {
build: <T extends ILibBuildOps = ILibBuildOps>(
ops: T
) => Promise<ILibBuildRes>
build: (ops: ILibBuildOps) => Promise<ILibBuildRes>
[key: string]: any
}

Expand Down

0 comments on commit 76ce0b8

Please sign in to comment.