Skip to content

Commit

Permalink
Be sure to add and delete task terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
piascikj committed Apr 26, 2024
1 parent 1cb9df2 commit 3ab99f0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
## #DONE Fix command line prompts
<card>

Also changed defaultProject path to a function so it works in imdone ui

Expand All @@ -10,5 +9,6 @@ Also changed defaultProject path to a function so it works in imdone ui
story-id:Add-a-command-to-show-defaults
task-id:lGkFg
order:0 completed:2023-10-01T17:34:03.848Z -->
</card>


-->
3 changes: 1 addition & 2 deletions backlog/stories/Complete-a-task/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## #DONE Complete a task by calling `imdone done`
<card>

```bash
npx imdone done
```
<!-- #story -->
<!-- created:2023-09-15T03:31:59.946Z task-id:6dKCq order:-5 story-id:Complete-a-task completed:2023-10-01T17:34:04.236Z -->
</card>

4 changes: 2 additions & 2 deletions backlog/stories/Plan-a-story/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# #DONE Plan a story
<card>

As a developer I would like to plan a story and make it visible by adding tasks to a story markdown in my repo

Expand Down Expand Up @@ -39,7 +38,8 @@ task-id:BSgB3
story-id:Plan-a-story order:-270
completed:2023-12-21T20:14:03.324Z
-->
</card>



## Plan a story
```mermaid
Expand Down
3 changes: 1 addition & 2 deletions backlog/stories/Test-all-cli-commands/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
## #TODO Test all cli commands
<card>

<!--
#story
Expand All @@ -8,4 +7,4 @@ task-id:WmdbU
story-id:Test-all-cli-commands
order:0
-->
</card>

16 changes: 11 additions & 5 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ var _clone = require('lodash.clone'),
{
FILE_TYPES,
getTaskContentNew,
START_TAG,
END_TAG,
LIST_NAME_PATTERN,
HASH_STYLE_REGEX,
HASH_STYLE_META_ORDER_REGEX,
Expand Down Expand Up @@ -78,8 +76,6 @@ function File(opts) {
}
}
util.inherits(File, events.EventEmitter)
File.START_TAG = START_TAG
File.END_TAG = END_TAG
const CODE_BLOCK_REGEX = (File.CODE_BLOCK_REGEX = /`{3}[\s\S]*?`{3}/gm)
const INLINE_CODE_REGEX = (File.INLINE_CODE_REGEX = /`[\s\S]*?`/g)
const CODE_STYLE_END = '((:)(-?[\\d.]+(?:e-?\\d+)?)?)?[ \\t]+(.+)$'
Expand Down Expand Up @@ -787,10 +783,19 @@ File.prototype.modifyTaskFromHtml = function (task, html) {
}

File.prototype.modifyTaskFromContent = function (task, content, config) {
content = trimBlankLines(content, this.isCodeFile())
task.updateFromContent(content)
this.modifyTask(task, config)
}

const trimBlankLines = File.trimBlankLines = function (content, isCodeFile) {
if (isCodeFile) {
// replace all occurrences of two empty lines in a row with a single empty line
return content.replace(/\n\s*\n/g, '\n')
}
return content.replace(/\n\s*\n\s*\n/g, '\n\n')
}

File.prototype.modifyDescription = function (task, config) {
// DOING This should be split out by type (code, markdown, etc)
// #urgent
Expand Down Expand Up @@ -840,7 +845,8 @@ File.prototype.modifyDescription = function (task, config) {
description.length > 0 &&
(tools.hasBlankLines(description) || isWrappedWithCardTag || trailingBlankLines)
) {
task.isWrappedWithCardTag = isWrappedWithCardTag // DOING: Find out where this is used and stop using it
task.isWrappedWithCardTag = isWrappedWithCardTag // DOING Find out where this is used and stop using it
// <!-- order:-30 -->
const blankLinesToAdd = isWrappedWithCardTag ? 2 : trailingBlankLines
description = `${description}${lineEnd.repeat(blankLinesToAdd)}`
}
Expand Down
7 changes: 2 additions & 5 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,6 @@ Repository.prototype.appendTask = function({file, content, list}, cb) {
}).trimEnd()
const lines = eol.split(content)
const text = lines[0]
if (tools.hasBlankLines(lines.join(eol.auto))) {
lines.splice(1, 0, File.START_TAG)
lines.push(File.END_TAG)
}
const taskSyntax = config.getNewCardSyntax()
const taskPrefix = interpretedTaskPrefix ? `${interpretedTaskPrefix} ` : ''
let fileContent = file.getContent()
Expand Down Expand Up @@ -1092,7 +1088,8 @@ Repository.prototype.appendTask = function({file, content, list}, cb) {
const inLineOrder = config.orderMeta ? '' : `:${orderString}`
appendContent = `${taskPrefix}#${list}${inLineOrder} ${text}${eol.lf}${taskContent}`
}
file.setContent(`${fileContent}${sep}${appendContent}`)
appendContent = File.trimBlankLines(appendContent)
file.setContent(`${fileContent}${sep}${appendContent}${"\n".repeat(2)}`)
this.writeAndExtract(file, true, cb)
}

Expand Down
5 changes: 3 additions & 2 deletions lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class Task {
}

getLastLine() {
let lastLine = this.line + this.description.length
if (this.isWrappedWithCardTag) lastLine += 2
let lastLine = this.line + this.rawTaskContentLines.length
return lastLine
}

Expand Down Expand Up @@ -178,6 +177,8 @@ class Task {
}

updateFromContent(content) {
// replace all occurrences of two empty lines in a row with a single empty line
content = content.replace(/\n\s*\n\s*\n/g, '\n\n')
let lines = eol.split(content)
this.text = lines.shift().trim()
if (lines && lines.length > 1 && lines[lines.length - 1].trim() === '') lines.pop()
Expand Down
8 changes: 8 additions & 0 deletions test/repository-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ describe('Repository', function () {
'- [ ] #DOING A task',
' <!-- order:40 newTask:true -->',
'',
'',
''
])
repo3.addTaskToFile(filePath, 'DOING', content, (err, file) => {
// BACKLOG:-110 make sure the task is added correctly
Expand Down Expand Up @@ -894,6 +896,8 @@ describe('Repository', function () {
'- [ ] [A task!](#DOING:)',
' <!-- newTask:true -->',
'',
'',
''
])
repo3.addTaskToFile(filePath, 'DOING', content, (err, file) => {
// BACKLOG:-110 make sure the task is added correctly
Expand Down Expand Up @@ -933,6 +937,8 @@ describe('Repository', function () {
const expectedLines = JSON.stringify([
'[A task](#DOING:)',
'- with a bullet',
'',
'',
''
])
repo3.addTaskToFile(filePath, 'DOING', content, (err, file) => {
Expand Down Expand Up @@ -963,6 +969,8 @@ describe('Repository', function () {
const expectedLines = JSON.stringify([
'- [ ] #DOING A task',
' - with a bullet',
'',
'',
''
])
repo3.addTaskToFile(filePath, 'DOING', content, (err, file) => {
Expand Down

0 comments on commit 3ab99f0

Please sign in to comment.