@monkeyplus/flow 6.0.30 → 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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.30",
3
+ "version": "6.0.31",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {