Skip to content

Commit

Permalink
feat(@142vip/fairy-cli): release发布命令增加--filter可选参数,支持多次调用,用于指定模块路径
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Sep 12, 2024
1 parent 208d3ad commit d0cc1e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/fairy-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface ReleaseOptions extends Pick<VersionBumpOptions, 'preid' | 'tag' | 'com
interface VipReleaseExtraOptions {
branch?: string
checkRelease?: boolean
filter?: string[]
vip?: boolean
}

Expand Down Expand Up @@ -101,14 +102,14 @@ function printPreCheckRelease() {
/**
* 执行142vip开源仓库迭代
*/
function execVipRelease(args: { checkRelease?: boolean }) {
function execVipRelease(args: VipReleaseExtraOptions) {
// 预先检查子模块
if (args.checkRelease) {
printPreCheckRelease()
process.exit(0)
}

const pkgJSON = getReleasePkgJSON('./packages/*')
const pkgJSON = getReleasePkgJSON(args.filter)

// 对话框
select({
Expand Down Expand Up @@ -166,6 +167,11 @@ export async function releaseMain(program: Command) {
.option('--package <package>', '指定需要发布的包')
.option('--branch <branch>', '指定分支进行发布')
.option('--check-release', '发布仓库主版本时,校验monorepo中子模块版本', false)
.option('-F, --filter <filter>', '模块的路径,例如:"./package/*"', (value: string, previous: string[]) => {
if (!value)
return [value]
return previous.concat(value)
}, [])
.option('--vip', '是否为@142vip组织专用功能', false)
.action(async (args: ReleaseOptions & VipReleaseExtraOptions) => {
// console.log(CliCommandEnum.RELEASE, args)
Expand All @@ -183,6 +189,7 @@ export async function releaseMain(program: Command) {
if (args.vip) {
execVipRelease({
checkRelease: args.checkRelease,
filter: args.filter,
})
}
else {
Expand Down
19 changes: 17 additions & 2 deletions packages/fairy-cli/src/shared/release-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ interface ValidateResponse {
* - filter参数: https://pnpm.io/filtering
*
*/
export function getReleasePkgJSON(filter?: string) {
export function getReleasePkgJSON(filter?: string | string[]) {
try {
const command = `pnpm ls --json --only-projects --filter "${filter ?? './packages/*'}" --depth -1`
// 格式: --filter ./packages/*
let filterRgx = ''
if (filter == null || filter.length === 0) {
filterRgx = '--filter "./packages/*"'
}
else {
if (Array.isArray(filter)) {
for (const f of filter) {
filterRgx += `--filter "${f}" `
}
}
else {
filterRgx = `--filter "${filter}"`
}
}
const command = `pnpm ls --json --only-projects ${filterRgx} --depth -1`
const packageStr = execSync(command).toString().trim()
return JSON.parse(packageStr) as Array<PackageJSON>
}
Expand Down

0 comments on commit d0cc1e7

Please sign in to comment.