@monkeyplus/flow 6.0.16 → 6.0.18
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 +2 -0
- package/cms/server/database/schema.d.ts +648 -0
- package/cms/server/database/schema.mjs +43 -0
- package/cms/server/routes/api/auth/[...auth].d.ts +2 -0
- package/cms/server/routes/api/auth/[...auth].mjs +5 -0
- package/cms/server/routes/api/draft.d.ts +3 -0
- package/cms/server/routes/api/draft.mjs +26 -0
- package/cms/server/routes/api/repos/remote/[repo]/blobs/[file]/index.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/blobs/[file]/index.mjs +20 -0
- package/cms/server/routes/api/repos/remote/[repo]/blobs/index.post.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/blobs/index.post.mjs +8 -0
- package/cms/server/routes/api/repos/remote/[repo]/branches/[branch]/index.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/branches/[branch]/index.mjs +8 -0
- package/cms/server/routes/api/repos/remote/[repo]/commits/index.post.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/commits/index.post.mjs +8 -0
- package/cms/server/routes/api/repos/remote/[repo]/files/[branch]/index.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/files/[branch]/index.mjs +38 -0
- package/cms/server/routes/api/repos/remote/[repo]/files/index.post.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/files/index.post.mjs +8 -0
- package/cms/server/routes/api/repos/remote/[repo]/refs/heads/[branch]/index.patch.d.ts +2 -0
- package/cms/server/routes/api/repos/remote/[repo]/refs/heads/[branch]/index.patch.mjs +9 -0
- package/cms/server/utils/auth.d.ts +3 -0
- package/cms/server/utils/auth.mjs +16 -0
- package/cms/server/utils/db.d.ts +3 -0
- package/cms/server/utils/db.mjs +5 -0
- package/cms/server/utils/github.d.ts +15 -0
- package/cms/server/utils/github.mjs +160 -0
- package/cms/server/utils/github_token.d.ts +71 -0
- package/cms/server/utils/github_token.mjs +377 -0
- package/modules/cms/module.d.ts +11 -0
- package/modules/cms/module.mjs +163 -0
- package/modules/cms/server/api/admin.d.ts +2 -0
- package/modules/cms/server/api/admin.mjs +18 -0
- package/modules/cms/server/api/config.d.ts +2 -0
- package/modules/cms/server/api/config.mjs +88 -0
- package/modules/cms/server/api/localFs.d.ts +2 -0
- package/modules/cms/server/api/localFs.mjs +88 -0
- package/modules/cms/server/api/meta.d.ts +2 -0
- package/modules/cms/server/api/meta.mjs +12 -0
- package/modules/cms/server/lib/composables.d.ts +116 -0
- package/modules/cms/server/lib/composables.mjs +82 -0
- package/modules/cms/server/lib/fs.d.ts +1 -0
- package/modules/cms/server/lib/fs.mjs +18 -0
- package/modules/cms/server/lib/helpers.d.ts +14 -0
- package/modules/cms/server/lib/helpers.mjs +78 -0
- package/modules/cms/server/lib/types.d.ts +120 -0
- package/modules/cms/server/lib/types.mjs +0 -0
- package/modules/cms/server/lib/widgets.d.ts +82 -0
- package/modules/cms/server/lib/widgets.mjs +200 -0
- package/modules/cms/server/trial.d.ts +2 -0
- package/modules/cms/server/trial.mjs +8 -0
- package/modules/content/query.mjs +31 -3
- package/modules/images/ipx.mjs +4 -2
- package/modules/images/module.d.ts +0 -1
- package/modules/images/module.mjs +5 -3
- package/modules/images/runtime/build.mjs +12 -0
- package/modules/images/runtime/image.mjs +4 -3
- package/modules/images/runtime/renames.mjs +59 -8
- package/modules/images/runtime/types.d.ts +27 -4
- package/modules/images/watermark.d.ts +1 -0
- package/modules/images/watermark.mjs +113 -0
- package/modules/netlify-cms/handler.mjs +2 -1
- package/modules/netlify-cms/module.mjs +1 -1
- package/modules/netlify-cms/server/api/config.mjs +25 -1
- package/modules/netlify-cms/server/api/local-fs.d.ts +51 -0
- package/modules/netlify-cms/server/api/local-fs.mjs +81 -77
- package/modules/netlify-cms/server/lib/cms/handler.d.ts +1 -1
- package/modules/netlify-cms/server/lib/cms/handlerV1.d.ts +1 -1
- package/modules/netlify-cms/server/lib/composables.d.ts +8 -0
- package/modules/netlify-cms/server/lib/composables.mjs +2 -1
- package/package.json +2 -2
- package/server/lib/context.d.ts +3 -0
- package/server/lib/context.mjs +5 -0
- package/server/lib/handler.mjs +58 -23
- package/server/lib/pages.d.ts +2 -2
- package/server/lib/pages.mjs +8 -6
- package/server/lib/render.mjs +20 -4
- package/server/plugins/00.lifecycle.mjs +2 -1
- package/src/public/index.d.ts +1 -0
- package/src/public/index.mjs +1 -0
- package/src/public/nitro.mjs +2 -0
- package/src/public/query-content.mjs +9 -2
- package/src/public/shared.d.ts +1 -0
- package/src/public/shared.mjs +3 -0
- package/src/public/vite.mjs +63 -8
- package/src/runtime/components/FlowIsland.mjs +32 -5
- package/src/runtime/components/MkImage.d.ts +100 -22
- package/src/runtime/components/MkImage.mjs +20 -12
- package/src/runtime/components/MkLink.d.ts +8 -5
- package/src/runtime/components/MkLink.mjs +9 -3
- package/src/runtime/components/MkPicture.d.ts +92 -7
- package/src/runtime/components/MkPicture.mjs +8 -2
- package/src/runtime/components/image-shared.d.ts +0 -1
- package/src/runtime/components/image-shared.mjs +9 -18
- package/src/runtime/config.d.ts +6 -15
- package/src/runtime/head.d.ts +2 -1
- package/src/runtime/head.mjs +5 -2
- package/src/runtime/islands.mjs +20 -2
- package/src/runtime/page-discovery.mjs +9 -1
- package/src/runtime/pages.d.ts +14 -13
- package/src/runtime/virtual-pages.mjs +2 -2
- package/src/runtime/vue.mjs +10 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { defineEventHandler, getQuery, readBody } from "nitro/h3";
|
|
5
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
6
|
+
import { listFiles } from "../lib/fs.mjs";
|
|
7
|
+
const baseUrl = "/api/repos/local/";
|
|
8
|
+
export default defineEventHandler(async (event) => {
|
|
9
|
+
const pathname = event.url.pathname.replace(baseUrl, "");
|
|
10
|
+
const config = useRuntimeConfig()?.flow?.cms;
|
|
11
|
+
console.log("runtimeConfig", config);
|
|
12
|
+
const [_repo, command, ...rest] = pathname.split("/");
|
|
13
|
+
if (command === "blobs") {
|
|
14
|
+
const query = getQuery(event);
|
|
15
|
+
if (query.update) {
|
|
16
|
+
const body = await readBody(event);
|
|
17
|
+
const data = Buffer.from(body?.content || "", "base64").toString("utf-8");
|
|
18
|
+
console.log(query.update, config.base);
|
|
19
|
+
const filePath = path.relative(config.base, decodeURIComponent(query.update).trim());
|
|
20
|
+
console.log("updatePath", filePath);
|
|
21
|
+
await fs.writeFile(filePath, data, "utf-8");
|
|
22
|
+
return {
|
|
23
|
+
sha: ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (query.create) {
|
|
27
|
+
const body = await readBody(event);
|
|
28
|
+
let data = Buffer.from(body?.content || "", "base64");
|
|
29
|
+
if (!query.isFile) {
|
|
30
|
+
data = data.toString("utf-8");
|
|
31
|
+
}
|
|
32
|
+
const createPath = decodeURIComponent(query.create);
|
|
33
|
+
const filePath = path.relative(config.base, createPath);
|
|
34
|
+
fs.ensureFileSync(filePath);
|
|
35
|
+
await fs.writeFile(filePath, data, "utf-8");
|
|
36
|
+
return {
|
|
37
|
+
sha: ""
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const [sha] = rest;
|
|
41
|
+
const blobPath = Buffer.from(sha, "base64").toString();
|
|
42
|
+
if (blobPath.endsWith(".json")) {
|
|
43
|
+
const file = await fs.readFile(blobPath, "utf-8");
|
|
44
|
+
return {
|
|
45
|
+
file: {
|
|
46
|
+
encoding: "json",
|
|
47
|
+
content: JSON.parse(file || "{}")
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
const content = await fs.readFile(blobPath);
|
|
52
|
+
return {
|
|
53
|
+
file: {
|
|
54
|
+
encoding: "base64",
|
|
55
|
+
content: Buffer.from(content).toString("base64")
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (command === "branches") {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
if (command === "commits") {
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
if (command === "files") {
|
|
67
|
+
const { folder, file } = getQuery(event);
|
|
68
|
+
if (file) {
|
|
69
|
+
const filePath = path.relative(config.base, decodeURIComponent(file));
|
|
70
|
+
console.log("file", file, config.base, filePath);
|
|
71
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
72
|
+
return {
|
|
73
|
+
content: JSON.parse(content),
|
|
74
|
+
encoding: "json"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const folderPath = path.relative(config.base, folder);
|
|
78
|
+
const files = await listFiles(folderPath, "", 1);
|
|
79
|
+
return { files: files.map((f) => {
|
|
80
|
+
return {
|
|
81
|
+
path: path.basename(f),
|
|
82
|
+
sha: Buffer.from(f).toString("base64")
|
|
83
|
+
};
|
|
84
|
+
}) };
|
|
85
|
+
}
|
|
86
|
+
if (command === "refs") {
|
|
87
|
+
}
|
|
88
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineEventHandler } from "nitro/h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
3
|
+
export default defineEventHandler(async () => {
|
|
4
|
+
const runtimeConfig = useRuntimeConfig();
|
|
5
|
+
return {
|
|
6
|
+
locale: runtimeConfig?.flow?.locale || {},
|
|
7
|
+
base: runtimeConfig?.flow?.cms?.base || "",
|
|
8
|
+
branch: runtimeConfig?.flow?.cms?.branch || "master",
|
|
9
|
+
mediaFolder: runtimeConfig?.flow?.cms?.mediaFolder || "media",
|
|
10
|
+
publicFolder: runtimeConfig?.flow?.cms?.publicFolder || "public"
|
|
11
|
+
};
|
|
12
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { AllCollections } from './helpers';
|
|
2
|
+
import type { CollectionsFiles, CollectionsFolder, DefineMethod } from './types';
|
|
3
|
+
import type { AllWidgets } from './widgets';
|
|
4
|
+
interface Ctx {
|
|
5
|
+
widgets: AllWidgets;
|
|
6
|
+
collections: AllCollections;
|
|
7
|
+
utils: any;
|
|
8
|
+
dir: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OptionsCollectionFiles {
|
|
11
|
+
dir: string;
|
|
12
|
+
preview?: {
|
|
13
|
+
pageName?: string;
|
|
14
|
+
};
|
|
15
|
+
setup: (ctx: Ctx) => (localeDir: string) => DefineMethod<CollectionsFiles>;
|
|
16
|
+
}
|
|
17
|
+
export interface OptionsCollectionFolder {
|
|
18
|
+
dir: string;
|
|
19
|
+
preview?: {
|
|
20
|
+
pageName?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
23
|
+
setup: (ctx: Ctx) => (localeDir: string) => DefineMethod<CollectionsFolder>;
|
|
24
|
+
}
|
|
25
|
+
export declare function defineCmsPage(options: OptionsCollectionFiles): (ctx: Ctx) => (baseDir: string, ctx2: any) => {
|
|
26
|
+
group: string;
|
|
27
|
+
preview: {
|
|
28
|
+
pageName?: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
name: string;
|
|
31
|
+
label: string;
|
|
32
|
+
flow?: {
|
|
33
|
+
url?: string | undefined;
|
|
34
|
+
locale?: any;
|
|
35
|
+
} | undefined;
|
|
36
|
+
options?: {
|
|
37
|
+
[x: string]: any;
|
|
38
|
+
} | undefined;
|
|
39
|
+
extension?: string;
|
|
40
|
+
files: import("./types").CollectionsFile[];
|
|
41
|
+
};
|
|
42
|
+
export declare function defineCmsPages(options: OptionsCollectionFolder): (ctx: Ctx) => (baseDir: string, ctx2: any) => {
|
|
43
|
+
group: string;
|
|
44
|
+
preview: {
|
|
45
|
+
pageName?: string;
|
|
46
|
+
url?: string;
|
|
47
|
+
} | undefined;
|
|
48
|
+
name: string;
|
|
49
|
+
label: string;
|
|
50
|
+
flow?: {
|
|
51
|
+
url?: string | undefined;
|
|
52
|
+
locale?: any;
|
|
53
|
+
} | undefined;
|
|
54
|
+
options?: {
|
|
55
|
+
[x: string]: any;
|
|
56
|
+
} | undefined;
|
|
57
|
+
extension?: string;
|
|
58
|
+
folder: string;
|
|
59
|
+
fields: import("./types").CmsFields[];
|
|
60
|
+
};
|
|
61
|
+
export declare function defineCmsPosts(options: OptionsCollectionFolder): (ctx: Ctx) => (baseDir: string, ctx2: any) => {
|
|
62
|
+
group: string;
|
|
63
|
+
preview: {
|
|
64
|
+
pageName?: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
} | undefined;
|
|
67
|
+
name: string;
|
|
68
|
+
label: string;
|
|
69
|
+
flow?: {
|
|
70
|
+
url?: string | undefined;
|
|
71
|
+
locale?: any;
|
|
72
|
+
} | undefined;
|
|
73
|
+
options?: {
|
|
74
|
+
[x: string]: any;
|
|
75
|
+
} | undefined;
|
|
76
|
+
extension?: string;
|
|
77
|
+
folder: string;
|
|
78
|
+
fields: import("./types").CmsFields[];
|
|
79
|
+
};
|
|
80
|
+
export declare function defineCmsItems(options: OptionsCollectionFolder): (ctx: Ctx) => (baseDir: string, ctx2: any) => {
|
|
81
|
+
group: string;
|
|
82
|
+
preview: {
|
|
83
|
+
pageName?: string;
|
|
84
|
+
url?: string;
|
|
85
|
+
} | undefined;
|
|
86
|
+
name: string;
|
|
87
|
+
label: string;
|
|
88
|
+
flow?: {
|
|
89
|
+
url?: string | undefined;
|
|
90
|
+
locale?: any;
|
|
91
|
+
} | undefined;
|
|
92
|
+
options?: {
|
|
93
|
+
[x: string]: any;
|
|
94
|
+
} | undefined;
|
|
95
|
+
extension?: string;
|
|
96
|
+
folder: string;
|
|
97
|
+
fields: import("./types").CmsFields[];
|
|
98
|
+
};
|
|
99
|
+
export declare function defineCmsSettings(options: OptionsCollectionFiles): (ctx: Ctx) => (baseDir: string, ctx2: any) => {
|
|
100
|
+
group: string;
|
|
101
|
+
preview: {
|
|
102
|
+
pageName?: string;
|
|
103
|
+
} | undefined;
|
|
104
|
+
name: string;
|
|
105
|
+
label: string;
|
|
106
|
+
flow?: {
|
|
107
|
+
url?: string | undefined;
|
|
108
|
+
locale?: any;
|
|
109
|
+
} | undefined;
|
|
110
|
+
options?: {
|
|
111
|
+
[x: string]: any;
|
|
112
|
+
} | undefined;
|
|
113
|
+
extension?: string;
|
|
114
|
+
files: import("./types").CollectionsFile[];
|
|
115
|
+
};
|
|
116
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export function defineCmsPage(options) {
|
|
3
|
+
return (ctx) => {
|
|
4
|
+
const setupFn = options.setup(ctx);
|
|
5
|
+
const group = "pages";
|
|
6
|
+
const collectionFn = setupFn(join(group, options.dir));
|
|
7
|
+
return (baseDir, ctx2) => {
|
|
8
|
+
const collection = collectionFn(baseDir, ctx2);
|
|
9
|
+
return {
|
|
10
|
+
...collection,
|
|
11
|
+
group,
|
|
12
|
+
preview: options.preview
|
|
13
|
+
// injectContext: options.injectContext,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function defineCmsPages(options) {
|
|
19
|
+
return (ctx) => {
|
|
20
|
+
const setupFn = options.setup(ctx);
|
|
21
|
+
const group = "pages";
|
|
22
|
+
const collectionFn = setupFn(join(group, options.dir));
|
|
23
|
+
return (baseDir, ctx2) => {
|
|
24
|
+
const collection = collectionFn(baseDir, ctx2);
|
|
25
|
+
return {
|
|
26
|
+
...collection,
|
|
27
|
+
group,
|
|
28
|
+
preview: options.preview
|
|
29
|
+
// injectContext: options.injectContext,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function defineCmsPosts(options) {
|
|
35
|
+
return (ctx) => {
|
|
36
|
+
const setupFn = options.setup(ctx);
|
|
37
|
+
const group = "posts";
|
|
38
|
+
console.log("preview...", options.preview);
|
|
39
|
+
const collectionFn = setupFn(join(group, options.dir));
|
|
40
|
+
return (baseDir, ctx2) => {
|
|
41
|
+
const collection = collectionFn(baseDir, ctx2);
|
|
42
|
+
return {
|
|
43
|
+
...collection,
|
|
44
|
+
group,
|
|
45
|
+
preview: options.preview
|
|
46
|
+
// injectContext: options.injectContext,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function defineCmsItems(options) {
|
|
52
|
+
return (ctx) => {
|
|
53
|
+
const setupFn = options.setup(ctx);
|
|
54
|
+
const group = "items";
|
|
55
|
+
const collectionFn = setupFn(join(group, options.dir));
|
|
56
|
+
return (baseDir, ctx2) => {
|
|
57
|
+
const collection = collectionFn(baseDir, ctx2);
|
|
58
|
+
return {
|
|
59
|
+
...collection,
|
|
60
|
+
group,
|
|
61
|
+
preview: options.preview
|
|
62
|
+
// injectContext: options.injectContext,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function defineCmsSettings(options) {
|
|
68
|
+
return (ctx) => {
|
|
69
|
+
const setupFn = options.setup(ctx);
|
|
70
|
+
const group = "settings";
|
|
71
|
+
const collectionFn = setupFn(join(group, options.dir));
|
|
72
|
+
return (baseDir, ctx2) => {
|
|
73
|
+
const collection = collectionFn(baseDir, ctx2);
|
|
74
|
+
return {
|
|
75
|
+
...collection,
|
|
76
|
+
group,
|
|
77
|
+
preview: options.preview
|
|
78
|
+
// inject Context: options.injectContext,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listFiles(dir: string, extension: string, depth: number): Promise<string[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export async function listFiles(dir, extension, depth) {
|
|
4
|
+
if (depth <= 0)
|
|
5
|
+
return [];
|
|
6
|
+
try {
|
|
7
|
+
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
|
8
|
+
const files = await Promise.all(
|
|
9
|
+
dirents.map((dirent) => {
|
|
10
|
+
const res = path.join(dir, dirent.name);
|
|
11
|
+
return dirent.isDirectory() ? listFiles(res, extension, depth - 1) : [res].filter((f) => f.endsWith(extension));
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
return [].concat(...files);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CollectionFolderId, Collections_Base, CollectionsFile, CollectionsFolder, DefineCms, DefineMethod, DefineMethodExtend, HelpersCollectionFiles, ModelFields } from './types';
|
|
2
|
+
export declare function mapObjIndexed<T, TResult, TKey extends string>(fn: (value: T, key: TKey, obj?: Record<TKey, T>) => TResult, obj: Record<TKey, T>): Record<TKey, TResult>;
|
|
3
|
+
export declare function collectionFile(base: Omit<Collections_Base, 'name'> & {
|
|
4
|
+
fields: ModelFields;
|
|
5
|
+
}): DefineMethodExtend<CollectionsFile>;
|
|
6
|
+
declare function collectionFolder(base: CollectionFolderId): (dir: string) => DefineMethod<CollectionsFolder>;
|
|
7
|
+
export declare const collections: {
|
|
8
|
+
folder: typeof collectionFolder;
|
|
9
|
+
files: HelpersCollectionFiles;
|
|
10
|
+
file: typeof collectionFile;
|
|
11
|
+
};
|
|
12
|
+
export type AllCollections = typeof collections;
|
|
13
|
+
export declare const defineCms: DefineCms;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function mapObjIndexed(fun, object) {
|
|
3
|
+
return Object.entries(object).reduce((acc, [key, any]) => {
|
|
4
|
+
return {
|
|
5
|
+
...acc,
|
|
6
|
+
[key]: fun(any, key)
|
|
7
|
+
};
|
|
8
|
+
}, {});
|
|
9
|
+
}
|
|
10
|
+
const collectionFiles = (base) => {
|
|
11
|
+
return (dir) => (baseDir, ctx) => {
|
|
12
|
+
const _list = mapObjIndexed((fileBase, name) => {
|
|
13
|
+
return fileBase(name);
|
|
14
|
+
}, base.files);
|
|
15
|
+
const parentDir = path.join(baseDir, dir);
|
|
16
|
+
const files = Object.values(_list).map(
|
|
17
|
+
(file) => file(parentDir, ctx)
|
|
18
|
+
);
|
|
19
|
+
const obj = {
|
|
20
|
+
name: parseName(path.join(dir)),
|
|
21
|
+
...base,
|
|
22
|
+
// description: `${localeDir.toUpperCase()}, `,
|
|
23
|
+
files
|
|
24
|
+
};
|
|
25
|
+
delete obj.id;
|
|
26
|
+
return obj;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
function parseName(name) {
|
|
30
|
+
const preName = name.replace(/\//g, "_");
|
|
31
|
+
return preName.charAt(0) === "_" ? preName.replace("_", "") : preName;
|
|
32
|
+
}
|
|
33
|
+
export function collectionFile(base) {
|
|
34
|
+
return (id) => (dirParent, ctx) => {
|
|
35
|
+
const file = path.join(dirParent, id);
|
|
36
|
+
const _fields = mapObjIndexed((buildField, id2) => {
|
|
37
|
+
return buildField(id2, ctx);
|
|
38
|
+
}, base.fields);
|
|
39
|
+
return {
|
|
40
|
+
name: parseName(path.join(path.basename(dirParent), id)),
|
|
41
|
+
...base,
|
|
42
|
+
file: `${file}.${base.extension ? base.extension : "json"}`,
|
|
43
|
+
fields: Object.values(_fields),
|
|
44
|
+
preview: base.preview
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function collectionFolder(base) {
|
|
49
|
+
return (dir) => (baseDir, ctx) => {
|
|
50
|
+
const _fields = mapObjIndexed((buildField, id) => {
|
|
51
|
+
return buildField(id, ctx);
|
|
52
|
+
}, base.fields);
|
|
53
|
+
const folder = path.join(baseDir, dir);
|
|
54
|
+
const obj = {
|
|
55
|
+
name: parseName(path.join(dir)),
|
|
56
|
+
...base,
|
|
57
|
+
extension: base.extension || "json",
|
|
58
|
+
folder,
|
|
59
|
+
fields: Object.values(_fields),
|
|
60
|
+
preview: base.preview
|
|
61
|
+
// identifier_field: '',
|
|
62
|
+
};
|
|
63
|
+
delete obj.id;
|
|
64
|
+
return obj;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export const collections = {
|
|
68
|
+
folder: collectionFolder,
|
|
69
|
+
files: collectionFiles,
|
|
70
|
+
file: collectionFile
|
|
71
|
+
};
|
|
72
|
+
export const defineCms = (options, _collections) => (dir, ctx) => {
|
|
73
|
+
const collections2 = _collections.map((c) => c(dir, ctx));
|
|
74
|
+
return {
|
|
75
|
+
...options,
|
|
76
|
+
collections: collections2
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widgets
|
|
3
|
+
*/
|
|
4
|
+
interface WidgetBase {
|
|
5
|
+
name: string;
|
|
6
|
+
label: string;
|
|
7
|
+
required?: boolean | undefined;
|
|
8
|
+
options?: {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
} | undefined;
|
|
11
|
+
default?: any;
|
|
12
|
+
hint?: string;
|
|
13
|
+
}
|
|
14
|
+
export type WidgetColor = WidgetBase & {
|
|
15
|
+
widget: 'color';
|
|
16
|
+
};
|
|
17
|
+
export type WidgetBoolean = WidgetBase & {
|
|
18
|
+
widget: 'boolean';
|
|
19
|
+
};
|
|
20
|
+
export type WidgetEditor = WidgetBase & {
|
|
21
|
+
widget: 'editor';
|
|
22
|
+
};
|
|
23
|
+
export type WidgetText = WidgetBase & {
|
|
24
|
+
widget: 'text';
|
|
25
|
+
};
|
|
26
|
+
export type WidgetString = WidgetBase & {
|
|
27
|
+
widget: 'string';
|
|
28
|
+
};
|
|
29
|
+
export type WidgetFile = WidgetBase & {
|
|
30
|
+
widget: 'file';
|
|
31
|
+
};
|
|
32
|
+
export type WidgetSelect = WidgetBase & {
|
|
33
|
+
widget: 'select';
|
|
34
|
+
items: (string | {
|
|
35
|
+
label: string;
|
|
36
|
+
value: string;
|
|
37
|
+
})[];
|
|
38
|
+
searchable?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type WidgetObject = WidgetBase & {
|
|
41
|
+
widget: 'object';
|
|
42
|
+
fields: CmsFields[];
|
|
43
|
+
collapsed?: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type WidgetList = WidgetBase & {
|
|
46
|
+
widget: 'list';
|
|
47
|
+
fields: CmsFields[];
|
|
48
|
+
collapsed?: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type WidgetImage = WidgetBase & {
|
|
51
|
+
widget: 'image';
|
|
52
|
+
mediaFolder?: string;
|
|
53
|
+
};
|
|
54
|
+
export type WidgetDate = WidgetBase & {
|
|
55
|
+
widget: 'date';
|
|
56
|
+
};
|
|
57
|
+
export type WidgetNumber = WidgetBase & {
|
|
58
|
+
widget: 'number';
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* CMS
|
|
62
|
+
*/
|
|
63
|
+
type CmsConfig = any;
|
|
64
|
+
export type CmsFields = WidgetString | WidgetSelect | WidgetText | WidgetBoolean | WidgetList | WidgetObject | WidgetColor | WidgetImage | WidgetDate | WidgetNumber | WidgetEditor | WidgetFile;
|
|
65
|
+
/**
|
|
66
|
+
* COLLECTION
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
export interface Collections_Base {
|
|
70
|
+
name: string;
|
|
71
|
+
label: string;
|
|
72
|
+
flow?: {
|
|
73
|
+
url?: string | undefined;
|
|
74
|
+
locale?: any;
|
|
75
|
+
} | undefined;
|
|
76
|
+
options?: {
|
|
77
|
+
[x: string]: any;
|
|
78
|
+
} | undefined;
|
|
79
|
+
extension?: string;
|
|
80
|
+
preview?: {
|
|
81
|
+
pageName: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export type CollectionsFolder = Collections_Base & {
|
|
85
|
+
folder: string;
|
|
86
|
+
fields: CmsFields[];
|
|
87
|
+
};
|
|
88
|
+
export type CollectionsFiles = Collections_Base & {
|
|
89
|
+
files: CollectionsFile[];
|
|
90
|
+
};
|
|
91
|
+
export interface CollectionsFile {
|
|
92
|
+
fields: CmsFields[];
|
|
93
|
+
label: string;
|
|
94
|
+
name: string;
|
|
95
|
+
file: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ContextWidget {
|
|
98
|
+
rootDir: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* HELPERS
|
|
102
|
+
*/
|
|
103
|
+
export type ModelFields = Record<string, (parentName: string, ctx: ContextWidget) => CmsFields>;
|
|
104
|
+
export type DefineMethod<R> = (parentName: string, ctx: ContextWidget) => R;
|
|
105
|
+
export type DefineCms = (options: Omit<CmsConfig, 'collections'>, collections: DefineMethod<CollectionsFiles | CollectionsFolder>[]) => (dir: string, ctx: ContextWidget) => CmsConfig;
|
|
106
|
+
/**
|
|
107
|
+
* Helpers
|
|
108
|
+
*/
|
|
109
|
+
export type DefineMethodExtend<R> = (id: string) => (parentName: string, ctx: ContextWidget) => R;
|
|
110
|
+
export type DefineFile = Record<string, DefineMethodExtend<CollectionsFile>>;
|
|
111
|
+
export interface CollectionFileId extends Omit<Collections_Base, 'name'> {
|
|
112
|
+
files: DefineFile;
|
|
113
|
+
}
|
|
114
|
+
export interface CollectionFolderId extends Omit<CollectionsFolder, 'name' | 'folder' | 'fields'> {
|
|
115
|
+
fields: ModelFields;
|
|
116
|
+
}
|
|
117
|
+
export interface HelpersCollectionFiles {
|
|
118
|
+
(base: CollectionFileId): (baseDir: string) => DefineMethod<CollectionsFiles>;
|
|
119
|
+
}
|
|
120
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ContextWidget, ModelFields, WidgetBoolean, WidgetColor, WidgetDate, WidgetEditor, WidgetFile, WidgetImage, WidgetList, WidgetNumber, WidgetObject, WidgetSelect, WidgetString, WidgetText } from './types';
|
|
2
|
+
export type BuildWidget<R> = (id: string, ctx: ContextWidget) => R;
|
|
3
|
+
export type WidgetInput<T> = Omit<T, 'widget' | 'name' | 'label'> & {
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Boolean
|
|
8
|
+
*/
|
|
9
|
+
export declare function boolean(options?: Omit<WidgetBoolean, 'widget' | 'name'>): BuildWidget<WidgetBoolean>;
|
|
10
|
+
/**
|
|
11
|
+
* editor
|
|
12
|
+
*/
|
|
13
|
+
export declare function editor(options?: Omit<WidgetEditor, 'widget' | 'name'>): BuildWidget<WidgetEditor>;
|
|
14
|
+
/**
|
|
15
|
+
* Color
|
|
16
|
+
*/
|
|
17
|
+
export declare function color(options?: WidgetInput<WidgetColor>): BuildWidget<WidgetColor>;
|
|
18
|
+
/**
|
|
19
|
+
* DateTime
|
|
20
|
+
*/
|
|
21
|
+
export declare function dateTime(options?: Omit<WidgetDate, 'widget' | 'name'>): BuildWidget<WidgetDate>;
|
|
22
|
+
/**
|
|
23
|
+
* List
|
|
24
|
+
*/
|
|
25
|
+
export declare function list(options: Omit<WidgetList, 'widget' | 'name' | 'fields'> & {
|
|
26
|
+
fields: ModelFields;
|
|
27
|
+
}): BuildWidget<WidgetList>;
|
|
28
|
+
/**
|
|
29
|
+
* Number
|
|
30
|
+
*/
|
|
31
|
+
export declare function number(options: Omit<WidgetNumber, 'widget' | 'name'>): BuildWidget<WidgetNumber>;
|
|
32
|
+
/**
|
|
33
|
+
* Object
|
|
34
|
+
*/
|
|
35
|
+
export declare function object(options: Omit<WidgetObject, 'widget' | 'name' | 'fields'> & {
|
|
36
|
+
fields: ModelFields;
|
|
37
|
+
}): BuildWidget<WidgetObject>;
|
|
38
|
+
/**
|
|
39
|
+
* Select
|
|
40
|
+
*/
|
|
41
|
+
export declare function select(options: Omit<WidgetSelect, 'widget' | 'name'>): BuildWidget<WidgetSelect>;
|
|
42
|
+
/**
|
|
43
|
+
* Text
|
|
44
|
+
*/
|
|
45
|
+
export declare function text(options: Omit<WidgetText, 'widget' | 'name'>): BuildWidget<WidgetText>;
|
|
46
|
+
/**
|
|
47
|
+
* String
|
|
48
|
+
*/
|
|
49
|
+
export declare function string(options?: WidgetInput<WidgetString>): BuildWidget<WidgetString>;
|
|
50
|
+
/**
|
|
51
|
+
* File
|
|
52
|
+
*/
|
|
53
|
+
export declare function file(options?: WidgetInput<WidgetFile>): BuildWidget<WidgetFile>;
|
|
54
|
+
export declare function image(options?: WidgetInput<WidgetImage>): BuildWidget<WidgetImage>;
|
|
55
|
+
/**
|
|
56
|
+
* Image
|
|
57
|
+
*/
|
|
58
|
+
export declare function imageObject(options?: WidgetInput<WidgetImage>): BuildWidget<WidgetObject>;
|
|
59
|
+
/**
|
|
60
|
+
* LinkOrButton
|
|
61
|
+
*/
|
|
62
|
+
export declare function link(options?: WidgetInput<Partial<WidgetObject>>): BuildWidget<WidgetObject>;
|
|
63
|
+
/**
|
|
64
|
+
*****************************************
|
|
65
|
+
*/
|
|
66
|
+
export declare const widgets: {
|
|
67
|
+
string: typeof string;
|
|
68
|
+
color: typeof color;
|
|
69
|
+
number: typeof number;
|
|
70
|
+
file: typeof file;
|
|
71
|
+
dateTime: typeof dateTime;
|
|
72
|
+
image: typeof image;
|
|
73
|
+
editor: typeof editor;
|
|
74
|
+
object: typeof object;
|
|
75
|
+
boolean: typeof boolean;
|
|
76
|
+
list: typeof list;
|
|
77
|
+
text: typeof text;
|
|
78
|
+
select: typeof select;
|
|
79
|
+
imageObject: typeof imageObject;
|
|
80
|
+
link: typeof link;
|
|
81
|
+
};
|
|
82
|
+
export type AllWidgets = typeof widgets;
|