@vivliostyle/cli 9.0.0-next.3 → 9.0.0-next.4

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.
Files changed (186) hide show
  1. package/dist/chunk-BIEQXUOY.js +50 -0
  2. package/dist/chunk-DMARNPN5.js +1073 -0
  3. package/dist/chunk-DMGAKSPH.js +590 -0
  4. package/dist/{core/init.js → chunk-E7QOXL6M.js} +39 -27
  5. package/dist/chunk-EX7EA34F.js +64 -0
  6. package/dist/chunk-LASMQBPP.js +85 -0
  7. package/dist/chunk-QC3BOE2G.js +74 -0
  8. package/dist/chunk-VBEHGS67.js +4990 -0
  9. package/dist/chunk-WX6JHPSL.js +16 -0
  10. package/dist/chunk-Y3ETBU5J.js +54 -0
  11. package/dist/cli.d.ts +0 -2
  12. package/dist/cli.js +17 -18
  13. package/dist/commands/build.d.ts +2 -2
  14. package/dist/commands/build.js +165 -17
  15. package/dist/commands/init.d.ts +2 -2
  16. package/dist/commands/init.js +35 -12
  17. package/dist/commands/preview.d.ts +2 -2
  18. package/dist/commands/preview.js +98 -12
  19. package/dist/config/schema.d.ts +2332 -2325
  20. package/dist/config/schema.js +50 -588
  21. package/dist/index.d.ts +116 -7
  22. package/dist/index.js +38 -42
  23. package/dist/node-modules.d.ts +21 -0
  24. package/dist/node-modules.js +9 -0
  25. package/dist/vite-adapter.d.ts +8 -2
  26. package/dist/vite-adapter.js +11 -43
  27. package/package.json +32 -13
  28. package/dist/browser.d.ts +0 -19
  29. package/dist/browser.d.ts.map +0 -1
  30. package/dist/browser.js +0 -154
  31. package/dist/browser.js.map +0 -1
  32. package/dist/cli.d.ts.map +0 -1
  33. package/dist/cli.js.map +0 -1
  34. package/dist/commands/build.d.ts.map +0 -1
  35. package/dist/commands/build.js.map +0 -1
  36. package/dist/commands/build.parser.d.ts +0 -3
  37. package/dist/commands/build.parser.d.ts.map +0 -1
  38. package/dist/commands/build.parser.js +0 -104
  39. package/dist/commands/build.parser.js.map +0 -1
  40. package/dist/commands/cli-flags.d.ts +0 -42
  41. package/dist/commands/cli-flags.d.ts.map +0 -1
  42. package/dist/commands/cli-flags.js +0 -58
  43. package/dist/commands/cli-flags.js.map +0 -1
  44. package/dist/commands/init.d.ts.map +0 -1
  45. package/dist/commands/init.js.map +0 -1
  46. package/dist/commands/init.parser.d.ts +0 -3
  47. package/dist/commands/init.parser.d.ts.map +0 -1
  48. package/dist/commands/init.parser.js +0 -17
  49. package/dist/commands/init.parser.js.map +0 -1
  50. package/dist/commands/preview.d.ts.map +0 -1
  51. package/dist/commands/preview.js.map +0 -1
  52. package/dist/commands/preview.parser.d.ts +0 -3
  53. package/dist/commands/preview.parser.d.ts.map +0 -1
  54. package/dist/commands/preview.parser.js +0 -52
  55. package/dist/commands/preview.parser.js.map +0 -1
  56. package/dist/config/load.d.ts +0 -4
  57. package/dist/config/load.d.ts.map +0 -1
  58. package/dist/config/load.js +0 -75
  59. package/dist/config/load.js.map +0 -1
  60. package/dist/config/merge.d.ts +0 -4
  61. package/dist/config/merge.d.ts.map +0 -1
  62. package/dist/config/merge.js +0 -59
  63. package/dist/config/merge.js.map +0 -1
  64. package/dist/config/resolve.d.ts +0 -205
  65. package/dist/config/resolve.d.ts.map +0 -1
  66. package/dist/config/resolve.js +0 -770
  67. package/dist/config/resolve.js.map +0 -1
  68. package/dist/config/schema.d.ts.map +0 -1
  69. package/dist/config/schema.js.map +0 -1
  70. package/dist/config/vite.d.ts +0 -6
  71. package/dist/config/vite.d.ts.map +0 -1
  72. package/dist/config/vite.js +0 -49
  73. package/dist/config/vite.js.map +0 -1
  74. package/dist/const.d.ts +0 -20
  75. package/dist/const.d.ts.map +0 -1
  76. package/dist/const.js +0 -41
  77. package/dist/const.js.map +0 -1
  78. package/dist/container.d.ts +0 -21
  79. package/dist/container.d.ts.map +0 -1
  80. package/dist/container.js +0 -175
  81. package/dist/container.js.map +0 -1
  82. package/dist/core/build.d.ts +0 -3
  83. package/dist/core/build.d.ts.map +0 -1
  84. package/dist/core/build.js +0 -168
  85. package/dist/core/build.js.map +0 -1
  86. package/dist/core/init.d.ts +0 -3
  87. package/dist/core/init.d.ts.map +0 -1
  88. package/dist/core/init.js.map +0 -1
  89. package/dist/core/preview.d.ts +0 -4
  90. package/dist/core/preview.d.ts.map +0 -1
  91. package/dist/core/preview.js +0 -114
  92. package/dist/core/preview.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/logger.d.ts +0 -30
  96. package/dist/logger.d.ts.map +0 -1
  97. package/dist/logger.js +0 -172
  98. package/dist/logger.js.map +0 -1
  99. package/dist/output/epub.d.ts +0 -10
  100. package/dist/output/epub.d.ts.map +0 -1
  101. package/dist/output/epub.js +0 -505
  102. package/dist/output/epub.js.map +0 -1
  103. package/dist/output/pdf-postprocess.d.ts +0 -30
  104. package/dist/output/pdf-postprocess.d.ts.map +0 -1
  105. package/dist/output/pdf-postprocess.js +0 -270
  106. package/dist/output/pdf-postprocess.js.map +0 -1
  107. package/dist/output/pdf.d.ts +0 -6
  108. package/dist/output/pdf.d.ts.map +0 -1
  109. package/dist/output/pdf.js +0 -200
  110. package/dist/output/pdf.js.map +0 -1
  111. package/dist/output/webbook.d.ts +0 -45
  112. package/dist/output/webbook.d.ts.map +0 -1
  113. package/dist/output/webbook.js +0 -413
  114. package/dist/output/webbook.js.map +0 -1
  115. package/dist/processor/compile.d.ts +0 -30
  116. package/dist/processor/compile.d.ts.map +0 -1
  117. package/dist/processor/compile.js +0 -348
  118. package/dist/processor/compile.js.map +0 -1
  119. package/dist/processor/html.d.ts +0 -107
  120. package/dist/processor/html.d.ts.map +0 -1
  121. package/dist/processor/html.js +0 -494
  122. package/dist/processor/html.js.map +0 -1
  123. package/dist/processor/markdown.d.ts +0 -12
  124. package/dist/processor/markdown.d.ts.map +0 -1
  125. package/dist/processor/markdown.js +0 -23
  126. package/dist/processor/markdown.js.map +0 -1
  127. package/dist/processor/theme.d.ts +0 -4
  128. package/dist/processor/theme.d.ts.map +0 -1
  129. package/dist/processor/theme.js +0 -41
  130. package/dist/processor/theme.js.map +0 -1
  131. package/dist/schema/pub-manifest.d.ts +0 -4
  132. package/dist/schema/pub-manifest.d.ts.map +0 -1
  133. package/dist/schema/pub-manifest.js +0 -41
  134. package/dist/schema/pub-manifest.js.map +0 -1
  135. package/dist/schema/publication.schema.d.ts +0 -104
  136. package/dist/schema/publication.schema.d.ts.map +0 -1
  137. package/dist/schema/publication.schema.js +0 -8
  138. package/dist/schema/publication.schema.js.map +0 -1
  139. package/dist/server.d.ts +0 -20
  140. package/dist/server.d.ts.map +0 -1
  141. package/dist/server.js +0 -126
  142. package/dist/server.js.map +0 -1
  143. package/dist/util.d.ts +0 -55
  144. package/dist/util.d.ts.map +0 -1
  145. package/dist/util.js +0 -274
  146. package/dist/util.js.map +0 -1
  147. package/dist/vite/plugin-util.d.ts +0 -6
  148. package/dist/vite/plugin-util.d.ts.map +0 -1
  149. package/dist/vite/plugin-util.js +0 -18
  150. package/dist/vite/plugin-util.js.map +0 -1
  151. package/dist/vite/vite-plugin-browser.d.ts +0 -8
  152. package/dist/vite/vite-plugin-browser.d.ts.map +0 -1
  153. package/dist/vite/vite-plugin-browser.js +0 -54
  154. package/dist/vite/vite-plugin-browser.js.map +0 -1
  155. package/dist/vite/vite-plugin-dev-server.d.ts +0 -8
  156. package/dist/vite/vite-plugin-dev-server.d.ts.map +0 -1
  157. package/dist/vite/vite-plugin-dev-server.js +0 -270
  158. package/dist/vite/vite-plugin-dev-server.js.map +0 -1
  159. package/dist/vite/vite-plugin-static-serve.d.ts +0 -8
  160. package/dist/vite/vite-plugin-static-serve.d.ts.map +0 -1
  161. package/dist/vite/vite-plugin-static-serve.js +0 -31
  162. package/dist/vite/vite-plugin-static-serve.js.map +0 -1
  163. package/dist/vite/vite-plugin-viewer.d.ts +0 -8
  164. package/dist/vite/vite-plugin-viewer.d.ts.map +0 -1
  165. package/dist/vite/vite-plugin-viewer.js +0 -52
  166. package/dist/vite/vite-plugin-viewer.js.map +0 -1
  167. package/dist/vite-adapter.d.ts.map +0 -1
  168. package/dist/vite-adapter.js.map +0 -1
  169. package/schemas/pub-manifest/README.md +0 -5
  170. package/schemas/pub-manifest/module/ItemList.schema.json +0 -32
  171. package/schemas/pub-manifest/module/bcp.schema.json +0 -7
  172. package/schemas/pub-manifest/module/context.schema.json +0 -62
  173. package/schemas/pub-manifest/module/contributor-object.schema.json +0 -42
  174. package/schemas/pub-manifest/module/contributor.schema.json +0 -26
  175. package/schemas/pub-manifest/module/date.schema.json +0 -7
  176. package/schemas/pub-manifest/module/duration.schema.json +0 -7
  177. package/schemas/pub-manifest/module/item-lists.schema.json +0 -16
  178. package/schemas/pub-manifest/module/language.schema.json +0 -16
  179. package/schemas/pub-manifest/module/link.schema.json +0 -60
  180. package/schemas/pub-manifest/module/localizable-object.schema.json +0 -15
  181. package/schemas/pub-manifest/module/localizable.schema.json +0 -26
  182. package/schemas/pub-manifest/module/resource.categorization.schema.json +0 -31
  183. package/schemas/pub-manifest/module/strings.schema.json +0 -9
  184. package/schemas/pub-manifest/module/url.schema.json +0 -7
  185. package/schemas/pub-manifest/module/urls.schema.json +0 -18
  186. package/schemas/pub-manifest/publication.schema.json +0 -123
