@monkeyplus/flow 6.0.90 → 6.0.93

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.
@@ -38,7 +38,7 @@ export default defineFlowModule({
38
38
  ...context.nitro.storage || {},
39
39
  content: {
40
40
  driver: "fs",
41
- base: contentDir
41
+ base: `./${options.dir}`
42
42
  }
43
43
  };
44
44
  context.nitro.runtimeConfig.flow = {
@@ -24,5 +24,4 @@ export declare function readContentEntries(): Promise<ContentEntry[]>;
24
24
  export declare function buildContentTree(entries: ContentEntry[]): ContentTreeNode[];
25
25
  export declare function findContentTree(tree: ContentTreeNode[], path?: string): ContentTreeNode[];
26
26
  export declare function processContentQuery(entries: ContentEntry[], query: Record<string, any>, allEntries: ContentEntry[]): ContentEntry[];
27
- declare const _default: any;
28
- export default _default;
27
+ export default function (event: any): Promise<ContentTreeNode[] | ContentEntry[]>;
@@ -1,7 +1,5 @@
1
1
  import { extname } from "node:path";
2
2
  import { consola } from "consola";
3
- import { defineEventHandler, getQuery, getRequestURL } from "nitro/h3";
4
- import { useStorage } from "nitro/storage";
5
3
  function normalizeQueryPath(path) {
6
4
  if (!path || path === "/") {
7
5
  return "/";
@@ -126,57 +124,62 @@ export async function readContentEntries() {
126
124
  }
127
125
  return entries2;
128
126
  };
129
- const storage = useStorage("content");
130
- const keys = await storage.getKeys();
131
127
  const entries = [];
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
- }
152
- }
128
+ try {
129
+ const { useStorage } = await import("nitro/storage");
130
+ const storage = useStorage("content");
131
+ const keys = await storage.getKeys();
132
+ if (keys.length > 0) {
133
+ for (const key of keys) {
134
+ const normalizedKey = key.replace(/:/g, "/");
135
+ const extension = extname(normalizedKey).toLowerCase();
136
+ if (![".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
137
+ continue;
138
+ }
139
+ const raw = await storage.getItem(key);
140
+ if (raw !== null && raw !== void 0) {
141
+ const entry = parseContentFile(normalizedKey, raw);
142
+ entries.push(entry);
153
143
  }
154
144
  }
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);
162
- } catch (e) {
163
- consola.error("[Flow Content] fs fallback failed:", e);
145
+ const sortedEntries = entries.sort((left, right) => left.path.localeCompare(right.path));
146
+ return applyCmsPreview(sortedEntries);
164
147
  }
148
+ } catch (e) {
165
149
  }
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;
150
+ try {
151
+ const fs = await import("node:fs/promises");
152
+ const path = await import("node:path");
153
+ const contentDir = path.resolve(process.cwd(), "content");
154
+ async function walkDir(dir, baseDir) {
155
+ const files = await fs.readdir(dir, { withFileTypes: true });
156
+ for (const file of files) {
157
+ const res = path.resolve(dir, file.name);
158
+ if (file.isDirectory()) {
159
+ await walkDir(res, baseDir);
160
+ } else {
161
+ const extension = path.extname(res).toLowerCase();
162
+ if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
163
+ const relativePath = path.relative(baseDir, res);
164
+ const normalizedKey = relativePath.replace(/\\/g, "/");
165
+ const raw = await fs.readFile(res, "utf-8");
166
+ const entry = parseContentFile(normalizedKey, raw);
167
+ entries.push(entry);
168
+ }
169
+ }
170
+ }
171
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);
172
+ try {
173
+ await fs.access(contentDir);
174
+ await walkDir(contentDir, contentDir);
175
+ } catch (e) {
176
176
  }
177
+ const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
178
+ return applyCmsPreview(sorted);
179
+ } catch (e) {
180
+ consola.error("[Flow Content] fs fallback failed:", e);
177
181
  }
