@plank-cms/plank 0.24.3 → 0.26.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.
@@ -12,7 +12,7 @@
12
12
  href="https://fonts.googleapis.com/css2?family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&display=swap"
13
13
  rel="stylesheet"
14
14
  />
15
- <script type="module" crossorigin src="/admin/assets/index-DcMspdw2.js"></script>
15
+ <script type="module" crossorigin src="/admin/assets/index-D97Xg1Z-.js"></script>
16
16
  <link rel="stylesheet" crossorigin href="/admin/assets/index-BSi0iXTe.css">
17
17
  </head>
18
18
  <body>
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { randomBytes } from "crypto";
7
7
  import { resolve, join } from "path";
8
8
  import fs from "fs-extra";
9
9
  import { execa } from "execa";
10
- var PACKAGE_VERSION = "0.24.3";
10
+ var PACKAGE_VERSION = "0.26.0";
11
11
  function generateSecret() {
12
12
  return randomBytes(32).toString("hex");
13
13
  }
@@ -25,7 +25,8 @@ function buildPackageJson(name) {
25
25
  version: "0.1.0",
26
26
  private: true,
27
27
  scripts: {
28
- start: "plank start"
28
+ start: "plank start",
29
+ update: "plank update"
29
30
  },
30
31
  dependencies: {
31
32
  "@plank-cms/plank": PACKAGE_VERSION
@@ -87,7 +88,11 @@ async function init(projectName) {
87
88
  `${chalk.yellow("Important:")} keep ${chalk.cyan("PLANK_JWT_SECRET")} and ${chalk.cyan("PLANK_ENCRYPTION_KEY")} set in production.`,
88
89
  "",
89
90
  ...!useCurrentDir ? [` ${chalk.cyan(`cd ${name}`)}`, ""] : [],
90
- ` ${chalk.cyan("npm start")}`
91
+ ` ${chalk.cyan("npm start")}`,
92
+ "",
93
+ `To update Plank later:`,
94
+ "",
95
+ ` ${chalk.cyan("npm run update")}`
91
96
  ].join("\n"),
92
97
  "Next steps"
93
98
  );
@@ -101,7 +106,7 @@ import { dirname, join as join2, resolve as resolve2 } from "path";
101
106
  async function start() {
102
107
  config({ path: resolve2(process.cwd(), ".env") });
103
108
  process.env.PLANK_ADMIN_DIST = join2(dirname(fileURLToPath(import.meta.url)), "admin");
104
- const { start: startServer } = await import("./server-KRX65XUC.js");
109
+ const { start: startServer } = await import("./server-ESNIHORP.js");
105
110
  await startServer();
106
111
  }
107
112
 
@@ -157,6 +162,44 @@ async function publishScheduled() {
157
162
  }
158
163
  }
159
164
 
165
+ // src/commands/update.ts
166
+ import { intro as intro2, outro as outro2, spinner as spinner2 } from "@clack/prompts";
167
+ import chalk2 from "chalk";
168
+ import { execa as execa2 } from "execa";
169
+ import fs2 from "fs-extra";
170
+ import { join as join3 } from "path";
171
+ var PACKAGE_NAME = "@plank-cms/plank";
172
+ async function update(version = "latest") {
173
+ intro2(chalk2.bold("\u25B2 Plank CMS"));
174
+ const packageJsonPath = join3(process.cwd(), "package.json");
175
+ const hasPackageJson = await fs2.pathExists(packageJsonPath);
176
+ if (!hasPackageJson) {
177
+ throw new Error("No package.json found in the current directory.");
178
+ }
179
+ const packageJson = await fs2.readJSON(packageJsonPath);
180
+ const dependencies = {
181
+ ...packageJson.dependencies,
182
+ ...packageJson.devDependencies
183
+ };
184
+ if (!dependencies[PACKAGE_NAME]) {
185
+ throw new Error(`Current project does not depend on ${PACKAGE_NAME}.`);
186
+ }
187
+ const s = spinner2();
188
+ const target = `${PACKAGE_NAME}@${version}`;
189
+ s.start(`Updating ${PACKAGE_NAME} to ${chalk2.cyan(version)}...`);
190
+ try {
191
+ await execa2("npm", ["install", "--save-exact", target], {
192
+ cwd: process.cwd(),
193
+ stdio: "inherit"
194
+ });
195
+ } catch (error) {
196
+ s.stop(chalk2.red("Update failed"));
197
+ throw error;
198
+ }
199
+ s.stop(`Updated ${PACKAGE_NAME}`);
200
+ outro2(`Plank is now installed from ${chalk2.cyan(target)}`);
201
+ }
202
+
160
203
  // src/index.ts
161
204
  var [, , command, ...args] = process.argv;