@@ -1,770 +0,0 @@
1
- import { VFM } from '@vivliostyle/vfm';
2
- import { lookup as mime } from 'mime-types';
3
- import fs from 'node:fs';
4
- import { pathToFileURL } from 'node:url';
5
- import npa from 'npm-package-arg';
6
- import upath from 'upath';
7
- import { getExecutableBrowserPath } from '../browser.js';
8
- import { COVER_HTML_FILENAME, COVER_HTML_IMAGE_ALT, EPUB_OUTPUT_VERSION, MANIFEST_FILENAME, TOC_FILENAME, TOC_TITLE, } from '../const.js';
9
- import { CONTAINER_IMAGE, CONTAINER_LOCAL_HOSTNAME } from '../container.js';
10
- import { Logger } from '../logger.js';
11
- import { readMarkdownMetadata } from '../processor/markdown.js';
12
- import { cwd as defaultCwd, getEpubRootDir, isInContainer, isValidUri, pathContains, pathEquals, readJSON, statFileSync, touchTmpFile, } from '../util.js';
13
- export const manuscriptMediaTypes = [
14
- 'text/markdown',
15
- 'text/html',
16
- 'application/xhtml+xml',
17
- ];
18
- const DEFAULT_ASSET_EXTENSIONS = [
19
- 'png',
20
- 'jpg',
21
- 'jpeg',
22
- 'svg',
23
- 'gif',
24
- 'webp',
25
- 'apng',
26
- 'ttf',
27
- 'otf',
28
- 'woff',
29
- 'woff2',
30
- ];
31
- function isManuscriptMediaType(mediaType) {
32
- return !!(mediaType && manuscriptMediaTypes.includes(mediaType));
33
- }
34
- export function isWebPubConfig(config) {
35
- return config.viewerInput.type === 'webpub';
36
- }
37
- export function isWebbookConfig(config) {
38
- return config.viewerInput.type === 'webbook';
39
- }
40
- export function parsePackageName(specifier, cwd) {
41
- try {
42
- let result = npa(specifier, cwd);
43
- // #373: Relative path specifiers may be assumed as shorthand of hosted git
44
- // (ex: foo/bar -> github:foo/bar)
45
- if (result.type === 'git' && result.saveSpec?.startsWith('github:')) {
46
- result = npa(`file:${specifier}`, cwd);
47
- }
48
- return result;
49
- }
50
- catch (error) {
51
- return null;
52
- }
53
- }
54
- // parse theme locator
55
- export function parseTheme({ theme, context, workspaceDir, themesDir, }) {
56
- const { specifier, import: importPath } = typeof theme === 'string' ? { specifier: theme, import: undefined } : theme;
57
- // url
58
- if (isValidUri(specifier)) {
59
- return {
60
- type: 'uri',
61
- name: upath.basename(specifier),
62
- location: specifier,
63
- };
64
- }
65
- // bare .css file
66
- const stylePath = upath.resolve(context, specifier);
67
- if (fs.existsSync(stylePath) && stylePath.endsWith('.css')) {
68
- const sourceRelPath = upath.relative(context, stylePath);
69
- return {
70
- type: 'file',
71
- name: upath.basename(specifier),
72
- source: stylePath,
73
- location: upath.resolve(workspaceDir, sourceRelPath),
74
- };
75
- }
76
- // node_modules, local pkg
77
- const parsed = parsePackageName(specifier, context);
78
- if (!parsed) {
79
- throw new Error(`Invalid package name: ${specifier}`);
80
- }
81
- // To security reason, Vivliostyle CLI disallow other than npm registry or local file as download source
82
- // TODO: Add option that user can allow an unofficial registry explicitly
83
- if (!parsed.registry && parsed.type !== 'directory') {
84
- throw new Error(`This package specifier is not allowed: ${specifier}`);
85
- }
86
- let name = parsed.name;
87
- let resolvedSpecifier = specifier;
88
- if (parsed.type === 'directory' && parsed.fetchSpec) {
89
- const pkgJsonPath = upath.join(parsed.fetchSpec, 'package.json');
90
- if (fs.existsSync(pkgJsonPath)) {
91
- const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
92
- name = packageJson.name;
93
- resolvedSpecifier = parsed.fetchSpec;
94
- }
95
- }
96
- if (!name) {
97
- throw new Error(`Could not determine the package name: ${specifier}`);
98
- }
99
- return {
100
- type: 'package',
101
- name,
102
- specifier: resolvedSpecifier,
103
- location: upath.join(themesDir, 'node_modules', name),
104
- importPath,
105
- };
106
- }
107
- function parsePageSize(size) {
108
- const [width, height, ...others] = `${size}`.split(',');
109
- if (!width || others.length) {
110
- throw new Error(`Cannot parse size: ${size}`);
111
- }
112
- else if (width && height) {
113
- return {
114
- width,
115
- height,
116
- };
117
- }
118
- else {
119
- return {
120
- format: width,
121
- };
122
- }
123
- }
124
- function parseFileMetadata({ contentType, sourcePath, workspaceDir, themesDir, }) {
125
- const sourceDir = upath.dirname(sourcePath);
126
- let title;
127
- let themes;
128
- if (contentType === 'text/markdown') {
129
- const metadata = readMarkdownMetadata(sourcePath);
130
- title = metadata.title;
131
- if (metadata.vfm?.theme && themesDir) {
132
- themes = [metadata.vfm.theme]
133
- .flat()
134
- .filter((entry) => !!entry && (typeof entry === 'string' || typeof entry === 'object'))
135
- .map((theme) => parseTheme({
136
- theme,
137
- context: sourceDir,
138
- workspaceDir,
139
- themesDir,
140
- }));
141
- }
142
- }
143
- else {
144
- const content = fs.readFileSync(sourcePath, 'utf8');
145
- title = content.match(/<title>([^<]*)<\/title>/)?.[1] || undefined;
146
- }
147
- return { title, themes };
148
- }
149
- export function resolveTaskConfig(config, options) {
150
- const context = options.cwd ?? defaultCwd;
151
- Logger.debug('resolveTaskConfig > context %s', context);
152
- const entryContextDir = config.entryContext
153
- ? upath.resolve(context, config.entryContext)
154
- : context;
155
- const language = config.language;
156
- const readingProgression = config.readingProgression;
157
- const size = config.size ? parsePageSize(config.size) : undefined;
158
- const cropMarks = options.cropMarks ?? false;
159
- const bleed = options.bleed;
160
- const cropOffset = options.cropOffset;
161
- const css = options.css;
162
- const customStyle = options.style &&
163
- (isValidUri(options.style)
164
- ? options.style
165
- : pathToFileURL(options.style).href);
166
- const customUserStyle = options.userStyle &&
167
- (isValidUri(options.userStyle)
168
- ? options.userStyle
169
- : pathToFileURL(options.userStyle).href);
170
- const singleDoc = options.singleDoc ?? false;
171
- const quick = options.quick ?? false;
172
- const temporaryFilePrefix = config.temporaryFilePrefix ?? `.vs-${Date.now()}.`;
173
- const documentProcessorFactory = config?.documentProcessor ?? VFM;
174
- const vfmOptions = {
175
- ...config?.vfm,
176
- hardLineBreaks: config?.vfm?.hardLineBreaks ?? false,
177
- disableFormatHtml: config?.vfm?.disableFormatHtml ?? false,
178
- };
179
- const timeout = config.timeout ?? 120_000; // 2 minutes
180
- const sandbox = options.sandbox ?? false;
181
- const browserType = config.browser ?? 'chromium';
182
- const proxyServer = options.proxyServer ?? process.env.HTTP_PROXY ?? undefined;
183
- const proxy = proxyServer
184
- ? {
185
- server: proxyServer,
186
- bypass: options.proxyBypass ?? process.env.NOPROXY ?? undefined,
187
- username: options.proxyUser,
188
- password: options.proxyPass,
189
- }
190
- : undefined;
191
- const executableBrowser = options.executableBrowser ?? getExecutableBrowserPath(browserType);
192
- const image = config.image ?? CONTAINER_IMAGE;
193
- const viewer = config.viewer ?? undefined;
194
- const viewerParam = config.viewerParam ?? undefined;
195
- const logLevel = options.logLevel ?? 'silent';
196
- const ignoreHttpsErrors = options.ignoreHttpsErrors ?? false;
197
- const base = config.base ?? '/vivliostyle';
198
- const staticRoutes = config.static ?? {};
199
- const viteConfig = config.vite;
200
- const viteConfigFile = config.viteConfigFile ?? true;
201
- const outputs = (() => {
202
- const defaultPdfOptions = {
203
- format: 'pdf',
204
- renderMode: 'local',
205
- preflight: config.pressReady ? 'press-ready' : undefined,
206
- preflightOption: [],
207
- };
208
- if (config.output) {
209
- return config.output.map((target) => {
210
- const outputPath = upath.resolve(context, target.path);
211
- const format = target.format;
212
- switch (format) {
213
- case 'pdf':
214
- return {
215
- ...defaultPdfOptions,
216
- ...target,
217
- format,
218
- path: outputPath,
219
- };
220
- case 'epub':
221
- return {
222
- ...target,
223
- format,
224
- path: outputPath,
225
- version: EPUB_OUTPUT_VERSION,
226
- };
227
- case 'webpub':
228
- return {
229
- ...target,
230
- format,
231
- path: outputPath,
232
- };
233
- default:
234
- return format;
235
- }
236
- });
237
- }
238
- // Outputs a pdf file if any output configuration is not set
239
- const filename = config.title ? `${config.title}.pdf` : 'output.pdf';
240
- return [
241
- {
242
- ...defaultPdfOptions,
243
- path: upath.resolve(context, filename),
244
- },
245
- ];
246
- })();
247
- const { server, rootUrl } = (() => {
248
- let host = config.server?.host ?? false;
249
- const port = config.server?.port ?? 13000;
250
- if (outputs.some((target) => target.format === 'pdf' && target.renderMode === 'docker')) {
251
- // Docker render mode requires wildcard host to allow access from the container
252
- host = true;
253
- }
254
- const rootHostname = isInContainer()
255
- ? CONTAINER_LOCAL_HOSTNAME
256
- : !host
257
- ? 'localhost'
258
- : host === true
259
- ? '0.0.0.0'
260
- : host;
261
- return {
262
- server: {
263
- host,
264
- port,
265
- proxy: config.server?.proxy ?? {},
266
- },
267
- rootUrl: `http://${rootHostname}:${port}`,
268
- };
269
- })();
270
- const cover = config.cover && {
271
- src: upath.resolve(entryContextDir, config.cover.src),
272
- name: config.cover.name || COVER_HTML_IMAGE_ALT,
273
- };
274
- const copyAsset = {
275
- includes: config.copyAsset?.includes ?? config.includeAssets ?? [],
276
- excludes: config.copyAsset?.excludes ?? [],
277
- fileExtensions: [
278
- ...new Set([
279
- ...DEFAULT_ASSET_EXTENSIONS,
280
- ...(config.copyAsset?.includeFileExtensions ?? []),
281
- ]),
282
- ].filter((ext) => !(config.copyAsset?.excludeFileExtensions ?? []).includes(ext)),
283
- };
284
- const themeIndexes = new Set();
285
- const projectConfig = !options.config && options.input
286
- ? resolveSingleInputConfig({
287
- config,
288
- input: options.input,
289
- context,
290
- temporaryFilePrefix,
291
- themeIndexes,
292
- base,
293
- })
294
- : resolveComposedProjectConfig({
295
- config,
296
- context,
297
- entryContextDir,
298
- outputs,
299
- temporaryFilePrefix,
300
- themeIndexes,
301
- rootUrl,
302
- cover,
303
- });
304
- // Check overwrites
305
- for (const output of outputs) {
306
- const relPath = upath.relative(context, output.path);
307
- if (pathContains(output.path, entryContextDir) ||
308
- pathEquals(output.path, entryContextDir)) {
309
- throw new Error(`The output path is set to "${relPath}", but this will overwrite the original manuscript file. Please specify a different path.`);
310
- }
311
- if (pathContains(output.path, projectConfig.workspaceDir) ||
312
- pathEquals(output.path, projectConfig.workspaceDir)) {
313
- throw new Error(`The output path is set to "${relPath}", but this will overwrite the working directory of Vivliostyle. Please specify a different path.`);
314
- }
315
- }
316
- const { entries, workspaceDir } = projectConfig;
317
- const duplicatedTarget = entries.find((v1, i) => entries.findLastIndex((v2) => v1.target === v2.target) !== i)?.target;
318
- if (duplicatedTarget) {
319
- const sourceFile = entries.find((entry) => entry.target === duplicatedTarget && entry.source?.type === 'file')?.source;
320
- throw new Error(`The output path "${upath.relative(workspaceDir, duplicatedTarget)}" will overwrite existing content.` +
321
- (sourceFile
322
- ? ` Please choose a different name for the source file: ${sourceFile.pathname}`
323
- : ''));
324
- }
325
- const resolvedConfig = {
326
- ...projectConfig,
327
- context,
328
- entryContextDir,
329
- outputs,
330
- themeIndexes,
331
- copyAsset,
332
- temporaryFilePrefix,
333
- size,
334
- cropMarks,
335
- bleed,
336
- cropOffset,
337
- css,
338
- customStyle,
339
- customUserStyle,
340
- singleDoc,
341
- quick,
342
- language,
343
- readingProgression,
344
- documentProcessorFactory,
345
- vfmOptions,
346
- cover,
347
- timeout,
348
- sandbox,
349
- executableBrowser,
350
- browserType,
351
- proxy,
352
- image,
353
- viewer,
354
- viewerParam,
355
- logLevel,
356
- ignoreHttpsErrors,
357
- base,
358
- server,
359
- static: staticRoutes,
360
- rootUrl,
361
- viteConfig,
362
- viteConfigFile,
363
- };
364
- return resolvedConfig;
365
- }
366
- function resolveSingleInputConfig({ config, input, context, temporaryFilePrefix, themeIndexes, base, }) {
367
- Logger.debug('entering single entry config mode');
368
- let sourcePath;
369
- let workspaceDir;
370
- const inputFormat = input.format;
371
- const title = config?.title;
372
- const author = config?.author;
373
- const entries = [];
374
- const exportAliases = [];
375
- if (isValidUri(input.entry)) {
376
- sourcePath = input.entry;
377
- workspaceDir = context;
378
- }
379
- else {
380
- sourcePath = upath.resolve(context, input.entry);
381
- // Check file exists
382
- statFileSync(sourcePath);
383
- switch (input.format) {
384
- case 'webbook':
385
- case 'markdown':
386
- case 'pub-manifest':
387
- case 'epub':
388
- workspaceDir = upath.dirname(sourcePath);
389
- break;
390
- case 'epub-opf': {
391
- const rootDir = getEpubRootDir(sourcePath);
392
- if (!rootDir) {
393
- throw new Error(`Could not determine the EPUB root directory for the OPF file: ${sourcePath}`);
394
- }
395
- workspaceDir = rootDir;
396
- break;
397
- }
398
- default:
399
- return input.format;
400
- }
401
- }
402
- const themesDir = upath.resolve(workspaceDir, 'themes');
403
- if (input.format === 'markdown') {
404
- // Single input file; create temporary file
405
- const contentType = 'text/markdown';
406
- const metadata = parseFileMetadata({
407
- contentType,
408
- sourcePath,
409
- workspaceDir,
410
- });
411
- const target = upath
412
- .resolve(workspaceDir, `${temporaryFilePrefix}${upath.basename(sourcePath)}`)
413
- .replace(/\.md$/, '.html');
414
- touchTmpFile(target);
415
- const themes = metadata.themes ??
416
- config.theme?.map((theme) => parseTheme({
417
- theme,
418
- context,
419
- workspaceDir,
420
- themesDir,
421
- })) ??
422
- [];
423
- themes.forEach((t) => themeIndexes.add(t));
424
- entries.push({
425
- contentType,
426
- source: {
427
- type: 'file',
428
- pathname: sourcePath,
429
- contentType,
430
- },
431
- target,
432
- title: metadata.title,
433
- themes,
434
- });
435
- exportAliases.push({
436
- source: target,
437
- target: upath.resolve(upath.dirname(target), upath.basename(sourcePath).replace(/\.md$/, '.html')),
438
- });
439
- }
440
- let fallbackTitle;
441
- let viewerInput;
442
- if (inputFormat === 'markdown') {
443
- // create temporary manifest file
444
- const manifestPath = upath.resolve(workspaceDir, `${temporaryFilePrefix}${MANIFEST_FILENAME}`);
445
- touchTmpFile(manifestPath);
446
- exportAliases.push({
447
- source: manifestPath,
448
- target: upath.resolve(workspaceDir, MANIFEST_FILENAME),
449
- });
450
- fallbackTitle =
451
- entries.length === 1 && entries[0].title
452
- ? entries[0].title
453
- : upath.basename(sourcePath);
454
- viewerInput = {
455
- type: 'webpub',
456
- manifestPath,
457
- needToGenerateManifest: true,
458
- };
459
- }
460
- else if (inputFormat === 'webbook') {
461
- let webbookEntryUrl;
462
- let webbookPath;
463
- if (isValidUri(sourcePath)) {
464
- const url = new URL(sourcePath);
465
- // Ensures trailing slash or explicit HTML extensions
466
- if (/^https?:/i.test(url.protocol) &&
467
- !url.pathname.endsWith('/') &&
468
- !/\.html?$/.test(url.pathname)) {
469
- url.pathname = `${url.pathname}/`;
470
- }
471
- webbookEntryUrl = url.href;
472
- }
473
- else {
474
- const rootFileUrl = pathToFileURL(workspaceDir).href;
475
- const urlPath = pathToFileURL(sourcePath).href.slice(rootFileUrl.length);
476
- webbookEntryUrl = `${base}${urlPath}`;
477
- webbookPath = sourcePath;
478
- }
479
- viewerInput = { type: 'webbook', webbookEntryUrl, webbookPath };
480
- }
481
- else if (inputFormat === 'pub-manifest') {
482
- viewerInput = {
483
- type: 'webpub',
484
- manifestPath: sourcePath,
485
- needToGenerateManifest: false,
486
- };
487
- }
488
- else if (inputFormat === 'epub-opf') {
489
- viewerInput = { type: 'epub-opf', epubOpfPath: sourcePath };
490
- }
491
- else if (inputFormat === 'epub') {
492
- viewerInput = {
493
- type: 'epub',
494
- epubPath: sourcePath,
495
- epubTmpOutputDir: upath.join(sourcePath, `../${temporaryFilePrefix}${upath.basename(sourcePath)}`),
496
- };
497
- }
498
- else {
499
- return inputFormat;
500
- }
501
- return {
502
- workspaceDir,
503
- themesDir,
504
- entries,
505
- input: {
506
- format: inputFormat,
507
- entry: sourcePath,
508
- },
509
- viewerInput,
510
- exportAliases,
511
- title: title || fallbackTitle,
512
- author,
513
- };
514
- }
515
- function resolveComposedProjectConfig({ config, context, entryContextDir, outputs, temporaryFilePrefix, themeIndexes, rootUrl, cover, }) {
516
- Logger.debug('entering composed project config mode');
517
- const workspaceDir = upath.resolve(context, config.workspaceDir ?? '.vivliostyle');
518
- const themesDir = upath.resolve(workspaceDir, 'themes');
519
- const pkgJsonPath = upath.resolve(entryContextDir, 'package.json');
520
- const pkgJson = fs.existsSync(pkgJsonPath)
521
- ? readJSON(pkgJsonPath)
522
- : undefined;
523
- if (pkgJson) {
524
- Logger.debug('located package.json path', pkgJsonPath);
525
- }
526
- const exportAliases = [];
527
- const rootThemes = config.theme?.map((theme) => parseTheme({
528
- theme,
529
- context,
530
- workspaceDir,
531
- themesDir,
532
- })) ?? [];
533
- rootThemes.forEach((t) => themeIndexes.add(t));
534
- const tocConfig = {
535
- tocTitle: config.toc?.title ?? config?.tocTitle ?? TOC_TITLE,
536
- target: upath.resolve(workspaceDir, config.toc?.htmlPath ?? TOC_FILENAME),
537
- sectionDepth: config.toc?.sectionDepth ?? 0,
538
- transform: {
539
- transformDocumentList: config.toc?.transformDocumentList,
540
- transformSectionList: config.toc?.transformSectionList,
541
- },
542
- };
543
- const coverHtml = config.cover &&
544
- ('htmlPath' in config.cover && !config.cover.htmlPath
545
- ? undefined
546
- : upath.resolve(workspaceDir, config.cover?.htmlPath || COVER_HTML_FILENAME));
547
- const ensureCoverImage = (src) => {
548
- const absPath = src && upath.resolve(entryContextDir, src);
549
- if (absPath) {
550
- statFileSync(absPath, {
551
- errorMessage: 'Specified cover image does not exist',
552
- });
553
- }
554
- return absPath;
555
- };
556
- const projectTitle = config?.title ?? pkgJson?.name;
557
- const projectAuthor = config?.author ?? pkgJson?.author;
558
- const isContentsEntry = (entry) => entry.rel === 'contents';
559
- const isCoverEntry = (entry) => entry.rel === 'cover';
560
- const isArticleEntry = (entry) => !isContentsEntry(entry) && !isCoverEntry(entry);
561
- function parseEntry(entry) {
562
- const getInputInfo = (entryPath) => {
563
- if (/^https?:/.test(entryPath)) {
564
- return {
565
- type: 'uri',
566
- href: entryPath,
567
- rootDir: upath.join(workspaceDir, new URL(entryPath).host),
568
- };
569
- }
570
- else if (entryPath.startsWith('/')) {
571
- return {
572
- type: 'uri',
573
- href: `${rootUrl}${entryPath}`,
574
- rootDir: upath.join(workspaceDir, 'localhost'),
575
- };
576
- }
577
- const pathname = upath.resolve(entryContextDir, entryPath);
578
- statFileSync(pathname);
579
- const contentType = mime(pathname);
580
- if (!isManuscriptMediaType(contentType)) {
581
- throw new Error(`Invalid manuscript type ${contentType} detected: ${entry}`);
582
- }
583
- return {
584
- type: 'file',
585
- pathname,
586
- contentType,
587
- metadata: parseFileMetadata({
588
- contentType,
589
- sourcePath: pathname,
590
- workspaceDir,
591
- themesDir,
592
- }),
593
- };
594
- };
595
- const getTargetPath = (source) => {
596
- switch (source.type) {
597
- case 'file':
598
- return upath.resolve(workspaceDir, upath
599
- .relative(entryContextDir, source.pathname)
600
- .replace(/\.md$/, '.html'));
601
- case 'uri': {
602
- const url = new URL(source.href, 'a://dummy');
603
- let pathname = url.pathname;
604
- if (!/\.html?$/.test(pathname)) {
605
- pathname = `${pathname.replace(/\/$/, '')}/index.html`;
606
- }
607
- return upath.join(source.rootDir, pathname);
608
- }
609
- default:
610
- return source;
611
- }
612
- };
613
- if ((isContentsEntry(entry) || isCoverEntry(entry)) && entry.path) {
614
- const source = upath.resolve(entryContextDir, entry.path);
615
- try {
616
- statFileSync(source);
617
- /* v8 ignore next 10 */
618
- }
619
- catch (error) {
620
- // For backward compatibility, we allow missing files then assume that option as `output` field.
621
- Logger.logWarn(`The "path" option is set but the file does not exist: ${source}\nMaybe you want to set the "output" field instead.`);
622
- entry.output = entry.path;
623
- entry.path = undefined;
624
- }
625
- }
626
- if (isContentsEntry(entry)) {
627
- const inputInfo = entry.path ? getInputInfo(entry.path) : undefined;
628
- const { metadata, ...template } = inputInfo || {};
629
- let target = entry.output
630
- ? upath.resolve(workspaceDir, entry.output)
631
- : inputInfo && getTargetPath(inputInfo);
632
- const themes = entry.theme
633
- ? [entry.theme].flat().map((theme) => parseTheme({
634
- theme,
635
- context,
636
- workspaceDir,
637
- themesDir,
638
- }))
639
- : (metadata?.themes ?? [...rootThemes]);
640
- themes.forEach((t) => themeIndexes.add(t));
641
- target ??= tocConfig.target;
642
- if (inputInfo?.type === 'file' &&
643
- pathEquals(inputInfo.pathname, target)) {
644
- const tmpPath = upath.resolve(upath.dirname(target), `${temporaryFilePrefix}${upath.basename(target)}`);
645
- exportAliases.push({ source: tmpPath, target });
646
- touchTmpFile(tmpPath);
647
- target = tmpPath;
648
- }
649
- const parsedEntry = {
650
- rel: 'contents',
651
- ...tocConfig,
652
- target,
653
- title: entry.title ?? metadata?.title ?? projectTitle,
654
- themes,
655
- pageBreakBefore: entry.pageBreakBefore,
656
- pageCounterReset: entry.pageCounterReset,
657
- ...('type' in template && { template }),
658
- };
659
- return parsedEntry;
660
- }
661
- if (isCoverEntry(entry)) {
662
- const inputInfo = entry.path ? getInputInfo(entry.path) : undefined;
663
- const { metadata, ...template } = inputInfo || {};
664
- let target = entry.output
665
- ? upath.resolve(workspaceDir, entry.output)
666
- : inputInfo && getTargetPath(inputInfo);
667
- const themes = entry.theme
668
- ? [entry.theme].flat().map((theme) => parseTheme({
669
- theme,
670
- context,
671
- workspaceDir,
672
- themesDir,
673
- }))
674
- : (metadata?.themes ?? []); // Don't inherit rootThemes for cover documents
675
- themes.forEach((t) => themeIndexes.add(t));
676
- const coverImageSrc = ensureCoverImage(entry.imageSrc || cover?.src);
677
- if (!coverImageSrc) {
678
- throw new Error(`A CoverEntryConfig is set in the entry list but a location of cover file is not set. Please set 'cover' property in your config file.`);
679
- }
680
- target ??= upath.resolve(workspaceDir, entry.path || coverHtml || COVER_HTML_FILENAME);
681
- if (inputInfo?.type === 'file' &&
682
- pathEquals(inputInfo.pathname, target)) {
683
- const tmpPath = upath.resolve(upath.dirname(target), `${temporaryFilePrefix}${upath.basename(target)}`);
684
- exportAliases.push({ source: tmpPath, target });
685
- touchTmpFile(tmpPath);
686
- target = tmpPath;
687
- }
688
- const parsedEntry = {
689
- rel: 'cover',
690
- target,
691
- title: entry.title ?? metadata?.title ?? projectTitle,
692
- themes,
693
- coverImageSrc,
694
- coverImageAlt: entry.imageAlt || cover?.name || COVER_HTML_IMAGE_ALT,
695
- pageBreakBefore: entry.pageBreakBefore,
696
- ...('type' in template && { template }),
697
- };
698
- return parsedEntry;
699
- }
700
- if (isArticleEntry(entry)) {
701
- const inputInfo = getInputInfo(entry.path);
702
- const { metadata, ...source } = inputInfo;
703
- const target = entry.output
704
- ? upath.resolve(workspaceDir, entry.output)
705
- : getTargetPath(inputInfo);
706
- const themes = entry.theme
707
- ? [entry.theme]
708
- .flat()
709
- .map((theme) => parseTheme({ theme, context, workspaceDir, themesDir }))
710
- : (metadata?.themes ?? [...rootThemes]);
711
- themes.forEach((t) => themeIndexes.add(t));
712
- const parsedEntry = {
713
- contentType: inputInfo.type === 'file' ? inputInfo.contentType : 'text/html',
714
- source,
715
- target,
716
- title: entry.title ?? metadata?.title ?? projectTitle,
717
- themes,
718
- ...(entry.rel && { rel: entry.rel }),
719
- };
720
- return parsedEntry;
721
- }
722
- /* v8 ignore next */
723
- return entry;
724
- }
725
- const entries = config.entry.map(parseEntry);
726
- let fallbackProjectTitle;
727
- if (!projectTitle) {
728
- if (entries.length === 1 && entries[0].title) {
729
- fallbackProjectTitle = entries[0].title;
730
- }
731
- else {
732
- fallbackProjectTitle = upath.basename(outputs[0].path);
733
- }
734
- }
735
- if (!!config?.toc && !entries.find(({ rel }) => rel === 'contents')) {
736
- entries.unshift({
737
- rel: 'contents',
738
- ...tocConfig,
739
- themes: [...rootThemes],
740
- });
741
- }
742
- if (cover && coverHtml && !entries.find(({ rel }) => rel === 'cover')) {
743
- entries.unshift({
744
- rel: 'cover',
745
- target: coverHtml,
746
- title: projectTitle,
747
- themes: [], // Don't inherit rootThemes for cover documents
748
- coverImageSrc: ensureCoverImage(cover.src),
749
- coverImageAlt: cover.name,
750
- });
751
- }
752
- return {
753
- workspaceDir,
754
- themesDir,
755
- entries,
756
- input: {
757
- format: 'pub-manifest',
758
- entry: upath.join(workspaceDir, MANIFEST_FILENAME),
759
- },
760
- viewerInput: {
761
- type: 'webpub',
762
- manifestPath: upath.join(workspaceDir, MANIFEST_FILENAME),
763
- needToGenerateManifest: true,
764
- },
765
- exportAliases,
766
- title: projectTitle || fallbackProjectTitle,
767
- author: projectAuthor,
768
- };
769
- }
770
- //# sourceMappingURL=resolve.js.map