@monkeyplus/flow 6.0.85 → 6.0.87
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.
|
@@ -34,13 +34,13 @@ export default defineFlowModule({
|
|
|
34
34
|
if (!context.nitro.plugins.includes(fetchPluginPath)) {
|
|
35
35
|
context.nitro.plugins.push(fetchPluginPath);
|
|
36
36
|
}
|
|
37
|
-
context.nitro.
|
|
38
|
-
...context.nitro.
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
context.nitro.storage = {
|
|
38
|
+
...context.nitro.storage || {},
|
|
39
|
+
content: {
|
|
40
|
+
driver: "fs",
|
|
41
|
+
base: contentDir
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
};
|
|
44
44
|
context.nitro.runtimeConfig.flow = {
|
|
45
45
|
...typeof context.nitro.runtimeConfig.flow === "object" && context.nitro.runtimeConfig.flow ? context.nitro.runtimeConfig.flow : {},
|
|
46
46
|
content: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
2
|
import { consola } from "consola";
|
|
3
3
|
import { defineEventHandler, getQuery, getRequestURL } from "nitro/h3";
|
|
4
|
+
import { useStorage } from "nitro/storage";
|
|
4
5
|
function normalizeQueryPath(path) {
|
|
5
6
|
if (!path || path === "/") {
|
|
6
7
|
return "/";
|
|
@@ -125,40 +126,57 @@ export async function readContentEntries() {
|
|
|
125
126
|
}
|
|
126
127
|
return entries2;
|
|
127
128
|
};
|
|
129
|
+
const storage = useStorage("content");
|
|
130
|
+
const keys = await storage.getKeys();
|
|
128
131
|
const entries = [];
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
132
|
+
if (keys.length === 0) {
|
|
133
|
+
try {
|
|
134
|
+
const fs = await import("node:fs/promises");
|
|
135
|
+
const path = await import("node:path");
|
|
136
|
+
const contentDir = path.resolve(process.cwd(), "content");
|
|
137
|
+
async function walkDir(dir, baseDir) {
|
|
138
|
+
const files = await fs.readdir(dir, { withFileTypes: true });
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
const res = path.resolve(dir, file.name);
|
|
141
|
+
if (file.isDirectory()) {
|
|
142
|
+
await walkDir(res, baseDir);
|
|
143
|
+
} else {
|
|
144
|
+
const extension = path.extname(res).toLowerCase();
|
|
145
|
+
if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
|
|
146
|
+
const relativePath = path.relative(baseDir, res);
|
|
147
|
+
const normalizedKey = relativePath.replace(/\\/g, "/");
|
|
148
|
+
const raw = await fs.readFile(res, "utf-8");
|
|
149
|
+
const entry = parseContentFile(normalizedKey, raw);
|
|
150
|
+
entries.push(entry);
|
|
151
|
+
}
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
try {
|
|
156
|
+
await fs.access(contentDir);
|
|
157
|
+
await walkDir(contentDir, contentDir);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
}
|
|
160
|
+
const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
161
|
+
return applyCmsPreview(sorted);
|
|
154
162
|
} catch (e) {
|
|
163
|
+
consola.error("[Flow Content] fs fallback failed:", e);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const key of keys) {
|
|
167
|
+
const normalizedKey = key.replace(/:/g, "/");
|
|
168
|
+
const extension = extname(normalizedKey).toLowerCase();
|
|
169
|
+
if (![".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const raw = await storage.getItem(key);
|
|
173
|
+
if (raw !== null && raw !== void 0) {
|
|
174
|
+
const entry = parseContentFile(normalizedKey, raw);
|
|
175
|
+
entries.push(entry);
|
|
155
176
|
}
|
|
156
|
-
const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
157
|
-
return applyCmsPreview(sorted);
|
|
158
|
-
} catch (e) {
|
|
159
|
-
consola.error("[Flow Content] fs reading failed:", e);
|
|
160
177
|
}
|
|
161
|
-
|
|
178
|
+
const sortedEntries = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
179
|
+
return applyCmsPreview(sortedEntries);
|
|
162
180
|
}
|
|
163
181
|
function sortTree(nodes) {
|
|
164
182
|
nodes.sort((left, right) => {
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { definePlugin } from "nitro";
|
|
2
2
|
import { consola } from "consola";
|
|
3
3
|
export default definePlugin((nitroApp) => {
|
|
4
|
-
if (!globalThis.$fetch) {
|
|
5
|
-
globalThis.$fetch = nitroApp.localFetch;
|
|
6
|
-
}
|
|
7
4
|
nitroApp.hooks.hook("request", (event) => {
|
|
8
5
|
const pathname = new URL(event.req.url, "http://localhost").pathname;
|
|
9
6
|
if (!pathname.startsWith("/api/")) {
|
package/src/public/nitro.mjs
CHANGED
|
@@ -36,11 +36,6 @@ export function createFlowNitroConfig(options = {}) {
|
|
|
36
36
|
(nitro) => {
|
|
37
37
|
nitro.hooks.hook("compiled", async (nitro2) => {
|
|
38
38
|
const preset = nitro2?.options?.preset || flowConfig.nitro?.preset || process.env.FLOW_BUILD_PRESET;
|
|
39
|
-
const nitroViteServicesSrc = resolve(nitro2.options.rootDir, "node_modules/.nitro/vite/services");
|
|
40
|
-
const nitroViteServicesDest = resolve(nitro2.options.output.serverDir, ".nitro/vite/services");
|
|
41
|
-
if (existsSync(nitroViteServicesSrc)) {
|
|
42
|
-
await fsp.cp(nitroViteServicesSrc, nitroViteServicesDest, { recursive: true });
|
|
43
|
-
}
|
|
44
39
|
if (preset === "netlify" || process.env.NETLIFY) {
|
|
45
40
|
const customPath = flowConfig.netlify?.path;
|
|
46
41
|
if (customPath) {
|