forgepress 0.0.1 → 0.0.2

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 (56) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md +28 -83
  2. package/dist/_chunks/client.d.mts +1 -1
  3. package/dist/_chunks/config.mjs +61 -19
  4. package/dist/_chunks/{validate.mjs → content.mjs} +350 -217
  5. package/dist/_chunks/fetch.mjs +2 -2
  6. package/dist/_chunks/files.mjs +32 -0
  7. package/dist/_chunks/libs/diff.mjs +485 -0
  8. package/dist/_chunks/media.mjs +282 -0
  9. package/dist/_chunks/once.mjs +16 -0
  10. package/dist/_chunks/output.mjs +98 -252
  11. package/dist/_chunks/plugin.mjs +87 -0
  12. package/dist/_chunks/preview.mjs +248 -0
  13. package/dist/_chunks/project.d.mts +7 -0
  14. package/dist/_chunks/reader.mjs +5 -9
  15. package/dist/_chunks/reader2.mjs +150 -202
  16. package/dist/_chunks/references.mjs +8 -5
  17. package/dist/_chunks/resolve.d.mts +2 -0
  18. package/dist/_chunks/response.mjs +5 -0
  19. package/dist/_chunks/routes.mjs +9 -0
  20. package/dist/_chunks/serialize.mjs +82 -0
  21. package/dist/_chunks/settings.mjs +328 -0
  22. package/dist/_chunks/settings2.mjs +2 -0
  23. package/dist/_chunks/types.d.mts +229 -24
  24. package/dist/_chunks/types2.d.mts +25 -0
  25. package/dist/_chunks/value.mjs +123 -1
  26. package/dist/cli/bin.mjs +50 -37
  27. package/dist/editor/index.mjs +9961 -8653
  28. package/dist/index.d.mts +2 -3
  29. package/dist/index.mjs +14 -24
  30. package/dist/next/preview.d.mts +1 -0
  31. package/dist/next/preview.mjs +3 -0
  32. package/dist/next/reload.d.mts +1 -0
  33. package/dist/next/reload.mjs +20 -0
  34. package/dist/next/settings.d.mts +12 -0
  35. package/dist/next/settings.mjs +2 -0
  36. package/dist/plugin/next.d.mts +11 -0
  37. package/dist/plugin/next.mjs +213 -0
  38. package/dist/plugin/nuxt.d.mts +7 -0
  39. package/dist/plugin/nuxt.mjs +52 -0
  40. package/dist/plugin/watcher.d.mts +1 -0
  41. package/dist/plugin/watcher.mjs +23 -0
  42. package/dist/preview/index.d.mts +1 -2
  43. package/dist/preview/index.mjs +1 -243
  44. package/dist/preview/react.d.mts +1 -0
  45. package/dist/preview/react.mjs +34 -0
  46. package/dist/unplugin.d.mts +12 -17
  47. package/dist/unplugin.mjs +1 -500
  48. package/package.json +72 -8
  49. package/dist/_chunks/config.d.mts +0 -35
  50. package/dist/_chunks/entry.d.mts +0 -194
  51. package/dist/_chunks/libs/@oxc-project/types.d.mts +0 -1297
  52. package/dist/_chunks/libs/@rolldown/pluginutils.d.mts +0 -62
  53. package/dist/_chunks/libs/rolldown.d.mts +0 -4711
  54. package/dist/_chunks/output2.mjs +0 -333
  55. package/dist/_chunks/parse.mjs +0 -22
  56. package/dist/_chunks/types.mjs +0 -2
