Skip to content

Commit e43913b

Browse files
committed
Working with comments
1 parent 42f3308 commit e43913b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

index.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/* Imports */
22
let markdownpdf = require(process.cwd() + '/markdown-pdf/index' )
3+
// Markdown PDF is bundled separately because there are issues running phantom with render.js when
4+
// bundled as an executable with nexe
5+
36
let fileSystem = require('fs')
47
let path = require('path')
58

69

710
/* Removes Original Markdown Files and Folders from directory */
811
let removeDir = (path) => {
912
if (fileSystem.existsSync(path)) {
10-
/*Delete Markdown Folders with assets */
13+
/* Ensure that software files and generated PDFs are not deleted */
1114
let files = fileSystem.readdirSync(path).filter((file) => {
1215
return file != 'node_modules'
1316
&& file != 'markdown-pdf'
@@ -23,8 +26,8 @@ let path = require('path')
2326

2427
}
2528
)
26-
console.log(files)
2729

30+
/* Recursive Deletion of Markdowns and their folders */
2831
if (files.length > 0) {
2932
files.forEach(function(filename) {
3033
if (fileSystem.statSync(path + "/" + filename).isDirectory()) {
@@ -58,20 +61,26 @@ let path = require('path')
5861

5962
/* Create an Array of Markdown Files to be Converted */
6063
let markdownFiles = []
61-
console.log('Directory being checked is ')
62-
console.log(__dirname)
6364
fileSystem.readdirSync(process.cwd()).forEach(file => {
64-
console.log(file)
6565
if(file.includes('.md')){
6666
markdownFiles.push(file)
6767
}
6868
})
69+
if(markdownFiles.length === 0){
70+
/* Only exit when user presses a key */
71+
console.log('\nPlease add some markdown files to the same folder as the exe file')
72+
console.log('Press any key to exit');
73+
74+
process.stdin.setRawMode(true);
75+
process.stdin.resume();
76+
process.stdin.on('data', process.exit.bind(process, 0));
77+
}
6978
console.log('Files to be converted :')
7079
console.log(markdownFiles)
7180

7281
/* Create a book with all markdown files */
7382
let bookPath = process.cwd() + "/pdfs/book.pdf"
74-
console.log('Creating a book...')
83+
console.log('\n\nCreating a book...')
7584
markdownpdf({phantomPath: path.join(process.cwd(), 'phantomjs.exe')}).concat.from(markdownFiles).to(bookPath, function () {
7685
console.log("Created a book at", bookPath)
7786

@@ -88,10 +97,11 @@ markdownpdf({phantomPath: path.join(process.cwd(), 'phantomjs.exe')}).concat.fro
8897
pdfDocs.forEach(function (d) { console.log("Created", d) })
8998

9099
/*Delete Original Markdown Files and Folders */
91-
console.log('Deleting Original Markdown Files...')
100+
console.log('\n\nDeleting Original Markdown Files...')
92101
removeDir(process.cwd())
93102

94103
/* Only exit when user presses a key */
104+
console.log('\nCompleted, PDFs can be found in the pdfs folder :)')
95105
console.log('Press any key to exit');
96106

97107
process.stdin.setRawMode(true);

0 commit comments

Comments
 (0)