Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Booklist generator (node)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Bersier committed Dec 14, 2018
1 parent 2c3c2f4 commit 2fa19a5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions booklistgen.js
Original file line number Diff line number Diff line change
@@ -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');
}
});

0 comments on commit 2fa19a5

Please sign in to comment.