@vivliostyle/cli 5.9.0 → 6.1.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.
Files changed (150) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +21 -63
  4. package/dist/browser.js.map +1 -1
  5. package/dist/build.d.ts +1 -1
  6. package/dist/build.d.ts.map +1 -1
  7. package/dist/build.js +46 -47
  8. package/dist/build.js.map +1 -1
  9. package/dist/builder.d.ts +5 -6
  10. package/dist/builder.d.ts.map +1 -1
  11. package/dist/builder.js +124 -103
  12. package/dist/builder.js.map +1 -1
  13. package/dist/cli.js +5 -10
  14. package/dist/cli.js.map +1 -1
  15. package/dist/commands/build.js +10 -16
  16. package/dist/commands/build.js.map +1 -1
  17. package/dist/commands/build.parser.d.ts +3 -3
  18. package/dist/commands/build.parser.d.ts.map +1 -1
  19. package/dist/commands/build.parser.js +13 -21
  20. package/dist/commands/build.parser.js.map +1 -1
  21. package/dist/commands/init.js +7 -9
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/init.parser.d.ts +2 -2
  24. package/dist/commands/init.parser.d.ts.map +1 -1
  25. package/dist/commands/init.parser.js +3 -10
  26. package/dist/commands/init.parser.js.map +1 -1
  27. package/dist/commands/preview.js +8 -11
  28. package/dist/commands/preview.js.map +1 -1
  29. package/dist/commands/preview.parser.d.ts +2 -2
  30. package/dist/commands/preview.parser.d.ts.map +1 -1
  31. package/dist/commands/preview.parser.js +5 -12
  32. package/dist/commands/preview.parser.js.map +1 -1
  33. package/dist/config.d.ts +29 -18
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/config.js +285 -251
  36. package/dist/config.js.map +1 -1
  37. package/dist/const.d.ts +2 -0
  38. package/dist/const.d.ts.map +1 -1
  39. package/dist/const.js +12 -15
  40. package/dist/const.js.map +1 -1
  41. package/dist/container.js +31 -41
  42. package/dist/container.js.map +1 -1
  43. package/dist/epub.d.ts.map +1 -1
  44. package/dist/epub.js +10 -17
  45. package/dist/epub.js.map +1 -1
  46. package/dist/html.d.ts +3 -3
  47. package/dist/html.d.ts.map +1 -1
  48. package/dist/html.js +21 -30
  49. package/dist/html.js.map +1 -1
  50. package/dist/index.d.ts +5 -5
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +3 -9
  53. package/dist/index.js.map +1 -1
  54. package/dist/init.js +12 -19
  55. package/dist/init.js.map +1 -1
  56. package/dist/input.d.ts +2 -2
  57. package/dist/input.d.ts.map +1 -1
  58. package/dist/input.js +8 -16
  59. package/dist/input.js.map +1 -1
  60. package/dist/markdown.js +9 -17
  61. package/dist/markdown.js.map +1 -1
  62. package/dist/output.d.ts +1 -1
  63. package/dist/output.d.ts.map +1 -1
  64. package/dist/output.js +6 -16
  65. package/dist/output.js.map +1 -1
  66. package/dist/pdf.d.ts +3 -3
  67. package/dist/pdf.d.ts.map +1 -1
  68. package/dist/pdf.js +66 -79
  69. package/dist/pdf.js.map +1 -1
  70. package/dist/postprocess.d.ts +5 -5
  71. package/dist/postprocess.d.ts.map +1 -1
  72. package/dist/postprocess.js +54 -81
  73. package/dist/postprocess.js.map +1 -1
  74. package/dist/preview.d.ts +1 -1
  75. package/dist/preview.d.ts.map +1 -1
  76. package/dist/preview.js +53 -58
  77. package/dist/preview.js.map +1 -1
  78. package/dist/schema/pubManifest.d.ts +2 -471
  79. package/dist/schema/pubManifest.d.ts.map +1 -1
  80. package/dist/schema/pubManifest.js +41 -42
  81. package/dist/schema/pubManifest.js.map +1 -1
  82. package/dist/schema/publication.schema.d.ts +12 -12
  83. package/dist/schema/publication.schema.d.ts.map +1 -1
  84. package/dist/schema/publication.schema.js +1 -2
  85. package/dist/schema/publication.schema.js.map +1 -1
  86. package/dist/schema/vivliostyle.d.ts +1 -1
  87. package/dist/schema/vivliostyle.d.ts.map +1 -1
  88. package/dist/schema/vivliostyle.js +7 -8
  89. package/dist/schema/vivliostyle.js.map +1 -1
  90. package/dist/schema/vivliostyleConfig.schema.d.ts +22 -9
  91. package/dist/schema/vivliostyleConfig.schema.d.ts.map +1 -1
  92. package/dist/schema/vivliostyleConfig.schema.js +1 -2
  93. package/dist/schema/vivliostyleConfig.schema.js.map +1 -1
  94. package/dist/server.d.ts +7 -6
  95. package/dist/server.d.ts.map +1 -1
  96. package/dist/server.js +26 -38
  97. package/dist/server.js.map +1 -1
  98. package/dist/theme.d.ts +6 -0
  99. package/dist/theme.d.ts.map +1 -0
  100. package/dist/theme.js +74 -0
  101. package/dist/theme.js.map +1 -0
  102. package/dist/util.d.ts +3 -3
  103. package/dist/util.d.ts.map +1 -1
  104. package/dist/util.js +80 -98
  105. package/dist/util.js.map +1 -1
  106. package/dist/webbook.d.ts +1 -1
  107. package/dist/webbook.d.ts.map +1 -1
  108. package/dist/webbook.js +40 -44
  109. package/dist/webbook.js.map +1 -1
  110. package/package.json +33 -17
  111. package/schemas/pubManifest/README.md +5 -0
  112. package/schemas/pubManifest/module/ItemList.schema.json +32 -0
  113. package/schemas/pubManifest/module/bcp.schema.json +7 -0
  114. package/schemas/pubManifest/module/context.schema.json +62 -0
  115. package/schemas/pubManifest/module/contributor-object.schema.json +42 -0
  116. package/schemas/pubManifest/module/contributor.schema.json +26 -0
  117. package/schemas/pubManifest/module/date.schema.json +7 -0
  118. package/schemas/pubManifest/module/duration.schema.json +7 -0
  119. package/schemas/pubManifest/module/item-lists.schema.json +16 -0
  120. package/schemas/pubManifest/module/language.schema.json +16 -0
  121. package/schemas/pubManifest/module/link.schema.json +60 -0
  122. package/schemas/pubManifest/module/localizable-object.schema.json +15 -0
  123. package/schemas/pubManifest/module/localizable.schema.json +26 -0
  124. package/schemas/pubManifest/module/resource.categorization.schema.json +31 -0
  125. package/schemas/pubManifest/module/strings.schema.json +9 -0
  126. package/schemas/pubManifest/module/url.schema.json +7 -0
  127. package/schemas/pubManifest/module/urls.schema.json +18 -0
  128. package/schemas/pubManifest/publication.schema.json +123 -0
  129. package/schemas/vivliostyle/vivliostyleConfig.schema.json +348 -0
  130. package/types/better-ajv-errors.d.ts +28 -0
  131. package/types/custom.d.ts +9 -0
  132. package/types/playwright.d.ts +49 -0
  133. package/dist/schema/pubManifest/module/ItemList.schema.json +0 -32
  134. package/dist/schema/pubManifest/module/bcp.schema.json +0 -7
  135. package/dist/schema/pubManifest/module/context.schema.json +0 -62
  136. package/dist/schema/pubManifest/module/contributor-object.schema.json +0 -42
  137. package/dist/schema/pubManifest/module/contributor.schema.json +0 -26
  138. package/dist/schema/pubManifest/module/date.schema.json +0 -7
  139. package/dist/schema/pubManifest/module/duration.schema.json +0 -7
  140. package/dist/schema/pubManifest/module/item-lists.schema.json +0 -16
  141. package/dist/schema/pubManifest/module/language.schema.json +0 -16
  142. package/dist/schema/pubManifest/module/link.schema.json +0 -60
  143. package/dist/schema/pubManifest/module/localizable-object.schema.json +0 -15
  144. package/dist/schema/pubManifest/module/localizable.schema.json +0 -26
  145. package/dist/schema/pubManifest/module/resource.categorization.schema.json +0 -31
  146. package/dist/schema/pubManifest/module/strings.schema.json +0 -9
  147. package/dist/schema/pubManifest/module/url.schema.json +0 -7
  148. package/dist/schema/pubManifest/module/urls.schema.json +0 -18
  149. package/dist/schema/pubManifest/publication.schema.json +0 -123
  150. package/dist/schema/vivliostyle/vivliostyleConfig.schema.json +0 -296
