@lexibase/rdx-core 3.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.
@@ -1,5 +1,5 @@
1
1
  // src/config/index.ts
2
- import path6 from "path";
2
+ import path7 from "path";
3
3
  import { existsSync, readdirSync } from "fs";
4
4
 
5
5
  // src/config/error.ts
@@ -578,6 +578,90 @@ function getEditPageHref(project, source, sourcePath) {
578
578
  return url.href;
579
579
  }
580
580
 
581
+ // src/config/document-dates.ts
582
+ import { execFileSync } from "child_process";
583
+ import fs5 from "fs";
584
+ import path6 from "path";
585
+ var snapshotDatesFilename = "_rdx-last-updated.json";
586
+ var datePattern = /^\d{4}-\d{2}-\d{2}$/;
587
+ function relativeFile(root, file) {
588
+ const relative = path6.relative(root, file);
589
+ if (!relative || path6.isAbsolute(relative) || relative.split(path6.sep)[0] === "..")
590
+ return;
591
+ return relative.split(path6.sep).join("/");
592
+ }
593
+ function createDocumentDateReader(root) {
594
+ const git = (...args) => execFileSync("git", ["--literal-pathspecs", ...args], {
595
+ cwd: root,
596
+ encoding: "utf8",
597
+ stdio: ["ignore", "pipe", "pipe"],
598
+ timeout: 3e3,
599
+ windowsHide: true
600
+ }).trim();
601
+ let shallow;
602
+ try {
603
+ shallow = git("rev-parse", "--is-shallow-repository") === "true";
604
+ } catch {
605
+ return () => void 0;
606
+ }
607
+ return (file) => {
608
+ const relative = relativeFile(root, file);
609
+ if (!relative) return;
610
+ try {
611
+ git("ls-files", "--error-unmatch", "--", relative);
612
+ git("diff", "--quiet", "--no-ext-diff", "HEAD", "--", relative);
613
+ const [date, parents] = git(
614
+ "log",
615
+ "-1",
616
+ "--format=%cs%x00%P",
617
+ "HEAD",
618
+ "--",
619
+ relative
620
+ ).split("\0");
621
+ if (date && datePattern.test(date) && (!shallow || parents)) return date;
622
+ } catch {
623
+ }
624
+ };
625
+ }
626
+ function collectSnapshotDocumentDates(directory, dateFor) {
627
+ const dates = /* @__PURE__ */ Object.create(null);
628
+ function visit(folder) {
629
+ for (const entry of fs5.readdirSync(
630
+ /* turbopackIgnore: true */
631
+ folder,
632
+ { withFileTypes: true }
633
+ ).sort((a, b) => a.name.localeCompare(b.name, "en"))) {
634
+ const file = path6.join(folder, entry.name);
635
+ if (entry.isDirectory()) visit(file);
636
+ else if (entry.isFile() && /\.mdx?$/.test(entry.name)) {
637
+ const date = dateFor(file);
638
+ if (date) dates[relativeFile(directory, file)] = date;
639
+ }
640
+ }
641
+ }
642
+ visit(directory);
643
+ return Object.keys(dates).length ? JSON.stringify(dates, null, 2) + "\n" : void 0;
644
+ }
645
+ function getSnapshotDocumentDate(directory, file) {
646
+ const relative = relativeFile(directory, file);
647
+ if (!relative) return;
648
+ try {
649
+ const filename = path6.join(directory, snapshotDatesFilename);
650
+ const dates = JSON.parse(
651
+ fs5.readFileSync(
652
+ /* turbopackIgnore: true */
653
+ filename,
654
+ "utf8"
655
+ )
656
+ );
657
+ if (!dates || typeof dates !== "object" || !Object.hasOwn(dates, relative))
658
+ return;
659
+ const date = dates[relative];
660
+ if (typeof date === "string" && datePattern.test(date)) return date;
661
+ } catch {
662
+ }
663
+ }
664
+
581
665
  // src/config/index.ts
