@eldrajs/theme-cli 0.0.0 → 0.2.0
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/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +248 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +156 -0
- package/template/package.json +56 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/public/favicon.ico +0 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +335 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +85 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +387 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +164 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +170 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +49 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { RESERVED_THEME_IDS, THEME_ID_PATTERN, createEldraClient } from "@eldrajs/theme-core";
|
|
6
|
+
import * as tar from "tar";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { generateBlockTypes } from "@eldrajs/vite-plugin-theme";
|
|
9
|
+
import { readPreviousManifest, scanTheme } from "@eldrajs/vite-plugin-theme/scan";
|
|
10
|
+
//#region src/deployReport.ts
|
|
11
|
+
/** The drop reasons this version can say in words. Anything else prints as the
|
|
12
|
+
* code the gateway sent, so a reason added later is still reported. */
|
|
13
|
+
const DROP_REASONS = { "kind-not-offered": "the field does not offer that kind" };
|
|
14
|
+
/**
|
|
15
|
+
* Every line a deploy's field migrations are worth printing: the retirements,
|
|
16
|
+
* then for each converted field what it carried forward and one warning per
|
|
17
|
+
* group of rows it could not.
|
|
18
|
+
*
|
|
19
|
+
* Returned rather than logged so the wording is testable on its own — the
|
|
20
|
+
* deploy command only forwards these to its logger.
|
|
21
|
+
*/
|
|
22
|
+
function fieldMigrationLines(report) {
|
|
23
|
+
if (report === void 0 || report === null || typeof report !== "object") return [];
|
|
24
|
+
const lines = [];
|
|
25
|
+
for (const retired of asArray(report.retired)) lines.push(`retired ${retired.blockApiId}.${retired.fieldId} → ${retired.retiredAs} (${retired.reason}, ${retired.migratedCount} entries) — previous content is read-only in Studio`);
|
|
26
|
+
const converted = asArray(report.converted);
|
|
27
|
+
for (const entry of converted) {
|
|
28
|
+
lines.push(convertedLine(entry));
|
|
29
|
+
lines.push(...droppedWarnings(entry));
|
|
30
|
+
}
|
|
31
|
+
if (converted.length === 0) {
|
|
32
|
+
const totals = totalsLine(report);
|
|
33
|
+
if (totals !== null) lines.push(totals);
|
|
34
|
+
}
|
|
35
|
+
return lines;
|
|
36
|
+
}
|
|
37
|
+
function convertedLine(entry) {
|
|
38
|
+
const parts = [units(count(entry.convertedCount ?? entry.count), "entry", "entries")];
|
|
39
|
+
const fallbacks = count(entry.urlFallbacks);
|
|
40
|
+
if (fallbacks > 0) parts.push(fallbacks === 1 ? "1 link kept its URL" : `${fallbacks} links kept their URL`);
|
|
41
|
+
return `converted ${where(entry)} (${parts.join(", ")})`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One warning per group of dropped rows, naming the kind first: the kind is
|
|
45
|
+
* what an author has to change, and the reason says why.
|
|
46
|
+
*/
|
|
47
|
+
function droppedWarnings(entry) {
|
|
48
|
+
const target = `${blockOf(entry)}.${fieldOf(entry)}`;
|
|
49
|
+
return asArray(entry.dropped).filter((row) => count(row.count) > 0).map((row) => {
|
|
50
|
+
const rows = count(row.count);
|
|
51
|
+
return `warning: dropped ${rows}${typeof row.kind === "string" && row.kind.trim() !== "" ? ` "${row.kind}"` : ""} ${rows === 1 ? "row" : "rows"} from ${target} — ${reasonText(row.reason)}`;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** `block.from → field`: which field was read and which was written. */
|
|
55
|
+
function where(entry) {
|
|
56
|
+
const field = fieldOf(entry);
|
|
57
|
+
const from = typeof entry.from === "string" && entry.from.trim() !== "" ? entry.from : field;
|
|
58
|
+
return `${blockOf(entry)}.${from} → ${field}`;
|
|
59
|
+
}
|
|
60
|
+
function blockOf(entry) {
|
|
61
|
+
return nameOf(entry.blockApiId ?? entry.block);
|
|
62
|
+
}
|
|
63
|
+
function fieldOf(entry) {
|
|
64
|
+
return nameOf(entry.fieldId ?? entry.field);
|
|
65
|
+
}
|
|
66
|
+
function reasonText(reason) {
|
|
67
|
+
const code = nameOf(reason);
|
|
68
|
+
return DROP_REASONS[code] ?? code;
|
|
69
|
+
}
|
|
70
|
+
function totalsLine(report) {
|
|
71
|
+
const converted = count(report.convertedCount);
|
|
72
|
+
const dropped = count(report.droppedCount);
|
|
73
|
+
if (converted === 0 && dropped === 0) return null;
|
|
74
|
+
if (converted === 0) return `dropped ${units(dropped, "row", "rows")} during the link conversion`;
|
|
75
|
+
const clauses = [`converted ${units(converted, "entry", "entries")} into link fields`];
|
|
76
|
+
if (dropped > 0) clauses.push(`${dropped} dropped`);
|
|
77
|
+
return clauses.join("; ");
|
|
78
|
+
}
|
|
79
|
+
function units(n, one, many) {
|
|
80
|
+
return `${n} ${n === 1 ? one : many}`;
|
|
81
|
+
}
|
|
82
|
+
function count(value) {
|
|
83
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0;
|
|
84
|
+
}
|
|
85
|
+
function nameOf(value) {
|
|
86
|
+
return typeof value === "string" && value.trim() !== "" ? value : "?";
|
|
87
|
+
}
|
|
88
|
+
function asArray(value) {
|
|
89
|
+
return Array.isArray(value) ? value : [];
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/urls.ts
|
|
93
|
+
/**
|
|
94
|
+
* Strips every trailing `/` from a URL (`https://x///` → `https://x`). A
|
|
95
|
+
* regex equivalent (`/\/+$/`) backtracks polynomially on a long run of
|
|
96
|
+
* slashes because the engine re-tries every split of the repeated group
|
|
97
|
+
* before failing to match past the string's end; this walks the string once
|
|
98
|
+
* from the end instead, which is linear regardless of how many slashes it
|
|
99
|
+
* finds. Shared by `deploy` and `validate`, both of which take a gateway/API
|
|
100
|
+
* URL from the caller (CLI flag or env var) and need it with no trailing
|
|
101
|
+
* slash before joining a path onto it.
|
|
102
|
+
*/
|
|
103
|
+
function stripTrailingSlashes(value) {
|
|
104
|
+
let end = value.length;
|
|
105
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) end--;
|
|
106
|
+
return value.slice(0, end);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/commands/deploy.ts
|
|
110
|
+
const MAX_FILES = 2e4;
|
|
111
|
+
const MAX_FILE_BYTES = 26214400;
|
|
112
|
+
const MAX_DESIGN_TOKEN_MAPPING_BYTES = 16384;
|
|
113
|
+
const DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
114
|
+
const DEFAULT_TIMEOUT_MS = 6e5;
|
|
115
|
+
const TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
116
|
+
"SUCCESS",
|
|
117
|
+
"FAILED",
|
|
118
|
+
"CANCELED"
|
|
119
|
+
]);
|
|
120
|
+
const BUILD_DIR_CANDIDATES = [".output/public", "dist"];
|
|
121
|
+
var DeployError = class extends Error {
|
|
122
|
+
code;
|
|
123
|
+
constructor(message, code = null) {
|
|
124
|
+
super(message);
|
|
125
|
+
this.code = code;
|
|
126
|
+
this.name = "DeployError";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function detectCommitSha(env) {
|
|
130
|
+
return env.GITHUB_SHA ?? env.CI_COMMIT_SHA ?? env.BITBUCKET_COMMIT ?? null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Refuses a build whose manifest does not declare a theme id before anything is
|
|
134
|
+
* uploaded: Core rejects it too, but this names the file and the fix. A stale
|
|
135
|
+
* build from before manifest v2 reads as "rebuild", not as a server error.
|
|
136
|
+
*/
|
|
137
|
+
async function assertManifestIdentity(manifestPath, cwd) {
|
|
138
|
+
const file = relative(cwd, manifestPath);
|
|
139
|
+
let manifest;
|
|
140
|
+
try {
|
|
141
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
142
|
+
} catch {
|
|
143
|
+
throw new DeployError(`deploy: ${file} is not valid JSON — rebuild the theme`);
|
|
144
|
+
}
|
|
145
|
+
const record = (value) => typeof value === "object" && value !== null ? value : {};
|
|
146
|
+
const root = record(manifest);
|
|
147
|
+
if (root.manifestVersion !== 2) throw new DeployError(`deploy: ${file} has manifestVersion ${JSON.stringify(root.manifestVersion)}; this kit emits manifestVersion 2 — rebuild the theme with the current @eldrajs/vite-plugin-theme`);
|
|
148
|
+
const id = record(root.theme).id;
|
|
149
|
+
if (typeof id !== "string" || !THEME_ID_PATTERN.test(id) || RESERVED_THEME_IDS.includes(id)) throw new DeployError(`deploy: ${file} theme.id is missing or invalid (got ${JSON.stringify(id)}); declare "eldra": { "themeId": "<id>" } in package.json and rebuild`);
|
|
150
|
+
}
|
|
151
|
+
async function deployTheme(opts) {
|
|
152
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
153
|
+
const doFetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
154
|
+
const log = opts.log ?? console.log;
|
|
155
|
+
const apiUrl = stripTrailingSlashes(opts.apiUrl);
|
|
156
|
+
if (opts.token === "") throw new DeployError("deploy: empty token (--token or ELDRA_DEPLOY_TOKEN)");
|
|
157
|
+
const dir = opts.dir !== void 0 ? join(cwd, opts.dir) : detectBuildDir(cwd);
|
|
158
|
+
const manifestPath = join(dir, ".eldra", "manifest.json");
|
|
159
|
+
if (!existsSync(manifestPath)) throw new DeployError(`deploy: ${relative(cwd, manifestPath)} not found — run your build (e.g. \`nuxi generate\`) first; the Eldra vite plugin emits the manifest into the build output`);
|
|
160
|
+
await assertManifestIdentity(manifestPath, cwd);
|
|
161
|
+
preflight(dir, cwd);
|
|
162
|
+
const tmp = await mkdtemp(join(tmpdir(), "eldra-deploy-"));
|
|
163
|
+
const tarPath = join(tmp, "artifact.tar.gz");
|
|
164
|
+
try {
|
|
165
|
+
const archiveEntries = readdirSync(dir).sort((left, right) => left.localeCompare(right, "en-US"));
|
|
166
|
+
await tar.create({
|
|
167
|
+
gzip: true,
|
|
168
|
+
cwd: dir,
|
|
169
|
+
portable: true,
|
|
170
|
+
file: tarPath
|
|
171
|
+
}, archiveEntries);
|
|
172
|
+
const form = new FormData();
|
|
173
|
+
form.append("manifest", new Blob([await readFile(manifestPath)], { type: "application/json" }), "manifest.json");
|
|
174
|
+
if (opts.designTokenMapping) {
|
|
175
|
+
const mappingPath = join(cwd, opts.designTokenMapping);
|
|
176
|
+
const mapping = await readFile(mappingPath).catch(() => {
|
|
177
|
+
throw new DeployError(`deploy: ${opts.designTokenMapping} not found`);
|
|
178
|
+
});
|
|
179
|
+
if (mapping.byteLength > MAX_DESIGN_TOKEN_MAPPING_BYTES) throw new DeployError("deploy: design token mapping exceeds the 16 KiB limit");
|
|
180
|
+
try {
|
|
181
|
+
JSON.parse(new TextDecoder().decode(mapping));
|
|
182
|
+
} catch {
|
|
183
|
+
throw new DeployError("deploy: design token mapping must be valid JSON");
|
|
184
|
+
}
|
|
185
|
+
form.append("designTokenMapping", new Blob([mapping], { type: "application/json" }), "design-token-mapping.json");
|
|
186
|
+
}
|
|
187
|
+
const commitSha = opts.commitSha ?? detectCommitSha(process.env);
|
|
188
|
+
if (commitSha) form.append("commitSha", commitSha);
|
|
189
|
+
const triggerId = opts.triggerDeploymentId ?? process.env.ELDRA_TRIGGER_DEPLOYMENT_ID;
|
|
190
|
+
if (triggerId) form.append("triggerDeploymentId", triggerId);
|
|
191
|
+
form.append("artifact", new Blob([await readFile(tarPath)], { type: "application/gzip" }), "artifact.tar.gz");
|
|
192
|
+
const res = await doFetch(`${apiUrl}/sites/v1/public/deploys`, {
|
|
193
|
+
method: "POST",
|
|
194
|
+
headers: { authorization: `Bearer ${opts.token}` },
|
|
195
|
+
body: form
|
|
196
|
+
});
|
|
197
|
+
if (res.status !== 202) throw await toDeployError(res);
|
|
198
|
+
const accepted = await res.json();
|
|
199
|
+
const syncResult = accepted.syncResult;
|
|
200
|
+
log(`deployment ${accepted.deploymentId} accepted — blocks +${syncResult.created.length} ~${syncResult.updated.length} -${syncResult.removed.length}`);
|
|
201
|
+
for (const w of syncResult.warnings) log(`warning: ${w}`);
|
|
202
|
+
for (const line of fieldMigrationLines(syncResult.fieldMigrations)) log(line);
|
|
203
|
+
const deadline = Date.now() + (opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
204
|
+
let lastStatus = "";
|
|
205
|
+
for (;;) {
|
|
206
|
+
const poll = await doFetch(`${apiUrl}/sites/v1/public/deploys/${accepted.deploymentId}`, { headers: { authorization: `Bearer ${opts.token}` } });
|
|
207
|
+
if (!poll.ok) throw await toDeployError(poll);
|
|
208
|
+
const deployment = await poll.json();
|
|
209
|
+
if (deployment.status !== lastStatus) {
|
|
210
|
+
lastStatus = deployment.status;
|
|
211
|
+
log(`status: ${deployment.status}`);
|
|
212
|
+
}
|
|
213
|
+
if (TERMINAL_STATUSES.has(deployment.status)) {
|
|
214
|
+
if (deployment.status !== "SUCCESS") throw new DeployError(`deploy ${deployment.status}${deployment.logExcerpt ? `: ${deployment.logExcerpt}` : ""}`);
|
|
215
|
+
return {
|
|
216
|
+
deploymentId: accepted.deploymentId,
|
|
217
|
+
status: "SUCCESS",
|
|
218
|
+
previewUrl: deployment.previewUrl ?? null,
|
|
219
|
+
syncResult
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (Date.now() >= deadline) throw new DeployError(`deploy: timed out after ${Math.round((opts.timeoutMs ?? DEFAULT_TIMEOUT_MS) / 6e4)} min waiting for deployment ${accepted.deploymentId} (last status ${deployment.status})`);
|
|
223
|
+
await new Promise((resolve) => setTimeout(resolve, opts.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS));
|
|
224
|
+
}
|
|
225
|
+
} finally {
|
|
226
|
+
await rm(tmp, {
|
|
227
|
+
recursive: true,
|
|
228
|
+
force: true
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function detectBuildDir(cwd) {
|
|
233
|
+
for (const c of BUILD_DIR_CANDIDATES) {
|
|
234
|
+
const p = join(cwd, c);
|
|
235
|
+
if (existsSync(p) && statSync(p).isDirectory()) return p;
|
|
236
|
+
}
|
|
237
|
+
throw new DeployError(`deploy: no build output found — looked for ${BUILD_DIR_CANDIDATES.join(", ")} under ${cwd}. Run your build first or pass --dir <path>.`);
|
|
238
|
+
}
|
|
239
|
+
function preflight(dir, cwd) {
|
|
240
|
+
let count = 0;
|
|
241
|
+
const walk = (p) => {
|
|
242
|
+
for (const name of readdirSync(p)) {
|
|
243
|
+
const full = join(p, name);
|
|
244
|
+
const st = lstatSync(full);
|
|
245
|
+
if (st.isSymbolicLink()) throw new DeployError(`deploy: ${relative(cwd, full)} is a symlink — the artifact must contain only regular files`);
|
|
246
|
+
if (st.isDirectory()) {
|
|
247
|
+
walk(full);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (name === "_worker.js" || name === "_worker.bundle") throw new DeployError(`deploy: ${relative(cwd, full)} is not supported — v1 accepts static assets only; Cloudflare Pages Functions and Worker bundles are rejected`);
|
|
251
|
+
count++;
|
|
252
|
+
if (count > MAX_FILES) throw new DeployError(`deploy: build output exceeds ${MAX_FILES.toLocaleString("en-US")} files`);
|
|
253
|
+
if (st.size > MAX_FILE_BYTES) throw new DeployError(`deploy: ${relative(cwd, full)} is ${(st.size / 1048576).toFixed(1)} MiB — exceeds the 25 MiB/file v1 limit`);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
walk(dir);
|
|
257
|
+
}
|
|
258
|
+
async function toDeployError(res) {
|
|
259
|
+
let body = null;
|
|
260
|
+
let bodyUnparseable = false;
|
|
261
|
+
try {
|
|
262
|
+
body = await res.json();
|
|
263
|
+
} catch {
|
|
264
|
+
bodyUnparseable = true;
|
|
265
|
+
}
|
|
266
|
+
const detail = body?.detail ?? null;
|
|
267
|
+
if (body?.errorId === "THEME_FIELD_INCOMPATIBLE" && body.errors?.activationRefusal?.locations) {
|
|
268
|
+
const seen = /* @__PURE__ */ new Set();
|
|
269
|
+
const lines = [];
|
|
270
|
+
for (const location of body.errors.activationRefusal.locations) {
|
|
271
|
+
const key = `${location.blockApiId}.${location.fieldId}: ${location.reason}`;
|
|
272
|
+
if (seen.has(key)) continue;
|
|
273
|
+
seen.add(key);
|
|
274
|
+
lines.push(` ${key}`);
|
|
275
|
+
}
|
|
276
|
+
return new DeployError([`deploy: ${detail ?? "theme content compatibility requires confirmation"}`, ...lines].join("\n"), body.errorId);
|
|
277
|
+
}
|
|
278
|
+
const messages = {
|
|
279
|
+
SITE_DEPLOY_TOKEN_INVALID: "token invalid or revoked — generate a new token in Studio (Settings → Site → Deploy token)",
|
|
280
|
+
SITE_ARTIFACT_TOO_LARGE: "artifact exceeds limits (≤ 20,000 files, ≤ 25 MiB/file, ≤ 500 MiB unpacked, ≤ 200 MiB compressed)",
|
|
281
|
+
SITE_ARTIFACT_INVALID: "artifact rejected (path traversal or symlink entries)",
|
|
282
|
+
SITE_MANIFEST_INVALID: "manifest rejected by ingest — run `eldra-theme validate` locally",
|
|
283
|
+
SITE_MANIFEST_TOO_LARGE: "manifest exceeds the 2 MiB limit — reduce block metadata and mock content, rebuild, and redeploy",
|
|
284
|
+
SITE_DEPLOY_RATE_LIMITED: "deploy rate limit hit — wait a few minutes, then retry"
|
|
285
|
+
};
|
|
286
|
+
if (res.status === 413 && bodyUnparseable) return new DeployError("deploy: gateway responded 413 (payload too large) with no error body — a proxy/CDN in front of it may have a smaller limit than the app's own (≤ 20,000 files, ≤ 25 MiB/file, ≤ 500 MiB unpacked, ≤ 200 MiB compressed), or the request exceeds one of those; check the artifact size, and if it is within them ask infra about the proxy limit");
|
|
287
|
+
return new DeployError(`deploy: ${messages[detail ?? ""] ?? `gateway responded ${res.status}${detail ? ` (${detail})` : ""}`}`, detail);
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/templateExclude.mjs
|
|
291
|
+
/** A directory with this name, at any depth, is never copied. */
|
|
292
|
+
const EXCLUDE_DIR_NAMES = [
|
|
293
|
+
"node_modules",
|
|
294
|
+
".git",
|
|
295
|
+
".nuxt",
|
|
296
|
+
".output",
|
|
297
|
+
"storybook-static",
|
|
298
|
+
"coverage",
|
|
299
|
+
"test-results",
|
|
300
|
+
"playwright-report",
|
|
301
|
+
".cache"
|
|
302
|
+
];
|
|
303
|
+
/**
|
|
304
|
+
* A directory excluded only directly under one specific parent — unlike the names above,
|
|
305
|
+
* "previews" alone is a real, authored directory name (e.g. a block could be named that), so
|
|
306
|
+
* only `.eldra/previews` (the generated preview screenshots) is excluded.
|
|
307
|
+
*/
|
|
308
|
+
const EXCLUDE_NESTED_DIRS = [{
|
|
309
|
+
parent: ".eldra",
|
|
310
|
+
name: "previews"
|
|
311
|
+
}];
|
|
312
|
+
/**
|
|
313
|
+
* `cpSync`'s `filter` predicate: false skips the path (and, for a directory, everything under
|
|
314
|
+
* it). `path` is an absolute filesystem path; only its segments matter here.
|
|
315
|
+
*
|
|
316
|
+
* @param {string} path
|
|
317
|
+
* @returns {boolean}
|
|
318
|
+
*/
|
|
319
|
+
function shouldCopyTemplatePath(path) {
|
|
320
|
+
const parts = path.split(/[\\/]/);
|
|
321
|
+
if (parts.some((part) => EXCLUDE_DIR_NAMES.includes(part))) return false;
|
|
322
|
+
return !parts.some((part, index) => EXCLUDE_NESTED_DIRS.some((nested) => part === nested.parent && parts[index + 1] === nested.name));
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/commands/init.ts
|
|
326
|
+
function initTheme(targetDir) {
|
|
327
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) throw new Error(`init: target directory ${targetDir} is not empty`);
|
|
328
|
+
const source = templateSource();
|
|
329
|
+
cpSync(source, targetDir, {
|
|
330
|
+
recursive: true,
|
|
331
|
+
filter: shouldCopyTemplatePath
|
|
332
|
+
});
|
|
333
|
+
rewriteWorkspaceVersions(join(targetDir, "package.json"));
|
|
334
|
+
}
|
|
335
|
+
function rewriteWorkspaceVersions(packagePath) {
|
|
336
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
337
|
+
for (const group of [packageJson.dependencies, packageJson.devDependencies]) {
|
|
338
|
+
if (group === void 0) continue;
|
|
339
|
+
for (const [name, version] of Object.entries(group)) if (name.startsWith("@eldrajs/") && version.startsWith("workspace:")) group[name] = "^0.1.0";
|
|
340
|
+
}
|
|
341
|
+
writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
342
|
+
}
|
|
343
|
+
function templateSource() {
|
|
344
|
+
const source = [
|
|
345
|
+
new URL("../template", import.meta.url),
|
|
346
|
+
new URL("../../template", import.meta.url),
|
|
347
|
+
new URL("../../../examples/starter-nuxt", import.meta.url),
|
|
348
|
+
new URL("../../../../examples/starter-nuxt", import.meta.url)
|
|
349
|
+
].map((url) => fileURLToPath(url)).find((candidate) => existsSync(join(candidate, "package.json")));
|
|
350
|
+
if (source === void 0) throw new Error("starter template not found (package built without template/)");
|
|
351
|
+
return source;
|
|
352
|
+
}
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/commands/scaffold.ts
|
|
355
|
+
const API_ID_RE = /^[a-z][a-z0-9-]{1,48}$/;
|
|
356
|
+
function scaffoldBlock(opts) {
|
|
357
|
+
if (!API_ID_RE.test(opts.apiId)) throw new Error(`scaffoldBlock: apiId "${opts.apiId}" must match ${API_ID_RE.source}`);
|
|
358
|
+
const dir = join(opts.themeDir, "blocks", opts.apiId);
|
|
359
|
+
if (existsSync(dir)) throw new Error(`scaffoldBlock: blocks/${opts.apiId} already exists`);
|
|
360
|
+
const name = opts.name ?? titleCase(opts.apiId);
|
|
361
|
+
const fields = opts.fields ?? [{
|
|
362
|
+
fieldId: "title",
|
|
363
|
+
name: "Title",
|
|
364
|
+
type: "string",
|
|
365
|
+
isTitle: true,
|
|
366
|
+
localized: true,
|
|
367
|
+
validators: { required: true }
|
|
368
|
+
}];
|
|
369
|
+
if (fields.length === 0) throw new Error("scaffoldBlock: fields must contain at least one field");
|
|
370
|
+
const firstFieldId = fields[0]?.fieldId;
|
|
371
|
+
if (typeof firstFieldId !== "string" || firstFieldId === "") throw new Error("scaffoldBlock: first field must have a non-empty fieldId");
|
|
372
|
+
const block = {
|
|
373
|
+
apiId: opts.apiId,
|
|
374
|
+
name,
|
|
375
|
+
category: opts.category ?? "general",
|
|
376
|
+
version: 1,
|
|
377
|
+
fields
|
|
378
|
+
};
|
|
379
|
+
const mock = {};
|
|
380
|
+
for (const field of fields) if ((field.type === "string" || field.type === "text") && typeof field.fieldId === "string") mock[field.fieldId] = `${name} ${field.fieldId}`;
|
|
381
|
+
const component = [
|
|
382
|
+
"<script setup lang=\"ts\">",
|
|
383
|
+
"defineProps<{ entry: { id: string; data: Record<string, unknown> } }>();",
|
|
384
|
+
"<\/script>",
|
|
385
|
+
"",
|
|
386
|
+
"<template>",
|
|
387
|
+
` <section class="${opts.apiId}">`,
|
|
388
|
+
` <h2>{{ entry.data.${firstFieldId} }}</h2>`,
|
|
389
|
+
" </section>",
|
|
390
|
+
"</template>",
|
|
391
|
+
""
|
|
392
|
+
].join("\n");
|
|
393
|
+
mkdirSync(dir, { recursive: true });
|
|
394
|
+
const created = [
|
|
395
|
+
join(dir, "block.json"),
|
|
396
|
+
join(dir, "Block.vue"),
|
|
397
|
+
join(dir, "mock.json")
|
|
398
|
+
];
|
|
399
|
+
writeFileSync(created[0], `${JSON.stringify(block, null, 2)}\n`);
|
|
400
|
+
writeFileSync(created[1], component);
|
|
401
|
+
writeFileSync(created[2], `${JSON.stringify(mock, null, 2)}\n`);
|
|
402
|
+
return { created };
|
|
403
|
+
}
|
|
404
|
+
function titleCase(apiId) {
|
|
405
|
+
return apiId.split("-").map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join(" ");
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/commands/types.ts
|
|
409
|
+
async function generateTypes(opts) {
|
|
410
|
+
const definitions = await createEldraClient({
|
|
411
|
+
gatewayUrl: opts.gatewayUrl,
|
|
412
|
+
orgId: opts.orgId,
|
|
413
|
+
fetch: opts.fetch
|
|
414
|
+
}).getTypeScriptDefinitions({
|
|
415
|
+
schemas: opts.schemas,
|
|
416
|
+
moduleName: "Eldra"
|
|
417
|
+
});
|
|
418
|
+
const target = resolve(opts.themeDir, opts.out);
|
|
419
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
420
|
+
writeFileSync(target, definitions.endsWith("\n") ? definitions : `${definitions}\n`);
|
|
421
|
+
return target;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* `eldra-theme types --blocks`: scans every block's `block.json` and writes
|
|
425
|
+
* only `.eldra/block-types.d.ts` — no gateway involved, unlike `generateTypes`
|
|
426
|
+
* above (which fetches the org's CMS schema types). Mirrors what the Vite
|
|
427
|
+
* plugin writes on every scan (`plugin.ts`'s `writeBlockTypes`), for a
|
|
428
|
+
* consumer that wants the file without running a dev server or build.
|
|
429
|
+
*/
|
|
430
|
+
function generateBlockTypesFile(opts) {
|
|
431
|
+
const scan = scanTheme({ themeDir: opts.themeDir });
|
|
432
|
+
if (scan.manifest === null) throw new Error(`types --blocks: theme validation failed:\n ${scan.errors.join("\n ")}`);
|
|
433
|
+
const target = join(opts.themeDir, ".eldra", "block-types.d.ts");
|
|
434
|
+
const content = generateBlockTypes(scan.manifest.blocks, scan.manifest.messages);
|
|
435
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
436
|
+
writeFileSync(target, content);
|
|
437
|
+
return target;
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/knownFieldTypes.ts
|
|
441
|
+
const KNOWN_FIELD_TYPES = [
|
|
442
|
+
"bool",
|
|
443
|
+
"color",
|
|
444
|
+
"composite",
|
|
445
|
+
"datetime",
|
|
446
|
+
"float",
|
|
447
|
+
"icon",
|
|
448
|
+
"int",
|
|
449
|
+
"json",
|
|
450
|
+
"link",
|
|
451
|
+
"list",
|
|
452
|
+
"lucide-icon",
|
|
453
|
+
"markdown",
|
|
454
|
+
"media",
|
|
455
|
+
"reference",
|
|
456
|
+
"rich-text",
|
|
457
|
+
"select",
|
|
458
|
+
"seo",
|
|
459
|
+
"slug",
|
|
460
|
+
"string",
|
|
461
|
+
"styling",
|
|
462
|
+
"tabler-icon",
|
|
463
|
+
"text",
|
|
464
|
+
"uuid"
|
|
465
|
+
];
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/commands/validate.ts
|
|
468
|
+
const DEFAULT_CAPABLE_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
469
|
+
"string",
|
|
470
|
+
"text",
|
|
471
|
+
"slug",
|
|
472
|
+
"markdown",
|
|
473
|
+
"rich-text",
|
|
474
|
+
"lucide-icon",
|
|
475
|
+
"tabler-icon",
|
|
476
|
+
"int",
|
|
477
|
+
"float",
|
|
478
|
+
"bool",
|
|
479
|
+
"color",
|
|
480
|
+
"datetime"
|
|
481
|
+
]);
|
|
482
|
+
async function validateTheme(opts) {
|
|
483
|
+
const historyErrors = [];
|
|
484
|
+
const previousManifest = readPreviousManifest(opts.themeDir, historyErrors);
|
|
485
|
+
const scan = scanTheme({
|
|
486
|
+
themeDir: opts.themeDir,
|
|
487
|
+
customPages: opts.customPages,
|
|
488
|
+
previousManifest
|
|
489
|
+
});
|
|
490
|
+
const errors = [...historyErrors, ...scan.errors];
|
|
491
|
+
const warnings = [];
|
|
492
|
+
if (scan.manifest === null) return {
|
|
493
|
+
errors,
|
|
494
|
+
warnings,
|
|
495
|
+
blockCount: 0
|
|
496
|
+
};
|
|
497
|
+
let validTypes = new Set(KNOWN_FIELD_TYPES);
|
|
498
|
+
if (opts.remote) {
|
|
499
|
+
const remoteTypes = await fetchRemoteFieldTypes(opts);
|
|
500
|
+
if (remoteTypes === null) warnings.push("remote field-type check unavailable (GET /cms/v1/field-types not reachable) — using bundled list");
|
|
501
|
+
else validTypes = remoteTypes;
|
|
502
|
+
}
|
|
503
|
+
for (const block of scan.manifest.blocks) validateFields(String(block.apiId), block.fields, validTypes, errors, "fields");
|
|
504
|
+
return {
|
|
505
|
+
errors,
|
|
506
|
+
warnings,
|
|
507
|
+
blockCount: scan.manifest.blocks.length
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
async function fetchRemoteFieldTypes(opts) {
|
|
511
|
+
if (opts.gatewayUrl === void 0 || opts.orgId === void 0) return null;
|
|
512
|
+
const doFetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
513
|
+
try {
|
|
514
|
+
const response = await doFetch(`${stripTrailingSlashes(opts.gatewayUrl)}/cms/v1/field-types`, { headers: { "X-Org-Id": opts.orgId } });
|
|
515
|
+
if (!response.ok) return null;
|
|
516
|
+
const ids = ((await response.json()).fieldTypes ?? []).map((type) => typeof type === "string" ? type : type.id).filter((id) => typeof id === "string" && id !== "");
|
|
517
|
+
return ids.length === 0 ? null : new Set(ids);
|
|
518
|
+
} catch {
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function validateFields(apiId, fields, validTypes, errors, path) {
|
|
523
|
+
fields.forEach((field, index) => {
|
|
524
|
+
const fieldPath = `${path}[${index}]`;
|
|
525
|
+
if (typeof field.type === "string" && !validTypes.has(field.type)) errors.push(`blocks/${apiId}/block.json: ${fieldPath}.type — unknown field type "${field.type}"`);
|
|
526
|
+
if (Object.hasOwn(field, "default") && typeof field.type === "string" && !DEFAULT_CAPABLE_FIELD_TYPES.has(field.type)) errors.push(`blocks/${apiId}/block.json: ${fieldPath}.default — type "${field.type}" does not support defaults`);
|
|
527
|
+
const metadata = field.metadata;
|
|
528
|
+
if (typeof metadata !== "object" || metadata === null) return;
|
|
529
|
+
const nested = metadata;
|
|
530
|
+
if (Array.isArray(nested.fields)) validateFields(apiId, nested.fields, validTypes, errors, `${fieldPath}.metadata.fields`);
|
|
531
|
+
if (typeof nested.item === "object" && nested.item !== null) validateFields(apiId, [nested.item], validTypes, errors, `${fieldPath}.metadata.item`);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
//#endregion
|
|
535
|
+
export { initTheme as a, detectCommitSha as c, scaffoldBlock as i, fieldMigrationLines as l, generateBlockTypesFile as n, DeployError as o, generateTypes as r, deployTheme as s, validateTheme as t };
|
package/package.json
CHANGED
|
@@ -1,11 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"cms",
|
|
8
|
+
"deploy",
|
|
9
|
+
"eldra",
|
|
10
|
+
"theme"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/eldra-is/headless-kit/tree/main/packages/theme-cli#readme",
|
|
13
|
+
"bugs": "https://github.com/eldra-is/headless-kit/issues",
|
|
5
14
|
"license": "MIT",
|
|
6
15
|
"repository": {
|
|
7
16
|
"type": "git",
|
|
8
17
|
"url": "git+https://github.com/eldra-is/headless-kit.git",
|
|
9
18
|
"directory": "packages/theme-cli"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"eldra-theme": "./dist/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"template",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"citty": "^0.1.6",
|
|
44
|
+
"tar": "^7.4.3",
|
|
45
|
+
"@eldrajs/theme-core": "^0.2.0",
|
|
46
|
+
"@eldrajs/vite-plugin-theme": "^0.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"execa": "^9.5.2"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
57
|
+
"test": "vitest run"
|
|
10
58
|
}
|
|
11
59
|
}
|