From 2fa19a590a25923801a1d01de3c10555e2ba9201 Mon Sep 17 00:00:00 2001 From: Lucas Bersier Date: Fri, 14 Dec 2018 02:23:26 +0000 Subject: [PATCH] Booklist generator (node) --- booklistgen.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 booklistgen.js diff --git a/booklistgen.js b/booklistgen.js new file mode 100644 index 0000000..fefbf90 --- /dev/null +++ b/booklistgen.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const rootFolder = process.argv[2]; +let booklist = fs.readdirSync(rootFolder); + +let books = []; + +booklist.forEach(book => { + let bookData = fs.readFileSync(`${rootFolder}/${book}/data.txt`) + .toString() + .split('\n'); + + let bookObj = { + folder: `${rootFolder}/${book}`, + name: bookData[0], + kanji: bookData[1], + author: bookData[2], + TL: bookData[3], + BG: bookData[4], + BBG: bookData[5] + }; + + bookObj.chapters = fs.readdirSync(bookObj.folder) + .filter(chapter => { + return fs.lstatSync(`${rootFolder}/${book}/${chapter}`).isDirectory() + }); + + books.push(bookObj); +}); + +fs.writeFile('./BOOKLIST.js', 'var books = '+JSON.stringify(books), err => { + if (err){ + return console.log('Unable to generate booklist file\n' + err) + } else { + console.log('Booklist generated!\nRun \'yarn run build\' next'); + } +});