vite-plugin-decap-cms 0.4.0 → 0.5.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 +113 -179
- package/dist/index.d.cts +23 -74
- package/dist/index.d.ts +23 -74
- package/dist/index.js +109 -171
- package/package.json +54 -56
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
|
-
# in /docs/
|
|
65
|
-
npm run docs:dev
|
|
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
|
@@ -55,24 +55,19 @@ __export(src_exports, {
|
|
|
55
55
|
createFileCollection: () => createFileCollection,
|
|
56
56
|
createFolderCollection: () => createFolderCollection,
|
|
57
57
|
createOverwriteableField: () => createOverwriteableField,
|
|
58
|
-
createSharedCollectionOptions: () => createSharedCollectionOptions,
|
|
59
58
|
default: () => VitePluginDecapCMS,
|
|
60
|
-
fieldToSnakeCase: () => fieldToSnakeCase,
|
|
61
59
|
getGitData: () => getGitData
|
|
62
60
|
});
|
|
63
61
|
module.exports = __toCommonJS(src_exports);
|
|
64
|
-
|
|
65
|
-
// src/update.ts
|
|
66
|
-
var import_promises = require("fs/promises");
|
|
67
|
-
var import_node_path = require("path");
|
|
62
|
+
var import_child_process2 = require("child_process");
|
|
68
63
|
var import_yaml = require("yaml");
|
|
69
64
|
|
|
70
|
-
// src/
|
|
71
|
-
var
|
|
65
|
+
// src/util.ts
|
|
66
|
+
var import_child_process = require("child_process");
|
|
72
67
|
function getGitData() {
|
|
73
68
|
const executeGit = (command) => {
|
|
74
69
|
try {
|
|
75
|
-
return (0,
|
|
70
|
+
return (0, import_child_process.execSync)(command).toString("utf8").replace(/[\n\r\s]+$/, "");
|
|
76
71
|
} catch (e) {
|
|
77
72
|
}
|
|
78
73
|
};
|
|
@@ -85,8 +80,39 @@ function getGitData() {
|
|
|
85
80
|
}
|
|
86
81
|
};
|
|
87
82
|
}
|
|
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
|
+
}
|
|
88
114
|
|
|
89
|
-
// src/
|
|
115
|
+
// src/files/config.ts
|
|
90
116
|
var objToSnakeCase = (obj) => {
|
|
91
117
|
const ignoredKeys = ["i18n"];
|
|
92
118
|
const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -94,22 +120,6 @@ var objToSnakeCase = (obj) => {
|
|
|
94
120
|
Object.entries(obj).map(([k, v]) => [ignoredKeys.includes(k) ? k : camelToSnakeCase(k), v])
|
|
95
121
|
);
|
|
96
122
|
};
|
|
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
|
|
113
123
|
function getBooleanFromEnv(value, command) {
|
|
114
124
|
return value === "dev" ? command === "serve" : value === "prod" ? command === "build" : value != null ? value : false;
|
|
115
125
|
}
|
|
@@ -127,7 +137,7 @@ function resolveBackend(options, command) {
|
|
|
127
137
|
};
|
|
128
138
|
return resolved;
|
|
129
139
|
}
|
|
130
|
-
function createConfigFile(config, command
|
|
140
|
+
function createConfigFile(config, command) {
|
|
131
141
|
const _a = config, { backend, collections } = _a, options = __objRest(_a, ["backend", "collections"]);
|
|
132
142
|
return __spreadProps(__spreadValues(__spreadValues({}, resolveBackend(backend, command)), objToSnakeCase(options)), {
|
|
133
143
|
collections: collections.map((col) => {
|
|
@@ -146,7 +156,7 @@ function createConfigFile(config, command, log) {
|
|
|
146
156
|
});
|
|
147
157
|
})
|
|
148
158
|
});
|
|
149
|
-
} else
|
|
159
|
+
} else throw new Error("Missing either fields or files property in collection");
|
|
150
160
|
})
|
|
151
161
|
});
|
|
152
162
|
}
|
|
@@ -296,167 +306,48 @@ span[class*='CustomIconWrapper'] {
|
|
|
296
306
|
</style>` : ""}`;
|
|
297
307
|
}
|
|
298
308
|
|
|
299
|
-
// src/
|
|
300
|
-
var
|
|
301
|
-
|
|
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
|
-
}, (_d = (_c = options == null ? void 0 : options.process) == null ? void 0 : _c.env) != null ? _d : {})
|
|
312
|
-
}));
|
|
313
|
-
if (log("proxy", "stdout")) (_e = proxy.stdout) == null ? void 0 : _e.pipe(process.stdout);
|
|
314
|
-
proxy.on("error", (err) => {
|
|
315
|
-
if ("code" in err && err.code === "EADDRINUSE") {
|
|
316
|
-
log("proxy", "stderr", `Port ${port} for decap-server is already used by another process`);
|
|
317
|
-
} else throw err;
|
|
318
|
-
});
|
|
319
|
-
process.on("beforeExit", () => proxy.kill());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// src/update.ts
|
|
309
|
+
// src/files.ts
|
|
310
|
+
var import_promises = require("fs/promises");
|
|
311
|
+
var import_path = require("path");
|
|
323
312
|
function resolveDir(publicDir, dir) {
|
|
324
|
-
return dir ? (0,
|
|
313
|
+
return dir ? (0, import_path.isAbsolute)(dir) ? dir : (0, import_path.resolve)(dir) : publicDir;
|
|
325
314
|
}
|
|
326
315
|
async function writeToFolder(folder, options) {
|
|
327
|
-
const dir = folder + (options.subfolder ?
|
|
316
|
+
const dir = folder + (options.subfolder ? import_path.sep + options.subfolder : "");
|
|
328
317
|
await (0, import_promises.mkdir)(dir, { recursive: true });
|
|
329
318
|
for (const file of options.files.filter((f) => !f.skip)) {
|
|
330
|
-
await (0, import_promises.writeFile)(dir +
|
|
319
|
+
await (0, import_promises.writeFile)(dir + import_path.sep + file.name, file.content, {
|
|
331
320
|
encoding: "utf-8"
|
|
332
321
|
});
|
|
333
322
|
}
|
|
334
323
|
}
|
|
335
|
-
function validateLoadOptions(options, log) {
|
|
336
|
-
var _a;
|
|
337
|
-
const valid = ["npm", "cdn"].includes((_a = options == null ? void 0 : options.method) != null ? _a : "cdn");
|
|
338
|
-
if (!valid) log("config", "stderr", "Invalid load options for decap-cms provided");
|
|
339
|
-
}
|
|
340
|
-
async function updateConfig(options, config, log) {
|
|
341
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
342
|
-
validateLoadOptions(options.load, log);
|
|
343
|
-
const configFile = createConfigFile(options.config, config.command, log);
|
|
344
|
-
await writeToFolder(
|
|
345
|
-
resolveDir(config.publicDir, options.dir),
|
|
346
|
-
{
|
|
347
|
-
subfolder: "admin",
|
|
348
|
-
files: [
|
|
349
|
-
{ name: "index.html", content: createIndexFile(options) },
|
|
350
|
-
{ 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) }
|
|
351
|
-
// { name: 'npm.js', content: createCustomScript(), skip: options.load?.method !== 'npm' },
|
|
352
|
-
]
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
if (config.command === "serve" && configFile.local_backend !== false && ((_d = (_c = options.proxy) == null ? void 0 : _c.enabled) != null ? _d : true)) {
|
|
356
|
-
runProxy(options.proxy, log);
|
|
357
|
-
}
|
|
358
|
-
await ((_f = (_e = options.script) == null ? void 0 : _e.onConfigUpdated) == null ? void 0 : _f.call(_e));
|
|
359
|
-
if (config.command === "build") {
|
|
360
|
-
await ((_h = (_g = options.script) == null ? void 0 : _g.onGenerated) == null ? void 0 : _h.call(_g));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
324
|
|
|
364
|
-
// src/
|
|
325
|
+
// src/log.ts
|
|
365
326
|
function createLogger(options) {
|
|
366
327
|
return function(type, pipe, ...data) {
|
|
367
|
-
if (options == void 0 || options === false)
|
|
368
|
-
if (!data.length) return false;
|
|
369
|
-
else return;
|
|
370
|
-
}
|
|
371
|
-
if (!data.length) return true;
|
|
328
|
+
if (options == void 0 || options === false) return;
|
|
372
329
|
const fn = pipe === "stderr" ? "error" : pipe === "debug" ? "debug" : "log";
|
|
373
330
|
const pipeDefined = ["debug", "stdout", "stderr"].includes(pipe);
|
|
374
331
|
for (const msg of pipeDefined ? data : [pipe, ...data]) {
|
|
375
|
-
console[fn](`[
|
|
332
|
+
console[fn](`[${type.toUpperCase()}] ` + msg);
|
|
376
333
|
}
|
|
377
334
|
};
|
|
378
335
|
}
|
|
379
336
|
|
|
380
|
-
// src/
|
|
381
|
-
function
|
|
382
|
-
return
|
|
383
|
-
widget
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
function createFolderCollection(data) {
|
|
387
|
-
return data;
|
|
388
|
-
}
|
|
389
|
-
function createFile(data) {
|
|
390
|
-
return data;
|
|
391
|
-
}
|
|
392
|
-
function createFileCollection(data) {
|
|
393
|
-
return data;
|
|
394
|
-
}
|
|
395
|
-
function fieldToSnakeCase(field) {
|
|
396
|
-
return objToSnakeCase(field);
|
|
337
|
+
// src/vitepress.ts
|
|
338
|
+
function filterUndefined(item) {
|
|
339
|
+
return item != void 0;
|
|
397
340
|
}
|
|
398
|
-
function
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
const combinedWithShared = keyof(collection).reduce((output, key) => {
|
|
404
|
-
var _a, _b;
|
|
405
|
-
const collectionValue = collection[key];
|
|
406
|
-
const sharedValue = shared[key];
|
|
407
|
-
if (sharedValue != void 0) {
|
|
408
|
-
if (isSharedOptions(sharedValue)) {
|
|
409
|
-
const sharedOptions = sharedValue;
|
|
410
|
-
const action = (_b = (_a = sharedOptions.action) != null ? _a : options == null ? void 0 : options.action) != null ? _b : "overwrite";
|
|
411
|
-
if (action === "overwrite") {
|
|
412
|
-
output[key] = collectionValue;
|
|
413
|
-
return output;
|
|
414
|
-
} else if (action === "append") {
|
|
415
|
-
if (typeof collectionValue === "string") {
|
|
416
|
-
output[key] = sharedOptions.value + collectionValue;
|
|
417
|
-
} else if (Array.isArray(collectionValue)) {
|
|
418
|
-
output[key] = sharedOptions.value.concat(collectionValue);
|
|
419
|
-
}
|
|
420
|
-
return output;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
output[key] = collectionValue;
|
|
425
|
-
return output;
|
|
426
|
-
}, {});
|
|
427
|
-
const sharedRaw = keyof(shared).reduce((output, key) => {
|
|
428
|
-
const value = shared[key];
|
|
429
|
-
if (isSharedOptions(value)) {
|
|
430
|
-
output[key] = value.value;
|
|
431
|
-
} else {
|
|
432
|
-
output[key] = value;
|
|
433
|
-
}
|
|
434
|
-
return output;
|
|
435
|
-
}, {});
|
|
436
|
-
return __spreadValues(__spreadValues({}, sharedRaw), combinedWithShared);
|
|
437
|
-
};
|
|
341
|
+
function omit(obj, keys) {
|
|
342
|
+
if (!obj) return {};
|
|
343
|
+
const validEntries = Object.entries(obj).filter(([key]) => !keys.includes(key));
|
|
344
|
+
return Object.fromEntries(validEntries);
|
|
438
345
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const toAdd = (key) => {
|
|
444
|
-
if ((overwrites == null ? void 0 : overwrites[key]) != void 0 && data[key] !== overwrites[key]) data[key] = overwrites[key];
|
|
445
|
-
};
|
|
446
|
-
for (const key of Object.keys(overwrites)) {
|
|
447
|
-
if (key !== "hidden" && key !== "deleted") {
|
|
448
|
-
toAdd(key);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (overwrites == null ? void 0 : overwrites.deleted) return void 0;
|
|
453
|
-
else if ((overwrites == null ? void 0 : overwrites.hidden) && widget !== "hidden") return createField("hidden", data);
|
|
454
|
-
else return __spreadProps(__spreadValues({}, data), {
|
|
455
|
-
widget
|
|
456
|
-
});
|
|
346
|
+
function pick(obj, keys) {
|
|
347
|
+
if (!obj) return {};
|
|
348
|
+
const validEntries = Object.entries(obj).filter(([key]) => keys.includes(key));
|
|
349
|
+
return Object.fromEntries(validEntries);
|
|
457
350
|
}
|
|
458
|
-
|
|
459
|
-
// src/vitepress.ts
|
|
460
351
|
var overwriteKeys = [
|
|
461
352
|
"comment",
|
|
462
353
|
"deleted",
|
|
@@ -557,12 +448,11 @@ var VitePress = class {
|
|
|
557
448
|
* - titleTemplate
|
|
558
449
|
* - description
|
|
559
450
|
* - head
|
|
560
|
-
* - body (field for writing the markdown in the file)
|
|
561
451
|
* @param options.overwrites Overwrite data, such as labels, for the fields
|
|
562
452
|
* @see https://vitepress.dev/reference/frontmatter-config
|
|
563
453
|
*/
|
|
564
454
|
static createDefaultPageFields(options) {
|
|
565
|
-
var _a, _b
|
|
455
|
+
var _a, _b;
|
|
566
456
|
const { additionalFields, overwrites } = options != null ? options : {};
|
|
567
457
|
const fields = [
|
|
568
458
|
createOverwriteableField("string", {
|
|
@@ -584,10 +474,10 @@ var VitePress = class {
|
|
|
584
474
|
label: "Head"
|
|
585
475
|
}, mergeOverwrites(overwrites == null ? void 0 : overwrites.head, overwrites))
|
|
586
476
|
].filter(filterUndefined);
|
|
587
|
-
return fields.concat(
|
|
477
|
+
return fields.concat(additionalFields != null ? additionalFields : []).concat((_b = createOverwriteableField("markdown", __spreadProps(__spreadValues({}, (_a = options == null ? void 0 : options.markdownOptions) != null ? _a : {}), {
|
|
588
478
|
name: "body",
|
|
589
479
|
label: "Page content"
|
|
590
|
-
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ?
|
|
480
|
+
}), mergeOverwrites(overwrites == null ? void 0 : overwrites.body, overwrites))) != null ? _b : []).filter(filterUndefined);
|
|
591
481
|
}
|
|
592
482
|
/**
|
|
593
483
|
* Create fields for:
|
|
@@ -603,7 +493,7 @@ var VitePress = class {
|
|
|
603
493
|
const keys = ["hidden", "deleted"];
|
|
604
494
|
function addAdditionalFields(fields) {
|
|
605
495
|
var _a2;
|
|
606
|
-
return (_a2 = fields == null ? void 0 : fields.map(
|
|
496
|
+
return (_a2 = fields == null ? void 0 : fields.map((f) => objToSnakeCase(f))) != null ? _a2 : [];
|
|
607
497
|
}
|
|
608
498
|
return [
|
|
609
499
|
createField("hidden", {
|
|
@@ -707,7 +597,7 @@ var VitePress = class {
|
|
|
707
597
|
...addAdditionalFields((_a = options == null ? void 0 : options.additionalFeatureFields) != null ? _a : [])
|
|
708
598
|
].filter(filterUndefined)
|
|
709
599
|
}, omit(mergeOverwrites(overwrites == null ? void 0 : overwrites.features, overwrites), keys))
|
|
710
|
-
]
|
|
600
|
+
];
|
|
711
601
|
}
|
|
712
602
|
static createDefaultPageFolderCollection(name, folder, options) {
|
|
713
603
|
const _a = options != null ? options : {}, { collection } = _a, fieldsOptions = __objRest(_a, ["collection"]);
|
|
@@ -743,19 +633,65 @@ var VitePress = class {
|
|
|
743
633
|
};
|
|
744
634
|
|
|
745
635
|
// src/index.ts
|
|
636
|
+
function validateLoadOptions(options, log) {
|
|
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
|
+
}
|
|
746
682
|
function VitePluginDecapCMS(options) {
|
|
747
683
|
let stored = null;
|
|
748
684
|
return {
|
|
749
685
|
name: "vite-plugin-decap-cms",
|
|
750
686
|
async configResolved(config) {
|
|
751
|
-
const
|
|
687
|
+
const isUpdated = stored != null ? stored.command !== config.command || stored.publicDir !== config.publicDir : true;
|
|
752
688
|
const log = createLogger(options.debug);
|
|
753
|
-
if (
|
|
689
|
+
if (isUpdated) {
|
|
754
690
|
await updateConfig(options, config, log);
|
|
755
691
|
stored = config;
|
|
756
|
-
log("config", "debug", "Updated Decap CMS configuration
|
|
692
|
+
log("config", "debug", "Updated Decap CMS configuration");
|
|
757
693
|
} else {
|
|
758
|
-
log("config", "debug", "Skipped updating Decap CMS
|
|
694
|
+
log("config", "debug", "Skipped updating Decap CMS");
|
|
759
695
|
}
|
|
760
696
|
}
|
|
761
697
|
};
|
|
@@ -768,7 +704,5 @@ function VitePluginDecapCMS(options) {
|
|
|
768
704
|
createFileCollection,
|
|
769
705
|
createFolderCollection,
|
|
770
706
|
createOverwriteableField,
|
|
771
|
-
createSharedCollectionOptions,
|
|
772
|
-
fieldToSnakeCase,
|
|
773
707
|
getGitData
|
|
774
708
|
});
|