const fs = require('node-fs') const sourceFilePath = 'source/tasks.json'; const stats = { countAllTasks: 0, tasksByDay: {} } // prendre le json source représentant les tâches DONE console.log(' ### lecture de source/emacs_json.json'); fs.stat(sourceFilePath, function (err, stat) { if (err == null) { console.log(`File ${sourceFilePath} exists`); sortTasksFromJson(stat) } else if (err.code === 'ENOENT') { // file does not exist console.error(`le fichier ${sourceFilePath} est introuvable. Impossible d en extraire des infos.`) } else { console.log('Some other error: ', err.code); } }); // parcourir les tâches function sortTasksFromJson(statObject) { console.log('sortTasksFromJson') fs.readFile(sourceFilePath, 'utf8', function (err, data) { if (err) { return console.log(err); } let dataTransformed = JSON.parse(data); console.log('data keys ', Object.keys(dataTransformed)) if (dataTransformed["contents"]) { countTasks = dataTransformed["contents"].length stats.countAllTasks = countTasks; console.log('yes data !', countTasks) console.log('first', dataTransformed["contents"][0]) dataTransformed["contents"].forEach((elem) => { if (elem['title'] && elem['title'][0]) { console.log(' - ', elem['title'][0]) } if (elem['properties'] && elem['properties']['closed']) { let title = elem['properties']['raw-value']; let tags = elem['tags'] ? elem['tags'] : []; let closeDate = elem['properties']['closed']['end']; let todoKeyword = elem['drawer']['ARCHIVE_TODO']; let itags = elem['drawer']['ARCHIVE_ITAGS']; // jour, 11 premiers caractères let day = closeDate.substring(0, 10); if (!stats.tasksByDay[day]) { stats.tasksByDay[day] = [] } stats.tasksByDay[day].push({ title, closeDate, tags, todoKeyword, day, itags }) // console.log(' ' + title) } else { console.log('no' , elem['properties']['raw-value']) } }) // console.log('element', dataTransformed["contents"]["0"]) } else { console.log('no content') } // console.log(data); writeHtmlOutput() }); // les répartir dans des tableaux selon les périodes de temps } // sortir un html présentant les périodes de temps et les tâches réalisées function writeHtmlOutput() { console.log('writeHtmlOutput', stats.countAllTasks) let daysListRef = Object.keys(stats.tasksByDay).sort() let htmlOut = `