package/dist/config.js CHANGED
@@ -1,27 +1,24 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkUnusedCliFlags = exports.mergeConfig = exports.collectVivliostyleConfig = exports.parseTheme = exports.contextResolve = exports.validateTimeoutFlag = void 0;
7
- const ajv_1 = __importDefault(require("ajv"));
8
- const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
- const better_ajv_errors_1 = __importDefault(require("better-ajv-errors"));
10
- const chalk_1 = __importDefault(require("chalk"));
11
- const cheerio_1 = __importDefault(require("cheerio"));
12
- const fs_1 = __importDefault(require("fs"));
13
- const resolve_pkg_1 = __importDefault(require("resolve-pkg"));
14
- const upath_1 = __importDefault(require("upath"));
15
- const url_1 = require("url");
16
- const browser_1 = require("./browser");
17
- const const_1 = require("./const");
18
- const container_1 = require("./container");
19
- const epub_1 = require("./epub");
20
- const input_1 = require("./input");
21
- const markdown_1 = require("./markdown");
22
- const output_1 = require("./output");
23
- const vivliostyle_1 = require("./schema/vivliostyle");
24
- const util_1 = require("./util");
1
+ import AjvModule from 'ajv';
2
+ import AjvFormatsModule from 'ajv-formats';
3
+ import betterAjvErrors from 'better-ajv-errors';
4
+ import chalk from 'chalk';
5
+ import cheerio from 'cheerio';
6
+ import fs from 'fs';
7
+ import path from 'upath';
8
+ import { pathToFileURL } from 'url';
9
+ import { getExecutableBrowserPath } from './browser.js';
10
+ import { MANIFEST_FILENAME, TOC_FILENAME, TOC_TITLE } from './const.js';
11
+ import { CONTAINER_IMAGE } from './container.js';
12
+ import { openEpubToTmpDirectory } from './epub.js';
13
+ import { detectInputFormat, detectManuscriptMediaType, } from './input.js';
14
+ import { readMarkdownMetadata } from './markdown.js';
15
+ import { checkOutputFormat, checkPreflightMode, checkRenderMode, detectOutputFormat, } from './output.js';
16
+ import { vivliostyleConfigSchema } from './schema/vivliostyle.js';
17
+ import { parsePackageName } from './theme.js';
18
+ import { cwd, debug, DetailError, filterRelevantAjvErrors, isUrlString, log, logWarn, readJSON, statFileSync, touchTmpFile, } from './util.js';
19
+ // FIXME: https://github.com/ajv-validator/ajv/issues/2047
20
+ const Ajv = AjvModule.default;
21
+ const addFormats = AjvFormatsModule.default;
25
22
  const DEFAULT_TIMEOUT = 2 * 60 * 1000; // 2 minutes
