-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkEPUB.ts
24 lines (21 loc) · 930 Bytes
/
checkEPUB.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as path from 'path';
import { promises as fsp, default as fs } from 'fs';
import { Configuration } from './Configuration.js';
/**
* Run some checks against the {@link Configuration}. Currently that means verifying
* that files in the {@link Manifest} exist.
* @param config The {@link Configuration} object
*/
export async function checkEPUBConfig(config: Configuration): Promise<void> {
for (const mItem of config.opfManifest) {
if (!mItem.id || typeof mItem.id !== 'string' || mItem.id === '') {
throw new Error(`Manifest item - path ${mItem.path} - does not have ID`);
}
const pathItem = path.join(config.renderedFullPath, mItem.path);
try {
await fsp.access(pathItem, fs.constants.R_OK);
} catch (e) {
throw new Error(`Manifest item is not readable or does not exist ${mItem.path} - ${pathItem} because ${e}`);
}
}
}