@vivliostyle/cli 10.3.0 → 10.3.1

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 (37) hide show
  1. package/README.md +7 -4
  2. package/dist/{chunk-3QOSSWIX.js → chunk-7GIJVX4M.js} +15 -5
  3. package/dist/chunk-7GIJVX4M.js.map +1 -0
  4. package/dist/{chunk-YNX6D2I6.js → chunk-C4HQHRXQ.js} +23 -8
  5. package/dist/chunk-C4HQHRXQ.js.map +1 -0
  6. package/dist/{chunk-RILZCPJE.js → chunk-DBK27BAR.js} +19 -12
  7. package/dist/chunk-DBK27BAR.js.map +1 -0
  8. package/dist/{chunk-ALY3QX7K.js → chunk-ERDN47XG.js} +10 -17
  9. package/dist/{chunk-ALY3QX7K.js.map → chunk-ERDN47XG.js.map} +1 -1
  10. package/dist/{chunk-NVNEYZ3J.js → chunk-LGOHUEEQ.js} +5 -5
  11. package/dist/{chunk-WIGLU3EK.js → chunk-LWMSAGHL.js} +4 -4
  12. package/dist/{chunk-RBKPG6VU.js → chunk-MU7JCDMK.js} +2 -2
  13. package/dist/{chunk-ZEBXHUJX.js → chunk-OAFXM4ES.js} +4 -4
  14. package/dist/chunk-OAFXM4ES.js.map +1 -0
  15. package/dist/{chunk-QLK3XMQI.js → chunk-PYPAYBFL.js} +170 -112
  16. package/dist/chunk-PYPAYBFL.js.map +1 -0
  17. package/dist/cli.js +1 -1
  18. package/dist/commands/build.js +13 -7
  19. package/dist/commands/build.js.map +1 -1
  20. package/dist/commands/create.js +11 -5
  21. package/dist/commands/create.js.map +1 -1
  22. package/dist/commands/init.js +4 -4
  23. package/dist/commands/preview.js +13 -7
  24. package/dist/commands/preview.js.map +1 -1
  25. package/dist/config/schema.d.ts +827 -810
  26. package/dist/config/schema.js +2 -2
  27. package/dist/index.js +9 -9
  28. package/dist/vite-adapter.js +5 -5
  29. package/package.json +3 -3
  30. package/dist/chunk-3QOSSWIX.js.map +0 -1
  31. package/dist/chunk-QLK3XMQI.js.map +0 -1
  32. package/dist/chunk-RILZCPJE.js.map +0 -1
  33. package/dist/chunk-YNX6D2I6.js.map +0 -1
  34. package/dist/chunk-ZEBXHUJX.js.map +0 -1
  35. /package/dist/{chunk-NVNEYZ3J.js.map → chunk-LGOHUEEQ.js.map} +0 -0
  36. /package/dist/{chunk-WIGLU3EK.js.map → chunk-LWMSAGHL.js.map} +0 -0
  37. /package/dist/{chunk-RBKPG6VU.js.map → chunk-MU7JCDMK.js.map} +0 -0
