@monkeyplus/flow 5.0.0-rc.79 → 5.0.0-rc.8
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/dist/app/flow.d.ts +2 -9
- package/dist/app/flow.mjs +0 -3
- package/dist/core/runtime/nitro/flow.mjs +2 -3
- package/dist/core/runtime/nitro/renderer.mjs +13 -48
- package/dist/index.mjs +56 -97
- package/dist/pages/runtime/helpers/index.mjs +2 -5
- package/dist/pages/runtime/index.d.ts +3 -10
- package/dist/pages/runtime/index.mjs +4 -11
- package/dist/pages/runtime/plugin.mjs +56 -0
- package/dist/vite-client/runtime/injectManifest.mjs +3 -4
- package/dist/vite-client/runtime/plugin.mjs +2 -3
- package/package.json +24 -24
- package/dist/pages/runtime/pages.mjs +0 -96
- /package/dist/pages/runtime/{pages.d.ts → plugin.d.ts} +0 -0
package/dist/app/flow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RadixRouter } from 'radix3';
|
|
2
2
|
import type { Hookable } from 'hookable';
|
|
3
|
-
import type {
|
|
3
|
+
import type { FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
|
|
4
4
|
declare type HookResult = Promise<void> | void;
|
|
5
5
|
export interface FlowAppHooks {
|
|
6
6
|
'flow:pages': (page: FlowPage[]) => HookResult;
|
|
@@ -11,10 +11,6 @@ export interface FlowAppHooks {
|
|
|
11
11
|
bodyStart: string[];
|
|
12
12
|
}) => HookResult;
|
|
13
13
|
'page:links': (links: string[]) => HookResult;
|
|
14
|
-
'page:context': (ctx: {
|
|
15
|
-
page: string;
|
|
16
|
-
localeCode: string;
|
|
17
|
-
}, utils: any, data: Record<string, any>) => HookResult;
|
|
18
14
|
'page:chunks': (bundle: string, scripts: {
|
|
19
15
|
head: string[];
|
|
20
16
|
body: string[];
|
|
@@ -31,14 +27,11 @@ export interface FlowApp {
|
|
|
31
27
|
callHook: FlowApp['hooks']['callHook'];
|
|
32
28
|
eta: any;
|
|
33
29
|
app: {
|
|
34
|
-
utils:
|
|
30
|
+
utils: Record<string, any>;
|
|
35
31
|
plugins: Record<string, any>;
|
|
36
32
|
globals: Record<string, any>;
|
|
37
33
|
};
|
|
38
34
|
engine: string;
|
|
39
|
-
site: {
|
|
40
|
-
origin: string;
|
|
41
|
-
};
|
|
42
35
|
engines: Record<string, (template: string) => string>;
|
|
43
36
|
generate: boolean;
|
|
44
37
|
render: (view: Record<string, string>, data: any) => Promise<string> | void | string;
|
package/dist/app/flow.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "node-fetch-native/polyfill";
|
|
2
1
|
import { defineEventHandler } from "h3";
|
|
3
|
-
import
|
|
2
|
+
import "node-fetch-native/polyfill";
|
|
3
|
+
import { useRuntimeConfig } from "#internal/nitro";
|
|
4
4
|
const getServerApp = cachedImport(() => import("#server"));
|
|
5
5
|
const getFlowRenderer = cachedResult(async () => {
|
|
6
6
|
const createFlowApp = await getServerApp();
|
|
@@ -12,7 +12,6 @@ export default defineEventHandler(async ({ context }) => {
|
|
|
12
12
|
const flow = await getFlowRenderer();
|
|
13
13
|
context.flow = flow;
|
|
14
14
|
context.render = flow.render;
|
|
15
|
-
context.defineCachedFunction = defineCachedFunction;
|
|
16
15
|
});
|
|
17
16
|
function _interopDefault(e) {
|
|
18
17
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { eventHandler, useQuery } from "h3";
|
|
2
|
-
import { joinURL } from "ufo";
|
|
3
|
-
const normalizeCall = async (seo, ctx) => {
|
|
4
|
-
if (typeof seo === "function")
|
|
5
|
-
return await seo(ctx);
|
|
6
|
-
return seo || {};
|
|
7
|
-
};
|
|
8
2
|
export default eventHandler(async (event) => {
|
|
9
3
|
const url = event.req.url?.split("?")[0];
|
|
10
4
|
const flow = event.context.flow;
|
|
@@ -15,58 +9,35 @@ export default eventHandler(async (event) => {
|
|
|
15
9
|
const scripts = { head: [], bodyStart: [], bodyEnd: [] };
|
|
16
10
|
const chunks = { head: [], body: [] };
|
|
17
11
|
const generate = {};
|
|
18
|
-
const { page, locale, params, view
|
|
12
|
+
const { page, locale, params, view } = flow.router.byUrl.lookup(url) || {};
|
|
19
13
|
if (!page)
|
|
20
14
|
return;
|
|
21
15
|
await flow.callHook("page:scripts", scripts);
|
|
22
16
|
if (view.bundle)
|
|
23
17
|
await flow.callHook("page:chunks", view.bundle, chunks);
|
|
24
18
|
const templateContext = {};
|
|
25
|
-
const
|
|
26
|
-
const contextPage = {
|
|
27
|
-
chunks,
|
|
28
|
-
locale
|
|
29
|
-
};
|
|
19
|
+
const dynamyc = params?._;
|
|
20
|
+
const contextPage = {};
|
|
30
21
|
const contextInject = {};
|
|
31
|
-
const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value
|
|
32
|
-
const contextHooks = {};
|
|
33
|
-
await flow.callHook("page:context", { localeCode: locale.code, page: pageName }, utils, contextHooks);
|
|
22
|
+
const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value }, flow.app.utils);
|
|
34
23
|
templateContext.url = url;
|
|
35
|
-
templateContext.baseURL = flow.$config.app.baseURL;
|
|
36
|
-
const pageObject = {
|
|
37
|
-
name: pageName,
|
|
38
|
-
pathname: url,
|
|
39
|
-
url: joinURL(flow.site.origin, templateContext.baseURL, `${url}`),
|
|
40
|
-
origin: flow.site.origin,
|
|
41
|
-
joinOrigin: (_url, includeBase) => joinURL(flow.site.origin, includeBase ? templateContext.baseURL : "/", _url)
|
|
42
|
-
};
|
|
43
|
-
templateContext.page = pageObject;
|
|
44
|
-
contextPage.page = pageObject;
|
|
45
24
|
templateContext.locale = locale;
|
|
46
25
|
templateContext.view = view;
|
|
47
|
-
if (
|
|
26
|
+
if (dynamyc && page.dynamic) {
|
|
48
27
|
const pages = await page.dynamic.method({ locale, utils });
|
|
49
|
-
const dynamicPage = pages.find((_page) => _page.url ===
|
|
28
|
+
const dynamicPage = pages.find((_page) => _page.url === dynamyc);
|
|
50
29
|
if (!dynamicPage)
|
|
51
30
|
return;
|
|
52
31
|
if (page.dynamic.assign)
|
|
53
32
|
templateContext[page.dynamic.assign] = dynamicPage.context;
|
|
54
|
-
contextPage.
|
|
33
|
+
contextPage.dynamyc = dynamicPage;
|
|
55
34
|
}
|
|
56
35
|
templateContext.seo = {};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
...contextPage,
|
|
60
|
-
utils
|
|
61
|
-
});
|
|
62
|
-
templateContext.sharedContext = sharedContext || {};
|
|
36
|
+
templateContext.context = {};
|
|
37
|
+
templateContext.sharedContext = {};
|
|
63
38
|
templateContext.utils = utils;
|
|
64
|
-
templateContext.seo = await
|
|
65
|
-
|
|
66
|
-
templateContext.context = {
|
|
67
|
-
...contextHooks,
|
|
68
|
-
...contexData
|
|
69
|
-
};
|
|
39
|
+
templateContext.seo = await page.seo?.({ ...contextPage, utils }) || {};
|
|
40
|
+
templateContext.context = await page.context?.({ ...contextPage, utils }) || {};
|
|
70
41
|
templateContext.getHeadScripts = () => {
|
|
71
42
|
return scripts.head.join("\n");
|
|
72
43
|
};
|
|
@@ -82,14 +53,8 @@ export default eventHandler(async (event) => {
|
|
|
82
53
|
const query = useQuery(event);
|
|
83
54
|
if (query?.context)
|
|
84
55
|
return { ...templateContext, utils: Object.keys(utils) };
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
html = await view.render(templateContext, event);
|
|
88
|
-
else
|
|
89
|
-
html = await flow.render(view, templateContext);
|
|
90
|
-
event.res.setHeader("Content-Type", view.contentType || "text/html;charset=UTF-8");
|
|
91
|
-
if (view.postRender)
|
|
92
|
-
html = await view.postRender(html, event);
|
|
56
|
+
const html = await flow.render(view, templateContext);
|
|
57
|
+
event.res.setHeader("Content-Type", "text/html;charset=UTF-8");
|
|
93
58
|
if (flow.generate) {
|
|
94
59
|
await flow.callHook("page:generate", generate);
|
|
95
60
|
globalThis.generate = generate;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
2
|
import { dirname, resolve, normalize, join, isAbsolute, relative, extname } from 'pathe';
|
|
3
3
|
import { defineFlowModule, addPlugin, defineNuxtModule, logger, addTemplate, addPluginTemplate, addVitePlugin, useNuxt, resolveAlias, resolveFilesFlow, nuxtCtx, installModule, loadFlowConfig, templateUtils, normalizeTemplate, compileTemplate, normalizePlugin, isIgnoredFlow } from '@monkeyplus/flow-kit';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
5
|
import { defineUnimportPreset, createUnimport, toImports, scanDirExports } from 'unimport';
|
|
6
|
-
import { pathToFileURL } from 'node:url';
|
|
7
6
|
import { createUnplugin } from 'unplugin';
|
|
8
7
|
import { parseURL, parseQuery, joinURL, withoutTrailingSlash } from 'ufo';
|
|
9
|
-
import fs from 'fs';
|
|
10
8
|
import escapeRE from 'escape-string-regexp';
|
|
11
9
|
import { camelCase, pascalCase } from 'scule';
|
|
12
10
|
import { genImport, genDynamicImport, genArrayFromRaw, genString, genObjectFromRawEntries } from 'knitwork';
|
|
@@ -29,7 +27,7 @@ import { isExternal as isExternal$1, ExternalsDefaults } from 'externality';
|
|
|
29
27
|
import { createHash } from 'node:crypto';
|
|
30
28
|
import MagicString from 'magic-string';
|
|
31
29
|
|
|
32
|
-
const version = "5.0.0-rc.
|
|
30
|
+
const version = "5.0.0-rc.8";
|
|
33
31
|
|
|
34
32
|
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
35
33
|
if (_distDir.endsWith("chunks"))
|
|
@@ -94,8 +92,7 @@ const commonPresets = [
|
|
|
94
92
|
from: "#_pages",
|
|
95
93
|
imports: [
|
|
96
94
|
"definePage",
|
|
97
|
-
"
|
|
98
|
-
"defineSharedContext"
|
|
95
|
+
"defineDinamycPage"
|
|
99
96
|
]
|
|
100
97
|
})
|
|
101
98
|
];
|
|
@@ -227,24 +224,18 @@ function addDeclarationTemplates(ctx) {
|
|
|
227
224
|
addTemplate({
|
|
228
225
|
filename: "types/auto-imports.d.ts",
|
|
229
226
|
getContents: () => `// Generated by auto imports
|
|
230
|
-
${ctx.
|
|
227
|
+
${ctx.generateTypeDecarations({ resolvePath: r })}`
|
|
231
228
|
});
|
|
232
229
|
}
|
|
233
230
|
|
|
234
|
-
async function
|
|
231
|
+
async function resolvePagesRoutes() {
|
|
235
232
|
const nuxt = useNuxt();
|
|
236
|
-
const
|
|
237
|
-
const allRoutes = (await Promise.all(
|
|
238
|
-
const files = await resolveFilesFlow(
|
|
233
|
+
const pagesDirs = [...new Set(nuxt.options._layers.map((layer) => resolve(layer.config.srcDir, layer.config.dir?.pages || "pages")))];
|
|
234
|
+
const allRoutes = (await Promise.all(pagesDirs.map(async (dir) => {
|
|
235
|
+
const files = await resolveFilesFlow(dir, `**/*{${nuxt.options.extensions.join(",")}}`);
|
|
239
236
|
files.sort();
|
|
240
|
-
return files.
|
|
241
|
-
|
|
242
|
-
return false;
|
|
243
|
-
if (!fs.readFileSync(file, "utf8").includes("export"))
|
|
244
|
-
return false;
|
|
245
|
-
return true;
|
|
246
|
-
}).map((file) => {
|
|
247
|
-
const segments = relative(dir2, file).replace(new RegExp(`${escapeRE(extname(file))}$`), "").split("/").join("_");
|
|
237
|
+
return files.map((file) => {
|
|
238
|
+
const segments = relative(dir, file).replace(new RegExp(`${escapeRE(extname(file))}$`), "").split("/").join("_");
|
|
248
239
|
return {
|
|
249
240
|
file,
|
|
250
241
|
name: camelCase(segments)
|
|
@@ -253,31 +244,24 @@ async function resolveFiles(dir) {
|
|
|
253
244
|
}))).flat();
|
|
254
245
|
return allRoutes;
|
|
255
246
|
}
|
|
256
|
-
function
|
|
257
|
-
const imports =
|
|
258
|
-
const exports = files.reduce((acc, curr) => {
|
|
259
|
-
const name = curr.name;
|
|
260
|
-
return `${name}:typeof ${name}==='function'?${name}():${name},${acc}`;
|
|
261
|
-
}, "");
|
|
247
|
+
function normalizePages(pages) {
|
|
248
|
+
const imports = pages.map((page) => genImport(page.file, [{ name: "pages", as: page.name }])).join("\n");
|
|
262
249
|
return {
|
|
263
250
|
imports,
|
|
264
|
-
exports
|
|
251
|
+
exports: pages.reduce((acc, curr) => {
|
|
252
|
+
const name = curr.name;
|
|
253
|
+
return `${name}:typeof ${name}==='function'?${name}():${name},${acc}`;
|
|
254
|
+
}, "")
|
|
265
255
|
};
|
|
266
256
|
}
|
|
267
257
|
|
|
268
258
|
const pagesTypeTemplate = {
|
|
269
|
-
filename: "
|
|
259
|
+
filename: "pages.d.ts",
|
|
270
260
|
getContents: ({ options }) => `// Generated by pages discovery
|
|
271
261
|
export {}
|
|
272
262
|
declare global {
|
|
273
|
-
type ArrElement<ArrType> = ArrType extends readonly (infer ElementType)[]
|
|
274
|
-
? ElementType
|
|
275
|
-
: never;
|
|
276
263
|
|
|
277
|
-
${options.pages.map((c) => {
|
|
278
|
-
const _type = `ArrElement<typeof ${genDynamicImport(isAbsolute(c.file) ? relative(join(options.buildDir, "types"), c.file) : c.file, { wrapper: false })}['default']>`;
|
|
279
|
-
return `export type ${pascalCase(c.name)}Context=Awaited<ReturnType<${_type}['locales']['es-ec']['context']>>`;
|
|
280
|
-
}).join("\n")}
|
|
264
|
+
${options.pages.map((c) => `export type ${pascalCase(c.name)}Context=Awaited<ReturnType<typeof ${genDynamicImport(isAbsolute(c.file) ? relative(options.buildDir, c.file) : c.file, { wrapper: false })}['pages']['locales']['es-ec']['context']>>`).join("\n")}
|
|
281
265
|
}
|
|
282
266
|
export const pagesNames: string[]
|
|
283
267
|
`.replaceAll(".ts", "")
|
|
@@ -291,52 +275,37 @@ const pagesModule = defineNuxtModule({
|
|
|
291
275
|
const runtimeDir = resolve(distDir, "pages/runtime");
|
|
292
276
|
flow.options.alias["#_pages"] = runtimeDir;
|
|
293
277
|
const pages = [];
|
|
294
|
-
|
|
295
|
-
|
|
278
|
+
flow.hook("builder:watch", async (event, path) => {
|
|
279
|
+
const dirs = [
|
|
280
|
+
flow.options.dir.pages,
|
|
281
|
+
flow.options.dir.layouts,
|
|
282
|
+
flow.options.dir.middleware
|
|
283
|
+
].filter(Boolean);
|
|
284
|
+
const pathPattern = new RegExp(`^(${dirs.map(escapeRE).join("|")})/`);
|
|
285
|
+
if (event !== "change" && path.match(pathPattern))
|
|
286
|
+
await flow.callHook("builder:generateApp");
|
|
287
|
+
});
|
|
288
|
+
const options = { pages, buildDir: flow.options.buildDir };
|
|
296
289
|
addTemplate({
|
|
297
290
|
...pagesTypeTemplate,
|
|
298
291
|
options
|
|
299
292
|
});
|
|
300
|
-
const pagesDirs = [{ path: resolve(flow.options.srcDir, flow.options.dir.pages) }];
|
|
301
293
|
flow.options.alias["#pages"] = resolve(flow.options.buildDir, "pages.mjs");
|
|
302
|
-
flow.options.alias["#pagesContexts"] = resolve(flow.options.buildDir, "pages.contexts.mjs");
|
|
303
294
|
addTemplate({
|
|
304
295
|
filename: "pages.mjs",
|
|
305
296
|
async getContents({ options: options2 }) {
|
|
306
|
-
const { exports, imports } =
|
|
307
|
-
|
|
308
|
-
return module;
|
|
309
|
-
},
|
|
310
|
-
options
|
|
311
|
-
});
|
|
312
|
-
addTemplate({
|
|
313
|
-
filename: "pages.contexts.mjs",
|
|
314
|
-
async getContents({ options: options2 }) {
|
|
315
|
-
const { exports, imports } = normalizeExports(options2.contexts);
|
|
316
|
-
const module = [imports, `export default {${exports}}`].join("\n");
|
|
317
|
-
return module;
|
|
297
|
+
const { exports, imports } = normalizePages(options2.pages);
|
|
298
|
+
return [imports, `export default {${exports}}`].join("\n");
|
|
318
299
|
},
|
|
319
300
|
options
|
|
320
301
|
});
|
|
321
302
|
flow.hook("app:templates", async () => {
|
|
322
|
-
options.pages = await
|
|
323
|
-
});
|
|
324
|
-
flow.hook("app:templates", async () => {
|
|
325
|
-
options.contexts = await resolveFiles("shared/contexts");
|
|
303
|
+
options.pages = await resolvePagesRoutes();
|
|
326
304
|
});
|
|
327
305
|
flow.hook("prepare:types", ({ references }) => {
|
|
328
|
-
references.push({ path: resolve(flow.options.buildDir, "
|
|
329
|
-
});
|
|
330
|
-
flow.hook("builder:watch", async (event, path) => {
|
|
331
|
-
if (!["add", "unlink", "change"].includes(event))
|
|
332
|
-
return;
|
|
333
|
-
if (path.includes(" copy"))
|
|
334
|
-
return;
|
|
335
|
-
const fPath = resolve(flow.options.rootDir, path);
|
|
336
|
-
if (pagesDirs.find((dir) => fPath.startsWith(dir.path)))
|
|
337
|
-
await flow.callHook("builder:generateApp");
|
|
306
|
+
references.push({ path: resolve(flow.options.buildDir, "pages.d.ts") });
|
|
338
307
|
});
|
|
339
|
-
addPlugin(resolve(runtimeDir, "
|
|
308
|
+
addPlugin({ src: resolve(runtimeDir, "plugin") });
|
|
340
309
|
}
|
|
341
310
|
});
|
|
342
311
|
|
|
@@ -364,7 +333,7 @@ const createClient = async (flow) => {
|
|
|
364
333
|
if (vite)
|
|
365
334
|
vite?.ws?.send({ type: "full-reload" });
|
|
366
335
|
};
|
|
367
|
-
const doReload = debounce(_doReload,
|
|
336
|
+
const doReload = debounce(_doReload, 60);
|
|
368
337
|
flow.hook("bundler:change", () => {
|
|
369
338
|
doReload();
|
|
370
339
|
});
|
|
@@ -375,11 +344,11 @@ const createClient = async (flow) => {
|
|
|
375
344
|
};
|
|
376
345
|
const builClient = async (flow) => {
|
|
377
346
|
return await build$1({
|
|
378
|
-
base: flow.options.dev ? "/" : flow.options.app.baseURL,
|
|
379
347
|
root: flow.options.rootDir,
|
|
380
348
|
mode: "production",
|
|
381
349
|
build: {
|
|
382
|
-
|
|
350
|
+
assetsDir: "scripts",
|
|
351
|
+
target: "es2017",
|
|
383
352
|
outDir: ".vite",
|
|
384
353
|
manifest: true
|
|
385
354
|
}
|
|
@@ -420,27 +389,26 @@ const viteModule = defineFlowModule({
|
|
|
420
389
|
}
|
|
421
390
|
});
|
|
422
391
|
} else {
|
|
423
|
-
|
|
424
|
-
addTemplate({
|
|
425
|
-
filename: "viteManifest.mjs",
|
|
426
|
-
async getContents() {
|
|
427
|
-
return [
|
|
428
|
-
"import fs from 'fs';",
|
|
429
|
-
`export default ()=>{
|
|
430
|
-
const manifest =JSON.parse(fs.readFileSync("${file}", 'utf8'));
|
|
431
|
-
return {manifest,base:'${_options.dir}'}
|
|
432
|
-
}`
|
|
433
|
-
].join("\n");
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
flow.hook("build:before", async () => {
|
|
392
|
+
flow.hook("modules:done", async () => {
|
|
437
393
|
const start = Date.now();
|
|
438
394
|
logger$1.info("Building client...");
|
|
439
395
|
await builClient(flow);
|
|
396
|
+
const file = resolve(flow.options.rootDir, ".vite/manifest.json");
|
|
397
|
+
const manifest = await fse.readFile(file, "utf8");
|
|
440
398
|
logger$1.success(`Client build in ${Date.now() - start}ms`);
|
|
399
|
+
addTemplate({
|
|
400
|
+
filename: "viteManifest.mjs",
|
|
401
|
+
async getContents() {
|
|
402
|
+
return [
|
|
403
|
+
"export default ()=>(",
|
|
404
|
+
manifest,
|
|
405
|
+
")"
|
|
406
|
+
].join("\n");
|
|
407
|
+
}
|
|
408
|
+
});
|
|
441
409
|
});
|
|
442
410
|
flow.hook("generate:before", async () => {
|
|
443
|
-
const files = resolve(flow.options.rootDir, ".vite/
|
|
411
|
+
const files = resolve(flow.options.rootDir, ".vite/scripts");
|
|
444
412
|
await fse.copy(files, resolve(flow.options.generate.dir, "assets"));
|
|
445
413
|
});
|
|
446
414
|
}
|
|
@@ -494,7 +462,6 @@ async function initNitro(flow) {
|
|
|
494
462
|
...flow.options.runtimeConfig,
|
|
495
463
|
app: {
|
|
496
464
|
...flow.options.runtimeConfig.app,
|
|
497
|
-
baseURL: flow.options.dev ? "/" : flow.options.app.baseURL,
|
|
498
465
|
rootDir: flow.options.rootDir,
|
|
499
466
|
locale: flow.options.locale
|
|
500
467
|
},
|
|
@@ -522,8 +489,7 @@ async function initNitro(flow) {
|
|
|
522
489
|
externals: {
|
|
523
490
|
inline: [
|
|
524
491
|
...flow.options.dev ? [] : ["eta", "@monkeyplus/", "@vue/", "@nuxt/", flow.options.buildDir],
|
|
525
|
-
"@monkeyplus/flow/dist"
|
|
526
|
-
"C:/Users/gnu/Documents/GitHub/flow/packages/flow/dist/app"
|
|
492
|
+
"@monkeyplus/flow/dist"
|
|
527
493
|
]
|
|
528
494
|
},
|
|
529
495
|
alias: {
|
|
@@ -534,8 +500,7 @@ async function initNitro(flow) {
|
|
|
534
500
|
...flow.options.alias
|
|
535
501
|
},
|
|
536
502
|
rollupConfig: {
|
|
537
|
-
plugins: []
|
|
538
|
-
external: [""]
|
|
503
|
+
plugins: []
|
|
539
504
|
}
|
|
540
505
|
});
|
|
541
506
|
await flow.callHook("nitro:config", nitroConfig);
|
|
@@ -1127,8 +1092,6 @@ const buildServer = async (ctx) => {
|
|
|
1127
1092
|
"/__vue-jsx",
|
|
1128
1093
|
"#app",
|
|
1129
1094
|
/(nuxt|nuxt3)\/(dist|src|app)/,
|
|
1130
|
-
/flow\/(dist|src|app)/,
|
|
1131
|
-
/flow\/modules\/(content|icons|images|netlify|netlify-cms|seo|sitemap|vue)/,
|
|
1132
1095
|
/@monkeyplus\/flow\/(dist|src|app)/,
|
|
1133
1096
|
/@nuxt\/nitro\/(dist|src)/
|
|
1134
1097
|
]
|
|
@@ -1206,11 +1169,9 @@ const buildServer = async (ctx) => {
|
|
|
1206
1169
|
await onBuild();
|
|
1207
1170
|
ctx.flow.callHook("bundler:change", {});
|
|
1208
1171
|
};
|
|
1209
|
-
const doBuild = debounce(_doBuild
|
|
1172
|
+
const doBuild = debounce(_doBuild);
|
|
1210
1173
|
await _doBuild();
|
|
1211
1174
|
viteServer.watcher.on("all", (_event, file) => {
|
|
1212
|
-
if (file.includes("/pages/"))
|
|
1213
|
-
return;
|
|
1214
1175
|
file = normalize(file);
|
|
1215
1176
|
if (file.indexOf(ctx.flow.options.buildDir) === 0)
|
|
1216
1177
|
return;
|
|
@@ -1330,7 +1291,6 @@ async function bundleVite(flow) {
|
|
|
1330
1291
|
include: []
|
|
1331
1292
|
},
|
|
1332
1293
|
build: {
|
|
1333
|
-
ssr: true,
|
|
1334
1294
|
rollupOptions: {
|
|
1335
1295
|
output: { sanitizeFileName: sanitizeFilePath },
|
|
1336
1296
|
input: resolve(flow.options.appDir, "entry")
|
|
@@ -1367,8 +1327,6 @@ async function bundleVite(flow) {
|
|
|
1367
1327
|
flow.hook("vite:serverCreated", (server) => {
|
|
1368
1328
|
ctx.nuxt.hook("app:templatesGenerated", () => {
|
|
1369
1329
|
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
|
1370
|
-
if (id.includes("pages."))
|
|
1371
|
-
server.moduleGraph.invalidateModule(mod);
|
|
1372
1330
|
if (id.startsWith("\0virtual:"))
|
|
1373
1331
|
server.moduleGraph.invalidateModule(mod);
|
|
1374
1332
|
}
|
|
@@ -1410,7 +1368,8 @@ function watch(flow) {
|
|
|
1410
1368
|
"node_modules"
|
|
1411
1369
|
]
|
|
1412
1370
|
});
|
|
1413
|
-
|
|
1371
|
+
const watchHook = debounce((event, path) => flow.callHook("builder:watch", event, normalize(path)));
|
|
1372
|
+
watcher.on("all", watchHook);
|
|
1414
1373
|
flow.hook("close", () => watcher.close());
|
|
1415
1374
|
return watcher;
|
|
1416
1375
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { joinURL, withTrailingSlash } from "ufo";
|
|
2
|
-
const buildPages = (page) => (location, language
|
|
3
|
-
const locales =
|
|
4
|
-
const _page = page.locales[key];
|
|
5
|
-
return [key, _page];
|
|
6
|
-
}).filter((el) => !!el[1]);
|
|
2
|
+
const buildPages = (page) => (location, language) => {
|
|
3
|
+
const locales = Object.entries(page.locales);
|
|
7
4
|
return locales.map(([locale, localePage]) => {
|
|
8
5
|
const [_language, _location] = locale.split("-");
|
|
9
6
|
const name = joinURL("/", _location, _language, page.name);
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type { DynamicPage,
|
|
2
|
-
export declare function definePage
|
|
3
|
-
export declare function
|
|
4
|
-
export interface SharedContext {
|
|
5
|
-
assign?: 'global' | 'local';
|
|
6
|
-
merge?: boolean;
|
|
7
|
-
setup: (cxt: PageCtx) => any;
|
|
8
|
-
locales?: Record<string, (ctx: PageCtx) => any>;
|
|
9
|
-
}
|
|
10
|
-
export declare function defineSharedContext(shared: SharedContext): SharedContext;
|
|
1
|
+
import type { DynamicPage, SimplePage } from '@monkeyplus/flow-schema';
|
|
2
|
+
export declare function definePage(page: SimplePage): SimplePage;
|
|
3
|
+
export declare function defineDinamycPage(page: DynamicPage): DynamicPage;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
export function definePage(
|
|
2
|
-
return
|
|
1
|
+
export function definePage(page) {
|
|
2
|
+
return page;
|
|
3
3
|
}
|
|
4
|
-
export function
|
|
5
|
-
return
|
|
6
|
-
if (!page.name.endsWith("/**"))
|
|
7
|
-
page.name = `${page.name}/**`;
|
|
8
|
-
return page;
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export function defineSharedContext(shared) {
|
|
12
|
-
return shared;
|
|
4
|
+
export function defineDinamycPage(page) {
|
|
5
|
+
return page;
|
|
13
6
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { joinURL } from "ufo";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { definePage } from "./helpers/index.mjs";
|
|
4
|
+
import { defineFlowPlugin, useRuntimeConfig } from "#app";
|
|
5
|
+
import pages from "#pages";
|
|
6
|
+
export default defineFlowPlugin(async (flow) => {
|
|
7
|
+
const { app } = useRuntimeConfig();
|
|
8
|
+
const allPages = [];
|
|
9
|
+
const basePages = Object.entries(pages);
|
|
10
|
+
consola.success("Parsed %i pages", basePages.length);
|
|
11
|
+
basePages.forEach(([name, page]) => {
|
|
12
|
+
const { getPages } = definePage({
|
|
13
|
+
name,
|
|
14
|
+
...page
|
|
15
|
+
});
|
|
16
|
+
const _pages = getPages(app.locale.location, app.locale.language);
|
|
17
|
+
_pages.forEach((page2) => {
|
|
18
|
+
flow.router.byUrl.insert(page2.url, page2.context);
|
|
19
|
+
flow.router.byName.insert(page2.name, page2.context);
|
|
20
|
+
allPages.push(page2.context);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
function getUrl(namePage, localeCode) {
|
|
24
|
+
const code = localeCode || this?.getLocale()?.code;
|
|
25
|
+
const [lang, loc] = code.split("-");
|
|
26
|
+
const name = joinURL("/", loc, lang, namePage);
|
|
27
|
+
const { path } = flow.router.byName.lookup(name) || {};
|
|
28
|
+
return path || "/404";
|
|
29
|
+
}
|
|
30
|
+
async function getUrls(withLocale = false) {
|
|
31
|
+
const urls = [];
|
|
32
|
+
for (const page of allPages) {
|
|
33
|
+
if (!page.path.includes("/**")) {
|
|
34
|
+
urls.push(withLocale ? { url: page.path, locale: page.locale.code, name: page.name } : page.path);
|
|
35
|
+
} else {
|
|
36
|
+
const dPages = await page.page.dynamic.method({
|
|
37
|
+
locale: page.locale,
|
|
38
|
+
utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils)
|
|
39
|
+
});
|
|
40
|
+
dPages.forEach((dPage) => {
|
|
41
|
+
const _path = joinURL(page.path.replace("/**", ""), dPage.url);
|
|
42
|
+
urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return urls.sort();
|
|
47
|
+
}
|
|
48
|
+
flow.setUtil("getUrl", getUrl);
|
|
49
|
+
flow.setUtil("getUrls", getUrls);
|
|
50
|
+
flow.setUtil("getPages", () => allPages);
|
|
51
|
+
return {
|
|
52
|
+
provide: {
|
|
53
|
+
pages: { allPages }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
});
|
|
@@ -5,8 +5,7 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
5
5
|
const chunks = [];
|
|
6
6
|
chunk2.imports?.forEach((file) => {
|
|
7
7
|
const importee = bundle[file];
|
|
8
|
-
|
|
9
|
-
if (isChunk && !seen.has(file)) {
|
|
8
|
+
if (file.startsWith("_") && !seen.has(file)) {
|
|
10
9
|
seen.add(file);
|
|
11
10
|
chunks.push(...getImportedChunks(importee, seen));
|
|
12
11
|
chunks.push(importee);
|
|
@@ -37,7 +36,7 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
37
36
|
analyzedChunk.set(chunk2, 1);
|
|
38
37
|
chunk2.imports?.forEach((file) => {
|
|
39
38
|
const importee = bundle[file];
|
|
40
|
-
if (file.startsWith("_")
|
|
39
|
+
if (file.startsWith("_"))
|
|
41
40
|
tags.push(...getCssTagsForChunk(importee, publicBase2, seen));
|
|
42
41
|
});
|
|
43
42
|
}
|
|
@@ -72,7 +71,7 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
72
71
|
export const externalRE = /^(https?:)?\/\//;
|
|
73
72
|
export const isExternalUrl = (url) => externalRE.test(url);
|
|
74
73
|
function toPublicPath(filename, publicBase) {
|
|
75
|
-
return isExternalUrl(filename) ? filename : joinURL(publicBase, filename);
|
|
74
|
+
return isExternalUrl(filename) ? filename : joinURL(publicBase, filename.replace("scripts", "assets"));
|
|
76
75
|
}
|
|
77
76
|
const unaryTags = new Set(["link", "meta", "base"]);
|
|
78
77
|
function serializeTag({ tag, attrs, children }, indent = "") {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import logger from "consola";
|
|
2
|
-
import { joinURL } from "ufo";
|
|
3
2
|
import { generateBundle } from "./injectManifest.mjs";
|
|
4
3
|
import { defineFlowPlugin } from "#app";
|
|
5
4
|
import manifest from "#viteManifest";
|
|
6
5
|
export default defineFlowPlugin((flow) => {
|
|
7
6
|
if (typeof manifest === "function") {
|
|
7
|
+
const _manifest = manifest();
|
|
8
8
|
flow.hook("page:chunks", (bundle, chunks) => {
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
11
|
-
const chunk = generateBundle(flow.$config.app || {}, data.manifest, joinURL("/", data.base, `${bundle}.ts`).replace("/", ""));
|
|
10
|
+
const chunk = generateBundle(flow.$config.app || {}, _manifest, `client/pages/${bundle}.ts`);
|
|
12
11
|
if (chunk) {
|
|
13
12
|
chunks.head.push(chunk.head);
|
|
14
13
|
chunks.body.push(chunk.body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkeyplus/flow",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -25,52 +25,52 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@monkeyplus/flow-cli": "5.0.0-rc.
|
|
29
|
-
"@monkeyplus/flow-kit": "5.0.0-rc.
|
|
30
|
-
"@monkeyplus/flow-schema": "5.0.0-rc.
|
|
28
|
+
"@monkeyplus/flow-cli": "5.0.0-rc.8",
|
|
29
|
+
"@monkeyplus/flow-kit": "5.0.0-rc.8",
|
|
30
|
+
"@monkeyplus/flow-schema": "5.0.0-rc.8",
|
|
31
31
|
"@rollup/plugin-replace": "^4.0.0",
|
|
32
32
|
"@vueuse/head": "^0.7.6",
|
|
33
|
-
"c12": "^0.2.
|
|
33
|
+
"c12": "^0.2.7",
|
|
34
34
|
"chokidar": "^3.5.3",
|
|
35
35
|
"consola": "^2.15.3",
|
|
36
36
|
"defu": "^6.0.0",
|
|
37
|
-
"esbuild": "^0.14.
|
|
37
|
+
"esbuild": "^0.14.38",
|
|
38
38
|
"escape-string-regexp": "^5.0.0",
|
|
39
|
-
"esno": "^0.
|
|
39
|
+
"esno": "^0.14.1",
|
|
40
40
|
"eta": "^1.12.3",
|
|
41
|
-
"externality": "^0.2.
|
|
41
|
+
"externality": "^0.2.1",
|
|
42
42
|
"fs-extra": "^10.1.0",
|
|
43
43
|
"get-port-please": "^2.5.0",
|
|
44
|
-
"globby": "^13.1.
|
|
45
|
-
"h3": "^0.7.
|
|
44
|
+
"globby": "^13.1.1",
|
|
45
|
+
"h3": "^0.7.4",
|
|
46
46
|
"hookable": "^5.1.1",
|
|
47
|
-
"jiti": "^1.
|
|
48
|
-
"knitwork": "^0.1.
|
|
49
|
-
"listhen": "^0.2.
|
|
47
|
+
"jiti": "^1.13.0",
|
|
48
|
+
"knitwork": "^0.1.1",
|
|
49
|
+
"listhen": "^0.2.10",
|
|
50
50
|
"magic-string": "^0.26.2",
|
|
51
|
-
"mlly": "^0.5.
|
|
51
|
+
"mlly": "^0.5.2",
|
|
52
52
|
"mri": "^1.2.0",
|
|
53
|
-
"nitropack": "^0.4.
|
|
54
|
-
"pathe": "^0.
|
|
53
|
+
"nitropack": "^0.4.4",
|
|
54
|
+
"pathe": "^0.2.0",
|
|
55
55
|
"perfect-debounce": "^0.1.3",
|
|
56
56
|
"radix3": "^0.1.2",
|
|
57
57
|
"unenv": "^0.5.2",
|
|
58
58
|
"ohmyfetch": "^0.4.18",
|
|
59
|
-
"node-fetch-native": "^0.1.
|
|
60
|
-
"rollup": "^2.
|
|
61
|
-
"rollup-plugin-visualizer": "^5.
|
|
59
|
+
"node-fetch-native": "^0.1.3",
|
|
60
|
+
"rollup": "^2.72.1",
|
|
61
|
+
"rollup-plugin-visualizer": "^5.6.0",
|
|
62
62
|
"scule": "^0.2.1",
|
|
63
|
-
"ufo": "^0.8.
|
|
63
|
+
"ufo": "^0.8.3",
|
|
64
64
|
"unctx": "^1.1.4",
|
|
65
|
-
"unimport": "^0.
|
|
66
|
-
"unplugin": "^0.
|
|
65
|
+
"unimport": "^0.2.1",
|
|
66
|
+
"unplugin": "^0.6.3",
|
|
67
67
|
"untyped": "^0.4.4",
|
|
68
68
|
"vite": "^2.9.9",
|
|
69
|
-
"vue": "^3.2.
|
|
69
|
+
"vue": "^3.2.33"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/fs-extra": "^9.0.13",
|
|
73
|
-
"vue-router": "^4.
|
|
73
|
+
"vue-router": "^4.0.15"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": "^16.11.0 || ^17.0.0 || ^18.0.0"
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { joinURL } from "ufo";
|
|
2
|
-
import consola from "consola";
|
|
3
|
-
import { definePage } from "./helpers/index.mjs";
|
|
4
|
-
import { defineFlowPlugin, useRuntimeConfig } from "#app";
|
|
5
|
-
import pages from "#build/pages";
|
|
6
|
-
import contexts from "#build/pages.contexts";
|
|
7
|
-
export default defineFlowPlugin(async (flow) => {
|
|
8
|
-
const { app } = useRuntimeConfig();
|
|
9
|
-
const allPages = [];
|
|
10
|
-
const basePages = Object.entries(pages);
|
|
11
|
-
consola.success("Parsed %i pages files", basePages.length);
|
|
12
|
-
basePages.forEach(([name, _pages]) => {
|
|
13
|
-
const __pages = Array.isArray(_pages) ? _pages : [_pages];
|
|
14
|
-
__pages.forEach((page) => {
|
|
15
|
-
const { getPages } = definePage({
|
|
16
|
-
name,
|
|
17
|
-
...page
|
|
18
|
-
});
|
|
19
|
-
const _pages2 = getPages(app.locale.location, app.locale.language, app.locale.locales);
|
|
20
|
-
_pages2.forEach((page2) => {
|
|
21
|
-
flow.router.byUrl.insert(page2.url, page2.context);
|
|
22
|
-
flow.router.byName.insert(page2.name, page2.context);
|
|
23
|
-
allPages.push(page2.context);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
const cache = {};
|
|
28
|
-
async function getUrl(namePage, localeCode) {
|
|
29
|
-
const code = localeCode || this?.getLocale()?.code;
|
|
30
|
-
const [lang, loc] = code.split("-");
|
|
31
|
-
const name = joinURL("/", loc, lang, namePage);
|
|
32
|
-
const { path, params, page } = flow.router.byName.lookup(name) || {};
|
|
33
|
-
if (params?._ && page.dynamic) {
|
|
34
|
-
if (!cache[path]) {
|
|
35
|
-
cache[path] = this.defineCachedFunction(async (_ctx) => {
|
|
36
|
-
return await page.dynamic.method(_ctx);
|
|
37
|
-
}, { maxAge: 8, getKey: () => path, swr: false });
|
|
38
|
-
}
|
|
39
|
-
const fn = cache[path];
|
|
40
|
-
const list = await fn({ utils: this, locale: this.getLocale() });
|
|
41
|
-
const dPage = list.find((el) => el.name === params._);
|
|
42
|
-
return dPage ? path.replace("**", dPage.url) : "/404";
|
|
43
|
-
}
|
|
44
|
-
return path || "/404";
|
|
45
|
-
}
|
|
46
|
-
async function getUrls(withLocale = false) {
|
|
47
|
-
const urls = [];
|
|
48
|
-
for (const page of allPages) {
|
|
49
|
-
if (page.path.includes("/**") && page.page.dynamic) {
|
|
50
|
-
const dPages = await page.page.dynamic.method({
|
|
51
|
-
locale: page.locale,
|
|
52
|
-
utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
|
|
53
|
-
chunks: {},
|
|
54
|
-
page: {}
|
|
55
|
-
});
|
|
56
|
-
dPages.forEach((dPage) => {
|
|
57
|
-
const _path = joinURL(page.path.replace("/**", ""), dPage.url);
|
|
58
|
-
urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
|
|
59
|
-
});
|
|
60
|
-
} else {
|
|
61
|
-
const url = page.path.replaceAll("*", "");
|
|
62
|
-
urls.push(withLocale ? { url, locale: page.locale.code, name: page.name } : url);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return urls.sort();
|
|
66
|
-
}
|
|
67
|
-
async function getSharedContext(ctx) {
|
|
68
|
-
const entries = Object.entries(contexts);
|
|
69
|
-
if (!entries.length)
|
|
70
|
-
return {};
|
|
71
|
-
const _contexts = await Promise.all(entries.map(async ([key, method]) => {
|
|
72
|
-
const data = await method.setup(ctx);
|
|
73
|
-
const setupLocal = method?.locales?.[ctx.locale.code];
|
|
74
|
-
let dataLocal = {};
|
|
75
|
-
if (setupLocal)
|
|
76
|
-
dataLocal = await setupLocal(ctx);
|
|
77
|
-
const obj = method.merge ? { ...data, ...dataLocal } : { [key]: { ...data, ...dataLocal } };
|
|
78
|
-
return obj;
|
|
79
|
-
}));
|
|
80
|
-
return _contexts.reduce((acc, curr) => {
|
|
81
|
-
return {
|
|
82
|
-
...acc,
|
|
83
|
-
...curr
|
|
84
|
-
};
|
|
85
|
-
}, {});
|
|
86
|
-
}
|
|
87
|
-
flow.setUtil("getUrl", getUrl);
|
|
88
|
-
flow.setUtil("getUrls", getUrls);
|
|
89
|
-
flow.setUtil("getPages", () => allPages);
|
|
90
|
-
flow.setUtil("getSharedContext", getSharedContext);
|
|
91
|
-
return {
|
|
92
|
-
provide: {
|
|
93
|
-
pages: { allPages }
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
});
|
|
File without changes
|