fimo 0.7.0-experimental.1 → 0.7.0-experimental.11
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 +20644 -12459
- 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 +104 -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 +27 -0
- package/dist/scripts/i18n-namespace.js +155 -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 +1232 -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,66 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { generateExampleSeed } from './example-content.js';
|
|
3
|
+
const blogPost = {
|
|
4
|
+
name: 'BlogPost',
|
|
5
|
+
label: 'Blog Post',
|
|
6
|
+
isSingleton: false,
|
|
7
|
+
localized: false,
|
|
8
|
+
fields: {
|
|
9
|
+
title: { type: 'string' },
|
|
10
|
+
content: { type: 'richtext' },
|
|
11
|
+
readTime: { type: 'number' },
|
|
12
|
+
featured: { type: 'boolean' },
|
|
13
|
+
publishedOn: { type: 'date' },
|
|
14
|
+
meta: { type: 'json' },
|
|
15
|
+
cover: { type: 'media' },
|
|
16
|
+
category: { type: 'reference', target: 'PostCategory' },
|
|
17
|
+
tags: { type: 'reference', target: 'PostTag', many: true },
|
|
18
|
+
},
|
|
19
|
+
sourceUid: 'api::blog-post.blog-post',
|
|
20
|
+
sourcePath: '/blog-posts',
|
|
21
|
+
};
|
|
22
|
+
describe('generateExampleSeed', () => {
|
|
23
|
+
it('generates typed rows with a slug per collection entry', () => {
|
|
24
|
+
const seed = generateExampleSeed(blogPost, { count: 2 });
|
|
25
|
+
expect(seed.rows).toHaveLength(2);
|
|
26
|
+
const [first, second] = seed.rows;
|
|
27
|
+
expect(first.slug).toBe('blog-post-example-1');
|
|
28
|
+
expect(first.title).toBe('Title example 1');
|
|
29
|
+
expect(first.content).toMatchObject({ type: 'doc' });
|
|
30
|
+
expect(first.readTime).toBe(1);
|
|
31
|
+
expect(first.featured).toBe(true);
|
|
32
|
+
expect(second.featured).toBe(false);
|
|
33
|
+
expect(first.publishedOn).toBe('2024-01-01');
|
|
34
|
+
expect(second.publishedOn).toBe('2024-01-02');
|
|
35
|
+
expect(first.meta).toEqual({});
|
|
36
|
+
});
|
|
37
|
+
it('seeds a self-contained placeholder for media fields', () => {
|
|
38
|
+
const seed = generateExampleSeed(blogPost, { count: 1 });
|
|
39
|
+
expect(seed.rows[0].cover).toMatchObject({ source: 'local', width: 1200, height: 630 });
|
|
40
|
+
expect(seed.rows[0].cover.url).toContain('data:image/svg+xml');
|
|
41
|
+
});
|
|
42
|
+
it('points references at the first example of the target, with a descriptor', () => {
|
|
43
|
+
const seed = generateExampleSeed(blogPost, { count: 1 });
|
|
44
|
+
expect(seed.rows[0].category).toBe('post-category-example-1');
|
|
45
|
+
expect(seed.rows[0].tags).toEqual(['post-tag-example-1']);
|
|
46
|
+
expect(seed.references.category).toEqual({ target: 'PostCategory', by: 'slug' });
|
|
47
|
+
expect(seed.references.tags).toEqual({ target: 'PostTag', by: 'slug', many: true });
|
|
48
|
+
});
|
|
49
|
+
it('gives a singleton exactly one slug-less row', () => {
|
|
50
|
+
const seed = generateExampleSeed({ ...blogPost, name: 'Global', isSingleton: true }, { count: 5 });
|
|
51
|
+
expect(seed.rows).toHaveLength(1);
|
|
52
|
+
expect(seed.rows[0].slug).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
it('varies string values per locale so per-language editing is visible', () => {
|
|
55
|
+
const fr = generateExampleSeed(blogPost, { count: 1, locale: 'fr' });
|
|
56
|
+
expect(fr.rows[0].title).toBe('Title example 1 (fr)');
|
|
57
|
+
});
|
|
58
|
+
it('uses a connector-supplied example (dynamic-zone array) over the type default', () => {
|
|
59
|
+
const withExample = {
|
|
60
|
+
...blogPost,
|
|
61
|
+
fields: { ...blogPost.fields, sections: { type: 'json' } },
|
|
62
|
+
examples: { sections: [] },
|
|
63
|
+
};
|
|
64
|
+
expect(generateExampleSeed(withExample, { count: 1 }).rows[0].sections).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Detect a Strapi backend behind a wrapped frontend. Strapi is consumed via a
|
|
5
|
+
* hand-rolled fetch client against an env-var base URL (no SDK, no hardcoded
|
|
6
|
+
* URL), so the generic external-source scanner misses it entirely — detection
|
|
7
|
+
* keys on the distinctive local signals instead:
|
|
8
|
+
* - a dependency whose name mentions strapi (`@repo/strapi-types`,
|
|
9
|
+
* `@strapi/client`, generated types packages);
|
|
10
|
+
* - a `strapi`-named client module under `src/lib`/`src`;
|
|
11
|
+
* - Strapi's `api::x.y` content-type UID strings in the source;
|
|
12
|
+
* - a `STRAPI`-flavored base-URL env var.
|
|
13
|
+
* The co-located Strapi app (monorepo) is located by walking up to the
|
|
14
|
+
* workspace root and finding the sibling that depends on `@strapi/strapi`; its
|
|
15
|
+
* path drives schema import. A decoupled Strapi (no co-located app) still
|
|
16
|
+
* surfaces as a source for the keep-live decision, with `appDir: null`.
|
|
17
|
+
*/
|
|
18
|
+
const UID_RE = /["'`]api::[a-z0-9-]+\.[a-z0-9-]+["'`]/;
|
|
19
|
+
const STRAPI_ENV_RE = /STRAPI[A-Z0-9_]*_URL|NEXT_PUBLIC_STRAPI/;
|
|
20
|
+
const SOURCE_EXT_RE = /\.(tsx?|jsx?|mjs|cjs)$/;
|
|
21
|
+
const SKIP_DIRS = new Set(['node_modules', '.next', '.turbo', 'dist', 'build', '.git', 'coverage']);
|
|
22
|
+
const MAX_FILES_SCANNED = 400;
|
|
23
|
+
function safeReaddir(dir) {
|
|
24
|
+
try {
|
|
25
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function readDeps(dir) {
|
|
32
|
+
try {
|
|
33
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
34
|
+
return { ...pkg.dependencies, ...pkg.devDependencies };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function strapiDependency(deps) {
|
|
41
|
+
for (const name of Object.keys(deps)) {
|
|
42
|
+
if (/strapi/i.test(name)) {
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Shallow look for a `strapi`-named client module under src/lib or src. */
|
|
49
|
+
function strapiLibModule(frontendDir) {
|
|
50
|
+
for (const base of [join(frontendDir, 'src', 'lib'), join(frontendDir, 'src'), join(frontendDir, 'lib')]) {
|
|
51
|
+
if (!existsSync(base)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
for (const entry of readdirSync(base, { withFileTypes: true })) {
|
|
56
|
+
if (/strapi/i.test(entry.name)) {
|
|
57
|
+
return join(base, entry.name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// unreadable dir — ignore
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/** Bounded source scan for `api::x.y` UID strings or a STRAPI base-URL env. */
|
|
68
|
+
function scanSourceSignals(frontendDir) {
|
|
69
|
+
const root = existsSync(join(frontendDir, 'src')) ? join(frontendDir, 'src') : frontendDir;
|
|
70
|
+
let scanned = 0;
|
|
71
|
+
let uid = false;
|
|
72
|
+
let env = false;
|
|
73
|
+
const walk = (dir) => {
|
|
74
|
+
if (scanned >= MAX_FILES_SCANNED || (uid && env)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (const entry of safeReaddir(dir)) {
|
|
78
|
+
if (scanned >= MAX_FILES_SCANNED || (uid && env)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith('.')) {
|
|
83
|
+
walk(join(dir, entry.name));
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!SOURCE_EXT_RE.test(entry.name)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
scanned += 1;
|
|
91
|
+
try {
|
|
92
|
+
const text = readFileSync(join(dir, entry.name), 'utf8');
|
|
93
|
+
if (!uid && UID_RE.test(text)) {
|
|
94
|
+
uid = true;
|
|
95
|
+
}
|
|
96
|
+
if (!env && STRAPI_ENV_RE.test(text)) {
|
|
97
|
+
env = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// unreadable file — ignore
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
walk(root);
|
|
106
|
+
return { uid, env };
|
|
107
|
+
}
|
|
108
|
+
function findWorkspaceRoot(startDir) {
|
|
109
|
+
let dir = startDir;
|
|
110
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
111
|
+
if (existsSync(join(dir, 'pnpm-workspace.yaml')) ||
|
|
112
|
+
existsSync(join(dir, 'turbo.json')) ||
|
|
113
|
+
existsSync(join(dir, 'lerna.json'))) {
|
|
114
|
+
return dir;
|
|
115
|
+
}
|
|
116
|
+
const parent = dirname(dir);
|
|
117
|
+
if (parent === dir) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
dir = parent;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/** Find the sibling app that depends on `@strapi/strapi` (the CMS app). */
|
|
125
|
+
function findStrapiApp(frontendDir) {
|
|
126
|
+
const root = findWorkspaceRoot(frontendDir);
|
|
127
|
+
if (!root) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const searchRoots = [join(root, 'apps'), root, join(root, 'packages')];
|
|
131
|
+
for (const searchRoot of searchRoots) {
|
|
132
|
+
if (!existsSync(searchRoot)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
for (const entry of safeReaddir(searchRoot)) {
|
|
136
|
+
if (!entry.isDirectory() || SKIP_DIRS.has(entry.name)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const candidate = join(searchRoot, entry.name);
|
|
140
|
+
const deps = readDeps(candidate);
|
|
141
|
+
if (deps['@strapi/strapi'] && existsSync(join(candidate, 'src', 'api'))) {
|
|
142
|
+
return candidate;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
export function detectStrapi(frontendDir) {
|
|
149
|
+
if (!existsSync(frontendDir) || !statSync(frontendDir).isDirectory()) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const evidence = [];
|
|
153
|
+
const dep = strapiDependency(readDeps(frontendDir));
|
|
154
|
+
if (dep) {
|
|
155
|
+
evidence.push(`dependency ${dep}`);
|
|
156
|
+
}
|
|
157
|
+
const libModule = strapiLibModule(frontendDir);
|
|
158
|
+
if (libModule) {
|
|
159
|
+
evidence.push(`client module ${libModule.slice(frontendDir.length + 1)}`);
|
|
160
|
+
}
|
|
161
|
+
// Only pay for the source scan when the cheap signals are inconclusive.
|
|
162
|
+
if (evidence.length === 0) {
|
|
163
|
+
const signals = scanSourceSignals(frontendDir);
|
|
164
|
+
if (signals.uid) {
|
|
165
|
+
evidence.push('api::* content-type UIDs in source');
|
|
166
|
+
}
|
|
167
|
+
if (signals.env) {
|
|
168
|
+
evidence.push('STRAPI base-URL env var');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (evidence.length === 0) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const appDir = findStrapiApp(frontendDir);
|
|
175
|
+
if (appDir) {
|
|
176
|
+
evidence.push(`schemas in ${appDir.slice(findWorkspaceRoot(frontendDir).length + 1)}`);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
cms: 'Strapi',
|
|
180
|
+
host: 'Strapi',
|
|
181
|
+
appDir,
|
|
182
|
+
clientDir: libModule,
|
|
183
|
+
evidence,
|
|
184
|
+
locales: [],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, 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 { detectStrapi } from './detect.js';
|
|
6
|
+
let root;
|
|
7
|
+
function pkg(dir, deps) {
|
|
8
|
+
mkdirSync(dir, { recursive: true });
|
|
9
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 't', dependencies: deps }));
|
|
10
|
+
}
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
if (root) {
|
|
13
|
+
rmSync(root, { recursive: true, force: true });
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
describe('detectStrapi', () => {
|
|
17
|
+
it('detects Strapi in a monorepo via a types dep and locates the CMS app', () => {
|
|
18
|
+
root = mkdtempSync(join(tmpdir(), 'strapi-detect-'));
|
|
19
|
+
writeFileSync(join(root, 'pnpm-workspace.yaml'), 'packages:\n - apps/*\n');
|
|
20
|
+
const frontend = join(root, 'apps', 'ui');
|
|
21
|
+
pkg(frontend, { next: '^16.0.0', '@repo/strapi-types': 'workspace:*' });
|
|
22
|
+
const cms = join(root, 'apps', 'strapi');
|
|
23
|
+
pkg(cms, { '@strapi/strapi': '5.48.1' });
|
|
24
|
+
mkdirSync(join(cms, 'src', 'api'), { recursive: true });
|
|
25
|
+
const detection = detectStrapi(frontend);
|
|
26
|
+
expect(detection).not.toBeNull();
|
|
27
|
+
expect(detection.cms).toBe('Strapi');
|
|
28
|
+
expect(detection.host).toBe('Strapi');
|
|
29
|
+
expect(detection.appDir).toBe(cms);
|
|
30
|
+
expect(detection.evidence.some((e) => e.includes('@repo/strapi-types'))).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('detects Strapi via a strapi-named client module with no dependency', () => {
|
|
33
|
+
root = mkdtempSync(join(tmpdir(), 'strapi-detect-lib-'));
|
|
34
|
+
const frontend = join(root, 'app');
|
|
35
|
+
pkg(frontend, { next: '^16.0.0' });
|
|
36
|
+
mkdirSync(join(frontend, 'src', 'lib', 'strapi-api'), { recursive: true });
|
|
37
|
+
const detection = detectStrapi(frontend);
|
|
38
|
+
expect(detection).not.toBeNull();
|
|
39
|
+
expect(detection.evidence.some((e) => e.includes('strapi-api'))).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('detects a decoupled Strapi (SDK dep, no co-located app) with a null appDir', () => {
|
|
42
|
+
root = mkdtempSync(join(tmpdir(), 'strapi-detect-decoupled-'));
|
|
43
|
+
const frontend = join(root, 'frontend');
|
|
44
|
+
pkg(frontend, { next: '^16.0.0', '@strapi/client': '^1.0.0' });
|
|
45
|
+
const detection = detectStrapi(frontend);
|
|
46
|
+
expect(detection).not.toBeNull();
|
|
47
|
+
expect(detection.appDir).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
it('returns null when there is no Strapi signal', () => {
|
|
50
|
+
root = mkdtempSync(join(tmpdir(), 'strapi-detect-none-'));
|
|
51
|
+
const frontend = join(root, 'app');
|
|
52
|
+
pkg(frontend, { next: '^16.0.0', '@sanity/client': '^3.0.0' });
|
|
53
|
+
mkdirSync(join(frontend, 'src', 'components'), { recursive: true });
|
|
54
|
+
expect(detectStrapi(frontend)).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { detectStrapi } from './detect.js';
|
|
2
|
+
import { renderStrapiListSource } from './list-source.js';
|
|
3
|
+
import { readStrapiSchemas } from './schema-map.js';
|
|
4
|
+
import { detectStrapiTouchpoints } from './touchpoints.js';
|
|
5
|
+
import { wireStrapiClient } from './wire-client.js';
|
|
6
|
+
/** Assemble the Strapi connector for a wrapped frontend, or null if no Strapi. */
|
|
7
|
+
export function strapiConnector(frontendDir) {
|
|
8
|
+
const detection = detectStrapi(frontendDir);
|
|
9
|
+
if (!detection) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
detection,
|
|
14
|
+
readSchemas: () => (detection.appDir ? readStrapiSchemas(detection.appDir) : []),
|
|
15
|
+
renderListSource: (schemas, serverImport) => schemas.length > 0 ? renderStrapiListSource(schemas, serverImport) : null,
|
|
16
|
+
wireClient: (cwd, schemas) => detection.clientDir
|
|
17
|
+
? wireStrapiClient(cwd, detection.clientDir, schemas)
|
|
18
|
+
: {
|
|
19
|
+
changes: [],
|
|
20
|
+
warnings: ['No Strapi client directory detected — wire fimoStrapiFetch manually.'],
|
|
21
|
+
wired: false,
|
|
22
|
+
},
|
|
23
|
+
detectTouchpoints: (cwd) => detectStrapiTouchpoints(cwd),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CmsCollectionSchema } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emit a GENERIC Strapi-list read helper as source text. The scaffold pushes a
|
|
4
|
+
* CMS model + example content into Fimo; this helper lets a site's LIST views
|
|
5
|
+
* render that example content from Fimo (detail views + dynamic zones stay on
|
|
6
|
+
* the CMS). It is intentionally best-effort and site-neutral — the agent drops
|
|
7
|
+
* it in and wires the site's list fetchers to it (the non-deterministic last
|
|
8
|
+
* mile the machine can't own).
|
|
9
|
+
*
|
|
10
|
+
* The reshape is grounded in the Fimo runtime contract (`fetchEntries` →
|
|
11
|
+
* `{ id, data }`, media fields `{ url, ... }`, richtext fields a ProseMirror
|
|
12
|
+
* doc): richtext docs are flattened to plain text (so list helpers like a
|
|
13
|
+
* read-time estimate that expect a string don't choke), media and scalars pass
|
|
14
|
+
* through, and an empty Fimo result returns null so the caller falls back to
|
|
15
|
+
* the live CMS.
|
|
16
|
+
*/
|
|
17
|
+
export declare function renderStrapiListSource(schemas: CmsCollectionSchema[], serverImport: string): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit a GENERIC Strapi-list read helper as source text. The scaffold pushes a
|
|
3
|
+
* CMS model + example content into Fimo; this helper lets a site's LIST views
|
|
4
|
+
* render that example content from Fimo (detail views + dynamic zones stay on
|
|
5
|
+
* the CMS). It is intentionally best-effort and site-neutral — the agent drops
|
|
6
|
+
* it in and wires the site's list fetchers to it (the non-deterministic last
|
|
7
|
+
* mile the machine can't own).
|
|
8
|
+
*
|
|
9
|
+
* The reshape is grounded in the Fimo runtime contract (`fetchEntries` →
|
|
10
|
+
* `{ id, data }`, media fields `{ url, ... }`, richtext fields a ProseMirror
|
|
11
|
+
* doc): richtext docs are flattened to plain text (so list helpers like a
|
|
12
|
+
* read-time estimate that expect a string don't choke), media and scalars pass
|
|
13
|
+
* through, and an empty Fimo result returns null so the caller falls back to
|
|
14
|
+
* the live CMS.
|
|
15
|
+
*/
|
|
16
|
+
export function renderStrapiListSource(schemas, serverImport) {
|
|
17
|
+
const entries = schemas
|
|
18
|
+
.filter((schema) => !schema.isSingleton)
|
|
19
|
+
.map((schema) => ` '${schema.sourceUid}': '${schema.name}',`)
|
|
20
|
+
.join('\n');
|
|
21
|
+
return `// AUTO-GENERATED by \`fimo migrate --scaffold-cms\`. Renders the CMS collections
|
|
22
|
+
// scaffolded into Fimo (EXAMPLE content) for LIST views, so pages show the fake
|
|
23
|
+
// content from Fimo while detail views and dynamic zones stay on your CMS.
|
|
24
|
+
//
|
|
25
|
+
// Wire your CMS client's list methods to this (see the migration prompt), e.g.
|
|
26
|
+
// inside fetchMany/fetchAll: const fimo = await fimoCmsList(uid, { limit });
|
|
27
|
+
// if (fimo) return fimo;
|
|
28
|
+
// Best-effort and generic by design — adjust per component as needed.
|
|
29
|
+
import { fetchEntries } from '${serverImport}';
|
|
30
|
+
|
|
31
|
+
// Strapi content-type UID -> Fimo type name (from the scaffold).
|
|
32
|
+
const FIMO_TYPES: Record<string, string> = {
|
|
33
|
+
${entries}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function docToText(node: unknown): string {
|
|
37
|
+
if (!node || typeof node !== 'object') {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
const record = node as { text?: unknown; content?: unknown };
|
|
41
|
+
if (typeof record.text === 'string') {
|
|
42
|
+
return record.text;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(record.content)) {
|
|
45
|
+
return record.content.map(docToText).join(' ');
|
|
46
|
+
}
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function reshapeValue(value: unknown): unknown {
|
|
51
|
+
// Richtext is a ProseMirror doc -> flatten to plain text so string consumers
|
|
52
|
+
// (excerpts, read-time) are safe. Media { url, ... } and scalars pass through.
|
|
53
|
+
if (value && typeof value === 'object' && (value as { type?: unknown }).type === 'doc') {
|
|
54
|
+
return docToText(value);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function reshape(data: Record<string, unknown>): Record<string, unknown> {
|
|
60
|
+
const out: Record<string, unknown> = {};
|
|
61
|
+
for (const [key, value] of Object.entries(data)) {
|
|
62
|
+
out[key] = reshapeValue(value);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A Strapi-v5-shaped list envelope built from the scaffolded Fimo content, or
|
|
69
|
+
* null when nothing was scaffolded for this UID (fall back to the live CMS).
|
|
70
|
+
*/
|
|
71
|
+
export async function fimoCmsList(
|
|
72
|
+
uid: string,
|
|
73
|
+
options: { limit?: number } = {}
|
|
74
|
+
): Promise<{ data: Record<string, unknown>[]; meta: { pagination: Record<string, number> } } | null> {
|
|
75
|
+
const typeName = FIMO_TYPES[uid];
|
|
76
|
+
if (!typeName) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const entries = await fetchEntries(typeName, options.limit ? { limit: options.limit } : {});
|
|
80
|
+
if (entries.length === 0) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const data = entries.map((entry) => ({ id: entry.id, documentId: entry.id, ...reshape(entry.data) }));
|
|
84
|
+
return {
|
|
85
|
+
data,
|
|
86
|
+
meta: { pagination: { page: 1, pageSize: data.length, pageCount: 1, total: data.length } },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { renderStrapiListSource } from './list-source.js';
|
|
3
|
+
const schema = (name, sourceUid, isSingleton = false) => ({
|
|
4
|
+
name,
|
|
5
|
+
label: name,
|
|
6
|
+
isSingleton,
|
|
7
|
+
localized: false,
|
|
8
|
+
fields: {},
|
|
9
|
+
sourceUid,
|
|
10
|
+
sourcePath: `/${name.toLowerCase()}`,
|
|
11
|
+
});
|
|
12
|
+
describe('renderStrapiListSource', () => {
|
|
13
|
+
it('emits a helper importing fetchEntries with a uid→type map for collections only', () => {
|
|
14
|
+
const src = renderStrapiListSource([
|
|
15
|
+
schema('BlogPost', 'api::blog-post.blog-post'),
|
|
16
|
+
schema('PostTag', 'api::post-tag.post-tag'),
|
|
17
|
+
schema('Global', 'api::global.global', true),
|
|
18
|
+
], 'fimo/next/server');
|
|
19
|
+
expect(src).toContain("import { fetchEntries } from 'fimo/next/server';");
|
|
20
|
+
expect(src).toContain("'api::blog-post.blog-post': 'BlogPost',");
|
|
21
|
+
expect(src).toContain("'api::post-tag.post-tag': 'PostTag',");
|
|
22
|
+
// Singletons have no list view — excluded from the map.
|
|
23
|
+
expect(src).not.toContain('api::global.global');
|
|
24
|
+
expect(src).toContain('export async function fimoCmsList(');
|
|
25
|
+
// Richtext flattening + fallback-to-CMS contract are present.
|
|
26
|
+
expect(src).toContain('docToText');
|
|
27
|
+
expect(src).toContain('return null');
|
|
28
|
+
});
|
|
29
|
+
it('threads the framework server import through', () => {
|
|
30
|
+
const src = renderStrapiListSource([schema('Cms', 'api::cms.cms')], 'fimo/astro/server');
|
|
31
|
+
expect(src).toContain("import { fetchEntries } from 'fimo/astro/server';");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CmsCollectionSchema } from '../types.js';
|
|
2
|
+
/** `blog-post` / `blog_posts` / `Blog Post` → `BlogPost`. */
|
|
3
|
+
export declare function pascalCase(name: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Read every local Strapi content-type schema into the Fimo schema shape.
|
|
6
|
+
* Two passes: first name every type (so relation targets resolve to Fimo
|
|
7
|
+
* names), then map fields.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readStrapiSchemas(strapiAppDir: string): CmsCollectionSchema[];
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const TO_MANY = new Set(['oneToMany', 'manyToMany']);
|
|
4
|
+
/** `blog-post` / `blog_posts` / `Blog Post` → `BlogPost`. */
|
|
5
|
+
export function pascalCase(name) {
|
|
6
|
+
return name
|
|
7
|
+
.replace(/[^a-zA-Z0-9]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
|
|
8
|
+
.replace(/^(.)/, (c) => c.toUpperCase());
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Map one Strapi attribute to a Fimo field. Returns `null` for fields Fimo does
|
|
12
|
+
* not model as content (the slug uid, passwords). Relations to imported types
|
|
13
|
+
* become references; relations to non-imported targets (users, plugins) and
|
|
14
|
+
* structural fields (components, dynamic zones) fall back to `json` so example
|
|
15
|
+
* content round-trips and never dangles.
|
|
16
|
+
*/
|
|
17
|
+
function mapAttribute(field, attr, uidToName) {
|
|
18
|
+
if (field === 'slug') {
|
|
19
|
+
// Fimo reserves `slug` as entry metadata (set inside the row data).
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
switch (attr.type) {
|
|
23
|
+
case 'password':
|
|
24
|
+
return null;
|
|
25
|
+
case 'string':
|
|
26
|
+
case 'text':
|
|
27
|
+
case 'email':
|
|
28
|
+
case 'uid':
|
|
29
|
+
case 'enumeration':
|
|
30
|
+
return { type: 'string' };
|
|
31
|
+
case 'richtext':
|
|
32
|
+
case 'blocks':
|
|
33
|
+
return { type: 'richtext' };
|
|
34
|
+
case 'integer':
|
|
35
|
+
case 'biginteger':
|
|
36
|
+
case 'decimal':
|
|
37
|
+
case 'float':
|
|
38
|
+
return { type: 'number' };
|
|
39
|
+
case 'boolean':
|
|
40
|
+
return { type: 'boolean' };
|
|
41
|
+
case 'date':
|
|
42
|
+
case 'datetime':
|
|
43
|
+
case 'time':
|
|
44
|
+
case 'timestamp':
|
|
45
|
+
return { type: 'date' };
|
|
46
|
+
case 'media':
|
|
47
|
+
return { type: 'media' };
|
|
48
|
+
case 'json':
|
|
49
|
+
case 'component':
|
|
50
|
+
case 'dynamiczone':
|
|
51
|
+
return { type: 'json' };
|
|
52
|
+
case 'relation': {
|
|
53
|
+
const targetName = attr.target ? uidToName.get(attr.target) : undefined;
|
|
54
|
+
if (!targetName) {
|
|
55
|
+
// Relation to a non-imported target (users-permissions, other plugins).
|
|
56
|
+
return { type: 'json' };
|
|
57
|
+
}
|
|
58
|
+
const many = attr.relation ? TO_MANY.has(attr.relation) : false;
|
|
59
|
+
return many ? { type: 'reference', target: targetName, many: true } : { type: 'reference', target: targetName };
|
|
60
|
+
}
|
|
61
|
+
default:
|
|
62
|
+
// Unknown/custom attribute — never crash; keep the value verbatim.
|
|
63
|
+
return { type: 'json' };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function mapSchema(raw, uidToName) {
|
|
67
|
+
const info = raw.schema.info ?? {};
|
|
68
|
+
const name = uidToName.get(raw.uid);
|
|
69
|
+
const fields = {};
|
|
70
|
+
const examples = {};
|
|
71
|
+
for (const [field, attr] of Object.entries(raw.schema.attributes ?? {})) {
|
|
72
|
+
const mapped = mapAttribute(field, attr, uidToName);
|
|
73
|
+
if (mapped) {
|
|
74
|
+
fields[field] = mapped;
|
|
75
|
+
// Dynamic zones (and repeatable components) render as ARRAYS a page
|
|
76
|
+
// builder maps over; a single component as an OBJECT. Seed the correct
|
|
77
|
+
// empty shape so pages render instead of crashing on `{}.map(...)`.
|
|
78
|
+
if (attr.type === 'dynamiczone' || (attr.type === 'component' && attr.repeatable)) {
|
|
79
|
+
examples[field] = [];
|
|
80
|
+
}
|
|
81
|
+
else if (attr.type === 'component') {
|
|
82
|
+
examples[field] = {};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
label: info.displayName || name,
|
|
89
|
+
isSingleton: raw.schema.kind === 'singleType',
|
|
90
|
+
localized: raw.schema.pluginOptions?.i18n?.localized === true,
|
|
91
|
+
fields,
|
|
92
|
+
...(Object.keys(examples).length > 0 ? { examples } : {}),
|
|
93
|
+
sourceUid: raw.uid,
|
|
94
|
+
sourcePath: `/${info.pluralName ?? raw.contentTypeName}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Walk `<strapiAppDir>/src/api/<api>/content-types/<ct>/schema.json`. */
|
|
98
|
+
function collectRawSchemas(strapiAppDir) {
|
|
99
|
+
const apiDir = join(strapiAppDir, 'src', 'api');
|
|
100
|
+
if (!existsSync(apiDir)) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const raws = [];
|
|
104
|
+
for (const apiEntry of readdirSync(apiDir, { withFileTypes: true })) {
|
|
105
|
+
if (!apiEntry.isDirectory()) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const ctRoot = join(apiDir, apiEntry.name, 'content-types');
|
|
109
|
+
if (!existsSync(ctRoot)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (const ctEntry of readdirSync(ctRoot, { withFileTypes: true })) {
|
|
113
|
+
if (!ctEntry.isDirectory()) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const schemaPath = join(ctRoot, ctEntry.name, 'schema.json');
|
|
117
|
+
if (!existsSync(schemaPath)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const schema = JSON.parse(readFileSync(schemaPath, 'utf8'));
|
|
122
|
+
raws.push({
|
|
123
|
+
uid: `api::${apiEntry.name}.${ctEntry.name}`,
|
|
124
|
+
apiName: apiEntry.name,
|
|
125
|
+
contentTypeName: ctEntry.name,
|
|
126
|
+
schema,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Malformed schema.json — skip, never abort the whole import.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return raws;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Read every local Strapi content-type schema into the Fimo schema shape.
|
|
138
|
+
* Two passes: first name every type (so relation targets resolve to Fimo
|
|
139
|
+
* names), then map fields.
|
|
140
|
+
*/
|
|
141
|
+
export function readStrapiSchemas(strapiAppDir) {
|
|
142
|
+
const raws = collectRawSchemas(strapiAppDir);
|
|
143
|
+
const uidToName = new Map();
|
|
144
|
+
for (const raw of raws) {
|
|
145
|
+
const singular = raw.schema.info?.singularName ?? raw.contentTypeName;
|
|
146
|
+
uidToName.set(raw.uid, pascalCase(singular));
|
|
147
|
+
}
|
|
148
|
+
return raws.map((raw) => mapSchema(raw, uidToName)).sort((a, b) => a.name.localeCompare(b.name));
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|