-
Notifications
You must be signed in to change notification settings - Fork 22
Ace CLI batch processing (folder of EPUB files)
Daniel Weck edited this page Apr 8, 2021
·
15 revisions
node ace.js "./RELATIVE/OR/ABSOLUTE/PATH/TO/EPUBS/" --verbose
(the --verbose
command line argument is optional)
Note that this utility script only processes EPUB files located at the root of the designated folder (i.e. ./RELATIVE/OR/ABSOLUTE/PATH/TO/EPUBS/
in the example above), publications inside subfolders are ignored.
By default, the following command line arguments are used (they can be modified at the top of the ace.js
script):
-
--outdir ace-reports
(this tells Ace to generate reports in a local folder namedace-reports
) -
--subdir
(this asks Ace to create subfolders for each publication inside the main report folder) -
--force
(this instructs Ace to overwrite the contents of existing report folders, if any)
CLI Command Line Interface documentation: https://daisy.github.io/ace/docs/cli/#options
Note that a 1 second pause is added between each EPUB evaluation. This can be configured at the top of the ace.js
script (the recommended minimum is 200 milliseconds):
const ACE_ARGS = ["--force", "--outdir", "ace-reports", "--subdir"]; // --verbose, --lang en, etc.
const PAUSE = 1000; // milliseconds
// sudo npm install --unsafe-perm=true -g @daisy/ace
const fs = require('fs');
const path = require('path');
const util = require('util');
const execFile = util.promisify(require('child_process').execFile);
(async () => {
console.log(`=== PROCESS ARGS: `, JSON.stringify(process.argv, null, 4));
const dirPath = path.normalize(path.resolve(fs.existsSync(process.argv[2]) ? process.argv[2] : path.join(process.cwd(), process.argv[2])));
console.log(`=== DIR PATH: `, dirPath);
const epubFiles = fs.readdirSync(dirPath, { withFileTypes: true })
.filter(dirent => dirent.isFile() && path.extname(dirent.name) === ".epub")
.map(dirent => path.join(dirPath, dirent.name));
console.log(`=== EPUB FILES: `, JSON.stringify(epubFiles, null, 4));
const sep = "#".repeat(100);
for (const epubFile of epubFiles) {
console.log(sep);
console.log(sep);
console.log(sep);
console.log(`=== EPUB FILE: [${epubFile}]`);
const args = process.argv.slice(3).concat(ACE_ARGS, [epubFile]);
console.log(`=== ACE ARGS: `, JSON.stringify(args, null, 4));
try {
const { stdout, stderr } = await execFile('ace', args);
console.log(stdout);
console.log(stderr);
} catch (err) {
console.log(err.stdout);
console.log(err.stderr);
delete err.stdout;
delete err.stderr;
console.log(`=== ACE ERROR: `, err);
}
await new Promise((resolve, reject) => {setTimeout(() => {resolve();}, PAUSE);});
}
})();