@monkeyplus/flow 5.0.0-rc.99 → 6.0.1

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.
Files changed (127) hide show
  1. package/README.md +34 -0
  2. package/entry-server.d.ts +1 -0
  3. package/entry-server.mjs +5 -0
  4. package/modules/content/module.d.ts +6 -0
  5. package/modules/content/module.mjs +32 -0
  6. package/modules/content/query.mjs +104 -0
  7. package/modules/sitemap/handler.mjs +17 -0
  8. package/modules/sitemap/module.d.ts +6 -0
  9. package/modules/sitemap/module.mjs +28 -0
  10. package/modules/strapi/README.md +235 -0
  11. package/modules/strapi/module.d.ts +11 -0
  12. package/modules/strapi/module.mjs +69 -0
  13. package/modules/strapi/proxy.mjs +54 -0
  14. package/modules/strapi/runtime/client.d.ts +30 -0
  15. package/modules/strapi/runtime/client.mjs +248 -0
  16. package/package.json +73 -77
  17. package/server/lib/handler.d.ts +1 -0
  18. package/server/lib/handler.mjs +43 -0
  19. package/server/lib/pages.d.ts +20 -0
  20. package/server/lib/pages.mjs +276 -0
  21. package/server/lib/render.d.ts +7 -0
  22. package/server/lib/render.mjs +156 -0
  23. package/server/plugins/00.lifecycle.d.ts +2 -0
  24. package/server/plugins/00.lifecycle.mjs +9 -0
  25. package/server/renderer.d.ts +3 -0
  26. package/server/renderer.mjs +14 -0
  27. package/server/routes/api/health.get.d.ts +2 -0
  28. package/server/routes/api/health.get.mjs +5 -0
  29. package/server.d.ts +1 -0
  30. package/server.mjs +32 -0
  31. package/src/main.d.ts +1 -0
  32. package/src/main.mjs +29 -0
  33. package/src/public/boot.d.ts +1 -0
  34. package/src/public/components.d.ts +1 -0
  35. package/src/public/components.mjs +1 -0
  36. package/src/public/head.d.ts +1 -0
  37. package/src/public/head.mjs +1 -0
  38. package/src/public/index.d.ts +5 -0
  39. package/src/public/index.mjs +2 -0
  40. package/src/public/modules/content.d.ts +2 -0
  41. package/src/public/modules/content.mjs +1 -0
  42. package/src/public/modules/sitemap.d.ts +2 -0
  43. package/src/public/modules/sitemap.mjs +1 -0
  44. package/src/public/modules/strapi.d.ts +2 -0
  45. package/src/public/modules/strapi.mjs +1 -0
  46. package/src/public/nitro.d.ts +6 -0
  47. package/src/public/nitro.mjs +78 -0
  48. package/src/public/shared.d.ts +2 -0
  49. package/src/public/shared.mjs +18 -0
  50. package/src/public/vite.d.ts +6 -0
  51. package/src/public/vite.mjs +273 -0
  52. package/src/public/vue.d.ts +1 -0
  53. package/src/public/vue.mjs +1 -0
  54. package/src/runtime/boot.d.ts +9 -0
  55. package/src/runtime/components/FlowIsland.d.ts +42 -0
  56. package/src/runtime/components/FlowIsland.mjs +35 -0
  57. package/src/runtime/config.d.ts +73 -0
  58. package/src/runtime/config.mjs +26 -0
  59. package/src/runtime/head.d.ts +3 -0
  60. package/src/runtime/head.mjs +7 -0
  61. package/src/runtime/islands.d.ts +2 -0
  62. package/src/runtime/islands.mjs +52 -0
  63. package/src/runtime/modules.d.ts +12 -0
  64. package/src/runtime/modules.mjs +115 -0
  65. package/src/runtime/page-discovery.d.ts +6 -0
  66. package/src/runtime/page-discovery.mjs +175 -0
  67. package/src/runtime/pages.d.ts +107 -0
  68. package/src/runtime/pages.mjs +3 -0
  69. package/src/runtime/ssg.d.ts +9 -0
  70. package/src/runtime/ssg.mjs +37 -0
  71. package/src/runtime/virtual-pages.d.ts +8 -0
  72. package/src/runtime/virtual-pages.mjs +151 -0
  73. package/src/runtime/virtual.d.ts +103 -0
  74. package/src/runtime/vite-assets.d.ts +9 -0
  75. package/src/runtime/vue.d.ts +6 -0
  76. package/src/runtime/vue.mjs +6 -0
  77. package/src/styles.css +1 -0
  78. package/app.d.ts +0 -1
  79. package/bin/flow.mjs +0 -2
  80. package/dist/app/composables/index.d.ts +0 -5
  81. package/dist/app/composables/index.mjs +0 -12
  82. package/dist/app/entry.async.d.ts +0 -3
  83. package/dist/app/entry.async.mjs +0 -1
  84. package/dist/app/entry.d.ts +0 -3
  85. package/dist/app/entry.mjs +0 -23
  86. package/dist/app/flow.d.ts +0 -80
  87. package/dist/app/flow.mjs +0 -88
  88. package/dist/app/index.d.ts +0 -3
  89. package/dist/app/index.mjs +0 -3
  90. package/dist/chunks/dev-bundler.mjs +0 -247
  91. package/dist/chunks/external.mjs +0 -37
  92. package/dist/chunks/index.mjs +0 -1140
  93. package/dist/chunks/vite-node.mjs +0 -155
  94. package/dist/core/runtime/client.manifest.d.mts +0 -2
  95. package/dist/core/runtime/client.manifest.mjs +0 -6
  96. package/dist/core/runtime/nitro/flow.d.ts +0 -3
  97. package/dist/core/runtime/nitro/flow.mjs +0 -33
  98. package/dist/core/runtime/nitro/paths.d.ts +0 -4
  99. package/dist/core/runtime/nitro/paths.mjs +0 -15
  100. package/dist/core/runtime/nitro/renderer.d.ts +0 -2
  101. package/dist/core/runtime/nitro/renderer.mjs +0 -101
  102. package/dist/core/runtime/vite-node-shared.d.mts +0 -1
  103. package/dist/core/runtime/vite-node-shared.d.ts +0 -8
  104. package/dist/core/runtime/vite-node-shared.mjs +0 -3
  105. package/dist/core/runtime/vite-node.d.mts +0 -2
  106. package/dist/core/runtime/vite-node.mjs +0 -42
  107. package/dist/head/runtime/composables.d.ts +0 -9
  108. package/dist/head/runtime/composables.mjs +0 -2
  109. package/dist/head/runtime/index.d.ts +0 -1
  110. package/dist/head/runtime/index.mjs +0 -1
  111. package/dist/head/runtime/plugin.mjs +0 -5
  112. package/dist/index.d.ts +0 -11
  113. package/dist/index.mjs +0 -27
  114. package/dist/pages/runtime/helpers/index.d.ts +0 -5
  115. package/dist/pages/runtime/helpers/index.mjs +0 -31
  116. package/dist/pages/runtime/index.d.ts +0 -10
  117. package/dist/pages/runtime/index.mjs +0 -13
  118. package/dist/pages/runtime/pages.mjs +0 -100
  119. package/dist/vite-client/runtime/injectManifest.d.ts +0 -26
  120. package/dist/vite-client/runtime/injectManifest.mjs +0 -110
  121. package/dist/vite-client/runtime/plugin.mjs +0 -28
  122. package/types.d.ts +0 -2
  123. /package/{dist/head/runtime/plugin.d.ts → modules/content/query.d.ts} +0 -0
  124. /package/{dist/pages/runtime/pages.d.ts → modules/sitemap/handler.d.ts} +0 -0
  125. /package/{dist/vite-client/runtime/plugin.d.ts → modules/strapi/proxy.d.ts} +0 -0
  126. /package/{dist/pages/runtime/helpers/chunks.d.ts → src/public/boot.mjs} +0 -0
  127. /package/{dist/pages/runtime/helpers/chunks.mjs → src/runtime/boot.mjs} +0 -0
