Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 004941e

Browse files
committed
support env list filter
1 parent 9cff9c3 commit 004941e

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

lib/env/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ function getEnvInfo(envId) {
5454
});
5555
}
5656
exports.getEnvInfo = getEnvInfo;
57-
function listEnvs() {
57+
function listEnvs(options = {}) {
5858
return __awaiter(this, void 0, void 0, function* () {
59+
const { source } = options;
5960
const res = yield tcbService.request('DescribeEnvs');
60-
const { EnvList = [] } = res;
61+
let { EnvList = [] } = res;
62+
if (source && Array.isArray(source)) {
63+
EnvList = EnvList.filter(item => source.includes(item.Source));
64+
}
6165
return EnvList;
6266
});
6367
}

src/env/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ export async function getEnvInfo(envId: string) {
4545
}
4646

4747
// 列出所有环境
48-
export async function listEnvs() {
48+
export async function listEnvs(options: { source?: string[] } = {}) {
49+
const { source } = options
4950
const res: any = await tcbService.request('DescribeEnvs')
50-
const { EnvList = [] } = res
51+
let { EnvList = [] } = res
52+
// 过滤为指定 source 环境
53+
if (source && Array.isArray(source)) {
54+
EnvList = EnvList.filter(item => source.includes(item.Source))
55+
}
5156
return EnvList
5257
}
5358

types/env/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export declare function createEnv({ alias }: {
55
alias: any;
66
}): Promise<any>;
77
export declare function getEnvInfo(envId: string): Promise<any>;
8-
export declare function listEnvs(): Promise<any>;
8+
export declare function listEnvs(options?: {
9+
source?: string[];
10+
}): Promise<any>;
911
export declare function updateEnvInfo({ envId, alias }: {
1012
envId: any;
1113
alias: any;

0 commit comments

Comments
 (0)