@@ -1,3 +1,122 @@
1
+ const META_KEYS = [
2
+ "id",
3
+ "status",
4
+ "createdAt",
5
+ "updatedAt"
6
+ ];
7
+ const OUTPUT_META_KEYS = [
8
+ "id",
9
+ "createdAt",
10
+ "updatedAt"
11
+ ];
12
+ const ENTRY_STATUSES = ["published", "unpublished"];
13
+ const dynamic = {
14
+ type: "dynamic",
15
+ label: "Dynamic",
16
+ options: { collections: {
17
+ label: "Collections",
18
+ type: "collections",
19
+ required: true
20
+ } }
21
+ };
22
+ const image = {
23
+ type: "image",
24
+ label: "Image",
25
+ options: { multiple: {
26
+ label: "Multiple",
27
+ type: "boolean"
28
+ } }
29
+ };
30
+ const number = {
31
+ type: "number",
32
+ label: "Number",
33
+ options: {
34
+ min: {
35
+ label: "Minimum",
36
+ type: "number"
37
+ },
38
+ max: {
39
+ label: "Maximum",
40
+ type: "number"
41
+ },
42
+ step: {
43
+ label: "Step",
44
+ type: "number"
45
+ },
46
+ index: {
47
+ label: "Indexed",
48
+ type: "boolean",
49
+ description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry."
50
+ }
51
+ }
52
+ };
53
+ const relation = {
54
+ type: "relation",
55
+ label: "Relation",
56
+ options: {
57
+ collection: {
58
+ label: "Collection",
59
+ type: "collection",
60
+ required: true
61
+ },
62
+ multiple: {
63
+ label: "Multiple",
64
+ type: "boolean"
65
+ },
66
+ index: {
67
+ label: "Indexed",
68
+ type: "boolean",
69
+ description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry."
70
+ }
71
+ }
72
+ };
73
+ const richtext = {
74
+ type: "richtext",
75
+ label: "Rich Text",
76
+ options: {}
77
+ };
78
+ const text = {
79
+ type: "text",
80
+ label: "Text",
81
+ options: {
82
+ validation: {
83
+ label: "Validation Pattern",
84
+ type: "text"
85
+ },
86
+ index: {
87
+ label: "Indexed",
88
+ type: "boolean",
89
+ description: "Listed in the collection manifest, so queries can filter and sort on it without loading every entry."
90
+ }
91
+ }
92
+ };
93
+ function compilePattern(validation) {
94
+ try {
95
+ return new RegExp(validation, "u");
96
+ } catch (error) {
97
+ return error;
98
+ }
99
+ }
100
+ const fieldTypes = {
101
+ text,
102
+ richtext,
103
+ number,
104
+ image,
105
+ video: {
106
+ type: "video",
107
+ label: "Video",
108
+ options: { multiple: {
109
+ label: "Multiple",
110
+ type: "boolean"
111
+ } }
112
+ },
113
+ relation,
114
+ dynamic
115
+ };
116
+ const fieldTypeNames = Object.keys(fieldTypes);
117
+ function isTranslated(field, locales) {
118
+ return field.translate === true && locales.length > 0;
119
+ }
1
120
  function isRecord(value) {
2
121
  return typeof value === "object" && value !== null && !Array.isArray(value);
3
122
  }
