Skip to content

Commit

Permalink
Merge pull request #327 from imdone/1.33.0/update-task-from-content
Browse files Browse the repository at this point in the history
1.33.0/update task from content
  • Loading branch information
piascikj committed Sep 2, 2023
2 parents acd7845 + d5c2c76 commit 0753e4b
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 29 deletions.
21 changes: 14 additions & 7 deletions .imdone/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,31 @@ code:
lists:
- hidden: true
name: FIXME
id: jea6nx7llx85j9j
- name: NOTE
hidden: false
hidden: true
ignore: false
id: jea6nx7llx85j9k
- name: HACK
hidden: true
ignore: false
- hidden: false
id: jea6nx7llx85j9l
- hidden: true
name: BACKLOG
id: jea6nx7llx85j9m
- hidden: false
name: TODO
id: jea6nx7llx85j9n
- hidden: false
name: DOING
id: jea6nx7llx85j9o
- hidden: false
name: READY
id: jea6nx7llx85j9p
- hidden: false
ignore: false
ignore: true
name: DONE
id: jea6nx7llx85j9q
marked:
gfm: true
tables: true
Expand Down Expand Up @@ -62,15 +70,14 @@ settings:
value: Release 1.29.0
- key: epic
value: Release 2.0
filteredLists: []
journalTemplate: null
theme: dark
filteredLists: []
filterHistory:
- allMeta.id = "4"
views:
- id: default
defaultFilter: ''
views: []
name: imdone core
defaultFilter: !<tag:yaml.org,2002:js/undefined> ''
cards:
colors:
- color: green
Expand Down
2 changes: 2 additions & 0 deletions .imdoneignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ test-big-file.md
tmp
imdone-export.json
.imdone/templates
.imdone
backlog
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test
notes
backlog
docs
tmp
coverage
Expand Down
58 changes: 58 additions & 0 deletions backlog/.imdone/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
keepEmptyPriority: true
code:
include_lists:
- TODO
- DOING
- DONE
- PLANNING
- FIXME
- ARCHIVE
- HACK
- CHANGED
- XXX
- IDEA
- NOTE
- REVIEW
lists:
- hidden: false
name: TODO
id: jea6phpllxpsj7j
- hidden: false
name: DOING
id: jea6phpllxpsj7k
- hidden: false
ignore: true
name: DONE
id: jea6phpllxpsj7l
settings:
openIn: default
customOpenIn: ''
editorTheme: blackboard
journalType: New File
journalPath: .
appendNewCardsTo: imdone-tasks.md
newCardSyntax: HASHTAG
replaceSpacesWith: '-'
plugins:
devMode: false
journalTemplate: null
theme: dark
views: []
name: backlog
cards:
colors: []
template: |
<!-- created:${(new Date()).toISOString()} sid:${sid} -->
trackChanges: false
metaNewLine: false
addCompletedMeta: false
addCheckBoxTasks: false
doneList: DONE
taskPrefix: '##'
tagPrefix: +
metaSep: ':'
orderMeta: true
maxLines: 6
addNewCardsToTop: true
defaultList: TODO
17 changes: 17 additions & 0 deletions backlog/.imdone/properties/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const generateRandomString = (length) => {
let result = '';
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};

module.exports = function (task) {
const project = this.project
return {
sid: generateRandomString(8)
}
}
56 changes: 56 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

const { program } = require('commander');
const { imdoneInit, addTask, listTasks } = require('./lib/controlers/CliControler')
const package = require('./package.json')

const { log, info, warn, logQueue } = hideLogs()

// TODO ## Add an option to add properties/card.js
program
.version(package.version, '-v, --version', 'output the current version')
.command('init')
.description('initialize imdone project')
.option('-p, --project-path <path>', 'The path to the imdone project')
.option('-c, --config-path <path>', 'The path to the imdone config file')
.action(async function () {
let { projectPath = process.env.PWD, configPath } = this.opts()
await imdoneInit(projectPath, configPath)
})

program
.command('add <task>')
.description('add a task')
.option('-p, --project-path <path>', 'The path to the imdone project')
.option('-l, --list <list>', 'The task list to use')
.option('-t, --tags <tags...>', 'The tags to use')
.option('-c, --contexts <contexts...>', 'The contexts to use')
.action(async function () {
let { projectPath = process.env.PWD, list, tags, contexts } = this.opts()
await addTask(this.args[0], projectPath, list, tags, contexts)
})

program
.command('ls')
.description('list tasks')
.option('-p, --project-path <path>', 'The path to the imdone project')
.option('-f, --filter <filter>', 'The filter to use')
.option('-j, --json', 'Output as json')
.action(async function () {
let { projectPath = process.env.PWD, filter, json } = this.opts()
await listTasks(projectPath, filter, json, log)
})
program.parse();

