Skip to content

Commit 8faef7c

Browse files
committed
[FEATURE] Task Extensibility: Add handling for task extensions
As per RFC0004: SAP/ui5-tooling#54
1 parent 45a25c2 commit 8faef7c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

lib/projectPreprocessor.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ class ProjectPreprocessor {
336336
case "project-shim":
337337
this.handleShim(extension);
338338
break;
339+
case "task":
340+
this.handleTask(extension);
341+
break;
339342
default:
340343
throw new Error(`Unknown extension type '${extension.type}' for ${extension.id}`);
341344
}
@@ -349,6 +352,9 @@ class ProjectPreprocessor {
349352
}
350353

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

354360
if (configurations) {
@@ -465,6 +471,21 @@ class ProjectPreprocessor {
465471
}
466472
}
467473
}
474+
475+
handleTask(extension) {
476+
if (!extension.metadata && !extension.metadata.name) {
477+
throw new Error(`Task extension ${extension.id} is missing 'metadata.name' configuration`);
478+
}
479+
if (!extension.task) {
480+
throw new Error(`Task extension ${extension.id} is missing 'task' configuration`);
481+
}
482+
const taskRepository = require("@ui5/builder").tasks.taskRepository;
483+
484+
const taskPath = path.join(extension.path, extension.task.path);
485+
const task = require(taskPath); // throws if not found
486+
487+
taskRepository.addTask(extension.metadata.name, task);
488+
}
468489
}
469490

470491
/**

test/lib/extensions.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,54 @@ test("Project with unknown extension dependency inline configuration", (t) => {
505505
return t.throws(projectPreprocessor.processTree(tree),
506506
"Unknown extension type 'phony-pony' for extension.a", "Rejected with error");
507507
});
508+
509+
test("Project with task extension dependency", (t) => {
510+
// "project-type" extension handling not yet implemented => test currently checks for error
511+
const tree = {
512+
id: "application.a",
513+
path: applicationAPath,
514+
dependencies: [{
515+
id: "ext.task.a",
516+
path: applicationAPath,
517+
dependencies: [],
518+
version: "1.0.0",
519+
specVersion: "0.1",
520+
kind: "extension",
521+
type: "task",
522+
metadata: {
523+
name: "task.a"
524+
}
525+
}],
526+
version: "1.0.0",
527+
specVersion: "0.1",
528+
type: "z",
529+
metadata: {
530+
name: "xy"
531+
}
532+
};
533+
return t.throws(projectPreprocessor.processTree(tree).then((parsedTree) => {
534+
t.deepEqual(parsedTree, {
535+
_level: 0,
536+
type: "z",
537+
metadata: {
538+
name: "xy",
539+
},
540+
resources: {
541+
configuration: {
542+
paths: {
543+
root: ""
544+
}
545+
},
546+
pathMappings: {
547+
"/": "",
548+
}
549+
},
550+
dependencies: [],
551+
id: "application.a",
552+
kind: "project",
553+
version: "1.0.0",
554+
specVersion: "0.1",
555+
path: applicationAPath
556+
}, "Parsed correctly");
557+
}), "Unknown extension type 'project-type' for extension.a", "Rejected with error");
558+
});

0 commit comments

Comments
 (0)