opacacms 0.3.6 → 0.3.8
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/{chunk-h2y2t07h.js → chunk-pqjyh3tk.js} +11 -2
- package/dist/cli/index.js +73 -6
- package/dist/runtimes/bun.js +1 -1
- package/dist/runtimes/cloudflare-workers.js +1 -1
- package/dist/runtimes/next.js +1 -1
- package/dist/runtimes/node.js +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
|
@@ -1786,8 +1786,17 @@ function createDatabaseInitMiddleware(config, state) {
|
|
|
1786
1786
|
const shouldMigrate = config.runMigrationsOnStartup || isDev;
|
|
1787
1787
|
if (shouldMigrate) {
|
|
1788
1788
|
if (config.runMigrationsOnStartup && config.db.runMigrations) {
|
|
1789
|
-
|
|
1790
|
-
|
|
1789
|
+
try {
|
|
1790
|
+
logger.info("Running file-based migrations on startup...");
|
|
1791
|
+
await config.db.runMigrations();
|
|
1792
|
+
} catch (e) {
|
|
1793
|
+
if (e.code === "ENOENT" && e.path && e.path.includes("migrations")) {
|
|
1794
|
+
logger.debug("No 'migrations' folder found. Skipping file-based migrations.");
|
|
1795
|
+
} else {
|
|
1796
|
+
logger.error("Error running migrations on startup:");
|
|
1797
|
+
console.error(e);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1791
1800
|
}
|
|
1792
1801
|
await runAuthMigrations(config.db);
|
|
1793
1802
|
} else {
|
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 (
|
|
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 {
|
|
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';`;
|
|
@@ -2019,7 +2031,7 @@ var init_init = __esm(() => {
|
|
|
2019
2031
|
const nextPathPrefix = framework === "nextjs" ? `${srcDir}app/(opaca)/` : "";
|
|
2020
2032
|
const cfPathPrefix = framework === "cloudflare-workers" ? "src/(opaca)/" : "";
|
|
2021
2033
|
const pathPrefix = framework === "nextjs" ? nextPathPrefix : cfPathPrefix;
|
|
2022
|
-
const configCode = `import { defineConfig } from 'opacacms
|
|
2034
|
+
const configCode = `import { defineConfig } from 'opacacms';
|
|
2023
2035
|
${dbImport}
|
|
2024
2036
|
import { posts } from './${pathPrefix}_collections/posts';
|
|
2025
2037
|
import { siteSettings } from './${pathPrefix}_globals/site-settings';
|
|
@@ -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", "bun --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") {
|
|
@@ -2203,6 +2264,12 @@ console.log('\uD83D\uDE80 OpacaCMS Backend Listening on http://localhost:3001');
|
|
|
2203
2264
|
Vt2(`1. Check the newly created \`opaca.config.ts\` and \`(opaca)\` folder.
|
|
2204
2265
|
2. Run \`npm install\` (or your preferred package manager) to install dependencies.
|
|
2205
2266
|
3. Start your dev server!`, "Next Steps");
|
|
2267
|
+
if (dbType === "better-sqlite3") {
|
|
2268
|
+
Vt2(import_picocolors.default.yellow(`WARNING: better-sqlite3 relies on C++ native bindings.
|
|
2269
|
+
` + `It often fails to compile or locate bindings on newer Node.js versions (e.g. 20/22).
|
|
2270
|
+
` + `If you encounter 'Could not locate bindings file' errors during development,
|
|
2271
|
+
` + "consider switching to 'bun-sqlite' (if using Bun) or PostgreSQL."), "Important Note");
|
|
2272
|
+
}
|
|
2206
2273
|
Gt(`Build something awesome! \uD83C\uDF88`);
|
|
2207
2274
|
}
|
|
2208
2275
|
});
|
package/dist/runtimes/bun.js
CHANGED
package/dist/runtimes/next.js
CHANGED
package/dist/runtimes/node.js
CHANGED
package/dist/server.js
CHANGED