-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from imdone/1.33.0/update-task-from-content
1.33.0/update task from content
- Loading branch information
Showing
20 changed files
with
444 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ test-big-file.md | |
tmp | ||
imdone-export.json | ||
.imdone/templates | ||
.imdone | ||
backlog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
test | ||
notes | ||
backlog | ||
docs | ||
tmp | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
}) | ||
} |
Oops, something went wrong.