forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataSource.ts
More file actions
43 lines (39 loc) · 1.16 KB
/
dataSource.ts
File metadata and controls
43 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import changeCase from 'change-case';
import type { IProjectInfo } from '../types/intermediate';
export type DataSourceDependenciesConfig = {
/** 数据源引擎的版本 */
engineVersion?: string;
/** 数据源引擎的包名 */
enginePackage?: string;
/** 数据源 handlers 的版本 */
handlersVersion?: {
[key: string]: string;
};
/** 数据源 handlers 的包名 */
handlersPackages?: {
[key: string]: string;
};
};
export function buildDataSourceDependencies(
ir: IProjectInfo,
cfg: DataSourceDependenciesConfig = {},
): Record<string, string> {
return {
// 数据源引擎的依赖包
[cfg.enginePackage || '@alilc/lowcode-datasource-engine']: cfg.engineVersion || 'latest',
// 各种数据源的 handlers 的依赖包
...(ir.dataSourcesTypes || []).reduce(
(acc, dsType) => ({
...acc,
[getDataSourceHandlerPackageName(dsType)]: cfg.handlersVersion?.[dsType] || 'latest',
}),
{},
),
};
function getDataSourceHandlerPackageName(dsType: string) {
return (
cfg.handlersPackages?.[dsType] ||
`@alilc/lowcode-datasource-${changeCase.kebab(dsType)}-handler`
);
}
}