178
- const sortedEntries = entries.sort((left, right) => left.path.localeCompare(right.path));
179
- return applyCmsPreview(sortedEntries);
182
+ return applyCmsPreview(entries);
180
183
  }
181
184
  function sortTree(nodes) {
182
185
  nodes.sort((left, right) => {
@@ -371,7 +374,8 @@ export function processContentQuery(entries, query, allEntries) {
371
374
  }
372
375
  return entries;
373
376
  }
374
- export default defineEventHandler(async (event) => {
377
+ export default async function(event) {
378
+ const { getQuery, getRequestURL } = await import("nitro/h3");
375
379
  const query = getQuery(event);
376
380
  const requestUrl = getRequestURL(event);
377
381
  const isTreeRequest = requestUrl.pathname.endsWith("/tree") || query.tree === true || query.tree === "true" || query.tree === "1";
@@ -385,4 +389,4 @@ export default defineEventHandler(async (event) => {
385
389
  entries = findContentEntries(entries, query.path);
386
390
  }
387
391
  return processContentQuery(entries, query, allEntries);
388
- });
392
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.90",
3
+ "version": "6.0.93",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1,2 +1,3 @@
1
1
  declare const _default: any;
2
2
  export default _default;
3
+ import 'nitro/storage';
@@ -8,3 +8,4 @@ export default definePlugin((nitroApp) => {
8
8
  }
9
9
  });
10
10
  });
11
+ import "nitro/storage";
@@ -48,6 +48,22 @@ export function createFlowNitroConfig(options = {}) {
48
48
  }
49
49
  }
50
50
  }
51
+ const serverDir = nitro2.options.output.serverDir;
52
+ if (serverDir && existsSync(serverDir)) {
53
+ const sourceNitro = resolve(projectRoot, "node_modules/.nitro");
54
+ const destNitro = resolve(serverDir, ".nitro");
55
+ if (existsSync(sourceNitro) && !destNitro.startsWith(sourceNitro)) {
56
+ await fsp.cp(sourceNitro, destNitro, { recursive: true });
57
+ }
58
+ const dirsToCopy = ["content", ...flowConfig.serverCopy || []];
59
+ for (const dirName of dirsToCopy) {
60
+ const sourceDir = resolve(projectRoot, dirName);
61
+ const destDir = resolve(serverDir, dirName);
62
+ if (existsSync(sourceDir)) {
63
+ await fsp.cp(sourceDir, destDir, { recursive: true });
64
+ }
65
+ }
66
+ }
51
67
  });
52
68
  }
53
69
  ],
@@ -51,6 +51,7 @@ export interface FlowConfig {
51
51
  locale: FlowLocaleConfig;
52
52
  images?: Partial<FlowImagesModuleOptions>;
53
53
  server?: FlowServerConfig;
54
+ serverCopy?: string[];
54
55
  siteUrl?: string;
55
56
  nitro?: Record<string, unknown>;
56
57
  netlify?: {
@@ -67,6 +68,7 @@ export type UserFlowConfig = Partial<FlowConfig> & Record<string, unknown> & {
67
68
  images?: Partial<FlowImagesModuleOptions>;
68
69
  cms?: Partial<NetlifyCmsModuleOptions>;
69
70
  server?: FlowServerConfig;
71
+ serverCopy?: string[];
70
72
  siteUrl?: string;
71
73
  components?: Partial<ComponentOptions>;
72
74
  autoImport?: Partial<AutoimportOptions>;
@@ -25,6 +25,7 @@ export function resolveFlowConfig(userFlowConfig = {}) {
25
25
  prefixStrategy: userFlowConfig.locale?.prefixStrategy || "auto",
26
26
  prefixFormat: userFlowConfig.locale?.prefixFormat || "compact"
27
27
  },
28
- server: userFlowConfig.server
28
+ server: userFlowConfig.server,
29
+ serverCopy: userFlowConfig.serverCopy || []
29
30
  };
30
31
  }
Binary file
Binary file
Binary file