@monkeyplus/flow 6.0.29 → 6.0.31
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/modules/images/cli-pregenerate.d.ts +2 -0
- package/modules/images/cli-pregenerate.mjs +85 -0
- package/modules/images/runtime/build.mjs +5 -0
- package/package.json +1 -1
- package/server/lib/render.mjs +7 -0
- package/src/public/components.d.ts +1 -0
- package/src/public/components.mjs +1 -0
- package/src/runtime/components/MkIcon.d.ts +4 -0
- package/src/runtime/components/MkIcon.mjs +34 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { consola } from "consola";
|
|
5
|
+
import { createJiti } from "jiti";
|
|
6
|
+
import { materializeGeneratedImages } from "./runtime/build.mjs";
|
|
7
|
+
import { screens } from "./runtime/helpers.mjs";
|
|
8
|
+
function withoutTrailingSlash(value) {
|
|
9
|
+
return value.replace(/\/+$/, "");
|
|
10
|
+
}
|
|
11
|
+
function resolveStrapiUrl(flowConfig) {
|
|
12
|
+
const strapi = flowConfig.strapi;
|
|
13
|
+
return typeof strapi?.url === "string" && strapi.url ? withoutTrailingSlash(strapi.url) : void 0;
|
|
14
|
+
}
|
|
15
|
+
function resolveStrapiDomains(flowConfig, dirImages) {
|
|
16
|
+
const strapiUrl = resolveStrapiUrl(flowConfig);
|
|
17
|
+
if (!strapiUrl) return {};
|
|
18
|
+
try {
|
|
19
|
+
const url = new URL(strapiUrl);
|
|
20
|
+
const target = dirImages;
|
|
21
|
+
const values = /* @__PURE__ */ new Set([
|
|
22
|
+
withoutTrailingSlash(url.origin),
|
|
23
|
+
withoutTrailingSlash(url.toString())
|
|
24
|
+
]);
|
|
25
|
+
if (url.pathname && url.pathname !== "/") {
|
|
26
|
+
values.add(withoutTrailingSlash(`${url.origin}${url.pathname}`));
|
|
27
|
+
}
|
|
28
|
+
return [...values].reduce((result, value) => {
|
|
29
|
+
if (value) result[value] = target;
|
|
30
|
+
return result;
|
|
31
|
+
}, {});
|
|
32
|
+
} catch {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function run() {
|
|
37
|
+
const projectRoot = process.cwd();
|
|
38
|
+
const publicDir = resolve(projectRoot, "public");
|
|
39
|
+
const outputDir = publicDir;
|
|
40
|
+
const imagesCacheRoot = resolve(projectRoot, "node_modules/.cache-images");
|
|
41
|
+
const generatedManifestPath = resolve(imagesCacheRoot, "generated-images.jsonl");
|
|
42
|
+
let flowConfig = {};
|
|
43
|
+
try {
|
|
44
|
+
const jiti = createJiti(resolve(projectRoot, "flow.config.ts"), { fsCache: false, moduleCache: false });
|
|
45
|
+
const loaded = jiti(resolve(projectRoot, "flow.config.ts"));
|
|
46
|
+
flowConfig = (loaded?.default ?? loaded) || {};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
consola.warn("No se pudo cargar flow.config.ts, usando valores por defecto.", error.message);
|
|
49
|
+
}
|
|
50
|
+
const userImagesConfig = flowConfig.images || {};
|
|
51
|
+
const dirImages = userImagesConfig.dirImages ?? "/assets/images";
|
|
52
|
+
const resolvedDomains = {
|
|
53
|
+
...resolveStrapiDomains(flowConfig, dirImages),
|
|
54
|
+
...userImagesConfig.domains || {}
|
|
55
|
+
};
|
|
56
|
+
const options = {
|
|
57
|
+
lazy: userImagesConfig.lazy ?? true,
|
|
58
|
+
screens: userImagesConfig.screens ?? screens,
|
|
59
|
+
domains: resolvedDomains,
|
|
60
|
+
presets: userImagesConfig.presets ?? {},
|
|
61
|
+
baseURL: userImagesConfig.baseURL ?? "/_ipx",
|
|
62
|
+
dirImages
|
|
63
|
+
};
|
|
64
|
+
const dirRenames = userImagesConfig.dirRenames ? resolve(projectRoot, userImagesConfig.dirRenames) : resolve(projectRoot, "shared/seo_images");
|
|
65
|
+
const config = {
|
|
66
|
+
dirRenames,
|
|
67
|
+
dirFiles: userImagesConfig.dirFiles || ["images", "media"],
|
|
68
|
+
buildBatchSize: userImagesConfig.buildBatchSize || 8,
|
|
69
|
+
publicDir,
|
|
70
|
+
outputDir,
|
|
71
|
+
generatedManifestPath,
|
|
72
|
+
generate: true,
|
|
73
|
+
netlifyCache: false,
|
|
74
|
+
options
|
|
75
|
+
};
|
|
76
|
+
consola.info("Iniciando generaci\xF3n local de im\xE1genes en la carpeta public...");
|
|
77
|
+
try {
|
|
78
|
+
const result = await materializeGeneratedImages(config);
|
|
79
|
+
consola.success(`[flow:images] Se han generado exitosamente ${result.total} im\xE1genes en public/ (${result.generated} nuevas generadas, ${result.cacheHits} omitidas por cach\xE9).`);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
consola.error("Error al generar las im\xE1genes localmente:", error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
run().catch(console.error);
|
|
@@ -148,6 +148,11 @@ export async function materializeGeneratedImages(config) {
|
|
|
148
148
|
const cachePath = config.generatedCacheDir ? outputFilePath(config.generatedCacheDir, cacheRelativePath) : void 0;
|
|
149
149
|
activeCacheFiles.add(cacheRelativePath);
|
|
150
150
|
await ensureParentDir(outputPath);
|
|
151
|
+
const publicPreGeneratedPath = outputFilePath(config.publicDir, image.generate);
|
|
152
|
+
if (existsSync(publicPreGeneratedPath)) {
|
|
153
|
+
await copyFile(publicPreGeneratedPath, outputPath);
|
|
154
|
+
return { cacheHit: 1, generated: 0 };
|
|
155
|
+
}
|
|
151
156
|
if (config.netlifyCache && cachePath && previousManifest[imageKey]?.signature === signature && existsSync(cachePath)) {
|
|
152
157
|
await copyFile(cachePath, outputPath);
|
|
153
158
|
return { cacheHit: 1, generated: 0 };
|
package/package.json
CHANGED
package/server/lib/render.mjs
CHANGED
|
@@ -133,6 +133,13 @@ async function renderBody(page) {
|
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
135
|
const app = createSSRApp(TemplateRoot);
|
|
136
|
+
app.config.warnHandler = (msg, instance, trace) => {
|
|
137
|
+
const cleanTrace = trace.split("\n").map((line) => {
|
|
138
|
+
return line.length > 200 ? line.substring(0, 200) + " ... >" : line;
|
|
139
|
+
}).join("\n");
|
|
140
|
+
console.warn(`[Vue warn]: ${msg}
|
|
141
|
+
${cleanTrace}`);
|
|
142
|
+
};
|
|
136
143
|
app.provide("context", context);
|
|
137
144
|
app.provide("utils", utils);
|
|
138
145
|
const head = createHead();
|
|
@@ -2,3 +2,4 @@ export { default as FlowIsland } from '../runtime/components/FlowIsland.ts';
|
|
|
2
2
|
export { default as MkImage } from '../runtime/components/MkImage.ts';
|
|
3
3
|
export { default as MkLink } from '../runtime/components/MkLink.ts';
|
|
4
4
|
export { default as MkPicture } from '../runtime/components/MkPicture.ts';
|
|
5
|
+
export { default as MkIcon } from '../runtime/components/MkIcon.ts';
|
|
@@ -2,3 +2,4 @@ export { default as FlowIsland } from "../runtime/components/FlowIsland.mjs";
|
|
|
2
2
|
export { default as MkImage } from "../runtime/components/MkImage.mjs";
|
|
3
3
|
export { default as MkLink } from "../runtime/components/MkLink.mjs";
|
|
4
4
|
export { default as MkPicture } from "../runtime/components/MkPicture.mjs";
|
|
5
|
+
export { default as MkIcon } from "../runtime/components/MkIcon.mjs";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Icon } from "@iconify/vue";
|
|
2
|
+
import { computed, defineComponent, h, Text } from "vue";
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: "MkIcon",
|
|
5
|
+
setup(props, { slots, attrs }) {
|
|
6
|
+
const iconName = computed(() => {
|
|
7
|
+
let name = "";
|
|
8
|
+
try {
|
|
9
|
+
const defaultSlot = slots.default?.();
|
|
10
|
+
if (defaultSlot) {
|
|
11
|
+
for (const vnode of defaultSlot) {
|
|
12
|
+
if (typeof vnode.children === "string") {
|
|
13
|
+
name += vnode.children;
|
|
14
|
+
} else if (vnode.type === Text && typeof vnode.children === "string") {
|
|
15
|
+
name += vnode.children;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} catch (e) {
|
|
20
|
+
name = "";
|
|
21
|
+
}
|
|
22
|
+
return name.trim();
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
if (!iconName.value) {
|
|
26
|
+
return h("span", { ...attrs }, slots.default?.());
|
|
27
|
+
}
|
|
28
|
+
return h(Icon, {
|
|
29
|
+
icon: iconName.value,
|
|
30
|
+
...attrs
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|