@gravito/constellation 2.0.0 → 3.0.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.
package/dist/index.cjs CHANGED
@@ -674,10 +674,9 @@ var SitemapGenerator = class {
674
674
  baseUrl: this.options.baseUrl,
675
675
  pretty: this.options.pretty
676
676
  });
677
+ let isMultiFile = false;
677
678
  const flushShard = async () => {
678
- if (currentCount === 0) {
679
- return;
680
- }
679
+ isMultiFile = true;
681
680
  const baseName = this.options.filename?.replace(/\.xml$/, "");
682
681
  const filename = `${baseName}-${shardIndex}.xml`;
683
682
  const xml = currentStream.toXML();
@@ -718,7 +717,22 @@ var SitemapGenerator = class {
718
717
  }
719
718
  }
720
719
  }
721
- await flushShard();
720
+ if (!isMultiFile) {
721
+ const xml = currentStream.toXML();
722
+ if (this.shadowProcessor) {
723
+ await this.shadowProcessor.addOperation({
724
+ filename: this.options.filename,
725
+ content: xml
726
+ });
727
+ await this.shadowProcessor.commit();
728
+ } else {
729
+ await this.options.storage.write(this.options.filename, xml);
730
+ }
731
+ return;
732
+ }
733
+ if (currentCount > 0) {
734
+ await flushShard();
735
+ }
722
736
  const indexXml = index.toXML();
723
737
  if (this.shadowProcessor) {
724
738
  await this.shadowProcessor.addOperation({
@@ -962,7 +976,7 @@ var GenerateSitemapJob = class extends import_stream.Job {
962
976
  this.generator = new SitemapGenerator(options.generatorOptions);
963
977
  }
964
978
  async handle() {
965
- const { progressTracker, shadowProcessor, onProgress, onComplete, onError } = this.options;
979
+ const { progressTracker, onComplete, onError } = this.options;
966
980
  try {
967
981
  if (progressTracker) {
968
982
  const total = await this.calculateTotal();
@@ -970,8 +984,8 @@ var GenerateSitemapJob = class extends import_stream.Job {
970
984
  this.totalEntries = total;
971
985
  }
972
986
  await this.generateWithProgress();
973
- if (shadowProcessor) {
974
- await shadowProcessor.commit();
987
+ if (this.options.shadowProcessor) {
988
+ await this.options.shadowProcessor.commit();
975
989
  }
976
990
  if (progressTracker) {
977
991
  await progressTracker.complete();
@@ -1012,15 +1026,7 @@ var GenerateSitemapJob = class extends import_stream.Job {
1012
1026
  * 帶進度追蹤的生成
1013
1027
  */
1014
1028
  async generateWithProgress() {
1015
- const { progressTracker, shadowProcessor, onProgress } = this.options;
1016
- const {
1017
- providers,
1018
- maxEntriesPerFile = 5e4,
1019
- storage,
1020
- baseUrl,
1021
- pretty,
1022
- filename
1023
- } = this.options.generatorOptions;
1029
+ const { progressTracker, onProgress } = this.options;
1024
1030
  await this.generator.run();
1025
1031
  this.processedEntries = this.totalEntries;
1026
1032
  if (progressTracker) {
@@ -1259,7 +1265,7 @@ var OrbitSitemap = class _OrbitSitemap {
1259
1265
  if (this.mode === "dynamic") {
1260
1266
  this.installDynamic(core);
1261
1267
  } else {
1262
- console.log("[OrbitSitemap] Static mode configured. Use generate() to build sitemaps.");
1268
+ core.logger.info("[OrbitSitemap] Static mode configured. Use generate() to build sitemaps.");
1263
1269
  }
1264
1270
  }
1265
1271
  installDynamic(core) {
@@ -1525,6 +1531,11 @@ var RouteScanner = class {
1525
1531
  ...options
1526
1532
  };
1527
1533
  }
1534
+ /**
1535
+ * Scan the router and return discovered entries.
1536
+ *
1537
+ * @returns An array of sitemap entries.
1538
+ */
1528
1539
  getEntries() {
1529
1540
  const entries = [];
1530
1541
  const routes = this.extractRoutes(this.router);