Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Move task list helper functions into the logTasks closure #256

Merged
merged 1 commit into from Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
160 changes: 80 additions & 80 deletions lib/shared/log/tasks.js
Expand Up @@ -25,105 +25,105 @@ function logTasks(tree, opts, getTask) {
};

printTaskTree(tree, treeOpts);
}

function printTaskTree(tree, opts) {
var lines = [];
lines.push({ label: tree.label });
var maxLabelWidth = 0;

tree.nodes.forEach(function(node, idx, arr) {
var isLast = idx === arr.length - 1;
var w = createTreeLines(node, lines, opts, 1, '', isLast);
maxLabelWidth = Math.max(maxLabelWidth, w || 0);
});

lines.forEach(function(line) {
var s = line.label;
if (line.desc) {
var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' ';
s += spaces + line.desc;
}
log.info(s);
});
}

function createTreeLines(node, lines, opts, depth, bars, isLast) {
var task = { label: node.label, bars: bars, depth: depth };
if (depth === 1) {
var t = opts.getTask(node.label);
task.desc = t.description;
task.flags = t.flags;
}

var isLeaf = isLeafNode(node, depth, opts);

var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf);
function printTaskTree(tree, opts) {
var lines = [];
lines.push({ label: tree.label });
var maxLabelWidth = 0;

if (!isLeaf) {
bars += (isLast ? ' ' : '│ ');
node.nodes.forEach(function(node, idx, arr) {
tree.nodes.forEach(function(node, idx, arr) {
var isLast = idx === arr.length - 1;
createTreeLines(node, lines, opts, depth + 1, bars, isLast);
var w = createTreeLines(node, lines, opts, 1, '', isLast);
maxLabelWidth = Math.max(maxLabelWidth, w || 0);
});
}

return maxLabelWidth;
}

function addTaskToLines(task, lines, isLast, isLeaf) {
var taskBars = task.bars + (isLast ? '└' : '├') + '─';
if (isLeaf) {
taskBars += '─ ';
} else {
taskBars += '┬ ';
lines.forEach(function(line) {
var s = line.label;
if (line.desc) {
var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' ';
s += spaces + line.desc;
}
log.info(s);
});
}

var line = {};
if (task.depth === 1) {
line.label = chalk.white(taskBars) + chalk.white(task.label);
} else {
line.label = chalk.white(taskBars) + chalk.cyan(task.label);
}
if (typeof task.desc === 'string' && task.desc) {
line.desc = chalk.white(task.desc);
}
lines.push(line);
function createTreeLines(node, lines, opts, depth, bars, isLast) {
var task = { label: node.label, bars: bars, depth: depth };
if (depth === 1) {
var t = opts.getTask(node.label);
task.desc = t.description;
task.flags = t.flags;
}

var maxLabelWidth = line.label.length
var isLeaf = isLeafNode(node, depth, opts);

if (!isObject(task.flags)) {
return maxLabelWidth;
}
var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf);

var flagBars = task.bars;
if (isLast) {
flagBars += ' ';
} else {
flagBars += '│ ';
}
if (!isLeaf) {
bars += (isLast ? ' ' : '│ ');
node.nodes.forEach(function(node, idx, arr) {
var isLast = idx === arr.length - 1;
createTreeLines(node, lines, opts, depth + 1, bars, isLast);
});
}

if (isLeaf) {
flagBars += ' ';
} else {
flagBars += '│ ';
return maxLabelWidth;
}

Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines);
function addTaskToLines(task, lines, isLast, isLeaf) {
var taskBars = task.bars + (isLast ? '└' : '├') + '─';
if (isLeaf) {
taskBars += '─ ';
} else {
taskBars += '┬ ';
}

function addFlagsToLines(ent) {
if (typeof ent[0] !== 'string' || !ent[0]) return;
var line = {};
if (task.depth === 1) {
line.label = chalk.white(taskBars) + chalk.white(task.label);
} else {
line.label = chalk.white(taskBars) + chalk.cyan(task.label);
}
if (typeof task.desc === 'string' && task.desc) {
line.desc = chalk.white(task.desc);
}
lines.push(line);
line.label = chalk.white(flagBars) + chalk.magenta(ent[0]);

maxLabelWidth = Math.max(maxLabelWidth, line.label.length);
var maxLabelWidth = line.label.length

if (typeof ent[1] !== 'string' || !ent[1]) return;
line.desc = chalk.white('…' + ent[1]);
}
if (!isObject(task.flags)) {
return maxLabelWidth;
}

var flagBars = task.bars;
if (isLast) {
flagBars += ' ';
} else {
flagBars += '│ ';
}

return maxLabelWidth;
if (isLeaf) {
flagBars += ' ';
} else {
flagBars += '│ ';
}

Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines);

function addFlagsToLines(ent) {
if (typeof ent[0] !== 'string' || !ent[0]) return;
var line = {};
lines.push(line);
line.label = chalk.white(flagBars) + chalk.magenta(ent[0]);

maxLabelWidth = Math.max(maxLabelWidth, line.label.length);

if (typeof ent[1] !== 'string' || !ent[1]) return;
line.desc = chalk.white('…' + ent[1]);
}

return maxLabelWidth;
}
}

function isLeafNode(node, depth, opts) {
Expand Down