vite-plugin-decap-cms 0.1.0 → 0.3.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.
package/README.md CHANGED
@@ -1,69 +1,70 @@
1
- # vite-plugin-decap-cms
2
-
3
- > A Vite plugin to connect Decap CMS
4
-
5
- ![NPM Version](https://img.shields.io/npm/v/vite-plugin-decap-cms)
6
- ![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-decap-cms)
7
- ![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ghostrider-05/vite-plugin-decap-cms)
8
-
9
-
10
- > [!DANGER] Unstable version
11
- > This plugin has not reached a stable version, 1.0.0, and can include breaking changes following the semver specification. This plugin is open for contributions, both for code, suggestions and (missing) documentation.
12
-
13
- ## Install
14
-
15
- ```sh
16
- pnpm add vite-plugin-decap-cms -D
17
- npm install vite-plugin-decap-cms -D
18
- yarn add vite-plugin-decap-cms -D
19
- ```
20
-
21
- ## Usage
22
-
23
- ```ts
24
- // vite.config.ts
25
- import { defineConfig } from 'vite'
26
- import decap, {
27
- createFolderCollection,
28
- createField,
29
- } from 'vite-plugin-decap-cms'
30
-
31
- export default defineConfig({
32
- publicDir: 'public',
33
- plugins: [
34
- decap({
35
- config: {
36
- backend: {
37
- name: 'test-repo',
38
- },
39
- mediaFolder: '/src/public/',
40
- collections: [
41
- createFolderCollection({
42
- name: 'test',
43
- label: 'Test collection',
44
- folder: 'test',
45
- fields: [
46
- createField('markdown', { name: 'body' }),
47
- ],
48
- }),
49
- ]
50
- }
51
- })
52
- ],
53
- })
54
- ```
55
-
56
- ## Example
57
-
58
- See [the documentation](https://vite-plugin-decap.pages.dev) for an example
59
-
60
- ## Development
61
-
62
- ```sh
63
- npm run docs:dev
64
- npm run cms:dev
65
- ```
66
-
67
- ## License
68
-
69
- [MIT](LICENSE)
1
+ # vite-plugin-decap-cms
2
+
3
+ > A Vite plugin to connect Decap CMS
4
+
5
+ ![NPM Version](https://img.shields.io/npm/v/vite-plugin-decap-cms)
6
+ ![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-decap-cms)
7
+ ![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ghostrider-05/vite-plugin-decap-cms)
8
+
9
+ > [!WARNING]
10
+ > This plugin has not reached a stable version, 1.0.0, and can include breaking changes following the semver specification. This plugin is open for contributions, both for code, suggestions and (missing) documentation.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ pnpm add vite-plugin-decap-cms -D
16
+ npm install vite-plugin-decap-cms -D
17
+ yarn add vite-plugin-decap-cms -D
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ // vite.config.ts
24
+ import { defineConfig } from 'vite'
25
+ import decap, {
26
+ createFolderCollection,
27
+ createField,
28
+ } from 'vite-plugin-decap-cms'
29
+
30
+ export default defineConfig({
31
+ publicDir: 'public',
32
+ plugins: [
33
+ decap({
34
+ config: {
35
+ backend: {
36
+ name: 'test-repo',
37
+ },
38
+ mediaFolder: '/src/public/',
39
+ collections: [
40
+ createFolderCollection({
41
+ name: 'test',
42
+ label: 'Test collection',
43
+ folder: 'test',
44
+ fields: [
45
+ createField('markdown', { name: 'body' }),
46
+ ],
47
+ }),
48
+ ]
49
+ }
50
+ })
51
+ ],
52
+ })
53
+ ```
54
+
55
+ For more options and guides, see [the documentation](https://vite-plugin-decap-cms.pages.dev)
56
+
57
+ ## Example
58
+
59
+ See [the documentation CMS](https://vite-plugin-decap-cms.pages.dev/admin/index.html) for an example
60
+
61
+ ## Development
62
+
63
+ ```sh
64
+ # in /docs/
65
+ npm run docs:dev
66
+ ```
67
+
68
+ ## License
69
+
70
+ [MIT](LICENSE)
package/dist/index.cjs CHANGED
@@ -58,6 +58,7 @@ __export(src_exports, {
58
58
  getGitData: () => getGitData
59
59
  });
60
60
  module.exports = __toCommonJS(src_exports);
61
+ var import_child_process2 = require("child_process");
61
62
  var import_yaml = require("yaml");
62
63
 
63
64
  // src/util.ts
@@ -70,10 +71,10 @@ function getGitData() {
70
71
  }
71
72
  };
72
73
  return {
73
- get branch() {
74
+ getBranch() {
74
75
  return executeGit("git rev-parse --abbrev-ref HEAD");
75
76
  },
76
- get commitSha() {
77
+ getCommitSha() {
77
78
  return executeGit("git rev-parse HEAD");
78
79
  }
79
80
  };
@@ -95,25 +96,32 @@ function createFileCollection(data) {
95
96
  function createOverwriteableField(widget, data, overwrites) {
96
97
  if (overwrites != void 0) {
97
98
  const toAdd = (key) => {
98
- if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key])
99
- data[key] = overwrites[key];
99
+ if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
100
100
  };
101
101
  for (const key of Object.keys(overwrites)) {
102
- if (key !== "hidden") {
102
+ if (key !== "hidden" && key !== "deleted") {
103
103
  toAdd(key);
104
104
  }
105
105
  }
106
106
  }
107
- if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden")
108
- return createField("hidden", data);
109
- else
110
- return __spreadProps(__spreadValues({}, data), {
111
- widget
112
- });
107
+ if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
108
+ else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
109
+ else return __spreadProps(__spreadValues({}, data), {
110
+ widget
111
+ });
112
+ }
113
+ function filterUndefined(item) {
114
+ return item != void 0;
115
+ }
116
+ function omit(obj, keys) {
117
+ if (!obj) return void 0;
118
+ const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
119
+ return Object.fromEntries(validEntries);
113
120
  }
114
121
  var VitePress = class {
115
122
  /**
116
123
  * Create fields for:
124
+ * - layout
117
125
  * - navbar
118
126
  * - sidebar
119
127
  * - aside
@@ -130,6 +138,12 @@ var VitePress = class {
130
138
  static createDefaultThemeNormalPageFields(options) {
131
139
  const { overwrites } = options != null ? options : {};
132
140
  return [
141
+ createOverwriteableField("string", {
142
+ name: "layout",
143
+ label: "Layout",
144
+ required: false,
145
+ default: "doc"
146
+ }),
133
147
  createOverwriteableField("boolean", {
134
148
  name: "navbar",
135
149
  label: "Whether to display the navbar",
@@ -139,42 +153,48 @@ var VitePress = class {
139
153
  createOverwriteableField("boolean", {
140
154
  name: "sidebar",
141
155
  label: "Whether to display the sidebar",
142
- default: true
156
+ default: true,
157
+ required: false
143
158
  }, overwrites == null ? void 0 : overwrites.sidebar),
144
159
  // TODO: add aside 'left' option
145
160
  createOverwriteableField("boolean", {
146
161
  name: "aside",
147
162
  label: "Whether to display the aside container",
148
- default: true
163
+ default: true,
164
+ required: false
149
165
  }, overwrites == null ? void 0 : overwrites.aside),
150
166
  // TODO: add support for [number, number] | 'deep' | false
151
167
  createOverwriteableField("number", {
152
168
  name: "outline",
153
169
  label: "The header levels in the outline",
154
- default: 2
170
+ default: 2,
171
+ required: false
155
172
  }, overwrites == null ? void 0 : overwrites.outline),
156
173
  // TODO: add support for Date
157
174
  createOverwriteableField("boolean", {
158
175
  name: "lastUpdated",
159
176
  label: "Whether to display last updated text",
160
- default: true
177
+ default: true,
178
+ required: false
161
179
  }, overwrites == null ? void 0 : overwrites.lastUpdated),
162
180
  createOverwriteableField("boolean", {
163
181
  name: "editLink",
164
182
  label: "Whether to display edit link text",
165
- default: true
183
+ default: true,
184
+ required: false
166
185
  }, overwrites == null ? void 0 : overwrites.editLink),
167
186
  createOverwriteableField("boolean", {
168
187
  name: "footer",
169
188
  label: "Whether to display footer text",
170
- default: true
189
+ default: true,
190
+ required: false
171
191
  }, overwrites == null ? void 0 : overwrites.footer),
172
192
  createOverwriteableField("string", {
173
193
  name: "pageClass",
174
194
  label: "Page class",
175
195
  required: false
176
196
  }, overwrites == null ? void 0 : overwrites.pageClass)
177
- ];
197
+ ].filter(filterUndefined);
178
198
  }
179
199
  /**
180
200
  * Create fields for:
@@ -186,7 +206,7 @@ var VitePress = class {
186
206
  * @see https://vitepress.dev/reference/frontmatter-config
187
207
  */
188
208
  static createDefaultPageFields(options) {
189
- var _a;
209
+ var _a, _b;
190
210
  const { additionalFields, overwrites } = options != null ? options : {};
191
211
  const fields = [
192
212
  createOverwriteableField("string", {
@@ -207,11 +227,123 @@ var VitePress = class {
207
227
  name: "head",
208
228
  label: "Head"
209
229
  }, overwrites == null ? void 0 : overwrites.head)
210
- ];
211
- return fields.concat(additionalFields != null ? additionalFields : []).concat(createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
230
+ ].filter(filterUndefined);
231
+ return fields.concat(additionalFields != null ? additionalFields : []).concat((_b = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
212
232
  name: "body",
213
233
  label: "Page content"
214
- }), overwrites == null ? void 0 : overwrites.body));
234
+ }), overwrites == null ? void 0 : overwrites.body)) != null ? _b : []).filter(filterUndefined);
235
+ }
236
+ /**
237
+ * Create fields for:
238
+ * - layout: home (not overwriteable)
239
+ * - hero
240
+ * - features
241
+ *
242
+ * The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
243
+ */
244
+ static createHomePageFields(options) {
245
+ const { overwrites } = options != null ? options : {};
246
+ const keys = ["hidden", "deleted"];
247
+ return [
248
+ createField("hidden", {
249
+ name: "layout",
250
+ default: "home"
251
+ }),
252
+ createOverwriteableField("object", {
253
+ name: "hero",
254
+ label: "Hero items",
255
+ required: true,
256
+ fields: [
257
+ createOverwriteableField("string", {
258
+ name: "name",
259
+ required: false
260
+ }, overwrites == null ? void 0 : overwrites.heroName),
261
+ createOverwriteableField("string", {
262
+ name: "text"
263
+ }, overwrites == null ? void 0 : overwrites.heroText),
264
+ createOverwriteableField("string", {
265
+ name: "tagline",
266
+ required: false
267
+ }, overwrites == null ? void 0 : overwrites.heroTagline),
268
+ // TODO: add support for object options
269
+ createOverwriteableField("image", {
270
+ name: "image",
271
+ required: false
272
+ }, overwrites == null ? void 0 : overwrites.heroImage),
273
+ createOverwriteableField("list", {
274
+ name: "actions",
275
+ label: "Action buttons",
276
+ label_singular: "action",
277
+ allow_add: true,
278
+ fields: [
279
+ createOverwriteableField("string", {
280
+ name: "text"
281
+ }, overwrites == null ? void 0 : overwrites.heroActionText),
282
+ createOverwriteableField("string", {
283
+ name: "link"
284
+ }, overwrites == null ? void 0 : overwrites.heroActionLink),
285
+ createOverwriteableField("select", {
286
+ name: "theme",
287
+ required: false,
288
+ default: "brand",
289
+ options: [
290
+ "brand",
291
+ "alt"
292
+ ]
293
+ }, overwrites == null ? void 0 : overwrites.heroActionTheme),
294
+ createOverwriteableField("string", {
295
+ name: "target",
296
+ required: false
297
+ }, overwrites == null ? void 0 : overwrites.heroActionTarget),
298
+ createOverwriteableField("string", {
299
+ name: "rel",
300
+ required: false
301
+ }, overwrites == null ? void 0 : overwrites.heroActionRel)
302
+ ].filter(filterUndefined)
303
+ }, omit(overwrites == null ? void 0 : overwrites.heroActions, keys))
304
+ ].filter(filterUndefined)
305
+ }, omit(overwrites == null ? void 0 : overwrites.hero, keys)),
306
+ createOverwriteableField("list", {
307
+ name: "features",
308
+ label: "Features",
309
+ label_singular: "feature",
310
+ allow_add: true,
311
+ required: false,
312
+ fields: [
313
+ createOverwriteableField("string", {
314
+ name: "title",
315
+ required: true
316
+ }, overwrites == null ? void 0 : overwrites.featuresTitle),
317
+ createOverwriteableField("string", {
318
+ name: "details",
319
+ required: false
320
+ }, overwrites == null ? void 0 : overwrites.featuresDetails),
321
+ // TODO: add support for object options
322
+ createOverwriteableField("string", {
323
+ name: "icon",
324
+ required: false
325
+ }, overwrites == null ? void 0 : overwrites.featuresIcon),
326
+ createOverwriteableField("string", {
327
+ name: "link",
328
+ required: false
329
+ }, overwrites == null ? void 0 : overwrites.featuresLink),
330
+ createOverwriteableField("string", {
331
+ name: "linkText",
332
+ label: "Link text",
333
+ required: false
334
+ }, overwrites == null ? void 0 : overwrites.featuresLinkText),
335
+ createOverwriteableField("string", {
336
+ name: "target",
337
+ label: "Target",
338
+ required: false
339
+ }, overwrites == null ? void 0 : overwrites.featuresTarget),
340
+ createOverwriteableField("string", {
341
+ name: "rel",
342
+ required: false
343
+ }, overwrites == null ? void 0 : overwrites.featuresRel)
344
+ ].filter(filterUndefined)
345
+ }, omit(overwrites == null ? void 0 : overwrites.features, keys))
346
+ ];
215
347
  }
216
348
  static createDefaultPageFolderCollection(name, folder, options) {
217
349
  const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
@@ -259,7 +391,8 @@ function getBooleanFromEnv(value, command) {
259
391
  }
260
392
  function resolveBackend(options, command) {
261
393
  const _a = options, { local, name } = _a, backend = __objRest(_a, ["local", "name"]);
262
- const branch = "useCurrentBranch" in options && getBooleanFromEnv(options.useCurrentBranch, command) ? getGitData().branch : "branch" in backend ? backend.branch : void 0;
394
+ const git = getGitData();
395
+ const branch = "useCurrentBranch" in options && getBooleanFromEnv(options.useCurrentBranch, command) ? git.getBranch() : "branch" in backend ? backend.branch : void 0;
263
396
  delete backend.useCurrentBranch;
264
397
  const resolved = {
265
398
  local_backend: typeof local === "object" ? objToSnakeCase(local) : getBooleanFromEnv(local, command),
@@ -289,78 +422,146 @@ function createConfigFile(config, command) {
289
422
  });
290
423
  })
291
424
  });
292
- } else
293
- throw new Error("Missing either fields or files property in collection");
425
+ } else throw new Error("Missing either fields or files property in collection");
294
426
  })
295
427
  });
296
428
  }
297
429
 
298
430
  // src/script.ts
431
+ function createCmsFunction(method, items, createParams, options) {
432
+ var _a;
433
+ const create = (params) => {
434
+ var _a2;
435
+ return `${(_a2 = options == null ? void 0 : options.base) != null ? _a2 : "CMS"}.${method}(${params})`;
436
+ };
437
+ return (items != null ? items : []).map((item) => {
438
+ const params = createParams(item);
439
+ if (!params) return null;
440
+ else return create(params);
441
+ }).filter(Boolean).join((_a = options == null ? void 0 : options.joinChar) != null ? _a : "\n");
442
+ }
299
443
  function createScript(options) {
300
444
  const _a = options, {
301
445
  useManualInitialization,
446
+ markdownEditorComponents,
447
+ formatters,
448
+ previewStylesheets,
302
449
  onGenerated: onGenerated,
303
450
  onInitialized
304
451
  } = _a, eventHooks = __objRest(_a, [
305
452
  "useManualInitialization",
453
+ "markdownEditorComponents",
454
+ "formatters",
455
+ "previewStylesheets",
456
+ // previewTemplates,
457
+ // widgets,
306
458
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
307
459
  "onGenerated",
308
460
  "onInitialized"
309
461
  ]);
310
- const events = Object.keys(eventHooks).map((hookName) => {
462
+ const events = createCmsFunction("registerEventListener", Object.keys(eventHooks), (hookName) => {
311
463
  const hook = eventHooks[hookName];
312
- if (!hook)
313
- return null;
464
+ if (!hook) return null;
314
465
  else {
315
466
  const name = hookName.slice(2)[0].toLowerCase() + hookName.slice(3);
316
- return `CMS.registerEventListener({ name: '${name}', handler: data => { function ${hook.toString()}; ${hookName}({ app: CMS, ...data }) } })`;
467
+ return `{ name: '${name}', handler: data => { function ${hook.toString()}; ${hookName}({ app: CMS, ...data }) } }`;
317
468
  }
318
- }).join("\n");
469
+ });
470
+ const customFormatters = createCmsFunction("registerCustomFormat", formatters, ({ name, extension, formatter }) => {
471
+ return `'${name}', '${extension}', ${formatter.toString()}`;
472
+ });
473
+ const customStyles = createCmsFunction("registerPreviewStyle", previewStylesheets, (style) => {
474
+ return typeof style === "string" ? style : `${style.style}, { raw: ${style.options.raw} }`;
475
+ });
476
+ const editorComponents = createCmsFunction("registerEditorComponent", markdownEditorComponents, (item) => {
477
+ const _a2 = item, { pattern, toPreview, toBlock, fromBlock } = _a2, component = __objRest(_a2, ["pattern", "toPreview", "toBlock", "fromBlock"]);
478
+ return `{ pattern: ${pattern}, toPreview: ${toPreview.toString()}, toBlock: ${toBlock.toString()}, fromBlock: ${fromBlock.toString()}, ...${JSON.stringify(component)}}`;
479
+ });
319
480
  return `
320
481
  <script>
321
482
  ${useManualInitialization ? "window.CMS_MANUAL_INIT = true;" : ""}
322
483
  ${onInitialized != void 0 ? `window.onload = () => { function ${onInitialized.toString()}; onInitialized({ app: CMS }) }` : ""}
484
+ ${customFormatters}
485
+ ${customStyles}
323
486
  ${events}
487
+ ${editorComponents}
324
488
  </script>`;
325
489
  }
326
490
 
327
491
  // src/files/index.ts
492
+ var defaultDecapCmsCdnVersion = "3.1.11";
493
+ var defaultNetlifyIdentityVersion = "1";
494
+ var addSlash = (path, slash = "/") => path.endsWith(slash) ? path : path + slash;
328
495
  function resolveCdnRoute(options) {
329
- const getUrl = (host = "https://unpkg.com/", version = "3.1.3") => {
330
- return `${host.endsWith("/") ? host : host + "/"}decap-cms@^${version}/dist/decap-cms.js`;
496
+ const getUrl = (host = "https://unpkg.com/", version = defaultDecapCmsCdnVersion) => {
497
+ return `${addSlash(host)}decap-cms@^${version}/dist/decap-cms.js`;
331
498
  };
332
499
  return typeof options === "boolean" ? options ? getUrl() : void 0 : typeof options === "string" ? options : options != void 0 ? getUrl(options.base, options.version) : void 0;
333
500
  }
334
- function getIndexFeatures(options) {
335
- var _a, _b;
336
- function useNetlifyIdentity(options2) {
337
- return options2.config.backend.name === "git-gateway";
338
- }
501
+ function resolveHead(head) {
502
+ return head.reduce((output, config) => {
503
+ if (typeof config === "string") return output.concat(config);
504
+ if ("skip" in config) {
505
+ if (config.skip) return output;
506
+ if (typeof config.head === "string") return output.concat(config.head);
507
+ }
508
+ const item = "head" in config ? config.head : config;
509
+ let str = `<${item[0]}`;
510
+ for (const key in item[1]) {
511
+ str += ` ${key}="${item[1][key]}"`;
512
+ }
513
+ str += item[0] === "meta" ? "/>" : ">";
514
+ if (item[2] == void 0) return output.concat(str);
515
+ str += item[2] + `</${item[0]}>`;
516
+ return output.concat(str);
517
+ }, []);
518
+ }
519
+ function getIndexFeatures(config, loadOptions) {
520
+ var _a;
521
+ const configRoute = config.dir ? addSlash(config.dir) + "config.yml" : void 0;
339
522
  return {
340
- cdn_route: resolveCdnRoute(options.load == void 0 || options.load.method === "cdn" ? (_b = (_a = options.load) == null ? void 0 : _a.options) != null ? _b : true : void 0),
341
- custom_logo: "logoUrl" in options.config ? options.config.logoUrl != void 0 : "logo_url" in options.config ? options.config.logo_url != void 0 : false,
342
- netlify_identity: useNetlifyIdentity(options),
343
- config_route: options.config.dir ? options.config.dir + (!options.config.dir.endsWith("/") ? "/" : "") + "config.yml" : void 0
523
+ cdn_route: resolveCdnRoute(loadOptions == void 0 || loadOptions.method === "cdn" ? (_a = loadOptions == null ? void 0 : loadOptions.options) != null ? _a : true : void 0),
524
+ custom_logo: "logoUrl" in config ? config.logoUrl != void 0 : "logo_url" in config ? config.logo_url != void 0 : false,
525
+ head: (options) => {
526
+ var _a2, _b, _c;
527
+ return resolveHead([
528
+ ["meta", { charset: "utf-8" }],
529
+ ["meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }],
530
+ ["meta", { name: "robots", content: "noindex" }],
531
+ ...(_a2 = options == null ? void 0 : options.head) != null ? _a2 : [],
532
+ ["title", {}, (_b = options == null ? void 0 : options.title) != null ? _b : "Content Manager"],
533
+ {
534
+ head: ["link", { rel: "favicon", ref: (_c = options == null ? void 0 : options.icon) != null ? _c : "" }],
535
+ skip: (options == null ? void 0 : options.icon) == void 0
536
+ },
537
+ {
538
+ head: ["script", { src: `https://identity.netlify.com/v${defaultNetlifyIdentityVersion}/netlify-identity-widget.js` }],
539
+ skip: config.backend.name !== "git-gateway"
540
+ },
541
+ {
542
+ head: ["link", { type: "text/yaml", rel: "cms-config-url", href: configRoute }],
543
+ skip: configRoute == void 0
544
+ }
545
+ ]);
546
+ }
344
547
  };
