opacacms 0.3.2 → 0.3.3
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/admin/index.js +1 -1
- package/dist/admin/react.js +1 -1
- package/dist/admin/vue.js +1 -1
- package/dist/admin/webcomponent.js +35 -37
- package/dist/{chunk-g9bxb6h0.js → chunk-2fm4kv2q.js} +1 -1
- package/dist/chunk-2vbfc4q8.js +6 -0
- package/dist/{chunk-adq2b75c.js → chunk-40tky6qh.js} +2 -2
- package/dist/{chunk-e0g6gn7n.js → chunk-49e16hjg.js} +3 -3
- package/dist/{chunk-fnsf1dfm.js → chunk-526a3gqx.js} +1 -1
- package/dist/{chunk-sqsfk9p4.js → chunk-6m1jhxmd.js} +1 -1
- package/dist/{chunk-6bywt602.js → chunk-8sqjbsgt.js} +1 -26
- package/dist/{chunk-n1twhqmf.js → chunk-acghejk8.js} +1 -1
- package/dist/{chunk-m24yqkeq.js → chunk-b1g8jmth.js} +3 -3
- package/dist/{chunk-5422w4eq.js → chunk-cm5rvcnn.js} +5 -5
- package/dist/{chunk-941zxavt.js → chunk-h2y2t07h.js} +4 -4
- package/dist/{chunk-6qs0g65f.js → chunk-h8v093av.js} +1 -1
- package/dist/{chunk-m5ems3hh.js → chunk-hthm9srb.js} +1 -1
- package/dist/{chunk-2k3ysje3.js → chunk-nch158fe.js} +1 -1
- package/dist/{chunk-naqcqj8n.js → chunk-pj31j6j0.js} +4 -4
- package/dist/{chunk-qsh2nqz3.js → chunk-pw2a9war.js} +3 -3
- package/dist/{chunk-j8js1y0h.js → chunk-r5k7jw66.js} +1 -1
- package/dist/{chunk-48ywpd0a.js → chunk-vmz9ncf1.js} +1 -1
- package/dist/{chunk-qhdsjek6.js → chunk-wry3rqh0.js} +3 -3
- package/dist/cli/index.js +6793 -6
- package/dist/client.js +3 -3
- package/dist/db/better-sqlite.js +4 -4
- package/dist/db/bun-sqlite.js +4 -4
- package/dist/db/d1.js +4 -4
- package/dist/db/index.js +8 -8
- package/dist/db/postgres.js +4 -4
- package/dist/db/sqlite.js +4 -4
- package/dist/index.js +7 -7
- package/dist/runtimes/bun.js +6 -6
- package/dist/runtimes/cloudflare-workers.js +6 -6
- package/dist/runtimes/next.js +6 -6
- package/dist/runtimes/node.js +6 -6
- package/dist/schema/index.js +3 -3
- package/dist/server.js +6 -6
- package/dist/storage/index.js +1 -1
- package/package.json +11 -10
- package/dist/chunk-0hxz770x.js +0 -10
- package/dist/chunk-2gdsy99f.js +0 -581
- package/dist/chunk-3j9zjfmn.js +0 -376
- package/dist/chunk-5b8r0v8c.js +0 -47
- package/dist/chunk-71wwx9vj.js +0 -413
- package/dist/chunk-9by912e9.js +0 -318
- package/dist/chunk-f3dg5dq4.js +0 -75
- package/dist/chunk-g17v7yfr.js +0 -237
- package/dist/chunk-gzdfc1ct.js +0 -1137
- package/dist/chunk-h6dhexzr.js +0 -94
- package/dist/chunk-jvv72110.js +0 -98
- package/dist/chunk-rg3jrfgg.js +0 -93
- package/dist/chunk-rjvcp6ph.js +0 -95
- package/dist/chunk-v0nazhmk.js +0 -263
- package/dist/chunk-wqvdwck9.js +0 -326
- package/dist/chunk-x7bnzswh.js +0 -174
- package/dist/chunk-y4e9twg2.js +0 -76
package/dist/chunk-9by912e9.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateDiffCode
|
|
3
|
-
} from "./chunk-2gdsy99f.js";
|
|
4
|
-
import {
|
|
5
|
-
require_picocolors
|
|
6
|
-
} from "./chunk-f3dg5dq4.js";
|
|
7
|
-
import {
|
|
8
|
-
Gt,
|
|
9
|
-
R,
|
|
10
|
-
Wt,
|
|
11
|
-
be
|
|
12
|
-
} from "./chunk-gzdfc1ct.js";
|
|
13
|
-
import {
|
|
14
|
-
loadConfig,
|
|
15
|
-
resolveConfigPath
|
|
16
|
-
} from "./chunk-jvv72110.js";
|
|
17
|
-
import {
|
|
18
|
-
defineCommand
|
|
19
|
-
} from "./chunk-71wwx9vj.js";
|
|
20
|
-
import {
|
|
21
|
-
getRandomMigrationName
|
|
22
|
-
} from "./chunk-5b8r0v8c.js";
|
|
23
|
-
import"./chunk-qxt9vge8.js";
|
|
24
|
-
import {
|
|
25
|
-
logger
|
|
26
|
-
} from "./chunk-jq1drsen.js";
|
|
27
|
-
import"./chunk-6qs0g65f.js";
|
|
28
|
-
import {
|
|
29
|
-
__require,
|
|
30
|
-
__toESM
|
|
31
|
-
} from "./chunk-6bywt602.js";
|
|
32
|
-
|
|
33
|
-
// src/cli/commands/migrate.ts
|
|
34
|
-
import fs2 from "node:fs";
|
|
35
|
-
import { relative as relative2, resolve as resolve2 } from "node:path";
|
|
36
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
37
|
-
|
|
38
|
-
// src/cli/core/migrations/migrate-logic.ts
|
|
39
|
-
import { spawnSync } from "node:child_process";
|
|
40
|
-
import fs from "node:fs";
|
|
41
|
-
import { relative, resolve } from "node:path";
|
|
42
|
-
async function migrateCreateCommand(opaca, migrationName, outDir) {
|
|
43
|
-
const db = opaca.db;
|
|
44
|
-
const migrationDir = outDir || db.migrationDir || "./migrations";
|
|
45
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
46
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
47
|
-
fs.mkdirSync(fullMigrationDir, { recursive: true });
|
|
48
|
-
}
|
|
49
|
-
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").split(".")[0];
|
|
50
|
-
const { generateDiffCode: generateDiffCode2 } = await import("./chunk-0hxz770x.js");
|
|
51
|
-
let dialect = "sqlite";
|
|
52
|
-
if (db.name === "postgres")
|
|
53
|
-
dialect = "postgres";
|
|
54
|
-
if (db.name === "d1")
|
|
55
|
-
dialect = "d1";
|
|
56
|
-
const isD1 = dialect === "d1";
|
|
57
|
-
const name = !migrationName || migrationName === "migration" ? getRandomMigrationName() : migrationName;
|
|
58
|
-
const snapshotName = `${timestamp}_${name}`;
|
|
59
|
-
const fileName = `${snapshotName}.${isD1 ? "sql" : "ts"}`;
|
|
60
|
-
const filePath = resolve(fullMigrationDir, fileName);
|
|
61
|
-
const result = await generateDiffCode2(opaca, dialect, migrationDir, snapshotName, {
|
|
62
|
-
saveSnapshot: true,
|
|
63
|
-
interactive: true
|
|
64
|
-
});
|
|
65
|
-
if (!result.hasChanges) {
|
|
66
|
-
logger.info("✨ No schema changes detected. Migration not created.");
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
let template = "";
|
|
70
|
-
if (isD1) {
|
|
71
|
-
template = `-- OpacaCMS Auto-generated SQL Migration
|
|
72
|
-
-- Migration: ${snapshotName}
|
|
73
|
-
|
|
74
|
-
-- UP
|
|
75
|
-
${result.upCode}
|
|
76
|
-
`;
|
|
77
|
-
} else {
|
|
78
|
-
template = `import { type OpacaMigrationDb, sql } from 'opacacms/db';
|
|
79
|
-
|
|
80
|
-
export async function up(db: OpacaMigrationDb): Promise<void> {
|
|
81
|
-
${result.upCode}}
|
|
82
|
-
|
|
83
|
-
export async function down(db: OpacaMigrationDb): Promise<void> {
|
|
84
|
-
${result.downCode}}
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
fs.writeFileSync(filePath, template);
|
|
88
|
-
logger.success(`\uD83D\uDE80 Migration created successfully at ${relative(process.cwd(), filePath)}`);
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
async function migrateRunCommand(db) {
|
|
92
|
-
logger.info("\uD83C\uDFAC Running migrations...");
|
|
93
|
-
if (db.runMigrations) {
|
|
94
|
-
await db.connect();
|
|
95
|
-
try {
|
|
96
|
-
await db.runMigrations();
|
|
97
|
-
logger.success("✅ Migrations applied successfully!");
|
|
98
|
-
} catch (error) {
|
|
99
|
-
logger.error(`❌ Failed to run migrations: ${error.message}`);
|
|
100
|
-
throw error;
|
|
101
|
-
} finally {}
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error(`Adapter ${db.name} does not support running migrations.`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async function migrateStatusCommand(opaca) {
|
|
107
|
-
logger.info("\uD83D\uDCCA Checking migration status...");
|
|
108
|
-
const db = opaca.db;
|
|
109
|
-
const migrationDir = db.migrationDir || "./migrations";
|
|
110
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
111
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
112
|
-
logger.info("No migrations directory found.");
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const migrationFiles = fs.readdirSync(fullMigrationDir).filter((f) => f.endsWith(".ts") || f.endsWith(".sql")).sort();
|
|
116
|
-
let appliedMigrations = [];
|
|
117
|
-
try {
|
|
118
|
-
await db.connect();
|
|
119
|
-
const rows = await db.unsafe("SELECT name FROM kysely_migration").catch(() => []);
|
|
120
|
-
appliedMigrations = rows.map((r) => r.name);
|
|
121
|
-
} catch (e) {} finally {}
|
|
122
|
-
console.log(`
|
|
123
|
-
Found ${migrationFiles.length} migration files in ${migrationDir}:`);
|
|
124
|
-
for (const file of migrationFiles) {
|
|
125
|
-
const name = file.replace(/\.(ts|sql)$/, "");
|
|
126
|
-
const isApplied = appliedMigrations.includes(name);
|
|
127
|
-
console.log(` ${isApplied ? "✅ [Applied] " : "❌ [Pending] "} ${file}`);
|
|
128
|
-
}
|
|
129
|
-
const pending = migrationFiles.filter((f) => !appliedMigrations.includes(f.replace(/\.(ts|sql)$/, "")));
|
|
130
|
-
if (pending.length > 0) {
|
|
131
|
-
console.log(`
|
|
132
|
-
\uD83D\uDCA1 You have ${pending.length} pending migrations. Run 'opacacms migrate' to apply them.`);
|
|
133
|
-
} else {
|
|
134
|
-
console.log(`
|
|
135
|
-
✨ All migrations are up to date.`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async function migrateD1Command(migrationDir, isRemote, binding = "DB") {
|
|
139
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
140
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
141
|
-
throw new Error(`[OpacaCMS] Migration directory not found: ${fullMigrationDir}`);
|
|
142
|
-
}
|
|
143
|
-
const migrations = fs.readdirSync(fullMigrationDir).filter((file) => file.endsWith(".sql")).sort();
|
|
144
|
-
if (migrations.length === 0) {
|
|
145
|
-
console.log(`[OpacaCMS] No SQL migrations found in ${fullMigrationDir}`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
console.log(`[OpacaCMS] Found ${migrations.length} migrations. Applying to ${isRemote ? "\uD83C\uDF0A REMOTE (Cloudflare D1)" : "\uD83D\uDCBB LOCAL (SQLite)"}...`);
|
|
149
|
-
for (const migration of migrations) {
|
|
150
|
-
const filePath = resolve(fullMigrationDir, migration);
|
|
151
|
-
console.log(`
|
|
152
|
-
[OpacaCMS] \uD83D\uDCE6 Applying: ${migration}...`);
|
|
153
|
-
const wranglerArgs = [
|
|
154
|
-
"wrangler",
|
|
155
|
-
"d1",
|
|
156
|
-
"execute",
|
|
157
|
-
binding,
|
|
158
|
-
"--file",
|
|
159
|
-
filePath,
|
|
160
|
-
isRemote ? "--remote" : "--local",
|
|
161
|
-
"--yes"
|
|
162
|
-
];
|
|
163
|
-
const result = spawnSync("bun", ["x", ...wranglerArgs], {
|
|
164
|
-
stdio: "inherit",
|
|
165
|
-
shell: false,
|
|
166
|
-
cwd: process.cwd()
|
|
167
|
-
});
|
|
168
|
-
if (result.status !== 0) {
|
|
169
|
-
console.error(`[OpacaCMS] ❌ Failed to apply migration: ${migration}`);
|
|
170
|
-
} else {
|
|
171
|
-
console.log(`[OpacaCMS] ✅ Success: ${migration}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
console.log(`
|
|
175
|
-
[OpacaCMS] ✨ Database migration process completed!`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/cli/commands/migrate.ts
|
|
179
|
-
var migrate_default = defineCommand({
|
|
180
|
-
meta: {
|
|
181
|
-
name: "migrate",
|
|
182
|
-
description: "Manage database migrations"
|
|
183
|
-
},
|
|
184
|
-
args: {
|
|
185
|
-
config: {
|
|
186
|
-
type: "string",
|
|
187
|
-
alias: "c",
|
|
188
|
-
description: "Path to the OpacaCMS configuration file"
|
|
189
|
-
},
|
|
190
|
-
action: {
|
|
191
|
-
type: "positional",
|
|
192
|
-
description: "Action to perform: run (default), create, diff, status, d1",
|
|
193
|
-
required: false
|
|
194
|
-
},
|
|
195
|
-
name: {
|
|
196
|
-
type: "positional",
|
|
197
|
-
description: "Name of the migration (for create)",
|
|
198
|
-
required: false
|
|
199
|
-
},
|
|
200
|
-
out: {
|
|
201
|
-
type: "string",
|
|
202
|
-
alias: "o",
|
|
203
|
-
description: "Output directory for migrations"
|
|
204
|
-
},
|
|
205
|
-
remote: {
|
|
206
|
-
type: "boolean",
|
|
207
|
-
description: "Apply migrations to remote D1"
|
|
208
|
-
},
|
|
209
|
-
binding: {
|
|
210
|
-
type: "string",
|
|
211
|
-
alias: "b",
|
|
212
|
-
description: "D1 database binding name",
|
|
213
|
-
default: "DB"
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
async run({ args }) {
|
|
217
|
-
console.log();
|
|
218
|
-
Wt(import_picocolors.default.bgMagenta(import_picocolors.default.white(" OpacaCMS Migrations ")));
|
|
219
|
-
const s = be();
|
|
220
|
-
const action = args.action || "run";
|
|
221
|
-
let opaca;
|
|
222
|
-
if (action !== "d1") {
|
|
223
|
-
s.start("Loading configuration...");
|
|
224
|
-
try {
|
|
225
|
-
const configPath = resolveConfigPath(args.config);
|
|
226
|
-
opaca = await loadConfig(configPath);
|
|
227
|
-
s.stop(`Configuration loaded. DB: ${import_picocolors.default.cyan(opaca.db.name)}`);
|
|
228
|
-
} catch (err) {
|
|
229
|
-
s.stop(import_picocolors.default.red("Failed to load configuration."));
|
|
230
|
-
R.error(err.message);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
try {
|
|
235
|
-
if (action === "create") {
|
|
236
|
-
const name = !args.name || args.name === "migration" ? getRandomMigrationName() : args.name;
|
|
237
|
-
s.start(`Generating baseline migration '${name}'...`);
|
|
238
|
-
const created = await migrateCreateCommand(opaca, name, args.out);
|
|
239
|
-
if (created) {
|
|
240
|
-
s.stop(`Baseline migration created successfully!`);
|
|
241
|
-
} else {
|
|
242
|
-
s.stop(`Operation aborted. No changes detected.`);
|
|
243
|
-
}
|
|
244
|
-
} else if (action === "diff") {
|
|
245
|
-
let name = args.name || "migration";
|
|
246
|
-
if (name === "migration") {
|
|
247
|
-
name = getRandomMigrationName();
|
|
248
|
-
}
|
|
249
|
-
s.start(`Analyzing schema for differences...`);
|
|
250
|
-
let dialect = "sqlite";
|
|
251
|
-
if (opaca.db.name === "postgres")
|
|
252
|
-
dialect = "postgres";
|
|
253
|
-
if (opaca.db.name === "d1")
|
|
254
|
-
dialect = "d1";
|
|
255
|
-
const migrationDir = opaca.db.migrationDir || "./migrations";
|
|
256
|
-
const { hasChanges, upCode, downCode } = await generateDiffCode(opaca, dialect, migrationDir, "diff_check", { saveSnapshot: false, interactive: false });
|
|
257
|
-
if (!hasChanges) {
|
|
258
|
-
s.stop(`Schema is already up to date. No migration generated.`);
|
|
259
|
-
} else {
|
|
260
|
-
s.start(`Generating diff migration '${name}'...`);
|
|
261
|
-
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").split(".")[0];
|
|
262
|
-
const isD1 = dialect === "d1";
|
|
263
|
-
const fileName = `${timestamp}_${name}.${isD1 ? "sql" : "ts"}`;
|
|
264
|
-
const migrationDir2 = args.out || opaca.db.migrationDir || "./migrations";
|
|
265
|
-
const fullMigrationDir = resolve2(process.cwd(), migrationDir2);
|
|
266
|
-
if (!fs2.existsSync(fullMigrationDir)) {
|
|
267
|
-
fs2.mkdirSync(fullMigrationDir, { recursive: true });
|
|
268
|
-
}
|
|
269
|
-
const filePath = resolve2(fullMigrationDir, fileName);
|
|
270
|
-
let template = "";
|
|
271
|
-
if (isD1) {
|
|
272
|
-
template = `-- OpacaCMS Auto-generated SQL Diff Migration
|
|
273
|
-
|
|
274
|
-
${upCode}`;
|
|
275
|
-
} else {
|
|
276
|
-
template = `import { type OpacaMigrationDb, sql } from 'opacacms/db';
|
|
277
|
-
|
|
278
|
-
export async function up(db: OpacaMigrationDb): Promise<void> {
|
|
279
|
-
${upCode}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export async function down(db: OpacaMigrationDb): Promise<void> {
|
|
283
|
-
${downCode}
|
|
284
|
-
}
|
|
285
|
-
`;
|
|
286
|
-
}
|
|
287
|
-
fs2.writeFileSync(filePath, template);
|
|
288
|
-
s.stop(`Diff migration created successfully at ${relative2(process.cwd(), filePath)}!`);
|
|
289
|
-
}
|
|
290
|
-
} else if (action === "run") {
|
|
291
|
-
s.start(`Applying pending migrations...`);
|
|
292
|
-
await migrateRunCommand(opaca.db);
|
|
293
|
-
s.stop(`Migrations applied successfully!`);
|
|
294
|
-
} else if (action === "status") {
|
|
295
|
-
s.start(`Checking migration status...`);
|
|
296
|
-
await migrateStatusCommand(opaca);
|
|
297
|
-
s.stop(`Migration status checked.`);
|
|
298
|
-
} else if (action === "d1") {
|
|
299
|
-
s.start(`Applying D1 migrations...`);
|
|
300
|
-
await migrateD1Command(args.out || "./migrations", !!args.remote, args.binding);
|
|
301
|
-
s.stop(`D1 migrations processed!`);
|
|
302
|
-
} else {
|
|
303
|
-
R.error(`Unknown migration action: ${action}`);
|
|
304
|
-
process.exit(1);
|
|
305
|
-
}
|
|
306
|
-
Gt("Done! \uD83D\uDE80");
|
|
307
|
-
} catch (err) {
|
|
308
|
-
if (s)
|
|
309
|
-
s.stop(import_picocolors.default.red("Migration failed."));
|
|
310
|
-
R.error(err.message);
|
|
311
|
-
Gt(import_picocolors.default.red("Operation aborted."));
|
|
312
|
-
process.exit(1);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
export {
|
|
317
|
-
migrate_default as default
|
|
318
|
-
};
|
package/dist/chunk-f3dg5dq4.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__commonJS
|
|
3
|
-
} from "./chunk-6bywt602.js";
|
|
4
|
-
|
|
5
|
-
// ../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
6
|
-
var require_picocolors = __commonJS((exports, module) => {
|
|
7
|
-
var p = process || {};
|
|
8
|
-
var argv = p.argv || [];
|
|
9
|
-
var env = p.env || {};
|
|
10
|
-
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
11
|
-
var formatter = (open, close, replace = open) => (input) => {
|
|
12
|
-
let string = "" + input, index = string.indexOf(close, open.length);
|
|
13
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
14
|
-
};
|
|
15
|
-
var replaceClose = (string, close, replace, index) => {
|
|
16
|
-
let result = "", cursor = 0;
|
|
17
|
-
do {
|
|
18
|
-
result += string.substring(cursor, index) + replace;
|
|
19
|
-
cursor = index + close.length;
|
|
20
|
-
index = string.indexOf(close, cursor);
|
|
21
|
-
} while (~index);
|
|
22
|
-
return result + string.substring(cursor);
|
|
23
|
-
};
|
|
24
|
-
var createColors = (enabled = isColorSupported) => {
|
|
25
|
-
let f = enabled ? formatter : () => String;
|
|
26
|
-
return {
|
|
27
|
-
isColorSupported: enabled,
|
|
28
|
-
reset: f("\x1B[0m", "\x1B[0m"),
|
|
29
|
-
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
30
|
-
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
31
|
-
italic: f("\x1B[3m", "\x1B[23m"),
|
|
32
|
-
underline: f("\x1B[4m", "\x1B[24m"),
|
|
33
|
-
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
34
|
-
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
35
|
-
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
36
|
-
black: f("\x1B[30m", "\x1B[39m"),
|
|
37
|
-
red: f("\x1B[31m", "\x1B[39m"),
|
|
38
|
-
green: f("\x1B[32m", "\x1B[39m"),
|
|
39
|
-
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
40
|
-
blue: f("\x1B[34m", "\x1B[39m"),
|
|
41
|
-
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
42
|
-
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
43
|
-
white: f("\x1B[37m", "\x1B[39m"),
|
|
44
|
-
gray: f("\x1B[90m", "\x1B[39m"),
|
|
45
|
-
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
46
|
-
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
47
|
-
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
48
|
-
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
49
|
-
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
50
|
-
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
51
|
-
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
52
|
-
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
53
|
-
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
54
|
-
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
55
|
-
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
56
|
-
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
57
|
-
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
58
|
-
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
59
|
-
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
60
|
-
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
61
|
-
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
62
|
-
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
63
|
-
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
64
|
-
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
65
|
-
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
66
|
-
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
67
|
-
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
68
|
-
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
module.exports = createColors();
|
|
72
|
-
module.exports.createColors = createColors;
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export { require_picocolors };
|
package/dist/chunk-g17v7yfr.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
require_picocolors
|
|
3
|
-
} from "./chunk-f3dg5dq4.js";
|
|
4
|
-
import {
|
|
5
|
-
Ct,
|
|
6
|
-
Nt,
|
|
7
|
-
R,
|
|
8
|
-
Vt,
|
|
9
|
-
Zt
|
|
10
|
-
} from "./chunk-gzdfc1ct.js";
|
|
11
|
-
import {
|
|
12
|
-
defineCommand
|
|
13
|
-
} from "./chunk-71wwx9vj.js";
|
|
14
|
-
import {
|
|
15
|
-
__toESM
|
|
16
|
-
} from "./chunk-6bywt602.js";
|
|
17
|
-
|
|
18
|
-
// src/cli/commands/generate.ts
|
|
19
|
-
import fs2 from "node:fs";
|
|
20
|
-
import { resolve as resolve2 } from "node:path";
|
|
21
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
22
|
-
|
|
23
|
-
// src/cli/core/types/generate-types.ts
|
|
24
|
-
import fs from "node:fs";
|
|
25
|
-
import { resolve } from "node:path";
|
|
26
|
-
async function generateTypesCommand(url, token, out) {
|
|
27
|
-
console.log(`[OpacaCMS] Fetching metadata from ${url}/api/__admin/metadata...`);
|
|
28
|
-
let data;
|
|
29
|
-
try {
|
|
30
|
-
const res = await fetch(`${url.replace(/\/$/, "")}/api/__admin/metadata`, {
|
|
31
|
-
headers: {
|
|
32
|
-
Authorization: `Bearer ${token}`
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
if (res.status === 401 || res.status === 403) {
|
|
37
|
-
throw new Error("Authentication failed. Ensure your API Key is correct and has the necessary permissions.");
|
|
38
|
-
}
|
|
39
|
-
const errorText = await res.text().catch(() => "Unknown error");
|
|
40
|
-
throw new Error(`Server responded with ${res.status}: ${errorText}`);
|
|
41
|
-
}
|
|
42
|
-
data = await res.json();
|
|
43
|
-
} catch (err) {
|
|
44
|
-
console.error(`[OpacaCMS] Failed to fetch metadata: ${err.message}`);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
console.log(`[OpacaCMS] Successfully fetched metadata for ${data.collections.length} collections and ${data.globals?.length || 0} globals.`);
|
|
48
|
-
let dtsContent = `// Automatically generated by OpacaCMS CLI
|
|
49
|
-
// Do not edit this file manually
|
|
50
|
-
|
|
51
|
-
export interface OpacaAsset {
|
|
52
|
-
assetId: string;
|
|
53
|
-
url: string;
|
|
54
|
-
filename: string;
|
|
55
|
-
mime_type: string;
|
|
56
|
-
filesize: number;
|
|
57
|
-
meta?: Record<string, any>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface OpacaCollections {
|
|
61
|
-
collections: {
|
|
62
|
-
`;
|
|
63
|
-
for (const collection of data.collections) {
|
|
64
|
-
dtsContent += ` "${collection.slug}": {
|
|
65
|
-
`;
|
|
66
|
-
dtsContent += ` id: string | number;
|
|
67
|
-
`;
|
|
68
|
-
for (const field of collection.fields) {
|
|
69
|
-
const typeStr = mapFieldToTsType(field.type);
|
|
70
|
-
const isOptional = field.required ? "" : "?";
|
|
71
|
-
dtsContent += ` ${field.name}${isOptional}: ${typeStr};
|
|
72
|
-
`;
|
|
73
|
-
}
|
|
74
|
-
if (collection.timestamps) {
|
|
75
|
-
dtsContent += ` createdAt: string;
|
|
76
|
-
`;
|
|
77
|
-
dtsContent += ` updatedAt: string;
|
|
78
|
-
`;
|
|
79
|
-
}
|
|
80
|
-
dtsContent += ` };
|
|
81
|
-
`;
|
|
82
|
-
}
|
|
83
|
-
dtsContent += ` };
|
|
84
|
-
`;
|
|
85
|
-
if (data.globals && data.globals.length > 0) {
|
|
86
|
-
dtsContent += ` globals: {
|
|
87
|
-
`;
|
|
88
|
-
for (const globalConf of data.globals) {
|
|
89
|
-
dtsContent += ` "${globalConf.slug}": {
|
|
90
|
-
`;
|
|
91
|
-
for (const field of globalConf.fields) {
|
|
92
|
-
const typeStr = mapFieldToTsType(field.type);
|
|
93
|
-
const isOptional = field.required ? "" : "?";
|
|
94
|
-
dtsContent += ` ${field.name}${isOptional}: ${typeStr};
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
dtsContent += ` };
|
|
98
|
-
`;
|
|
99
|
-
}
|
|
100
|
-
dtsContent += ` };
|
|
101
|
-
`;
|
|
102
|
-
} else {
|
|
103
|
-
dtsContent += ` globals: Record<string, any>;
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
dtsContent += `}
|
|
107
|
-
`;
|
|
108
|
-
const outputPath = resolve(process.cwd(), out || "opaca.d.ts");
|
|
109
|
-
fs.writeFileSync(outputPath, dtsContent);
|
|
110
|
-
console.log(`[OpacaCMS] Types successfully generated at ${outputPath}`);
|
|
111
|
-
}
|
|
112
|
-
function mapFieldToTsType(type) {
|
|
113
|
-
switch (type) {
|
|
114
|
-
case "text":
|
|
115
|
-
case "textarea":
|
|
116
|
-
case "richtext":
|
|
117
|
-
case "select":
|
|
118
|
-
case "date":
|
|
119
|
-
return "string";
|
|
120
|
-
case "number":
|
|
121
|
-
return "number";
|
|
122
|
-
case "boolean":
|
|
123
|
-
return "boolean";
|
|
124
|
-
case "json":
|
|
125
|
-
return "any | any[]";
|
|
126
|
-
case "file":
|
|
127
|
-
return "OpacaAsset";
|
|
128
|
-
case "relationship":
|
|
129
|
-
return "string | number | any";
|
|
130
|
-
default:
|
|
131
|
-
return "any";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/cli/commands/generate.ts
|
|
136
|
-
var generate_default = defineCommand({
|
|
137
|
-
meta: {
|
|
138
|
-
name: "generate",
|
|
139
|
-
description: "Generate boilerplates (collections/globals) or TypeScript definitions"
|
|
140
|
-
},
|
|
141
|
-
args: {
|
|
142
|
-
type: {
|
|
143
|
-
type: "positional",
|
|
144
|
-
description: "What to generate: 'types', 'collection', or 'global'",
|
|
145
|
-
required: true
|
|
146
|
-
},
|
|
147
|
-
name: {
|
|
148
|
-
type: "positional",
|
|
149
|
-
description: "The name of the collection or global to generate (if applicable)",
|
|
150
|
-
required: false
|
|
151
|
-
},
|
|
152
|
-
url: {
|
|
153
|
-
type: "string",
|
|
154
|
-
description: "The URL of the OpacaCMS instance (for 'types')"
|
|
155
|
-
},
|
|
156
|
-
token: {
|
|
157
|
-
type: "string",
|
|
158
|
-
description: "The API Key to use for fetching metadata (for 'types')"
|
|
159
|
-
},
|
|
160
|
-
out: {
|
|
161
|
-
type: "string",
|
|
162
|
-
alias: "o",
|
|
163
|
-
description: "The output file path (for 'types')"
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
async run({ args }) {
|
|
167
|
-
if (args.type === "types") {
|
|
168
|
-
if (!args.url || !args.token) {
|
|
169
|
-
R.error(import_picocolors.default.red("URL and Token are required to generate types from a remote instance."));
|
|
170
|
-
R.info("Usage: opacacms generate types --url <url> --token <token> [--out <file>]");
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
await generateTypesCommand(args.url, args.token, args.out || "opaca.d.ts");
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (args.type === "collection" || args.type === "global") {
|
|
177
|
-
let name = args.name;
|
|
178
|
-
if (!name) {
|
|
179
|
-
const response = await Zt({
|
|
180
|
-
message: `What should we name your ${args.type}? (e.g. ${args.type === "collection" ? "posts" : "site-settings"})`
|
|
181
|
-
});
|
|
182
|
-
if (Ct(response)) {
|
|
183
|
-
Nt("Operation cancelled.");
|
|
184
|
-
process.exit(0);
|
|
185
|
-
}
|
|
186
|
-
name = response;
|
|
187
|
-
}
|
|
188
|
-
const isCollection = args.type === "collection";
|
|
189
|
-
const folderName = isCollection ? "collections" : "globals";
|
|
190
|
-
const fileName = `${name}.ts`;
|
|
191
|
-
const filePath = resolve2(process.cwd(), folderName, fileName);
|
|
192
|
-
if (fs2.existsSync(filePath)) {
|
|
193
|
-
R.error(import_picocolors.default.red(`File already exists at ${folderName}/${fileName}`));
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
fs2.mkdirSync(resolve2(process.cwd(), folderName), { recursive: true });
|
|
197
|
-
const template = isCollection ? `import { z, defineCollection } from 'opacacms/schema';
|
|
198
|
-
|
|
199
|
-
export const ${name} = defineCollection({
|
|
200
|
-
slug: '${name}',
|
|
201
|
-
label: '${name.charAt(0).toUpperCase() + name.slice(1)}',
|
|
202
|
-
admin: {
|
|
203
|
-
useAsTitle: 'title',
|
|
204
|
-
icon: 'FileText'
|
|
205
|
-
},
|
|
206
|
-
schema: z.object({
|
|
207
|
-
id: z.text().default(() => crypto.randomUUID()),
|
|
208
|
-
title: z.text({ label: 'Title' }).required(),
|
|
209
|
-
content: z.richText({ label: 'Content' }),
|
|
210
|
-
})
|
|
211
|
-
});
|
|
212
|
-
` : `import { z, defineGlobal } from 'opacacms/schema';
|
|
213
|
-
|
|
214
|
-
export const ${name} = defineGlobal({
|
|
215
|
-
slug: '${name}',
|
|
216
|
-
label: '${name.charAt(0).toUpperCase() + name.slice(1)}',
|
|
217
|
-
admin: {
|
|
218
|
-
icon: 'Settings'
|
|
219
|
-
},
|
|
220
|
-
schema: z.object({
|
|
221
|
-
siteName: z.text({ label: 'Site Name' }).required(),
|
|
222
|
-
description: z.textarea({ label: 'Description' }),
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
`;
|
|
226
|
-
fs2.writeFileSync(filePath, template);
|
|
227
|
-
R.success(import_picocolors.default.green(`Successfully generated ${args.type} at ./${folderName}/${fileName}`));
|
|
228
|
-
Vt(`Don't forget to import it into your opacacms.config.ts and add it to the '${folderName}' array!`, "Reminder");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
R.error(import_picocolors.default.red(`Unknown generation type: ${args.type}. Use 'types', 'collection', or 'global'.`));
|
|
232
|
-
process.exit(1);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
export {
|
|
236
|
-
generate_default as default
|
|
237
|
-
};
|