function hideLogs() {
const log = console.log
const info = console.info
const warn = console.warn
const logQueue = {warn: [], info: [], log: []}
Object.keys(logQueue).forEach((key) => {
console[key] = function(...args) {
logQueue[key].push(args)
}
})
return {log, info, warn, logQueue}
}
58 changes: 58 additions & 0 deletions devops/imdone/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
keepEmptyPriority: true
code:
include_lists:
- TODO
- DOING
- DONE
- PLANNING
- FIXME
- ARCHIVE
- HACK
- CHANGED
- XXX
- IDEA
- NOTE
- REVIEW
lists:
- hidden: false
name: TODO
id: jea6phpllxpsj7j
- hidden: false
name: DOING
id: jea6phpllxpsj7k
- hidden: false
ignore: true
name: DONE
id: jea6phpllxpsj7l
settings:
openIn: default
customOpenIn: ''
editorTheme: blackboard
journalType: New File
journalPath: .
appendNewCardsTo: imdone-tasks.md
newCardSyntax: HASHTAG
replaceSpacesWith: '-'
plugins:
devMode: false
journalTemplate: null
theme: dark
views: []
name: backlog
cards:
colors: []
template: |
<!-- created:${(new Date()).toISOString()} sid:${sid} -->
trackChanges: false
metaNewLine: false
addCompletedMeta: false
addCheckBoxTasks: false
doneList: DONE
taskPrefix: '##'
tagPrefix: +
metaSep: ':'
orderMeta: true
maxLines: 6
addNewCardsToTop: true
defaultList: TODO
17 changes: 17 additions & 0 deletions devops/imdone/properties/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const generateRandomString = (length) => {
let result = '';
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};

module.exports = function (task) {
const project = this.project
return {
sid: generateRandomString(8)
}
}
1 change: 0 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,4 @@ class Config {
}

Config.newDefaultConfig = (config = {}) => new Config({...DEFAULT_CONFIG, lists: [...DEFAULT_CONFIG.lists], ...config})

module.exports = Config
102 changes: 102 additions & 0 deletions lib/controlers/CliControler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const { resolve } = require('path')
const { createFileSystemProject } = require('../project-factory')
const { loadYAML } = require('../tools')
const { readFile } = require('fs/promises')
const Config = require('../config')

newConfigFromFile = async (configPath) => {
const config = await readFile(configPath, 'utf8')
return new Config(loadYAML(config))
}


module.exports = {
imdoneInit: async function (projectPath, configPath) {
projectPath = resolve(projectPath)
let config
if (configPath) {
configPath = resolve(configPath)
config = await newConfigFromFile(configPath)
}
const project = createFileSystemProject({path: projectPath, config})
return await project.init()
},

addTask: async function (task, projectPath, list, tags, contexts) {
projectPath = resolve(projectPath)
const project = createFileSystemProject({path: projectPath})
await project.init()
const data = await project.addTaskToFile({list, content: task, tags, contexts})
},

listTasks: async function (projectPath, filter, json, log) {
projectPath = resolve(projectPath)
const project = createFileSystemProject({path: projectPath})
await project.init()
const tasks = project.getCards(filter)
const lists = project.getLists({tasks})

if (json) return log(JSON.stringify(lists, null, 2))

if (project.getCards('meta.group=*', tasks).length > 0) {
const groupedTasks = getGroupedTasks(tasks)
logProject(log, project)
logGroupedTasks(log, project, groupedTasks)
} else {
logProject(log, project)
logLists(log, project, lists, '##')
}
}
}

function getGroupedTasks(tasks) {
const groupedTasks = {"Ungrouped Tasks": []}
tasks.forEach((task) => {
const group = task.meta.group
if (group) {
if (!groupedTasks[group]) groupedTasks[group] = []
groupedTasks[group].push(task)
} else {
groupedTasks["Ungrouped Tasks"].push(task)
}
})
return groupedTasks
}

function logGroupedTasks(log, project, groupedTasks) {
Object.keys(groupedTasks).forEach((group) => {
log(`## ${group}`)
log('')
logLists(log, project, project.getLists({tasks: groupedTasks[group]}), '###')
})
}

function logLists(log, project, lists, heading) {
lists.forEach((list) => {
const tasks = list.tasks
if (tasks.length > 0) {
log(`${heading} ${list.name}`)
log('')
logTasks(log, project, tasks)
log('')
}
})
}

function logTasks(log, project, tasks) {
tasks.forEach(task => logTask(log, project, task))
}

function logProject(log, project) {
log(project.name)
log('====')
log('')
}

function logTask(log, project, task) {
const doneMark = (task.list === project.config.getDoneList()) ? 'x' : ' '
log(`- [${doneMark}] ${task.text}`)
task.description.forEach((line) => {
log(` ${line}`)
})
}
Loading

0 comments on commit 0753e4b

Please sign in to comment.