vite-plugin-decap-cms 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +188 -118
- package/dist/index.d.cts +84 -24
- package/dist/index.d.ts +84 -24
- package/dist/index.js +177 -111
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -47,27 +47,32 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
47
47
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
48
|
|
|
49
49
|
// src/index.ts
|
|
50
|
-
var
|
|
51
|
-
__export(
|
|
50
|
+
var index_exports = {};
|
|
51
|
+
__export(index_exports, {
|
|
52
52
|
VitePress: () => VitePress,
|
|
53
53
|
createField: () => createField,
|
|
54
54
|
createFile: () => createFile,
|
|
55
55
|
createFileCollection: () => createFileCollection,
|
|
56
56
|
createFolderCollection: () => createFolderCollection,
|
|
57
57
|
createOverwriteableField: () => createOverwriteableField,
|
|
58
|
+
createSharedCollectionOptions: () => createSharedCollectionOptions,
|
|
58
59
|
default: () => VitePluginDecapCMS,
|
|
60
|
+
fieldToSnakeCase: () => fieldToSnakeCase,
|
|
59
61
|
getGitData: () => getGitData
|
|
60
62
|
});
|
|
61
|
-
module.exports = __toCommonJS(
|
|
62
|
-
|
|
63
|
+
module.exports = __toCommonJS(index_exports);
|
|
64
|
+
|
|
65
|
+
// src/update.ts
|
|
66
|
+
var import_promises = require("fs/promises");
|
|
67
|
+
var import_node_path = require("path");
|
|
63
68
|
var import_yaml = require("yaml");
|
|
64
69
|
|
|
65
|
-
// src/
|
|
66
|
-
var
|
|
70
|
+
// src/utils/git.ts
|
|
71
|
+
var import_node_child_process = require("child_process");
|
|
67
72
|
function getGitData() {
|
|
68
73
|
const executeGit = (command) => {
|
|
69
74
|
try {
|
|
70
|
-
return (0,
|
|
75
|
+
return (0, import_node_child_process.execSync)(command).toString("utf8").replace(/[\n\r\s]+$/, "");
|
|
71
76
|
} catch (e) {
|
|
72
77
|
}
|
|
73
78
|
};
|
|
@@ -80,39 +85,8 @@ function getGitData() {
|
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
}
|
|
83
|
-
function createField(widget, data) {
|
|
84
|
-
return __spreadProps(__spreadValues({}, data), {
|
|
85
|
-
widget
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
function createFolderCollection(data) {
|
|
89
|
-
return data;
|
|
90
|
-
}
|
|
91
|
-
function createFile(data) {
|
|
92
|
-
return data;
|
|
93
|
-
}
|
|
94
|
-
function createFileCollection(data) {
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
function createOverwriteableField(widget, data, overwrites) {
|
|
98
|
-
if (overwrites != void 0) {
|
|
99
|
-
const toAdd = (key) => {
|
|
100
|
-
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
101
|
-
};
|
|
102
|
-
for (const key of Object.keys(overwrites)) {
|
|
103
|
-
if (key !== "hidden" && key !== "deleted") {
|
|
104
|
-
toAdd(key);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
|
|
109
|
-
else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
|
|
110
|
-
else return __spreadProps(__spreadValues({}, data), {
|
|
111
|
-
widget
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
88
|
|
|
115
|
-
// src/
|
|
89
|
+
// src/utils/object.ts
|
|
116
90
|
var objToSnakeCase = (obj) => {
|
|
117
91
|
const ignoredKeys = ["i18n"];
|
|
118
92
|
const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -120,6 +94,22 @@ var objToSnakeCase = (obj) => {
|
|
|
120
94
|
Object.entries(obj).map(([k, v]) => [ignoredKeys.includes(k) ? k : camelToSnakeCase(k), v])
|
|
121
95
|
);
|
|
122
96
|
};
|
|
97
|
+
var keyof = (obj) => Object.keys(obj);
|
|
98
|
+
function filterUndefined(item) {
|
|
99
|
+
return item != void 0;
|
|
100
|
+
}
|
|
101
|
+
function omit(obj, keys) {
|
|
102
|
+
if (!obj) return {};
|
|
103
|
+
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
104
|
+
return Object.fromEntries(validEntries);
|
|
105
|
+
}
|
|
106
|
+
function pick(obj, keys) {
|
|
107
|
+
if (!obj) return {};
|
|
108
|
+
const validEntries = Object.entries(obj).filter(([key]) => keys.includes(key));
|
|
109
|
+
return Object.fromEntries(validEntries);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/files/config.ts
|
|
123
113
|
function getBooleanFromEnv(value, command) {
|
|
124
114
|
return value === "dev" ? command === "serve" : value === "prod" ? command === "build" : value != null ? value : false;
|
|
125
115
|
}
|
|
@@ -137,7 +127,7 @@ function resolveBackend(options, command) {
|
|
|
137
127
|
};
|
|
138
128
|
return resolved;
|
|
139
129
|
}
|
|
140
|
-
function createConfigFile(config, command) {
|
|
130
|
+
function createConfigFile(config, command, log) {
|
|
141
131
|
const _a = config, { backend, collections } = _a, options = __objRest(_a, ["backend", "collections"]);
|
|
142
132
|
return __spreadProps(__spreadValues(__spreadValues({}, resolveBackend(backend, command)), objToSnakeCase(options)), {
|
|
143
133
|
collections: collections.map((col) => {
|
|
@@ -156,7 +146,7 @@ function createConfigFile(config, command) {
|
|
|
156
146
|
});
|
|
157
147
|
})
|
|
158
148
|
});
|
|
159
|
-
} else
|
|
149
|
+
} else log("config", "stderr", "Missing either fields or files property in collection");
|
|
160
150
|
})
|
|
161
151
|
});
|
|
162
152
|
}
|
|
@@ -227,8 +217,8 @@ var defaultDecapCmsCdnVersion = "3.1.11";
|
|
|
227
217
|
var defaultNetlifyIdentityVersion = "1";
|
|
228
218
|
var addSlash = (path, slash = "/") => path.endsWith(slash) ? path : path + slash;
|
|
229
219
|
function resolveCdnRoute(options) {
|
|
230
|
-
const getUrl = (host = "https://unpkg.com/",
|
|
231
|
-
return `${addSlash(host)}decap-cms@^${
|
|
220
|
+
const getUrl = (host = "https://unpkg.com/", version2 = defaultDecapCmsCdnVersion) => {
|
|
221
|
+
return `${addSlash(host)}decap-cms@^${version2}/dist/decap-cms.js`;
|
|
232
222
|
};
|
|
233
223
|
return typeof options === "boolean" ? options ? getUrl() : void 0 : typeof options === "string" ? options : options != void 0 ? getUrl(options.base, options.version) : void 0;
|
|
234
224
|
}
|
|
@@ -306,48 +296,169 @@ span[class*='CustomIconWrapper'] {
|
|
|
306
296
|
</style>` : ""}`;
|
|
307
297
|
}
|
|
308
298
|
|
|
309
|
-
// src/
|
|
310
|
-
var
|
|
311
|
-
|
|
299
|
+
// src/proxy.ts
|
|
300
|
+
var import_node_child_process2 = require("child_process");
|
|
301
|
+
function runProxy(options, log) {
|
|
302
|
+
var _a, _b, _c, _d, _e;
|
|
303
|
+
const port = ((_a = options == null ? void 0 : options.port) != null ? _a : 8081).toString();
|
|
304
|
+
log("proxy", "debug", `Starting decap-server on port ${port}`);
|
|
305
|
+
const proxy = (0, import_node_child_process2.exec)("npx decap-server", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.process) != null ? _b : {}), {
|
|
306
|
+
env: __spreadValues({
|
|
307
|
+
PORT: port,
|
|
308
|
+
MODE: options == null ? void 0 : options.mode,
|
|
309
|
+
LOG_LEVEL: options == null ? void 0 : options.logLevel,
|
|
310
|
+
GIT_REPO_DIRECTORY: options == null ? void 0 : options.gitRepoDirectory,
|
|
311
|
+
BIND_HOST: options == null ? void 0 : options.host,
|
|
312
|
+
ORIGIN: options == null ? void 0 : options.origin
|
|
313
|
+
}, (_d = (_c = options == null ? void 0 : options.process) == null ? void 0 : _c.env) != null ? _d : {})
|
|
314
|
+
}));
|
|
315
|
+
if (log("proxy", "stdout")) (_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
|
|
316
|
+
proxy.on("error", (err) => {
|
|
317
|
+
if ("code" in err && err.code === "EADDRINUSE") {
|
|
318
|
+
log("proxy", "stderr", `Port ${port} for decap-server is already used by another process`);
|
|
319
|
+
} else throw err;
|
|
320
|
+
});
|
|
321
|
+
process.on("beforeExit", () => proxy.kill());
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/update.ts
|
|
312
325
|
function resolveDir(publicDir, dir) {
|
|
313
|
-
return dir ? (0,
|
|
326
|
+
return dir ? (0, import_node_path.isAbsolute)(dir) ? dir : (0, import_node_path.resolve)(dir) : publicDir;
|
|
314
327
|
}
|
|
315
328
|
async function writeToFolder(folder, options) {
|
|
316
|
-
const dir = folder + (options.subfolder ?
|
|
329
|
+
const dir = folder + (options.subfolder ? import_node_path.sep + options.subfolder : "");
|
|
317
330
|
await (0, import_promises.mkdir)(dir, { recursive: true });
|
|
318
331
|
for (const file of options.files.filter((f) => !f.skip)) {
|
|
319
|
-
await (0, import_promises.writeFile)(dir +
|
|
332
|
+
await (0, import_promises.writeFile)(dir + import_node_path.sep + file.name, file.content, {
|
|
320
333
|
encoding: "utf-8"
|
|
321
334
|
});
|
|
322
335
|
}
|
|
323
336
|
}
|
|
337
|
+
function validateLoadOptions(options, log) {
|
|
338
|
+
var _a;
|
|
339
|
+
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
340
|
+
if (!valid) log("config", "stderr", "Invalid load options for decap-cms provided");
|
|
341
|
+
}
|
|
342
|
+
async function updateConfig(options, config, log) {
|
|
343
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
344
|
+
validateLoadOptions(options.load, log);
|
|
345
|
+
const configFile = createConfigFile(options.config, config.command, log);
|
|
346
|
+
await writeToFolder(
|
|
347
|
+
resolveDir(config.publicDir, options.dir),
|
|
348
|
+
{
|
|
349
|
+
subfolder: "admin",
|
|
350
|
+
files: [
|
|
351
|
+
{ name: "index.html", content: createIndexFile(options) },
|
|
352
|
+
{ name: "config.yml", content: (0, import_yaml.stringify)(configFile, (_a = options.yml) == null ? void 0 : _a.replacer, (_b = options.yml) == null ? void 0 : _b.options) }
|
|
353
|
+
// { name: 'npm.js', content: createCustomScript(), skip: options.load?.method !== 'npm' },
|
|
354
|
+
]
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
|
|
358
|
+
runProxy(options.proxy, log);
|
|
359
|
+
}
|
|
360
|
+
await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
|
|
361
|
+
if (config.command === "build") {
|
|
362
|
+
await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
324
365
|
|
|
325
|
-
// src/log.ts
|
|
366
|
+
// src/utils/log.ts
|
|
326
367
|
function createLogger(options) {
|
|
327
368
|
return function(type, pipe, ...data) {
|
|
328
|
-
if (options == void 0 || options === false)
|
|
369
|
+
if (options == void 0 || options === false) {
|
|
370
|
+
if (!data.length) return false;
|
|
371
|
+
else return;
|
|
372
|
+
}
|
|
373
|
+
if (!data.length) return true;
|
|
329
374
|
const fn = pipe === "stderr" ? "error" : pipe === "debug" ? "debug" : "log";
|
|
330
375
|
const pipeDefined = ["debug", "stdout", "stderr"].includes(pipe);
|
|
331
376
|
for (const msg of pipeDefined ? data : [pipe, ...data]) {
|
|
332
|
-
console[fn](`[${type.toUpperCase()}] ` + msg);
|
|
377
|
+
console[fn](`[Vite Decap] - [${type.toUpperCase()}] ` + msg);
|
|
333
378
|
}
|
|
334
379
|
};
|
|
335
380
|
}
|
|
336
381
|
|
|
337
|
-
// src/
|
|
338
|
-
function
|
|
339
|
-
return
|
|
382
|
+
// src/utils/collection.ts
|
|
383
|
+
function createField(widget, data) {
|
|
384
|
+
return __spreadProps(__spreadValues({}, data), {
|
|
385
|
+
widget
|
|
386
|
+
});
|
|
340
387
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
344
|
-
return Object.fromEntries(validEntries);
|
|
388
|
+
function createFolderCollection(data) {
|
|
389
|
+
return data;
|
|
345
390
|
}
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
391
|
+
function createFile(data) {
|
|
392
|
+
return data;
|
|
393
|
+
}
|
|
394
|
+
function createFileCollection(data) {
|
|
395
|
+
return data;
|
|
396
|
+
}
|
|
397
|
+
function fieldToSnakeCase(field) {
|
|
398
|
+
return objToSnakeCase(field);
|
|
399
|
+
}
|
|
400
|
+
function createSharedCollectionOptions(shared, options) {
|
|
401
|
+
return function(collection) {
|
|
402
|
+
const isSharedOptions = (value) => {
|
|
403
|
+
return value != void 0 && typeof value === "object" && "value" in value && !("field" in value);
|
|
404
|
+
};
|
|
405
|
+
const combinedWithShared = keyof(collection).reduce((output, key) => {
|
|
406
|
+
var _a, _b;
|
|
407
|
+
const collectionValue = collection[key];
|
|
408
|
+
const sharedValue = shared[key];
|
|
409
|
+
if (sharedValue != void 0) {
|
|
410
|
+
if (isSharedOptions(sharedValue)) {
|
|
411
|
+
const sharedOptions = sharedValue;
|
|
412
|
+
const action = (_b = (_a = sharedOptions.action) != null ? _a : options == null ? void 0 : options.action) != null ? _b : "overwrite";
|
|
413
|
+
if (action === "overwrite") {
|
|
414
|
+
output[key] = collectionValue;
|
|
415
|
+
return output;
|
|
416
|
+
} else if (action === "append") {
|
|
417
|
+
if (typeof collectionValue === "string") {
|
|
418
|
+
output[key] = sharedOptions.value + collectionValue;
|
|
419
|
+
} else if (Array.isArray(collectionValue)) {
|
|
420
|
+
output[key] = sharedOptions.value.concat(collectionValue);
|
|
421
|
+
}
|
|
422
|
+
return output;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
output[key] = collectionValue;
|
|
427
|
+
return output;
|
|
428
|
+
}, {});
|
|
429
|
+
const sharedRaw = keyof(shared).reduce((output, key) => {
|
|
430
|
+
const value = shared[key];
|
|
431
|
+
if (isSharedOptions(value)) {
|
|
432
|
+
output[key] = value.value;
|
|
433
|
+
} else {
|
|
434
|
+
output[key] = value;
|
|
435
|
+
}
|
|
436
|
+
return output;
|
|
437
|
+
}, {});
|
|
438
|
+
return __spreadValues(__spreadValues({}, sharedRaw), combinedWithShared);
|
|
439
|
+
};
|
|
350
440
|
}
|
|
441
|
+
|
|
442
|
+
// src/utils/overwrites.ts
|
|
443
|
+
function createOverwriteableField(widget, data, overwrites) {
|
|
444
|
+
if (overwrites != void 0) {
|
|
445
|
+
const toAdd = (key) => {
|
|
446
|
+
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
447
|
+
};
|
|
448
|
+
for (const key of Object.keys(overwrites)) {
|
|
449
|
+
if (key !== "hidden" && key !== "deleted") {
|
|
450
|
+
toAdd(key);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
|
|
455
|
+
else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
|
|
456
|
+
else return __spreadProps(__spreadValues({}, data), {
|
|
457
|
+
widget
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/vitepress.ts
|
|
351
462
|
var overwriteKeys = [
|
|
352
463
|
"comment",
|
|
353
464
|
"deleted",
|
|
@@ -448,11 +559,12 @@ var VitePress = class {
|
|
|
448
559
|
* - titleTemplate
|
|
449
560
|
* - description
|
|
450
561
|
* - head
|
|
562
|
+
* - body (field for writing the markdown in the file)
|
|
451
563
|
* @param options.overwrites Overwrite data, such as labels, for the fields
|
|
452
564
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
453
565
|
*/
|
|
454
566
|
static createDefaultPageFields(options) {
|
|
455
|
-
var _a, _b;
|
|
567
|
+
var _a, _b, _c;
|
|
456
568
|
const { additionalFields, overwrites } = options != null ? options : {};
|
|
457
569
|
const fields = [
|
|
458
570
|
createOverwriteableField("string", {
|
|
@@ -474,10 +586,10 @@ var VitePress = class {
|
|
|
474
586
|
label: "Head"
|
|
475
587
|
}, mergeOverwrites(overwrites == null ? void 0 : overwrites.head, overwrites))
|
|
476
588
|
].filter(filterUndefined);
|
|
477
|
-
return fields.concat(additionalFields
|
|
589
|
+
return fields.concat((_a = additionalFields == null ? void 0 : additionalFields.map(fieldToSnakeCase)) != null ? _a : []).concat((_c = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.markdownOptions) != null ? _b : {}), {
|
|
478
590
|
name: "body",
|
|
479
591
|
label: "Page content"
|
|
480
|
-
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ?
|
|
592
|
+
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ? _c : []).filter(filterUndefined);
|
|
481
593
|
}
|
|
482
594
|
/**
|
|
483
595
|
* Create fields for:
|
|
@@ -493,7 +605,7 @@ var VitePress = class {
|
|
|
493
605
|
const keys = ["hidden", "deleted"];
|
|
494
606
|
function addAdditionalFields(fields) {
|
|
495
607
|
var _a2;
|
|
496
|
-
return (_a2 = fields == null ? void 0 : fields.map(
|
|
608
|
+
return (_a2 = fields == null ? void 0 : fields.map(fieldToSnakeCase)) != null ? _a2 : [];
|
|
497
609
|
}
|
|
498
610
|
return [
|
|
499
611
|
createField("hidden", {
|
|
@@ -597,7 +709,7 @@ var VitePress = class {
|
|
|
597
709
|
...addAdditionalFields((_a = options == null ? void 0 : options.additionalFeatureFields) != null ? _a : [])
|
|
598
710
|
].filter(filterUndefined)
|
|
599
711
|
}, omit(mergeOverwrites(overwrites == null ? void 0 : overwrites.features, overwrites), keys))
|
|
600
|
-
];
|
|
712
|
+
].filter(filterUndefined);
|
|
601
713
|
}
|
|
602
714
|
static createDefaultPageFolderCollection(name, folder, options) {
|
|
603
715
|
const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
|
|
@@ -633,65 +745,21 @@ var VitePress = class {
|
|
|
633
745
|
};
|
|
634
746
|
|
|
635
747
|
// src/index.ts
|
|
636
|
-
|
|
637
|
-
var _a;
|
|
638
|
-
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
639
|
-
if (!valid) log("config", "stderr", "Invalid load options for decap-cms provided");
|
|
640
|
-
}
|
|
641
|
-
function runProxy(options, log) {
|
|
642
|
-
var _a, _b, _c, _d, _e;
|
|
643
|
-
const port = ((_a = options == null ? void 0 : options.port) != null ? _a : 8081).toString();
|
|
644
|
-
log("proxy", "debug", `Starting decap-server on port ${port}`);
|
|
645
|
-
const proxy = (0, import_child_process2.exec)("npx decap-server", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.process) != null ? _b : {}), {
|
|
646
|
-
env: __spreadProps(__spreadValues({}, (_d = (_c = options == null ? void 0 : options.process) == null ? void 0 : _c.env) != null ? _d : {}), {
|
|
647
|
-
PORT: port
|
|
648
|
-
})
|
|
649
|
-
}));
|
|
650
|
-
(_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
|
|
651
|
-
proxy.on("error", (err) => {
|
|
652
|
-
if ("code" in err && err.code === "EADDRINUSE") {
|
|
653
|
-
log("proxy", "stderr", `Port ${port} for decap-server is already used by another process`);
|
|
654
|
-
} else throw err;
|
|
655
|
-
});
|
|
656
|
-
process.on("beforeExit", () => proxy.kill());
|
|
657
|
-
}
|
|
658
|
-
async function updateConfig(options, config, log) {
|
|
659
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
660
|
-
validateLoadOptions(options.load, log);
|
|
661
|
-
const loginFile = createIndexFile(options);
|
|
662
|
-
const configFile = createConfigFile(options.config, config.command);
|
|
663
|
-
await writeToFolder(
|
|
664
|
-
resolveDir(config.publicDir, options.dir),
|
|
665
|
-
{
|
|
666
|
-
subfolder: "admin",
|
|
667
|
-
files: [
|
|
668
|
-
{ name: "index.html", content: loginFile },
|
|
669
|
-
{ name: "config.yml", content: (0, import_yaml.stringify)(configFile, (_a = options.yml) == null ? void 0 : _a.replacer, (_b = options.yml) == null ? void 0 : _b.options) }
|
|
670
|
-
// { name: 'npm.js', content: createCustomScript(), skip: options.load?.method !== 'npm' },
|
|
671
|
-
]
|
|
672
|
-
}
|
|
673
|
-
);
|
|
674
|
-
if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
|
|
675
|
-
runProxy(options.proxy, log);
|
|
676
|
-
}
|
|
677
|
-
await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
|
|
678
|
-
if (config.command === "build") {
|
|
679
|
-
await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
|
|
680
|
-
}
|
|
681
|
-
}
|
|
748
|
+
var version = "0.5.1";
|
|
682
749
|
function VitePluginDecapCMS(options) {
|
|
683
750
|
let stored = null;
|
|
684
751
|
return {
|
|
685
752
|
name: "vite-plugin-decap-cms",
|
|
753
|
+
version,
|
|
686
754
|
async configResolved(config) {
|
|
687
|
-
const
|
|
755
|
+
const needsUpdate = stored != null ? stored.command !== config.command || stored.publicDir !== config.publicDir : true;
|
|
688
756
|
const log = createLogger(options.debug);
|
|
689
|
-
if (
|
|
757
|
+
if (needsUpdate) {
|
|
690
758
|
await updateConfig(options, config, log);
|
|
691
759
|
stored = config;
|
|
692
|
-
log("config", "debug", "Updated Decap CMS configuration");
|
|
760
|
+
log("config", "debug", "Updated Decap CMS configuration files");
|
|
693
761
|
} else {
|
|
694
|
-
log("config", "debug", "Skipped updating Decap CMS");
|
|
762
|
+
log("config", "debug", "Skipped updating Decap CMS configuration files");
|
|
695
763
|
}
|
|
696
764
|
}
|
|
697
765
|
};
|
|
@@ -704,5 +772,7 @@ function VitePluginDecapCMS(options) {
|
|
|
704
772
|
createFileCollection,
|
|
705
773
|
createFolderCollection,
|
|
706
774
|
createOverwriteableField,
|
|
775
|
+
createSharedCollectionOptions,
|
|
776
|
+
fieldToSnakeCase,
|
|
707
777
|
getGitData
|
|
708
778
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import * as yaml from 'yaml';
|
|
3
|
+
import { ExecOptions } from 'node:child_process';
|
|
3
4
|
import * as decap_cms_core from 'decap-cms-core';
|
|
4
|
-
import { CmsEventListener, CMS, EditorComponentOptions, Formatter,
|
|
5
|
-
import { ExecOptions } from 'child_process';
|
|
5
|
+
import { CmsEventListener, CMS, EditorComponentOptions, Formatter, CmsCollection, CmsField, CmsCollectionFile, CmsConfig, CmsLocalBackend, CmsBackend, CmsFieldMeta, CmsFieldStringOrText, CmsFieldBase, CmsFieldMarkdown } from 'decap-cms-core';
|
|
6
6
|
|
|
7
7
|
interface CmsHookContext {
|
|
8
8
|
app: CMS;
|
|
@@ -83,13 +83,14 @@ type ScriptOptions = {
|
|
|
83
83
|
|
|
84
84
|
type CamelToSnakeCase<S extends string, I extends string = never> = S extends `${infer T}${infer U}` ? S extends I ? S : `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}` : S;
|
|
85
85
|
type KeysToSnakeCase<T> = {
|
|
86
|
-
[K in keyof T as CamelToSnakeCase<string & K, 'i18n'>]: T[K];
|
|
86
|
+
[K in keyof T as CamelToSnakeCase<string & K, 'i18n'>]: T[K] extends boolean ? T[K] : T[K] extends {} ? T[K] extends unknown[] ? KeysToSnakeCase<T[K][number]>[] : KeysToSnakeCase<T[K]> : T[K];
|
|
87
87
|
};
|
|
88
88
|
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
|
|
89
89
|
type KeysToCamelCase<T> = {
|
|
90
|
-
[K in keyof T as CamelCase<string & K>]: T[K] extends {} ? KeysToCamelCase<T[K]> : T[K];
|
|
90
|
+
[K in keyof T as CamelCase<string & K>]: T[K] extends boolean ? T[K] : T[K] extends {} ? T[K] extends unknown[] ? KeysToCamelCase<T[K][number]>[] : KeysToCamelCase<T[K]> : T[K];
|
|
91
91
|
};
|
|
92
92
|
type PickRequired<O extends object, K extends keyof O> = Omit<O, K> & Required<Pick<O, K>>;
|
|
93
|
+
|
|
93
94
|
type EnvContextOption = boolean | 'dev' | 'prod';
|
|
94
95
|
type EnvDevContextOption = Exclude<EnvContextOption, 'prod'>;
|
|
95
96
|
type CollectionType = 'file' | 'folder';
|
|
@@ -99,11 +100,11 @@ type DecapCmsFieldType = NonNullable<Exclude<CmsField, CmsFieldMeta>['widget']>;
|
|
|
99
100
|
type DecapCmsWidget = Exclude<CmsField, CmsFieldStringOrText | CmsFieldMeta> | (CmsFieldBase & PickRequired<CmsFieldStringOrText, 'widget'>);
|
|
100
101
|
type DecapCmsFieldWidget<Name extends DecapCmsFieldType> = DecapCmsWidget extends infer K ? K extends DecapCmsWidget ? Name extends K['widget'] ? K : never : never : never;
|
|
101
102
|
type DecapCmsCollectionFile = KeysToCamelCase<Omit<CmsCollectionFile, 'fields'>> & {
|
|
102
|
-
fields: DecapCmsField[];
|
|
103
|
+
fields: DecapCmsField[] | CmsField[];
|
|
103
104
|
};
|
|
104
105
|
type BaseDecapCmsCollection<Props> = KeysToCamelCase<Omit<CmsCollection, 'files' | 'fields'>> & Props;
|
|
105
106
|
type DecapCmsCollection<Type extends CollectionType = CollectionType> = Type extends 'folder' ? BaseDecapCmsCollection<{
|
|
106
|
-
fields: DecapCmsField[];
|
|
107
|
+
fields: DecapCmsField[] | CmsField[];
|
|
107
108
|
}> : Type extends 'file' ? BaseDecapCmsCollection<{
|
|
108
109
|
files: DecapCmsCollectionFile[];
|
|
109
110
|
}> : never;
|
|
@@ -176,12 +177,41 @@ interface DecapProxyOptions {
|
|
|
176
177
|
* @default true
|
|
177
178
|
*/
|
|
178
179
|
enabled?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Set the CORS 'Access-Content-Allow-Origin' for the server.
|
|
182
|
+
* @default '*'
|
|
183
|
+
*/
|
|
184
|
+
origin?: string;
|
|
179
185
|
/**
|
|
180
186
|
* Run the proxy on a different port.
|
|
181
187
|
* Does not change the local backend allowed hosts
|
|
182
188
|
* @default 8081
|
|
183
189
|
*/
|
|
184
190
|
port?: number;
|
|
191
|
+
/**
|
|
192
|
+
* Binds the proxy server to an IP address.
|
|
193
|
+
*/
|
|
194
|
+
host?: string;
|
|
195
|
+
/**
|
|
196
|
+
* Undocumented.
|
|
197
|
+
*
|
|
198
|
+
* Option for the process environment variable 'MODE'.
|
|
199
|
+
* @default 'fs'
|
|
200
|
+
*/
|
|
201
|
+
mode?: 'git' | 'fs';
|
|
202
|
+
/**
|
|
203
|
+
* Option for the process environment variable 'GIT_REPO_DIRECTORY'.
|
|
204
|
+
*
|
|
205
|
+
* The full local path to the git repo
|
|
206
|
+
* @default 'process.cwd()'
|
|
207
|
+
*/
|
|
208
|
+
gitRepoDirectory?: string;
|
|
209
|
+
/**
|
|
210
|
+
* Option for the process environment variable 'LOG_LEVEL'.
|
|
211
|
+
*
|
|
212
|
+
* @default 'info'
|
|
213
|
+
*/
|
|
214
|
+
logLevel?: string;
|
|
185
215
|
/**
|
|
186
216
|
* Pass any option to use in the child process
|
|
187
217
|
* @default undefined
|
|
@@ -231,18 +261,6 @@ interface Options {
|
|
|
231
261
|
};
|
|
232
262
|
}
|
|
233
263
|
|
|
234
|
-
declare function getGitData(): {
|
|
235
|
-
getBranch(): string | undefined;
|
|
236
|
-
getCommitSha(): string | undefined;
|
|
237
|
-
};
|
|
238
|
-
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
239
|
-
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
240
|
-
fields: DecapCmsField[];
|
|
241
|
-
};
|
|
242
|
-
declare function createFile(data: DecapCmsCollectionFile): DecapCmsCollectionFile;
|
|
243
|
-
declare function createFileCollection(data: DecapCmsCollection<'file'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
244
|
-
files: DecapCmsCollectionFile[];
|
|
245
|
-
};
|
|
246
264
|
type OverwriteOptions = Omit<CmsFieldBase, 'name'> & {
|
|
247
265
|
/**
|
|
248
266
|
* Hide this field in the CMS editor UI.
|
|
@@ -261,8 +279,9 @@ type VitePressPageFrontmatterKeys = 'title' | 'titleTemplate' | 'description' |
|
|
|
261
279
|
interface BaseVitePressFieldOptions<Keys extends string> {
|
|
262
280
|
overwrites?: Partial<Record<Keys, OverwriteOptions>> & Partial<OverwriteOptions>;
|
|
263
281
|
}
|
|
282
|
+
type VitePressAdditionalField = DecapCmsField | CmsField;
|
|
264
283
|
interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageFrontmatterKeys> {
|
|
265
|
-
additionalFields?:
|
|
284
|
+
additionalFields?: VitePressAdditionalField[];
|
|
266
285
|
/**
|
|
267
286
|
* Options for the markdown editor in the CMS
|
|
268
287
|
*/
|
|
@@ -271,7 +290,7 @@ interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageF
|
|
|
271
290
|
type VitePressDefaultThemeFrontmatterKeys = 'layout' | 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
272
291
|
type VitePressDefaultThemeFieldOptions = BaseVitePressFieldOptions<VitePressDefaultThemeFrontmatterKeys>;
|
|
273
292
|
type VitePressHomePageFrontmatterKeys = 'hero' | 'heroName' | 'heroText' | 'heroTagline' | 'heroImage' | 'heroActions' | 'heroActionTheme' | 'heroActionText' | 'heroActionLink' | 'heroActionTarget' | 'heroActionRel' | 'features' | 'featuresTitle' | 'featuresDetails' | 'featuresIcon' | 'featuresLink' | 'featuresLinkText' | 'featuresRel' | 'featuresTarget';
|
|
274
|
-
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields',
|
|
293
|
+
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields', VitePressAdditionalField[]>>;
|
|
275
294
|
declare class VitePress {
|
|
276
295
|
/**
|
|
277
296
|
* Create fields for:
|
|
@@ -289,17 +308,18 @@ declare class VitePress {
|
|
|
289
308
|
* @param options Options for overwriting field data
|
|
290
309
|
* @see https://vitepress.dev/reference/frontmatter-config#default-theme-only
|
|
291
310
|
*/
|
|
292
|
-
static createDefaultThemeNormalPageFields(options?: VitePressDefaultThemeFieldOptions):
|
|
311
|
+
static createDefaultThemeNormalPageFields(options?: VitePressDefaultThemeFieldOptions): CmsField[];
|
|
293
312
|
/**
|
|
294
313
|
* Create fields for:
|
|
295
314
|
* - title
|
|
296
315
|
* - titleTemplate
|
|
297
316
|
* - description
|
|
298
317
|
* - head
|
|
318
|
+
* - body (field for writing the markdown in the file)
|
|
299
319
|
* @param options.overwrites Overwrite data, such as labels, for the fields
|
|
300
320
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
301
321
|
*/
|
|
302
|
-
static createDefaultPageFields(options?: VitePressFieldOptions):
|
|
322
|
+
static createDefaultPageFields(options?: VitePressFieldOptions): CmsField[];
|
|
303
323
|
/**
|
|
304
324
|
* Create fields for:
|
|
305
325
|
* - layout: home (not overwriteable)
|
|
@@ -308,7 +328,7 @@ declare class VitePress {
|
|
|
308
328
|
*
|
|
309
329
|
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
310
330
|
*/
|
|
311
|
-
static createHomePageFields(options?: VitePressHomePageFieldOptions):
|
|
331
|
+
static createHomePageFields(options?: VitePressHomePageFieldOptions): CmsField[];
|
|
312
332
|
static createDefaultPageFolderCollection(name: string, folder: string, options?: VitePressFieldOptions & {
|
|
313
333
|
collection?: Partial<Omit<DecapCmsCollection<'folder'>, 'name' | 'fields' | 'folder'>>;
|
|
314
334
|
}): DecapCmsCollection<'folder'>;
|
|
@@ -322,6 +342,46 @@ declare class VitePress {
|
|
|
322
342
|
};
|
|
323
343
|
}
|
|
324
344
|
|
|
345
|
+
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
346
|
+
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
347
|
+
fields: DecapCmsField[] | CmsField[];
|
|
348
|
+
};
|
|
349
|
+
declare function createFile(data: DecapCmsCollectionFile): DecapCmsCollectionFile;
|
|
350
|
+
declare function createFileCollection(data: DecapCmsCollection<'file'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
351
|
+
files: DecapCmsCollectionFile[];
|
|
352
|
+
};
|
|
353
|
+
declare function fieldToSnakeCase(field: DecapCmsField | CmsField): CmsField;
|
|
354
|
+
type SharedAction<Type> = (Type extends (string | undefined) ? true : Type extends (unknown[] | undefined) ? true : false) extends true ? ({
|
|
355
|
+
/**
|
|
356
|
+
* The action to take when combining options from shared and collection options:
|
|
357
|
+
* - append: if specified in another collection, the new options will be appended to the shared value
|
|
358
|
+
* - overwrite: if specified in another collection, the new options will overwrite the share value
|
|
359
|
+
* @default 'overwrite'
|
|
360
|
+
*/
|
|
361
|
+
action?: 'append' | 'overwrite';
|
|
362
|
+
value: Type;
|
|
363
|
+
} | Type) : Type;
|
|
364
|
+
type PartialIf<If extends boolean, T> = If extends true ? Partial<T> : T;
|
|
365
|
+
type Invert<T extends boolean> = T extends true ? false : true;
|
|
366
|
+
type SharedDecapCmsCollection<Type extends CollectionType> = Omit<DecapCmsCollection<Type>, 'fields' | 'files'>;
|
|
367
|
+
type SharedDecapCmsCollectionOptions<Type extends CollectionType> = {
|
|
368
|
+
[K in keyof SharedDecapCmsCollection<Type>]: SharedAction<SharedDecapCmsCollection<Type>[K]>;
|
|
369
|
+
};
|
|
370
|
+
interface SharedOptions<Parent extends boolean = true> extends Pick<Exclude<SharedAction<string>, string>, 'action'> {
|
|
371
|
+
/**
|
|
372
|
+
* Changes the types on where required name fields (name, labels) must be defined:
|
|
373
|
+
* on the shared or collection options.
|
|
374
|
+
* @default true
|
|
375
|
+
*/
|
|
376
|
+
requiredNameOnChildOptions?: Parent;
|
|
377
|
+
}
|
|
378
|
+
declare function createSharedCollectionOptions<Type extends CollectionType = CollectionType, Parent extends boolean = true, ChildType extends CollectionType = Type>(shared: PartialIf<Parent, SharedDecapCmsCollectionOptions<Type>>, options?: SharedOptions<Parent>): (collection: PartialIf<Invert<Parent>, SharedDecapCmsCollection<ChildType>>) => SharedDecapCmsCollection<ChildType>;
|
|
379
|
+
|
|
380
|
+
declare function getGitData(): {
|
|
381
|
+
getBranch(): string | undefined;
|
|
382
|
+
getCommitSha(): string | undefined;
|
|
383
|
+
};
|
|
384
|
+
|
|
325
385
|
declare function VitePluginDecapCMS(options: Options): Plugin;
|
|
326
386
|
|
|
327
|
-
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, createOverwriteableField, VitePluginDecapCMS as default, getGitData };
|
|
387
|
+
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, type SharedDecapCmsCollection, type SharedDecapCmsCollectionOptions, type SharedOptions, VitePress, type VitePressAdditionalField, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressHomePageFieldOptions, type VitePressHomePageFrontmatterKeys, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, createOverwriteableField, createSharedCollectionOptions, VitePluginDecapCMS as default, fieldToSnakeCase, getGitData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import * as yaml from 'yaml';
|
|
3
|
+
import { ExecOptions } from 'node:child_process';
|
|
3
4
|
import * as decap_cms_core from 'decap-cms-core';
|
|
4
|
-
import { CmsEventListener, CMS, EditorComponentOptions, Formatter,
|
|
5
|
-
import { ExecOptions } from 'child_process';
|
|
5
|
+
import { CmsEventListener, CMS, EditorComponentOptions, Formatter, CmsCollection, CmsField, CmsCollectionFile, CmsConfig, CmsLocalBackend, CmsBackend, CmsFieldMeta, CmsFieldStringOrText, CmsFieldBase, CmsFieldMarkdown } from 'decap-cms-core';
|
|
6
6
|
|
|
7
7
|
interface CmsHookContext {
|
|
8
8
|
app: CMS;
|
|
@@ -83,13 +83,14 @@ type ScriptOptions = {
|
|
|
83
83
|
|
|
84
84
|
type CamelToSnakeCase<S extends string, I extends string = never> = S extends `${infer T}${infer U}` ? S extends I ? S : `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}` : S;
|
|
85
85
|
type KeysToSnakeCase<T> = {
|
|
86
|
-
[K in keyof T as CamelToSnakeCase<string & K, 'i18n'>]: T[K];
|
|
86
|
+
[K in keyof T as CamelToSnakeCase<string & K, 'i18n'>]: T[K] extends boolean ? T[K] : T[K] extends {} ? T[K] extends unknown[] ? KeysToSnakeCase<T[K][number]>[] : KeysToSnakeCase<T[K]> : T[K];
|
|
87
87
|
};
|
|
88
88
|
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
|
|
89
89
|
type KeysToCamelCase<T> = {
|
|
90
|
-
[K in keyof T as CamelCase<string & K>]: T[K] extends {} ? KeysToCamelCase<T[K]> : T[K];
|
|
90
|
+
[K in keyof T as CamelCase<string & K>]: T[K] extends boolean ? T[K] : T[K] extends {} ? T[K] extends unknown[] ? KeysToCamelCase<T[K][number]>[] : KeysToCamelCase<T[K]> : T[K];
|
|
91
91
|
};
|
|
92
92
|
type PickRequired<O extends object, K extends keyof O> = Omit<O, K> & Required<Pick<O, K>>;
|
|
93
|
+
|
|
93
94
|
type EnvContextOption = boolean | 'dev' | 'prod';
|
|
94
95
|
type EnvDevContextOption = Exclude<EnvContextOption, 'prod'>;
|
|
95
96
|
type CollectionType = 'file' | 'folder';
|
|
@@ -99,11 +100,11 @@ type DecapCmsFieldType = NonNullable<Exclude<CmsField, CmsFieldMeta>['widget']>;
|
|
|
99
100
|
type DecapCmsWidget = Exclude<CmsField, CmsFieldStringOrText | CmsFieldMeta> | (CmsFieldBase & PickRequired<CmsFieldStringOrText, 'widget'>);
|
|
100
101
|
type DecapCmsFieldWidget<Name extends DecapCmsFieldType> = DecapCmsWidget extends infer K ? K extends DecapCmsWidget ? Name extends K['widget'] ? K : never : never : never;
|
|
101
102
|
type DecapCmsCollectionFile = KeysToCamelCase<Omit<CmsCollectionFile, 'fields'>> & {
|
|
102
|
-
fields: DecapCmsField[];
|
|
103
|
+
fields: DecapCmsField[] | CmsField[];
|
|
103
104
|
};
|
|
104
105
|
type BaseDecapCmsCollection<Props> = KeysToCamelCase<Omit<CmsCollection, 'files' | 'fields'>> & Props;
|
|
105
106
|
type DecapCmsCollection<Type extends CollectionType = CollectionType> = Type extends 'folder' ? BaseDecapCmsCollection<{
|
|
106
|
-
fields: DecapCmsField[];
|
|
107
|
+
fields: DecapCmsField[] | CmsField[];
|
|
107
108
|
}> : Type extends 'file' ? BaseDecapCmsCollection<{
|
|
108
109
|
files: DecapCmsCollectionFile[];
|
|
109
110
|
}> : never;
|
|
@@ -176,12 +177,41 @@ interface DecapProxyOptions {
|
|
|
176
177
|
* @default true
|
|
177
178
|
*/
|
|
178
179
|
enabled?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Set the CORS 'Access-Content-Allow-Origin' for the server.
|
|
182
|
+
* @default '*'
|
|
183
|
+
*/
|
|
184
|
+
origin?: string;
|
|
179
185
|
/**
|
|
180
186
|
* Run the proxy on a different port.
|
|
181
187
|
* Does not change the local backend allowed hosts
|
|
182
188
|
* @default 8081
|
|
183
189
|
*/
|
|
184
190
|
port?: number;
|
|
191
|
+
/**
|
|
192
|
+
* Binds the proxy server to an IP address.
|
|
193
|
+
*/
|
|
194
|
+
host?: string;
|
|
195
|
+
/**
|
|
196
|
+
* Undocumented.
|
|
197
|
+
*
|
|
198
|
+
* Option for the process environment variable 'MODE'.
|
|
199
|
+
* @default 'fs'
|
|
200
|
+
*/
|
|
201
|
+
mode?: 'git' | 'fs';
|
|
202
|
+
/**
|
|
203
|
+
* Option for the process environment variable 'GIT_REPO_DIRECTORY'.
|
|
204
|
+
*
|
|
205
|
+
* The full local path to the git repo
|
|
206
|
+
* @default 'process.cwd()'
|
|
207
|
+
*/
|
|
208
|
+
gitRepoDirectory?: string;
|
|
209
|
+
/**
|
|
210
|
+
* Option for the process environment variable 'LOG_LEVEL'.
|
|
211
|
+
*
|
|
212
|
+
* @default 'info'
|
|
213
|
+
*/
|
|
214
|
+
logLevel?: string;
|
|
185
215
|
/**
|
|
186
216
|
* Pass any option to use in the child process
|
|
187
217
|
* @default undefined
|
|
@@ -231,18 +261,6 @@ interface Options {
|
|
|
231
261
|
};
|
|
232
262
|
}
|
|
233
263
|
|
|
234
|
-
declare function getGitData(): {
|
|
235
|
-
getBranch(): string | undefined;
|
|
236
|
-
getCommitSha(): string | undefined;
|
|
237
|
-
};
|
|
238
|
-
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
239
|
-
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
240
|
-
fields: DecapCmsField[];
|
|
241
|
-
};
|
|
242
|
-
declare function createFile(data: DecapCmsCollectionFile): DecapCmsCollectionFile;
|
|
243
|
-
declare function createFileCollection(data: DecapCmsCollection<'file'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
244
|
-
files: DecapCmsCollectionFile[];
|
|
245
|
-
};
|
|
246
264
|
type OverwriteOptions = Omit<CmsFieldBase, 'name'> & {
|
|
247
265
|
/**
|
|
248
266
|
* Hide this field in the CMS editor UI.
|
|
@@ -261,8 +279,9 @@ type VitePressPageFrontmatterKeys = 'title' | 'titleTemplate' | 'description' |
|
|
|
261
279
|
interface BaseVitePressFieldOptions<Keys extends string> {
|
|
262
280
|
overwrites?: Partial<Record<Keys, OverwriteOptions>> & Partial<OverwriteOptions>;
|
|
263
281
|
}
|
|
282
|
+
type VitePressAdditionalField = DecapCmsField | CmsField;
|
|
264
283
|
interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageFrontmatterKeys> {
|
|
265
|
-
additionalFields?:
|
|
284
|
+
additionalFields?: VitePressAdditionalField[];
|
|
266
285
|
/**
|
|
267
286
|
* Options for the markdown editor in the CMS
|
|
268
287
|
*/
|
|
@@ -271,7 +290,7 @@ interface VitePressFieldOptions extends BaseVitePressFieldOptions<VitePressPageF
|
|
|
271
290
|
type VitePressDefaultThemeFrontmatterKeys = 'layout' | 'navbar' | 'sidebar' | 'aside' | 'outline' | 'lastUpdated' | 'editLink' | 'footer' | 'pageClass';
|
|
272
291
|
type VitePressDefaultThemeFieldOptions = BaseVitePressFieldOptions<VitePressDefaultThemeFrontmatterKeys>;
|
|
273
292
|
type VitePressHomePageFrontmatterKeys = 'hero' | 'heroName' | 'heroText' | 'heroTagline' | 'heroImage' | 'heroActions' | 'heroActionTheme' | 'heroActionText' | 'heroActionLink' | 'heroActionTarget' | 'heroActionRel' | 'features' | 'featuresTitle' | 'featuresDetails' | 'featuresIcon' | 'featuresLink' | 'featuresLinkText' | 'featuresRel' | 'featuresTarget';
|
|
274
|
-
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields',
|
|
293
|
+
type VitePressHomePageFieldOptions = BaseVitePressFieldOptions<VitePressHomePageFrontmatterKeys> & Partial<Record<'additionalHeroFields' | 'additionalHeroActionFields' | 'additionalFeatureFields', VitePressAdditionalField[]>>;
|
|
275
294
|
declare class VitePress {
|
|
276
295
|
/**
|
|
277
296
|
* Create fields for:
|
|
@@ -289,17 +308,18 @@ declare class VitePress {
|
|
|
289
308
|
* @param options Options for overwriting field data
|
|
290
309
|
* @see https://vitepress.dev/reference/frontmatter-config#default-theme-only
|
|
291
310
|
*/
|
|
292
|
-
static createDefaultThemeNormalPageFields(options?: VitePressDefaultThemeFieldOptions):
|
|
311
|
+
static createDefaultThemeNormalPageFields(options?: VitePressDefaultThemeFieldOptions): CmsField[];
|
|
293
312
|
/**
|
|
294
313
|
* Create fields for:
|
|
295
314
|
* - title
|
|
296
315
|
* - titleTemplate
|
|
297
316
|
* - description
|
|
298
317
|
* - head
|
|
318
|
+
* - body (field for writing the markdown in the file)
|
|
299
319
|
* @param options.overwrites Overwrite data, such as labels, for the fields
|
|
300
320
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
301
321
|
*/
|
|
302
|
-
static createDefaultPageFields(options?: VitePressFieldOptions):
|
|
322
|
+
static createDefaultPageFields(options?: VitePressFieldOptions): CmsField[];
|
|
303
323
|
/**
|
|
304
324
|
* Create fields for:
|
|
305
325
|
* - layout: home (not overwriteable)
|
|
@@ -308,7 +328,7 @@ declare class VitePress {
|
|
|
308
328
|
*
|
|
309
329
|
* The object fields (`features`, `hero`, `heroActions`) can not be hidden and deleted.
|
|
310
330
|
*/
|
|
311
|
-
static createHomePageFields(options?: VitePressHomePageFieldOptions):
|
|
331
|
+
static createHomePageFields(options?: VitePressHomePageFieldOptions): CmsField[];
|
|
312
332
|
static createDefaultPageFolderCollection(name: string, folder: string, options?: VitePressFieldOptions & {
|
|
313
333
|
collection?: Partial<Omit<DecapCmsCollection<'folder'>, 'name' | 'fields' | 'folder'>>;
|
|
314
334
|
}): DecapCmsCollection<'folder'>;
|
|
@@ -322,6 +342,46 @@ declare class VitePress {
|
|
|
322
342
|
};
|
|
323
343
|
}
|
|
324
344
|
|
|
345
|
+
declare function createField<T extends DecapCmsFieldType>(widget: T, data: Omit<DecapCmsFieldWidget<T>, 'widget'>): DecapCmsFieldWidget<T>;
|
|
346
|
+
declare function createFolderCollection(data: DecapCmsCollection<'folder'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
347
|
+
fields: DecapCmsField[] | CmsField[];
|
|
348
|
+
};
|
|
349
|
+
declare function createFile(data: DecapCmsCollectionFile): DecapCmsCollectionFile;
|
|
350
|
+
declare function createFileCollection(data: DecapCmsCollection<'file'>): KeysToCamelCase<Omit<decap_cms_core.CmsCollection, "fields" | "files">> & {
|
|
351
|
+
files: DecapCmsCollectionFile[];
|
|
352
|
+
};
|
|
353
|
+
declare function fieldToSnakeCase(field: DecapCmsField | CmsField): CmsField;
|
|
354
|
+
type SharedAction<Type> = (Type extends (string | undefined) ? true : Type extends (unknown[] | undefined) ? true : false) extends true ? ({
|
|
355
|
+
/**
|
|
356
|
+
* The action to take when combining options from shared and collection options:
|
|
357
|
+
* - append: if specified in another collection, the new options will be appended to the shared value
|
|
358
|
+
* - overwrite: if specified in another collection, the new options will overwrite the share value
|
|
359
|
+
* @default 'overwrite'
|
|
360
|
+
*/
|
|
361
|
+
action?: 'append' | 'overwrite';
|
|
362
|
+
value: Type;
|
|
363
|
+
} | Type) : Type;
|
|
364
|
+
type PartialIf<If extends boolean, T> = If extends true ? Partial<T> : T;
|
|
365
|
+
type Invert<T extends boolean> = T extends true ? false : true;
|
|
366
|
+
type SharedDecapCmsCollection<Type extends CollectionType> = Omit<DecapCmsCollection<Type>, 'fields' | 'files'>;
|
|
367
|
+
type SharedDecapCmsCollectionOptions<Type extends CollectionType> = {
|
|
368
|
+
[K in keyof SharedDecapCmsCollection<Type>]: SharedAction<SharedDecapCmsCollection<Type>[K]>;
|
|
369
|
+
};
|
|
370
|
+
interface SharedOptions<Parent extends boolean = true> extends Pick<Exclude<SharedAction<string>, string>, 'action'> {
|
|
371
|
+
/**
|
|
372
|
+
* Changes the types on where required name fields (name, labels) must be defined:
|
|
373
|
+
* on the shared or collection options.
|
|
374
|
+
* @default true
|
|
375
|
+
*/
|
|
376
|
+
requiredNameOnChildOptions?: Parent;
|
|
377
|
+
}
|
|
378
|
+
declare function createSharedCollectionOptions<Type extends CollectionType = CollectionType, Parent extends boolean = true, ChildType extends CollectionType = Type>(shared: PartialIf<Parent, SharedDecapCmsCollectionOptions<Type>>, options?: SharedOptions<Parent>): (collection: PartialIf<Invert<Parent>, SharedDecapCmsCollection<ChildType>>) => SharedDecapCmsCollection<ChildType>;
|
|
379
|
+
|
|
380
|
+
declare function getGitData(): {
|
|
381
|
+
getBranch(): string | undefined;
|
|
382
|
+
getCommitSha(): string | undefined;
|
|
383
|
+
};
|
|
384
|
+
|
|
325
385
|
declare function VitePluginDecapCMS(options: Options): Plugin;
|
|
326
386
|
|
|
327
|
-
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, createOverwriteableField, VitePluginDecapCMS as default, getGitData };
|
|
387
|
+
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, type SharedDecapCmsCollection, type SharedDecapCmsCollectionOptions, type SharedOptions, VitePress, type VitePressAdditionalField, type VitePressDefaultThemeFieldOptions, type VitePressDefaultThemeFrontmatterKeys, type VitePressFieldOptions, type VitePressHomePageFieldOptions, type VitePressHomePageFrontmatterKeys, type VitePressPageFrontmatterKeys, createField, createFile, createFileCollection, createFolderCollection, createOverwriteableField, createSharedCollectionOptions, VitePluginDecapCMS as default, fieldToSnakeCase, getGitData };
|
package/dist/index.js
CHANGED
|
@@ -30,11 +30,12 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
// src/
|
|
34
|
-
import {
|
|
33
|
+
// src/update.ts
|
|
34
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
35
|
+
import { resolve, isAbsolute, sep } from "path";
|
|
35
36
|
import { stringify } from "yaml";
|
|
36
37
|
|
|
37
|
-
// src/
|
|
38
|
+
// src/utils/git.ts
|
|
38
39
|
import { execSync } from "child_process";
|
|
39
40
|
function getGitData() {
|
|
40
41
|
const executeGit = (command) => {
|
|
@@ -52,39 +53,8 @@ function getGitData() {
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
function createField(widget, data) {
|
|
56
|
-
return __spreadProps(__spreadValues({}, data), {
|
|
57
|
-
widget
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function createFolderCollection(data) {
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
function createFile(data) {
|
|
64
|
-
return data;
|
|
65
|
-
}
|
|
66
|
-
function createFileCollection(data) {
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
function createOverwriteableField(widget, data, overwrites) {
|
|
70
|
-
if (overwrites != void 0) {
|
|
71
|
-
const toAdd = (key) => {
|
|
72
|
-
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
73
|
-
};
|
|
74
|
-
for (const key of Object.keys(overwrites)) {
|
|
75
|
-
if (key !== "hidden" && key !== "deleted") {
|
|
76
|
-
toAdd(key);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
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
56
|
|
|
87
|
-
// src/
|
|
57
|
+
// src/utils/object.ts
|
|
88
58
|
var objToSnakeCase = (obj) => {
|
|
89
59
|
const ignoredKeys = ["i18n"];
|
|
90
60
|
const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -92,6 +62,22 @@ var objToSnakeCase = (obj) => {
|
|
|
92
62
|
Object.entries(obj).map(([k, v]) => [ignoredKeys.includes(k) ? k : camelToSnakeCase(k), v])
|
|
93
63
|
);
|
|
94
64
|
};
|
|
65
|
+
var keyof = (obj) => Object.keys(obj);
|
|
66
|
+
function filterUndefined(item) {
|
|
67
|
+
return item != void 0;
|
|
68
|
+
}
|
|
69
|
+
function omit(obj, keys) {
|
|
70
|
+
if (!obj) return {};
|
|
71
|
+
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
72
|
+
return Object.fromEntries(validEntries);
|
|
73
|
+
}
|
|
74
|
+
function pick(obj, keys) {
|
|
75
|
+
if (!obj) return {};
|
|
76
|
+
const validEntries = Object.entries(obj).filter(([key]) => keys.includes(key));
|
|
77
|
+
return Object.fromEntries(validEntries);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/files/config.ts
|
|
95
81
|
function getBooleanFromEnv(value, command) {
|
|
96
82
|
return value === "dev" ? command === "serve" : value === "prod" ? command === "build" : value != null ? value : false;
|
|
97
83
|
}
|
|
@@ -109,7 +95,7 @@ function resolveBackend(options, command) {
|
|
|
109
95
|
};
|
|
110
96
|
return resolved;
|
|
111
97
|
}
|
|
112
|
-
function createConfigFile(config, command) {
|
|
98
|
+
function createConfigFile(config, command, log) {
|
|
113
99
|
const _a = config, { backend, collections } = _a, options = __objRest(_a, ["backend", "collections"]);
|
|
114
100
|
return __spreadProps(__spreadValues(__spreadValues({}, resolveBackend(backend, command)), objToSnakeCase(options)), {
|
|
115
101
|
collections: collections.map((col) => {
|
|
@@ -128,7 +114,7 @@ function createConfigFile(config, command) {
|
|
|
128
114
|
});
|
|
129
115
|
})
|
|
130
116
|
});
|
|
131
|
-
} else
|
|
117
|
+
} else log("config", "stderr", "Missing either fields or files property in collection");
|
|
132
118
|
})
|
|
133
119
|
});
|
|
134
120
|
}
|
|
@@ -199,8 +185,8 @@ var defaultDecapCmsCdnVersion = "3.1.11";
|
|
|
199
185
|
var defaultNetlifyIdentityVersion = "1";
|
|
200
186
|
var addSlash = (path, slash = "/") => path.endsWith(slash) ? path : path + slash;
|
|
201
187
|
function resolveCdnRoute(options) {
|
|
202
|
-
const getUrl = (host = "https://unpkg.com/",
|
|
203
|
-
return `${addSlash(host)}decap-cms@^${
|
|
188
|
+
const getUrl = (host = "https://unpkg.com/", version2 = defaultDecapCmsCdnVersion) => {
|
|
189
|
+
return `${addSlash(host)}decap-cms@^${version2}/dist/decap-cms.js`;
|
|
204
190
|
};
|
|
205
191
|
return typeof options === "boolean" ? options ? getUrl() : void 0 : typeof options === "string" ? options : options != void 0 ? getUrl(options.base, options.version) : void 0;
|
|
206
192
|
}
|
|
@@ -278,9 +264,32 @@ span[class*='CustomIconWrapper'] {
|
|
|
278
264
|
</style>` : ""}`;
|
|
279
265
|
}
|
|
280
266
|
|
|
281
|
-
// src/
|
|
282
|
-
import {
|
|
283
|
-
|
|
267
|
+
// src/proxy.ts
|
|
268
|
+
import { exec } from "child_process";
|
|
269
|
+
function runProxy(options, log) {
|
|
270
|
+
var _a, _b, _c, _d, _e;
|
|
271
|
+
const port = ((_a = options == null ? void 0 : options.port) != null ? _a : 8081).toString();
|
|
272
|
+
log("proxy", "debug", `Starting decap-server on port ${port}`);
|
|
273
|
+
const proxy = exec("npx decap-server", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.process) != null ? _b : {}), {
|
|
274
|
+
env: __spreadValues({
|
|
275
|
+
PORT: port,
|
|
276
|
+
MODE: options == null ? void 0 : options.mode,
|
|
277
|
+
LOG_LEVEL: options == null ? void 0 : options.logLevel,
|
|
278
|
+
GIT_REPO_DIRECTORY: options == null ? void 0 : options.gitRepoDirectory,
|
|
279
|
+
BIND_HOST: options == null ? void 0 : options.host,
|
|
280
|
+
ORIGIN: options == null ? void 0 : options.origin
|
|
281
|
+
}, (_d = (_c = options == null ? void 0 : options.process) == null ? void 0 : _c.env) != null ? _d : {})
|
|
282
|
+
}));
|
|
283
|
+
if (log("proxy", "stdout")) (_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
|
|
284
|
+
proxy.on("error", (err) => {
|
|
285
|
+
if ("code" in err && err.code === "EADDRINUSE") {
|
|
286
|
+
log("proxy", "stderr", `Port ${port} for decap-server is already used by another process`);
|
|
287
|
+
} else throw err;
|
|
288
|
+
});
|
|
289
|
+
process.on("beforeExit", () => proxy.kill());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/update.ts
|
|
284
293
|
function resolveDir(publicDir, dir) {
|
|
285
294
|
return dir ? isAbsolute(dir) ? dir : resolve(dir) : publicDir;
|
|
286
295
|
}
|
|
@@ -293,33 +302,131 @@ async function writeToFolder(folder, options) {
|
|
|
293
302
|
});
|
|
294
303
|
}
|
|
295
304
|
}
|
|
305
|
+
function validateLoadOptions(options, log) {
|
|
306
|
+
var _a;
|
|
307
|
+
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
308
|
+
if (!valid) log("config", "stderr", "Invalid load options for decap-cms provided");
|
|
309
|
+
}
|
|
310
|
+
async function updateConfig(options, config, log) {
|
|
311
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
312
|
+
validateLoadOptions(options.load, log);
|
|
313
|
+
const configFile = createConfigFile(options.config, config.command, log);
|
|
314
|
+
await writeToFolder(
|
|
315
|
+
resolveDir(config.publicDir, options.dir),
|
|
316
|
+
{
|
|
317
|
+
subfolder: "admin",
|
|
318
|
+
files: [
|
|
319
|
+
{ name: "index.html", content: createIndexFile(options) },
|
|
320
|
+
{ name: "config.yml", content: stringify(configFile, (_a = options.yml) == null ? void 0 : _a.replacer, (_b = options.yml) == null ? void 0 : _b.options) }
|
|
321
|
+
// { name: 'npm.js', content: createCustomScript(), skip: options.load?.method !== 'npm' },
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
|
|
326
|
+
runProxy(options.proxy, log);
|
|
327
|
+
}
|
|
328
|
+
await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
|
|
329
|
+
if (config.command === "build") {
|
|
330
|
+
await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
296
333
|
|
|
297
|
-
// src/log.ts
|
|
334
|
+
// src/utils/log.ts
|
|
298
335
|
function createLogger(options) {
|
|
299
336
|
return function(type, pipe, ...data) {
|
|
300
|
-
if (options == void 0 || options === false)
|
|
337
|
+
if (options == void 0 || options === false) {
|
|
338
|
+
if (!data.length) return false;
|
|
339
|
+
else return;
|
|
340
|
+
}
|
|
341
|
+
if (!data.length) return true;
|
|
301
342
|
const fn = pipe === "stderr" ? "error" : pipe === "debug" ? "debug" : "log";
|
|
302
343
|
const pipeDefined = ["debug", "stdout", "stderr"].includes(pipe);
|
|
303
344
|
for (const msg of pipeDefined ? data : [pipe, ...data]) {
|
|
304
|
-
console[fn](`[${type.toUpperCase()}] ` + msg);
|
|
345
|
+
console[fn](`[Vite Decap] - [${type.toUpperCase()}] ` + msg);
|
|
305
346
|
}
|
|
306
347
|
};
|
|
307
348
|
}
|
|
308
349
|
|
|
309
|
-
// src/
|
|
310
|
-
function
|
|
311
|
-
return
|
|
350
|
+
// src/utils/collection.ts
|
|
351
|
+
function createField(widget, data) {
|
|
352
|
+
return __spreadProps(__spreadValues({}, data), {
|
|
353
|
+
widget
|
|
354
|
+
});
|
|
312
355
|
}
|
|
313
|
-
function
|
|
314
|
-
|
|
315
|
-
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
316
|
-
return Object.fromEntries(validEntries);
|
|
356
|
+
function createFolderCollection(data) {
|
|
357
|
+
return data;
|
|
317
358
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
359
|
+
function createFile(data) {
|
|
360
|
+
return data;
|
|
361
|
+
}
|
|
362
|
+
function createFileCollection(data) {
|
|
363
|
+
return data;
|
|
364
|
+
}
|
|
365
|
+
function fieldToSnakeCase(field) {
|
|
366
|
+
return objToSnakeCase(field);
|
|
367
|
+
}
|
|
368
|
+
function createSharedCollectionOptions(shared, options) {
|
|
369
|
+
return function(collection) {
|
|
370
|
+
const isSharedOptions = (value) => {
|
|
371
|
+
return value != void 0 && typeof value === "object" && "value" in value && !("field" in value);
|
|
372
|
+
};
|
|
373
|
+
const combinedWithShared = keyof(collection).reduce((output, key) => {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
const collectionValue = collection[key];
|
|
376
|
+
const sharedValue = shared[key];
|
|
377
|
+
if (sharedValue != void 0) {
|
|
378
|
+
if (isSharedOptions(sharedValue)) {
|
|
379
|
+
const sharedOptions = sharedValue;
|
|
380
|
+
const action = (_b = (_a = sharedOptions.action) != null ? _a : options == null ? void 0 : options.action) != null ? _b : "overwrite";
|
|
381
|
+
if (action === "overwrite") {
|
|
382
|
+
output[key] = collectionValue;
|
|
383
|
+
return output;
|
|
384
|
+
} else if (action === "append") {
|
|
385
|
+
if (typeof collectionValue === "string") {
|
|
386
|
+
output[key] = sharedOptions.value + collectionValue;
|
|
387
|
+
} else if (Array.isArray(collectionValue)) {
|
|
388
|
+
output[key] = sharedOptions.value.concat(collectionValue);
|
|
389
|
+
}
|
|
390
|
+
return output;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
output[key] = collectionValue;
|
|
395
|
+
return output;
|
|
396
|
+
}, {});
|
|
397
|
+
const sharedRaw = keyof(shared).reduce((output, key) => {
|
|
398
|
+
const value = shared[key];
|
|
399
|
+
if (isSharedOptions(value)) {
|
|
400
|
+
output[key] = value.value;
|
|
401
|
+
} else {
|
|
402
|
+
output[key] = value;
|
|
403
|
+
}
|
|
404
|
+
return output;
|
|
405
|
+
}, {});
|
|
406
|
+
return __spreadValues(__spreadValues({}, sharedRaw), combinedWithShared);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/utils/overwrites.ts
|
|
411
|
+
function createOverwriteableField(widget, data, overwrites) {
|
|
412
|
+
if (overwrites != void 0) {
|
|
413
|
+
const toAdd = (key) => {
|
|
414
|
+
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
415
|
+
};
|
|
416
|
+
for (const key of Object.keys(overwrites)) {
|
|
417
|
+
if (key !== "hidden" && key !== "deleted") {
|
|
418
|
+
toAdd(key);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
|
|
423
|
+
else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
|
|
424
|
+
else return __spreadProps(__spreadValues({}, data), {
|
|
425
|
+
widget
|
|
426
|
+
});
|
|
322
427
|
}
|
|
428
|
+
|
|
429
|
+
// src/vitepress.ts
|
|
323
430
|
var overwriteKeys = [
|
|
324
431
|
"comment",
|
|
325
432
|
"deleted",
|
|
@@ -420,11 +527,12 @@ var VitePress = class {
|
|
|
420
527
|
* - titleTemplate
|
|
421
528
|
* - description
|
|
422
529
|
* - head
|
|
530
|
+
* - body (field for writing the markdown in the file)
|
|
423
531
|
* @param options.overwrites Overwrite data, such as labels, for the fields
|
|
424
532
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
425
533
|
*/
|
|
426
534
|
static createDefaultPageFields(options) {
|
|
427
|
-
var _a, _b;
|
|
535
|
+
var _a, _b, _c;
|
|
428
536
|
const { additionalFields, overwrites } = options != null ? options : {};
|
|
429
537
|
const fields = [
|
|
430
538
|
createOverwriteableField("string", {
|
|
@@ -446,10 +554,10 @@ var VitePress = class {
|
|
|
446
554
|
label: "Head"
|
|
447
555
|
}, mergeOverwrites(overwrites == null ? void 0 : overwrites.head, overwrites))
|
|
448
556
|
].filter(filterUndefined);
|
|
449
|
-
return fields.concat(additionalFields
|
|
557
|
+
return fields.concat((_a = additionalFields == null ? void 0 : additionalFields.map(fieldToSnakeCase)) != null ? _a : []).concat((_c = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.markdownOptions) != null ? _b : {}), {
|
|
450
558
|
name: "body",
|
|
451
559
|
label: "Page content"
|
|
452
|
-
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ?
|
|
560
|
+
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ? _c : []).filter(filterUndefined);
|
|
453
561
|
}
|
|
454
562
|
/**
|
|
455
563
|
* Create fields for:
|
|
@@ -465,7 +573,7 @@ var VitePress = class {
|
|
|
465
573
|
const keys = ["hidden", "deleted"];
|
|
466
574
|
function addAdditionalFields(fields) {
|
|
467
575
|
var _a2;
|
|
468
|
-
return (_a2 = fields == null ? void 0 : fields.map(
|
|
576
|
+
return (_a2 = fields == null ? void 0 : fields.map(fieldToSnakeCase)) != null ? _a2 : [];
|
|
469
577
|
}
|
|
470
578
|
return [
|
|
471
579
|
createField("hidden", {
|
|
@@ -569,7 +677,7 @@ var VitePress = class {
|
|
|
569
677
|
...addAdditionalFields((_a = options == null ? void 0 : options.additionalFeatureFields) != null ? _a : [])
|
|
570
678
|
].filter(filterUndefined)
|
|
571
679
|
}, omit(mergeOverwrites(overwrites == null ? void 0 : overwrites.features, overwrites), keys))
|
|
572
|
-
];
|
|
680
|
+
].filter(filterUndefined);
|
|
573
681
|
}
|
|
574
682
|
static createDefaultPageFolderCollection(name, folder, options) {
|
|
575
683
|
const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
|
|
@@ -605,65 +713,21 @@ var VitePress = class {
|
|
|
605
713
|
};
|
|
606
714
|
|
|
607
715
|
// src/index.ts
|
|
608
|
-
|
|
609
|
-
var _a;
|
|
610
|
-
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
611
|
-
if (!valid) log("config", "stderr", "Invalid load options for decap-cms provided");
|
|
612
|
-
}
|
|
613
|
-
function runProxy(options, log) {
|
|
614
|
-
var _a, _b, _c, _d, _e;
|
|
615
|
-
const port = ((_a = options == null ? void 0 : options.port) != null ? _a : 8081).toString();
|
|
616
|
-
log("proxy", "debug", `Starting decap-server on port ${port}`);
|
|
617
|
-
const proxy = exec("npx decap-server", __spreadProps(__spreadValues({}, (_b = options == null ? void 0 : options.process) != null ? _b : {}), {
|
|
618
|
-
env: __spreadProps(__spreadValues({}, (_d = (_c = options == null ? void 0 : options.process) == null ? void 0 : _c.env) != null ? _d : {}), {
|
|
619
|
-
PORT: port
|
|
620
|
-
})
|
|
621
|
-
}));
|
|
622
|
-
(_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
|
|
623
|
-
proxy.on("error", (err) => {
|
|
624
|
-
if ("code" in err && err.code === "EADDRINUSE") {
|
|
625
|
-
log("proxy", "stderr", `Port ${port} for decap-server is already used by another process`);
|
|
626
|
-
} else throw err;
|
|
627
|
-
});
|
|
628
|
-
process.on("beforeExit", () => proxy.kill());
|
|
629
|
-
}
|
|
630
|
-
async function updateConfig(options, config, log) {
|
|
631
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
632
|
-
validateLoadOptions(options.load, log);
|
|
633
|
-
const loginFile = createIndexFile(options);
|
|
634
|
-
const configFile = createConfigFile(options.config, config.command);
|
|
635
|
-
await writeToFolder(
|
|
636
|
-
resolveDir(config.publicDir, options.dir),
|
|
637
|
-
{
|
|
638
|
-
subfolder: "admin",
|
|
639
|
-
files: [
|
|
640
|
-
{ name: "index.html", content: loginFile },
|
|
641
|
-
{ name: "config.yml", content: stringify(configFile, (_a = options.yml) == null ? void 0 : _a.replacer, (_b = options.yml) == null ? void 0 : _b.options) }
|
|
642
|
-
// { name: 'npm.js', content: createCustomScript(), skip: options.load?.method !== 'npm' },
|
|
643
|
-
]
|
|
644
|
-
}
|
|
645
|
-
);
|
|
646
|
-
if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
|
|
647
|
-
runProxy(options.proxy, log);
|
|
648
|
-
}
|
|
649
|
-
await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
|
|
650
|
-
if (config.command === "build") {
|
|
651
|
-
await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
|
|
652
|
-
}
|
|
653
|
-
}
|
|
716
|
+
var version = "0.5.1";
|
|
654
717
|
function VitePluginDecapCMS(options) {
|
|
655
718
|
let stored = null;
|
|
656
719
|
return {
|
|
657
720
|
name: "vite-plugin-decap-cms",
|
|
721
|
+
version,
|
|
658
722
|
async configResolved(config) {
|
|
659
|
-
const
|
|
723
|
+
const needsUpdate = stored != null ? stored.command !== config.command || stored.publicDir !== config.publicDir : true;
|
|
660
724
|
const log = createLogger(options.debug);
|
|
661
|
-
if (
|
|
725
|
+
if (needsUpdate) {
|
|
662
726
|
await updateConfig(options, config, log);
|
|
663
727
|
stored = config;
|
|
664
|
-
log("config", "debug", "Updated Decap CMS configuration");
|
|
728
|
+
log("config", "debug", "Updated Decap CMS configuration files");
|
|
665
729
|
} else {
|
|
666
|
-
log("config", "debug", "Skipped updating Decap CMS");
|
|
730
|
+
log("config", "debug", "Skipped updating Decap CMS configuration files");
|
|
667
731
|
}
|
|
668
732
|
}
|
|
669
733
|
};
|
|
@@ -675,6 +739,8 @@ export {
|
|
|
675
739
|
createFileCollection,
|
|
676
740
|
createFolderCollection,
|
|
677
741
|
createOverwriteableField,
|
|
742
|
+
createSharedCollectionOptions,
|
|
678
743
|
VitePluginDecapCMS as default,
|
|
744
|
+
fieldToSnakeCase,
|
|
679
745
|
getGitData
|
|
680
746
|
};
|