26
23
  const DEFAULT_ASSETS = [
27
24
  '**/*.png',
@@ -36,14 +33,12 @@ const DEFAULT_ASSETS = [
36
33
  '**/*.woff',
37
34
  '**/*.woff2',
38
35
  ];
39
- function validateTimeoutFlag(val) {
36
+ export function validateTimeoutFlag(val) {
40
37
  return Number.isFinite(+val) && +val > 0 ? +val * 1000 : DEFAULT_TIMEOUT;
41
38
  }
42
- exports.validateTimeoutFlag = validateTimeoutFlag;
43
- function contextResolve(context, loc) {
44
- return loc && upath_1.default.resolve(context, loc);
39
+ export function contextResolve(context, loc) {
40
+ return loc && path.resolve(context, loc);
45
41
  }
46
- exports.contextResolve = contextResolve;
47
42
  function normalizeEntry(e) {
48
43
  if (typeof e === 'object') {
49
44
  return e;
@@ -51,56 +46,58 @@ function normalizeEntry(e) {
51
46
  return { path: e };
52
47
  }
53
48
  // parse theme locator
54
- function parseTheme(locator, contextDir, workspaceDir) {
55
- if (typeof locator !== 'string' || locator == '') {
56
- return undefined;
57
- }
49
+ export function parseTheme({ theme, context, workspaceDir, themesDir, }) {
50
+ const { specifier, import: importPath } = typeof theme === 'string' ? { specifier: theme, import: undefined } : theme;
58
51
  // url
59
- if (util_1.isUrlString(locator)) {
52
+ if (isUrlString(specifier)) {
60
53
  return {
61
54
  type: 'uri',
62
- name: upath_1.default.basename(locator),
63
- location: locator,
55
+ name: path.basename(specifier),
56
+ location: specifier,
57
+ };
58
+ }
59
+ // bare .css file
60
+ const stylePath = path.resolve(context, specifier);
61
+ if (fs.existsSync(stylePath) && stylePath.endsWith('.css')) {
62
+ const sourceRelPath = path.relative(context, stylePath);
63
+ return {
64
+ type: 'file',
65
+ name: path.basename(specifier),
66
+ source: stylePath,
67
+ location: path.resolve(workspaceDir, sourceRelPath),
64
68
  };
65
69
  }
66
- const stylePath = upath_1.default.resolve(contextDir, locator);
67
70
  // node_modules, local pkg
68
- const pkgRootDir = resolve_pkg_1.default(locator, { cwd: contextDir });
69
- if (!(pkgRootDir === null || pkgRootDir === void 0 ? void 0 : pkgRootDir.endsWith('.css'))) {
70
- const style = parseStyleLocator(pkgRootDir !== null && pkgRootDir !== void 0 ? pkgRootDir : stylePath, locator);
71
- if (style) {
72
- return {
73
- type: 'package',
74
- name: style.name,
75
- location: pkgRootDir !== null && pkgRootDir !== void 0 ? pkgRootDir : stylePath,
76
- destination: upath_1.default.join(workspaceDir, 'themes/packages', style.name),
77
- style: style.maybeStyle,
78
- };
71
+ const parsed = parsePackageName(specifier, context);
72
+ if (!parsed) {
73
+ throw new Error(`Invalid package name: ${specifier}`);
74
+ }
75
+ // To security reason, Vivliostyle CLI disallow other than npm registry or local file as download source
76
+ // TODO: Add option that user can allow an unofficial registry explicitly
77
+ if (!parsed.registry && parsed.type !== 'directory') {
78
+ throw new Error(`This package specifier is not allowed: ${specifier}`);
79
+ }
80
+ let name = parsed.name;
81
+ let resolvedSpecifier = specifier;
82
+ if (parsed.type === 'directory' && parsed.fetchSpec) {
83
+ const pkgJsonPath = path.join(parsed.fetchSpec, 'package.json');
84
+ if (fs.existsSync(pkgJsonPath)) {
85
+ const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
86
+ name = packageJson.name;
87
+ resolvedSpecifier = parsed.fetchSpec;
79
88
  }
80
89
  }
81
- // bare .css file
82
- const sourceRelPath = upath_1.default.relative(contextDir, stylePath);
90
+ if (!name) {
91
+ throw new Error(`Could not determine the package name: ${specifier}`);
92
+ }
83
93
  return {
84
- type: 'file',
85
- name: upath_1.default.basename(locator),
86
- location: stylePath,
87
- destination: upath_1.default.resolve(workspaceDir, sourceRelPath),
94
+ type: 'package',
95
+ name,
96
+ specifier: resolvedSpecifier,
97
+ location: path.join(themesDir, 'packages', name),
98
+ importPath,
88
99
  };
89
100
  }
90
- exports.parseTheme = parseTheme;
91
- function parseStyleLocator(pkgRootDir, locator) {
92
- var _a, _b, _c, _d;
93
- const pkgJsonPath = upath_1.default.join(pkgRootDir, 'package.json');
94
- if (!fs_1.default.existsSync(pkgJsonPath)) {
95
- return undefined;
96
- }
97
- const packageJson = JSON.parse(fs_1.default.readFileSync(pkgJsonPath, 'utf8'));
98
- const maybeStyle = (_d = (_c = (_b = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.vivliostyle) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.style) !== null && _c !== void 0 ? _c : packageJson.style) !== null && _d !== void 0 ? _d : packageJson.main;
99
- if (!maybeStyle) {
100
- throw new Error(`invalid style file: ${maybeStyle} while parsing ${locator}`);
101
- }
102
- return { name: packageJson.name, maybeStyle };
103
- }
104
101
  function parsePageSize(size) {
105
102
  const [width, height, ...others] = `${size}`.split(',');
106
103
  if (others.length) {
@@ -114,163 +111,191 @@ function parsePageSize(size) {
114
111
  }
115
112
  else {
116
113
  return {
117
- format: width !== null && width !== void 0 ? width : 'Letter',
114
+ format: width ?? 'Letter',
118
115
  };
119
116
  }
120
117
  }
121
- function parseFileMetadata(type, sourcePath, workspaceDir) {
122
- var _a, _b, _c;
123
- const sourceDir = upath_1.default.dirname(sourcePath);
118
+ function parseFileMetadata({ type, sourcePath, workspaceDir, themesDir, }) {
119
+ const sourceDir = path.dirname(sourcePath);
124
120
  let title;
125
- let theme;
121
+ let themes;
126
122
  if (type === 'text/markdown') {
127
- const metadata = markdown_1.readMarkdownMetadata(sourcePath);
123
+ const metadata = readMarkdownMetadata(sourcePath);
128
124
  title = metadata.title;
129
- theme = parseTheme((_a = metadata.vfm) === null || _a === void 0 ? void 0 : _a.theme, sourceDir, workspaceDir);
125
+ if (metadata.vfm?.theme && themesDir) {
126
+ themes = [metadata.vfm.theme]
127
+ .flat()
128
+ .filter((entry) => !!entry && (typeof entry === 'string' || typeof entry === 'object'))
129
+ .map((theme) => parseTheme({
130
+ theme,
131
+ context: sourceDir,
132
+ workspaceDir,
133
+ themesDir,
134
+ }));
135
+ }
130
136
  }
131
137
  else {
132
- const $ = cheerio_1.default.load(fs_1.default.readFileSync(sourcePath, 'utf8'));
133
- title = (_c = (_b = $('title')) === null || _b === void 0 ? void 0 : _b.text()) !== null && _c !== void 0 ? _c : undefined;
138
+ const $ = cheerio.load(fs.readFileSync(sourcePath, 'utf8'));
139
+ title = $('title')?.text() ?? undefined;
134
140
  }
135
- return { title, theme };
141
+ return { title, themes };
136
142
  }
137
- function collectVivliostyleConfig(cliFlags) {
138
- const load = (configPath) => {
139
- if (!fs_1.default.existsSync(configPath)) {
140
- return undefined;
143
+ export async function collectVivliostyleConfig(cliFlags) {
144
+ const load = async (configPath) => {
145
+ let config;
146
+ let jsonRaw;
147
+ try {
148
+ if (path.extname(configPath) === '.json') {
149
+ jsonRaw = fs.readFileSync(configPath, 'utf8');
150
+ config = JSON.parse(jsonRaw);
151
+ }
152
+ else {
153
+ config = (await import(configPath)).default;
154
+ }
141
155
  }
142
- delete require.cache[configPath]; // clear require cache
143
- const config = require(configPath);
144
- const ajv = new ajv_1.default({ strict: false });
145
- ajv_formats_1.default(ajv);
146
- const validate = ajv.compile(vivliostyle_1.vivliostyleConfigSchema);
156
+ catch (error) {
157
+ const thrownError = error;
158
+ throw new DetailError(`An error occurred on loading a config file: ${configPath}`, thrownError.stack ?? thrownError.message);
159
+ }
160
+ const ajv = new Ajv({ strict: false });
161
+ addFormats(ajv);
162
+ const validate = ajv.compile(vivliostyleConfigSchema);
147
163
  const valid = validate(config);
148
164
  if (!valid) {
149
- let jsonRaw;
150
- try {
151
- jsonRaw = fs_1.default.readFileSync(configPath, 'utf8');
152
- // Check JSON validity
153
- JSON.parse(jsonRaw);
154
- }
155
- catch {
156
- jsonRaw = undefined;
157
- }
158
165
  const message = `Validation of vivliostyle.config failed. Please check the schema: ${configPath}`;
159
166
  const detailMessage = validate.errors &&
160
- better_ajv_errors_1.default(vivliostyle_1.vivliostyleConfigSchema, config, util_1.filterRelevantAjvErrors(validate.errors), typeof jsonRaw === 'string' ? { json: jsonRaw } : { indent: 2 });
167
+ betterAjvErrors(vivliostyleConfigSchema, config, filterRelevantAjvErrors(validate.errors), typeof jsonRaw === 'string' ? { json: jsonRaw } : { indent: 2 });
161
168
  throw detailMessage
162
- ? new util_1.DetailError(message, detailMessage)
169
+ ? new DetailError(message, detailMessage)
163
170
  : new Error(message);
164
171
  }
165
172
  return config;
166
173
  };
167
- let vivliostyleConfigPath = cliFlags.configPath
168
- ? upath_1.default.resolve(util_1.cwd, cliFlags.configPath)
169
- : upath_1.default.join(util_1.cwd, 'vivliostyle.config.js');
170
- let vivliostyleConfig = load(vivliostyleConfigPath);
171
- if (!vivliostyleConfig &&
172
- cliFlags.input &&
173
- upath_1.default.basename(cliFlags.input).startsWith('vivliostyle.config')) {
174
+ let configEntry = {};
175
+ let vivliostyleConfigPath;
176
+ if (cliFlags.configPath) {
177
+ vivliostyleConfigPath = path.resolve(cwd, cliFlags.configPath);
178
+ }
179
+ else {
180
+ vivliostyleConfigPath = ['.js', '.mjs', '.cjs']
181
+ .map((ext) => path.join(cwd, `vivliostyle.config${ext}`))
182
+ .find((p) => fs.existsSync(p));
183
+ }
184
+ // let vivliostyleConfig: VivliostyleConfigSchema | undefined;
185
+ if (vivliostyleConfigPath) {
186
+ configEntry = {
187
+ vivliostyleConfigPath,
188
+ vivliostyleConfig: [await load(vivliostyleConfigPath)].flat(),
189
+ };
190
+ }
191
+ else if (cliFlags.input &&
192
+ path.basename(cliFlags.input).startsWith('vivliostyle.config')) {
174
193
  // Load an input argument as a Vivliostyle config
175
194
  try {
176
- const inputPath = upath_1.default.resolve(util_1.cwd, cliFlags.input);
177
- const inputConfig = load(inputPath);
178
- if (inputConfig) {
179
- cliFlags = {
180
- ...cliFlags,
181
- input: undefined,
182
- };
183
- vivliostyleConfigPath = inputPath;
184
- vivliostyleConfig = inputConfig;
185
- }
195
+ const inputPath = path.resolve(cwd, cliFlags.input);
196
+ const inputConfig = await load(inputPath);
197
+ cliFlags = {
198
+ ...cliFlags,
199
+ input: undefined,
200
+ };
201
+ configEntry = {
202
+ vivliostyleConfigPath: inputPath,
203
+ vivliostyleConfig: [inputConfig].flat(),
204
+ };
186
205
  }
187
206
  catch (_err) { }
188
207
  }
189
208
  if (cliFlags.executableChromium) {
190
- util_1.logWarn(chalk_1.default.yellowBright("'--executable-chromium' option was deprecated and will be removed in a future release. Please replace with '--executable-browser' option."));
209
+ logWarn(chalk.yellowBright("'--executable-chromium' option was deprecated and will be removed in a future release. Please replace with '--executable-browser' option."));
191
210
  cliFlags.executableBrowser = cliFlags.executableChromium;
192
211
  }
193
212
  return {
194
213
  cliFlags,
195
- vivliostyleConfig: vivliostyleConfig &&
196
- // Config file allows both single input and list of inputs
197
- (Array.isArray(vivliostyleConfig)
198
- ? vivliostyleConfig
199
- : [vivliostyleConfig]),
200
- vivliostyleConfigPath,
214
+ ...configEntry,
201
215
  };
202
216
  }
203
- exports.collectVivliostyleConfig = collectVivliostyleConfig;
204
- async function mergeConfig(cliFlags, config, context) {
205
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
206
- util_1.debug('context directory', context);
207
- util_1.debug('cliFlags', cliFlags);
208
- util_1.debug('vivliostyle.config.js', config);
217
+ export async function mergeConfig(cliFlags, config, context) {
218
+ debug('context directory', context);
219
+ debug('cliFlags', cliFlags);
220
+ debug('vivliostyle.config.js', config);
209
221
  let entryContextDir;
210
222
  let workspaceDir;
211
- if (cliFlags.input && util_1.isUrlString(cliFlags.input)) {
212
- workspaceDir = entryContextDir = util_1.cwd;
223
+ if (cliFlags.input && isUrlString(cliFlags.input)) {
224
+ workspaceDir = entryContextDir = cwd;
213
225
  }
214
226
  else {
215
- entryContextDir = upath_1.default.resolve(cliFlags.input
216
- ? upath_1.default.dirname(upath_1.default.resolve(context, cliFlags.input))
217
- : (_a = contextResolve(context, config === null || config === void 0 ? void 0 : config.entryContext)) !== null && _a !== void 0 ? _a : context);
227
+ entryContextDir = path.resolve(cliFlags.input
228
+ ? path.dirname(path.resolve(context, cliFlags.input))
229
+ : contextResolve(context, config?.entryContext) ?? context);
218
230
  workspaceDir =
219
- (_b = contextResolve(context, config === null || config === void 0 ? void 0 : config.workspaceDir)) !== null && _b !== void 0 ? _b : entryContextDir;
231
+ contextResolve(context, config?.workspaceDir) ?? entryContextDir;
220
232
  }
221
- const includeAssets = (config === null || config === void 0 ? void 0 : config.includeAssets)
233
+ const themesDir = path.join(workspaceDir, 'themes');
234
+ const includeAssets = config?.includeAssets
222
235
  ? Array.isArray(config.includeAssets)
223
236
  ? config.includeAssets
224
237
  : [config.includeAssets]
225
238
  : DEFAULT_ASSETS;
226
- const language = (_d = (_c = cliFlags.language) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config.language) !== null && _d !== void 0 ? _d : null;
227
- const readingProgression = (_e = config === null || config === void 0 ? void 0 : config.readingProgression) !== null && _e !== void 0 ? _e : undefined;
228
- const sizeFlag = (_f = cliFlags.size) !== null && _f !== void 0 ? _f : config === null || config === void 0 ? void 0 : config.size;
239
+ const language = cliFlags.language ?? config?.language ?? null;
240
+ const readingProgression = config?.readingProgression ?? undefined;
241
+ const sizeFlag = cliFlags.size ?? config?.size;
229
242
  const size = sizeFlag ? parsePageSize(sizeFlag) : undefined;
230
- const cropMarks = (_g = cliFlags.cropMarks) !== null && _g !== void 0 ? _g : false;
243
+ const cropMarks = cliFlags.cropMarks ?? false;
231
244
  const bleed = cliFlags.bleed;
232
245
  const cropOffset = cliFlags.cropOffset;
233
246
  const css = cliFlags.css;
234
247
  const customStyle = cliFlags.style &&
235
- (util_1.isUrlString(cliFlags.style)
248
+ (isUrlString(cliFlags.style)
236
249
  ? cliFlags.style
237
- : url_1.pathToFileURL(cliFlags.style).href);
250
+ : pathToFileURL(cliFlags.style).href);
238
251
  const customUserStyle = cliFlags.userStyle &&
239
- (util_1.isUrlString(cliFlags.userStyle)
252
+ (isUrlString(cliFlags.userStyle)
240
253
  ? cliFlags.userStyle
241
- : url_1.pathToFileURL(cliFlags.userStyle).href);
242
- const singleDoc = (_h = cliFlags.singleDoc) !== null && _h !== void 0 ? _h : false;
243
- const quick = (_j = cliFlags.quick) !== null && _j !== void 0 ? _j : false;
244
- const cover = (_k = contextResolve(entryContextDir, config === null || config === void 0 ? void 0 : config.cover)) !== null && _k !== void 0 ? _k : undefined;
245
- const pressReady = (_m = (_l = cliFlags.pressReady) !== null && _l !== void 0 ? _l : config === null || config === void 0 ? void 0 : config.pressReady) !== null && _m !== void 0 ? _m : false;
246
- const renderMode = (_o = cliFlags.renderMode) !== null && _o !== void 0 ? _o : 'local';
247
- const preflight = (_p = cliFlags.preflight) !== null && _p !== void 0 ? _p : (pressReady ? 'press-ready' : null);
248
- const preflightOption = (_q = cliFlags.preflightOption) !== null && _q !== void 0 ? _q : [];
254
+ : pathToFileURL(cliFlags.userStyle).href);
255
+ const singleDoc = cliFlags.singleDoc ?? false;
256
+ const quick = cliFlags.quick ?? false;
257
+ const cover = contextResolve(entryContextDir, config?.cover) ?? undefined;
258
+ const pressReady = cliFlags.pressReady ?? config?.pressReady ?? false;
259
+ const renderMode = cliFlags.renderMode ?? 'local';
260
+ const preflight = cliFlags.preflight ?? (pressReady ? 'press-ready' : null);
261
+ const preflightOption = cliFlags.preflightOption ?? [];
249
262
  const vfmOptions = {
250
- ...config === null || config === void 0 ? void 0 : config.vfm,
251
- hardLineBreaks: (_s = (_r = config === null || config === void 0 ? void 0 : config.vfm) === null || _r === void 0 ? void 0 : _r.hardLineBreaks) !== null && _s !== void 0 ? _s : false,
252
- disableFormatHtml: (_u = (_t = config === null || config === void 0 ? void 0 : config.vfm) === null || _t === void 0 ? void 0 : _t.disableFormatHtml) !== null && _u !== void 0 ? _u : false,
263
+ ...config?.vfm,
264
+ hardLineBreaks: config?.vfm?.hardLineBreaks ?? false,
265
+ disableFormatHtml: config?.vfm?.disableFormatHtml ?? false,
253
266
  };
254
- const verbose = (_v = cliFlags.verbose) !== null && _v !== void 0 ? _v : false;
255
- const timeout = (_x = (_w = cliFlags.timeout) !== null && _w !== void 0 ? _w : config === null || config === void 0 ? void 0 : config.timeout) !== null && _x !== void 0 ? _x : DEFAULT_TIMEOUT;
256
- const sandbox = (_y = cliFlags.sandbox) !== null && _y !== void 0 ? _y : true;
257
- const browserType = (_0 = (_z = cliFlags.browser) !== null && _z !== void 0 ? _z : config === null || config === void 0 ? void 0 : config.browser) !== null && _0 !== void 0 ? _0 : 'chromium';
258
- const executableBrowser = (_1 = cliFlags.executableBrowser) !== null && _1 !== void 0 ? _1 : browser_1.getExecutableBrowserPath(browserType);
259
- const image = (_3 = (_2 = cliFlags.image) !== null && _2 !== void 0 ? _2 : config === null || config === void 0 ? void 0 : config.image) !== null && _3 !== void 0 ? _3 : container_1.CONTAINER_IMAGE;
260
- const httpServer = (_5 = (_4 = cliFlags.http) !== null && _4 !== void 0 ? _4 : config === null || config === void 0 ? void 0 : config.http) !== null && _5 !== void 0 ? _5 : false;
261
- const viewer = (_7 = (_6 = cliFlags.viewer) !== null && _6 !== void 0 ? _6 : config === null || config === void 0 ? void 0 : config.viewer) !== null && _7 !== void 0 ? _7 : undefined;
262
- const themeIndexes = [];
263
- const rootTheme = (_8 = parseTheme(cliFlags.theme, util_1.cwd, workspaceDir)) !== null && _8 !== void 0 ? _8 : parseTheme(config === null || config === void 0 ? void 0 : config.theme, context, workspaceDir);
264
- if (rootTheme) {
265
- themeIndexes.push(rootTheme);
266
- }
267
+ const verbose = cliFlags.verbose ?? false;
268
+ const timeout = cliFlags.timeout ?? config?.timeout ?? DEFAULT_TIMEOUT;
269
+ const sandbox = cliFlags.sandbox ?? true;
270
+ const browserType = cliFlags.browser ?? config?.browser ?? 'chromium';
271
+ const executableBrowser = cliFlags.executableBrowser ?? getExecutableBrowserPath(browserType);
272
+ const image = cliFlags.image ?? config?.image ?? CONTAINER_IMAGE;
273
+ const httpServer = cliFlags.http ?? config?.http ?? false;
274
+ const viewer = cliFlags.viewer ?? config?.viewer ?? undefined;
275
+ const rootThemes = cliFlags.theme
276
+ ? [
277
+ parseTheme({
278
+ theme: cliFlags.theme,
279
+ context: cwd,
280
+ workspaceDir,
281
+ themesDir,
282
+ }),
283
+ ]
284
+ : config?.theme
285
+ ? [config.theme].flat().map((theme) => parseTheme({
286
+ theme,
287
+ context,
288
+ workspaceDir,
289
+ themesDir,
290
+ }))
291
+ : [];
292
+ const themeIndexes = new Set(rootThemes);
267
293
  const outputs = (() => {
268
- var _a;
269
- if ((_a = cliFlags.targets) === null || _a === void 0 ? void 0 : _a.length) {
294
+ if (cliFlags.targets?.length) {
270
295
  return cliFlags.targets.map(({ path: outputPath, format }) => {
271
296
  if (format === 'pdf') {
272
297
  return {
273
- path: upath_1.default.resolve(outputPath),
298
+ path: path.resolve(outputPath),
274
299
  format,
275
300
  renderMode,
276
301
  preflight,
@@ -279,29 +304,28 @@ async function mergeConfig(cliFlags, config, context) {
279
304
  }
280
305
  else {
281
306
  return {
282
- path: upath_1.default.resolve(outputPath),
307
+ path: path.resolve(outputPath),
283
308
  format,
284
309
  };
285
310
  }
286
311
  });
287
312
  }
288
- if (config === null || config === void 0 ? void 0 : config.output) {
313
+ if (config?.output) {
289
314
  return (Array.isArray(config.output) ? config.output : [config.output]).map((target) => {
290
- var _a, _b, _c, _d;
291
315
  const targetObj = typeof target === 'string' ? { path: target } : target;
292
- const outputPath = upath_1.default.resolve(context, targetObj.path);
293
- const format = (_a = targetObj.format) !== null && _a !== void 0 ? _a : output_1.detectOutputFormat(outputPath);
294
- if (!output_1.checkOutputFormat(format)) {
316
+ const outputPath = path.resolve(context, targetObj.path);
317
+ const format = targetObj.format ?? detectOutputFormat(outputPath);
318
+ if (!checkOutputFormat(format)) {
295
319
  throw new Error(`Unknown format: ${format}`);
296
320
  }
297
321
  if (format === 'pdf') {
298
- const outputRenderMode = (_b = targetObj.renderMode) !== null && _b !== void 0 ? _b : renderMode;
299
- const outputPreflight = (_c = targetObj.preflight) !== null && _c !== void 0 ? _c : preflight;
300
- if (!output_1.checkRenderMode(outputRenderMode)) {
322
+ const outputRenderMode = targetObj.renderMode ?? renderMode;
323
+ const outputPreflight = targetObj.preflight ?? preflight;
324
+ if (!checkRenderMode(outputRenderMode)) {
301
325
  throw new Error(`Unknown renderMode: ${outputRenderMode}`);
302
326
  }
303
327
  if (outputPreflight !== null &&
304
- !output_1.checkPreflightMode(outputPreflight)) {
328
+ !checkPreflightMode(outputPreflight)) {
305
329
  throw new Error(`Unknown preflight: ${outputPreflight}`);
306
330
  }
307
331
  return {
@@ -310,7 +334,7 @@ async function mergeConfig(cliFlags, config, context) {
310
334
  format,
311
335
  renderMode: outputRenderMode,
312
336
  preflight: outputPreflight,
313
- preflightOption: (_d = targetObj.preflightOption) !== null && _d !== void 0 ? _d : preflightOption,
337
+ preflightOption: targetObj.preflightOption ?? preflightOption,
314
338
  };
315
339
  }
316
340
  else {
@@ -319,10 +343,10 @@ async function mergeConfig(cliFlags, config, context) {
319
343
  });
320
344
  }
321
345
  // Outputs a pdf file if any output configuration is not set
322
- const filename = (config === null || config === void 0 ? void 0 : config.title) ? `${config.title}.pdf` : 'output.pdf';
346
+ const filename = config?.title ? `${config.title}.pdf` : 'output.pdf';
323
347
  return [
324
348
  {
325
- path: upath_1.default.resolve(context, filename),
349
+ path: path.resolve(context, filename),
326
350
  format: 'pdf',
327
351
  renderMode,
328
352
  preflight,
@@ -333,9 +357,11 @@ async function mergeConfig(cliFlags, config, context) {
333
357
  const commonOpts = {
334
358
  entryContextDir,
335
359
  workspaceDir,
360
+ themesDir,
336
361
  includeAssets,
337
362
  outputs,
338
363
  themeIndexes,
364
+ rootThemes,
339
365
  size,
340
366
  cropMarks,
341
367
  bleed,
@@ -364,69 +390,70 @@ async function mergeConfig(cliFlags, config, context) {
364
390
  const parsedConfig = cliFlags.input
365
391
  ? await composeSingleInputConfig(commonOpts, cliFlags, config)
366
392
  : await composeProjectConfig(commonOpts, cliFlags, config, context);
367
- util_1.debug('parsedConfig', parsedConfig);
393
+ debug('parsedConfig', parsedConfig);
368
394
  checkUnusedCliFlags(parsedConfig, cliFlags);
369
395
  return parsedConfig;
370
396
  }
371
- exports.mergeConfig = mergeConfig;
372
397
  async function composeSingleInputConfig(otherConfig, cliFlags, config) {
373
- var _a;
374
- util_1.debug('entering single entry config mode');
398
+ debug('entering single entry config mode');
375
399
  let sourcePath;
376
400
  let workspaceDir;
377
401
  let input;
378
402
  const entries = [];
379
403
  const exportAliases = [];
380
404
  const tmpPrefix = `.vs-${Date.now()}.`;
381
- if (cliFlags.input && util_1.isUrlString(cliFlags.input)) {
405
+ if (cliFlags.input && isUrlString(cliFlags.input)) {
382
406
  sourcePath = cliFlags.input;
383
407
  workspaceDir = otherConfig.workspaceDir;
384
408
  input = { format: 'webbook', entry: sourcePath };
385
409
  }
386
410
  else {
387
- sourcePath = upath_1.default.resolve(cliFlags.input);
388
- workspaceDir = upath_1.default.dirname(sourcePath);
389
- input = input_1.detectInputFormat(sourcePath);
411
+ sourcePath = path.resolve(cliFlags.input);
412
+ workspaceDir = path.dirname(sourcePath);
413
+ input = detectInputFormat(sourcePath);
390
414
  // Check file exists
391
- util_1.statFileSync(sourcePath);
415
+ statFileSync(sourcePath);
392
416
  }
393
417
  if (input.format === 'markdown') {
394
418
  // Single input file; create temporary file
395
- const type = input_1.detectManuscriptMediaType(sourcePath);
396
- const metadata = parseFileMetadata(type, sourcePath, workspaceDir);
397
- const target = upath_1.default
398
- .resolve(workspaceDir, `${tmpPrefix}${upath_1.default.basename(sourcePath)}`)
419
+ const type = detectManuscriptMediaType(sourcePath);
420
+ const metadata = parseFileMetadata({ type, sourcePath, workspaceDir });
421
+ const target = path
422
+ .resolve(workspaceDir, `${tmpPrefix}${path.basename(sourcePath)}`)
399
423
  .replace(/\.md$/, '.html');
400
- await util_1.touchTmpFile(target);
424
+ await touchTmpFile(target);
425
+ const themes = metadata.themes ?? [...otherConfig.rootThemes];
426
+ themes.forEach((t) => otherConfig.themeIndexes.add(t));
401
427
  entries.push({
402
428
  type,
403
429
  source: sourcePath,
404
430
  target,
405
431
  title: metadata.title,
406
- theme: (_a = metadata.theme) !== null && _a !== void 0 ? _a : otherConfig.themeIndexes[0],
432
+ themes,
407
433
  });
408
434
  exportAliases.push({
409
435
  source: target,
410
- target: upath_1.default.resolve(workspaceDir, upath_1.default.basename(sourcePath).replace(/\.md$/, '.html')),
436
+ target: path.resolve(workspaceDir, path.basename(sourcePath).replace(/\.md$/, '.html')),
411
437
  });
412
438
  }
413
439
  const manifestDeclaration = await (async () => {
414
- var _a, _b, _c, _d;
415
440
  if (input.format === 'markdown') {
416
441
  // create temporary manifest file
417
- const manifestPath = upath_1.default.resolve(workspaceDir, `${tmpPrefix}${const_1.MANIFEST_FILENAME}`);
418
- await util_1.touchTmpFile(manifestPath);
442
+ const manifestPath = path.resolve(workspaceDir, `${tmpPrefix}${MANIFEST_FILENAME}`);
443
+ await touchTmpFile(manifestPath);
419
444
  exportAliases.push({
420
445
  source: manifestPath,
421
- target: upath_1.default.resolve(workspaceDir, const_1.MANIFEST_FILENAME),
446
+ target: path.resolve(workspaceDir, MANIFEST_FILENAME),
422
447
  });
423
448
  return {
424
449
  manifestPath,
425
450
  manifestAutoGenerate: {
426
- title: (_b = (_a = cliFlags.title) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.title) !== null && _b !== void 0 ? _b : (entries.length === 1 && entries[0].title
427
- ? entries[0].title
428
- : upath_1.default.basename(sourcePath)),
429
- author: (_d = (_c = cliFlags.author) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config.author) !== null && _d !== void 0 ? _d : '',
451
+ title: cliFlags.title ??
452
+ config?.title ??
453
+ (entries.length === 1 && entries[0].title
454
+ ? entries[0].title
455
+ : path.basename(sourcePath)),
456
+ author: cliFlags.author ?? config?.author ?? '',
430
457
  },
431
458
  };
432
459
  }
@@ -440,7 +467,7 @@ async function composeSingleInputConfig(otherConfig, cliFlags, config) {
440
467
  return { epubOpfPath: input.entry };
441
468
  }
442
469
  else if (input.format === 'epub') {
443
- const { epubOpfPath } = await epub_1.openEpubToTmpDirectory(input.entry);
470
+ const { epubOpfPath } = await openEpubToTmpDirectory(input.entry);
444
471
  return { epubOpfPath };
445
472
  }
446
473
  else {
@@ -456,61 +483,69 @@ async function composeSingleInputConfig(otherConfig, cliFlags, config) {
456
483
  };
457
484
  }
458
485
  async function composeProjectConfig(otherConfig, cliFlags, config, context) {
459
- var _a, _b, _c, _d, _e;
460
- util_1.debug('entering project config mode');
461
- const { entryContextDir, workspaceDir, themeIndexes, outputs } = otherConfig;
462
- const pkgJsonPath = upath_1.default.resolve(context, 'package.json');
463
- const pkgJson = fs_1.default.existsSync(pkgJsonPath)
464
- ? util_1.readJSON(pkgJsonPath)
486
+ debug('entering project config mode');
487
+ const { entryContextDir, workspaceDir, themesDir, themeIndexes, rootThemes, outputs, } = otherConfig;
488
+ const pkgJsonPath = path.resolve(entryContextDir, 'package.json');
489
+ const pkgJson = fs.existsSync(pkgJsonPath)
490
+ ? readJSON(pkgJsonPath)
465
491
  : undefined;
466
492
  if (pkgJson) {
467
- util_1.debug('located package.json path', pkgJsonPath);
493
+ debug('located package.json path', pkgJsonPath);
468
494
  }
469
- const autoGeneratedTocPath = upath_1.default.resolve(workspaceDir, typeof (config === null || config === void 0 ? void 0 : config.toc) === 'string' ? config.toc : const_1.TOC_FILENAME);
470
- const projectTitle = (_b = (_a = cliFlags.title) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.title) !== null && _b !== void 0 ? _b : pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.name;
471
- const projectAuthor = (_d = (_c = cliFlags.author) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config.author) !== null && _d !== void 0 ? _d : pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.author;
495
+ const autoGeneratedTocPath = path.resolve(workspaceDir, typeof config?.toc === 'string' ? config.toc : TOC_FILENAME);
496
+ const projectTitle = cliFlags.title ?? config?.title ?? pkgJson?.name;
497
+ const projectAuthor = cliFlags.author ?? config?.author ?? pkgJson?.author;
472
498
  function parseEntry(entry) {
473
- var _a, _b, _c, _d, _e, _f, _g;
474
499
  if (!('path' in entry)) {
475
- const theme = (_a = parseTheme(entry.theme, context, workspaceDir)) !== null && _a !== void 0 ? _a : themeIndexes[0];
476
- if (theme &&
477
- themeIndexes.every((t) => !util_1.pathEquals(t.location, theme.location))) {
478
- themeIndexes.push(theme);
479
- }
500
+ const themes = entry.theme
501
+ ? [entry.theme].flat().map((theme) => parseTheme({
502
+ theme,
503
+ context,
504
+ workspaceDir,
505
+ themesDir,
506
+ }))
507
+ : [...rootThemes];
508
+ themes.forEach((t) => themeIndexes.add(t));
480
509
  return {
481
510
  rel: 'contents',
482
511
  target: autoGeneratedTocPath,
483
- title: (_c = (_b = entry.title) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config.tocTitle) !== null && _c !== void 0 ? _c : const_1.TOC_TITLE,
484
- theme,
512
+ title: entry.title ?? config?.tocTitle ?? TOC_TITLE,
513
+ themes,
485
514
  };
486
515
  }
487
- const sourcePath = upath_1.default.resolve(entryContextDir, entry.path); // abs
488
- const contextEntryPath = upath_1.default.relative(entryContextDir, sourcePath); // rel
489
- const targetPath = upath_1.default
516
+ const sourcePath = path.resolve(entryContextDir, entry.path); // abs
517
+ const contextEntryPath = path.relative(entryContextDir, sourcePath); // rel
518
+ const targetPath = path
490
519
  .resolve(workspaceDir, contextEntryPath)
491
520
  .replace(/\.md$/, '.html');
492
- if (!util_1.isUrlString(sourcePath)) {
521
+ if (!isUrlString(sourcePath)) {
493
522
  // Check file exists
494
- util_1.statFileSync(sourcePath);
495
- }
496
- const type = input_1.detectManuscriptMediaType(sourcePath);
497
- const metadata = parseFileMetadata(type, sourcePath, workspaceDir);
498
- const title = (_e = (_d = entry.title) !== null && _d !== void 0 ? _d : metadata.title) !== null && _e !== void 0 ? _e : projectTitle;
499
- const theme = (_g = (_f = parseTheme(entry.theme, context, workspaceDir)) !== null && _f !== void 0 ? _f : metadata.theme) !== null && _g !== void 0 ? _g : themeIndexes[0];
500
- if (theme &&
501
- themeIndexes.every((t) => !util_1.pathEquals(t.location, theme.location))) {
502
- themeIndexes.push(theme);
523
+ statFileSync(sourcePath);
503
524
  }
525
+ const type = detectManuscriptMediaType(sourcePath);
526
+ const metadata = parseFileMetadata({
527
+ type,
528
+ sourcePath,
529
+ workspaceDir,
530
+ themesDir,
531
+ });
532
+ const title = entry.title ?? metadata.title ?? projectTitle;
533
+ const themes = entry.theme
534
+ ? [entry.theme]
535
+ .flat()
536
+ .map((theme) => parseTheme({ theme, context, workspaceDir, themesDir }))
537
+ : metadata.themes ?? [...rootThemes];
538
+ themes.forEach((t) => themeIndexes.add(t));
504
539
  return {
505
540
  type,
506
541
  source: sourcePath,
507
542
  target: targetPath,
508
543
  title,
509
- theme,
544
+ themes,
510
545
  ...(entry.rel && { rel: entry.rel }),
511
546
  };
512
547
  }
513
- const entries = (config === null || config === void 0 ? void 0 : config.entry)
548
+ const entries = config?.entry
514
549
  ? (Array.isArray(config.entry) ? config.entry : [config.entry])
515
550
  .map(normalizeEntry)
516
551
  .map(parseEntry)
@@ -524,16 +559,16 @@ async function composeProjectConfig(otherConfig, cliFlags, config, context) {
524
559
  fallbackProjectTitle = entries[0].title;
525
560
  }
526
561
  else {
527
- fallbackProjectTitle = upath_1.default.basename(outputs[0].path);
528
- util_1.log(`\n${chalk_1.default.yellow('Could not find any appropriate publication title. We set ')}${chalk_1.default.bold.yellow(`"${fallbackProjectTitle}"`)}${chalk_1.default.yellow(' as a fallback.')}`);
562
+ fallbackProjectTitle = path.basename(outputs[0].path);
563
+ log(`\n${chalk.yellow('Could not find any appropriate publication title. We set ')}${chalk.bold.yellow(`"${fallbackProjectTitle}"`)}${chalk.yellow(' as a fallback.')}`);
529
564
  }
530
565
  }
531
- if (!!(config === null || config === void 0 ? void 0 : config.toc) && !entries.find(({ rel }) => rel === 'contents')) {
566
+ if (!!config?.toc && !entries.find(({ rel }) => rel === 'contents')) {
532
567
  entries.unshift({
533
568
  rel: 'contents',
534
569
  target: autoGeneratedTocPath,
535
- title: (_e = config === null || config === void 0 ? void 0 : config.tocTitle) !== null && _e !== void 0 ? _e : const_1.TOC_TITLE,
536
- theme: themeIndexes[0],
570
+ title: config?.tocTitle ?? TOC_TITLE,
571
+ themes: [...rootThemes],
537
572
  });
538
573
  }
539
574
  return {
@@ -541,17 +576,17 @@ async function composeProjectConfig(otherConfig, cliFlags, config, context) {
541
576
  entries,
542
577
  input: {
543
578
  format: 'pub-manifest',
544
- entry: upath_1.default.join(workspaceDir, const_1.MANIFEST_FILENAME),
579
+ entry: path.join(workspaceDir, MANIFEST_FILENAME),
545
580
  },
546
581
  exportAliases: [],
547
- manifestPath: upath_1.default.join(workspaceDir, const_1.MANIFEST_FILENAME),
582
+ manifestPath: path.join(workspaceDir, MANIFEST_FILENAME),
548
583
  manifestAutoGenerate: {
549
584
  title: projectTitle || fallbackProjectTitle,
550
585
  author: projectAuthor || '',
551
586
  },
552
587
  };
553
588
  }
554
- function checkUnusedCliFlags(config, cliFlags) {
589
+ export function checkUnusedCliFlags(config, cliFlags) {
555
590
  const unusedFlags = [];
556
591
  if (!config.manifestPath) {
557
592
  if (cliFlags.theme) {
@@ -568,11 +603,10 @@ function checkUnusedCliFlags(config, cliFlags) {
568
603
  }
569
604
  }
570
605
  if (unusedFlags.length) {
571
- util_1.log('\n');
606
+ log('\n');
572
607
  unusedFlags.forEach((flag) => {
573
- util_1.log(`${chalk_1.default.bold.yellow(flag)}${chalk_1.default.bold.yellow(` flag seems to be set but the current export setting doesn't support this. This option will be ignored.`)}`);
608
+ log(`${chalk.bold.yellow(flag)}${chalk.bold.yellow(` flag seems to be set but the current export setting doesn't support this. This option will be ignored.`)}`);
574
609
  });
575
610
  }
576
611
  }
577
- exports.checkUnusedCliFlags = checkUnusedCliFlags;
578
612
  //# sourceMappingURL=config.js.map