vite-plugin-decap-cms 0.2.0 → 0.3.1
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 +70 -70
- package/dist/index.cjs +163 -49
- package/dist/index.d.cts +22 -5
- package/dist/index.d.ts +22 -5
- package/dist/index.js +163 -49
- package/package.json +56 -54
package/README.md
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
# vite-plugin-decap-cms
|
|
2
|
-
|
|
3
|
-
> A Vite plugin to connect Decap CMS
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
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
|
-
|
|
65
|
-
npm run
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## License
|
|
69
|
-
|
|
70
|
-
[MIT](LICENSE)
|
|
1
|
+
# vite-plugin-decap-cms
|
|
2
|
+
|
|
3
|
+
> A Vite plugin to connect Decap CMS
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
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
|
@@ -71,10 +71,10 @@ function getGitData() {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
return {
|
|
74
|
-
|
|
74
|
+
getBranch() {
|
|
75
75
|
return executeGit("git rev-parse --abbrev-ref HEAD");
|
|
76
76
|
},
|
|
77
|
-
|
|
77
|
+
getCommitSha() {
|
|
78
78
|
return executeGit("git rev-parse HEAD");
|
|
79
79
|
}
|
|
80
80
|
};
|
|
@@ -96,25 +96,32 @@ function createFileCollection(data) {
|
|
|
96
96
|
function createOverwriteableField(widget, data, overwrites) {
|
|
97
97
|
if (overwrites != void 0) {
|
|
98
98
|
const toAdd = (key) => {
|
|
99
|
-
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key])
|
|
100
|
-
data[key] = overwrites[key];
|
|
99
|
+
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
101
100
|
};
|
|
102
101
|
for (const key of Object.keys(overwrites)) {
|
|
103
|
-
if (key !== "hidden") {
|
|
102
|
+
if (key !== "hidden" && key !== "deleted") {
|
|
104
103
|
toAdd(key);
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
else
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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);
|
|
114
120
|
}
|
|
115
121
|
var VitePress = class {
|
|
116
122
|
/**
|
|
117
123
|
* Create fields for:
|
|
124
|
+
* - layout
|
|
118
125
|
* - navbar
|
|
119
126
|
* - sidebar
|
|
120
127
|
* - aside
|
|
@@ -131,49 +138,47 @@ var VitePress = class {
|
|
|
131
138
|
static createDefaultThemeNormalPageFields(options) {
|
|
132
139
|
const { overwrites } = options != null ? options : {};
|
|
133
140
|
return [
|
|
141
|
+
createOverwriteableField("string", {
|
|
142
|
+
name: "layout",
|
|
143
|
+
label: "Layout",
|
|
144
|
+
required: false
|
|
145
|
+
}),
|
|
134
146
|
createOverwriteableField("boolean", {
|
|
135
147
|
name: "navbar",
|
|
136
148
|
label: "Whether to display the navbar",
|
|
137
|
-
default: true,
|
|
138
149
|
required: false
|
|
139
150
|
}, overwrites == null ? void 0 : overwrites.navbar),
|
|
140
151
|
createOverwriteableField("boolean", {
|
|
141
152
|
name: "sidebar",
|
|
142
153
|
label: "Whether to display the sidebar",
|
|
143
|
-
default: true,
|
|
144
154
|
required: false
|
|
145
155
|
}, overwrites == null ? void 0 : overwrites.sidebar),
|
|
146
156
|
// TODO: add aside 'left' option
|
|
147
157
|
createOverwriteableField("boolean", {
|
|
148
158
|
name: "aside",
|
|
149
159
|
label: "Whether to display the aside container",
|
|
150
|
-
default: true,
|
|
151
160
|
required: false
|
|
152
161
|
}, overwrites == null ? void 0 : overwrites.aside),
|
|
153
162
|
// TODO: add support for [number, number] | 'deep' | false
|
|
154
163
|
createOverwriteableField("number", {
|
|
155
164
|
name: "outline",
|
|
156
165
|
label: "The header levels in the outline",
|
|
157
|
-
default: 2,
|
|
158
166
|
required: false
|
|
159
167
|
}, overwrites == null ? void 0 : overwrites.outline),
|
|
160
168
|
// TODO: add support for Date
|
|
161
169
|
createOverwriteableField("boolean", {
|
|
162
170
|
name: "lastUpdated",
|
|
163
171
|
label: "Whether to display last updated text",
|
|
164
|
-
default: true,
|
|
165
172
|
required: false
|
|
166
173
|
}, overwrites == null ? void 0 : overwrites.lastUpdated),
|
|
167
174
|
createOverwriteableField("boolean", {
|
|
168
175
|
name: "editLink",
|
|
169
176
|
label: "Whether to display edit link text",
|
|
170
|
-
default: true,
|
|
171
177
|
required: false
|
|
172
178
|
}, overwrites == null ? void 0 : overwrites.editLink),
|
|
173
179
|
createOverwriteableField("boolean", {
|
|
174
180
|
name: "footer",
|
|
175
181
|
label: "Whether to display footer text",
|
|
176
|
-
default: true,
|
|
177
182
|
required: false
|
|
178
183
|
}, overwrites == null ? void 0 : overwrites.footer),
|
|
179
184
|
createOverwriteableField("string", {
|
|
@@ -181,7 +186,7 @@ var VitePress = class {
|
|
|
181
186
|
label: "Page class",
|
|
182
187
|
required: false
|
|
183
188
|
}, overwrites == null ? void 0 : overwrites.pageClass)
|
|
184
|
-
];
|
|
189
|
+
].filter(filterUndefined);
|
|
185
190
|
}
|
|
186
191
|
/**
|
|
187
192
|
* Create fields for:
|
|
@@ -193,7 +198,7 @@ var VitePress = class {
|
|
|
193
198
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
194
199
|
*/
|
|
195
200
|
static createDefaultPageFields(options) {
|
|
196
|
-
var _a;
|
|
201
|
+
var _a, _b;
|
|
197
202
|
const { additionalFields, overwrites } = options != null ? options : {};
|
|
198
203
|
const fields = [
|
|
199
204
|
createOverwriteableField("string", {
|
|
@@ -214,11 +219,131 @@ var VitePress = class {
|
|
|
214
219
|
name: "head",
|
|
215
220
|
label: "Head"
|
|
216
221
|
}, overwrites == null ? void 0 : overwrites.head)
|
|
217
|
-
];
|
|
218
|
-
return fields.concat(additionalFields != null ? additionalFields : []).concat(createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
|
|
222
|
+
].filter(filterUndefined);
|
|
223
|
+
return fields.concat(additionalFields != null ? additionalFields : []).concat((_b = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
|
|
219
224
|
name: "body",
|
|
220
225
|
label: "Page content"
|
|
221
|
-
}), overwrites == null ? void 0 : overwrites.body));
|
|
226
|
+
}), overwrites == null ? void 0 : overwrites.body)) != null ? _b : []).filter(filterUndefined);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Create fields for:
|
|
230
|
+
* - layout: home (not overwriteable)
|
|
231
|
+
* - hero
|
|
232
|
+
* - features
|
|
233
|
+
*
|
|
234
|
+
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
235
|
+
*/
|
|
236
|
+
static createHomePageFields(options) {
|
|
237
|
+
var _a;
|
|
238
|
+
const { overwrites } = options != null ? options : {};
|
|
239
|
+
const keys = ["hidden", "deleted"];
|
|
240
|
+
function addAdditionalFields(fields) {
|
|
241
|
+
var _a2;
|
|
242
|
+
return (_a2 = fields == null ? void 0 : fields.map((f) => objToSnakeCase(f))) != null ? _a2 : [];
|
|
243
|
+
}
|
|
244
|
+
return [
|
|
245
|
+
createField("hidden", {
|
|
246
|
+
name: "layout",
|
|
247
|
+
default: "home"
|
|
248
|
+
}),
|
|
249
|
+
createOverwriteableField("object", {
|
|
250
|
+
name: "hero",
|
|
251
|
+
label: "Hero items",
|
|
252
|
+
required: true,
|
|
253
|
+
fields: [
|
|
254
|
+
createOverwriteableField("string", {
|
|
255
|
+
name: "name",
|
|
256
|
+
required: false
|
|
257
|
+
}, overwrites == null ? void 0 : overwrites.heroName),
|
|
258
|
+
createOverwriteableField("string", {
|
|
259
|
+
name: "text"
|
|
260
|
+
}, overwrites == null ? void 0 : overwrites.heroText),
|
|
261
|
+
createOverwriteableField("string", {
|
|
262
|
+
name: "tagline",
|
|
263
|
+
required: false
|
|
264
|
+
}, overwrites == null ? void 0 : overwrites.heroTagline),
|
|
265
|
+
// TODO: add support for object options
|
|
266
|
+
createOverwriteableField("image", {
|
|
267
|
+
name: "image",
|
|
268
|
+
required: false
|
|
269
|
+
}, overwrites == null ? void 0 : overwrites.heroImage),
|
|
270
|
+
createOverwriteableField("list", {
|
|
271
|
+
name: "actions",
|
|
272
|
+
label: "Action buttons",
|
|
273
|
+
label_singular: "action",
|
|
274
|
+
allow_add: true,
|
|
275
|
+
fields: [
|
|
276
|
+
createOverwriteableField("string", {
|
|
277
|
+
name: "text"
|
|
278
|
+
}, overwrites == null ? void 0 : overwrites.heroActionText),
|
|
279
|
+
createOverwriteableField("string", {
|
|
280
|
+
name: "link"
|
|
281
|
+
}, overwrites == null ? void 0 : overwrites.heroActionLink),
|
|
282
|
+
createOverwriteableField("select", {
|
|
283
|
+
name: "theme",
|
|
284
|
+
required: false,
|
|
285
|
+
default: "brand",
|
|
286
|
+
options: [
|
|
287
|
+
"brand",
|
|
288
|
+
"alt"
|
|
289
|
+
]
|
|
290
|
+
}, overwrites == null ? void 0 : overwrites.heroActionTheme),
|
|
291
|
+
createOverwriteableField("string", {
|
|
292
|
+
name: "target",
|
|
293
|
+
required: false
|
|
294
|
+
}, overwrites == null ? void 0 : overwrites.heroActionTarget),
|
|
295
|
+
createOverwriteableField("string", {
|
|
296
|
+
name: "rel",
|
|
297
|
+
required: false
|
|
298
|
+
}, overwrites == null ? void 0 : overwrites.heroActionRel),
|
|
299
|
+
...addAdditionalFields(options == null ? void 0 : options.additionalHeroActionFields)
|
|
300
|
+
].filter(filterUndefined)
|
|
301
|
+
}, omit(overwrites == null ? void 0 : overwrites.heroActions, keys)),
|
|
302
|
+
...addAdditionalFields(options == null ? void 0 : options.additionalHeroFields)
|
|
303
|
+
].filter(filterUndefined)
|
|
304
|
+
}, omit(overwrites == null ? void 0 : overwrites.hero, keys)),
|
|
305
|
+
createOverwriteableField("list", {
|
|
306
|
+
name: "features",
|
|
307
|
+
label: "Features",
|
|
308
|
+
label_singular: "feature",
|
|
309
|
+
allow_add: true,
|
|
310
|
+
required: false,
|
|
311
|
+
fields: [
|
|
312
|
+
createOverwriteableField("string", {
|
|
313
|
+
name: "title",
|
|
314
|
+
required: true
|
|
315
|
+
}, overwrites == null ? void 0 : overwrites.featuresTitle),
|
|
316
|
+
createOverwriteableField("string", {
|
|
317
|
+
name: "details",
|
|
318
|
+
required: false
|
|
319
|
+
}, overwrites == null ? void 0 : overwrites.featuresDetails),
|
|
320
|
+
// TODO: add support for object options
|
|
321
|
+
createOverwriteableField("string", {
|
|
322
|
+
name: "icon",
|
|
323
|
+
required: false
|
|
324
|
+
}, overwrites == null ? void 0 : overwrites.featuresIcon),
|
|
325
|
+
createOverwriteableField("string", {
|
|
326
|
+
name: "link",
|
|
327
|
+
required: false
|
|
328
|
+
}, overwrites == null ? void 0 : overwrites.featuresLink),
|
|
329
|
+
createOverwriteableField("string", {
|
|
330
|
+
name: "linkText",
|
|
331
|
+
label: "Link text",
|
|
332
|
+
required: false
|
|
333
|
+
}, overwrites == null ? void 0 : overwrites.featuresLinkText),
|
|
334
|
+
createOverwriteableField("string", {
|
|
335
|
+
name: "target",
|
|
336
|
+
label: "Target",
|
|
337
|
+
required: false
|
|
338
|
+
}, overwrites == null ? void 0 : overwrites.featuresTarget),
|
|
339
|
+
createOverwriteableField("string", {
|
|
340
|
+
name: "rel",
|
|
341
|
+
required: false
|
|
342
|
+
}, overwrites == null ? void 0 : overwrites.featuresRel),
|
|
343
|
+
...addAdditionalFields((_a = options == null ? void 0 : options.additionalFeatureFields) != null ? _a : [])
|
|
344
|
+
].filter(filterUndefined)
|
|
345
|
+
}, omit(overwrites == null ? void 0 : overwrites.features, keys))
|
|
346
|
+
];
|
|
222
347
|
}
|
|
223
348
|
static createDefaultPageFolderCollection(name, folder, options) {
|
|
224
349
|
const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
|
|
@@ -266,7 +391,8 @@ function getBooleanFromEnv(value, command) {
|
|
|
266
391
|
}
|
|
267
392
|
function resolveBackend(options, command) {
|
|
268
393
|
const _a = options, { local, name } = _a, backend = __objRest(_a, ["local", "name"]);
|
|
269
|
-
const
|
|
394
|
+
const git = getGitData();
|
|
395
|
+
const branch = "useCurrentBranch" in options && getBooleanFromEnv(options.useCurrentBranch, command) ? git.getBranch() : "branch" in backend ? backend.branch : void 0;
|
|
270
396
|
delete backend.useCurrentBranch;
|
|
271
397
|
const resolved = {
|
|
272
398
|
local_backend: typeof local === "object" ? objToSnakeCase(local) : getBooleanFromEnv(local, command),
|
|
@@ -296,8 +422,7 @@ function createConfigFile(config, command) {
|
|
|
296
422
|
});
|
|
297
423
|
})
|
|
298
424
|
});
|
|
299
|
-
} else
|
|
300
|
-
throw new Error("Missing either fields or files property in collection");
|
|
425
|
+
} else throw new Error("Missing either fields or files property in collection");
|
|
301
426
|
})
|
|
302
427
|
});
|
|
303
428
|
}
|
|
@@ -311,10 +436,8 @@ function createCmsFunction(method, items, createParams, options) {
|
|
|
311
436
|
};
|
|
312
437
|
return (items != null ? items : []).map((item) => {
|
|
313
438
|
const params = createParams(item);
|
|
314
|
-
if (!params)
|
|
315
|
-
|
|
316
|
-
else
|
|
317
|
-
return create(params);
|
|
439
|
+
if (!params) return null;
|
|
440
|
+
else return create(params);
|
|
318
441
|
}).filter(Boolean).join((_a = options == null ? void 0 : options.joinChar) != null ? _a : "\n");
|
|
319
442
|
}
|
|
320
443
|
function createScript(options) {
|
|
@@ -338,8 +461,7 @@ function createScript(options) {
|
|
|
338
461
|
]);
|
|
339
462
|
const events = createCmsFunction("registerEventListener", Object.keys(eventHooks), (hookName) => {
|
|
340
463
|
const hook = eventHooks[hookName];
|
|
341
|
-
if (!hook)
|
|
342
|
-
return null;
|
|
464
|
+
if (!hook) return null;
|
|
343
465
|
else {
|
|
344
466
|
const name = hookName.slice(2)[0].toLowerCase() + hookName.slice(3);
|
|
345
467
|
return `{ name: '${name}', handler: data => { function ${hook.toString()}; ${hookName}({ app: CMS, ...data }) } }`;
|
|
@@ -367,7 +489,7 @@ ${editorComponents}
|
|
|
367
489
|
}
|
|
368
490
|
|
|
369
491
|
// src/files/index.ts
|
|
370
|
-
var defaultDecapCmsCdnVersion = "3.1.
|
|
492
|
+
var defaultDecapCmsCdnVersion = "3.1.11";
|
|
371
493
|
var defaultNetlifyIdentityVersion = "1";
|
|
372
494
|
var addSlash = (path, slash = "/") => path.endsWith(slash) ? path : path + slash;
|
|
373
495
|
function resolveCdnRoute(options) {
|
|
@@ -378,13 +500,10 @@ function resolveCdnRoute(options) {
|
|
|
378
500
|
}
|
|
379
501
|
function resolveHead(head) {
|
|
380
502
|
return head.reduce((output, config) => {
|
|
381
|
-
if (typeof config === "string")
|
|
382
|
-
return output.concat(config);
|
|
503
|
+
if (typeof config === "string") return output.concat(config);
|
|
383
504
|
if ("skip" in config) {
|
|
384
|
-
if (config.skip)
|
|
385
|
-
|
|
386
|
-
if (typeof config.head === "string")
|
|
387
|
-
return output.concat(config.head);
|
|
505
|
+
if (config.skip) return output;
|
|
506
|
+
if (typeof config.head === "string") return output.concat(config.head);
|
|
388
507
|
}
|
|
389
508
|
const item = "head" in config ? config.head : config;
|
|
390
509
|
let str = `<${item[0]}`;
|
|
@@ -392,8 +511,7 @@ function resolveHead(head) {
|
|
|
392
511
|
str += ` ${key}="${item[1][key]}"`;
|
|
393
512
|
}
|
|
394
513
|
str += item[0] === "meta" ? "/>" : ">";
|
|
395
|
-
if (item[2] == void 0)
|
|
396
|
-
return output.concat(str);
|
|
514
|
+
if (item[2] == void 0) return output.concat(str);
|
|
397
515
|
str += item[2] + `</${item[0]}>`;
|
|
398
516
|
return output.concat(str);
|
|
399
517
|
}, []);
|
|
@@ -431,8 +549,7 @@ function getIndexFeatures(config, loadOptions) {
|
|
|
431
549
|
function createIndexFile(pluginOptions) {
|
|
432
550
|
var _a, _b;
|
|
433
551
|
const { config, load, login: options, script } = pluginOptions;
|
|
434
|
-
if (options == null ? void 0 : options.html)
|
|
435
|
-
return options.html;
|
|
552
|
+
if (options == null ? void 0 : options.html) return options.html;
|
|
436
553
|
const features = getIndexFeatures(config, load);
|
|
437
554
|
return `<!DOCTYPE html>
|
|
438
555
|
<html>
|
|
@@ -475,8 +592,7 @@ async function writeToFolder(folder, options) {
|
|
|
475
592
|
function validateLoadOptions(options) {
|
|
476
593
|
var _a;
|
|
477
594
|
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
478
|
-
if (!valid)
|
|
479
|
-
throw new Error("Invalid load options for decap-cms provided");
|
|
595
|
+
if (!valid) throw new Error("Invalid load options for decap-cms provided");
|
|
480
596
|
}
|
|
481
597
|
function runProxy(options) {
|
|
482
598
|
var _a, _b, _c, _d, _e;
|
|
@@ -489,8 +605,7 @@ function runProxy(options) {
|
|
|
489
605
|
proxy.on("error", (err) => {
|
|
490
606
|
if ("code" in err && err.code === "EADDRINUSE") {
|
|
491
607
|
console.log("[PROXY] Port is already used");
|
|
492
|
-
} else
|
|
493
|
-
throw err;
|
|
608
|
+
} else throw err;
|
|
494
609
|
});
|
|
495
610
|
process.on("beforeExit", () => proxy.kill());
|
|
496
611
|
}
|
|
@@ -521,8 +636,7 @@ async function updateConfig(options, config) {
|
|
|
521
636
|
function VitePluginDecapCMS(options) {
|
|
522
637
|
let stored = null;
|
|
523
638
|
const debug = (...str) => {
|
|
524
|
-
if (options.debug)
|
|
525
|
-
console.debug(str);
|
|
639
|
+
if (options.debug) console.debug(str);
|
|
526
640
|
};
|
|
527
641
|
return {
|
|
528
642
|
name: "vite-plugin-decap-cms",
|
package/dist/index.d.cts
CHANGED
|
@@ -192,7 +192,7 @@ interface Options {
|
|
|
192
192
|
/**
|
|
193
193
|
* How to load Decap CMS
|
|
194
194
|
* @default
|
|
195
|
-
* { method: 'cdn'}
|
|
195
|
+
* { method: 'cdn', options: { version: '^3.1.11' }}
|
|
196
196
|
*/
|
|
197
197
|
load?: {
|
|
198
198
|
method: 'cdn';
|
|
@@ -232,8 +232,8 @@ interface Options {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
declare function getGitData(): {
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
getBranch(): string | undefined;
|
|
236
|
+
getCommitSha(): string | undefined;
|
|
237
237
|
};
|
|
238
238
|
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
239
239
|
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
@@ -249,6 +249,11 @@ type OverwriteOptions = Omit<CmsFieldBase, 'name'> & {
|
|
|
249
249
|
* @default false
|
|
250
250
|
*/
|
|
251
251
|
hidden?: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Hide this field in the CMS editor UI and do not include it in the frontmatter.
|
|
254
|
+
* @default false
|
|
255
|
+
*/
|
|
256
|
+
deleted?: boolean;
|
|
252
257
|
};
|
|
253
258
|
type VitePressPageFrontmatterKeys = 'title' | 'titleTemplate' | 'description' | 'head' | 'body';
|
|
254
259
|
interface BaseVitePressFieldOptions<Keys extends string> {
|
|
@@ -261,11 +266,14 @@ interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageF
|
|
|
261
266
|
*/
|
|
262
267
|
markdownOptions?: DecapCmsMarkdownFieldRenderOptions;
|
|
263
268
|
}
|
|
264
|
-
type VitePressDefaultThemeFrontmatterKeys = 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
269
|
+
type VitePressDefaultThemeFrontmatterKeys = 'layout' | 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
265
270
|
type VitePressDefaultThemeFieldOptions = BaseVitePressFieldOptions<VitePressDefaultThemeFrontmatterKeys>;
|
|
271
|
+
type VitePressHomePageFrontmatterKeys = 'hero' | 'heroName' | 'heroText' | 'heroTagline' | 'heroImage' | 'heroActions' | 'heroActionTheme' | 'heroActionText' | 'heroActionLink' | 'heroActionTarget' | 'heroActionRel' | 'features' | 'featuresTitle' | 'featuresDetails' | 'featuresIcon' | 'featuresLink' | 'featuresLinkText' | 'featuresRel' | 'featuresTarget';
|
|
272
|
+
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields', DecapCmsField[]>>;
|
|
266
273
|
declare class VitePress {
|
|
267
274
|
/**
|
|
268
275
|
* Create fields for:
|
|
276
|
+
* - layout
|
|
269
277
|
* - navbar
|
|
270
278
|
* - sidebar
|
|
271
279
|
* - aside
|
|
@@ -290,6 +298,15 @@ declare class VitePress {
|
|
|
290
298
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
291
299
|
*/
|
|
292
300
|
static createDefaultPageFields(options?: VitePressFieldOptions): DecapCmsField[];
|
|
301
|
+
/**
|
|
302
|
+
* Create fields for:
|
|
303
|
+
* - layout: home (not overwriteable)
|
|
304
|
+
* - hero
|
|
305
|
+
* - features
|
|
306
|
+
*
|
|
307
|
+
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
308
|
+
*/
|
|
309
|
+
static createHomePageFields(options?: VitePressHomePageFieldOptions): ((CmsFieldBase & decap_cms_core.CmsFieldList) | (CmsFieldBase & decap_cms_core.CmsFieldHidden) | undefined)[];
|
|
293
310
|
static createDefaultPageFolderCollection(name: string, folder: string, options?: VitePressFieldOptions & {
|
|
294
311
|
collection?: Partial<Omit<DecapCmsCollection<'folder'>, 'name' | 'fields' | 'folder'>>;
|
|
295
312
|
}): DecapCmsCollection<'folder'>;
|
|
@@ -305,4 +322,4 @@ declare class VitePress {
|
|
|
305
322
|
|
|
306
323
|
declare function VitePluginDecapCMS(options: Options): Plugin;
|
|
307
324
|
|
|
308
|
-
export { type CdnLinkOptions, type CollectionType, type DecapCmsCollection, type DecapCmsCollectionFile, type DecapCmsConfig, type DecapCmsField, type DecapCmsFieldType, type DecapCmsFieldWidget, type DecapCmsMarkdownFieldRenderOptions, type DecapProxyOptions, type EnvContextOption, type EnvDevContextOption, type HeadConfig, type KeysToCamelCase, type KeysToSnakeCase, type LoginPageOptions, type Options, type OverwriteOptions, VitePress, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, VitePluginDecapCMS as default, getGitData };
|
|
325
|
+
export { type CdnLinkOptions, type CollectionType, type DecapCmsCollection, type DecapCmsCollectionFile, type DecapCmsConfig, type DecapCmsField, type DecapCmsFieldType, type DecapCmsFieldWidget, type DecapCmsMarkdownFieldRenderOptions, type DecapProxyOptions, type EnvContextOption, type EnvDevContextOption, type HeadConfig, type KeysToCamelCase, type KeysToSnakeCase, type LoginPageOptions, type Options, type OverwriteOptions, VitePress, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressHomePageFieldOptions, type VitePressHomePageFrontmatterKeys, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, VitePluginDecapCMS as default, getGitData };
|
package/dist/index.d.ts
CHANGED
|
@@ -192,7 +192,7 @@ interface Options {
|
|
|
192
192
|
/**
|
|
193
193
|
* How to load Decap CMS
|
|
194
194
|
* @default
|
|
195
|
-
* { method: 'cdn'}
|
|
195
|
+
* { method: 'cdn', options: { version: '^3.1.11' }}
|
|
196
196
|
*/
|
|
197
197
|
load?: {
|
|
198
198
|
method: 'cdn';
|
|
@@ -232,8 +232,8 @@ interface Options {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
declare function getGitData(): {
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
getBranch(): string | undefined;
|
|
236
|
+
getCommitSha(): string | undefined;
|
|
237
237
|
};
|
|
238
238
|
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
239
239
|
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
@@ -249,6 +249,11 @@ type OverwriteOptions = Omit<CmsFieldBase, 'name'> & {
|
|
|
249
249
|
* @default false
|
|
250
250
|
*/
|
|
251
251
|
hidden?: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Hide this field in the CMS editor UI and do not include it in the frontmatter.
|
|
254
|
+
* @default false
|
|
255
|
+
*/
|
|
256
|
+
deleted?: boolean;
|
|
252
257
|
};
|
|
253
258
|
type VitePressPageFrontmatterKeys = 'title' | 'titleTemplate' | 'description' | 'head' | 'body';
|
|
254
259
|
interface BaseVitePressFieldOptions<Keys extends string> {
|
|
@@ -261,11 +266,14 @@ interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageF
|
|
|
261
266
|
*/
|
|
262
267
|
markdownOptions?: DecapCmsMarkdownFieldRenderOptions;
|
|
263
268
|
}
|
|
264
|
-
type VitePressDefaultThemeFrontmatterKeys = 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
269
|
+
type VitePressDefaultThemeFrontmatterKeys = 'layout' | 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
265
270
|
type VitePressDefaultThemeFieldOptions = BaseVitePressFieldOptions<VitePressDefaultThemeFrontmatterKeys>;
|
|
271
|
+
type VitePressHomePageFrontmatterKeys = 'hero' | 'heroName' | 'heroText' | 'heroTagline' | 'heroImage' | 'heroActions' | 'heroActionTheme' | 'heroActionText' | 'heroActionLink' | 'heroActionTarget' | 'heroActionRel' | 'features' | 'featuresTitle' | 'featuresDetails' | 'featuresIcon' | 'featuresLink' | 'featuresLinkText' | 'featuresRel' | 'featuresTarget';
|
|
272
|
+
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields', DecapCmsField[]>>;
|
|
266
273
|
declare class VitePress {
|
|
267
274
|
/**
|
|
268
275
|
* Create fields for:
|
|
276
|
+
* - layout
|
|
269
277
|
* - navbar
|
|
270
278
|
* - sidebar
|
|
271
279
|
* - aside
|
|
@@ -290,6 +298,15 @@ declare class VitePress {
|
|
|
290
298
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
291
299
|
*/
|
|
292
300
|
static createDefaultPageFields(options?: VitePressFieldOptions): DecapCmsField[];
|
|
301
|
+
/**
|
|
302
|
+
* Create fields for:
|
|
303
|
+
* - layout: home (not overwriteable)
|
|
304
|
+
* - hero
|
|
305
|
+
* - features
|
|
306
|
+
*
|
|
307
|
+
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
308
|
+
*/
|
|
309
|
+
static createHomePageFields(options?: VitePressHomePageFieldOptions): ((CmsFieldBase & decap_cms_core.CmsFieldList) | (CmsFieldBase & decap_cms_core.CmsFieldHidden) | undefined)[];
|
|
293
310
|
static createDefaultPageFolderCollection(name: string, folder: string, options?: VitePressFieldOptions & {
|
|
294
311
|
collection?: Partial<Omit<DecapCmsCollection<'folder'>, 'name' | 'fields' | 'folder'>>;
|
|
295
312
|
}): DecapCmsCollection<'folder'>;
|
|
@@ -305,4 +322,4 @@ declare class VitePress {
|
|
|
305
322
|
|
|
306
323
|
declare function VitePluginDecapCMS(options: Options): Plugin;
|
|
307
324
|
|
|
308
|
-
export { type CdnLinkOptions, type CollectionType, type DecapCmsCollection, type DecapCmsCollectionFile, type DecapCmsConfig, type DecapCmsField, type DecapCmsFieldType, type DecapCmsFieldWidget, type DecapCmsMarkdownFieldRenderOptions, type DecapProxyOptions, type EnvContextOption, type EnvDevContextOption, type HeadConfig, type KeysToCamelCase, type KeysToSnakeCase, type LoginPageOptions, type Options, type OverwriteOptions, VitePress, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, VitePluginDecapCMS as default, getGitData };
|
|
325
|
+
export { type CdnLinkOptions, type CollectionType, type DecapCmsCollection, type DecapCmsCollectionFile, type DecapCmsConfig, type DecapCmsField, type DecapCmsFieldType, type DecapCmsFieldWidget, type DecapCmsMarkdownFieldRenderOptions, type DecapProxyOptions, type EnvContextOption, type EnvDevContextOption, type HeadConfig, type KeysToCamelCase, type KeysToSnakeCase, type LoginPageOptions, type Options, type OverwriteOptions, VitePress, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressHomePageFieldOptions, type VitePressHomePageFrontmatterKeys, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, VitePluginDecapCMS as default, getGitData };
|
package/dist/index.js
CHANGED
|
@@ -44,10 +44,10 @@ function getGitData() {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
return {
|
|
47
|
-
|
|
47
|
+
getBranch() {
|
|
48
48
|
return executeGit("git rev-parse --abbrev-ref HEAD");
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
getCommitSha() {
|
|
51
51
|
return executeGit("git rev-parse HEAD");
|
|
52
52
|
}
|
|
53
53
|
};
|
|
@@ -69,25 +69,32 @@ function createFileCollection(data) {
|
|
|
69
69
|
function createOverwriteableField(widget, data, overwrites) {
|
|
70
70
|
if (overwrites != void 0) {
|
|
71
71
|
const toAdd = (key) => {
|
|
72
|
-
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key])
|
|
73
|
-
data[key] = overwrites[key];
|
|
72
|
+
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
74
73
|
};
|
|
75
74
|
for (const key of Object.keys(overwrites)) {
|
|
76
|
-
if (key !== "hidden") {
|
|
75
|
+
if (key !== "hidden" && key !== "deleted") {
|
|
77
76
|
toAdd(key);
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
else
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
|
|
81
|
+
else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
|
|
82
|
+
else return __spreadProps(__spreadValues({}, data), {
|
|
83
|
+
widget
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function filterUndefined(item) {
|
|
87
|
+
return item != void 0;
|
|
88
|
+
}
|
|
89
|
+
function omit(obj, keys) {
|
|
90
|
+
if (!obj) return void 0;
|
|
91
|
+
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
92
|
+
return Object.fromEntries(validEntries);
|
|
87
93
|
}
|
|
88
94
|
var VitePress = class {
|
|
89
95
|
/**
|
|
90
96
|
* Create fields for:
|
|
97
|
+
* - layout
|
|
91
98
|
* - navbar
|
|
92
99
|
* - sidebar
|
|
93
100
|
* - aside
|
|
@@ -104,49 +111,47 @@ var VitePress = class {
|
|
|
104
111
|
static createDefaultThemeNormalPageFields(options) {
|
|
105
112
|
const { overwrites } = options != null ? options : {};
|
|
106
113
|
return [
|
|
114
|
+
createOverwriteableField("string", {
|
|
115
|
+
name: "layout",
|
|
116
|
+
label: "Layout",
|
|
117
|
+
required: false
|
|
118
|
+
}),
|
|
107
119
|
createOverwriteableField("boolean", {
|
|
108
120
|
name: "navbar",
|
|
109
121
|
label: "Whether to display the navbar",
|
|
110
|
-
default: true,
|
|
111
122
|
required: false
|
|
112
123
|
}, overwrites == null ? void 0 : overwrites.navbar),
|
|
113
124
|
createOverwriteableField("boolean", {
|
|
114
125
|
name: "sidebar",
|
|
115
126
|
label: "Whether to display the sidebar",
|
|
116
|
-
default: true,
|
|
117
127
|
required: false
|
|
118
128
|
}, overwrites == null ? void 0 : overwrites.sidebar),
|
|
119
129
|
// TODO: add aside 'left' option
|
|
120
130
|
createOverwriteableField("boolean", {
|
|
121
131
|
name: "aside",
|
|
122
132
|
label: "Whether to display the aside container",
|
|
123
|
-
default: true,
|
|
124
133
|
required: false
|
|
125
134
|
}, overwrites == null ? void 0 : overwrites.aside),
|
|
126
135
|
// TODO: add support for [number, number] | 'deep' | false
|
|
127
136
|
createOverwriteableField("number", {
|
|
128
137
|
name: "outline",
|
|
129
138
|
label: "The header levels in the outline",
|
|
130
|
-
default: 2,
|
|
131
139
|
required: false
|
|
132
140
|
}, overwrites == null ? void 0 : overwrites.outline),
|
|
133
141
|
// TODO: add support for Date
|
|
134
142
|
createOverwriteableField("boolean", {
|
|
135
143
|
name: "lastUpdated",
|
|
136
144
|
label: "Whether to display last updated text",
|
|
137
|
-
default: true,
|
|
138
145
|
required: false
|
|
139
146
|
}, overwrites == null ? void 0 : overwrites.lastUpdated),
|
|
140
147
|
createOverwriteableField("boolean", {
|
|
141
148
|
name: "editLink",
|
|
142
149
|
label: "Whether to display edit link text",
|
|
143
|
-
default: true,
|
|
144
150
|
required: false
|
|
145
151
|
}, overwrites == null ? void 0 : overwrites.editLink),
|
|
146
152
|
createOverwriteableField("boolean", {
|
|
147
153
|
name: "footer",
|
|
148
154
|
label: "Whether to display footer text",
|
|
149
|
-
default: true,
|
|
150
155
|
required: false
|
|
151
156
|
}, overwrites == null ? void 0 : overwrites.footer),
|
|
152
157
|
createOverwriteableField("string", {
|
|
@@ -154,7 +159,7 @@ var VitePress = class {
|
|
|
154
159
|
label: "Page class",
|
|
155
160
|
required: false
|
|
156
161
|
}, overwrites == null ? void 0 : overwrites.pageClass)
|
|
157
|
-
];
|
|
162
|
+
].filter(filterUndefined);
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
160
165
|
* Create fields for:
|
|
@@ -166,7 +171,7 @@ var VitePress = class {
|
|
|
166
171
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
167
172
|
*/
|
|
168
173
|
static createDefaultPageFields(options) {
|
|
169
|
-
var _a;
|
|
174
|
+
var _a, _b;
|
|
170
175
|
const { additionalFields, overwrites } = options != null ? options : {};
|
|
171
176
|
const fields = [
|
|
172
177
|
createOverwriteableField("string", {
|
|
@@ -187,11 +192,131 @@ var VitePress = class {
|
|
|
187
192
|
name: "head",
|
|
188
193
|
label: "Head"
|
|
189
194
|
}, overwrites == null ? void 0 : overwrites.head)
|
|
190
|
-
];
|
|
191
|
-
return fields.concat(additionalFields != null ? additionalFields : []).concat(createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
|
|
195
|
+
].filter(filterUndefined);
|
|
196
|
+
return fields.concat(additionalFields != null ? additionalFields : []).concat((_b = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
|
|
192
197
|
name: "body",
|
|
193
198
|
label: "Page content"
|
|
194
|
-
}), overwrites == null ? void 0 : overwrites.body));
|
|
199
|
+
}), overwrites == null ? void 0 : overwrites.body)) != null ? _b : []).filter(filterUndefined);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Create fields for:
|
|
203
|
+
* - layout: home (not overwriteable)
|
|
204
|
+
* - hero
|
|
205
|
+
* - features
|
|
206
|
+
*
|
|
207
|
+
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
208
|
+
*/
|
|
209
|
+
static createHomePageFields(options) {
|
|
210
|
+
var _a;
|
|
211
|
+
const { overwrites } = options != null ? options : {};
|
|
212
|
+
const keys = ["hidden", "deleted"];
|
|
213
|
+
function addAdditionalFields(fields) {
|
|
214
|
+
var _a2;
|
|
215
|
+
return (_a2 = fields == null ? void 0 : fields.map((f) => objToSnakeCase(f))) != null ? _a2 : [];
|
|
216
|
+
}
|
|
217
|
+
return [
|
|
218
|
+
createField("hidden", {
|
|
219
|
+
name: "layout",
|
|
220
|
+
default: "home"
|
|
221
|
+
}),
|
|
222
|
+
createOverwriteableField("object", {
|
|
223
|
+
name: "hero",
|
|
224
|
+
label: "Hero items",
|
|
225
|
+
required: true,
|
|
226
|
+
fields: [
|
|
227
|
+
createOverwriteableField("string", {
|
|
228
|
+
name: "name",
|
|
229
|
+
required: false
|
|
230
|
+
}, overwrites == null ? void 0 : overwrites.heroName),
|
|
231
|
+
createOverwriteableField("string", {
|
|
232
|
+
name: "text"
|
|
233
|
+
}, overwrites == null ? void 0 : overwrites.heroText),
|
|
234
|
+
createOverwriteableField("string", {
|
|
235
|
+
name: "tagline",
|
|
236
|
+
required: false
|
|
237
|
+
}, overwrites == null ? void 0 : overwrites.heroTagline),
|
|
238
|
+
// TODO: add support for object options
|
|
239
|
+
createOverwriteableField("image", {
|
|
240
|
+
name: "image",
|
|
241
|
+
required: false
|
|
242
|
+
}, overwrites == null ? void 0 : overwrites.heroImage),
|
|
243
|
+
createOverwriteableField("list", {
|
|
244
|
+
name: "actions",
|
|
245
|
+
label: "Action buttons",
|
|
246
|
+
label_singular: "action",
|
|
247
|
+
allow_add: true,
|
|
248
|
+
fields: [
|
|
249
|
+
createOverwriteableField("string", {
|
|
250
|
+
name: "text"
|
|
251
|
+
}, overwrites == null ? void 0 : overwrites.heroActionText),
|
|
252
|
+
createOverwriteableField("string", {
|
|
253
|
+
name: "link"
|
|
254
|
+
}, overwrites == null ? void 0 : overwrites.heroActionLink),
|
|
255
|
+
createOverwriteableField("select", {
|
|
256
|
+
name: "theme",
|
|
257
|
+
required: false,
|
|
258
|
+
default: "brand",
|
|
259
|
+
options: [
|
|
260
|
+
"brand",
|
|
261
|
+
"alt"
|
|
262
|
+
]
|
|
263
|
+
}, overwrites == null ? void 0 : overwrites.heroActionTheme),
|
|
264
|
+
createOverwriteableField("string", {
|
|
265
|
+
name: "target",
|
|
266
|
+
required: false
|
|
267
|
+
}, overwrites == null ? void 0 : overwrites.heroActionTarget),
|
|
268
|
+
createOverwriteableField("string", {
|
|
269
|
+
name: "rel",
|
|
270
|
+
required: false
|
|
271
|
+
}, overwrites == null ? void 0 : overwrites.heroActionRel),
|
|
272
|
+
...addAdditionalFields(options == null ? void 0 : options.additionalHeroActionFields)
|
|
273
|
+
].filter(filterUndefined)
|
|
274
|
+
}, omit(overwrites == null ? void 0 : overwrites.heroActions, keys)),
|
|
275
|
+
...addAdditionalFields(options == null ? void 0 : options.additionalHeroFields)
|
|
276
|
+
].filter(filterUndefined)
|
|
277
|
+
}, omit(overwrites == null ? void 0 : overwrites.hero, keys)),
|
|
278
|
+
createOverwriteableField("list", {
|
|
279
|
+
name: "features",
|
|
280
|
+
label: "Features",
|
|
281
|
+
label_singular: "feature",
|
|
282
|
+
allow_add: true,
|
|
283
|
+
required: false,
|
|
284
|
+
fields: [
|
|
285
|
+
createOverwriteableField("string", {
|
|
286
|
+
name: "title",
|
|
287
|
+
required: true
|
|
288
|
+
}, overwrites == null ? void 0 : overwrites.featuresTitle),
|
|
289
|
+
createOverwriteableField("string", {
|
|
290
|
+
name: "details",
|
|
291
|
+
required: false
|
|
292
|
+
}, overwrites == null ? void 0 : overwrites.featuresDetails),
|
|
293
|
+
// TODO: add support for object options
|
|
294
|
+
createOverwriteableField("string", {
|
|
295
|
+
name: "icon",
|
|
296
|
+
required: false
|
|
297
|
+
}, overwrites == null ? void 0 : overwrites.featuresIcon),
|
|
298
|
+
createOverwriteableField("string", {
|
|
299
|
+
name: "link",
|
|
300
|
+
required: false
|
|
301
|
+
}, overwrites == null ? void 0 : overwrites.featuresLink),
|
|
302
|
+
createOverwriteableField("string", {
|
|
303
|
+
name: "linkText",
|
|
304
|
+
label: "Link text",
|
|
305
|
+
required: false
|
|
306
|
+
}, overwrites == null ? void 0 : overwrites.featuresLinkText),
|
|
307
|
+
createOverwriteableField("string", {
|
|
308
|
+
name: "target",
|
|
309
|
+
label: "Target",
|
|
310
|
+
required: false
|
|
311
|
+
}, overwrites == null ? void 0 : overwrites.featuresTarget),
|
|
312
|
+
createOverwriteableField("string", {
|
|
313
|
+
name: "rel",
|
|
314
|
+
required: false
|
|
315
|
+
}, overwrites == null ? void 0 : overwrites.featuresRel),
|
|
316
|
+
...addAdditionalFields((_a = options == null ? void 0 : options.additionalFeatureFields) != null ? _a : [])
|
|
317
|
+
].filter(filterUndefined)
|
|
318
|
+
}, omit(overwrites == null ? void 0 : overwrites.features, keys))
|
|
319
|
+
];
|
|
195
320
|
}
|
|
196
321
|
static createDefaultPageFolderCollection(name, folder, options) {
|
|
197
322
|
const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
|
|
@@ -239,7 +364,8 @@ function getBooleanFromEnv(value, command) {
|
|
|
239
364
|
}
|
|
240
365
|
function resolveBackend(options, command) {
|
|
241
366
|
const _a = options, { local, name } = _a, backend = __objRest(_a, ["local", "name"]);
|
|
242
|
-
const
|
|
367
|
+
const git = getGitData();
|
|
368
|
+
const branch = "useCurrentBranch" in options && getBooleanFromEnv(options.useCurrentBranch, command) ? git.getBranch() : "branch" in backend ? backend.branch : void 0;
|
|
243
369
|
delete backend.useCurrentBranch;
|
|
244
370
|
const resolved = {
|
|
245
371
|
local_backend: typeof local === "object" ? objToSnakeCase(local) : getBooleanFromEnv(local, command),
|
|
@@ -269,8 +395,7 @@ function createConfigFile(config, command) {
|
|
|
269
395
|
});
|
|
270
396
|
})
|
|
271
397
|
});
|
|
272
|
-
} else
|
|
273
|
-
throw new Error("Missing either fields or files property in collection");
|
|
398
|
+
} else throw new Error("Missing either fields or files property in collection");
|
|
274
399
|
})
|
|
275
400
|
});
|
|
276
401
|
}
|
|
@@ -284,10 +409,8 @@ function createCmsFunction(method, items, createParams, options) {
|
|
|
284
409
|
};
|
|
285
410
|
return (items != null ? items : []).map((item) => {
|
|
286
411
|
const params = createParams(item);
|
|
287
|
-
if (!params)
|
|
288
|
-
|
|
289
|
-
else
|
|
290
|
-
return create(params);
|
|
412
|
+
if (!params) return null;
|
|
413
|
+
else return create(params);
|
|
291
414
|
}).filter(Boolean).join((_a = options == null ? void 0 : options.joinChar) != null ? _a : "\n");
|
|
292
415
|
}
|
|
293
416
|
function createScript(options) {
|
|
@@ -311,8 +434,7 @@ function createScript(options) {
|
|
|
311
434
|
]);
|
|
312
435
|
const events = createCmsFunction("registerEventListener", Object.keys(eventHooks), (hookName) => {
|
|
313
436
|
const hook = eventHooks[hookName];
|
|
314
|
-
if (!hook)
|
|
315
|
-
return null;
|
|
437
|
+
if (!hook) return null;
|
|
316
438
|
else {
|
|
317
439
|
const name = hookName.slice(2)[0].toLowerCase() + hookName.slice(3);
|
|
318
440
|
return `{ name: '${name}', handler: data => { function ${hook.toString()}; ${hookName}({ app: CMS, ...data }) } }`;
|
|
@@ -340,7 +462,7 @@ ${editorComponents}
|
|
|
340
462
|
}
|
|
341
463
|
|
|
342
464
|
// src/files/index.ts
|
|
343
|
-
var defaultDecapCmsCdnVersion = "3.1.
|
|
465
|
+
var defaultDecapCmsCdnVersion = "3.1.11";
|
|
344
466
|
var defaultNetlifyIdentityVersion = "1";
|
|
345
467
|
var addSlash = (path, slash = "/") => path.endsWith(slash) ? path : path + slash;
|
|
346
468
|
function resolveCdnRoute(options) {
|
|
@@ -351,13 +473,10 @@ function resolveCdnRoute(options) {
|
|
|
351
473
|
}
|
|
352
474
|
function resolveHead(head) {
|
|
353
475
|
return head.reduce((output, config) => {
|
|
354
|
-
if (typeof config === "string")
|
|
355
|
-
return output.concat(config);
|
|
476
|
+
if (typeof config === "string") return output.concat(config);
|
|
356
477
|
if ("skip" in config) {
|
|
357
|
-
if (config.skip)
|
|
358
|
-
|
|
359
|
-
if (typeof config.head === "string")
|
|
360
|
-
return output.concat(config.head);
|
|
478
|
+
if (config.skip) return output;
|
|
479
|
+
if (typeof config.head === "string") return output.concat(config.head);
|
|
361
480
|
}
|
|
362
481
|
const item = "head" in config ? config.head : config;
|
|
363
482
|
let str = `<${item[0]}`;
|
|
@@ -365,8 +484,7 @@ function resolveHead(head) {
|
|
|
365
484
|
str += ` ${key}="${item[1][key]}"`;
|
|
366
485
|
}
|
|
367
486
|
str += item[0] === "meta" ? "/>" : ">";
|
|
368
|
-
if (item[2] == void 0)
|
|
369
|
-
return output.concat(str);
|
|
487
|
+
if (item[2] == void 0) return output.concat(str);
|
|
370
488
|
str += item[2] + `</${item[0]}>`;
|
|
371
489
|
return output.concat(str);
|
|
372
490
|
}, []);
|
|
@@ -404,8 +522,7 @@ function getIndexFeatures(config, loadOptions) {
|
|
|
404
522
|
function createIndexFile(pluginOptions) {
|
|
405
523
|
var _a, _b;
|
|
406
524
|
const { config, load, login: options, script } = pluginOptions;
|
|
407
|
-
if (options == null ? void 0 : options.html)
|
|
408
|
-
return options.html;
|
|
525
|
+
if (options == null ? void 0 : options.html) return options.html;
|
|
409
526
|
const features = getIndexFeatures(config, load);
|
|
410
527
|
return `<!DOCTYPE html>
|
|
411
528
|
<html>
|
|
@@ -448,8 +565,7 @@ async function writeToFolder(folder, options) {
|
|
|
448
565
|
function validateLoadOptions(options) {
|
|
449
566
|
var _a;
|
|
450
567
|
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
451
|
-
if (!valid)
|
|
452
|
-
throw new Error("Invalid load options for decap-cms provided");
|
|
568
|
+
if (!valid) throw new Error("Invalid load options for decap-cms provided");
|
|
453
569
|
}
|
|
454
570
|
function runProxy(options) {
|
|
455
571
|
var _a, _b, _c, _d, _e;
|
|
@@ -462,8 +578,7 @@ function runProxy(options) {
|
|
|
462
578
|
proxy.on("error", (err) => {
|
|
463
579
|
if ("code" in err && err.code === "EADDRINUSE") {
|
|
464
580
|
console.log("[PROXY] Port is already used");
|
|
465
|
-
} else
|
|
466
|
-
throw err;
|
|
581
|
+
} else throw err;
|
|
467
582
|
});
|
|
468
583
|
process.on("beforeExit", () => proxy.kill());
|
|
469
584
|
}
|
|
@@ -494,8 +609,7 @@ async function updateConfig(options, config) {
|
|
|
494
609
|
function VitePluginDecapCMS(options) {
|
|
495
610
|
let stored = null;
|
|
496
611
|
const debug = (...str) => {
|
|
497
|
-
if (options.debug)
|
|
498
|
-
console.debug(str);
|
|
612
|
+
if (options.debug) console.debug(str);
|
|
499
613
|
};
|
|
500
614
|
return {
|
|
501
615
|
name: "vite-plugin-decap-cms",
|
package/package.json
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vite-plugin-decap-cms",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Simplify the configuration of Decap cms for Vite projects",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"vite",
|
|
9
|
-
"vite-plugin",
|
|
10
|
-
"decap-cms"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://github.com/ghostrider-05/vite-plugin-decap-cms",
|
|
13
|
-
"bugs": "https://github.com/ghostrider-05/vite-plugin-decap-cms/issues",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "https://github.com/ghostrider-05/vite-plugin-decap-cms"
|
|
17
|
-
},
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"require": "./dist/index.cjs",
|
|
22
|
-
"import": "./dist/index.js"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"main": "./dist/index.cjs",
|
|
26
|
-
"module": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsup src/index.ts --dts --format cjs,esm"
|
|
33
|
-
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-decap-cms",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Simplify the configuration of Decap cms for Vite projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"vite",
|
|
9
|
+
"vite-plugin",
|
|
10
|
+
"decap-cms"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/ghostrider-05/vite-plugin-decap-cms",
|
|
13
|
+
"bugs": "https://github.com/ghostrider-05/vite-plugin-decap-cms/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/ghostrider-05/vite-plugin-decap-cms"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup src/index.ts --dts --format cjs,esm"
|
|
33
|
+
},
|
|
34
|
+
"overrides": {
|
|
35
|
+
"react": "^18.3.0",
|
|
36
|
+
"@types/react": "^18.0.17",
|
|
37
|
+
"react-dom": "^18.3.1"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"decap-cms-core": "^3.3.7",
|
|
41
|
+
"decap-server": "^3.0.4",
|
|
42
|
+
"veaury": "^2.4.2",
|
|
43
|
+
"yaml": "^2.5.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "18",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
48
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
49
|
+
"eslint": "^8.57.0",
|
|
50
|
+
"tsup": "^8.2.4",
|
|
51
|
+
"typescript": "^5.5.4",
|
|
52
|
+
"vite": "^5.3.5",
|
|
53
|
+
"vitest": "^2.0.5",
|
|
54
|
+
"vue": "^3.4.35"
|
|
55
|
+
}
|
|
56
|
+
}
|