@gearu/cli 1.2.0

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.
@@ -0,0 +1,162 @@
1
+ import {
2
+ parseEntryFields,
3
+ parseNullableOption
4
+ } from "./chunk-HI5EA6RV.js";
5
+ import {
6
+ createGearuCliRuntime,
7
+ printError,
8
+ printSuccess
9
+ } from "./chunk-U5KPPK2Y.js";
10
+ import {
11
+ init_esm_shims
12
+ } from "./chunk-RAR5OL4C.js";
13
+
14
+ // src/commands/entries.ts
15
+ init_esm_shims();
16
+ function buildEntryFields(rawFields) {
17
+ return parseEntryFields(rawFields);
18
+ }
19
+ async function listEntries(options) {
20
+ const runtime = await createGearuCliRuntime();
21
+ try {
22
+ const entries = await runtime.caller.entries.list({
23
+ collectionId: options.collectionId,
24
+ status: options.status,
25
+ limit: options.limit,
26
+ offset: options.offset
27
+ });
28
+ printSuccess(entries, options, (result) => {
29
+ if (result.length === 0) {
30
+ return "No entries found.";
31
+ }
32
+ return [
33
+ `Found ${result.length} entr${result.length === 1 ? "y" : "ies"}.`,
34
+ ...result.map(
35
+ (entry) => `#${entry.id} ${entry.title} (${entry.slug}) - ${entry.status}${entry.collection ? ` in ${entry.collection.name}` : ""}`
36
+ )
37
+ ].join("\n");
38
+ });
39
+ } catch (error) {
40
+ printError(error, options);
41
+ } finally {
42
+ runtime.close();
43
+ }
44
+ }
45
+ async function getEntry(id, options) {
46
+ const runtime = await createGearuCliRuntime();
47
+ try {
48
+ const entry = await runtime.caller.entries.getById({ id });
49
+ if (!entry) {
50
+ throw new Error(`Entry #${id} was not found.`);
51
+ }
52
+ printSuccess(entry, options, (result) => {
53
+ const lines = [
54
+ `Entry #${result.id}: ${result.title} (${result.slug})`,
55
+ `Status: ${result.status}`
56
+ ];
57
+ if (result.collection) {
58
+ lines.push(`Collection: ${result.collection.name} (${result.collection.slug})`);
59
+ }
60
+ if (result.metaTitle) {
61
+ lines.push(`Meta title: ${result.metaTitle}`);
62
+ }
63
+ if (result.metaDescription) {
64
+ lines.push(`Meta description: ${result.metaDescription}`);
65
+ }
66
+ if (result.ogImage) {
67
+ lines.push(`OG image: ${result.ogImage}`);
68
+ }
69
+ lines.push(`Fields: ${result.fields.length}`);
70
+ for (const field of result.fields) {
71
+ lines.push(`- ${field.field.name} (#${field.fieldId}): ${field.value ?? "null"}`);
72
+ }
73
+ return lines.join("\n");
74
+ });
75
+ } catch (error) {
76
+ printError(error, options);
77
+ } finally {
78
+ runtime.close();
79
+ }
80
+ }
81
+ async function createEntry(options) {
82
+ const runtime = await createGearuCliRuntime();
83
+ try {
84
+ if (!options.collectionId) {
85
+ throw new Error("`--collection-id` is required.");
86
+ }
87
+ if (!options.title) {
88
+ throw new Error("`--title` is required.");
89
+ }
90
+ const entry = await runtime.caller.entries.create({
91
+ collectionId: options.collectionId,
92
+ title: options.title,
93
+ slug: options.slug,
94
+ status: options.status ?? "draft",
95
+ metaTitle: options.metaTitle,
96
+ metaDescription: options.metaDescription,
97
+ ogImage: options.ogImage,
98
+ fields: buildEntryFields(options.fields) ?? []
99
+ });
100
+ printSuccess(entry, options, (result) => `Created entry #${result.id} ${result.title} (${result.slug}) with status ${result.status}.`);
101
+ } catch (error) {
102
+ printError(error, options);
103
+ } finally {
104
+ runtime.close();
105
+ }
106
+ }
107
+ async function updateEntry(id, options) {
108
+ const runtime = await createGearuCliRuntime();
109
+ try {
110
+ const hasContentUpdate = options.title !== void 0 || options.slug !== void 0 || options.metaTitle !== void 0 || options.metaDescription !== void 0 || options.ogImage !== void 0 || options.fields !== void 0;
111
+ if (!hasContentUpdate && options.status === void 0) {
112
+ throw new Error(
113
+ "Provide at least one of `--title`, `--slug`, `--status`, `--meta-title`, `--meta-description`, `--og-image`, or `--fields`."
114
+ );
115
+ }
116
+ let entry = hasContentUpdate ? await runtime.caller.entries.update({
117
+ id,
118
+ title: options.title,
119
+ slug: options.slug,
120
+ metaTitle: parseNullableOption(options.metaTitle),
121
+ metaDescription: parseNullableOption(options.metaDescription),
122
+ ogImage: parseNullableOption(options.ogImage),
123
+ fields: buildEntryFields(options.fields)
124
+ }) : await runtime.caller.entries.getById({ id });
125
+ if (!entry) {
126
+ throw new Error(`Entry #${id} was not found.`);
127
+ }
128
+ if (options.status !== void 0) {
129
+ entry = await runtime.caller.entries.updateStatus({
130
+ id,
131
+ status: options.status
132
+ });
133
+ if (!entry) {
134
+ throw new Error(`Entry #${id} was not found.`);
135
+ }
136
+ }
137
+ printSuccess(entry, options, (result) => `Updated entry #${result.id} ${result.title} (${result.slug}) with status ${result.status}.`);
138
+ } catch (error) {
139
+ printError(error, options);
140
+ } finally {
141
+ runtime.close();
142
+ }
143
+ }
144
+ async function deleteEntry(id, options) {
145
+ const runtime = await createGearuCliRuntime();
146
+ try {
147
+ await runtime.caller.entries.delete({ id });
148
+ printSuccess({ id }, options, (result) => `Deleted entry #${result.id}.`);
149
+ } catch (error) {
150
+ printError(error, options);
151
+ } finally {
152
+ runtime.close();
153
+ }
154
+ }
155
+ export {
156
+ createEntry,
157
+ deleteEntry,
158
+ getEntry,
159
+ listEntries,
160
+ updateEntry
161
+ };
162
+ //# sourceMappingURL=entries-AKHKPFRA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/entries.ts"],"sourcesContent":["import { parseEntryFields, parseNullableOption, type EntryFieldInput } from \"../lib/parsers\"\nimport { createGearuCliRuntime } from \"../lib/runtime\"\nimport { printError, printSuccess, type JsonFlagOption } from \"../lib/output\"\n\ninterface EntryListOptions extends JsonFlagOption {\n collectionId?: number\n status?: \"draft\" | \"published\" | \"archived\"\n limit?: number\n offset?: number\n}\n\ninterface EntryCreateOptions extends JsonFlagOption {\n collectionId?: number\n title?: string\n slug?: string\n status?: \"draft\" | \"published\"\n metaTitle?: string\n metaDescription?: string\n ogImage?: string\n fields?: string\n}\n\ninterface EntryUpdateOptions extends JsonFlagOption {\n title?: string\n slug?: string\n status?: \"draft\" | \"published\" | \"archived\"\n metaTitle?: string\n metaDescription?: string\n ogImage?: string\n fields?: string\n}\n\nfunction buildEntryFields(rawFields: string | undefined): EntryFieldInput[] | undefined {\n return parseEntryFields(rawFields)\n}\n\nexport async function listEntries(options: EntryListOptions) {\n const runtime = await createGearuCliRuntime()\n\n try {\n const entries = await runtime.caller.entries.list({\n collectionId: options.collectionId,\n status: options.status,\n limit: options.limit,\n offset: options.offset,\n })\n\n printSuccess(entries, options, (result) => {\n if (result.length === 0) {\n return \"No entries found.\"\n }\n\n return [\n `Found ${result.length} entr${result.length === 1 ? \"y\" : \"ies\"}.`,\n ...result.map(\n (entry) =>\n `#${entry.id} ${entry.title} (${entry.slug}) - ${entry.status}${entry.collection ? ` in ${entry.collection.name}` : \"\"}`,\n ),\n ].join(\"\\n\")\n })\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function getEntry(id: number, options: JsonFlagOption) {\n const runtime = await createGearuCliRuntime()\n\n try {\n const entry = await runtime.caller.entries.getById({ id })\n if (!entry) {\n throw new Error(`Entry #${id} was not found.`)\n }\n\n printSuccess(entry, options, (result) => {\n const lines = [\n `Entry #${result.id}: ${result.title} (${result.slug})`,\n `Status: ${result.status}`,\n ]\n\n if (result.collection) {\n lines.push(`Collection: ${result.collection.name} (${result.collection.slug})`)\n }\n if (result.metaTitle) {\n lines.push(`Meta title: ${result.metaTitle}`)\n }\n if (result.metaDescription) {\n lines.push(`Meta description: ${result.metaDescription}`)\n }\n if (result.ogImage) {\n lines.push(`OG image: ${result.ogImage}`)\n }\n\n lines.push(`Fields: ${result.fields.length}`)\n for (const field of result.fields) {\n lines.push(`- ${field.field.name} (#${field.fieldId}): ${field.value ?? \"null\"}`)\n }\n\n return lines.join(\"\\n\")\n })\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function createEntry(options: EntryCreateOptions) {\n const runtime = await createGearuCliRuntime()\n\n try {\n if (!options.collectionId) {\n throw new Error(\"`--collection-id` is required.\")\n }\n if (!options.title) {\n throw new Error(\"`--title` is required.\")\n }\n\n const entry = await runtime.caller.entries.create({\n collectionId: options.collectionId,\n title: options.title,\n slug: options.slug,\n status: options.status ?? \"draft\",\n metaTitle: options.metaTitle,\n metaDescription: options.metaDescription,\n ogImage: options.ogImage,\n fields: buildEntryFields(options.fields) ?? [],\n })\n\n printSuccess(entry, options, (result) => `Created entry #${result.id} ${result.title} (${result.slug}) with status ${result.status}.`)\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function updateEntry(id: number, options: EntryUpdateOptions) {\n const runtime = await createGearuCliRuntime()\n\n try {\n const hasContentUpdate =\n options.title !== undefined ||\n options.slug !== undefined ||\n options.metaTitle !== undefined ||\n options.metaDescription !== undefined ||\n options.ogImage !== undefined ||\n options.fields !== undefined\n\n if (!hasContentUpdate && options.status === undefined) {\n throw new Error(\n \"Provide at least one of `--title`, `--slug`, `--status`, `--meta-title`, `--meta-description`, `--og-image`, or `--fields`.\",\n )\n }\n\n let entry = hasContentUpdate\n ? await runtime.caller.entries.update({\n id,\n title: options.title,\n slug: options.slug,\n metaTitle: parseNullableOption(options.metaTitle),\n metaDescription: parseNullableOption(options.metaDescription),\n ogImage: parseNullableOption(options.ogImage),\n fields: buildEntryFields(options.fields),\n })\n : await runtime.caller.entries.getById({ id })\n\n if (!entry) {\n throw new Error(`Entry #${id} was not found.`)\n }\n\n if (options.status !== undefined) {\n entry = await runtime.caller.entries.updateStatus({\n id,\n status: options.status,\n })\n if (!entry) {\n throw new Error(`Entry #${id} was not found.`)\n }\n }\n\n printSuccess(entry, options, (result) => `Updated entry #${result.id} ${result.title} (${result.slug}) with status ${result.status}.`)\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function deleteEntry(id: number, options: JsonFlagOption) {\n const runtime = await createGearuCliRuntime()\n\n try {\n await runtime.caller.entries.delete({ id })\n printSuccess({ id }, options, (result) => `Deleted entry #${result.id}.`)\n } catch (error) {\n printError(error, options)\n } finally {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AAO,EAAE,IAAI,OAAO,KAAK,KAAK,OAAO,IAAI,iBAAiB,OAAO,MAAM,GAAG;AAAA,EACvI,SAAS,OAAO;AACd,eAAW,OAAO,OAAO;AAAA,EAC3B,UAAE;AACA,YAAQ,MAAM;AAAA,EAChB;AACF;AAEA,eAAsB,YAAY,IAAY,SAAyB;AACrE,QAAM,UAAU,MAAM,sBAAsB;AAE5C,MAAI;AACF,UAAM,QAAQ,OAAO,QAAQ,OAAO,EAAE,GAAG,CAAC;AAC1C,iBAAa,EAAE,GAAG,GAAG,SAAS,CAAC,WAAW,kBAAkB,OAAO,EAAE,GAAG;AAAA,EAC1E,SAAS,OAAO;AACd,eAAW,OAAO,OAAO;AAAA,EAC3B,UAAE;AACA,YAAQ,MAAM;AAAA,EAChB;AACF;","names":[]}
@@ -0,0 +1,37 @@
1
+ import {
2
+ init_esm_shims
3
+ } from "./chunk-RAR5OL4C.js";
4
+
5
+ // src/commands/init.ts
6
+ init_esm_shims();
7
+ import { writeFileSync, existsSync } from "fs";
8
+ import { join } from "path";
9
+ import { cwd } from "process";
10
+ var GEARU_CONFIG = `import type { GearuConfig } from "@gearu/core"
11
+
12
+ const config: GearuConfig = {
13
+ database: process.env.DATABASE_URL ?? "file:./dev.db",
14
+ plugins: [
15
+ "@gearu/plugin-leads",
16
+ "@gearu/plugin-analytics",
17
+ ],
18
+ }
19
+
20
+ export default config
21
+ `;
22
+ async function init() {
23
+ const root = cwd();
24
+ const configPath = join(root, "gearu.config.ts");
25
+ if (!existsSync(configPath)) {
26
+ writeFileSync(configPath, GEARU_CONFIG, "utf-8");
27
+ console.log("Created gearu.config.ts");
28
+ } else {
29
+ console.log("gearu.config.ts already exists");
30
+ }
31
+ console.log("Ensure your app has a route src/routes/admin/$.tsx that renders @gearu/admin.");
32
+ console.log("Run gearu migrate to apply migrations.");
33
+ }
34
+ export {
35
+ init
36
+ };
37
+ //# sourceMappingURL=init-YPPWOECE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/init.ts"],"sourcesContent":["import { writeFileSync, existsSync } from \"fs\"\nimport { join } from \"path\"\nimport { cwd } from \"process\"\n\nconst GEARU_CONFIG = `import type { GearuConfig } from \"@gearu/core\"\n\nconst config: GearuConfig = {\n database: process.env.DATABASE_URL ?? \"file:./dev.db\",\n plugins: [\n \"@gearu/plugin-leads\",\n \"@gearu/plugin-analytics\",\n ],\n}\n\nexport default config\n`\n\nexport async function init() {\n const root = cwd()\n const configPath = join(root, \"gearu.config.ts\")\n if (!existsSync(configPath)) {\n writeFileSync(configPath, GEARU_CONFIG, \"utf-8\")\n console.log(\"Created gearu.config.ts\")\n } else {\n console.log(\"gearu.config.ts already exists\")\n }\n console.log(\"Ensure your app has a route src/routes/admin/$.tsx that renders @gearu/admin.\")\n console.log(\"Run gearu migrate to apply migrations.\")\n}\n"],"mappings":";;;;;AAAA;AAAA,SAAS,eAAe,kBAAkB;AAC1C,SAAS,YAAY;AACrB,SAAS,WAAW;AAEpB,IAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAarB,eAAsB,OAAO;AAC3B,QAAM,OAAO,IAAI;AACjB,QAAM,aAAa,KAAK,MAAM,iBAAiB;AAC/C,MAAI,CAAC,WAAW,UAAU,GAAG;AAC3B,kBAAc,YAAY,cAAc,OAAO;AAC/C,YAAQ,IAAI,yBAAyB;AAAA,EACvC,OAAO;AACL,YAAQ,IAAI,gCAAgC;AAAA,EAC9C;AACA,UAAQ,IAAI,+EAA+E;AAC3F,UAAQ,IAAI,wCAAwC;AACtD;","names":[]}