/
configuration.ts
160 lines (132 loc) 路 3.84 KB
/
configuration.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { Project } from './';
import { Dictionary } from '../lang';
export interface PackageData {
name: string;
version: string;
}
export interface PlatformSpecifier {
multiplatform?: boolean;
platform?: string;
platforms?: string[];
}
export interface DependencyPlatformSpecifier extends PlatformSpecifier {
kit?: boolean;
}
export interface TaskDescriptor {
name: string;
cwd?: string;
env?: Dictionary<string>;
args?: string[];
}
export interface CommandDescriptor {
name: string;
cwd?: string;
env?: Dictionary<string>;
args?: string[];
}
export type TaskConfiguration = string | TaskDescriptor;
export type CommandConfiguration = string | CommandDescriptor;
export interface ProcedureConfiguration {
description?: string;
task?: TaskConfiguration;
command?: CommandConfiguration;
multiplatform?: boolean;
platform?: string;
platforms?: string[];
}
export interface FileMappingDescriptor {
pattern: string;
baseDir?: string;
package?: string;
path?: string;
platform?: string;
platforms?: string[];
}
export type FileMappingConfiguration = string | FileMappingDescriptor;
export interface ArtifactMetadataItem {
id: string;
platform?: string;
path: string;
}
export interface ArtifactMetadata {
name: string;
version: string;
artifacts: ArtifactMetadataItem[];
[key: string]: any;
}
export interface ArtifactConfiguration {
id?: string;
baseDir?: string;
targetDir?: string;
files: FileMappingConfiguration[];
}
export interface HostConfiguration {
platform?: string;
}
export interface ProjectConfiguration {
name?: string;
version?: string;
distDir?: string;
depsDir?: string;
plugins?: string[];
host?: HostConfiguration;
platform?: PlatformConfiguration;
platforms?: PlatformConfiguration[] | string;
dependencies?: DependencyConfiguration[];
procedures?: ProcedureConfiguration[];
artifact?: ArtifactConfiguration;
}
export interface PlatformInfo {
name: string;
env?: Dictionary<string>;
variables?: Dictionary<any>;
}
export type PlatformConfiguration = string | PlatformInfo;
export interface DependencyConfiguration extends DependencyPlatformSpecifier {
name: string;
targetDir?: string;
}
export namespace Configuration {
export interface MatchedPlatformsResult {
platforms: PlatformInfo[];
specified: boolean;
}
export function getMatchedDependencyPlatforms(specifier: DependencyPlatformSpecifier, platforms: PlatformInfo[], hostPlatform: string): MatchedPlatformsResult {
if (specifier.kit) {
let platformNames = specifier.platforms ?
specifier.platforms :
[specifier.platform || hostPlatform];
platforms = platformNames.map(name => {
return {
name
};
});
}
return getMatchedPlatforms(specifier, platforms);
}
export function getMatchedPlatforms(specifier: PlatformSpecifier, platforms: PlatformInfo[]): MatchedPlatformsResult {
let platformNames = specifier.platforms ?
specifier.platforms :
specifier.platform && [specifier.platform];
let specified: boolean;
if (platformNames) {
let platformNameSet = new Set(platformNames);
platforms = platforms.filter(platform => platformNameSet.has(platform.name));
specified = true;
} else if (specifier.multiplatform) {
platforms = platforms.concat();
specified = true;
} else {
platforms = [
{
name: process.platform
}
];
specified = false;
}
return {
platforms,
specified
};
}
}