remove manual main definitions

This commit is contained in:
2021-07-25 21:10:15 -06:00
parent b00e3d3c2e
commit 872b4861f8
7 changed files with 73 additions and 82 deletions

View File

@@ -13,16 +13,15 @@
// TODO add sequentialPerPDF argument (which, when used, .shift()s pages from the beginning of PDFs)
// TODO add chunkSize argument (default 1, which specifies how many pages in order to pull from a random PDF. value of -1 means take the whole PDF, and remove it from the list)
// TODO make output page limit optional
(function :Void main []
(let [[sourceDir numPages] (Sys.args)]
(loadAll (for file (Fs.readdirSync sourceDir) (+ sourceDir "/" file))
(lambda [:Array<PDFDocument> inputPdfs]
(awaitLet [saladPdf (PDFDocument.create)
pages (Promise.all
(for _ (range 0 (Std.parseInt numPages))
(let [:PDFDocument pdf (nth inputPdfs (Std.random inputPdfs.length))
page (Std.random (pdf.getPageCount))]
(saladPdf.copyPages pdf [page]))))]
(doFor page pages (saladPdf.addPage (first page)))
(awaitLet [bytesOut (saladPdf.save)]
(Fs.writeFileSync "out.pdf" bytesOut)))))))
(let [[sourceDir numPages] (Sys.args)]
(loadAll (for file (Fs.readdirSync sourceDir) (+ sourceDir "/" file))
(lambda [:Array<PDFDocument> inputPdfs]
(awaitLet [saladPdf (PDFDocument.create)
pages (Promise.all
(for _ (range 0 (Std.parseInt numPages))
(let [:PDFDocument pdf (nth inputPdfs (Std.random inputPdfs.length))
page (Std.random (pdf.getPageCount))]
(saladPdf.copyPages pdf [page]))))]
(doFor page pages (saladPdf.addPage (first page)))
(awaitLet [bytesOut (saladPdf.save)]
(Fs.writeFileSync "out.pdf" bytesOut))))))