Skip to content

Commit 978fc8d

Browse files
committed
Cleanup
1 parent f801aa9 commit 978fc8d

File tree

8 files changed

+41
-206
lines changed

8 files changed

+41
-206
lines changed

lib/Specification.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,17 @@
66
* @param {object} parameters.configuration Configuration object to use
77
*/
88
module.exports = {
9-
// async create(specParams) {
10-
// if (!specParams.configuration) {
11-
// throw new Error(`Unable to create Specification: No configuration provided`);
12-
// }
13-
// switch (specParams.configuration.kind) {
14-
// case "project":
15-
// return Project.create(specParams);
16-
// case "extension":
17-
// return Extension.create(specParams);
18-
// default:
19-
// throw new Error(
20-
// `Encountered unexpected specification configuration of kind ${specParams.configuration.kind} ` +
21-
// `Supported kinds are 'project' and 'extension'`);
22-
// }
23-
// }
24-
259
async create(params) {
26-
if (!["project", "extension"].includes(params.configuration.kind)) {
27-
throw new Error(`Unable to create Specification instance: Unknown kind '${params.configuration.kind}'`);
10+
if (!params.configuration) {
11+
throw new Error(
12+
`Unable to create Specification instance: Missing configuration parameter`);
13+
}
14+
const {kind, type} = params.configuration;
15+
if (!["project", "extension"].includes(kind)) {
16+
throw new Error(`Unable to create Specification instance: Unknown kind '${kind}'`);
2817
}
2918

30-
switch (params.configuration.type) {
19+
switch (type) {
3120
case "application": {
3221
return createAndInitializeSpec("Application", params);
3322
}
@@ -51,7 +40,7 @@ module.exports = {
5140
}
5241
default:
5342
throw new Error(
54-
`Unable to create Specification instance: Unknown specification type '${params.configuration.type}'`);
43+
`Unable to create Specification instance: Unknown specification type '${type}'`);
5544
}
5645
}
5746
};

lib/graph/Module.js

Lines changed: 12 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Module {
6161
if (shimCollection) {
6262
// Retrieve and clone shims in constructor
6363
// Shims added to the collection at a later point in time should not be applied in this module
64-
const shims = shimCollection.getConfigurationShims(this.getId());
64+
const shims = shimCollection.getProjectConfigurationShims(this.getId());
6565
if (shims && shims.length) {
66-
this._configShims = clone(shims);
66+
this._projectConfigShims = clone(shims);
6767
}
6868
}
6969
}
@@ -91,8 +91,6 @@ class Module {
9191
async _getSpecifications() {
9292
const configs = await this._getConfigurations();
9393

94-
// let project;
95-
// const extensions = [];
9694
const specs = await Promise.all(configs.map(async (configuration) => {
9795
const spec = await Specification.create({
9896
id: this.getId(),
@@ -103,36 +101,6 @@ class Module {
103101

104102
log.verbose(`Module ${this.getId()} contains ${spec.getKind()} ${spec.getName()}`);
105103
return spec;
106-
107-
// switch (configuration.kind) {
108-
// case "project":
109-
// if (project) {
110-
// throw new Error(
111-
// `Invalid configuration for module ${this.getId()}: Per module there ` +
112-
// `must be no more than one configuration of kind 'project'`);
113-
// }
114-
// log.verbose(`Module ${this.getId()} contains project ${configuration.getName()}`);
115-
// project = await Project.create({
116-
// id: this.getId(),
117-
// version: this.getVersion(),
118-
// modulePath: this.getPath(),
119-
// configuration
120-
// });
121-
// break;
122-
// case "extension":
123-
// log.verbose(`Module ${this.getId()} contains extension ${configuration.getName()}`);
124-
// extensions.push(new Extension({
125-
// id: this.getId(),
126-
// version: this.getVersion(),
127-
// modulePath: this.getPath(),
128-
// configuration
129-
// }));
130-
// break;
131-
// default:
132-
// throw new Error(
133-
// `Encountered unexpected specification configuration of kind ${configuration.kind} ` +
134-
// `Supported kinds are 'project' and 'extension'`);
135-
// }
136104
}));
137105

138106
const projects = specs.filter((spec) => {
@@ -172,29 +140,28 @@ class Module {
172140
return configurations || [];
173141
}
174142

175-
async _createConfigurationObject(config) {
143+
async _normalizeAndApplyShims(config) {
176144
this._normalizeConfig(config);
177-
if (config.kind === "project") {
178-
this._applyShims(config);
145+
146+
if (config.kind !== "project") {
147+
this._applyProjectShims(config);
179148
}
180-
// await this._validateConfig(config);
181149
return config;
182150
}
183151

184152
async _createConfigurationFromShim() {
185-
const config = this._applyShims();
153+
const config = this._applyProjectShims();
186154
if (config) {
187155
this._normalizeConfig(config);
188-
// await this._validateConfig(config);
189156
return config;
190157
}
191158
}
192159

193-
_applyShims(config = {}) {
194-
if (!this._configShims) {
160+
_applyProjectShims(config = {}) {
161+
if (!this._projectConfigShims) {
195162
return;
196163
}
197-
this._configShims.forEach(({name, shim}) => {
164+
this._projectConfigShims.forEach(({name, shim}) => {
198165
log.verbose(`Applying project shim ${name} for module ${this.getId()}...`);
199166
Object.assign(config, shim);
200167
});
@@ -205,7 +172,7 @@ class Module {
205172
if (this._suppliedConfigs.length) {
206173
log.verbose(`Configuration for module ${this.getId()} has been supplied directly`);
207174
return await Promise.all(this._suppliedConfigs.map(async (config) => {
208-
return this._createConfigurationObject(config);
175+
return this._normalizeAndApplyShims(config);
209176
}));
210177
}
211178
}
@@ -228,44 +195,8 @@ class Module {
228195
return [];
229196
}
230197

231-
// for (let i = configs.length - 1; i >= 0; i--) {
232-
// this._normalizeConfig(configs[i]);
233-
// }
234-
235-
// const projectConfigs = configs.filter((config) => {
236-
// return config.kind === "project";
237-
// });
238-
239-
// const extensionConfigs = configs.filter((config) => {
240-
// return config.kind === "extension";
241-
// });
242-
243-
// // While a project can contain multiple configurations,
244-
// // from a dependency tree perspective it is always a single project
245-
// // This means it can represent one "project", plus multiple extensions or
246-
// // one extension, plus multiple extensions
247-
248-
// if (projectConfigs.length > 1) {
249-
// throw new Error(
250-
// `Found ${projectConfigs.length} configurations of kind 'project' for ` +
251-
// `project ${this.getId()}. There is only one project per configuration allowed.`);
252-
// } else if (projectConfigs.length === 0 && extensionConfigs.length === 0) {
253-
// throw new Error(
254-
// `Found ${configs.length} configurations for ` +
255-
// `project ${this.getId()}. However, none of them are of kind 'project' or 'extension'.`);
256-
// }
257-
258-
// const configurations = [];
259-
// if (projectConfigs.length) {
260-
// configurations.push(await this._createConfigurationObject(projectConfigs[0]));
261-
// }
262-
263-
// await Promise.all(extensionConfigs.map(async (config) => {
264-
// configurations.push(await this._createConfigurationObject(config));
265-
// }));
266-
267198
return await Promise.all(configs.map((config) => {
268-
return this._createConfigurationObject(config);
199+
return this._normalizeAndApplyShims(config);
269200
}));
270201
}
271202

@@ -361,34 +292,6 @@ class Module {
361292
return config;
362293
}
363294

364-
// async _validateConfig(config) {
365-
// const moduleId = this.getId();
366-
// if (!moduleId.startsWith("@openui5/") && !moduleId.startsWith("@sapui5/")) {
367-
// if (config.specVersion === "0.1" || config.specVersion === "1.0" ||
368-
// config.specVersion === "1.1") {
369-
// throw new Error(
370-
// `Unsupported specification version ${config.specVersion} defined in module ` +
371-
// `${this.getId()}. The new Module API can only be used with specification versions >= 2.0. ` +
372-
// `For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions`);
373-
// }
374-
// if (config.specVersion !== "2.0" &&
375-
// config.specVersion !== "2.1" && config.specVersion !== "2.2" &&
376-
// config.specVersion !== "2.3") {
377-
// throw new Error(
378-
// `Unsupported specification version ${config.specVersion} defined in module ` +
379-
// `${this.getId()}. Your UI5 CLI installation might be outdated. ` +
380-
// `For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions`);
381-
// }
382-
// }
383-
384-
// await validate({
385-
// config,
386-
// project: {
387-
// id: moduleId
388-
// }
389-
// });
390-
// }
391-
392295
_isConfigValid(project) {
393296
if (!project.type) {
394297
if (project._isRoot) {

lib/graph/ShimCollection.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ function addToMap(name, fromMap, toMap) {
1414

1515
class ShimCollection {
1616
constructor() {
17-
this._configShims = {};
17+
this._projectConfigShims = {};
1818
this._dependencyShims = {};
1919
this._collectionShims = {};
2020
}
2121

22-
addShim(shimExtension) {
22+
addProjectShim(shimExtension) {
2323
const name = shimExtension.getName();
2424
log.verbose(`Adding new shim ${name}...`);
2525
// TODO: Move this into a dedicated ShimConfiguration class?
2626
const config = shimExtension.getConfigurationObject();
2727
const {configurations, dependencies, collections} = config.shims;
2828
if (configurations) {
29-
addToMap(name, configurations, this._configShims);
29+
addToMap(name, configurations, this._projectConfigShims);
3030
}
3131
if (dependencies) {
3232
addToMap(name, dependencies, this._dependencyShims);
@@ -36,8 +36,8 @@ class ShimCollection {
3636
}
3737
}
3838

39-
getConfigurationShims(moduleId) {
40-
return this._configShims[moduleId];
39+
getProjectConfigurationShims(moduleId) {
40+
return this._projectConfigShims[moduleId];
4141
}
4242

4343
getAllDependencyShims() {

lib/graph/projectGraphBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function _handleExtensions(graph, shimCollection, extensions) {
99
const type = extension.getType();
1010
switch (type) {
1111
case "project-shim":
12-
shimCollection.addShim(extension);
12+
shimCollection.addProjectShim(extension);
1313
break;
1414
case "task":
1515
case "server-middleware":

lib/specifications/configurations/AbstractConfiguration.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

lib/specifications/configurations/Application.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/specifications/types/Application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Application extends Project {
4545
getBuildtimeReader() {
4646
return resourceFactory.createReader({
4747
fsBasePath: path.join(this.getPath(), this._webappPath),
48-
virBasePath: "/resources" + this.getNamespace(),
48+
virBasePath: `/resources/${this.getNamespace()}/`,
4949
name: `Source reader for ${this.getType()} ${this.getKind()} ${this.getName()}`
5050
});
5151
}

test/lib/specifications/Project.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
const test = require("ava");
22
const path = require("path");
3-
const Project = require("../../../lib/specifications/Project");
4-
const Configuration = require("../../../lib/specifications/Configuration");
3+
const Specification = require("../../../lib/Specification");
54

65
const applicationAPath = path.join(__dirname, "..", "..", "fixtures", "application.a");
7-
8-
test.beforeEach(async (t) => {
9-
t.context.basicConfiguration = new Configuration({
6+
const basicProjectInput = {
7+
id: "application.a.id",
8+
version: "1.0.0",
9+
modulePath: applicationAPath,
10+
configuration: {
1011
specVersion: "2.3",
1112
kind: "project",
1213
type: "application",
1314
metadata: {name: "application.a"}
14-
});
15-
16-
t.context.basicProjectInput = {
17-
id: "application.a.id",
18-
version: "1.0.0",
19-
modulePath: applicationAPath,
20-
configuration: t.context.basicConfiguration
21-
};
22-
});
15+
}
16+
};
2317

2418
test("Instantiate a basic project", async (t) => {
25-
const project = new Project(t.context.basicProjectInput);
19+
const project = await Specification.create(basicProjectInput);
2620
t.is(project.getName(), "application.a", "Returned correct name");
2721
t.is(project.getVersion(), "1.0.0", "Returned correct version");
2822
t.is(project.getPath(), applicationAPath, "Returned correct project path");
2923
});
3024

31-
test("_getConfiguration", async (t) => {
32-
const project = new Project(t.context.basicProjectInput);
33-
t.is(await project._getConfiguration(), t.context.basicConfiguration, "Returned correct configuration instance");
25+
test("Configurations", async (t) => {
26+
const project = await Specification.create(basicProjectInput);
27+
t.is(project.getKind(), "project", "Returned correct kind configuration");
3428
});
3529

3630
test("Access project root resources via reader", async (t) => {
37-
const project = new Project(t.context.basicProjectInput);
31+
const project = await Specification.create(basicProjectInput);
3832
const rootReader = await project.getRootReader();
3933
const packageJsonResource = await rootReader.byPath("/package.json");
4034
t.is(packageJsonResource.getPath(), "/package.json", "Successfully retrieved root resource");

0 commit comments

Comments
 (0)