162
205
  switch (command) {
@@ -169,11 +212,14 @@ switch (command) {
169
212
  case "publish-scheduled":
170
213
  await publishScheduled();
171
214
  break;
215
+ case "update":
216
+ await update(args[0]);
217
+ break;
172
218
  default:
173
219
  if (command && !command.startsWith("-")) {
174
220
  await init(command);
175
221
  } else {
176
- console.error("Usage: plank <init|start|publish-scheduled> [project-name]");
222
+ console.error("Usage: plank <init|start|publish-scheduled|update> [project-name|version]");
177
223
  process.exit(1);
178
224
  }
179
225
  }
@@ -0,0 +1,2 @@
1
+ ALTER TABLE plank_content_types
2
+ ADD COLUMN IF NOT EXISTS preview_enabled BOOLEAN NOT NULL DEFAULT TRUE;
@@ -204,6 +204,7 @@ function rowToContentType(row) {
204
204
  name: row.name,
205
205
  slug: row.slug,
206
206
  kind: row.kind,
207
+ previewEnabled: row.preview_enabled,
207
208
  tableName: row.table_name,
208
209
  fields: row.fields,
209
210
  isDefault: row.is_default,
@@ -220,16 +221,24 @@ async function findContentTypeBySlug(slug) {
220
221
  return rows[0] ? rowToContentType(rows[0]) : null;
221
222
  }
222
223
  async function saveContentType(contentType) {
223
- const { rows } = await pool_default.query(`INSERT INTO plank_content_types (id, name, slug, kind, table_name, fields)
224
- VALUES ($1, $2, $3, $4, $5, $6)
225
- RETURNING *`, [createId(), contentType.name, contentType.slug, contentType.kind ?? "collection", contentType.tableName, JSON.stringify(contentType.fields)]);
224
+ const { rows } = await pool_default.query(`INSERT INTO plank_content_types (id, name, slug, kind, preview_enabled, table_name, fields)
225
+ VALUES ($1, $2, $3, $4, $5, $6, $7)
226
+ RETURNING *`, [
227
+ createId(),
228
+ contentType.name,
229
+ contentType.slug,
230
+ contentType.kind ?? "collection",
231
+ contentType.previewEnabled ?? true,
232
+ contentType.tableName,
233
+ JSON.stringify(contentType.fields)
234
+ ]);
226
235
  return rowToContentType(rows[0]);
227
236
  }
228
237
  async function updateContentType(slug, contentType) {
229
238
  const { rows } = await pool_default.query(`UPDATE plank_content_types
230
- SET name = $1, fields = $2, updated_at = NOW()
231
- WHERE slug = $3
232
- RETURNING *`, [contentType.name, JSON.stringify(contentType.fields), slug]);
239
+ SET name = $1, fields = $2, preview_enabled = $3, updated_at = NOW()
240
+ WHERE slug = $4
241
+ RETURNING *`, [contentType.name, JSON.stringify(contentType.fields), contentType.previewEnabled ?? true, slug]);
233
242
  return rowToContentType(rows[0]);
234
243
  }
235
244
  async function setDefaultContentType(slug) {
@@ -2977,6 +2986,7 @@ var ContentTypeSchema = z2.object({
2977
2986
  name: z2.string().min(1),
2978
2987
  slug: z2.string().regex(/^[a-z][a-z0-9-]*$/, "Slug must be lowercase with hyphens"),
2979
2988
  tableName: z2.string().regex(/^[a-z][a-z0-9_]*$/, "Table name must be lowercase with underscores"),
2989
+ previewEnabled: z2.boolean().default(true),
2980
2990
  fields: z2.array(FieldSchema)
2981
2991
  });
2982
2992
  var CreateContentTypeSchema = ContentTypeSchema.extend({
@@ -3628,7 +3638,9 @@ var createEntry = async (req, res) => {
3628
3638
  }));
3629
3639
  res.status(201).json(normalizeNavigationFields(rows[0], ct.fields));
3630
3640
  triggerWebhooks("entry.created", { content_type: req.params.slug, entry_id: rows[0].id });
3631
- triggerPreviewSyncWebhook({ contentType: req.params.slug, entry: rows[0] });
3641
+ if (ct.previewEnabled !== false) {
3642
+ triggerPreviewSyncWebhook({ contentType: req.params.slug, entry: rows[0] });
3643
+ }
3632
3644
  };
3633
3645
  var getSingleEntry = async (req, res) => {
3634
3646
  const ct = await findContentTypeBySlug(req.params.slug);
@@ -3722,7 +3734,9 @@ var updateEntry = async (req, res) => {
3722
3734
  }));
3723
3735
  res.json(normalizeNavigationFields(rows[0], ct.fields));
3724
3736
  triggerWebhooks("entry.updated", { content_type: req.params.slug, entry_id: req.params.id });
3725
- triggerPreviewSyncWebhook({ contentType: req.params.slug, entry: rows[0] });
3737
+ if (ct.previewEnabled !== false) {
3738
+ triggerPreviewSyncWebhook({ contentType: req.params.slug, entry: rows[0] });
3739
+ }
3726
3740
  };
3727
3741
  var SNAPSHOT_EXCLUDED = [
3728
3742
  "'id'",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plank-cms/plank",
3
- "version": "0.24.3",
3
+ "version": "0.26.0",
4
4
  "description": "Self-hosted headless CMS. Deploy in minutes on your own infrastructure.",
5
5
  "type": "module",
6
6
  "files": [
@@ -55,9 +55,9 @@
55
55
  "devDependencies": {
56
56
  "@types/fs-extra": "^11.0.4",
57
57
  "tsup": "^8.5.0",
58
- "@plank-cms/core": "0.24.3",
59
- "@plank-cms/schema": "0.24.3",
60
- "@plank-cms/db": "0.24.3"
58
+ "@plank-cms/core": "0.26.0",
59
+ "@plank-cms/db": "0.26.0",
60
+ "@plank-cms/schema": "0.26.0"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsup",