fimo 0.7.0-experimental.1 → 0.7.0-experimental.10
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/assets/content-templates/hooks-template.eta +27 -73
- package/assets/content-templates/types-template.eta +1 -4
- package/assets/skills/fimo/SKILL.md +2 -2
- package/assets/skills/fimo/references/content.md +42 -46
- package/assets/skills/fimo/references/locales.md +0 -8
- package/assets/skills/fimo/references/setup-react-router.md +2 -2
- package/assets/skills/fimo/references/ui.md +1 -1
- package/assets/skills/fimo-cli/references/content.md +14 -17
- package/assets/skills/fimo-cli/references/locales.md +0 -6
- package/assets/skills/fimo-migration/SKILL.md +22 -2
- package/assets/skills/fimo-migration/references/content.md +8 -0
- package/assets/skills/fimo-migration/references/manifest.md +35 -0
- package/assets/skills/fimo-migration/references/qa.md +24 -2
- package/assets/skills/fimo-migration/references/workflow.md +12 -1
- package/assets/skills/fimo-migration/references/wrap.md +617 -0
- package/assets/skills/fimo-studio/references/visual-editing.md +5 -3
- package/dist/build/vite/plugins/translations.d.ts +2 -8
- package/dist/build/vite/plugins/translations.d.ts.map +1 -1
- package/dist/build/vite/plugins/translations.js +3 -121
- package/dist/cli/bundle.json +1 -1
- package/dist/cli/index.js +20655 -12551
- package/dist/runtime/app/FimoProviders.d.ts +1 -11
- package/dist/runtime/app/FimoProviders.d.ts.map +1 -1
- package/dist/runtime/app/FimoProviders.js +2 -23
- package/dist/runtime/astro/index.d.ts +2 -0
- package/dist/runtime/astro/index.d.ts.map +1 -0
- package/dist/runtime/astro/index.js +3 -0
- package/dist/runtime/astro/server.d.ts +3 -0
- package/dist/runtime/astro/server.d.ts.map +1 -0
- package/dist/runtime/astro/server.js +6 -0
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts +0 -1
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts.map +1 -1
- package/dist/runtime/content/utils/retrieve-data-sources.js +4 -27
- package/dist/runtime/i18n/FimoLocaleContext.d.ts.map +1 -1
- package/dist/runtime/i18n/FimoLocaleContext.js +1 -0
- package/dist/runtime/next/FimoNextProviders.d.ts +24 -0
- package/dist/runtime/next/FimoNextProviders.d.ts.map +1 -0
- package/dist/runtime/next/FimoNextProviders.js +20 -0
- package/dist/runtime/next/FimoNextScripts.d.ts +10 -0
- package/dist/runtime/next/FimoNextScripts.d.ts.map +1 -0
- package/dist/runtime/next/FimoNextScripts.js +19 -0
- package/dist/runtime/next/index.d.ts +14 -0
- package/dist/runtime/next/index.d.ts.map +1 -0
- package/dist/runtime/next/index.js +14 -0
- package/dist/runtime/next/server.d.ts +2 -0
- package/dist/runtime/next/server.d.ts.map +1 -0
- package/dist/runtime/next/server.js +4 -0
- package/dist/runtime/nuxt/composables.d.ts +9 -0
- package/dist/runtime/nuxt/composables.d.ts.map +1 -0
- package/dist/runtime/nuxt/composables.js +57 -0
- package/dist/runtime/nuxt/index.d.ts +3 -0
- package/dist/runtime/nuxt/index.d.ts.map +1 -0
- package/dist/runtime/nuxt/index.js +6 -0
- package/dist/runtime/nuxt/server.d.ts +3 -0
- package/dist/runtime/nuxt/server.d.ts.map +1 -0
- package/dist/runtime/nuxt/server.js +6 -0
- package/dist/runtime/paths/get-fimo-paths.d.ts.map +1 -1
- package/dist/runtime/paths/get-fimo-paths.js +5 -15
- package/dist/runtime/primitives/labels-hook.d.ts +33 -0
- package/dist/runtime/primitives/labels-hook.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-hook.js +41 -0
- package/dist/runtime/primitives/labels-store.d.ts +12 -0
- package/dist/runtime/primitives/labels-store.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-store.js +60 -0
- package/dist/runtime/primitives/labels-store.test.d.ts +2 -0
- package/dist/runtime/primitives/labels-store.test.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-store.test.js +66 -0
- package/dist/runtime/primitives/lib/primitives.d.ts +2 -2
- package/dist/runtime/primitives/lib/primitives.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/query.d.ts +3 -5
- package/dist/runtime/primitives/lib/query.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/useFimoLiveValue.d.ts +5 -3
- package/dist/runtime/primitives/lib/useFimoLiveValue.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/useFimoLiveValue.js +11 -4
- package/dist/runtime/primitives/public-surface.test.js +5 -9
- package/dist/runtime/primitives/translations.d.ts +1 -27
- package/dist/runtime/primitives/translations.d.ts.map +1 -1
- package/dist/runtime/primitives/translations.js +7 -85
- package/dist/runtime/react/FimoSpaProviders.d.ts +36 -0
- package/dist/runtime/react/FimoSpaProviders.d.ts.map +1 -0
- package/dist/runtime/react/FimoSpaProviders.js +63 -0
- package/dist/runtime/react/index.d.ts +33 -0
- package/dist/runtime/react/index.d.ts.map +1 -0
- package/dist/runtime/react/index.js +39 -0
- package/dist/runtime/remix/FimoRemixProviders.d.ts +16 -0
- package/dist/runtime/remix/FimoRemixProviders.d.ts.map +1 -0
- package/dist/runtime/remix/FimoRemixProviders.js +12 -0
- package/dist/runtime/remix/FimoRemixScripts.d.ts +10 -0
- package/dist/runtime/remix/FimoRemixScripts.d.ts.map +1 -0
- package/dist/runtime/remix/FimoRemixScripts.js +19 -0
- package/dist/runtime/remix/index.d.ts +12 -0
- package/dist/runtime/remix/index.d.ts.map +1 -0
- package/dist/runtime/remix/index.js +11 -0
- package/dist/runtime/remix/server.d.ts +2 -0
- package/dist/runtime/remix/server.d.ts.map +1 -0
- package/dist/runtime/remix/server.js +2 -0
- package/dist/runtime/seo/buildSeoForPath.d.ts +3 -1
- package/dist/runtime/seo/buildSeoForPath.d.ts.map +1 -1
- package/dist/runtime/seo/buildSeoForPath.js +1 -4
- package/dist/runtime/shared/display-routes.d.ts +14 -0
- package/dist/runtime/shared/display-routes.d.ts.map +1 -0
- package/dist/runtime/shared/display-routes.js +25 -0
- package/dist/runtime/shared/fimo-config.server.d.ts.map +1 -1
- package/dist/runtime/shared/fimo-config.server.js +1 -0
- package/dist/runtime/shared/fimo-config.types.d.ts +2 -0
- package/dist/runtime/shared/fimo-config.types.d.ts.map +1 -1
- package/dist/runtime/shared/i18n-messages.d.ts +29 -0
- package/dist/runtime/shared/i18n-messages.d.ts.map +1 -0
- package/dist/runtime/shared/i18n-messages.js +79 -0
- package/dist/runtime/shared/i18n-messages.test.d.ts +2 -0
- package/dist/runtime/shared/i18n-messages.test.d.ts.map +1 -0
- package/dist/runtime/shared/i18n-messages.test.js +39 -0
- package/dist/runtime/shared/labels-fetch.pure.d.ts +17 -0
- package/dist/runtime/shared/labels-fetch.pure.d.ts.map +1 -0
- package/dist/runtime/shared/labels-fetch.pure.js +71 -0
- package/dist/runtime/shared/labels-fetch.server.d.ts +7 -0
- package/dist/runtime/shared/labels-fetch.server.d.ts.map +1 -0
- package/dist/runtime/shared/labels-fetch.server.js +97 -0
- package/dist/runtime/shared/labels-t.pure.d.ts +2 -0
- package/dist/runtime/shared/labels-t.pure.d.ts.map +1 -0
- package/dist/runtime/shared/labels-t.pure.js +10 -0
- package/dist/runtime/strapi/client.d.ts +26 -0
- package/dist/runtime/strapi/client.d.ts.map +1 -0
- package/dist/runtime/strapi/client.js +88 -0
- package/dist/runtime/strapi/client.test.d.ts +2 -0
- package/dist/runtime/strapi/client.test.d.ts.map +1 -0
- package/dist/runtime/strapi/client.test.js +64 -0
- package/dist/runtime/strapi/index.d.ts +5 -0
- package/dist/runtime/strapi/index.d.ts.map +1 -0
- package/dist/runtime/strapi/index.js +6 -0
- package/dist/runtime/strapi/reshape.d.ts +28 -0
- package/dist/runtime/strapi/reshape.d.ts.map +1 -0
- package/dist/runtime/strapi/reshape.js +79 -0
- package/dist/runtime/strapi/reshape.test.d.ts +2 -0
- package/dist/runtime/strapi/reshape.test.d.ts.map +1 -0
- package/dist/runtime/strapi/reshape.test.js +33 -0
- package/dist/runtime/svelte/index.d.ts +3 -0
- package/dist/runtime/svelte/index.d.ts.map +1 -0
- package/dist/runtime/svelte/index.js +7 -0
- package/dist/runtime/svelte/server.d.ts +3 -0
- package/dist/runtime/svelte/server.d.ts.map +1 -0
- package/dist/runtime/svelte/server.js +6 -0
- package/dist/runtime/vue/index.d.ts +3 -0
- package/dist/runtime/vue/index.d.ts.map +1 -0
- package/dist/runtime/vue/index.js +5 -0
- package/dist/runtime/vue/server.d.ts +3 -0
- package/dist/runtime/vue/server.d.ts.map +1 -0
- package/dist/runtime/vue/server.js +6 -0
- package/dist/runtime/wrapped/FimoFileLink.d.ts +17 -0
- package/dist/runtime/wrapped/FimoFileLink.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoFileLink.js +19 -0
- package/dist/runtime/wrapped/FimoMediaImage.d.ts +14 -0
- package/dist/runtime/wrapped/FimoMediaImage.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoMediaImage.js +20 -0
- package/dist/runtime/wrapped/FimoMediaVideo.d.ts +14 -0
- package/dist/runtime/wrapped/FimoMediaVideo.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoMediaVideo.js +20 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.d.ts +23 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.js +22 -0
- package/dist/runtime/wrapped/FimoText.d.ts +22 -0
- package/dist/runtime/wrapped/FimoText.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoText.js +20 -0
- package/dist/runtime/wrapped/WrappedContentContext.d.ts +28 -0
- package/dist/runtime/wrapped/WrappedContentContext.d.ts.map +1 -0
- package/dist/runtime/wrapped/WrappedContentContext.js +30 -0
- package/dist/runtime/wrapped/WrappedProviders.d.ts +33 -0
- package/dist/runtime/wrapped/WrappedProviders.d.ts.map +1 -0
- package/dist/runtime/wrapped/WrappedProviders.js +101 -0
- package/dist/runtime/wrapped/dom.d.ts +4 -0
- package/dist/runtime/wrapped/dom.d.ts.map +1 -0
- package/dist/runtime/wrapped/dom.js +23 -0
- package/dist/runtime/wrapped/dom.test.d.ts +2 -0
- package/dist/runtime/wrapped/dom.test.d.ts.map +1 -0
- package/dist/runtime/wrapped/dom.test.js +16 -0
- package/dist/runtime/wrapped/server.d.ts +77 -0
- package/dist/runtime/wrapped/server.d.ts.map +1 -0
- package/dist/runtime/wrapped/server.js +237 -0
- package/dist/runtime/wrapped/server.test.d.ts +2 -0
- package/dist/runtime/wrapped/server.test.d.ts.map +1 -0
- package/dist/runtime/wrapped/server.test.js +91 -0
- package/dist/scripts/apply-wrap-templates.d.ts +61 -0
- package/dist/scripts/apply-wrap-templates.js +132 -0
- package/dist/scripts/apply-wrap-templates.test.d.ts +1 -0
- package/dist/scripts/apply-wrap-templates.test.js +199 -0
- package/dist/scripts/apply-wrap.d.ts +46 -0
- package/dist/scripts/apply-wrap.js +278 -0
- package/dist/scripts/apply-wrap.test.d.ts +1 -0
- package/dist/scripts/apply-wrap.test.js +226 -0
- package/dist/scripts/cms/discover.d.ts +2 -0
- package/dist/scripts/cms/discover.js +17 -0
- package/dist/scripts/cms/example-content.d.ts +32 -0
- package/dist/scripts/cms/example-content.js +108 -0
- package/dist/scripts/cms/example-content.test.d.ts +1 -0
- package/dist/scripts/cms/example-content.test.js +66 -0
- package/dist/scripts/cms/strapi/detect.d.ts +2 -0
- package/dist/scripts/cms/strapi/detect.js +186 -0
- package/dist/scripts/cms/strapi/detect.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/detect.test.js +56 -0
- package/dist/scripts/cms/strapi/index.d.ts +3 -0
- package/dist/scripts/cms/strapi/index.js +25 -0
- package/dist/scripts/cms/strapi/list-source.d.ts +17 -0
- package/dist/scripts/cms/strapi/list-source.js +90 -0
- package/dist/scripts/cms/strapi/list-source.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/list-source.test.js +33 -0
- package/dist/scripts/cms/strapi/schema-map.d.ts +9 -0
- package/dist/scripts/cms/strapi/schema-map.js +149 -0
- package/dist/scripts/cms/strapi/schema-map.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/schema-map.test.js +91 -0
- package/dist/scripts/cms/strapi/touchpoints.d.ts +31 -0
- package/dist/scripts/cms/strapi/touchpoints.js +145 -0
- package/dist/scripts/cms/strapi/touchpoints.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/touchpoints.test.js +62 -0
- package/dist/scripts/cms/strapi/wire-client.d.ts +15 -0
- package/dist/scripts/cms/strapi/wire-client.js +107 -0
- package/dist/scripts/cms/strapi/wire-client.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/wire-client.test.js +51 -0
- package/dist/scripts/cms/strapi/wiring.d.ts +17 -0
- package/dist/scripts/cms/strapi/wiring.js +36 -0
- package/dist/scripts/cms/strapi/wiring.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/wiring.test.js +27 -0
- package/dist/scripts/cms/types.d.ts +117 -0
- package/dist/scripts/cms/types.js +11 -0
- package/dist/scripts/detect-framework.d.ts +39 -0
- package/dist/scripts/detect-framework.js +133 -0
- package/dist/scripts/detect-framework.test.d.ts +1 -0
- package/dist/scripts/detect-framework.test.js +122 -0
- package/dist/scripts/draft-rows.d.ts +19 -0
- package/dist/scripts/draft-rows.js +135 -0
- package/dist/scripts/draft-rows.test.d.ts +1 -0
- package/dist/scripts/draft-rows.test.js +113 -0
- package/dist/scripts/draft-schemas.d.ts +27 -0
- package/dist/scripts/draft-schemas.js +188 -0
- package/dist/scripts/draft-schemas.test.d.ts +1 -0
- package/dist/scripts/draft-schemas.test.js +152 -0
- package/dist/scripts/extract-translations.js +16 -11
- package/dist/scripts/extract-translations.test.d.ts +1 -0
- package/dist/scripts/extract-translations.test.js +66 -0
- package/dist/scripts/frameworks/astro/routes.d.ts +3 -0
- package/dist/scripts/frameworks/astro/routes.js +55 -0
- package/dist/scripts/frameworks/astro/template-style.d.ts +7 -0
- package/dist/scripts/frameworks/astro/template-style.js +19 -0
- package/dist/scripts/frameworks/discover.d.ts +70 -0
- package/dist/scripts/frameworks/discover.js +178 -0
- package/dist/scripts/frameworks/next/rewire.d.ts +30 -0
- package/dist/scripts/frameworks/next/rewire.js +258 -0
- package/dist/scripts/frameworks/next/rewire.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/rewire.test.js +134 -0
- package/dist/scripts/frameworks/next/routes.d.ts +17 -0
- package/dist/scripts/frameworks/next/routes.js +134 -0
- package/dist/scripts/frameworks/next/routes.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/routes.test.js +64 -0
- package/dist/scripts/frameworks/next/wiring.d.ts +33 -0
- package/dist/scripts/frameworks/next/wiring.js +186 -0
- package/dist/scripts/frameworks/next/wiring.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/wiring.test.js +174 -0
- package/dist/scripts/frameworks/nuxt/routes.d.ts +3 -0
- package/dist/scripts/frameworks/nuxt/routes.js +54 -0
- package/dist/scripts/frameworks/nuxt/template-style.d.ts +9 -0
- package/dist/scripts/frameworks/nuxt/template-style.js +27 -0
- package/dist/scripts/frameworks/remix/routes.d.ts +3 -0
- package/dist/scripts/frameworks/remix/routes.js +50 -0
- package/dist/scripts/frameworks/support.d.ts +75 -0
- package/dist/scripts/frameworks/support.js +165 -0
- package/dist/scripts/frameworks/support.test.d.ts +1 -0
- package/dist/scripts/frameworks/support.test.js +87 -0
- package/dist/scripts/frameworks/sveltekit/routes.d.ts +3 -0
- package/dist/scripts/frameworks/sveltekit/routes.js +50 -0
- package/dist/scripts/frameworks/sveltekit/template-style.d.ts +9 -0
- package/dist/scripts/frameworks/sveltekit/template-style.js +54 -0
- package/dist/scripts/frameworks/vite/routes.d.ts +15 -0
- package/dist/scripts/frameworks/vite/routes.js +93 -0
- package/dist/scripts/frameworks/vite/routes.test.d.ts +1 -0
- package/dist/scripts/frameworks/vite/routes.test.js +73 -0
- package/dist/scripts/frameworks/vite/wiring.d.ts +10 -0
- package/dist/scripts/frameworks/vite/wiring.js +99 -0
- package/dist/scripts/frameworks/vite/wiring.test.d.ts +1 -0
- package/dist/scripts/frameworks/vite/wiring.test.js +88 -0
- package/dist/scripts/generated-types.test.js +1 -1
- package/dist/scripts/i18n-namespace.d.ts +25 -0
- package/dist/scripts/i18n-namespace.js +53 -0
- package/dist/scripts/lib/validation-report.d.ts +1 -0
- package/dist/scripts/lib/validation-report.js +3 -0
- package/dist/scripts/render-parity/capture.d.ts +56 -0
- package/dist/scripts/render-parity/capture.js +366 -0
- package/dist/scripts/render-parity/capture.test.d.ts +1 -0
- package/dist/scripts/render-parity/capture.test.js +306 -0
- package/dist/scripts/render-parity/compare.d.ts +59 -0
- package/dist/scripts/render-parity/compare.js +0 -0
- package/dist/scripts/render-parity/compare.test.d.ts +1 -0
- package/dist/scripts/render-parity/compare.test.js +98 -0
- package/dist/scripts/render-parity/normalize-html.d.ts +13 -0
- package/dist/scripts/render-parity/normalize-html.js +223 -0
- package/dist/scripts/render-parity/normalize-html.test.d.ts +1 -0
- package/dist/scripts/render-parity/normalize-html.test.js +58 -0
- package/dist/scripts/render-parity/types.d.ts +41 -0
- package/dist/scripts/render-parity/types.js +1 -0
- package/dist/scripts/resolve-routes.js +1 -1
- package/dist/scripts/scan-wrappable.d.ts +196 -0
- package/dist/scripts/scan-wrappable.js +1227 -0
- package/dist/scripts/scan-wrappable.test.d.ts +1 -0
- package/dist/scripts/scan-wrappable.test.js +521 -0
- package/dist/scripts/sync-schemas.test.js +4 -24
- package/dist/scripts/validate-route-metadata.js +11 -0
- package/dist/scripts/validate-schemas.test.js +2 -2
- package/package.json +92 -5
- package/templates/react-router/package.json +7 -10
- package/dist/runtime/paths/get-fimo-paths.test.d.ts +0 -2
- package/dist/runtime/paths/get-fimo-paths.test.d.ts.map +0 -1
- package/dist/runtime/paths/get-fimo-paths.test.js +0 -69
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { parseSync } from 'oxc-parser';
|
|
4
|
+
import { scanWrappable } from './scan-wrappable.js';
|
|
5
|
+
/**
|
|
6
|
+
* The --apply codemod: performs the PROVABLY-SAFE wrap transforms
|
|
7
|
+
* deterministically, leaving every judgment call to the agent.
|
|
8
|
+
*
|
|
9
|
+
* In scope: plain JSX text -> FimoText, <img src="literal"> -> FimoMediaImage,
|
|
10
|
+
* <a href="/file.pdf"> -> FimoFileLink.
|
|
11
|
+
* Out of scope (agent work): attributes (useLabels crosses the RSC boundary),
|
|
12
|
+
* formatted text (marks -> FimoRichTextBlock), next/image <Image>
|
|
13
|
+
* (framework-specific props), collections, layout wiring.
|
|
14
|
+
*
|
|
15
|
+
* Correctness is enforced by the gates, not assumed: the render-parity
|
|
16
|
+
* baseline is captured BEFORE applying, and `fimo migrate wrap --check`
|
|
17
|
+
* verifies the result like any other actor's work.
|
|
18
|
+
*/
|
|
19
|
+
/** Elements whose children cannot contain a <span> wrapper. */
|
|
20
|
+
const NO_ELEMENT_CHILDREN = new Set(['option', 'title', 'textarea', 'script', 'style', 'select']);
|
|
21
|
+
function collapse(text) {
|
|
22
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
23
|
+
}
|
|
24
|
+
// JSX text carries HTML entities (', &, …). The FALLBACK keeps the
|
|
25
|
+
// original source form, but the label VALUE is rendered literally by
|
|
26
|
+
// FimoText — seeding the raw entity re-escapes it on screen (the remix
|
|
27
|
+
// dogfood shipped "What's next?"). Decode when generating values.
|
|
28
|
+
const JSX_ENTITIES = {
|
|
29
|
+
'&': '&',
|
|
30
|
+
'<': '<',
|
|
31
|
+
'>': '>',
|
|
32
|
+
'"': '"',
|
|
33
|
+
''': "'",
|
|
34
|
+
' ': ' ',
|
|
35
|
+
'©': '©',
|
|
36
|
+
};
|
|
37
|
+
export function decodeJsxEntities(text) {
|
|
38
|
+
return text
|
|
39
|
+
.replace(/&(amp|lt|gt|quot|apos|nbsp|copy);/g, (entity) => JSX_ENTITIES[entity] ?? entity)
|
|
40
|
+
.replace(/&#(\d+);/g, (_, code) => String.fromCodePoint(Number(code)))
|
|
41
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)));
|
|
42
|
+
}
|
|
43
|
+
/** Deterministic scope from the file path: app/about/page.tsx -> about. */
|
|
44
|
+
export function keyScope(file) {
|
|
45
|
+
const normalized = file.replace(/\\/g, '/');
|
|
46
|
+
const appMatch = normalized.match(/(?:^|\/)app\/(.*)\/?page\.[jt]sx?$/);
|
|
47
|
+
if (appMatch) {
|
|
48
|
+
const dir = appMatch[1].replace(/\/$/, '');
|
|
49
|
+
if (!dir) {
|
|
50
|
+
return 'home';
|
|
51
|
+
}
|
|
52
|
+
const segments = dir
|
|
53
|
+
.split('/')
|
|
54
|
+
.filter((segment) => !segment.startsWith('(') && !segment.startsWith('@'))
|
|
55
|
+
.map((segment) => segment.replace(/^\[+|\]+$/g, '').replace(/^\.\.\./, ''));
|
|
56
|
+
return segments.join('.') || 'home';
|
|
57
|
+
}
|
|
58
|
+
if (/(?:^|\/)app\/layout\.[jt]sx?$/.test(normalized)) {
|
|
59
|
+
return 'layout';
|
|
60
|
+
}
|
|
61
|
+
const stem = basename(normalized).replace(/\.[jt]sx?$/, '');
|
|
62
|
+
return slugify(stem) || 'shared';
|
|
63
|
+
}
|
|
64
|
+
export function slugify(text) {
|
|
65
|
+
return collapse(text)
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.normalize('NFD')
|
|
68
|
+
.replace(/[̀-ͯ]/g, '')
|
|
69
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
70
|
+
.replace(/^-+|-+$/g, '')
|
|
71
|
+
.split('-')
|
|
72
|
+
.slice(0, 4)
|
|
73
|
+
.join('-');
|
|
74
|
+
}
|
|
75
|
+
export class KeyAllocator {
|
|
76
|
+
used = new Set();
|
|
77
|
+
constructor(existing) {
|
|
78
|
+
for (const key of existing) {
|
|
79
|
+
this.used.add(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
allocate(scope, slug) {
|
|
83
|
+
const base = `${scope}.${slug || 'item'}`;
|
|
84
|
+
let candidate = base;
|
|
85
|
+
let counter = 2;
|
|
86
|
+
while (this.used.has(candidate)) {
|
|
87
|
+
candidate = `${base}-${counter++}`;
|
|
88
|
+
}
|
|
89
|
+
this.used.add(candidate);
|
|
90
|
+
return candidate;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merge the fimo/next import with an existing one, or insert a new one AFTER
|
|
95
|
+
* the last import statement — positioned via the AST, never line matching
|
|
96
|
+
* (a multiline `import {\n …` opening line is not the end of the imports,
|
|
97
|
+
* as a real portfolio migration proved).
|
|
98
|
+
*/
|
|
99
|
+
export function ensureFimoImport(code, specifiers, importModule = 'fimo/next') {
|
|
100
|
+
if (specifiers.length === 0) {
|
|
101
|
+
return code;
|
|
102
|
+
}
|
|
103
|
+
const moduleRe = importModule.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
104
|
+
const importMatch = code.match(new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*(['\"])${moduleRe}\\2\\s*;?`));
|
|
105
|
+
if (importMatch) {
|
|
106
|
+
const existing = importMatch[1]
|
|
107
|
+
.split(',')
|
|
108
|
+
.map((token) => token.trim())
|
|
109
|
+
.filter(Boolean);
|
|
110
|
+
const merged = [...new Set([...existing, ...specifiers])].sort();
|
|
111
|
+
return code.replace(importMatch[0], `import { ${merged.join(', ')} } from "${importModule}";`);
|
|
112
|
+
}
|
|
113
|
+
const statement = `import { ${[...new Set(specifiers)].sort().join(', ')} } from "${importModule}";`;
|
|
114
|
+
let insertAt = 0;
|
|
115
|
+
try {
|
|
116
|
+
const program = parseSync('module.tsx', code).program;
|
|
117
|
+
for (const node of program.body ?? []) {
|
|
118
|
+
if (node.type === 'ImportDeclaration') {
|
|
119
|
+
insertAt = node.end;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
insertAt = 0;
|
|
125
|
+
}
|
|
126
|
+
if (insertAt === 0) {
|
|
127
|
+
return `${statement}\n${code}`;
|
|
128
|
+
}
|
|
129
|
+
return `${code.slice(0, insertAt)}\n${statement}${code.slice(insertAt)}`;
|
|
130
|
+
}
|
|
131
|
+
export function applyWrapToFile(code, items, allocator, importModule = 'fimo/next') {
|
|
132
|
+
const applied = [];
|
|
133
|
+
const skipped = [];
|
|
134
|
+
const labels = {};
|
|
135
|
+
const edits = [];
|
|
136
|
+
const specifiers = new Set();
|
|
137
|
+
for (const item of items) {
|
|
138
|
+
const span = item.span;
|
|
139
|
+
if (!span) {
|
|
140
|
+
skipped.push({ item, reason: 'no span info' });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const scope = keyScope(item.file);
|
|
144
|
+
if (item.kind === 'text') {
|
|
145
|
+
if (span.parentTag && NO_ELEMENT_CHILDREN.has(span.parentTag.toLowerCase())) {
|
|
146
|
+
skipped.push({ item, reason: `<${span.parentTag}> cannot contain a wrapper element` });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const raw = code.slice(span.start, span.end);
|
|
150
|
+
const core = raw.trim();
|
|
151
|
+
if (!core) {
|
|
152
|
+
skipped.push({ item, reason: 'whitespace only' });
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const lead = raw.slice(0, raw.indexOf(core));
|
|
156
|
+
const trail = raw.slice(raw.indexOf(core) + core.length);
|
|
157
|
+
const id = allocator.allocate(scope, slugify(core));
|
|
158
|
+
edits.push({
|
|
159
|
+
start: span.start,
|
|
160
|
+
end: span.end,
|
|
161
|
+
replacement: `${lead}<FimoText id="${id}">${core}</FimoText>${trail}`,
|
|
162
|
+
});
|
|
163
|
+
specifiers.add('FimoText');
|
|
164
|
+
labels[id] = decodeJsxEntities(collapse(core));
|
|
165
|
+
applied.push({ kind: 'text', file: item.file, line: item.line, id, preview: item.preview });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (item.kind === 'image') {
|
|
169
|
+
if (span.openNameStart === undefined ||
|
|
170
|
+
span.openNameEnd === undefined ||
|
|
171
|
+
code.slice(span.openNameStart, span.openNameEnd) !== 'img') {
|
|
172
|
+
skipped.push({ item, reason: 'next/image and custom components stay agent work' });
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const id = allocator.allocate(scope, slugify(basename(item.preview).replace(/\.[a-z0-9]+$/i, '')));
|
|
176
|
+
edits.push({
|
|
177
|
+
start: span.openNameStart,
|
|
178
|
+
end: span.openNameEnd,
|
|
179
|
+
replacement: `FimoMediaImage id="${id}"`,
|
|
180
|
+
});
|
|
181
|
+
specifiers.add('FimoMediaImage');
|
|
182
|
+
applied.push({ kind: 'image', file: item.file, line: item.line, id, preview: item.preview });
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (item.kind === 'file-link') {
|
|
186
|
+
if (span.openNameStart === undefined ||
|
|
187
|
+
span.openNameEnd === undefined ||
|
|
188
|
+
span.closeNameStart === undefined ||
|
|
189
|
+
span.closeNameEnd === undefined) {
|
|
190
|
+
skipped.push({ item, reason: 'self-closing or unparsable anchor' });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const id = allocator.allocate(scope, slugify(basename(item.preview).replace(/\.[a-z0-9]+$/i, '')));
|
|
194
|
+
edits.push({ start: span.openNameStart, end: span.openNameEnd, replacement: `FimoFileLink id="${id}"` });
|
|
195
|
+
edits.push({ start: span.closeNameStart, end: span.closeNameEnd, replacement: 'FimoFileLink' });
|
|
196
|
+
specifiers.add('FimoFileLink');
|
|
197
|
+
applied.push({ kind: 'file-link', file: item.file, line: item.line, id, preview: item.preview });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
skipped.push({ item, reason: `${item.kind} stays agent work` });
|
|
201
|
+
}
|
|
202
|
+
let next = code;
|
|
203
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
204
|
+
next = next.slice(0, edit.start) + edit.replacement + next.slice(edit.end);
|
|
205
|
+
}
|
|
206
|
+
next = ensureFimoImport(next, [...specifiers], importModule);
|
|
207
|
+
return { code: next, applied, skipped, labels };
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Apply the safe transforms across the project. Mutates source files and
|
|
211
|
+
* merges generated labels into `.fimo/migration/labels.json` (never
|
|
212
|
+
* overwriting existing keys).
|
|
213
|
+
*/
|
|
214
|
+
/** Recorded coverage exemptions the codemod must NOT wrap — items the user
|
|
215
|
+
* deliberately kept out (dev-only UI, OG-image markup, …). Matched by the
|
|
216
|
+
* same (file, kind, preview) triple the coverage gate uses, so "record the
|
|
217
|
+
* exemption first, then --apply auto-wraps the rest" holds. */
|
|
218
|
+
function readApplyExemptions(rootDir) {
|
|
219
|
+
try {
|
|
220
|
+
const manifest = JSON.parse(readFileSync(join(rootDir, '.fimo', 'migration', 'manifest.json'), 'utf8'));
|
|
221
|
+
const raw = manifest?.wrap?.exemptions;
|
|
222
|
+
return Array.isArray(raw)
|
|
223
|
+
? raw.filter((entry) => typeof entry?.file === 'string' &&
|
|
224
|
+
typeof entry?.kind === 'string' &&
|
|
225
|
+
typeof entry?.preview === 'string')
|
|
226
|
+
: [];
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export function applyWrap(rootDir, opts = {}) {
|
|
233
|
+
const scan = scanWrappable(rootDir, { excludePrefixes: opts.excludePrefixes });
|
|
234
|
+
const existingLabels = (() => {
|
|
235
|
+
try {
|
|
236
|
+
return JSON.parse(readFileSync(join(rootDir, '.fimo', 'migration', 'labels.json'), 'utf8'));
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
})();
|
|
242
|
+
// Honor recorded exemptions: the codemod skips them so the coverage gate's
|
|
243
|
+
// exemption and the codemod stay consistent — otherwise --apply would wrap
|
|
244
|
+
// an item the user just exempted and the gate would flag the drift.
|
|
245
|
+
const exemptions = readApplyExemptions(rootDir);
|
|
246
|
+
const isExempt = (item) => exemptions.some((exemption) => exemption.file === item.file && exemption.kind === item.kind && exemption.preview === item.preview);
|
|
247
|
+
const allocator = new KeyAllocator([...Object.keys(existingLabels), ...scan.wrappedIds.labels]);
|
|
248
|
+
const byFile = new Map();
|
|
249
|
+
for (const item of scan.items) {
|
|
250
|
+
if (isExempt(item)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const list = byFile.get(item.file) ?? [];
|
|
254
|
+
list.push(item);
|
|
255
|
+
byFile.set(item.file, list);
|
|
256
|
+
}
|
|
257
|
+
const result = { applied: [], skipped: [], labels: {}, filesChanged: [] };
|
|
258
|
+
for (const [file, items] of byFile) {
|
|
259
|
+
const filePath = join(rootDir, file);
|
|
260
|
+
let code;
|
|
261
|
+
try {
|
|
262
|
+
code = readFileSync(filePath, 'utf8');
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
result.skipped.push(...items.map((item) => ({ item, reason: 'unreadable file' })));
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const fileResult = applyWrapToFile(code, items, allocator, opts.importModule ?? 'fimo/next');
|
|
269
|
+
result.applied.push(...fileResult.applied);
|
|
270
|
+
result.skipped.push(...fileResult.skipped);
|
|
271
|
+
Object.assign(result.labels, fileResult.labels);
|
|
272
|
+
if (fileResult.applied.length > 0) {
|
|
273
|
+
writeFileSync(filePath, fileResult.code);
|
|
274
|
+
result.filesChanged.push(file);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { applyWrap, ensureFimoImport, keyScope, slugify } from './apply-wrap.js';
|
|
6
|
+
import { scanWrappable } from './scan-wrappable.js';
|
|
7
|
+
let dir;
|
|
8
|
+
const project = (files) => {
|
|
9
|
+
dir = mkdtempSync(join(tmpdir(), 'apply-wrap-'));
|
|
10
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
11
|
+
const full = join(dir, rel);
|
|
12
|
+
mkdirSync(join(full, '..'), { recursive: true });
|
|
13
|
+
writeFileSync(full, content);
|
|
14
|
+
}
|
|
15
|
+
return dir;
|
|
16
|
+
};
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
if (dir) {
|
|
19
|
+
rmSync(dir, { recursive: true, force: true });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
describe('keyScope / slugify', () => {
|
|
23
|
+
it('derives scopes from app-router paths', () => {
|
|
24
|
+
expect(keyScope('app/page.tsx')).toBe('home');
|
|
25
|
+
expect(keyScope('app/about/page.tsx')).toBe('about');
|
|
26
|
+
expect(keyScope('app/(marketing)/pricing/page.tsx')).toBe('pricing');
|
|
27
|
+
expect(keyScope('app/layout.tsx')).toBe('layout');
|
|
28
|
+
expect(keyScope('components/Footer.tsx')).toBe('footer');
|
|
29
|
+
});
|
|
30
|
+
it('slugifies text deterministically', () => {
|
|
31
|
+
expect(slugify('To get started, edit the page.tsx file.')).toBe('to-get-started-edit');
|
|
32
|
+
expect(slugify('Déjà vu!')).toBe('deja-vu');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('ensureFimoImport', () => {
|
|
36
|
+
it('inserts after the last import', () => {
|
|
37
|
+
const out = ensureFimoImport('import x from "y";\n\nconst a = 1;', ['FimoText']);
|
|
38
|
+
expect(out).toContain('import x from "y";\nimport { FimoText } from "fimo/next";');
|
|
39
|
+
});
|
|
40
|
+
it('merges into an existing fimo/next import', () => {
|
|
41
|
+
const out = ensureFimoImport('import { FimoText } from "fimo/next";\n', ['FimoMediaImage', 'FimoText']);
|
|
42
|
+
expect(out).toContain('import { FimoMediaImage, FimoText } from "fimo/next";');
|
|
43
|
+
});
|
|
44
|
+
it('decodes JSX entities in generated label values (fallback keeps the source form)', async () => {
|
|
45
|
+
const { applyWrapToFile, KeyAllocator } = await import('./apply-wrap.js');
|
|
46
|
+
const code = `export default function P() {\n return <p>What's next & more?</p>;\n}`;
|
|
47
|
+
const result = applyWrapToFile(code, [
|
|
48
|
+
{
|
|
49
|
+
kind: 'text',
|
|
50
|
+
file: 'app/page.tsx',
|
|
51
|
+
line: 2,
|
|
52
|
+
preview: 'What's next & more?',
|
|
53
|
+
span: { start: code.indexOf('What'), end: code.indexOf('?</p>') + 1, parentTag: 'p' },
|
|
54
|
+
},
|
|
55
|
+
], new KeyAllocator([]));
|
|
56
|
+
const [value] = Object.values(result.labels);
|
|
57
|
+
expect(value).toBe("What's next & more?");
|
|
58
|
+
expect(result.code).toContain('What's next & more?');
|
|
59
|
+
});
|
|
60
|
+
it('targets the adapter module of the detected framework, never fimo/next unconditionally', () => {
|
|
61
|
+
const inserted = ensureFimoImport('const a = 1;', ['FimoText'], 'fimo/remix');
|
|
62
|
+
expect(inserted).toContain('import { FimoText } from "fimo/remix";');
|
|
63
|
+
const merged = ensureFimoImport('import { FimoText } from "fimo/remix";\n', ['FimoMediaImage'], 'fimo/remix');
|
|
64
|
+
expect(merged).toContain('import { FimoMediaImage, FimoText } from "fimo/remix";');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('applyWrap', () => {
|
|
68
|
+
it('wraps plain text, images, and file links; leaves judgment items', () => {
|
|
69
|
+
const cwd = project({
|
|
70
|
+
'app/page.tsx': `export default function Page() {
|
|
71
|
+
return (
|
|
72
|
+
<main>
|
|
73
|
+
<h1>Ship your site in hours</h1>
|
|
74
|
+
<img src="/hero.png" alt="Hero" />
|
|
75
|
+
<a href="/whitepaper.pdf">Download the whitepaper</a>
|
|
76
|
+
<p>Read <strong>honest numbers</strong> today</p>
|
|
77
|
+
<input placeholder="Your email" />
|
|
78
|
+
<select><option>Pick one</option></select>
|
|
79
|
+
</main>
|
|
80
|
+
);
|
|
81
|
+
}`,
|
|
82
|
+
});
|
|
83
|
+
const result = applyWrap(cwd);
|
|
84
|
+
const code = readFileSync(join(cwd, 'app/page.tsx'), 'utf8');
|
|
85
|
+
expect(code).toContain('<FimoText id="home.ship-your-site-in">Ship your site in hours</FimoText>');
|
|
86
|
+
expect(code).toContain('<FimoMediaImage id="home.hero" src="/hero.png" alt="Hero" />');
|
|
87
|
+
expect(code).toContain('<FimoFileLink id="home.whitepaper" href="/whitepaper.pdf">');
|
|
88
|
+
expect(code).toContain('</FimoFileLink>');
|
|
89
|
+
expect(code).toContain('import { FimoFileLink, FimoMediaImage, FimoText } from "fimo/next";');
|
|
90
|
+
// Judgment items untouched: option text, attribute, rich-ish fragments.
|
|
91
|
+
expect(code).toContain('<option>Pick one</option>');
|
|
92
|
+
expect(code).toContain('placeholder="Your email"');
|
|
93
|
+
expect(result.skipped.some((entry) => entry.reason.includes('<option>'))).toBe(true);
|
|
94
|
+
expect(result.skipped.some((entry) => entry.item.kind === 'attribute')).toBe(true);
|
|
95
|
+
// Labels generated for wrapped text (incl. link text wrapped inside FimoFileLink).
|
|
96
|
+
expect(result.labels['home.ship-your-site-in']).toBe('Ship your site in hours');
|
|
97
|
+
// The wrapped file parses again and the safe items are gone.
|
|
98
|
+
const rescan = scanWrappable(cwd);
|
|
99
|
+
expect(rescan.items.filter((item) => item.kind === 'image' || item.kind === 'file-link')).toEqual([]);
|
|
100
|
+
expect(rescan.wrappedIds.media).toEqual(['home.hero']);
|
|
101
|
+
expect(rescan.wrappedIds.files).toEqual(['home.whitepaper']);
|
|
102
|
+
});
|
|
103
|
+
it('is idempotent: a second apply changes nothing', () => {
|
|
104
|
+
const cwd = project({
|
|
105
|
+
'app/about/page.tsx': `export default function About() {
|
|
106
|
+
return <h1>We believe analytics should be readable</h1>;
|
|
107
|
+
}`,
|
|
108
|
+
});
|
|
109
|
+
applyWrap(cwd);
|
|
110
|
+
const once = readFileSync(join(cwd, 'app/about/page.tsx'), 'utf8');
|
|
111
|
+
const second = applyWrap(cwd);
|
|
112
|
+
const twice = readFileSync(join(cwd, 'app/about/page.tsx'), 'utf8');
|
|
113
|
+
expect(twice).toBe(once);
|
|
114
|
+
expect(second.applied).toEqual([]);
|
|
115
|
+
expect(second.filesChanged).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
it('skips items recorded as exemptions (exempt-first, then --apply wraps the rest)', () => {
|
|
118
|
+
const cwd = project({
|
|
119
|
+
'app/page.tsx': `export default function Page() {
|
|
120
|
+
return (
|
|
121
|
+
<main>
|
|
122
|
+
<h1>Wrap this headline</h1>
|
|
123
|
+
<p>But keep this dev note verbatim</p>
|
|
124
|
+
</main>
|
|
125
|
+
);
|
|
126
|
+
}`,
|
|
127
|
+
'.fimo/migration/manifest.json': JSON.stringify({
|
|
128
|
+
wrap: {
|
|
129
|
+
exemptions: [
|
|
130
|
+
{
|
|
131
|
+
file: 'app/page.tsx',
|
|
132
|
+
kind: 'text',
|
|
133
|
+
preview: 'But keep this dev note verbatim',
|
|
134
|
+
reason: 'dev-only note',
|
|
135
|
+
status: 'unresolved',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
const result = applyWrap(cwd);
|
|
142
|
+
const code = readFileSync(join(cwd, 'app/page.tsx'), 'utf8');
|
|
143
|
+
// The non-exempt headline is auto-wrapped...
|
|
144
|
+
expect(code).toContain('<FimoText id="home.wrap-this-headline">Wrap this headline</FimoText>');
|
|
145
|
+
// ...the exempt item is left byte-for-byte and never labelled.
|
|
146
|
+
expect(code).toContain('<p>But keep this dev note verbatim</p>');
|
|
147
|
+
expect(code).not.toContain('FimoText id="home.but-keep');
|
|
148
|
+
expect(Object.values(result.labels)).not.toContain('But keep this dev note verbatim');
|
|
149
|
+
expect(Object.values(result.labels)).toContain('Wrap this headline');
|
|
150
|
+
});
|
|
151
|
+
it('leaves next/image components to the agent', () => {
|
|
152
|
+
const cwd = project({
|
|
153
|
+
'app/page.tsx': `import Image from "next/image";
|
|
154
|
+
export default function Page() {
|
|
155
|
+
return <Image src="/logo.svg" alt="Logo" width={10} height={10} priority />;
|
|
156
|
+
}`,
|
|
157
|
+
});
|
|
158
|
+
const result = applyWrap(cwd);
|
|
159
|
+
expect(result.applied).toEqual([]);
|
|
160
|
+
expect(result.skipped.some((entry) => entry.reason.includes('next/image'))).toBe(true);
|
|
161
|
+
expect(readFileSync(join(cwd, 'app/page.tsx'), 'utf8')).toContain('<Image src="/logo.svg"');
|
|
162
|
+
});
|
|
163
|
+
it('preserves surrounding whitespace so rendering stays identical', () => {
|
|
164
|
+
const cwd = project({
|
|
165
|
+
'app/page.tsx': `export default function Page() {
|
|
166
|
+
return (
|
|
167
|
+
<p>
|
|
168
|
+
Hello world from Fimo
|
|
169
|
+
</p>
|
|
170
|
+
);
|
|
171
|
+
}`,
|
|
172
|
+
});
|
|
173
|
+
applyWrap(cwd);
|
|
174
|
+
const code = readFileSync(join(cwd, 'app/page.tsx'), 'utf8');
|
|
175
|
+
expect(code).toMatch(/<p>\n <FimoText id="home\.hello-world-from-fimo">Hello world from Fimo<\/FimoText>\n <\/p>/);
|
|
176
|
+
});
|
|
177
|
+
it('avoids key collisions across duplicate texts', () => {
|
|
178
|
+
const cwd = project({
|
|
179
|
+
'app/page.tsx': `export default function Page() {
|
|
180
|
+
return (
|
|
181
|
+
<div>
|
|
182
|
+
<button>Contact us</button>
|
|
183
|
+
<button>Contact us</button>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}`,
|
|
187
|
+
});
|
|
188
|
+
const result = applyWrap(cwd);
|
|
189
|
+
expect(Object.keys(result.labels).sort()).toEqual(['home.contact-us', 'home.contact-us-2']);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe('back-office exclusion', () => {
|
|
193
|
+
it('never touches excluded sections', () => {
|
|
194
|
+
const cwd = project({
|
|
195
|
+
'app/admin/page.tsx': `export default function Admin() {
|
|
196
|
+
return <h1>Secret admin panel</h1>;
|
|
197
|
+
}`,
|
|
198
|
+
'app/page.tsx': `export default function Home() {
|
|
199
|
+
return <h1>Public home</h1>;
|
|
200
|
+
}`,
|
|
201
|
+
});
|
|
202
|
+
const result = applyWrap(cwd, { excludePrefixes: ['app/admin'] });
|
|
203
|
+
expect(readFileSync(join(cwd, 'app/admin/page.tsx'), 'utf8')).not.toContain('FimoText');
|
|
204
|
+
expect(readFileSync(join(cwd, 'app/page.tsx'), 'utf8')).toContain('FimoText');
|
|
205
|
+
expect(result.applied.map((entry) => entry.file)).toEqual(['app/page.tsx']);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('ensureFimoImport with multiline imports', () => {
|
|
209
|
+
it('inserts after a multiline import statement, never inside it', () => {
|
|
210
|
+
const code = `import { useEffect } from "react";
|
|
211
|
+
import {
|
|
212
|
+
AnimatedSpan,
|
|
213
|
+
Terminal,
|
|
214
|
+
TypingAnimation,
|
|
215
|
+
} from "@/components/magicui/terminal";
|
|
216
|
+
|
|
217
|
+
export function X() { return null; }`;
|
|
218
|
+
const out = ensureFimoImport(code, ['FimoText']);
|
|
219
|
+
expect(out).toContain('} from "@/components/magicui/terminal";\nimport { FimoText } from "fimo/next";');
|
|
220
|
+
expect(out.indexOf('import { FimoText }')).toBeGreaterThan(out.indexOf('TypingAnimation'));
|
|
221
|
+
});
|
|
222
|
+
it('prepends when the file has no imports', () => {
|
|
223
|
+
const out = ensureFimoImport('export const x = 1;', ['FimoText']);
|
|
224
|
+
expect(out.startsWith('import { FimoText } from "fimo/next";\n')).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { strapiConnector } from './strapi/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* CMS-connector registry. Add a connector factory here to support a new
|
|
4
|
+
* headless CMS; each returns its `CmsConnector` when it recognizes the
|
|
5
|
+
* frontend, or null. First match wins. This is the ONLY CMS-neutral file that
|
|
6
|
+
* enumerates the supported CMSs (the analogue of `frameworks/discover.ts`).
|
|
7
|
+
*/
|
|
8
|
+
const CONNECTORS = [strapiConnector];
|
|
9
|
+
export function detectCms(frontendDir) {
|
|
10
|
+
for (const factory of CONNECTORS) {
|
|
11
|
+
const connector = factory(frontendDir);
|
|
12
|
+
if (connector) {
|
|
13
|
+
return connector;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CmsCollectionSchema } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate example content for a CMS schema WITHOUT connecting to the CMS. The
|
|
4
|
+
* shapes match `api.importEntries`: media fields are omitted (a fake URL
|
|
5
|
+
* would render a broken image), references point at the first example of the
|
|
6
|
+
* target type (`<target>-example-1`) so they resolve against the co-seeded
|
|
7
|
+
* data, and localized types get per-locale string variance so the per-language
|
|
8
|
+
* editability is visible in Fimo. This is CMS-neutral: it consumes the mapped
|
|
9
|
+
* Fimo schema only.
|
|
10
|
+
*/
|
|
11
|
+
export interface ExampleSeed {
|
|
12
|
+
/** Fimo type name. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly isSingleton: boolean;
|
|
15
|
+
readonly localized: boolean;
|
|
16
|
+
/** Entry data rows (slug lives inside data for collections). */
|
|
17
|
+
readonly rows: Array<Record<string, unknown>>;
|
|
18
|
+
/** Reference descriptor for `importEntries`. */
|
|
19
|
+
readonly references: Record<string, {
|
|
20
|
+
target?: string;
|
|
21
|
+
targets?: string[];
|
|
22
|
+
by: 'slug';
|
|
23
|
+
many?: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export interface ExampleOptions {
|
|
27
|
+
/** Rows per collection type (singletons always get exactly one). */
|
|
28
|
+
readonly count?: number;
|
|
29
|
+
/** Locale suffix on string values + the batch locale (for localized types). */
|
|
30
|
+
readonly locale?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function generateExampleSeed(schema: CmsCollectionSchema, options?: ExampleOptions): ExampleSeed;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const DEFAULT_COUNT = 3;
|
|
2
|
+
function kebabCase(name) {
|
|
3
|
+
return name
|
|
4
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
5
|
+
.replace(/[^a-zA-Z0-9]+/g, '-')
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/^-+|-+$/g, '');
|
|
8
|
+
}
|
|
9
|
+
function humanize(field) {
|
|
10
|
+
return field
|
|
11
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
12
|
+
.replace(/[_-]+/g, ' ')
|
|
13
|
+
.replace(/^\w/, (c) => c.toUpperCase());
|
|
14
|
+
}
|
|
15
|
+
function richTextDoc(text) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'doc',
|
|
18
|
+
content: [{ type: 'paragraph', content: [{ type: 'text', text }] }],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** A self-contained placeholder image (inline SVG data-URI) in the media
|
|
22
|
+
* envelope shape the wrap runtime already understands — no external host, no
|
|
23
|
+
* CSP surprises, so cards/heroes render instead of showing broken images. */
|
|
24
|
+
function placeholderMedia(label) {
|
|
25
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630"><rect width="100%" height="100%" fill="#e5e7eb"/><text x="50%" y="50%" font-family="sans-serif" font-size="44" fill="#9ca3af" text-anchor="middle" dominant-baseline="middle">${label}</text></svg>`;
|
|
26
|
+
return {
|
|
27
|
+
source: 'local',
|
|
28
|
+
url: `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`,
|
|
29
|
+
alt: `${label} placeholder`,
|
|
30
|
+
width: 1200,
|
|
31
|
+
height: 630,
|
|
32
|
+
mime: 'image/svg+xml',
|
|
33
|
+
name: 'placeholder.svg',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Deterministic ISO date (no wall clock): 2024-01-01 + (n-1) days. */
|
|
37
|
+
function exampleDate(n) {
|
|
38
|
+
return new Date(Date.UTC(2024, 0, n)).toISOString().slice(0, 10);
|
|
39
|
+
}
|
|
40
|
+
function exampleReferenceSlug(field) {
|
|
41
|
+
const targetName = field.target ?? field.targets?.[0];
|
|
42
|
+
if (!targetName) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const slug = `${kebabCase(targetName)}-example-1`;
|
|
46
|
+
return field.many ? [slug] : slug;
|
|
47
|
+
}
|
|
48
|
+
export function generateExampleSeed(schema, options = {}) {
|
|
49
|
+
const locale = options.locale;
|
|
50
|
+
const localeSuffix = locale ? ` (${locale})` : '';
|
|
51
|
+
const count = schema.isSingleton ? 1 : Math.max(1, options.count ?? DEFAULT_COUNT);
|
|
52
|
+
const references = {};
|
|
53
|
+
const rows = [];
|
|
54
|
+
for (let i = 1; i <= count; i += 1) {
|
|
55
|
+
const row = {};
|
|
56
|
+
if (!schema.isSingleton) {
|
|
57
|
+
row.slug = `${kebabCase(schema.name)}-example-${i}`;
|
|
58
|
+
}
|
|
59
|
+
for (const [field, def] of Object.entries(schema.fields)) {
|
|
60
|
+
// A connector-supplied example (dynamic zones, components) wins over the
|
|
61
|
+
// type-driven default — critical for dynamic zones, which must be arrays.
|
|
62
|
+
if (schema.examples && field in schema.examples) {
|
|
63
|
+
row[field] = schema.examples[field];
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
switch (def.type) {
|
|
67
|
+
case 'string':
|
|
68
|
+
row[field] = `${humanize(field)} example ${i}${localeSuffix}`;
|
|
69
|
+
break;
|
|
70
|
+
case 'richtext':
|
|
71
|
+
row[field] = richTextDoc(`Example ${humanize(schema.name).toLowerCase()} content ${i}${localeSuffix}.`);
|
|
72
|
+
break;
|
|
73
|
+
case 'number':
|
|
74
|
+
row[field] = i;
|
|
75
|
+
break;
|
|
76
|
+
case 'boolean':
|
|
77
|
+
row[field] = i % 2 === 1;
|
|
78
|
+
break;
|
|
79
|
+
case 'date':
|
|
80
|
+
row[field] = exampleDate(i);
|
|
81
|
+
break;
|
|
82
|
+
case 'json':
|
|
83
|
+
row[field] = {};
|
|
84
|
+
break;
|
|
85
|
+
case 'media':
|
|
86
|
+
row[field] = placeholderMedia(humanize(field));
|
|
87
|
+
break;
|
|
88
|
+
case 'reference': {
|
|
89
|
+
const value = exampleReferenceSlug(def);
|
|
90
|
+
if (value !== undefined) {
|
|
91
|
+
row[field] = value;
|
|
92
|
+
references[field] = {
|
|
93
|
+
...(def.target ? { target: def.target } : {}),
|
|
94
|
+
...(def.targets ? { targets: def.targets } : {}),
|
|
95
|
+
by: 'slug',
|
|
96
|
+
...(def.many ? { many: true } : {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
rows.push(row);
|
|
106
|
+
}
|
|
107
|
+
return { name: schema.name, isSingleton: schema.isSingleton, localized: schema.localized, rows, references };
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|