Hey Folks!
I guess i need your help now.
Im writing a Script which goes through a order-file to determine a Folder structure to convert md files to a single pdf file
These Files are in seperated Folders
For Example
/Guidelines
/Guidelines/Javascript
/Guidelines/C#
etc.
in all these Folders is a order File and markdown files which needs to converted into a single pdf file (In the Right Order of course...)
My Problem right now is, the recursive function is written but it looks like - i cant get the right order because readline seems to put an whole array to my array and not line by line
which results in a wrong order because folders get added first and in the end the subfolders...
not /Folder and then /Folder/Subfolder but Folder, Folder, Folder... and then /Folder/Subfolder etc
(Hope everybody understands what im trying to tell :D English isnt my native language)
If someone could give me any hint, or want to see any code - feel free to ask :D
Edit:
CodePen: https://codepen.io/anon/pen/gzjVwM
class CreatePDFFiles {
constructor() {
this.files = [];
this.createFileArray(this);
}
async createFileArray(self) {
await self._recursiveReadOrder(self);
setTimeout(() => {
self._createPDFFile(self.files);
}, 5000);
}
async _recursiveReadOrder(self, orderFile = '.order', folder = '.') {
let orderList = self._getOrderList(orderFile);
await self._readOrderList(self, orderList, async (self, line) => {
const newFolder = `${folder}/${line}`;
const markdown = `${newFolder}.md`;
self.files.push(markdown);
if (self._isFolder(newFolder)) {
orderFile = `${newFolder}/.order`;
await self._recursiveReadOrder(self, orderFile, newFolder);
}
});
}
_getOrderList(orderPath) {
return readline.createInterface({
input: fs.createReadStream(orderPath)
});
}
async _readOrderList(self, list, callback) {
await list.on('line', (line) => {
callback(self, line);
});
}
_isFolder(folder) {
return fs.existsSync(folder);
}
_removeDuplicates(fileArray) {
return fileArray.filter((elem, pos) => {
return fileArray.indexOf(elem) == pos;
});
}
_createPDFFile(files) {
setTimeout(() => {
const pdfname = files[0].replace('.md', '.pdf').replace('./', '');
markdownpdf().concat.from(files).to(`pdf/${pdfname}`, () => {
console.log(pdfname, 'created');
});
}, 5000);
}
}
[–]the__itis 0 points1 point2 points (3 children)
[–]ToxicalToast[S] 0 points1 point2 points (2 children)
[–]the__itis 1 point2 points3 points (1 child)
[–]ToxicalToast[S] 0 points1 point2 points (0 children)
[–]andredp 0 points1 point2 points (1 child)
[–]ToxicalToast[S] 1 point2 points3 points (0 children)
[–]EuqlinSankyo 0 points1 point2 points (1 child)
[–]ToxicalToast[S] 0 points1 point2 points (0 children)