Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 369x 369x 369x 369x 380x 380x 380x 380x 380x 380x 369x 369x 1x 1x 1x 1x 1x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 393x 2x 2x 393x 1x 1x 1x 1x 1x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 619x 1x 1x 619x 1x 1x 1x 1x 1x 572x 572x 572x 572x 572x 572x 572x 572x 572x 572x 572x 572x 572x 1x 1x 1x 1x 1x 567x 567x 567x 567x 567x 567x 567x 567x 567x 567x 567x 567x 567x 1x 1x 1x 1x 1x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 1x 1x 1x 1x 1x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 1x 1x 1x 1x 1x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 392x 392x 1x 1x 392x 391x 392x 157x 157x 392x 209x 1x 1x 208x 392x 5x 5x 392x 8x 8x 392x 6x 6x 392x 6x 392x 392x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 410x 410x 410x 410x 410x 5x 5x 410x 2x 2x 403x 403x 410x 278x 278x 278x 278x 1x 1x 278x 402x 402x 402x 402x 402x 410x 1x 1x 401x 401x 401x 410x 4x 4x 397x 397x 397x 397x 397x 397x 397x 397x 397x 410x 17x 17x 17x 17x 4x 4x 13x 13x 13x 13x 13x 393x 393x 393x 410x 2x 2x 2x 2x 410x 2x 2x 2x 2x 410x 2x 2x 2x 2x 410x 2x 2x 2x 2x 410x 2x 2x 2x 2x 410x 1x 1x 1x 1x 410x 1x 1x 1x 1x 379x 379x 410x 4x 4x 4x 4x 379x 379x 410x 127x 127x 693x 693x 127x 127x 1x 1x 126x 126x 378x 378x 410x 14x 14x 21x 21x 21x 4x 4x 4x 21x 17x 17x 21x 14x 14x 1x 1x 13x 13x 377x 377x 410x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 1x 1x 1x 2x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x 1x 1x 1x 376x 376x 410x 123x 123x 123x 212x 212x 212x 912x 912x 912x 912x 912x 212x 212x 123x 123x 123x 123x 123x 123x 123x 123x 212x 212x 212x 3x 3x 209x 209x 209x 212x 86x 86x 1x 1x 85x 85x 208x 212x 86x 86x 1x 1x 85x 85x 207x 207x 207x 123x 123x 369x 369x 369x 369x 369x 410x 41x 41x 369x 369x 369x 410x 116x 116x 369x 1x 1x 1x 1x 1x 1x 1x 1x 652x 652x 652x 652x 652x 1x 1x 652x 1x 1x 650x 650x 652x 1x 1x 649x 649x 652x 619x 619x 610x 610x 610x 610x 619x 648x 648x 648x 652x 566x 566x 648x 648x 652x 572x 572x 470x 470x 470x 470x 470x 572x 648x 648x 652x 567x 567x 8x 8x 8x 8x 8x 8x 8x 567x 648x 648x 652x 112x 112x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 112x 648x 648x 652x 102x 102x 102x 102x 102x 102x 185x 185x 185x 185x 69x 69x 185x 109x 109x 185x 108x 108x 185x 65x 65x 185x 65x 65x 185x 185x 185x 185x 185x 789x 3x 3x 789x 185x 102x 102x 102x 102x 652x 4x 4x 648x 648x 648x 652x 1x | const yaml = require('yamljs');
const fm = require('front-matter');
const marked = require('marked');
const utility = require('./utility');
const chrono = require('chrono-node');
const validate = require('jsonschema').validate;
const parseMarkdown = require('./parse-markdown');
/**
* Compile separate headings together into a task description
* @param {object} data
*/
function compileDescription(data) {
const description = [];
if ('raw' in data) {
description.push(data.raw.content.replace(/[\r\n]{3}/g, '\n\n').trim());
}
for (let heading in data) {
if (['raw', 'Metadata', 'Sub-tasks', 'Relations', 'History', 'Comments'].indexOf(heading) !== -1) {
continue;
}
description.push(
/^# (.*)/.test(data[heading].heading) ? '' : data[heading].heading,
data[heading].content
);
}
return description.join('\n\n').trim();
}
/**
* Validate the metadata object converted from Markdown
* @param {object} metadata
*/
function validateMetadataFromMarkdown(metadata) {
const result = validate(metadata, {
type: 'object',
properties: {
'created': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'updated': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'started': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'completed': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'due': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'plannedStart': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'plannedFinish': {
oneOf: [
{ type: 'string' },
{ type: 'date'}
]
},
'progress': {
type: 'number'
},
'tags': {
type: 'array',
items: { type: 'string' }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the metadata object converted from JSON
* @param {object} metadata
*/
function validateMetadataFromJSON(metadata) {
const result = validate(metadata, {
type: 'object',
properties: {
'created': { type: 'date'},
'updated': { type: 'date'},
'started': { type: 'date'},
'completed': { type: 'date'},
'due': { type: 'date'},
'plannedStart': { type: 'date'},
'plannedFinish': { type: 'date'},
'progress': { type: 'number' },
'tags': {
type: 'array',
items: { type: 'string' }
},
'assigned': { type: 'string' }
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the sub-tasks object
* @param {object} subTasks
*/
function validateSubTasks(subTasks) {
const result = validate(subTasks, {
type: 'array',
items: {
type: 'object',
properties: {
'text': { type: 'string' },
'completed': { type: 'boolean' }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the relations object
* @param {object} relations
*/
function validateRelations(relations) {
const result = validate(relations, {
type: 'array',
items: {
type: 'object',
properties: {
'type': { type: 'string' },
'task': { type: 'string' }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the comments object
* @param {object} comments
*/
function validateComments(comments) {
const result = validate(comments, {
type: 'array',
items: {
type: 'object',
properties: {
'author': { type: 'string' },
'date': { type: 'date' },
'text': { type: 'string' }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the history object converted from Markdown
* @param {object[]} history
*/
function validateHistoryFromMarkdown(history) {
const result = validate(history, {
type: 'array',
items: {
type: 'object',
properties: {
'type': { type: 'string' },
'date': {
oneOf: [
{ type: 'string' },
{ type: 'date' }
]
},
'column': { type: 'string' },
'fromColumn': { type: 'string' },
'toColumn': { type: 'string' },
'author': { type: 'string' },
'fromProgress': { oneOf: [{ type: 'number' }, { type: 'string' }] },
'toProgress': { oneOf: [{ type: 'number' }, { type: 'string' }] }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate the history object converted from JSON
* @param {object[]} history
*/
function validateHistoryFromJSON(history) {
const result = validate(history, {
type: 'array',
items: {
type: 'object',
properties: {
'type': { type: 'string' },
'date': { type: 'date' },
'column': { type: 'string' },
'fromColumn': { type: 'string' },
'toColumn': { type: 'string' },
'author': { type: 'string' },
'fromProgress': { type: 'number' },
'toProgress': { type: 'number' }
}
}
});
if (result.errors.length) {
throw new Error(result.errors.map(error => `\n${error.property} ${error.message}`).join(''));
}
}
/**
* Validate required fields in a history event
*
* An event with an unrecognised type is left alone rather than rejected: a task file written by a
* newer version of kanbn may contain event types this version doesn't know about, and refusing to
* parse the whole task would make the file unreadable. Unknown events are preserved on write and
* ignored when history is replayed.
* @param {object} historyEvent
*/
function validateHistoryEvent(historyEvent) {
if (!historyEvent.type) {
throw new Error('history event is missing type');
}
if (!historyEvent.date) {
throw new Error(`history event "${historyEvent.type}" is missing date`);
}
switch (historyEvent.type) {
case 'created':
if (!historyEvent.column) {
throw new Error('created history event is missing column');
}
break;
case 'moved':
if (!historyEvent.fromColumn || !historyEvent.toColumn) {
throw new Error('moved history event is missing fromColumn or toColumn');
}
break;
case 'progress':
if (historyEvent.fromProgress === undefined || historyEvent.toProgress === undefined) {
throw new Error('progress history event is missing fromProgress or toProgress');
}
break;
case 'archived':
if (!historyEvent.fromColumn) {
throw new Error('archived history event is missing fromColumn');
}
break;
case 'restored':
if (!historyEvent.toColumn) {
throw new Error('restored history event is missing toColumn');
}
break;
default:
break;
}
}
/**
* History event keys that this version understands, in the order they should be written
*/
const KNOWN_HISTORY_EVENT_KEYS = [
'type',
'date',
'column',
'fromColumn',
'toColumn',
'fromProgress',
'toProgress',
'author'
];
module.exports = {
/**
* Convert markdown into a task object
* @param {string} data
* @return {object}
*/
md2json(data) {
let id = '', name = '', description = '', metadata = {}, subTasks = [], relations = [], history = [], comments = [];
try {
// Check data type
if (!data) {
throw new Error('data is null or empty');
}
if (typeof data !== 'string') {
throw new Error('data is not a string');
}
// Get YAML front matter if any exists
if (fm.test(data)) {
({ attributes: metadata, body: data } = fm(data));
// Make sure the front matter contains an object
if (typeof metadata !== 'object') {
throw new Error('invalid front matter content');
}
}
// Parse markdown to an object
let task = null;
try {
task = parseMarkdown(data);
} catch (error) {
throw new Error(`invalid markdown (${error.message})`);
}
// Check resulting object
const taskHeadings = Object.keys(task);
if (taskHeadings.length === 0 || taskHeadings[0] === 'raw') {
throw new Error('data is missing a name heading');
}
// Get name
name = taskHeadings[0];
// Get id from name
id = utility.getTaskId(name);
// Parse metadata
// Metadata will be serialized back to front-matter, this check remains here for backwards compatibility
if ('Metadata' in task) {
// Get embedded metadata and make sure it's an object
const embeddedMetadata = yaml.parse(task['Metadata'].content.trim().replace(/```(yaml|yml)?/g, ''));
if (typeof embeddedMetadata !== 'object') {
throw new Error('invalid metadata content');
}
// Merge with front matter metadata
metadata = Object.assign(metadata, embeddedMetadata);
delete task['Metadata'];
}
validateMetadataFromMarkdown(metadata);
// Check created/updated/completed/due dates
if ('created' in metadata && !(metadata.created instanceof Date)) {
const dateValue = chrono.parseDate(metadata.created);
if (dateValue === null) {
throw new Error('unable to parse created date');
}
metadata.created = dateValue;
}
if ('updated' in metadata && !(metadata.updated instanceof Date)) {
const dateValue = chrono.parseDate(metadata.updated);
if (dateValue === null) {
throw new Error('unable to parse updated date');
}
metadata.updated = dateValue;
}
if ('started' in metadata && !(metadata.started instanceof Date)) {
const dateValue = chrono.parseDate(metadata.started);
if (dateValue === null) {
throw new Error('unable to parse started date');
}
metadata.started = dateValue;
}
if ('completed' in metadata && !(metadata.completed instanceof Date)) {
const dateValue = chrono.parseDate(metadata.completed);
if (dateValue === null) {
throw new Error('unable to parse completed date');
}
metadata.completed = dateValue;
}
if ('due' in metadata && !(metadata.due instanceof Date)) {
const dateValue = chrono.parseDate(metadata.due);
if (dateValue === null) {
throw new Error('unable to parse due date');
}
metadata.due = dateValue;
}
if ('plannedStart' in metadata && !(metadata.plannedStart instanceof Date)) {
const dateValue = chrono.parseDate(metadata.plannedStart);
if (dateValue === null) {
throw new Error('unable to parse plannedStart date');
}
metadata.plannedStart = dateValue;
}
if ('plannedFinish' in metadata && !(metadata.plannedFinish instanceof Date)) {
const dateValue = chrono.parseDate(metadata.plannedFinish);
if (dateValue === null) {
throw new Error('unable to parse plannedFinish date');
}
metadata.plannedFinish = dateValue;
}
// Check progress value
if ('progress' in metadata) {
const numberValue = parseFloat(metadata.progress);
if (isNaN(numberValue)) {
throw new Error('progress value is not numeric');
}
metadata.progress = numberValue;
}
// Parse sub-tasks
if ('Sub-tasks' in task) {
try {
subTasks = marked.lexer(task['Sub-tasks'].content)[0].items.map(item => ({
text: item.text.trim(),
completed: item.checked || false
}));
} catch (error) {
throw new Error('sub-tasks must contain a list');
}
delete task['Sub-tasks'];
}
// Parse relations
if ('Relations' in task) {
try {
relations = marked.lexer(task['Relations'].content)[0].items.map(item => {
const parts = item.tokens[0].tokens[0].text.split(' ');
return parts.length === 1
? {
task: parts[0].trim(),
type: ''
}
: {
task: parts.pop().trim(),
type: parts.join(' ').trim()
};
});
} catch (error) {
throw new Error('relations must contain a list');
}
delete task['Relations'];
}
// Parse comments
if ('Comments' in task) {
try {
// const commentsHeading = '## Comments';
// const start = data.indexOf(commentsHeading) + commentsHeading.length;
// let end = data.substring(start).search(/\n#/);
// if (end >= 0) {
// end += start;
// } else {
// end = data.length;
// }
// const parsedComments = marked.lexer(data.slice(start, end).trim())[0].items;
const parsedComments = marked.lexer(task['Comments'].content)[0].items;
for (let parsedComment of parsedComments) {
const comment = { text: [] };
const parts = parsedComment.text.split('\n');
for (let part of parts) {
if (part.startsWith('date: ')) {
const dateValue = chrono.parseDate(part.substring('date: '.length));
if (dateValue === null) {
throw new Error('unable to parse comment date');
}
comment.date = dateValue;
} else if (part.startsWith('author: ')) {
comment.author = part.substring('author: '.length);
} else {
comment.text.push(part);
}
}
comment.text = comment.text.join('\n').trim();
comments.push(comment);
}
} catch (error) {
throw new Error('comments must contain a list');
}
delete task['Comments'];
}
// Parse history
if ('History' in task) {
try {
const parsedHistory = marked.lexer(task['History'].content)[0].items;
for (let parsedHistoryEvent of parsedHistory) {
const historyEvent = {};
const parts = parsedHistoryEvent.text.split('\n');
for (let part of parts) {
const parsedPart = part.match(/^([A-Za-z][A-Za-z0-9]*):\s*(.*)$/);
if (!parsedPart) {
continue;
}
const key = parsedPart[1];
historyEvent[key] = parsedPart[2].trim();
}
history.push(historyEvent);
}
} catch (error) {
throw new Error('history must contain a list');
}
delete task['History'];
// Validate basic history structure before value coercion
validateHistoryFromMarkdown(history);
// Parse and validate event dates and numeric fields
history = history.map((historyEvent) => {
if (!(historyEvent.date instanceof Date)) {
const dateValue = chrono.parseDate(historyEvent.date);
if (dateValue === null) {
throw new Error(`unable to parse history event date for "${historyEvent.type || 'unknown'}"`);
}
historyEvent.date = dateValue;
}
if ('fromProgress' in historyEvent) {
const fromProgressValue = parseFloat(historyEvent.fromProgress);
if (isNaN(fromProgressValue)) {
throw new Error('history event fromProgress value is not numeric');
}
historyEvent.fromProgress = fromProgressValue;
}
if ('toProgress' in historyEvent) {
const toProgressValue = parseFloat(historyEvent.toProgress);
if (isNaN(toProgressValue)) {
throw new Error('history event toProgress value is not numeric');
}
historyEvent.toProgress = toProgressValue;
}
validateHistoryEvent(historyEvent);
return historyEvent;
});
}
// Assemble description
// const descriptionParts = [];
description = compileDescription(task);
// description = descriptionParts.join('\n\n');
} catch (error) {
throw new Error(`Unable to parse task: ${error.message}`);
}
// Assemble task object
const result = { id, name, description, metadata, subTasks, relations, comments };
if (history.length > 0) {
result.history = history;
}
return result;
},
/**
* Convert a task object into markdown
* @param {object} data
* @return {string}
*/
json2md(data) {
const result = [];
try {
// Check data type
if (!data) {
throw new Error('data is null or empty');
}
if (typeof data !== 'object') {
throw new Error('data is not an object');
}
// Check required fields
if (!('name' in data)) {
throw new Error('data object is missing name');
}
// Add metadata as front-matter content if present
if ('metadata' in data && data.metadata !== null) {
validateMetadataFromJSON(data.metadata);
if (Object.keys(data.metadata).length > 0) {
result.push(
`---\n${yaml.stringify(data.metadata, 4, 2).trim()}\n---`
);
}
}
// Add name and description
result.push(`# ${data.name}`);
if ('description' in data) {
result.push(data.description);
}
// Add sub-tasks if present
if ('subTasks' in data && data.subTasks !== null) {
validateSubTasks(data.subTasks);
if (data.subTasks.length > 0) {
result.push(
'## Sub-tasks',
data.subTasks.map(subTask => `- [${subTask.completed ? 'x' : ' '}] ${subTask.text}`).join('\n')
);
}
}
// Add relations if present
if ('relations' in data && data.relations !== null) {
validateRelations(data.relations);
if (data.relations.length > 0) {
result.push(
'## Relations',
data.relations.map(
relation => `- [${relation.type ? `${relation.type} ` : ''}${relation.task}](${relation.task}.md)`
).join('\n')
);
}
}
// Add comments if present
if ('comments' in data && data.comments !== null) {
validateComments(data.comments);
if (data.comments.length > 0) {
result.push(
'## Comments',
data.comments.map(comment => {
const commentOutput = [];
if ('author' in comment && comment.author) {
commentOutput.push(`author: ${comment.author}`);
}
if ('date' in comment && comment.date) {
commentOutput.push(`date: ${comment.date.toISOString()}`);
}
commentOutput.push(...comment.text.split('\n'));
return `- ${commentOutput.map((v, i) => i > 0 ? ` ${v}` : v).join('\n')}`;
}).join('\n')
);
}
}
// Add history if present
if ('history' in data && data.history !== null) {
validateHistoryFromJSON(data.history);
data.history.forEach(validateHistoryEvent);
if (data.history.length > 0) {
result.push(
'## History',
data.history.map((historyEvent) => {
const historyEventOutput = [];
historyEventOutput.push(`type: ${historyEvent.type}`);
historyEventOutput.push(`date: ${historyEvent.date.toISOString()}`);
if ('column' in historyEvent) {
historyEventOutput.push(`column: ${historyEvent.column}`);
}
if ('fromColumn' in historyEvent) {
historyEventOutput.push(`fromColumn: ${historyEvent.fromColumn}`);
}
if ('toColumn' in historyEvent) {
historyEventOutput.push(`toColumn: ${historyEvent.toColumn}`);
}
if ('fromProgress' in historyEvent) {
historyEventOutput.push(`fromProgress: ${historyEvent.fromProgress}`);
}
if ('toProgress' in historyEvent) {
historyEventOutput.push(`toProgress: ${historyEvent.toProgress}`);
}
if ('author' in historyEvent && historyEvent.author) {
historyEventOutput.push(`author: ${historyEvent.author}`);
}
// Write back any keys this version doesn't recognise, so that a file written by a
// newer version of kanbn survives a read/write cycle here without losing data
for (const key of Object.keys(historyEvent)) {
if (KNOWN_HISTORY_EVENT_KEYS.indexOf(key) === -1 && historyEvent[key] !== undefined) {
historyEventOutput.push(`${key}: ${historyEvent[key]}`);
}
}
return `- ${historyEventOutput.map((v, i) => i > 0 ? ` ${v}` : v).join('\n')}`;
}).join('\n')
);
}
}
} catch (error) {
throw new Error(`Unable to build task: ${error.message}`);
}
// Filter empty lines and join into a string
return `${result.filter(l => !!l).join('\n\n')}\n`;
}
};
|