Skip to content

Commit

Permalink
[FEATURE] Task Extensibility: Add handling for task extensions
Browse files Browse the repository at this point in the history
As per RFC0004: SAP/ui5-tooling#54
  • Loading branch information
RandomByte committed Nov 16, 2018
1 parent 45a25c2 commit 8faef7c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ class ProjectPreprocessor {
case "project-shim":
this.handleShim(extension);
break;
case "task":
this.handleTask(extension);
break;
default:
throw new Error(`Unknown extension type '${extension.type}' for ${extension.id}`);
}
Expand All @@ -349,6 +352,9 @@ class ProjectPreprocessor {
}

handleShim(extension) {
if (!extension.shims) {
throw new Error(`Project shim extension ${extension.id} is missing 'shim' configuration`);
}
const {configurations, dependencies, collections} = extension.shims;

if (configurations) {
Expand Down Expand Up @@ -465,6 +471,21 @@ class ProjectPreprocessor {
}
}
}

handleTask(extension) {
if (!extension.metadata && !extension.metadata.name) {
throw new Error(`Task extension ${extension.id} is missing 'metadata.name' configuration`);
}
if (!extension.task) {
throw new Error(`Task extension ${extension.id} is missing 'task' configuration`);
}
const taskRepository = require("@ui5/builder").tasks.taskRepository;

const taskPath = path.join(extension.path, extension.task.path);
const task = require(taskPath); // throws if not found

taskRepository.addTask(extension.metadata.name, task);
}
}

/**
Expand Down
51 changes: 51 additions & 0 deletions test/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,54 @@ test("Project with unknown extension dependency inline configuration", (t) => {
return t.throws(projectPreprocessor.processTree(tree),
"Unknown extension type 'phony-pony' for extension.a", "Rejected with error");
});

test("Project with task extension dependency", (t) => {
// "project-type" extension handling not yet implemented => test currently checks for error
const tree = {
id: "application.a",
path: applicationAPath,
dependencies: [{
id: "ext.task.a",
path: applicationAPath,
dependencies: [],
version: "1.0.0",
specVersion: "0.1",
kind: "extension",
type: "task",
metadata: {
name: "task.a"
}
}],
version: "1.0.0",
specVersion: "0.1",
type: "z",
metadata: {
name: "xy"
}
};
return t.throws(projectPreprocessor.processTree(tree).then((parsedTree) => {
t.deepEqual(parsedTree, {
_level: 0,
type: "z",
metadata: {
name: "xy",
},
resources: {
configuration: {
paths: {
root: ""
}
},
pathMappings: {
"/": "",
}
},
dependencies: [],
id: "application.a",
kind: "project",
version: "1.0.0",
specVersion: "0.1",
path: applicationAPath
}, "Parsed correctly");
}), "Unknown extension type 'project-type' for extension.a", "Rejected with error");
});

0 comments on commit 8faef7c

Please sign in to comment.