@@ -7,6 +126,9 @@ function plain(value) {
7
126
  function same(left, right) {
8
127
  return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
9
128
  }
129
+ function pick(record, keys) {
130
+ return Object.fromEntries(keys.filter((key) => record[key] !== void 0).map((key) => [key, record[key]]));
131
+ }
10
132
  function defined(value) {
11
133
  if (!value) return {};
12
134
  return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
@@ -14,4 +136,4 @@ function defined(value) {
14
136
  function quote(value) {
15
137
  return JSON.stringify(value) ?? String(value);
16
138
  }
17
- export { defined, isRecord, plain, quote, same };
139
+ export { ENTRY_STATUSES, META_KEYS, OUTPUT_META_KEYS, compilePattern, defined, fieldTypeNames, fieldTypes, isRecord, isTranslated, pick, plain, quote, same };
package/dist/cli/bin.mjs CHANGED
@@ -1,48 +1,61 @@
1
1
  #!/usr/bin/env node
2
2
  import { errorMessage } from "../_chunks/error.mjs";
3
+ import { ContentError, formatIssue, readContent } from "../_chunks/content.mjs";
4
+ import { buildOutput } from "../_chunks/output.mjs";
5
+ import { diskFiles } from "../_chunks/files.mjs";
3
6
  import { findRoot, loadConfig, resolveConfig } from "../_chunks/config.mjs";
4
- import { ContentError, formatIssue } from "../_chunks/validate.mjs";
5
- import { buildOutput, checkContent } from "../_chunks/output2.mjs";
6
7
  import process from "node:process";
7
- const USAGE = `Usage: forgepress <command>
8
-
9
- Commands:
10
- check Check the schema and all content the way the build does
11
- build Check the content, then write the content output`;
12
- function report(issues, terminal) {
13
- terminal.error(`${issues.map(formatIssue).join("\n")}\n\n${issues.length} ${issues.length === 1 ? "problem" : "problems"} found`);
14
- return 1;
8
+ import { defineCommand, runMain } from "citty";
9
+ var version = "0.0.2";
10
+ function fail(message) {
11
+ console.error(message);
12
+ process.exitCode = 1;
15
13
  }
16
- async function check(root, terminal) {
17
- const config = resolveConfig(await loadConfig(root));
18
- const issues = await checkContent(root, config.paths);
19
- if (issues.length > 0) return report(issues, terminal);
20
- terminal.log("No problems found");
21
- return 0;
14
+ function report(issues) {
15
+ fail(`${issues.map(formatIssue).join("\n")}\n\n${issues.length} ${issues.length === 1 ? "problem" : "problems"} found`);
22
16
  }
23
- async function build(root, terminal) {
24
- const result = await buildOutput(root, resolveConfig(await loadConfig(root)));
25
- terminal.log(`Wrote the content output to ${result.dir} (${result.files} files, ${result.commit ? `commit ${result.commit.slice(0, 7)}` : "no commit found"})`);
26
- return 0;
27
- }
28
- async function run(args, cwd, terminal) {
29
- const [command, ...rest] = args;
30
- if (command === void 0 || command === "help" || command === "--help" || command === "-h") {
31
- terminal.log(USAGE);
32
- return 0;
33
- }
34
- if (command !== "check" && command !== "build" || rest.length > 0) {
35
- terminal.error(`${command !== "check" && command !== "build" ? `Unknown command ${JSON.stringify(command)}` : `${command} takes no arguments`}\n\n${USAGE}`);
36
- return 1;
37
- }
17
+ async function inProject(cwd, task) {
38
18
  try {
39
- const root = findRoot(cwd);
40
- return command === "check" ? await check(root, terminal) : await build(root, terminal);
19
+ await task(findRoot(cwd));
41
20
  } catch (error) {
42
- if (error instanceof ContentError) return report(error.issues, terminal);
43
- terminal.error(errorMessage(error));
44
- return 1;
21
+ if (error instanceof ContentError) return report(error.issues);
22
+ fail(errorMessage(error));
45
23
  }
46
24
  }
47
- process.exitCode = await run(process.argv.slice(2), process.cwd(), console);
25
+ function createCli(cwd) {
26
+ const check = defineCommand({
27
+ meta: {
28
+ name: "check",
29
+ description: "Check the schema and all content the way the build does"
30
+ },
31
+ run: () => inProject(cwd, async (root) => {
32
+ const config = resolveConfig(await loadConfig(root));
33
+ const { issues } = await readContent(diskFiles(root), config.paths);
34
+ if (issues.length > 0) return report(issues);
35
+ console.log("No problems found");
36
+ })
37
+ });
38
+ const build = defineCommand({
39
+ meta: {
40
+ name: "build",
41
+ description: "Check the content, then write the content output"
42
+ },
43
+ run: () => inProject(cwd, async (root) => {
44
+ const result = await buildOutput(root, resolveConfig(await loadConfig(root)));
45
+ console.log(`Wrote the content output to ${result.dir} (${result.files} ${result.files === 1 ? "file" : "files"}, ${result.commit ? `commit ${result.commit.slice(0, 7)}` : "no commit found"})`);
46
+ })
47
+ });
48
+ return defineCommand({
49
+ meta: {
50
+ name: "forgepress",
51
+ version,
52
+ description: "Check and build the content of a ForgePress project"
53
+ },
54
+ subCommands: {
55
+ check,
56
+ build
57
+ }
58
+ });
59
+ }
60
+ await runMain(createCli(process.cwd()));
48
61
  export {};