Skip to content
On this page

配置索引

类型

ts
interface DefaultParams {
  mode: Mode
  push: boolean
}
interface ExecuteCommandConfig extends DefaultParams {
  packagesPath: string | string[] | undefined
  version: CommandVersionParams
  publish: CommandPublishParams
  run: CommandRunParams
  plugins: Array<PluginData | string>
}

通过类型提示编写配置

ts
// pkgs.config.ts
import { defineConfig } from '@abmao/pkgs'

export default defineConfig({})

配置读取

支持的配置方式如下:

  • 根目录
    • pkgs.config.ts
    • pkgs.config.js
    • pkgs.config.cjs
    • pkgs.config.mjs
    • pkgs.config.json
  • package.json的字段
    • pkgs

选项

packagesPath

  • 类型: string | string[] | undefined
  • 默认值: 'packages/*'

工作区

mode

  • 类型: 'sync' | 'diff'
  • 默认值: 'sync'

分别对应 lerna 的固定模式(Fixed)或独立模式(Independent)

push

  • 类型: boolean
  • 默认值: true

version 和 publish 后是否需要推送到远程仓库

version

关于 version 命令配置

version.mode

  • 类型: 'sync' | 'diff'
  • 默认值: 'sync'

优先级比 mode 高

version.message

  • 类型: string
  • 默认值: 'chore: version %s'

version 成功后,会进行一次 git commit ,你可以自定义它的 message 。%s 是内部基于包与版本生成的文案

version.push

  • 类型: boolean
  • 默认值: true

优先级比 mode 高

publish

关于 publish 命令配置

publish.mode

  • 类型: 'sync' | 'diff'
  • 默认值: 'sync'

优先级比 mode 高

publish.push

  • 类型: boolean
  • 默认值: true

优先级比 mode 高

run

关于 run 命令配置

run.type

  • 类型: 'all' | 'work' | 'stage' | 'repository'
  • 默认值: 'all'

all[全部] | work(工作区) | stage(暂存区) | repository(版本库),不同模式对应不同的diff区域对比,并且会分析你的包顺序,智能运行你的命令

run.mode

  • 类型: 'sync' | 'diff'
  • 默认值: 'sync'

优先级比 mode 高

run.DAG
  • 类型: boolean
  • 默认值: true

我依赖的包是否做拓扑排序,依次执行

例如:pkgs run build,构建之前,需要先构建我依赖的包,从而才能正确构建当前包,不然我依赖的包如果没有构建物,会导致构建失败

run.serial
  • 类型: boolean
  • 默认值: true

命令是否串行执行,否则并行

例如:pkgs run build,构建之前,需要根据依赖关系依次执行

plugins

插件入口,支持函数、路径、模块名

类型

ts
interface BasePluginData<T extends any[] = any> {
  id: string // 插件唯一标识
  command: string // 命令
  description: string // 详情
  options?: PluginOption[] // 选择命令
  allowUnknownOption?: boolean // 是否允许传输未定义的 options 命令参数
  action: (context: Context, ...args: T) => void // 执行逻辑
}
type PluginData = Readonly<BasePluginData>
type PluginOption = readonly [flags: string, description?: string, defaultValue?: string | boolean]