Skip to content

Commit 3f56e6f

Browse files
committed
[FEATURE] projectPreprocessor: Add handling for task extensions
As per RFC0004: SAP/ui5-tooling#54
1 parent 45a25c2 commit 3f56e6f

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-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/fixtures/application.a/task.a.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = function () {};

test/lib/extensions.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,37 @@ 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+
task: {
526+
path: "/task.a.js"
527+
}
528+
}],
529+
version: "1.0.0",
530+
specVersion: "0.1",
531+
type: "application",
532+
metadata: {
533+
name: "xy"
534+
}
535+
};
536+
return projectPreprocessor.processTree(tree).then((parsedTree) => {
537+
t.deepEqual(parsedTree.dependencies.length, 0, "Application project has no dependencies");
538+
const taskRepository = require("@ui5/builder").tasks.taskRepository;
539+
t.truthy(taskRepository.getTask("task.a"), "task.a has been added to the task repository");
540+
});
541+
});

0 commit comments

Comments
 (0)