opacacms 0.3.5 → 0.3.7

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/cli/index.js CHANGED
@@ -1937,6 +1937,14 @@ var init_init = __esm(() => {
1937
1937
  Wt2(import_picocolors.default.bgBlue(import_picocolors.default.white(" Welcome to OpacaCMS Setup! ")));
1938
1938
  const targetDir = args.target ? resolve(process.cwd(), args.target) : process.cwd();
1939
1939
  const pkgJsonPath = resolve(targetDir, "package.json");
1940
+ const existingConfigs = ["opaca.config.ts", "opacacms.config.ts", "opaca.config.js"];
1941
+ for (const config of existingConfigs) {
1942
+ if (fs3.existsSync(resolve(targetDir, config))) {
1943
+ Vt2(`Found an existing ${config} in the directory. OpacaCMS is already initialized!`);
1944
+ Gt(import_picocolors.default.yellow("Initialization skipped."));
1945
+ process.exit(0);
1946
+ }
1947
+ }
1940
1948
  let framework = detectFramework(pkgJsonPath);
1941
1949
  if (framework !== "unknown") {
1942
1950
  const confirmFramework = await Rt({
@@ -1973,11 +1981,12 @@ var init_init = __esm(() => {
1973
1981
  const dbType = await Jt({
1974
1982
  message: "Which database would you like to use?",
1975
1983
  options: [
1976
- { value: "sqlite", label: "SQLite (Local/Bun)" },
1984
+ { value: "bun-sqlite", label: "Bun SQLite (Fastest, requires Bun runtime)" },
1985
+ { value: "better-sqlite3", label: "Better SQLite3 (Standard Node.js)" },
1977
1986
  { value: "d1", label: "Cloudflare D1" },
1978
1987
  { value: "postgres", label: "PostgreSQL" }
1979
1988
  ],
1980
- initialValue: framework === "cloudflare-workers" ? "d1" : "sqlite"
1989
+ initialValue: framework === "cloudflare-workers" ? "d1" : "bun-sqlite"
1981
1990
  });
1982
1991
  if (Ct(dbType)) {
1983
1992
  Nt("Operation cancelled.");
@@ -1995,8 +2004,11 @@ var init_init = __esm(() => {
1995
2004
  s.start(`Generating boilerplate for ${framework}...`);
1996
2005
  let dbImport = "";
1997
2006
  let dbInit = "";
1998
- if (dbType === "sqlite") {
1999
- dbImport = `import { createSQLiteAdapter } from 'opacacms/db/sqlite';`;
2007
+ if (dbType === "bun-sqlite") {
2008
+ dbImport = `import { createBunSQLiteAdapter } from 'opacacms/db/bun-sqlite';`;
2009
+ dbInit = `createBunSQLiteAdapter('local.db')`;
2010
+ } else if (dbType === "better-sqlite3") {
2011
+ dbImport = `import { createSQLiteAdapter } from 'opacacms/db/better-sqlite';`;
2000
2012
  dbInit = `createSQLiteAdapter('local.db')`;
2001
2013
  } else if (dbType === "d1") {
2002
2014
  dbImport = `import { createD1Adapter } from 'opacacms/db/d1';`;
@@ -2017,12 +2029,12 @@ var init_init = __esm(() => {
2017
2029
  }
2018
2030
  const srcDir = fs3.existsSync(resolve(targetDir, "src")) ? "src/" : "";
2019
2031
  const nextPathPrefix = framework === "nextjs" ? `${srcDir}app/(opaca)/` : "";
2020
- const cfPathPrefix = framework === "cloudflare-workers" ? "src/" : "";
2032
+ const cfPathPrefix = framework === "cloudflare-workers" ? "src/(opaca)/" : "";
2021
2033
  const pathPrefix = framework === "nextjs" ? nextPathPrefix : cfPathPrefix;
2022
2034
  const configCode = `import { defineConfig } from 'opacacms/config';
2023
2035
  ${dbImport}
2024
- import { posts } from './${pathPrefix}(opaca)/_collections/posts';
2025
- import { siteSettings } from './${pathPrefix}(opaca)/_globals/site-settings';
2036
+ import { posts } from './${pathPrefix}_collections/posts';
2037
+ import { siteSettings } from './${pathPrefix}_globals/site-settings';
2026
2038
 
2027
2039
  ${dbType === "d1" ? `const getConfig = (env: any, request: Request) => defineConfig({
2028
2040
  appName: "My OpacaCMS App",
@@ -2073,6 +2085,49 @@ export const siteSettings = defineGlobal({
2073
2085
  };
2074
2086
  writeFile("opaca.config.ts", configCode);
2075
2087
  if (framework === "nextjs") {
2088
+ if (dbType === "better-sqlite3") {
2089
+ const nextConfigs = ["next.config.ts", "next.config.mjs", "next.config.js"];
2090
+ let foundConfig = false;
2091
+ for (const conf of nextConfigs) {
2092
+ const confPath = resolve(targetDir, conf);
2093
+ if (fs3.existsSync(confPath)) {
2094
+ let content = fs3.readFileSync(confPath, "utf-8");
2095
+ if (content.includes("serverExternalPackages")) {
2096
+ if (!content.includes("better-sqlite3")) {
2097
+ content = content.replace(/serverExternalPackages:\s*\[/, "serverExternalPackages: ['better-sqlite3', ");
2098
+ fs3.writeFileSync(confPath, content);
2099
+ }
2100
+ } else if (content.includes("const nextConfig = {")) {
2101
+ content = content.replace("const nextConfig = {", `const nextConfig = {
2102
+ serverExternalPackages: ['better-sqlite3'],`);
2103
+ fs3.writeFileSync(confPath, content);
2104
+ } else if (content.includes("const nextConfig: NextConfig = {")) {
2105
+ content = content.replace("const nextConfig: NextConfig = {", `const nextConfig: NextConfig = {
2106
+ serverExternalPackages: ['better-sqlite3'],`);
2107
+ fs3.writeFileSync(confPath, content);
2108
+ } else if (content.includes("module.exports = {")) {
2109
+ content = content.replace("module.exports = {", `module.exports = {
2110
+ serverExternalPackages: ['better-sqlite3'],`);
2111
+ fs3.writeFileSync(confPath, content);
2112
+ } else {
2113
+ Vt2(`Could not automatically modify ${conf}. Please add \`serverExternalPackages: ['better-sqlite3']\` to your Next.js config.`);
2114
+ }
2115
+ foundConfig = true;
2116
+ break;
2117
+ }
2118
+ }
2119
+ if (!foundConfig) {
2120
+ const newNextConfig = `import type { NextConfig } from "next";
2121
+
2122
+ const nextConfig: NextConfig = {
2123
+ serverExternalPackages: ["better-sqlite3"]
2124
+ };
2125
+
2126
+ export default nextConfig;
2127
+ `;
2128
+ writeFile("next.config.ts", newNextConfig);
2129
+ }
2130
+ }
2076
2131
  const baseDir = `${srcDir}app/(opaca)`;
2077
2132
  createDir(`${baseDir}/_collections`);
2078
2133
  createDir(`${baseDir}/_globals`);
@@ -2184,7 +2239,13 @@ console.log('\uD83D\uDE80 OpacaCMS Backend Listening on http://localhost:3001');
2184
2239
  if (!pkg.dependencies.opacacms) {
2185
2240
  pkg.dependencies.opacacms = "latest";
2186
2241
  }
2187
- if (dbType === "sqlite") {
2242
+ if (dbType === "bun-sqlite") {
2243
+ if (!pkg.dependencies["kysely-bun-sqlite"])
2244
+ pkg.dependencies["kysely-bun-sqlite"] = "latest";
2245
+ if (framework === "nextjs" && pkg.scripts && pkg.scripts.dev) {
2246
+ pkg.scripts.dev = pkg.scripts.dev.replace("next dev", "bunx --bun next dev");
2247
+ }
2248
+ } else if (dbType === "better-sqlite3") {
2188
2249
  if (!pkg.dependencies["better-sqlite3"])
2189
2250
  pkg.dependencies["better-sqlite3"] = "latest";
2190
2251
  } else if (dbType === "postgres") {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from "./auth";
2
2
  export * from "./client";
3
- export * from "./client/RichText";
4
- export * from "./client/rich-text-utils";
5
3
  export * from "./config";
6
4
  export * from "./config-utils";
7
5
  export * from "./schema";
package/dist/index.js CHANGED
@@ -32,134 +32,15 @@ import {
32
32
  import"./chunk-jq1drsen.js";
33
33
  import"./chunk-h8v093av.js";
34
34
  import"./chunk-8sqjbsgt.js";
35
- // src/client/RichText.tsx
36
- import { CodeNode } from "@lexical/code";
37
- import { AutoLinkNode, LinkNode } from "@lexical/link";
38
- import { ListItemNode, ListNode } from "@lexical/list";
39
- import { LexicalComposer } from "@lexical/react/LexicalComposer";
40
- import { ContentEditable } from "@lexical/react/LexicalContentEditable";
41
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
42
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
43
- import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
44
- import { ListPlugin } from "@lexical/react/LexicalListPlugin";
45
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
46
- import { HeadingNode, QuoteNode } from "@lexical/rich-text";
47
- import { useMemo } from "react";
48
- import { jsxDEV } from "react/jsx-dev-runtime";
49
- "use client";
50
- var theme = {
51
- ltr: "ltr",
52
- rtl: "rtl",
53
- placeholder: "opaca-rich-text-placeholder",
54
- paragraph: "opaca-rich-text-p",
55
- quote: "opaca-rich-text-quote",
56
- heading: {
57
- h1: "opaca-rich-text-h1",
58
- h2: "opaca-rich-text-h2",
59
- h3: "opaca-rich-text-h3"
60
- },
61
- list: {
62
- ol: "opaca-rich-text-ol",
63
- ul: "opaca-rich-text-ul",
64
- listitem: "opaca-rich-text-li"
65
- },
66
- link: "opaca-rich-text-link",
67
- text: {
68
- bold: "opaca-rich-text-bold",
69
- italic: "opaca-rich-text-italic",
70
- underline: "opaca-rich-text-underline",
71
- strikethrough: "opaca-rich-text-strikethrough",
72
- code: "opaca-rich-text-code"
73
- }
74
- };
75
- function RichText({ content, className }) {
76
- const initialConfig = useMemo(() => {
77
- let editorState = content;
78
- if (typeof content === "string" && content.startsWith("{")) {
79
- try {
80
- editorState = content;
81
- } catch (e) {
82
- editorState = undefined;
83
- }
84
- } else if (typeof content === "object" && content !== null) {
85
- editorState = JSON.stringify(content);
86
- }
87
- return {
88
- namespace: "OpacaRichTextRenderer",
89
- theme,
90
- editable: false,
91
- nodes: [HeadingNode, ListNode, ListItemNode, QuoteNode, CodeNode, LinkNode, AutoLinkNode],
92
- onError: (error) => {
93
- console.error("RichText Renderer Error:", error);
94
- },
95
- editorState
96
- };
97
- }, [content]);
98
- if (!content)
99
- return null;
100
- return /* @__PURE__ */ jsxDEV("div", {
101
- className: `opaca-rich-text-renderer ${className || ""}`,
102
- children: /* @__PURE__ */ jsxDEV(LexicalComposer, {
103
- initialConfig,
104
- children: [
105
- /* @__PURE__ */ jsxDEV(RichTextPlugin, {
106
- contentEditable: /* @__PURE__ */ jsxDEV(ContentEditable, {
107
- className: "opaca-rich-text-content"
108
- }, undefined, false, undefined, this),
109
- placeholder: null,
110
- ErrorBoundary: LexicalErrorBoundary
111
- }, undefined, false, undefined, this),
112
- /* @__PURE__ */ jsxDEV(ListPlugin, {}, undefined, false, undefined, this),
113
- /* @__PURE__ */ jsxDEV(LinkPlugin, {}, undefined, false, undefined, this),
114
- /* @__PURE__ */ jsxDEV(HistoryPlugin, {}, undefined, false, undefined, this)
115
- ]
116
- }, undefined, true, undefined, this)
117
- }, undefined, false, undefined, this);
118
- }
119
- // src/client/rich-text-utils.ts
120
- function getRichTextText(content) {
121
- if (!content)
122
- return "";
123
- if (typeof content === "string") {
124
- if (content.startsWith("{") && content.includes('"root"')) {
125
- try {
126
- return getRichTextText(JSON.parse(content));
127
- } catch {
128
- return content;
129
- }
130
- }
131
- return content;
132
- }
133
- if (content.root) {
134
- return extractLexicalNodes(content.root.children);
135
- }
136
- if (Array.isArray(content)) {
137
- return extractLexicalNodes(content);
138
- }
139
- return "";
140
- }
141
- function extractLexicalNodes(nodes) {
142
- if (!nodes || !Array.isArray(nodes))
143
- return "";
144
- return nodes.map((node) => {
145
- if (node.text)
146
- return node.text;
147
- if (node.children)
148
- return extractLexicalNodes(node.children);
149
- return "";
150
- }).join(" ").replace(/\s+/g, " ").trim();
151
- }
152
35
  export {
153
36
  zodToOpacaFields,
154
37
  z,
155
38
  sanitizeConfig,
156
- getRichTextText,
157
39
  defineGlobal,
158
40
  defineConfig,
159
41
  defineCollection,
160
42
  createClient,
161
43
  createAuth,
162
- RichText,
163
44
  OpacaError,
164
45
  $ZodString,
165
46
  $ZodOptional,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opacacms",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "license": "MIT",
5
5
  "description": "OpacaCMS: A lightweight, type-safe, and developer-first Headless CMS for the edge and beyond.",
6
6
  "keywords": [