task-tree.js 604 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. module.exports = function(tasks) {
  3. var map = {};
  4. var arr = [];
  5. Object.keys(tasks).forEach(function(taskname) {
  6. var task = {
  7. label: taskname,
  8. type: 'task',
  9. nodes: [],
  10. };
  11. map[taskname] = task;
  12. arr.push(task);
  13. });
  14. Object.keys(tasks).forEach(function(taskname) {
  15. var task = map[taskname];
  16. tasks[taskname].dep.forEach(function(childname) {
  17. var child = map[childname] || {
  18. label: childname,
  19. type: 'task',
  20. nodes: [],
  21. };
  22. task.nodes.push(child);
  23. });
  24. });
  25. return { label: 'Tasks', nodes: arr };
  26. };