-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathProject.js
More file actions
292 lines (262 loc) · 8.44 KB
/
Project.js
File metadata and controls
292 lines (262 loc) · 8.44 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import Specification from "./Specification.js";
import ResourceTagCollection from "@ui5/fs/internal/ResourceTagCollection";
/**
* Project
*
* @public
* @abstract
* @class
* @alias @ui5/project/specifications/Project
* @extends @ui5/project/specifications/Specification
* @hideconstructor
*/
class Project extends Specification {
constructor(parameters) {
super(parameters);
if (new.target === Project) {
throw new TypeError("Class 'Project' is abstract. Please use one of the 'types' subclasses");
}
this._resourceTagCollection = null;
}
/**
* @param {object} parameters Specification parameters
* @param {string} parameters.id Unique ID
* @param {string} parameters.version Version
* @param {string} parameters.modulePath File System path to access resources
* @param {object} parameters.configuration Configuration object
* @param {object} [parameters.buildManifest] Build metadata object
*/
async init(parameters) {
await super.init(parameters);
this._buildManifest = parameters.buildManifest;
await this._configureAndValidatePaths(this._config);
await this._parseConfiguration(this._config, this._buildManifest);
return this;
}
/* === Attributes === */
/**
* Get the project namespace. Returns `null` for projects that have none or multiple namespaces,
* for example Modules or Theme Libraries.
*
* @public
* @returns {string|null} Project namespace in slash notation (e.g. <code>my/project/name</code>) or null
*/
getNamespace() {
// Default namespace for general Projects:
// Their resources should be structured with globally unique paths, hence their namespace is undefined
return null;
}
/**
* Check whether the project is a UI5-Framework project
*
* @public
* @returns {boolean} True if the project is a framework project
*/
isFrameworkProject() {
const id = this.getId();
return id.startsWith("@openui5/") || id.startsWith("@sapui5/");
}
/**
* Get the project's customConfiguration
*
* @public
* @returns {object} Custom Configuration
*/
getCustomConfiguration() {
return this._config.customConfiguration;
}
/**
* Get the path of the project's source directory. This might not be POSIX-style on some platforms.
* Projects with multiple source paths will throw an error. For example Modules.
*
* @public
* @returns {string} Absolute path to the source directory of the project
* @throws {Error} In case a project has multiple source directories
*/
getSourcePath() {
throw new Error(`getSourcePath must be implemented by subclass ${this.constructor.name}`);
}
/**
* Get the project's framework name configuration
*
* @public
* @returns {string} Framework name configuration, either <code>OpenUI5</code> or <code>SAPUI5</code>
*/
getFrameworkName() {
return this._config.framework?.name;
}
/**
* Get the project's framework version configuration
*
* @public
* @returns {string} Framework version configuration, e.g <code>1.110.0</code>
*/
getFrameworkVersion() {
return this._config.framework?.version;
}
/**
* Framework dependency entry of the project configuration.
* Also see [Framework Configuration: Dependencies]{@link https://ui5.github.io/cli/stable/pages/Configuration/#dependencies}
*
* @public
* @typedef {object} @ui5/project/specifications/Project~FrameworkDependency
* @property {string} name Name of the framework library. For example <code>sap.ui.core</code>
* @property {boolean} development Whether the dependency is meant for development purposes only
* @property {boolean} optional Whether the dependency should be treated as optional
*/
/**
* Get the project's framework dependencies configuration
*
* @public
* @returns {@ui5/project/specifications/Project~FrameworkDependency[]} Framework dependencies configuration
*/
getFrameworkDependencies() {
return this._config.framework?.libraries || [];
}
/**
* Get the project's deprecated configuration
*
* @private
* @returns {boolean} True if the project is flagged as deprecated
*/
isDeprecated() {
return !!this._config.metadata.deprecated;
}
/**
* Get the project's sapInternal configuration
*
* @private
* @returns {boolean} True if the project is flagged as SAP-internal
*/
isSapInternal() {
return !!this._config.metadata.sapInternal;
}
/**
* Get the project's allowSapInternal configuration
*
* @private
* @returns {boolean} True if the project allows for using SAP-internal projects
*/
getAllowSapInternal() {
return !!this._config.metadata.allowSapInternal;
}
/**
* Get the project's builderResourcesExcludes configuration
*
* @private
* @returns {string[]} BuilderResourcesExcludes configuration
*/
getBuilderResourcesExcludes() {
return this._config.builder?.resources?.excludes || [];
}
/**
* Get the project's customTasks configuration
*
* @private
* @returns {object[]} CustomTasks configuration
*/
getCustomTasks() {
return this._config.builder?.customTasks || [];
}
/**
* Get the project's customMiddleware configuration
*
* @private
* @returns {object[]} CustomMiddleware configuration
*/
getCustomMiddleware() {
return this._config.server?.customMiddleware || [];
}
/**
* Get the project's serverSettings configuration
*
* @private
* @returns {object} ServerSettings configuration
*/
getServerSettings() {
return this._config.server?.settings;
}
/**
* Get the project's builderSettings configuration
*
* @private
* @returns {object} BuilderSettings configuration
*/
getBuilderSettings() {
return this._config.builder?.settings;
}
/**
* Get the project's buildManifest configuration
*
* @private
* @returns {object|null} BuildManifest configuration or null if none is available
*/
getBuildManifest() {
return this._buildManifest || null;
}
/* === Resource Access === */
/**
* Get a [ReaderCollection]{@link @ui5/fs/ReaderCollection} for accessing all resources of the
* project in the specified "style":
*
* <ul>
* <li><b>buildtime:</b> Resource paths are always prefixed with <code>/resources/</code>
* or <code>/test-resources/</code> followed by the project's namespace.
* Any configured build-excludes are applied</li>
* <li><b>dist:</b> Resource paths always match with what the UI5 runtime expects.
* This means that paths generally depend on the project type. Applications for example use a "flat"-like
* structure, while libraries use a "buildtime"-like structure.
* Any configured build-excludes are applied</li>
* <li><b>runtime:</b> Resource paths always match with what the UI5 runtime expects.
* This means that paths generally depend on the project type. Applications for example use a "flat"-like
* structure, while libraries use a "buildtime"-like structure.
* This style is typically used for serving resources directly. Therefore, build-excludes are not applied</li>
* <li><b>flat:</b> Resource paths are never prefixed and namespaces are omitted if possible. Note that
* project types like "theme-library", which can have multiple namespaces, can't omit them.
* Any configured build-excludes are applied</li>
* </ul>
*
* Resource readers always use POSIX-style paths.
*
* @public
* @param {object} [options]
* @param {string} [options.style=buildtime] Path style to access resources.
* Can be "buildtime", "dist", "runtime" or "flat"
* @returns {@ui5/fs/ReaderCollection} Reader collection allowing access to all resources of the project
*/
getReader(options) {
throw new Error(`getReader must be implemented by subclass ${this.constructor.name}`);
}
getResourceTagCollection() {
if (!this._resourceTagCollection) {
this._resourceTagCollection = new ResourceTagCollection({
allowedTags: ["ui5:IsDebugVariant", "ui5:HasDebugVariant"],
allowedNamespaces: ["project"],
tags: this.getBuildManifest()?.tags
});
}
return this._resourceTagCollection;
}
/**
* Get a [DuplexCollection]{@link @ui5/fs/DuplexCollection} for accessing and modifying a
* project's resources. This is always of style <code>buildtime</code>.
*
* @public
* @returns {@ui5/fs/DuplexCollection} DuplexCollection
*/
getWorkspace() {
throw new Error(`getWorkspace must be implemented by subclass ${this.constructor.name}`);
}
/* === Internals === */
/**
* @private
* @param {object} config Configuration object
*/
async _configureAndValidatePaths(config) {}
/**
* @private
* @param {object} config Configuration object
*/
async _parseConfiguration(config) {}
}
export default Project;