@@ -8,12 +8,12 @@ import {
8
8
  registerExitHandler,
9
9
  toTitleCase,
10
10
  whichPm
11
- } from "./chunk-RILZCPJE.js";
11
+ } from "./chunk-DBK27BAR.js";
12
12
  import {
13
13
  ValidString,
14
14
  VivliostyleInlineConfigWithoutChecks,
15
15
  VivliostylePackageMetadata
16
- } from "./chunk-3QOSSWIX.js";
16
+ } from "./chunk-7GIJVX4M.js";
17
17
  import {
18
18
  DEFAULT_CONFIG_FILENAME,
19
19
  DEFAULT_PROJECT_AUTHOR,
@@ -23,7 +23,7 @@ import {
23
23
  cliVersion,
24
24
  coreVersion,
25
25
  languages
26
- } from "./chunk-ZEBXHUJX.js";
26
+ } from "./chunk-OAFXM4ES.js";
27
27
  import {
28
28
  __callDispose,
29
29
  __using
@@ -113,6 +113,7 @@ import {
113
113
  } from "yoctocolors";
114
114
  async function askQuestion({
115
115
  question: questions,
116
+ interactiveLogger,
116
117
  schema,
117
118
  validateProgressMessage
118
119
  }) {
@@ -166,10 +167,15 @@ async function askQuestion({
166
167
  process.exit(0);
167
168
  }
168
169
  response[name] = result2;
170
+ interactiveLogger.messageHistory.push({
171
+ type: "question",
172
+ message: question.message,
173
+ answer: result2
174
+ });
169
175
  }
170
176
  let result;
171
177
  if (schema && schema.async) {
172
- result = await interactiveLogLoading(
178
+ result = await interactiveLogger?.logLoading(
173
179
  validateProgressMessage ?? "",
174
180
  () => v.safeParseAsync(schema, response)
175
181
  );
@@ -182,7 +188,7 @@ async function askQuestion({
182
188
  if (success) {
183
189
  return output;
184
190
  }
185
- interactiveLogWarn(issues[0].message);
191
+ interactiveLogger.logWarn(issues[0].message);
186
192
  }
187
193
  }
188
194
  var promptStateSymbol = {
@@ -377,93 +383,102 @@ ${userInputText}`;
377
383
  function autocompleteMultiSelectPrompt(opts) {
378
384
  return autocompletePrompt(opts, true);
379
385
  }
380
- async function interactiveLogLoading(message, fn, deferredTimeMs = 300) {
381
- if (!Logger.isInteractive) {
382
- return await fn();
383
- }
384
- const output = Logger.stdout;
385
- const columns = getColumns(output);
386
- const showMessage = (msg) => {
387
- const wrapped = wrapAnsi(msg, columns, { hard: true, trim: false });
388
- output.write(wrapped);
389
- return () => {
390
- const prevLines = wrapped.split("\n");
391
- if (prevLines.length > 1) {
392
- output.write(cursor.up(prevLines.length - 1));
393
- }
394
- output.write(cursor.to(0));
395
- output.write(erase.down());
386
+ var InteractiveLogger = class {
387
+ messageHistory = [];
388
+ async logLoading(message, fn, deferredTimeMs = 300) {
389
+ this.messageHistory.push({ type: "loading", message });
390
+ if (!Logger.isInteractive || import.meta.env?.VITEST) {
391
+ return await fn();
392
+ }
393
+ const output = Logger.stdout;
394
+ const columns = getColumns(output);
395
+ const showMessage = (msg) => {
396
+ const wrapped = wrapAnsi(msg, columns, { hard: true, trim: false });
397
+ output.write(wrapped);
398
+ return () => {
399
+ const prevLines = wrapped.split("\n");
400
+ if (prevLines.length > 1) {
401
+ output.write(cursor.up(prevLines.length - 1));
402
+ }
403
+ output.write(cursor.to(0));
404
+ output.write(erase.down());
405
+ };
396
406
  };
397
- };
398
- let timer;
399
- let clearMessage;
400
- const promise = new Promise((resolve) => {
401
- timer = setTimeout(() => {
402
- output.write(`${blueBright("\u2551")}
407
+ let timer;
408
+ let clearMessage;
409
+ const promise = new Promise((resolve) => {
410
+ timer = setTimeout(() => {
411
+ output.write(`${blueBright("\u2551")}
403
412
  `);
404
- clearMessage = showMessage(
405
- `${blueBright(`${promptStateSymbol.active}\u2500`)} ${dim(message)}
413
+ clearMessage = showMessage(
414
+ `${blueBright(`${promptStateSymbol.active}\u2500`)} ${dim(message)}
406
415
  `
416
+ );
417
+ resolve();
418
+ }, deferredTimeMs);
419
+ });
420
+ const result = await fn().then((r) => {
421
+ if (!clearMessage) {
422
+ return r;
423
+ }
424
+ return new Promise(
425
+ (resolve) => setTimeout(() => resolve(r), deferredTimeMs)
407
426
  );
408
- resolve();
409
- }, deferredTimeMs);
410
- });
411
- const result = await fn().then((r) => {
412
- if (!clearMessage) {
413
- return r;
414
- }
415
- return new Promise(
416
- (resolve) => setTimeout(() => resolve(r), deferredTimeMs)
417
- );
418
- }).catch(async (e) => {
419
- await promise;
420
- clearMessage?.();
421
- showMessage(
422
- `${redBright(`${promptStateSymbol.error}\u2500`)} ${dim(message)}
427
+ }).catch(async (e) => {
428
+ await promise;
429
+ clearMessage?.();
430
+ showMessage(
431
+ `${redBright(`${promptStateSymbol.error}\u2500`)} ${dim(message)}
423
432
 
424
433
  `
425
- );
426
- throw e;
427
- });
428
- clearTimeout(timer);
429
- if (clearMessage) {
430
- clearMessage();
431
- showMessage(
432
- `${blueBright(`${promptStateSymbol.submit}\u2500`)} ${dim(message)}
434
+ );
435
+ throw e;
436
+ });
437
+ clearTimeout(timer);
438
+ if (clearMessage) {
439
+ clearMessage();
440
+ showMessage(
441
+ `${blueBright(`${promptStateSymbol.submit}\u2500`)} ${dim(message)}
433
442
  `
434
- );
435
- }
436
- return result;
437
- }
438
- function interactiveLogInfo(message) {
439
- if (import.meta.env?.VITEST) {
440
- return;
443
+ );
444
+ }
445
+ return result;
441
446
  }
442
- Logger.stdout.write(
443
- `${blueBright(`${promptStateSymbol.submit}\u2500`)} ${message.split("\n").join(`
447
+ logInfo(message) {
448
+ this.messageHistory.push({ type: "info", message });
449
+ if (import.meta.env?.VITEST) {
450
+ return;
451
+ }
452
+ Logger.stdout.write(
453
+ `${blueBright(`${promptStateSymbol.submit}\u2500`)} ${message.split("\n").join(`
444
454
  ${blueBright("\u2551")} `)}
445
455
  `
446
- );
447
- }
448
- function interactiveLogWarn(message) {
449
- if (import.meta.env?.VITEST) {
450
- return;
456
+ );
451
457
  }
452
- Logger.stdout.write(
453
- `${yellowBright(`${promptStateSymbol.error}\u2500`)} ${yellowBright(message.split("\n").join(`
458
+ logWarn(message) {
459
+ this.messageHistory.push({ type: "warn", message });
460
+ if (import.meta.env?.VITEST) {
461
+ return;
462
+ }
463
+ Logger.stdout.write(
464
+ `${yellowBright(`${promptStateSymbol.error}\u2500`)} ${yellowBright(message.split("\n").join(`
454
465
  ${yellowBright("\u2551")} `))}
455
466
  `
456
- );
457
- }
458
- function interactiveLogOutro(message) {
459
- if (import.meta.env?.VITEST) {
460
- return;
467
+ );
461
468
  }
462
- Logger.stdout.write(`${blueBright("\u2551")}
469
+ logOutro(message) {
470
+ this.messageHistory.push({ type: "outro", message });
471
+ if (import.meta.env?.VITEST) {
472
+ return;
473
+ }
474
+ Logger.stdout.write(
475
+ `${blueBright("\u2551")}
463
476
  ${blueBright("\u2559\u2500")} ${message}
464
477
 
465
- `);
466
- }
478
+ `
479
+ );
480
+ }
481
+ };
467
482
 
468
483
  // src/npm.ts
469
484
  import { fetch as _fetch } from "node-fetch-native";
@@ -517,6 +532,7 @@ async function create(inlineConfig) {
517
532
  Logger.setLogOptions(inlineConfig);
518
533
  Logger.debug("create > inlineConfig %O", inlineConfig);
519
534
  const fetch = createFetch(inlineConfig);
535
+ const interactiveLogger = new InteractiveLogger();
520
536
  let {
521
537
  projectPath,
522
538
  cwd: cwd2 = cwd,
@@ -525,29 +541,34 @@ async function create(inlineConfig) {
525
541
  language,
526
542
  theme,
527
543
  template,
544
+ installDependencies,
528
545
  createConfigFileOnly = false
529
546
  } = inlineConfig;
530
547
  let extraTemplateVariables = {};
531
548
  let themePackage;
532
- let installDependencies;
533
549
  let useLocalTemplate = false;
534
550
  if (template && !/^([\w-.]+):/.test(template)) {
535
551
  const absTemplatePath = upath.resolve(cwd2, template);
536
552
  useLocalTemplate = fs.existsSync(upath.resolve(cwd2, template)) && fs.statSync(upath.resolve(cwd2, template)).isDirectory();
553
+ const usingPresetTemplate = TEMPLATE_SETTINGS.find(
554
+ (t) => t.value === template
555
+ );
537
556
  if (useLocalTemplate) {
538
557
  template = absTemplatePath;
539
- interactiveLogInfo(
558
+ interactiveLogger.logInfo(
540
559
  `Using the specified local template directory
541
560
  ${dim2(upath.relative(cwd2, absTemplatePath) || ".")}`
542
561
  );
562
+ } else if (usingPresetTemplate) {
563
+ template = usingPresetTemplate.template;
543
564
  } else {
544
- interactiveLogWarn(
565
+ interactiveLogger.logWarn(
545
566
  `The specified theme ${green2(template)} was not found as a local directory. Proceeding to fetch it from GitHub repository.`
546
567
  );
547
568
  }
548
569
  }
549
570
  if (!projectPath) {
550
- ({ projectPath } = await askProjectPath());
571
+ ({ projectPath } = await askProjectPath({ interactiveLogger }));
551
572
  }
552
573
  const dist = upath.join(cwd2, projectPath);
553
574
  if (createConfigFileOnly) {
@@ -558,35 +579,41 @@ ${dim2(upath.relative(cwd2, absTemplatePath) || ".")}`
558
579
  throw new Error(`Destination ${dist} is not empty.`);
559
580
  }
560
581
  if (!title) {
561
- ({ title } = createConfigFileOnly ? { title: DEFAULT_PROJECT_TITLE } : await askTitle({ projectPath }));
582
+ ({ title } = createConfigFileOnly ? { title: DEFAULT_PROJECT_TITLE } : await askTitle({ projectPath, interactiveLogger }));
562
583
  }
563
584
  if (!author) {
564
- ({ author } = createConfigFileOnly ? { author: DEFAULT_PROJECT_AUTHOR } : await askAuthor());
585
+ ({ author } = createConfigFileOnly ? { author: DEFAULT_PROJECT_AUTHOR } : await askAuthor({ interactiveLogger }));
565
586
  }
566
587
  if (!language) {
567
- ({ language } = createConfigFileOnly ? { language: await getOsLocale() } : await askLanguage());
588
+ ({ language } = createConfigFileOnly ? { language: await getOsLocale() } : await askLanguage({ interactiveLogger }));
568
589
  }
569
590
  if (!createConfigFileOnly) {
570
591
  let presetTemplate;
571
592
  if (!template) {
572
- ({ presetTemplate } = await askPresetTemplate());
593
+ ({ presetTemplate } = await askPresetTemplate({ interactiveLogger }));
573
594
  if (presetTemplate) {
574
595
  template = presetTemplate.template;
575
596
  }
576
597
  }
577
- if (!theme) {
598
+ if (!theme && theme !== false) {
578
599
  ({ theme, themePackage } = await askTheme({
579
600
  presetTemplate,
580
601
  template,
581
- fetch
602
+ fetch,
603
+ interactiveLogger
582
604
  }));
583
605
  }
584
606
  if (!template) {
585
- ({ template, extraTemplateVariables } = await askThemeTemplate(
586
- themePackage?.vivliostyle
587
- ));
607
+ ({ template, extraTemplateVariables } = await askThemeTemplate({
608
+ themeMetadata: themePackage?.vivliostyle,
609
+ interactiveLogger
610
+ }));
611
+ }
612
+ if (typeof installDependencies !== "boolean") {
613
+ ({ installDependencies } = await askInstallDependencies({
614
+ interactiveLogger
615
+ }));
588
616
  }
589
- ({ installDependencies } = await askInstallDependencies());
590
617
  }
591
618
  const browserType = "chrome";
592
619
  const browserTag = getDefaultBrowserTag(browserType);
@@ -625,7 +652,11 @@ ${dim2(upath.relative(cwd2, absTemplatePath) || ".")}`
625
652
  } else {
626
653
  var _stack2 = [];
627
654
  try {
628
- interactiveLogOutro("All configurations are set! Creating your project...");
655
+ if (interactiveLogger.messageHistory.length > 0) {
656
+ interactiveLogger.logOutro(
657
+ "All configurations are set! Creating your project..."
658
+ );
659
+ }
629
660
  const _3 = __using(_stack2, Logger.startLogging(
630
661
  useLocalTemplate ? "Copying a local template" : "Downloading a template"
631
662
  ));
@@ -675,7 +706,9 @@ ${dim2(upath.relative(cwd2, absTemplatePath) || ".")}`
675
706
  });
676
707
  }
677
708
  }
678
- async function askProjectPath() {
709
+ async function askProjectPath({
710
+ interactiveLogger
711
+ }) {
679
712
  return await askQuestion({
680
713
  question: {
681
714
  projectPath: {
@@ -687,10 +720,14 @@ async function askProjectPath() {
687
720
  },
688
721
  schema: v2.required(
689
722
  v2.pick(VivliostyleInlineConfigWithoutChecks, ["projectPath"])
690
- )
723
+ ),
724
+ interactiveLogger
691
725
  });
692
726
  }
693
- async function askTitle({ projectPath }) {
727
+ async function askTitle({
728
+ projectPath,
729
+ interactiveLogger
730
+ }) {
694
731
  return await askQuestion({
695
732
  question: {
696
733
  title: {
@@ -700,10 +737,13 @@ async function askTitle({ projectPath }) {
700
737
  placeholder: toTitleCase(projectPath) || DEFAULT_PROJECT_TITLE
701
738
  }
702
739
  },
703
- schema: v2.required(v2.pick(VivliostyleInlineConfigWithoutChecks, ["title"]))
740
+ schema: v2.required(v2.pick(VivliostyleInlineConfigWithoutChecks, ["title"])),
741
+ interactiveLogger
704
742
  });
705
743
  }
706
- async function askAuthor() {
744
+ async function askAuthor({
745
+ interactiveLogger
746
+ }) {
707
747
  return await askQuestion({
708
748
  question: {
709
749
  author: {
@@ -715,10 +755,13 @@ async function askAuthor() {
715
755
  },
716
756
  schema: v2.required(
717
757
  v2.pick(VivliostyleInlineConfigWithoutChecks, ["author"])
718
- )
758
+ ),
759
+ interactiveLogger
719
760
  });
720
761
  }
721
- async function askLanguage() {
762
+ async function askLanguage({
763
+ interactiveLogger
764
+ }) {
722
765
  const initialValue = await getOsLocale();
723
766
  return await askQuestion({
724
767
  question: {
@@ -735,11 +778,14 @@ async function askLanguage() {
735
778
  },
736
779
  schema: v2.required(
737
780
  v2.pick(VivliostyleInlineConfigWithoutChecks, ["language"])
738
- )
781
+ ),
782
+ interactiveLogger
739
783
  });
740
784
  }
741
785
  var PRESET_TEMPLATE_NOT_USE = "Use templates from the community theme";
742
- async function askPresetTemplate() {
786
+ async function askPresetTemplate({
787
+ interactiveLogger
788
+ }) {
743
789
  const { presetTemplate } = await askQuestion({
744
790
  question: {
745
791
  presetTemplate: {
@@ -762,7 +808,8 @@ async function askPresetTemplate() {
762
808
  (value) => value === PRESET_TEMPLATE_NOT_USE ? void 0 : TEMPLATE_SETTINGS.find((t) => t.value === value)
763
809
  )
764
810
  )
765
- })
811
+ }),
812
+ interactiveLogger
766
813
  });
767
814
  return { presetTemplate };
768
815
  }
@@ -776,10 +823,11 @@ var THEME_ANSWER_MANUAL = "Install other themes from npm";
776
823
  async function askTheme({
777
824
  template,
778
825
  presetTemplate,
779
- fetch
826
+ fetch,
827
+ interactiveLogger
780
828
  }) {
781
829
  const useCommunityThemes = !presetTemplate && !template;
782
- const themePackages = await interactiveLogLoading(
830
+ const themePackages = await interactiveLogger.logLoading(
783
831
  "Fetching a list of Vivliostyle themes...",
784
832
  async () => {
785
833
  let themes = (await listVivliostyleThemes({ fetch })).objects;
@@ -842,7 +890,8 @@ async function askTheme({
842
890
  }
843
891
  },
844
892
  schema: v2.objectAsync({ theme: validateThemeMetadataSchema }),
845
- validateProgressMessage: "Fetching package metadata..."
893
+ validateProgressMessage: "Fetching package metadata...",
894
+ interactiveLogger
846
895
  });
847
896
  if (theme === THEME_ANSWER_NOT_USE) {
848
897
  return { theme: void 0, themePackage: void 0 };
@@ -877,7 +926,8 @@ async function askTheme({
877
926
  validateThemeMetadataSchema
878
927
  )
879
928
  }),
880
- validateProgressMessage: "Fetching package metadata..."
929
+ validateProgressMessage: "Fetching package metadata...",
930
+ interactiveLogger
881
931
  }).then((ret) => ret.themeManualInput);
882
932
  }
883
933
  return {
@@ -887,7 +937,10 @@ async function askTheme({
887
937
  themePackage
888
938
  };
889
939
  }
890
- async function askThemeTemplate(themeMetadata) {
940
+ async function askThemeTemplate({
941
+ interactiveLogger,
942
+ themeMetadata
943
+ }) {
891
944
  const themeTemplate = themeMetadata?.template;
892
945
  const options = Object.entries(themeTemplate || {}).map(([value, tmpl]) => ({
893
946
  label: tmpl.name || value,
@@ -895,7 +948,7 @@ async function askThemeTemplate(themeMetadata) {
895
948
  hint: truncateString(tmpl.description || "")
896
949
  }));
897
950
  if (!themeTemplate || options.length === 0) {
898
- interactiveLogWarn(
951
+ interactiveLogger.logWarn(
899
952
  "The chosen theme does not set template settings. Applying the minimal template."
900
953
  );
901
954
  return {
@@ -916,19 +969,23 @@ async function askThemeTemplate(themeMetadata) {
916
969
  v2.string(),
917
970
  v2.transform((input) => themeTemplate[input])
918
971
  )
919
- })
972
+ }),
973
+ interactiveLogger
920
974
  });
921
975
  let extraTemplateVariables = {};
922
976
  if (usingTemplate.prompt?.length) {
923
977
  extraTemplateVariables = await askQuestion({
924
978
  question: Object.fromEntries(
925
979
  usingTemplate.prompt.map((q) => [q.name, q])
926
- )
980
+ ),
981
+ interactiveLogger
927
982
  });
928
983
  }
929
984
  return { template: usingTemplate.source, extraTemplateVariables };
930
985
  }
931
- async function askInstallDependencies() {
986
+ async function askInstallDependencies({
987
+ interactiveLogger
988
+ }) {
932
989
  return await askQuestion({
933
990
  question: {
934
991
  installDependencies: {
@@ -942,7 +999,8 @@ async function askInstallDependencies() {
942
999
  },
943
1000
  schema: v2.object({
944
1001
  installDependencies: v2.boolean()
945
- })
1002
+ }),
1003
+ interactiveLogger
946
1004
  });
947
1005
  }
948
1006
  async function setupTemplate({
@@ -1080,4 +1138,4 @@ For more information, visit ${terminalLink(yellow2("https://docs.vivliostyle.org
1080
1138
  export {
1081
1139
  create
1082
1140
  };
1083
- //# sourceMappingURL=chunk-QLK3XMQI.js.map
1141
+ //# sourceMappingURL=chunk-PYPAYBFL.js.map