582
666
  function record(value) {
583
667
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -778,7 +862,7 @@ async function createRdxProject(input, {
778
862
  rootDir = process.cwd(),
779
863
  command = "runtime"
780
864
  } = {}) {
781
- rootDir = path6.resolve(
865
+ rootDir = path7.resolve(
782
866
  /* turbopackIgnore: true */
783
867
  rootDir
784
868
  );
@@ -854,7 +938,7 @@ async function createRdxProject(input, {
854
938
  const field = `plugin "${plugin.name}" runtimeFiles`;
855
939
  const filename = text(value, field);
856
940
  const resolved = resolveProjectPath(rootDir, filename, field);
857
- runtimeFiles.add(path6.relative(rootDir, resolved));
941
+ runtimeFiles.add(path7.relative(rootDir, resolved));
858
942
  }
859
943
  }
860
944
  if (contribution.sources === void 0) continue;
@@ -966,6 +1050,10 @@ export {
966
1050
  resolveProjectPath,
967
1051
  collectSnapshotContributions,
968
1052
  getEditPageHref,
1053
+ snapshotDatesFilename,
1054
+ createDocumentDateReader,
1055
+ collectSnapshotDocumentDates,
1056
+ getSnapshotDocumentDate,
969
1057
  resolveConfig,
970
1058
  defineConfig,
971
1059
  createRdxProject
@@ -1,2 +1,2 @@
1
1
  import '@lexibase/rdx-types';
2
- export { R as RdxConfigError, h as collectSnapshotContributions, c as createRdxProject, d as defineConfig, g as getContentSources, j as getEditPageHref, n as normalizeLocalization, r as resolveConfig, f as resolveProjectPath } from '../index-2qiAhOwp.js';
2
+ export { R as RdxConfigError, h as collectSnapshotContributions, j as collectSnapshotDocumentDates, k as createDocumentDateReader, c as createRdxProject, d as defineConfig, g as getContentSources, l as getEditPageHref, m as getSnapshotDocumentDate, n as normalizeLocalization, r as resolveConfig, f as resolveProjectPath, s as snapshotDatesFilename } from '../index-CIBgPARs.js';
@@ -1,24 +1,32 @@
1
1
  import {
2
2
  RdxConfigError,
3
3
  collectSnapshotContributions,
4
+ collectSnapshotDocumentDates,
5
+ createDocumentDateReader,
4
6
  createRdxProject,
5
7
  defineConfig,
6
8
  getEditPageHref,
9
+ getSnapshotDocumentDate,
7
10
  normalizeLocalization,
8
11
  resolveConfig,
9
- resolveProjectPath
10
- } from "../chunk-GSIKV6MV.js";
12
+ resolveProjectPath,
13
+ snapshotDatesFilename
14
+ } from "../chunk-FZGWKA74.js";
11
15
  import {
12
16
  getContentSources
13
17
  } from "../chunk-SNNEXRLQ.js";
14
18
  export {
15
19
  RdxConfigError,
16
20
  collectSnapshotContributions,
21
+ collectSnapshotDocumentDates,
22
+ createDocumentDateReader,
17
23
  createRdxProject,
18
24
  defineConfig,
19
25
  getContentSources,
20
26
  getEditPageHref,
27
+ getSnapshotDocumentDate,
21
28
  normalizeLocalization,
22
29
  resolveConfig,
23
- resolveProjectPath
30
+ resolveProjectPath,
31
+ snapshotDatesFilename
24
32
  };
@@ -41,6 +41,11 @@ declare function isFallbackPage(project: RdxProject, source: RdxContentSource, s
41
41
 
42
42
  declare function getEditPageHref(project: Pick<RdxProject, 'config' | 'rootDir'>, source: Pick<RdxContentSource, 'id'> | undefined, sourcePath: string): string | undefined;
43
43
 
44
+ declare const snapshotDatesFilename = "_rdx-last-updated.json";
45
+ declare function createDocumentDateReader(root: string): (file: string) => string | undefined;
46
+ declare function collectSnapshotDocumentDates(directory: string, dateFor: (file: string) => string | undefined): string | undefined;
47
+ declare function getSnapshotDocumentDate(directory: string, file: string): string | undefined;
48
+
44
49
  declare function resolveConfig(input: unknown): ResolvedRdxConfig;
45
50
  declare function defineConfig(config: RDXConfig): RDXConfig;
46
51
  declare function createRdxProject(input: unknown, { rootDir, command, }?: {
@@ -48,4 +53,4 @@ declare function createRdxProject(input: unknown, { rootDir, command, }?: {
48
53
  command?: string;
49
54
  }): Promise<RdxProject>;
50
55
 
51
- export { RdxConfigError as R, getDocsHref as a, getLanguageLinks as b, createRdxProject as c, defineConfig as d, getLocalizedProject as e, resolveProjectPath as f, getContentSources as g, collectSnapshotContributions as h, isFallbackPage as i, getEditPageHref as j, normalizeLocalization as n, resolveConfig as r };
56
+ export { RdxConfigError as R, getDocsHref as a, getLanguageLinks as b, createRdxProject as c, defineConfig as d, getLocalizedProject as e, resolveProjectPath as f, getContentSources as g, collectSnapshotContributions as h, isFallbackPage as i, collectSnapshotDocumentDates as j, createDocumentDateReader as k, getEditPageHref as l, getSnapshotDocumentDate as m, normalizeLocalization as n, resolveConfig as r, snapshotDatesFilename as s };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _lexibase_rdx_types from '@lexibase/rdx-types';
2
2
  import { RdxDocsOptions, RdxDocCategory, RdxDocument, RdxProject, RdxContentSource } from '@lexibase/rdx-types';
3
- export { R as RdxConfigError, c as createRdxProject, d as defineConfig, g as getContentSources, a as getDocsHref, b as getLanguageLinks, e as getLocalizedProject, i as isFallbackPage, r as resolveConfig, f as resolveProjectPath } from './index-2qiAhOwp.js';
3
+ export { R as RdxConfigError, c as createRdxProject, d as defineConfig, g as getContentSources, a as getDocsHref, b as getLanguageLinks, e as getLocalizedProject, i as isFallbackPage, r as resolveConfig, f as resolveProjectPath } from './index-CIBgPARs.js';
4
4
  export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver } from './document-links-fo6ul9xz.js';
5
5
 
6
6
  /**
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  defineConfig,
13
13
  resolveConfig,
14
14
  resolveProjectPath
15
- } from "./chunk-GSIKV6MV.js";
15
+ } from "./chunk-FZGWKA74.js";
16
16
  import {
17
17
  getContentSources,
18
18
  getDocsHref,