@monkeyplus/flow 6.0.85 → 6.0.86

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.serverAssets = [
38
- ...context.nitro.serverAssets || [],
39
- {
40
- baseName: "content",
41
- dir: contentDir
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
- try {
130
- const fs = await import("node:fs/promises");
131
- const path = await import("node:path");
132
- const contentDir = path.resolve(process.cwd(), "content");
133
- async function walkDir(dir, baseDir) {
134
- const files = await fs.readdir(dir, { withFileTypes: true });
135
- for (const file of files) {
136
- const res = path.resolve(dir, file.name);
137
- if (file.isDirectory()) {
138
- await walkDir(res, baseDir);
139
- } else {
140
- const extension = path.extname(res).toLowerCase();
141
- if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
142
- const relativePath = path.relative(baseDir, res);
143
- const normalizedKey = relativePath.replace(/\\/g, "/");
144
- const raw = await fs.readFile(res, "utf-8");
145
- const entry = parseContentFile(normalizedKey, raw);
146
- entries.push(entry);
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
- try {
152
- await fs.access(contentDir);
153
- await walkDir(contentDir, contentDir);
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
- return applyCmsPreview(entries);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.85",
3
+ "version": "6.0.86",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -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/")) {