@vivliostyle/cli 8.17.1 → 9.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +12 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +108 -13
- package/dist/browser.js.map +1 -1
- package/dist/commands/build.js +10 -44
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/build.parser.d.ts +0 -5
- package/dist/commands/build.parser.d.ts.map +1 -1
- package/dist/commands/build.parser.js +15 -23
- package/dist/commands/build.parser.js.map +1 -1
- package/dist/commands/cli-flags.d.ts +42 -0
- package/dist/commands/cli-flags.d.ts.map +1 -0
- package/dist/commands/cli-flags.js +58 -0
- package/dist/commands/cli-flags.js.map +1 -0
- package/dist/commands/init.js +4 -12
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/preview.js +4 -37
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/preview.parser.d.ts.map +1 -1
- package/dist/commands/preview.parser.js +6 -4
- package/dist/commands/preview.parser.js.map +1 -1
- package/dist/config/load.d.ts +7 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +72 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/merge.d.ts +4 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +78 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/{input/config.d.ts → config/resolve.d.ts} +81 -82
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +727 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/{input → config}/schema.d.ts +6023 -3542
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +562 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/vite.d.ts +53 -0
- package/dist/config/vite.d.ts.map +1 -0
- package/dist/config/vite.js +19 -0
- package/dist/config/vite.js.map +1 -0
- package/dist/const.d.ts +2 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +2 -0
- package/dist/const.js.map +1 -1
- package/dist/container.d.ts +12 -3
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +130 -30
- package/dist/container.js.map +1 -1
- package/dist/core/build.d.ts +3 -0
- package/dist/core/build.d.ts.map +1 -0
- package/dist/core/build.js +168 -0
- package/dist/core/build.js.map +1 -0
- package/dist/core/init.d.ts +3 -0
- package/dist/core/init.d.ts.map +1 -0
- package/dist/{init.js → core/init.js} +14 -19
- package/dist/core/init.js.map +1 -0
- package/dist/core/preview.d.ts +3 -0
- package/dist/core/preview.d.ts.map +1 -0
- package/dist/core/preview.js +93 -0
- package/dist/core/preview.js.map +1 -0
- package/dist/index.d.ts +32 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +23 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +161 -0
- package/dist/logger.js.map +1 -0
- package/dist/output/epub.d.ts.map +1 -1
- package/dist/output/epub.js +17 -15
- package/dist/output/epub.js.map +1 -1
- package/dist/output/pdf-postprocess.d.ts +2 -3
- package/dist/output/pdf-postprocess.d.ts.map +1 -1
- package/dist/output/pdf-postprocess.js +94 -29
- package/dist/output/pdf-postprocess.js.map +1 -1
- package/dist/output/pdf.d.ts +4 -7
- package/dist/output/pdf.d.ts.map +1 -1
- package/dist/output/pdf.js +77 -141
- package/dist/output/pdf.js.map +1 -1
- package/dist/output/webbook.d.ts +10 -10
- package/dist/output/webbook.d.ts.map +1 -1
- package/dist/output/webbook.js +44 -62
- package/dist/output/webbook.js.map +1 -1
- package/dist/processor/compile.d.ts +24 -10
- package/dist/processor/compile.d.ts.map +1 -1
- package/dist/processor/compile.js +195 -130
- package/dist/processor/compile.js.map +1 -1
- package/dist/processor/html.d.ts +29 -17
- package/dist/processor/html.d.ts.map +1 -1
- package/dist/processor/html.js +112 -88
- package/dist/processor/html.js.map +1 -1
- package/dist/processor/markdown.d.ts +1 -1
- package/dist/processor/markdown.d.ts.map +1 -1
- package/dist/processor/theme.d.ts +3 -3
- package/dist/processor/theme.d.ts.map +1 -1
- package/dist/processor/theme.js +29 -53
- package/dist/processor/theme.js.map +1 -1
- package/dist/server.d.ts +17 -38
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +76 -102
- package/dist/server.js.map +1 -1
- package/dist/util.d.ts +9 -29
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +54 -158
- package/dist/util.js.map +1 -1
- package/dist/vite/plugin-util.d.ts +6 -0
- package/dist/vite/plugin-util.d.ts.map +1 -0
- package/dist/vite/plugin-util.js +20 -0
- package/dist/vite/plugin-util.js.map +1 -0
- package/dist/vite/vite-plugin-browser.d.ts +8 -0
- package/dist/vite/vite-plugin-browser.d.ts.map +1 -0
- package/dist/vite/vite-plugin-browser.js +57 -0
- package/dist/vite/vite-plugin-browser.js.map +1 -0
- package/dist/vite/vite-plugin-dev-server.d.ts +8 -0
- package/dist/vite/vite-plugin-dev-server.d.ts.map +1 -0
- package/dist/vite/vite-plugin-dev-server.js +267 -0
- package/dist/vite/vite-plugin-dev-server.js.map +1 -0
- package/dist/vite/vite-plugin-static-serve.d.ts +8 -0
- package/dist/vite/vite-plugin-static-serve.d.ts.map +1 -0
- package/dist/vite/vite-plugin-static-serve.js +24 -0
- package/dist/vite/vite-plugin-static-serve.js.map +1 -0
- package/dist/vite/vite-plugin-viewer.d.ts +8 -0
- package/dist/vite/vite-plugin-viewer.d.ts.map +1 -0
- package/dist/vite/vite-plugin-viewer.js +52 -0
- package/dist/vite/vite-plugin-viewer.js.map +1 -0
- package/dist/vite-adapter.d.ts +3 -0
- package/dist/vite-adapter.d.ts.map +1 -0
- package/dist/vite-adapter.js +27 -0
- package/dist/vite-adapter.js.map +1 -0
- package/package.json +13 -15
- package/dist/build.d.ts +0 -21
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -119
- package/dist/build.js.map +0 -1
- package/dist/init.d.ts +0 -16
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js.map +0 -1
- package/dist/input/config.d.ts.map +0 -1
- package/dist/input/config.js +0 -807
- package/dist/input/config.js.map +0 -1
- package/dist/input/input-types.d.ts +0 -34
- package/dist/input/input-types.d.ts.map +0 -1
- package/dist/input/input-types.js +0 -34
- package/dist/input/input-types.js.map +0 -1
- package/dist/input/schema.d.ts.map +0 -1
- package/dist/input/schema.js +0 -233
- package/dist/input/schema.js.map +0 -1
- package/dist/output/output-types.d.ts +0 -26
- package/dist/output/output-types.d.ts.map +0 -1
- package/dist/output/output-types.js +0 -23
- package/dist/output/output-types.js.map +0 -1
- package/dist/preview.d.ts +0 -11
- package/dist/preview.d.ts.map +0 -1
- package/dist/preview.js +0 -191
- package/dist/preview.js.map +0 -1
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import fs from 'node:fs';
|
|
3
2
|
import upath from 'upath';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export async function init(cliFlags) {
|
|
13
|
-
setLogLevel(cliFlags.logLevel);
|
|
14
|
-
const vivliostyleConfigPath = upath.join(cwd, 'vivliostyle.config.js');
|
|
3
|
+
import { cyan, yellow } from 'yoctocolors';
|
|
4
|
+
import { CONTAINER_IMAGE } from '../container.js';
|
|
5
|
+
import { Logger } from '../logger.js';
|
|
6
|
+
import { cwd, runExitHandlers } from '../util.js';
|
|
7
|
+
export async function init(inlineConfig) {
|
|
8
|
+
Logger.setLogLevel(inlineConfig.logLevel);
|
|
9
|
+
const vivliostyleConfigPath = upath.join(inlineConfig.cwd ?? cwd, 'vivliostyle.config.js');
|
|
15
10
|
if (fs.existsSync(vivliostyleConfigPath)) {
|
|
16
11
|
runExitHandlers();
|
|
17
|
-
return log(`${
|
|
12
|
+
return Logger.log(`${yellow('vivliostyle.config.js already exists. aborting.')}`);
|
|
18
13
|
}
|
|
19
14
|
// prettier-ignore
|
|
20
15
|
const vivliostyleConfig = `// @ts-check
|
|
21
16
|
/** @type {import('@vivliostyle/cli').VivliostyleConfigSchema} */
|
|
22
17
|
const vivliostyleConfig = {
|
|
23
|
-
title: '${
|
|
24
|
-
author: '${
|
|
25
|
-
${
|
|
18
|
+
title: '${inlineConfig.title || 'Principia'}', // populated into 'publication.json', default to 'title' of the first entry or 'name' in 'package.json'.
|
|
19
|
+
author: '${inlineConfig.author || 'Isaac Newton'}', // default to 'author' in 'package.json' or undefined
|
|
20
|
+
${inlineConfig.language ? '' : '// '}language: '${inlineConfig.language || 'la'}',
|
|
26
21
|
// readingProgression: 'rtl', // reading progression direction, 'ltr' or 'rtl'.
|
|
27
|
-
${
|
|
28
|
-
${
|
|
22
|
+
${inlineConfig.size ? '' : '// '}size: '${inlineConfig.size || 'A4'}',
|
|
23
|
+
${inlineConfig.theme ? '' : '// '}theme: '${inlineConfig.theme || ''}', // .css or local dir or npm package. default to undefined
|
|
29
24
|
image: '${CONTAINER_IMAGE}',
|
|
30
25
|
entry: [ // **required field**
|
|
31
26
|
// 'introduction.md', // 'title' is automatically guessed from the file (frontmatter > first heading)
|
|
@@ -71,6 +66,6 @@ module.exports = vivliostyleConfig;
|
|
|
71
66
|
`;
|
|
72
67
|
fs.writeFileSync(vivliostyleConfigPath, vivliostyleConfig);
|
|
73
68
|
runExitHandlers();
|
|
74
|
-
log(`Successfully created ${
|
|
69
|
+
Logger.log(`Successfully created ${cyan('vivliostyle.config.js')}`);
|
|
75
70
|
}
|
|
76
71
|
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/core/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE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AC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/core/preview.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAKpE,wBAAsB,OAAO,CAAC,YAAY,EAAE,6BAA6B,iBAgCxE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
function next() {
|
|
30
|
+
while (env.stack.length) {
|
|
31
|
+
var rec = env.stack.pop();
|
|
32
|
+
try {
|
|
33
|
+
var result = rec.dispose && rec.dispose.call(rec.value);
|
|
34
|
+
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
fail(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (env.hasError) throw env.error;
|
|
41
|
+
}
|
|
42
|
+
return next();
|
|
43
|
+
};
|
|
44
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
+
var e = new Error(message);
|
|
46
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
+
});
|
|
48
|
+
import terminalLink from 'terminal-link';
|
|
49
|
+
import { blueBright, cyan, dim } from 'yoctocolors';
|
|
50
|
+
import { setupConfigFromFlags } from '../commands/cli-flags.js';
|
|
51
|
+
import { loadVivliostyleConfig, warnDeprecatedConfig } from '../config/load.js';
|
|
52
|
+
import { mergeInlineConfig } from '../config/merge.js';
|
|
53
|
+
import { resolveTaskConfig } from '../config/resolve.js';
|
|
54
|
+
import { cliVersion } from '../const.js';
|
|
55
|
+
import { isUnicodeSupported, Logger, randomBookSymbol } from '../logger.js';
|
|
56
|
+
import { createViteServer, getViewerFullUrl } from '../server.js';
|
|
57
|
+
export async function preview(inlineConfig) {
|
|
58
|
+
Logger.setLogLevel(inlineConfig.logLevel);
|
|
59
|
+
const vivliostyleConfig = (await loadVivliostyleConfig({
|
|
60
|
+
configPath: inlineConfig.config,
|
|
61
|
+
cwd: inlineConfig.cwd,
|
|
62
|
+
})) ?? setupConfigFromFlags(inlineConfig);
|
|
63
|
+
warnDeprecatedConfig(vivliostyleConfig);
|
|
64
|
+
const { tasks, inlineOptions } = mergeInlineConfig(vivliostyleConfig, inlineConfig);
|
|
65
|
+
// Only show preview of first entry
|
|
66
|
+
const config = resolveTaskConfig(tasks[0], inlineOptions);
|
|
67
|
+
{
|
|
68
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
69
|
+
try {
|
|
70
|
+
const _ = __addDisposableResource(env_1, Logger.startLogging('Start preview'), false);
|
|
71
|
+
const server = await createViteServer({
|
|
72
|
+
config,
|
|
73
|
+
inlineOptions,
|
|
74
|
+
mode: 'preview',
|
|
75
|
+
});
|
|
76
|
+
await server.listen();
|
|
77
|
+
}
|
|
78
|
+
catch (e_1) {
|
|
79
|
+
env_1.error = e_1;
|
|
80
|
+
env_1.hasError = true;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
__disposeResources(env_1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const url = await getViewerFullUrl(config);
|
|
87
|
+
Logger.log(`
|
|
88
|
+
${cyan(`Vivliostyle CLI v${cliVersion}`)}
|
|
89
|
+
${blueBright('║')} ${isUnicodeSupported ? `${randomBookSymbol} ` : ''}Up and running (press Ctrl+C to quit)
|
|
90
|
+
${blueBright('╙─')} ${dim(`Preview URL: ${terminalLink(url, url, { fallback: () => url })}`)}
|
|
91
|
+
`);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/core/preview.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAA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gBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;CAC3F,CAAC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
+
import { VivliostyleInlineConfig } from './config/schema.js';
|
|
1
2
|
import type { PublicationManifest as _PublicationManifest } from './schema/publication.schema.js';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { StructuredDocument, StructuredDocumentSection, VivliostyleConfigSchema, } from './input/schema.js';
|
|
5
|
-
export { preview, PreviewCliFlags } from './preview.js';
|
|
3
|
+
export type { StructuredDocument, StructuredDocumentSection, VivliostyleConfigSchema, } from './config/schema.js';
|
|
4
|
+
export { createVitePlugin } from './vite-adapter.js';
|
|
6
5
|
/** @hidden */
|
|
7
6
|
export type PublicationManifest = _PublicationManifest;
|
|
7
|
+
/**
|
|
8
|
+
* Build publication file(s) from the given configuration.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { build } from '@vivliostyle/cli';
|
|
12
|
+
* build({
|
|
13
|
+
* configPath: './vivliostyle.config.js',
|
|
14
|
+
* logLevel: 'silent',
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function build(options: VivliostyleInlineConfig): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Initialize a new vivliostyle.config.js file.
|
|
24
|
+
*
|
|
25
|
+
* @param options
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function init(options: VivliostyleInlineConfig): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Open a browser for previewing the publication.
|
|
31
|
+
*
|
|
32
|
+
* @param options
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export declare function preview(options: VivliostyleInlineConfig): Promise<void>;
|
|
8
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAI7D,OAAO,KAAK,EAAE,mBAAmB,IAAI,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAElG,YAAY,EACV,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,cAAc;AACd,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,uBAAuB,iBAG3D;AAED;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,uBAAuB,iBAG1D;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,uBAAuB,iBAG7D"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { VivliostyleInlineConfig } from './config/schema.js';
|
|
3
|
+
import { build as _build } from './core/build.js';
|
|
4
|
+
import { init as _init } from './core/init.js';
|
|
5
|
+
import { preview as _preview } from './core/preview.js';
|
|
6
|
+
export { createVitePlugin } from './vite-adapter.js';
|
|
7
|
+
/**
|
|
8
|
+
* Build publication file(s) from the given configuration.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { build } from '@vivliostyle/cli';
|
|
12
|
+
* build({
|
|
13
|
+
* configPath: './vivliostyle.config.js',
|
|
14
|
+
* logLevel: 'silent',
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export async function build(options) {
|
|
22
|
+
const parsed = v.parse(VivliostyleInlineConfig, options);
|
|
23
|
+
return await _build(parsed);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize a new vivliostyle.config.js file.
|
|
27
|
+
*
|
|
28
|
+
* @param options
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export async function init(options) {
|
|
32
|
+
const parsed = v.parse(VivliostyleInlineConfig, options);
|
|
33
|
+
return await _init(parsed);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Open a browser for previewing the publication.
|
|
37
|
+
*
|
|
38
|
+
* @param options
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export async function preview(options) {
|
|
42
|
+
const parsed = v.parse(VivliostyleInlineConfig, options);
|
|
43
|
+
return await _preview(parsed);
|
|
44
|
+
}
|
|
4
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,IAAI,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAgC;IAC1D,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAgC;IACzD,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAgC;IAC5D,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
export declare const isUnicodeSupported: boolean;
|
|
3
|
+
export declare const randomBookSymbol: string;
|
|
4
|
+
export declare class Logger {
|
|
5
|
+
#private;
|
|
6
|
+
static debug: debug.Debugger;
|
|
7
|
+
static get isInteractive(): boolean;
|
|
8
|
+
static startLogging(text: string): Logger | undefined;
|
|
9
|
+
static suspendLogging(text: string): {
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
} | undefined;
|
|
12
|
+
static log(...messages: any[]): void;
|
|
13
|
+
static logUpdate(...messages: any[]): void;
|
|
14
|
+
static logSuccess(...messages: any[]): void;
|
|
15
|
+
static logError(...messages: any[]): void;
|
|
16
|
+
static logWarn(...messages: any[]): void;
|
|
17
|
+
static logInfo(...messages: any[]): void;
|
|
18
|
+
static logVerbose(...messages: any[]): void;
|
|
19
|
+
static setLogLevel(level?: 'silent' | 'info' | 'verbose' | 'debug'): void;
|
|
20
|
+
constructor();
|
|
21
|
+
[Symbol.dispose](): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,eAAO,MAAM,kBAAkB,SACkC,CAAC;AAElE,eAAO,MAAM,gBAAgB,QAE5B,CAAC;AAOF,qBAAa,MAAM;;IAQjB,MAAM,CAAC,KAAK,iBAAmB;IAM/B,MAAM,KAAK,aAAa,YASvB;IAED,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM;IAiBhC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAsBlC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAO7B,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IA+BnC,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAOpC,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAUlC,MAAM,CAAC,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAUjC,MAAM,CAAC,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAOjC,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE;IAOpC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO;;IAgClE,CAAC,MAAM,CAAC,OAAO,CAAC;CAQjB"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import yoctoSpinner from 'yocto-spinner';
|
|
3
|
+
import { blueBright, gray, greenBright, red, redBright, yellow, yellowBright, } from 'yoctocolors';
|
|
4
|
+
import { isInContainer } from './util.js';
|
|
5
|
+
export const isUnicodeSupported = process.platform !== 'win32' || Boolean(process.env.WT_SESSION);
|
|
6
|
+
export const randomBookSymbol = ['📕', '📗', '📘', '📙'][Math.floor(Math.random() * 4)];
|
|
7
|
+
const infoSymbol = blueBright('INFO');
|
|
8
|
+
const successSymbol = greenBright('SUCCESS');
|
|
9
|
+
const warnSymbol = yellowBright('WARN');
|
|
10
|
+
const errorSymbol = redBright('ERROR');
|
|
11
|
+
export class Logger {
|
|
12
|
+
/**
|
|
13
|
+
* 0: silent 1: info 2: verbose 3: debug
|
|
14
|
+
*/
|
|
15
|
+
static #logLevel = 0;
|
|
16
|
+
static #loggerInstance;
|
|
17
|
+
static #nonBlockingLogPrinted = false;
|
|
18
|
+
static debug = debug('vs-cli');
|
|
19
|
+
static get #spinner() {
|
|
20
|
+
return this.#loggerInstance && this.#loggerInstance.#_spinner;
|
|
21
|
+
}
|
|
22
|
+
static get isInteractive() {
|
|
23
|
+
return Boolean(process.stderr.isTTY &&
|
|
24
|
+
process.env.TERM !== 'dumb' &&
|
|
25
|
+
!('CI' in process.env) &&
|
|
26
|
+
!debug.enabled('vs-cli') &&
|
|
27
|
+
// Prevent stream output in docker container so that not to spawn process
|
|
28
|
+
!isInContainer());
|
|
29
|
+
}
|
|
30
|
+
static startLogging(text) {
|
|
31
|
+
if (this.#logLevel === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!this.isInteractive) {
|
|
35
|
+
this.logInfo(text);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (this.#loggerInstance) {
|
|
39
|
+
this.#loggerInstance.#_spinner.text = text;
|
|
40
|
+
return this.#loggerInstance;
|
|
41
|
+
}
|
|
42
|
+
this.#loggerInstance = new Logger();
|
|
43
|
+
this.#loggerInstance.#_spinner.start(text);
|
|
44
|
+
return this.#loggerInstance;
|
|
45
|
+
}
|
|
46
|
+
static suspendLogging(text) {
|
|
47
|
+
if (this.#logLevel === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!this.#spinner || !this.isInteractive) {
|
|
51
|
+
this.logInfo(text);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const currentMsg = this.#spinner?.text;
|
|
55
|
+
this.logUpdate(currentMsg);
|
|
56
|
+
this.#spinner.stop(`${infoSymbol} ${text}\n`);
|
|
57
|
+
return {
|
|
58
|
+
[Symbol.dispose]() {
|
|
59
|
+
if (Logger.isInteractive) {
|
|
60
|
+
console.log('');
|
|
61
|
+
Logger.#spinner?.start(currentMsg);
|
|
62
|
+
Logger.#nonBlockingLogPrinted = true;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
static log(...messages) {
|
|
68
|
+
if (this.#logLevel < 1) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(...messages);
|
|
72
|
+
}
|
|
73
|
+
static logUpdate(...messages) {
|
|
74
|
+
if (!this.#spinner || !this.isInteractive) {
|
|
75
|
+
this.logInfo(...messages);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.#spinner.stop(this.#nonBlockingLogPrinted
|
|
79
|
+
? undefined
|
|
80
|
+
: `${infoSymbol} ${this.#spinner.text}`);
|
|
81
|
+
this.#spinner.start(messages.join(' '));
|
|
82
|
+
this.#nonBlockingLogPrinted = false;
|
|
83
|
+
}
|
|
84
|
+
static #nonBlockingLog(fallback, message) {
|
|
85
|
+
if (!this.#spinner || !this.isInteractive) {
|
|
86
|
+
if (isInContainer()) {
|
|
87
|
+
message = `${gray('[Docker]')} ${message}`;
|
|
88
|
+
}
|
|
89
|
+
this.#logLevel >= 3 ? this.debug(message) : fallback(message);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.logUpdate(this.#spinner.text);
|
|
93
|
+
this.#nonBlockingLogPrinted = true;
|
|
94
|
+
this.#spinner.stop(message);
|
|
95
|
+
this.#spinner.start();
|
|
96
|
+
}
|
|
97
|
+
static logSuccess(...messages) {
|
|
98
|
+
if (this.#logLevel < 1) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.#nonBlockingLog(console.log, `${successSymbol} ${messages.join(' ')}`);
|
|
102
|
+
}
|
|
103
|
+
static logError(...messages) {
|
|
104
|
+
if (this.#logLevel < 1) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.#nonBlockingLog(console.error, `${errorSymbol} ${red(messages.join(' '))}`);
|
|
108
|
+
}
|
|
109
|
+
static logWarn(...messages) {
|
|
110
|
+
if (this.#logLevel < 1) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.#nonBlockingLog(console.warn, `${warnSymbol} ${yellow(messages.join(' '))}`);
|
|
114
|
+
}
|
|
115
|
+
static logInfo(...messages) {
|
|
116
|
+
if (this.#logLevel < 1) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.#nonBlockingLog(console.info, `${infoSymbol} ${messages.join(' ')}`);
|
|
120
|
+
}
|
|
121
|
+
static logVerbose(...messages) {
|
|
122
|
+
if (this.#logLevel < 2) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.#nonBlockingLog(console.log, messages.join(' '));
|
|
126
|
+
}
|
|
127
|
+
static setLogLevel(level) {
|
|
128
|
+
if (!level) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.#logLevel = {
|
|
132
|
+
silent: 0,
|
|
133
|
+
info: 1,
|
|
134
|
+
verbose: 2,
|
|
135
|
+
debug: 3,
|
|
136
|
+
}[level];
|
|
137
|
+
if (this.#logLevel >= 3) {
|
|
138
|
+
debug.enable('vs-cli');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
#_spinner;
|
|
142
|
+
constructor() {
|
|
143
|
+
this.#_spinner = yoctoSpinner({
|
|
144
|
+
spinner: {
|
|
145
|
+
frames: isUnicodeSupported
|
|
146
|
+
? ['▁▁╱ ', '▁║▁ ', '╲▁▁ ', '▁▁▁ ', '▁▁▁ ', '▁▁▁ ']
|
|
147
|
+
: ['- ', '\\ ', '| ', '/ '],
|
|
148
|
+
interval: 80,
|
|
149
|
+
},
|
|
150
|
+
color: 'gray',
|
|
151
|
+
});
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
[Symbol.dispose]() {
|
|
155
|
+
this.#_spinner.stop(Logger.#nonBlockingLogPrinted
|
|
156
|
+
? undefined
|
|
157
|
+
: `${infoSymbol} ${this.#_spinner.text}`);
|
|
158
|
+
Logger.#loggerInstance = undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,YAAyB,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,UAAU,EACV,IAAI,EACJ,WAAW,EACX,GAAG,EACH,SAAS,EACT,MAAM,EACN,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,kBAAkB,GAC7B,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CACtD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAC9B,CAAC;AAEF,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AACtC,MAAM,aAAa,GAAG,WAAW,C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zB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,KAAK,CAAC;CACpB,
|
|
1
|
+
{"version":3,"file":"epub.d.ts","sourceRoot":"","sources":["../../src/output/epub.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAKV,mBAAmB,EAEpB,MAAM,iCAAiC,CAAC;AAqFzC,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,aAAa,EACb,QAAQ,EACR,eAAe,EACf,MAAM,EACN,WAAW,GACZ,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,KAAK,CAAC;CACpB,iBAsOA"}
|
package/dist/output/epub.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import archiver from 'archiver';
|
|
2
2
|
import { lookup as lookupLanguage } from 'bcp-47-match';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
3
|
import { XMLBuilder } from 'fast-xml-parser';
|
|
5
4
|
import { copy, remove } from 'fs-extra/esm';
|
|
6
5
|
import GithubSlugger from 'github-slugger';
|
|
@@ -11,8 +10,9 @@ import upath from 'upath';
|
|
|
11
10
|
import { v4 as uuid } from 'uuid';
|
|
12
11
|
import serializeToXml from 'w3c-xmlserializer';
|
|
13
12
|
import { EPUB_CONTAINER_XML, EPUB_LANDMARKS_COVER_ENTRY, EPUB_LANDMARKS_TITLE, EPUB_LANDMARKS_TOC_ENTRY, EPUB_NS, TOC_TITLE, XML_DECLARATION, } from '../const.js';
|
|
13
|
+
import { Logger } from '../logger.js';
|
|
14
14
|
import { getJsdomFromUrlOrFile, parsePageListDocument, parseTocDocument, } from '../processor/html.js';
|
|
15
|
-
import { DetailError,
|
|
15
|
+
import { DetailError, useTmpDirectory } from '../util.js';
|
|
16
16
|
const TOC_ID = 'toc';
|
|
17
17
|
const LANDMARKS_ID = 'landmarks';
|
|
18
18
|
const PAGELIST_ID = 'page-list';
|
|
@@ -60,7 +60,7 @@ const appendManifestProperty = (entry, newProperty) => {
|
|
|
60
60
|
: newProperty;
|
|
61
61
|
};
|
|
62
62
|
export async function exportEpub({ webpubDir, entryHtmlFile, manifest, relManifestPath, target, epubVersion, }) {
|
|
63
|
-
debug('Export EPUB', {
|
|
63
|
+
Logger.debug('Export EPUB', {
|
|
64
64
|
webpubDir,
|
|
65
65
|
entryHtmlFile,
|
|
66
66
|
relManifestPath,
|
|
@@ -128,7 +128,7 @@ export async function exportEpub({ webpubDir, entryHtmlFile, manifest, relManife
|
|
|
128
128
|
.flat()
|
|
129
129
|
.flatMap((v) => (v ? (typeof v === 'string' ? { url: v } : v) : []));
|
|
130
130
|
if (!tocHtml) {
|
|
131
|
-
logWarn(
|
|
131
|
+
Logger.logWarn('No table of contents document was found. for EPUB output, we recommend to enable `toc` option in your Vivliostyle config file to generate a table of contents document.');
|
|
132
132
|
tocHtml =
|
|
133
133
|
htmlFiles.find((f) => f === entryHtmlRelPath) || readingOrder[0].url;
|
|
134
134
|
}
|
|
@@ -184,10 +184,10 @@ export async function exportEpub({ webpubDir, entryHtmlFile, manifest, relManife
|
|
|
184
184
|
return parseResult;
|
|
185
185
|
};
|
|
186
186
|
const processResult = {};
|
|
187
|
-
debug(`Transpiling ToC HTML to XHTML: ${tocHtml}`);
|
|
187
|
+
Logger.debug(`Transpiling ToC HTML to XHTML: ${tocHtml}`);
|
|
188
188
|
processResult[tocHtml] = await processHtml(tocHtml);
|
|
189
189
|
for (const target of htmlFiles.filter((f) => f !== tocHtml)) {
|
|
190
|
-
debug(`Transpiling HTML to XHTML: ${target}`);
|
|
190
|
+
Logger.debug(`Transpiling HTML to XHTML: ${target}`);
|
|
191
191
|
processResult[target] = await processHtml(target);
|
|
192
192
|
}
|
|
193
193
|
// Process ToC document
|
|
@@ -227,7 +227,7 @@ export async function exportEpub({ webpubDir, entryHtmlFile, manifest, relManife
|
|
|
227
227
|
// META-INF/container.xml
|
|
228
228
|
fs.writeFileSync(upath.join(tmpDir, 'META-INF/container.xml'), EPUB_CONTAINER_XML, 'utf8');
|
|
229
229
|
// EPUB/content.opf
|
|
230
|
-
debug(`Generating content.opf`);
|
|
230
|
+
Logger.debug(`Generating content.opf`);
|
|
231
231
|
fs.writeFileSync(upath.join(tmpDir, 'EPUB/content.opf'), buildEpubPackageDocument({
|
|
232
232
|
epubVersion,
|
|
233
233
|
uid,
|
|
@@ -245,7 +245,7 @@ async function writeAsXhtml(dom, absPath) {
|
|
|
245
245
|
}
|
|
246
246
|
async function transpileHtmlToXhtml({ target, contextDir, }) {
|
|
247
247
|
const absPath = upath.join(contextDir, target);
|
|
248
|
-
const
|
|
248
|
+
const dom = await getJsdomFromUrlOrFile({ src: absPath });
|
|
249
249
|
const { document } = dom.window;
|
|
250
250
|
// `xmlns` will be supplied in later serialization process
|
|
251
251
|
document.documentElement.removeAttribute('xmlns');
|
|
@@ -287,7 +287,7 @@ async function processTocDocument({ dom, target, contextDir, readingOrder, docLa
|
|
|
287
287
|
nav.setAttribute('epub:type', 'toc');
|
|
288
288
|
}
|
|
289
289
|
else {
|
|
290
|
-
debug(`Generating toc nav element: ${target}`);
|
|
290
|
+
Logger.debug(`Generating toc nav element: ${target}`);
|
|
291
291
|
const nav = document.createElement('nav');
|
|
292
292
|
nav.setAttribute('id', TOC_ID);
|
|
293
293
|
nav.setAttribute('role', 'doc-toc');
|
|
@@ -304,7 +304,9 @@ async function processTocDocument({ dom, target, contextDir, readingOrder, docLa
|
|
|
304
304
|
for (const content of readingOrder) {
|
|
305
305
|
let name = normalizeLocalizableString(content.name, docLanguages);
|
|
306
306
|
if (!name) {
|
|
307
|
-
const
|
|
307
|
+
const dom = await getJsdomFromUrlOrFile({
|
|
308
|
+
src: upath.join(contextDir, changeExtname(content.url, '.xhtml')),
|
|
309
|
+
});
|
|
308
310
|
name = dom.window.document.title;
|
|
309
311
|
}
|
|
310
312
|
const li = document.createElement('li');
|
|
@@ -317,10 +319,10 @@ async function processTocDocument({ dom, target, contextDir, readingOrder, docLa
|
|
|
317
319
|
}
|
|
318
320
|
nav.appendChild(ol);
|
|
319
321
|
document.body.appendChild(nav);
|
|
320
|
-
debug('Generated toc nav element', nav.outerHTML);
|
|
322
|
+
Logger.debug('Generated toc nav element', nav.outerHTML);
|
|
321
323
|
}
|
|
322
324
|
if (landmarks.length > 0) {
|
|
323
|
-
debug(`Generating landmark nav element: ${target}`);
|
|
325
|
+
Logger.debug(`Generating landmark nav element: ${target}`);
|
|
324
326
|
const nav = document.createElement('nav');
|
|
325
327
|
nav.setAttribute('epub:type', 'landmarks');
|
|
326
328
|
nav.setAttribute('id', LANDMARKS_ID);
|
|
@@ -340,7 +342,7 @@ async function processTocDocument({ dom, target, contextDir, readingOrder, docLa
|
|
|
340
342
|
}
|
|
341
343
|
nav.appendChild(ol);
|
|
342
344
|
document.body.appendChild(nav);
|
|
343
|
-
debug('Generated landmark nav element', nav.outerHTML);
|
|
345
|
+
Logger.debug('Generated landmark nav element', nav.outerHTML);
|
|
344
346
|
}
|
|
345
347
|
}
|
|
346
348
|
// Remove a publication manifest linked to ToC html.
|
|
@@ -475,14 +477,14 @@ function buildEpubPackageDocument({ epubVersion, manifest, uid, docTitle, docLan
|
|
|
475
477
|
});
|
|
476
478
|
}
|
|
477
479
|
async function compressEpub({ target, sourceDir, }) {
|
|
478
|
-
debug(`Compressing EPUB: ${target}`);
|
|
480
|
+
Logger.debug(`Compressing EPUB: ${target}`);
|
|
479
481
|
const output = fs.createWriteStream(target);
|
|
480
482
|
const archive = archiver('zip', {
|
|
481
483
|
zlib: { level: 9 }, // Compression level
|
|
482
484
|
});
|
|
483
485
|
return new Promise((resolve, reject) => {
|
|
484
486
|
output.on('close', () => {
|
|
485
|
-
debug(`Compressed EPUB: ${target}`);
|
|
487
|
+
Logger.debug(`Compressed EPUB: ${target}`);
|
|
486
488
|
resolve();
|
|
487
489
|
});
|
|
488
490
|
output.on('error', reject);
|