345
548
  }
346
- function createIndexFile(_options) {
549
+ function createIndexFile(pluginOptions) {
347
550
  var _a, _b;
348
- const features = getIndexFeatures(_options);
349
- const options = _options.login;
350
- const identifyScript = '<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>';
551
+ const { config, load, login: options, script } = pluginOptions;
552
+ if (options == null ? void 0 : options.html) return options.html;
553
+ const features = getIndexFeatures(config, load);
351
554
  return `<!DOCTYPE html>
352
555
  <html>
353
556
  <head>
354
- <meta charset="utf-8" />
355
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
356
- <meta name="robots" content="noindex" />
357
- <title>${(_a = options == null ? void 0 : options.title) != null ? _a : "Content Manager"}</title>${features.netlify_identity ? identifyScript : ""}
358
- ${features.config_route ? `<link href="${features.config_route}" type="text/yaml" rel="cms-config-url">` : ""}
359
- ${((_b = options == null ? void 0 : options.head) != null ? _b : []).join("\n" + " ".repeat(8))}
557
+ ${features.head(options).join("\n" + " ".repeat(8))}
360
558
  </head>
361
559
  <body>
362
560
  ${features.cdn_route ? `<script src="${features.cdn_route}"></script>` : ""}
363
- ${_options.script ? createScript(_options.script) : ""}
561
+ ${script ? createScript(script) : ""}
562
+ ${((_a = pluginOptions.login) == null ? void 0 : _a.additionalHtml) ? `${(_b = pluginOptions.login) == null ? void 0 : _b.additionalHtml}
563
+
564
+ <div id="nc-root"></div>` : ""}
364
565
  </body>
365
566
  </html>${features.custom_logo ? `
366
567
 
@@ -391,11 +592,25 @@ async function writeToFolder(folder, options) {
391
592
  function validateLoadOptions(options) {
392
593
  var _a;
393
594
  const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
394
- if (!valid)
395
- throw new Error("Invalid load options for decap-cms provided");
595
+ if (!valid) throw new Error("Invalid load options for decap-cms provided");
596
+ }
597
+ function runProxy(options) {
598
+ var _a, _b, _c, _d, _e;
599
+ const proxy = (0, import_child_process2.exec)("npx decap-server", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.process) != null ? _a : {}), {
600
+ env: __spreadProps(__spreadValues({}, (_c = (_b = options == null ? void 0 : options.process) == null ? void 0 : _b.env) != null ? _c : {}), {
601
+ PORT: ((_d = options == null ? void 0 : options.port) != null ? _d : 8081).toString()
602
+ })
603
+ }));
604
+ (_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
605
+ proxy.on("error", (err) => {
606
+ if ("code" in err && err.code === "EADDRINUSE") {
607
+ console.log("[PROXY] Port is already used");
608
+ } else throw err;
609
+ });
610
+ process.on("beforeExit", () => proxy.kill());
396
611
  }
397
612
  async function updateConfig(options, config) {
398
- var _a, _b, _c, _d, _e, _f;
613
+ var _a, _b, _c, _d, _e, _f, _g, _h;
399
614
  validateLoadOptions(options.load);
400
615
  const loginFile = createIndexFile(options);
401
616
  const configFile = createConfigFile(options.config, config.command);
@@ -410,16 +625,18 @@ async function updateConfig(options, config) {
410
625
  ]
411
626
  }
412
627
  );
413
- await ((_d = (_c = options.script) == null ? void 0 : _c.onConfigUpdated) == null ? void 0 : _d.call(_c));
628
+ if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
629
+ runProxy(options.proxy);
630
+ }
631
+ await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
414
632
  if (config.command === "build") {
415
- await ((_f = (_e = options.script) == null ? void 0 : _e.onGenerated) == null ? void 0 : _f.call(_e));
633
+ await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
416
634
  }
417
635
  }
418
636
  function VitePluginDecapCMS(options) {
419
637
  let stored = null;
420
638
  const debug = (...str) => {
421
- if (options.debug)
422
- console.debug(str);
639
+ if (options.debug) console.debug(str);
423
640
  };
424
641
  return {
425
642
  name: "vite-plugin-decap-cms",