@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
package/dist/server.js
CHANGED
|
@@ -1,75 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import handler from 'serve-handler';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { URL } from 'node:url';
|
|
4
3
|
import upath from 'upath';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_viewerServer = _viewerServer || (await launchServer(viewerRoot));
|
|
15
|
-
const viewerUrl = new URL('http://localhost');
|
|
16
|
-
viewerUrl.port = `${_viewerServer.port}`;
|
|
17
|
-
viewerUrl.pathname = '/lib/index.html';
|
|
18
|
-
return viewerUrl;
|
|
19
|
-
})()
|
|
20
|
-
: (() => {
|
|
21
|
-
const viewerUrl = new URL('file://');
|
|
22
|
-
viewerUrl.pathname = upath.join(viewerRoot, 'lib/index.html');
|
|
23
|
-
return viewerUrl;
|
|
24
|
-
})());
|
|
25
|
-
const inputUrl = isUrlString(option.input)
|
|
26
|
-
? new URL(option.input)
|
|
27
|
-
: pathToFileURL(option.input);
|
|
28
|
-
const sourceUrl = await (async () => {
|
|
29
|
-
if (inputUrl.protocol === 'file:' &&
|
|
30
|
-
(option.httpServer ||
|
|
31
|
-
// Use http server because http viewer cannot access to file protocol
|
|
32
|
-
(option.viewer && /^https?:/i.test(option.viewer)))) {
|
|
33
|
-
_sourceServer =
|
|
34
|
-
_sourceServer || (await launchServer(option.workspaceDir));
|
|
35
|
-
const sourceUrl = new URL('http://localhost');
|
|
36
|
-
sourceUrl.port = `${_sourceServer.port}`;
|
|
37
|
-
sourceUrl.pathname = upath.relative(option.workspaceDir, fileURLToPath(inputUrl));
|
|
38
|
-
return sourceUrl;
|
|
39
|
-
}
|
|
40
|
-
return inputUrl;
|
|
41
|
-
})();
|
|
42
|
-
return {
|
|
43
|
-
viewerFullUrl: getViewerFullUrl(option, {
|
|
44
|
-
viewerUrl,
|
|
45
|
-
sourceUrl,
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export function teardownServer() {
|
|
50
|
-
if (_viewerServer) {
|
|
51
|
-
_viewerServer.server.close();
|
|
52
|
-
_viewerServer = undefined;
|
|
53
|
-
}
|
|
54
|
-
if (_sourceServer) {
|
|
55
|
-
_sourceServer.server.close();
|
|
56
|
-
_sourceServer = undefined;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export function getViewerFullUrl({ size, cropMarks, bleed, cropOffset, css, style, userStyle, singleDoc, quick, viewerParam, }, { viewerUrl, sourceUrl }) {
|
|
4
|
+
import { createServer, mergeConfig as mergeViteConfig, preview, } from 'vite';
|
|
5
|
+
import { prepareViteConfig } from './config/vite.js';
|
|
6
|
+
import { EMPTY_DATA_URI, VIEWER_ROOT_PATH } from './const.js';
|
|
7
|
+
import { getDefaultEpubOpfPath, isValidUri, openEpub } from './util.js';
|
|
8
|
+
import { vsBrowserPlugin } from './vite/vite-plugin-browser.js';
|
|
9
|
+
import { vsDevServerPlugin } from './vite/vite-plugin-dev-server.js';
|
|
10
|
+
import { vsStaticServePlugin } from './vite/vite-plugin-static-serve.js';
|
|
11
|
+
import { vsViewerPlugin } from './vite/vite-plugin-viewer.js';
|
|
12
|
+
export function getViewerParams(src, { size, cropMarks, bleed, cropOffset, css, customStyle, customUserStyle, singleDoc, quick, viewerParam, }) {
|
|
60
13
|
const pageSizeValue = size && ('format' in size ? size.format : `${size.width} ${size.height}`);
|
|
61
14
|
function escapeParam(url) {
|
|
62
15
|
return url.replace(/&/g, '%26');
|
|
63
16
|
}
|
|
64
|
-
let viewerParams =
|
|
65
|
-
? '' // open Viewer start page
|
|
66
|
-
: `src=${escapeParam(sourceUrl.href)}`;
|
|
17
|
+
let viewerParams = src ? `src=${escapeParam(src)}` : '';
|
|
67
18
|
viewerParams += `&bookMode=${!singleDoc}&renderAllPages=${!quick}`;
|
|
68
|
-
if (
|
|
69
|
-
viewerParams += `&style=${escapeParam(
|
|
19
|
+
if (customStyle) {
|
|
20
|
+
viewerParams += `&style=${escapeParam(customStyle)}`;
|
|
70
21
|
}
|
|
71
|
-
if (
|
|
72
|
-
viewerParams += `&userStyle=${escapeParam(
|
|
22
|
+
if (customUserStyle) {
|
|
23
|
+
viewerParams += `&userStyle=${escapeParam(customUserStyle)}`;
|
|
73
24
|
}
|
|
74
25
|
if (pageSizeValue || cropMarks || bleed || cropOffset || css) {
|
|
75
26
|
let pageStyle = '@page{';
|
|
@@ -96,46 +47,69 @@ export function getViewerFullUrl({ size, cropMarks, bleed, cropOffset, css, styl
|
|
|
96
47
|
// append additional viewer parameters
|
|
97
48
|
viewerParams += `&${viewerParam}`;
|
|
98
49
|
}
|
|
99
|
-
return
|
|
50
|
+
return viewerParams;
|
|
100
51
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
52
|
+
export async function getSourceUrl({ viewerInput, base, workspaceDir, rootUrl, }) {
|
|
53
|
+
let input;
|
|
54
|
+
switch (viewerInput.type) {
|
|
55
|
+
case 'webpub':
|
|
56
|
+
input = viewerInput.manifestPath;
|
|
57
|
+
break;
|
|
58
|
+
case 'webbook':
|
|
59
|
+
input = viewerInput.webbookEntryUrl;
|
|
60
|
+
break;
|
|
61
|
+
case 'epub-opf':
|
|
62
|
+
input = viewerInput.epubOpfPath;
|
|
63
|
+
break;
|
|
64
|
+
case 'epub': {
|
|
65
|
+
if (!fs.existsSync(viewerInput.epubTmpOutputDir)) {
|
|
66
|
+
await openEpub(viewerInput.epubPath, viewerInput.epubTmpOutputDir);
|
|
67
|
+
}
|
|
68
|
+
input = getDefaultEpubOpfPath(viewerInput.epubTmpOutputDir);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
default:
|
|
72
|
+
input = viewerInput;
|
|
73
|
+
}
|
|
74
|
+
return (isValidUri(input)
|
|
75
|
+
? new URL(input)
|
|
76
|
+
: new URL(upath.posix.join(base, upath.relative(workspaceDir, input)), rootUrl)).href;
|
|
77
|
+
}
|
|
78
|
+
export async function getViewerFullUrl({ viewerInput, base, workspaceDir, rootUrl, viewer, ...config }) {
|
|
79
|
+
const viewerUrl = viewer
|
|
80
|
+
? new URL(viewer)
|
|
81
|
+
: new URL(`${VIEWER_ROOT_PATH}/index.html`, rootUrl);
|
|
82
|
+
const sourceUrl = await getSourceUrl({
|
|
83
|
+
viewerInput,
|
|
84
|
+
base,
|
|
85
|
+
workspaceDir,
|
|
86
|
+
rootUrl,
|
|
125
87
|
});
|
|
126
|
-
|
|
88
|
+
const viewerParams = getViewerParams(sourceUrl === EMPTY_DATA_URI
|
|
89
|
+
? undefined // open Viewer start page
|
|
90
|
+
: sourceUrl, config);
|
|
91
|
+
viewerUrl.hash = viewerParams;
|
|
92
|
+
return viewerUrl.href;
|
|
127
93
|
}
|
|
128
|
-
async function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
|
|
94
|
+
export async function createViteServer({ config, inlineOptions: options, mode, }) {
|
|
95
|
+
let { viteConfig } = await prepareViteConfig({ ...config, mode });
|
|
96
|
+
viteConfig = mergeViteConfig(viteConfig, {
|
|
97
|
+
clearScreen: false,
|
|
98
|
+
configFile: false,
|
|
99
|
+
appType: 'custom',
|
|
100
|
+
plugins: [
|
|
101
|
+
vsDevServerPlugin({ config, options }),
|
|
102
|
+
vsViewerPlugin({ config, options }),
|
|
103
|
+
vsBrowserPlugin({ config, options }),
|
|
104
|
+
vsStaticServePlugin({ config, options }),
|
|
105
|
+
],
|
|
106
|
+
server: viteConfig.server ?? config.server,
|
|
139
107
|
});
|
|
108
|
+
if (mode === 'preview') {
|
|
109
|
+
return await createServer(viteConfig);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return await preview(viteConfig);
|
|
113
|
+
}
|
|
140
114
|
}
|
|
141
115
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,YAAY,EAEZ,WAAW,IAAI,eAAe,EAC9B,OAAO,GAGR,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,Y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,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,UAAU,GAAG,eAAe,CAAC,UAAU,EAAE;QACvC,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,KAAK;QACjB,OAAO,EAAE,QAAQ;QACjB,OAAO,EAAE;YACP,iBAAiB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YACtC,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YACnC,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YACpC,mBAAmB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;SACzC;QACD,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM;KACpB,CAAC,CAAC;IAE1B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;AACH,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
1
|
-
import debugConstructor from 'debug';
|
|
2
1
|
import fs from 'node:fs';
|
|
3
2
|
import { BaseIssue } from 'valibot';
|
|
4
3
|
import type { PublicationManifest } from './schema/publication.schema.js';
|
|
5
|
-
export declare const debug: debugConstructor.Debugger;
|
|
6
4
|
export declare const cwd: string;
|
|
7
5
|
export declare let beforeExitHandlers: (() => void)[];
|
|
8
6
|
export declare function runExitHandlers(): void;
|
|
9
|
-
export declare function setLogLevel(level?: 'silent' | 'info' | 'verbose' | 'debug'): void;
|
|
10
|
-
/**
|
|
11
|
-
* @returns A function that stops logging
|
|
12
|
-
*/
|
|
13
|
-
export declare function startLogging(text?: string): typeof stopLogging;
|
|
14
|
-
/**
|
|
15
|
-
* @returns A function that starts logging again
|
|
16
|
-
*/
|
|
17
|
-
export declare function suspendLogging(text?: string, symbol?: string): (text?: string) => void;
|
|
18
|
-
declare function stopLogging(text?: string, symbol?: string): void;
|
|
19
|
-
export declare function log(...obj: any): void;
|
|
20
|
-
export declare function logUpdate(...obj: string[]): void;
|
|
21
|
-
export declare function logSuccess(...obj: string[]): void;
|
|
22
|
-
export declare function logError(...obj: string[]): void;
|
|
23
|
-
export declare function logWarn(...obj: string[]): void;
|
|
24
|
-
export declare function logInfo(...obj: string[]): void;
|
|
25
7
|
export declare class DetailError extends Error {
|
|
26
8
|
detail: string | undefined;
|
|
27
9
|
constructor(message: string | undefined, detail: string | undefined);
|
|
28
10
|
}
|
|
29
|
-
export declare function
|
|
11
|
+
export declare function getFormattedError(err: Error): string;
|
|
12
|
+
export declare function gracefulError(err: Error): void;
|
|
30
13
|
export declare function readJSON(path: string): any;
|
|
31
14
|
export declare function statFileSync(filePath: string, { errorMessage, }?: {
|
|
32
15
|
errorMessage?: string;
|
|
33
16
|
}): fs.Stats;
|
|
34
17
|
export declare function inflateZip(filePath: string, dest: string): Promise<void>;
|
|
35
18
|
export declare function useTmpDirectory(): Promise<[string, () => void]>;
|
|
36
|
-
export declare function touchTmpFile(path: string):
|
|
19
|
+
export declare function touchTmpFile(path: string): () => void;
|
|
37
20
|
export declare function pathEquals(path1: string, path2: string): boolean;
|
|
38
21
|
export declare function pathContains(parentPath: string, childPath: string): boolean;
|
|
39
|
-
export declare function
|
|
40
|
-
export declare function
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
43
|
-
|
|
44
|
-
epubOpfPath: string;
|
|
45
|
-
deleteEpub: () => void;
|
|
46
|
-
}>;
|
|
22
|
+
export declare function isValidUri(str: string): boolean;
|
|
23
|
+
export declare function isInContainer(): boolean;
|
|
24
|
+
export declare function openEpub(epubPath: string, tmpDir: string): Promise<() => void>;
|
|
25
|
+
export declare function getDefaultEpubOpfPath(epubDir: string): string;
|
|
26
|
+
export declare function getEpubRootDir(epubOpfPath: string): string | undefined;
|
|
47
27
|
export declare const assertPubManifestSchema: (obj: unknown) => obj is PublicationManifest;
|
|
48
28
|
export declare function parseJsonc(rawJsonc: string): string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any | {
|
|
49
29
|
[property: string]: string | number | boolean | any | any | null;
|
|
@@ -71,5 +51,5 @@ export declare function parseJsonc(rawJsonc: string): string | number | boolean
|
|
|
71
51
|
[property: string]: string | number | boolean | any | any | null;
|
|
72
52
|
} | null;
|
|
73
53
|
export declare function prettifySchemaError(rawJsonc: string, issues: BaseIssue<unknown>[]): string;
|
|
74
|
-
export
|
|
54
|
+
export declare function writeFileIfChanged(filePath: string, content: Buffer): void;
|
|
75
55
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,MAAM,SAAS,CAAC;AAKzB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAOpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,eAAO,MAAM,GAAG,QAAiC,CAAC;AAElD,eAAO,IAAI,kBAAkB,EAAE,CAAC,MAAM,IAAI,CAAC,EAAO,CAAC;AACnD,wBAAgB,eAAe,SAQ9B;AA2BD,qBAAa,WAAY,SAAQ,KAAK;IAG3B,MAAM,EAAE,MAAM,GAAG,SAAS;gBADjC,OAAO,EAAE,MAAM,GAAG,SAAS,EACpB,MAAM,EAAE,MAAM,GAAG,SAAS;CAIpC;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,KAAK,UAI3C;AAED,wBAAgB,aAAa,CAAC,GA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dist/util.js
CHANGED
|
@@ -2,28 +2,18 @@ import { codeFrameColumns } from '@babel/code-frame';
|
|
|
2
2
|
import { evaluate, parse, } from '@humanwhocodes/momoa';
|
|
3
3
|
import AjvModule from 'ajv';
|
|
4
4
|
import AjvFormatsModule from 'ajv-formats';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import debugConstructor from 'debug';
|
|
7
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
8
6
|
import { removeSync } from 'fs-extra/esm';
|
|
9
7
|
import StreamZip from 'node-stream-zip';
|
|
10
8
|
import fs from 'node:fs';
|
|
11
9
|
import readline from 'node:readline';
|
|
12
10
|
import util from 'node:util';
|
|
13
|
-
import oraConstructor from 'ora';
|
|
14
|
-
import portfinder from 'portfinder';
|
|
15
11
|
import tmp from 'tmp';
|
|
16
12
|
import upath from 'upath';
|
|
13
|
+
import { gray, red, redBright } from 'yoctocolors';
|
|
14
|
+
import { Logger } from './logger.js';
|
|
17
15
|
import { publicationSchema, publicationSchemas, } from './schema/pub-manifest.js';
|
|
18
|
-
export const debug = debugConstructor('vs-cli');
|
|
19
16
|
export const cwd = upath.normalize(process.cwd());
|
|
20
|
-
const ora = oraConstructor({
|
|
21
|
-
color: 'blue',
|
|
22
|
-
spinner: 'circle',
|
|
23
|
-
// Prevent stream output in docker so that not to spawn process
|
|
24
|
-
// In other environment, check TTY context
|
|
25
|
-
isEnabled: checkContainerEnvironment() ? false : undefined,
|
|
26
|
-
});
|
|
27
17
|
export let beforeExitHandlers = [];
|
|
28
18
|
export function runExitHandlers() {
|
|
29
19
|
while (beforeExitHandlers.length) {
|
|
@@ -58,120 +48,6 @@ if (process.platform === 'win32') {
|
|
|
58
48
|
rl.close();
|
|
59
49
|
});
|
|
60
50
|
}
|
|
61
|
-
/**
|
|
62
|
-
* 0: silent
|
|
63
|
-
* 1: info
|
|
64
|
-
* 2: verbose
|
|
65
|
-
* 3: debug
|
|
66
|
-
*/
|
|
67
|
-
let logLevel = 0;
|
|
68
|
-
export function setLogLevel(level) {
|
|
69
|
-
if (!level) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
logLevel = {
|
|
73
|
-
silent: 0,
|
|
74
|
-
info: 1,
|
|
75
|
-
verbose: 2,
|
|
76
|
-
debug: 3,
|
|
77
|
-
}[level];
|
|
78
|
-
if (logLevel >= 3) {
|
|
79
|
-
debugConstructor.enable('vs-cli');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @returns A function that stops logging
|
|
84
|
-
*/
|
|
85
|
-
export function startLogging(text) {
|
|
86
|
-
if (logLevel < 1) {
|
|
87
|
-
return () => { };
|
|
88
|
-
}
|
|
89
|
-
// If text is not set, erase previous log with space character
|
|
90
|
-
ora.start(text ?? ' ');
|
|
91
|
-
return stopLogging;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* @returns A function that starts logging again
|
|
95
|
-
*/
|
|
96
|
-
export function suspendLogging(text, symbol) {
|
|
97
|
-
if (logLevel < 1) {
|
|
98
|
-
return () => { };
|
|
99
|
-
}
|
|
100
|
-
const { isSpinning, text: previousLoggingText } = ora;
|
|
101
|
-
stopLogging(text, symbol);
|
|
102
|
-
return (text) => {
|
|
103
|
-
isSpinning ? startLogging(text || previousLoggingText) : ora.info(text);
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
// NOTE: This function is intended to be used in conjunction with startLogging function,
|
|
107
|
-
// so it is not intentionally exported.
|
|
108
|
-
function stopLogging(text, symbol) {
|
|
109
|
-
if (logLevel < 1) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!text) {
|
|
113
|
-
ora.stop();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
ora.stopAndPersist({ text, symbol });
|
|
117
|
-
}
|
|
118
|
-
export function log(...obj) {
|
|
119
|
-
if (logLevel < 1) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
console.log(...obj);
|
|
123
|
-
}
|
|
124
|
-
export function logUpdate(...obj) {
|
|
125
|
-
if (logLevel < 1) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (ora.isSpinning) {
|
|
129
|
-
ora.text = obj.join(' ');
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
ora.info(obj.join(' '));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
export function logSuccess(...obj) {
|
|
136
|
-
if (logLevel < 1) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const { isSpinning, text } = ora;
|
|
140
|
-
ora.succeed(obj.join(' '));
|
|
141
|
-
if (isSpinning) {
|
|
142
|
-
startLogging(text);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
export function logError(...obj) {
|
|
146
|
-
if (logLevel < 1) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const { isSpinning, text } = ora;
|
|
150
|
-
ora.fail(obj.join(' '));
|
|
151
|
-
if (isSpinning) {
|
|
152
|
-
startLogging(text);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
export function logWarn(...obj) {
|
|
156
|
-
if (logLevel < 1) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const { isSpinning, text } = ora;
|
|
160
|
-
ora.warn(obj.join(' '));
|
|
161
|
-
if (isSpinning) {
|
|
162
|
-
startLogging(text);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
export function logInfo(...obj) {
|
|
166
|
-
if (logLevel < 1) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
const { isSpinning, text } = ora;
|
|
170
|
-
ora.info(obj.join(' '));
|
|
171
|
-
if (isSpinning) {
|
|
172
|
-
startLogging(text);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
51
|
export class DetailError extends Error {
|
|
176
52
|
detail;
|
|
177
53
|
constructor(message, detail) {
|
|
@@ -179,20 +55,15 @@ export class DetailError extends Error {
|
|
|
179
55
|
this.detail = detail;
|
|
180
56
|
}
|
|
181
57
|
}
|
|
58
|
+
export function getFormattedError(err) {
|
|
59
|
+
return err instanceof DetailError
|
|
60
|
+
? `${err.message}\n${err.detail}`
|
|
61
|
+
: err.stack || `${err.message}`;
|
|
62
|
+
}
|
|
182
63
|
export function gracefulError(err) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
? err.stack.replace(/^Error:/, chalk.red.bold('Error:'))
|
|
187
|
-
: `${chalk.red.bold('Error:')} ${err.message}`;
|
|
188
|
-
if (ora.isSpinning) {
|
|
189
|
-
ora.fail(message);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
console.error(message);
|
|
193
|
-
}
|
|
194
|
-
console.log(chalk.gray(`
|
|
195
|
-
If you think this is a bug, please report at https://github.com/vivliostyle/vivliostyle-cli/issues`));
|
|
64
|
+
console.log(`${redBright('ERROR')} ${getFormattedError(err)}
|
|
65
|
+
|
|
66
|
+
${gray('If you think this is a bug, please report at https://github.com/vivliostyle/vivliostyle-cli/issues')}`);
|
|
196
67
|
process.exit(1);
|
|
197
68
|
}
|
|
198
69
|
export function readJSON(path) {
|
|
@@ -227,7 +98,7 @@ export async function inflateZip(filePath, dest) {
|
|
|
227
98
|
zip.on('ready', async () => {
|
|
228
99
|
await util.promisify(zip.extract)(null, dest);
|
|
229
100
|
await util.promisify(zip.close)();
|
|
230
|
-
debug(`Unzipped ${filePath} to ${dest}`);
|
|
101
|
+
Logger.debug(`Unzipped ${filePath} to ${dest}`);
|
|
231
102
|
res();
|
|
232
103
|
});
|
|
233
104
|
}
|
|
@@ -242,26 +113,26 @@ export function useTmpDirectory() {
|
|
|
242
113
|
if (err) {
|
|
243
114
|
return rej(err);
|
|
244
115
|
}
|
|
245
|
-
debug(`Created the temporary directory: ${path}`);
|
|
116
|
+
Logger.debug(`Created the temporary directory: ${path}`);
|
|
246
117
|
const callback = () => {
|
|
247
118
|
// clear function doesn't work well?
|
|
248
119
|
// clear();
|
|
249
120
|
removeSync(path);
|
|
250
|
-
debug(`Removed the temporary directory: ${path}`);
|
|
121
|
+
Logger.debug(`Removed the temporary directory: ${path}`);
|
|
251
122
|
};
|
|
252
123
|
beforeExitHandlers.push(callback);
|
|
253
124
|
res([path, callback]);
|
|
254
125
|
});
|
|
255
126
|
});
|
|
256
127
|
}
|
|
257
|
-
export
|
|
128
|
+
export function touchTmpFile(path) {
|
|
258
129
|
fs.mkdirSync(upath.dirname(path), { recursive: true });
|
|
259
130
|
// Create file if not exist
|
|
260
131
|
fs.closeSync(fs.openSync(path, 'a'));
|
|
261
|
-
debug(`Created the temporary file: ${path}`);
|
|
132
|
+
Logger.debug(`Created the temporary file: ${path}`);
|
|
262
133
|
const callback = () => {
|
|
263
134
|
removeSync(path);
|
|
264
|
-
debug(`Removed the temporary file: ${path}`);
|
|
135
|
+
Logger.debug(`Removed the temporary file: ${path}`);
|
|
265
136
|
};
|
|
266
137
|
beforeExitHandlers.push(callback);
|
|
267
138
|
return callback;
|
|
@@ -273,27 +144,46 @@ export function pathContains(parentPath, childPath) {
|
|
|
273
144
|
const rel = upath.relative(parentPath, childPath);
|
|
274
145
|
return rel !== '' && !rel.startsWith('..');
|
|
275
146
|
}
|
|
276
|
-
export function
|
|
147
|
+
export function isValidUri(str) {
|
|
277
148
|
return /^(https?|file|data):/i.test(str);
|
|
278
149
|
}
|
|
279
|
-
export function
|
|
280
|
-
portfinder.basePort = 13000;
|
|
281
|
-
return portfinder.getPortPromise();
|
|
282
|
-
}
|
|
283
|
-
export function checkContainerEnvironment() {
|
|
150
|
+
export function isInContainer() {
|
|
284
151
|
return fs.existsSync('/opt/vivliostyle-cli/.vs-cli-version');
|
|
285
152
|
}
|
|
286
|
-
export async function
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const
|
|
153
|
+
export async function openEpub(epubPath, tmpDir) {
|
|
154
|
+
await inflateZip(epubPath, tmpDir);
|
|
155
|
+
Logger.debug(`Created the temporary EPUB directory: ${tmpDir}`);
|
|
156
|
+
const deleteEpub = () => {
|
|
157
|
+
fs.rmSync(tmpDir, { recursive: true });
|
|
158
|
+
Logger.debug(`Removed the temporary EPUB directory: ${tmpDir}`);
|
|
159
|
+
};
|
|
160
|
+
beforeExitHandlers.push(deleteEpub);
|
|
161
|
+
return deleteEpub;
|
|
162
|
+
}
|
|
163
|
+
export function getDefaultEpubOpfPath(epubDir) {
|
|
164
|
+
const containerXmlPath = upath.join(epubDir, 'META-INF/container.xml');
|
|
290
165
|
const xmlParser = new XMLParser({
|
|
291
166
|
ignoreAttributes: false,
|
|
292
167
|
});
|
|
293
168
|
const { container } = xmlParser.parse(fs.readFileSync(containerXmlPath, 'utf8'));
|
|
294
169
|
const rootfile = [container.rootfiles.rootfile].flat()[0]; // Only supports a default rendition
|
|
295
|
-
const epubOpfPath = upath.join(
|
|
296
|
-
return
|
|
170
|
+
const epubOpfPath = upath.join(epubDir, rootfile['@_full-path']);
|
|
171
|
+
return epubOpfPath;
|
|
172
|
+
}
|
|
173
|
+
export function getEpubRootDir(epubOpfPath) {
|
|
174
|
+
function traverse(dir) {
|
|
175
|
+
const files = fs.readdirSync(dir);
|
|
176
|
+
if (files.includes('META-INF') &&
|
|
177
|
+
pathEquals(epubOpfPath, getDefaultEpubOpfPath(dir))) {
|
|
178
|
+
return dir;
|
|
179
|
+
}
|
|
180
|
+
const next = upath.dirname(dir);
|
|
181
|
+
if (pathEquals(dir, next)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
return traverse(next);
|
|
185
|
+
}
|
|
186
|
+
return traverse(upath.dirname(epubOpfPath));
|
|
297
187
|
}
|
|
298
188
|
// FIXME: https://github.com/ajv-validator/ajv/issues/2047
|
|
299
189
|
const Ajv = AjvModule.default;
|
|
@@ -359,7 +249,7 @@ export function prettifySchemaError(rawJsonc, issues) {
|
|
|
359
249
|
break;
|
|
360
250
|
}
|
|
361
251
|
}
|
|
362
|
-
let message = `${
|
|
252
|
+
let message = `${red(issuesTraversed.at(-1).message)}`;
|
|
363
253
|
if (jsonValue) {
|
|
364
254
|
message += `\n${codeFrameColumns(rawJsonc, jsonValue.loc, {
|
|
365
255
|
highlightCode: true,
|
|
@@ -367,4 +257,10 @@ export function prettifySchemaError(rawJsonc, issues) {
|
|
|
367
257
|
}
|
|
368
258
|
return message;
|
|
369
259
|
}
|
|
260
|
+
export function writeFileIfChanged(filePath, content) {
|
|
261
|
+
if (!fs.existsSync(filePath) || !fs.readFileSync(filePath).equals(content)) {
|
|
262
|
+
fs.mkdirSync(upath.dirname(filePath), { recursive: true });
|
|
263
|
+
fs.writeFileSync(filePath, content);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
370
266
|
//# sourceMappingURL=util.js.map
|