@@ -1,155 +0,0 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { createApp, defineEventHandler, defineLazyEventHandler, createError } from 'h3';
3
- import { ViteNodeServer } from 'vite-node/server';
4
- import fse from 'fs-extra';
5
- import { resolve as resolve$1 } from 'pathe';
6
- import { addServerMiddleware } from '@monkeyplus/flow-kit';
7
- import { normalizeViteManifest } from 'vue-bundle-renderer';
8
- import { resolve } from 'mlly';
9
- import { d as distDir } from './index.mjs';
10
- import { c as createIsExternal, i as isCSS } from './external.mjs';
11
- import 'hookable';
12
- import 'url';
13
- import 'unimport';
14
- import 'unplugin';
15
- import 'ufo';
16
- import 'fs';
17
- import 'escape-string-regexp';
18
- import 'scule';
19
- import 'knitwork';
20
- import 'consola';
21
- import 'vite';
22
- import 'perfect-debounce';
23
- import 'node:fs';
24
- import 'nitropack';
25
- import 'defu';
26
- import 'node:module';
27
- import 'chokidar';
28
- import 'untyped';
29
- import '@rollup/plugin-replace';
30
- import 'pkg-types';
31
- import 'ohash';
32
- import 'externality';
33
-
34
- function viteNodePlugin(ctx) {
35
- const invalidates = /* @__PURE__ */ new Set();
36
- return {
37
- name: "nuxt:vite-node-server",
38
- enforce: "post",
39
- configureServer(server) {
40
- server.middlewares.use("/__nuxt_vite_node__", createViteNodeMiddleware(ctx, invalidates));
41
- },
42
- handleHotUpdate({ file, server }) {
43
- function markInvalidate(mod) {
44
- if (invalidates.has(mod.id))
45
- return;
46
- invalidates.add(mod.id);
47
- for (const importer of mod.importers)
48
- markInvalidate(importer);
49
- }
50
- const mods = server.moduleGraph.getModulesByFile(file) || [];
51
- for (const mod of mods)
52
- markInvalidate(mod);
53
- }
54
- };
55
- }
56
- function registerViteNodeMiddleware(ctx) {
57
- addServerMiddleware({
58
- route: "/__nuxt_vite_node__/",
59
- handler: createViteNodeMiddleware(ctx)
60
- });
61
- }
62
- function getManifest(ctx) {
63
- const css = Array.from(ctx.ssrServer.moduleGraph.urlToModuleMap.keys()).filter((i) => isCSS(i));
64
- const manifest = normalizeViteManifest({
65
- "@vite/client": {
66
- file: "@vite/client",
67
- css,
68
- module: true,
69
- isEntry: true
70
- },
71
- [ctx.entry]: {
72
- file: ctx.entry,
73
- isEntry: true,
74
- module: true,
75
- resourceType: "script"
76
- }
77
- });
78
- return manifest;
79
- }
80
- function createViteNodeMiddleware(ctx, invalidates = /* @__PURE__ */ new Set()) {
81
- const app = createApp();
82
- app.use("/manifest", defineEventHandler(() => {
83
- const manifest = getManifest(ctx);
84
- return manifest;
85
- }));
86
- app.use("/invalidates", defineEventHandler(() => {
87
- if (invalidates.size) {
88
- for (const key of ctx.ssrServer.moduleGraph.fileToModulesMap.keys()) {
89
- if (key.startsWith(`${ctx.nuxt.options.appDir}/entry`))
90
- invalidates.add(key);
91
- }
92
- }
93
- const ids = Array.from(invalidates);
94
- invalidates.clear();
95
- return ids;
96
- }));
97
- app.use("/module", defineLazyEventHandler(() => {
98
- const viteServer = ctx.ssrServer;
99
- const node = new ViteNodeServer(viteServer, {
100
- deps: {
101
- inline: [
102
- /\/(nuxt|nuxt3)\//,
103
- /^#/,
104
- ...ctx.nuxt.options.build.transpile
105
- ]
106
- },
107
- transformMode: {
108
- ssr: [/.*/],
109
- web: []
110
- }
111
- });
112
- const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir);
113
- node.shouldExternalize = async (id) => {
114
- const result = await isExternal(id);
115
- if (result?.external)
116
- return resolve(result.id, { url: ctx.nuxt.options.rootDir });
117
- return false;
118
- };
119
- return async (event) => {
120
- const moduleId = decodeURI(event.req.url).substring(1);
121
- if (moduleId === "/")
122
- throw createError({ statusCode: 400 });
123
- const module = await node.fetchModule(moduleId);
124
- return module;
125
- };
126
- }));
127
- return app.nodeHandler;
128
- }
129
- async function initViteNodeServer(ctx) {
130
- let entryPath = resolve$1(ctx.nuxt.options.appDir, "entry.async.mjs");
131
- if (!fse.existsSync(entryPath))
132
- entryPath = resolve$1(ctx.nuxt.options.appDir, "entry.async.ts");
133
- const host = ctx.nuxt.options.server.host || "localhost";
134
- const port = ctx.nuxt.options.server.port || "3000";
135
- const protocol = ctx.nuxt.options.server.https ? "https" : "http";
136
- const viteNodeServerOptions = {
137
- baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`,
138
- root: ctx.nuxt.options.srcDir,
139
- entryPath,
140
- base: ctx.ssrServer.config.base || "/_nuxt/"
141
- };
142
- process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions);
143
- const serverResolvedPath = resolve$1(distDir, "core/runtime/vite-node.mjs");
144
- const manifestResolvedPath = resolve$1(distDir, "core/runtime/client.manifest.mjs");
145
- await fse.writeFile(
146
- resolve$1(ctx.nuxt.options.buildDir, "dist/server/server.mjs"),
147
- `export { default } from ${JSON.stringify(pathToFileURL(serverResolvedPath).href)}`
148
- );
149
- await fse.writeFile(
150
- resolve$1(ctx.nuxt.options.buildDir, "dist/server/client.manifest.mjs"),
151
- `export { default } from ${JSON.stringify(pathToFileURL(manifestResolvedPath).href)}`
152
- );
153
- }
154
-
155
- export { initViteNodeServer, registerViteNodeMiddleware, viteNodePlugin };
@@ -1,2 +0,0 @@
1
- declare function _default(): Promise<any>;
2
- export default _default;
@@ -1,6 +0,0 @@
1
- import { $fetch } from 'ohmyfetch';
2
- import { getViteNodeOptions } from './vite-node-shared.mjs';
3
-
4
- const viteNodeOptions = getViteNodeOptions();
5
-
6
- export default () => $fetch('/manifest', { baseURL: viteNodeOptions.baseURL });
@@ -1,3 +0,0 @@
1
- import 'node-fetch-native/polyfill';
2
- declare const _default: import("h3").EventHandler<void>;
3
- export default _default;
@@ -1,33 +0,0 @@
1
- import "node-fetch-native/polyfill";
2
- import { defineEventHandler } from "h3";
3
- import { defineCachedFunction, useRuntimeConfig } from "#internal/nitro";
4
- const getServerApp = cachedImport(() => import("#server"));
5
- const getFlowRenderer = cachedResult(async () => {
6
- const createFlowApp = await getServerApp();
7
- if (!createFlowApp)
8
- throw new Error("Server bundle is not available");
9
- return createFlowApp(useRuntimeConfig());
10
- });
11
- export default defineEventHandler(async ({ context }) => {
12
- const flow = await getFlowRenderer();
13
- context.flow = flow;
14
- context.render = flow.render;
15
- context.defineCachedFunction = defineCachedFunction;
16
- });
17
- function _interopDefault(e) {
18
- return e && typeof e === "object" && "default" in e ? e.default : e;
19
- }
20
- function cachedImport(importer) {
21
- return cachedResult(() => importer().then(_interopDefault).then(_interopDefault));
22
- }
23
- function cachedResult(fn) {
24
- let res = null;
25
- return () => {
26
- if (res === null)
27
- res = fn().catch((err) => {
28
- res = null;
29
- throw err;
30
- });
31
- return res;
32
- };
33
- }
@@ -1,4 +0,0 @@
1
- export declare function baseURL(): string;
2
- export declare function buildAssetsDir(): string;
3
- export declare function buildAssetsURL(...path: string[]): string;
4
- export declare function publicAssetsURL(...path: string[]): string;
@@ -1,15 +0,0 @@
1
- import { joinURL } from "ufo";
2
- import { useRuntimeConfig } from "#internal/nitro";
3
- export function baseURL() {
4
- return useRuntimeConfig().app.baseURL;
5
- }
6
- export function buildAssetsDir() {
7
- return useRuntimeConfig().app.buildAssetsDir;
8
- }
9
- export function buildAssetsURL(...path) {
10
- return joinURL(publicAssetsURL(), useRuntimeConfig().app.buildAssetsDir, ...path);
11
- }
12
- export function publicAssetsURL(...path) {
13
- const publicBase = useRuntimeConfig().app.cdnURL || useRuntimeConfig().app.baseURL;
14
- return path.length ? joinURL(publicBase, ...path) : publicBase;
15
- }
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<any>;
2
- export default _default;
@@ -1,101 +0,0 @@
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
- export default eventHandler(async (event) => {
9
- const url = event.req.url?.split("?")[0];
10
- const flow = event.context.flow;
11
- if (url.includes("_urls")) {
12
- const urls = await flow.app.utils.getUrls();
13
- return urls;
14
- }
15
- const scripts = { head: [], bodyStart: [], bodyEnd: [] };
16
- const chunks = { head: [], body: [] };
17
- const generate = {};
18
- const { page, locale, params, view, name: pageName } = flow.router.byUrl.lookup(url) || {};
19
- if (!page)
20
- return;
21
- if (view.bundle)
22
- await flow.callHook("page:chunks", view.bundle, chunks);
23
- const templateContext = {};
24
- const dynamic = params?._;
25
- const contextPage = {
26
- chunks,
27
- locale
28
- };
29
- const contextInject = {};
30
- const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value, defineCachedFunction: event.context.defineCachedFunction }, flow.app.utils);
31
- const contextHooks = {};
32
- await flow.callHook("page:context", { localeCode: locale.code, page: pageName }, utils, contextHooks);
33
- templateContext.url = url;
34
- templateContext.baseURL = flow.$config.app.baseURL;
35
- const pageObject = {
36
- name: pageName,
37
- pathname: url,
38
- url: joinURL(flow.site.origin, templateContext.baseURL, `${url}`),
39
- origin: flow.site.origin,
40
- joinOrigin: (_url, includeBase) => joinURL(flow.site.origin, includeBase ? templateContext.baseURL : "/", _url)
41
- };
42
- templateContext.page = pageObject;
43
- contextPage.page = pageObject;
44
- templateContext.locale = locale;
45
- templateContext.view = view;
46
- if (dynamic && page.dynamic) {
47
- const pages = await page.dynamic.method({ locale, utils });
48
- const dynamicPage = pages.find((_page) => _page.url === dynamic);
49
- if (!dynamicPage)
50
- return;
51
- if (page.dynamic.assign)
52
- templateContext[page.dynamic.assign] = dynamicPage.context;
53
- contextPage.dynamic = dynamicPage;
54
- }
55
- templateContext.seo = {};
56
- const sharedContext = await utils.getSharedContext({
57
- ...contextHooks,
58
- ...contextPage,
59
- utils
60
- });
61
- templateContext.sharedContext = sharedContext || {};
62
- templateContext.utils = utils;
63
- templateContext.seo = await normalizeCall(page?.seo, { ...contextHooks, ...contextPage, utils, sharedContext });
64
- const contexData = await page.context?.({ ...contextHooks, ...contextPage, utils, sharedContext }) || {};
65
- templateContext.context = {
66
- ...contextHooks,
67
- ...contexData
68
- };
69
- await flow.callHook("page:scripts", scripts, templateContext);
70
- templateContext.getHeadScripts = () => {
71
- return scripts.head.join("\n");
72
- };
73
- templateContext.getBodyEndScripts = () => {
74
- return scripts.bodyEnd.join("\n");
75
- };
76
- templateContext.getHeadChunks = () => {
77
- return chunks.head.join("\n");
78
- };
79
- templateContext.getBodyChunks = () => {
80
- return chunks.body.join("\n");
81
- };
82
- templateContext.getInjectContext = () => {
83
- return `<script id="__FLOW_DATA__" type="application/json">${JSON.stringify(contextInject)}<\/script>`;
84
- };
85
- const query = useQuery(event);
86
- if (query?.context)
87
- return { ...templateContext, utils: Object.keys(utils) };
88
- let html;
89
- if (view.render)
90
- html = await view.render(templateContext, event);
91
- else
92
- html = await flow.render(view, templateContext);
93
- event.res.setHeader("Content-Type", view.contentType || "text/html;charset=UTF-8");
94
- if (view.postRender)
95
- html = await view.postRender(html, event);
96
- if (flow.generate) {
97
- await flow.callHook("page:generate", generate);
98
- globalThis.generate = generate;
99
- }
100
- return html;
101
- });
@@ -1 +0,0 @@
1
- export function getViteNodeOptions(): any;
@@ -1,8 +0,0 @@
1
- export interface ViteNodeRuntimeOptions {
2
- baseURL: string
3
- rootDir: string
4
- entryPath: string
5
- base: string
6
- }
7
-
8
- export function getViteNodeOptions (): ViteNodeRuntimeOptions;
@@ -1,3 +0,0 @@
1
- export function getViteNodeOptions() {
2
- return JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS || '{}');
3
- }
@@ -1,2 +0,0 @@
1
- declare function _default(ssrContext: any): Promise<any>;
2
- export default _default;
@@ -1,42 +0,0 @@
1
- import { performance } from 'node:perf_hooks';
2
- import { ViteNodeRunner } from 'vite-node/client';
3
- import { $fetch } from 'ohmyfetch';
4
- import consola from 'consola';
5
- import { getViteNodeOptions } from './vite-node-shared.mjs';
6
-
7
- const viteNodeOptions = getViteNodeOptions();
8
- console.log(viteNodeOptions);
9
- const runner = new ViteNodeRunner({
10
- root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
11
- base: viteNodeOptions.base,
12
- async fetchModule(id) {
13
- return await $fetch(`/module/${encodeURI(id)}`, {
14
- baseURL: viteNodeOptions.baseURL,
15
- });
16
- },
17
- });
18
-
19
- let render;
20
-
21
- export default async(ssrContext) => {
22
- // Workaround for stub mode
23
- // https://github.com/nuxt/framework/pull/3983
24
- process.server = true;
25
-
26
- // Invalidate cache for files changed since last rendering
27
- const invalidates = await $fetch('/invalidates', {
28
- baseURL: viteNodeOptions.baseURL,
29
- });
30
- const updates = runner.moduleCache.invalidateDepTree(invalidates);
31
-
32
- // Execute SSR bundle on demand
33
- const start = performance.now();
34
- render = render || (await runner.executeFile(viteNodeOptions.entryPath)).default;
35
- if (updates.size) {
36
- const time = Math.round((performance.now() - start) * 1000) / 1000;
37
- consola.success(`Vite server hmr ${updates.size} files`, time ? `in ${time}ms` : '');
38
- }
39
-
40
- const result = await render(ssrContext);
41
- return result;
42
- };
@@ -1,9 +0,0 @@
1
- import type { MetaObject } from '@monkeyplus/flow-schema';
2
- /**
3
- * You can pass in a meta object, which has keys corresponding to meta tags:
4
- * `title`, `base`, `script`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`.
5
- *
6
- * Alternatively, for reactive meta state, you can pass in a function
7
- * that returns a meta object.
8
- */
9
- export declare function useHead(meta: MetaObject): void;
@@ -1,2 +0,0 @@
1
- export function useHead(meta) {
2
- }
@@ -1 +0,0 @@
1
- export * from './composables';
@@ -1 +0,0 @@
1
- export * from "./composables.mjs";
@@ -1,5 +0,0 @@
1
- import { defineFlowPlugin } from "#app";
2
- export default defineFlowPlugin((flow) => {
3
- flow._useHead = (_meta) => {
4
- };
5
- });
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { FlowOptions, Flow, FlowConfig } from '@monkeyplus/flow-schema';
2
- export { FlowConfig } from '@monkeyplus/flow-schema';
3
- import { LoadFlowOptions } from '@monkeyplus/flow-kit';
4
-
5
- declare function createFlow(options: FlowOptions): Flow;
6
- declare function loadFlow(opts: LoadFlowOptions): Promise<Flow>;
7
- declare function defineFlowConfig(config: FlowConfig): FlowConfig;
8
-
9
- declare function build(flow: Flow): Promise<void>;
10
-
11
- export { build, createFlow, defineFlowConfig, loadFlow };
package/dist/index.mjs DELETED
@@ -1,27 +0,0 @@
1
- export { b as build, c as createFlow, a as defineFlowConfig, l as loadFlow } from './chunks/index.mjs';
2
- import 'hookable';
3
- import 'pathe';
4
- import '@monkeyplus/flow-kit';
5
- import 'url';
6
- import 'unimport';
7
- import 'node:url';
8
- import 'unplugin';
9
- import 'ufo';
10
- import 'fs';
11
- import 'escape-string-regexp';
12
- import 'scule';
13
- import 'knitwork';
14
- import 'fs-extra';
15
- import 'consola';
16
- import 'vite';
17
- import 'perfect-debounce';
18
- import 'node:fs';
19
- import 'nitropack';
20
- import 'defu';
21
- import 'h3';
22
- import 'node:module';
23
- import 'chokidar';
24
- import 'untyped';
25
- import '@rollup/plugin-replace';
26
- import 'mlly';
27
- import 'pkg-types';
@@ -1,5 +0,0 @@
1
- import type { GetPages, PageDefinition } from '@monkeyplus/flow-schema';
2
- export declare function definePage(page: PageDefinition): {
3
- pages: any[];
4
- getPages: GetPages;
5
- };
@@ -1,31 +0,0 @@
1
- import { joinURL, withTrailingSlash } from "ufo";
2
- const buildPages = (page) => (location, language, _locales) => {
3
- const locales = _locales.map((key) => {
4
- const _page = page.locales[key];
5
- return [key, _page];
6
- }).filter((el) => !!el[1]);
7
- return locales.map(([locale, localePage]) => {
8
- const [_language, _location] = locale.split("-");
9
- const name = joinURL("/", _location, _language, page.name);
10
- const defLocation = _location === location ? "" : _location;
11
- const defLanguage = _language === language ? "" : _language;
12
- const url = joinURL("/", defLocation, defLanguage, localePage.url);
13
- const _locale = {
14
- lang: _language,
15
- loc: _location,
16
- code: locale
17
- };
18
- const path = localePage.url.endsWith("/") ? withTrailingSlash(url) : url;
19
- return {
20
- name,
21
- url: path,
22
- context: { page: localePage, locale: _locale, path, view: page.view, name: page.name }
23
- };
24
- });
25
- };
26
- export function definePage(page) {
27
- return {
28
- pages: [],
29
- getPages: buildPages(page)
30
- };
31
- }
@@ -1,10 +0,0 @@
1
- import type { DynamicPage, PageCtx, SimplePage } from '@monkeyplus/flow-schema';
2
- export declare function definePage<T>(...pages: SimplePage<T>[]): SimplePage<T>[];
3
- export declare function defineDynamicPage<T>(...pages: DynamicPage<T>[]): DynamicPage<T>[];
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,13 +0,0 @@
1
- export function definePage(...pages) {
2
- return pages;
3
- }
4
- export function defineDynamicPage(...pages) {
5
- return pages.map((page) => {
6
- if (!page.name.endsWith("/**"))
7
- page.name = `${page.name}/**`;
8
- return page;
9
- });
10
- }
11
- export function defineSharedContext(shared) {
12
- return shared;
13
- }
@@ -1,100 +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(
20
- app.locale.location,
21
- app.locale.language,
22
- app.locale.locales
23
- );
24
- _pages2.forEach((page2) => {
25
- flow.router.byUrl.insert(page2.url, page2.context);
26
- flow.router.byName.insert(page2.name, page2.context);
27
- allPages.push(page2.context);
28
- });
29
- });
30
- });
31
- const cache = {};
32
- async function getUrl(namePage, localeCode) {
33
- const code = localeCode || this?.getLocale()?.code;
34
- const [lang, loc] = code.split("-");
35
- const name = joinURL("/", loc, lang, namePage);
36
- const { path, params, page } = flow.router.byName.lookup(name) || {};
37
- if (params?._ && page.dynamic) {
38
- if (!cache[path]) {
39
- cache[path] = this.defineCachedFunction(async (_ctx) => {
40
- return await page.dynamic.method(_ctx);
41
- }, { maxAge: 8, getKey: () => path, swr: false });
42
- }
43
- const fn = cache[path];
44
- const list = await fn({ utils: this, locale: this.getLocale() });
45
- const dPage = list.find((el) => el.name === params._);
46
- return dPage ? path.replace("**", dPage.url) : "/404";
47
- }
48
- return path || "/404";
49
- }
50
- async function getUrls(withLocale = false) {
51
- const urls = [];
52
- for (const page of allPages) {
53
- if (page.path.includes("/**") && page.page.dynamic) {
54
- const dPages = await page.page.dynamic.method({
55
- locale: page.locale,
56
- utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
57
- chunks: {},
58
- page: {}
59
- });
60
- dPages.forEach((dPage) => {
61
- const _path = joinURL(page.path.replace("/**", ""), dPage.url);
62
- urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
63
- });
64
- } else {
65
- const url = page.path.replaceAll("*", "");
66
- urls.push(withLocale ? { url, locale: page.locale.code, name: page.name } : url);
67
- }
68
- }
69
- return urls.sort();
70
- }
71
- async function getSharedContext(ctx) {
72
- const entries = Object.entries(contexts);
73
- if (!entries.length)
74
- return {};
75
- const _contexts = await Promise.all(entries.map(async ([key, method]) => {
76
- const data = await method.setup(ctx);
77
- const setupLocal = method?.locales?.[ctx.locale.code];
78
- let dataLocal = {};
79
- if (setupLocal)
80
- dataLocal = await setupLocal(ctx);
81
- const obj = method.merge ? { ...data, ...dataLocal } : { [key]: { ...data, ...dataLocal } };
82
- return obj;
83
- }));
84
- return _contexts.reduce((acc, curr) => {
85
- return {
86
- ...acc,
87
- ...curr
88
- };
89
- }, {});
90
- }
91
- flow.setUtil("getUrl", getUrl);
92
- flow.setUtil("getUrls", getUrls);
93
- flow.setUtil("getPages", () => allPages);
94
- flow.setUtil("getSharedContext", getSharedContext);
95
- return {
96
- provide: {
97
- pages: { allPages }
98
- }
99
- };
100
- });
@@ -1,26 +0,0 @@
1
- export declare type Manifest = Record<string, ManifestChunk>;
2
- export interface ManifestChunk {
3
- src?: string;
4
- file: string;
5
- css?: string[];
6
- assets?: string[];
7
- isEntry?: boolean;
8
- isDynamicEntry?: boolean;
9
- imports?: string[];
10
- dynamicImports?: string[];
11
- }
12
- export interface HtmlTagDescriptor {
13
- tag: string;
14
- attrs?: Record<string, string | boolean | undefined>;
15
- children?: string | HtmlTagDescriptor[];
16
- /**
17
- * default: 'head-prepend'
18
- */
19
- injectTo?: 'head' | 'body' | 'head-prepend' | 'body-prepend';
20
- }
21
- export declare const generateBundle: (config: any, bundle: Manifest, _id: string) => {
22
- head: string;
23
- body: string;
24
- };
25
- export declare const externalRE: RegExp;
26
- export declare const isExternalUrl: (url: string) => boolean;