create-abcart-theme 0.10.0 → 1.0.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 +133 -127
- package/LICENSE +202 -202
- package/NOTICE +2 -2
- package/README.md +65 -65
- package/bin/create-abcart-theme.mjs +4 -4
- package/package.json +49 -49
- package/src/args.mjs +113 -113
- package/src/banner.mjs +21 -21
- package/src/cli.mjs +119 -119
- package/src/create.mjs +85 -82
- package/src/package-manager.mjs +32 -32
- package/src/style.mjs +17 -17
- package/templates/default/.agents/skills/{wocart-docs → abcart-docs}/SKILL.md +146 -146
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/SKILL.md +58 -58
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/inputs-and-rights.md +47 -47
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/layout-rtl-and-phone.md +36 -36
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/measure-the-design.md +60 -60
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/tokens-sections-content.md +103 -103
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/verify-and-report.md +102 -102
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/compare-design.cjs +230 -230
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/qa-pages.cjs +219 -219
- package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -125
- package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -370
- package/templates/default/.dev.vars.example +12 -12
- package/templates/default/AGENTS.md +240 -240
- package/templates/default/README.md +184 -184
- package/templates/default/_gitignore +11 -11
- package/templates/default/astro.config.mjs +85 -85
- package/templates/default/package.json +36 -36
- package/templates/default/public/fonts/OFL.txt +96 -96
- package/templates/default/src/actions/index.ts +22 -22
- package/templates/default/src/components/cart/AddToCartButton.astro +45 -45
- package/templates/default/src/components/cart/CartDrawer.astro +47 -47
- package/templates/default/src/components/cart/CartSummary.astro +11 -11
- package/templates/default/src/components/cart/FreeShipping.astro +7 -7
- package/templates/default/src/components/checkout/CheckoutMain.astro +29 -29
- package/templates/default/src/components/checkout/OrderForm.astro +280 -280
- package/templates/default/src/components/checkout/ThankYouMain.astro +68 -68
- package/templates/default/src/components/landing/LandingImages.astro +51 -51
- package/templates/default/src/components/landing/LandingOrder.astro +46 -46
- package/templates/default/src/components/landing/LandingProduct.astro +41 -41
- package/templates/default/src/components/listing/ListingMain.astro +93 -93
- package/templates/default/src/components/listing/PageMain.astro +52 -52
- package/templates/default/src/components/listing/Pagination.astro +31 -31
- package/templates/default/src/components/listing/SortControl.astro +35 -35
- package/templates/default/src/components/product/BuyBox.astro +96 -96
- package/templates/default/src/components/product/Description.astro +24 -24
- package/templates/default/src/components/product/Gallery.astro +66 -66
- package/templates/default/src/components/product/MobileBuyBar.astro +29 -29
- package/templates/default/src/components/product/OfferChoice.astro +66 -66
- package/templates/default/src/components/product/ProductMain.astro +40 -40
- package/templates/default/src/components/product/ProductReviews.astro +72 -72
- package/templates/default/src/components/product/RelatedProducts.astro +30 -30
- package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -13
- package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -20
- package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -19
- package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -33
- package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -12
- package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -30
- package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -23
- package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -16
- package/templates/default/src/components/product/blocks/StockBlock.astro +22 -22
- package/templates/default/src/components/product/blocks/TextBlock.astro +11 -11
- package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -20
- package/templates/default/src/components/reviews/ReviewCard.astro +46 -46
- package/templates/default/src/components/reviews/ReviewForm.astro +113 -113
- package/templates/default/src/components/reviews/VoiceNote.astro +60 -60
- package/templates/default/src/components/sections/CollectionCards.astro +65 -65
- package/templates/default/src/components/sections/Countdown.astro +57 -57
- package/templates/default/src/components/sections/Faq.astro +44 -44
- package/templates/default/src/components/sections/FeaturedProduct.astro +71 -71
- package/templates/default/src/components/sections/Hero.astro +99 -99
- package/templates/default/src/components/sections/ImageBanner.astro +46 -46
- package/templates/default/src/components/sections/ProductGrid.astro +47 -47
- package/templates/default/src/components/sections/RichText.astro +35 -35
- package/templates/default/src/components/sections/Steps.astro +46 -46
- package/templates/default/src/components/sections/Testimonials.astro +57 -57
- package/templates/default/src/components/shell/Footer.astro +80 -80
- package/templates/default/src/components/shell/Header.astro +89 -89
- package/templates/default/src/components/shell/LanguageMenu.astro +33 -33
- package/templates/default/src/components/shell/MobileMenu.astro +65 -65
- package/templates/default/src/components/shell/SearchDialog.astro +19 -19
- package/templates/default/src/components/shell/TopBar.astro +54 -54
- package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -111
- package/templates/default/src/components/store/ContactMain.astro +79 -79
- package/templates/default/src/components/store/SearchMain.astro +56 -56
- package/templates/default/src/components/store/TrackOrderMain.astro +161 -161
- package/templates/default/src/components/surface/Area.astro +20 -20
- package/templates/default/src/components/surface/PreviewBridge.astro +24 -24
- package/templates/default/src/components/surface/Sections.astro +35 -35
- package/templates/default/src/components/ui/Breadcrumbs.astro +36 -36
- package/templates/default/src/components/ui/Button.astro +45 -45
- package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -24
- package/templates/default/src/components/ui/Icon.astro +93 -93
- package/templates/default/src/components/ui/Logo.astro +36 -36
- package/templates/default/src/components/ui/Photo.astro +46 -46
- package/templates/default/src/components/ui/Price.astro +24 -24
- package/templates/default/src/components/ui/ProductCard.astro +41 -41
- package/templates/default/src/components/ui/Rating.astro +22 -22
- package/templates/default/src/components/ui/Section.astro +34 -34
- package/templates/default/src/components/ui/SectionHeading.astro +19 -19
- package/templates/default/src/env.d.ts +23 -23
- package/templates/default/src/layouts/StoreLayout.astro +145 -145
- package/templates/default/src/lib/browser-copy.ts +37 -37
- package/templates/default/src/lib/context.ts +89 -89
- package/templates/default/src/lib/coupon-notice.ts +47 -47
- package/templates/default/src/lib/i18n.ts +32 -32
- package/templates/default/src/lib/images.ts +38 -38
- package/templates/default/src/lib/listing-query.ts +41 -41
- package/templates/default/src/lib/money.ts +16 -16
- package/templates/default/src/lib/motion.ts +16 -16
- package/templates/default/src/lib/nav.ts +26 -26
- package/templates/default/src/lib/offer-tiles.ts +105 -105
- package/templates/default/src/lib/order-outcome.ts +66 -66
- package/templates/default/src/lib/otp-message.ts +21 -21
- package/templates/default/src/lib/products.ts +38 -38
- package/templates/default/src/lib/review-refusals.ts +31 -31
- package/templates/default/src/lib/store.ts +31 -31
- package/templates/default/src/lib/whatsapp.ts +29 -29
- package/templates/default/src/middleware.ts +23 -23
- package/templates/default/src/pages/404.astro +22 -22
- package/templates/default/src/pages/{wocart-preview.astro → abcart-preview.astro} +43 -43
- package/templates/default/src/pages/{wocart-revalidate.ts → abcart-revalidate.ts} +10 -10
- package/templates/default/src/pages/{wocart-styles.css.ts → abcart-styles.css.ts} +5 -5
- package/templates/default/src/pages/{wocart-theme.json.ts → abcart-theme.json.ts} +5 -5
- package/templates/default/src/pages/api/abandoned/convert.ts +4 -4
- package/templates/default/src/pages/api/abandoned/upsert.ts +4 -4
- package/templates/default/src/pages/api/cart/validate.ts +4 -4
- package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -4
- package/templates/default/src/pages/api/otp/send.ts +4 -4
- package/templates/default/src/pages/api/otp/verify.ts +4 -4
- package/templates/default/src/pages/api/reviews/[productId].ts +3 -3
- package/templates/default/src/pages/api/reviews/eligibility.ts +3 -3
- package/templates/default/src/pages/api/reviews/submit.ts +3 -3
- package/templates/default/src/pages/api/reviews/upload.ts +3 -3
- package/templates/default/src/pages/category/[slug].astro +20 -20
- package/templates/default/src/pages/checkout.astro +25 -25
- package/templates/default/src/pages/collections/[handle].astro +20 -20
- package/templates/default/src/pages/contact.astro +17 -17
- package/templates/default/src/pages/index.astro +9 -9
- package/templates/default/src/pages/lp/[slug].astro +47 -47
- package/templates/default/src/pages/pages/[slug].astro +16 -16
- package/templates/default/src/pages/products/[handle].astro +37 -37
- package/templates/default/src/pages/products/index.astro +15 -15
- package/templates/default/src/pages/robots.txt.ts +9 -9
- package/templates/default/src/pages/search.astro +19 -19
- package/templates/default/src/pages/sitemap.xml.ts +12 -12
- package/templates/default/src/pages/thank-you.astro +33 -33
- package/templates/default/src/pages/track-order.astro +17 -17
- package/templates/default/src/scripts/cart.ts +371 -371
- package/templates/default/src/scripts/checkout/coupon.ts +96 -96
- package/templates/default/src/scripts/checkout/delivery.ts +86 -86
- package/templates/default/src/scripts/checkout/form.ts +54 -54
- package/templates/default/src/scripts/checkout/otp.ts +106 -106
- package/templates/default/src/scripts/checkout/picker.ts +169 -169
- package/templates/default/src/scripts/checkout/quote.ts +169 -169
- package/templates/default/src/scripts/checkout/submit.ts +113 -113
- package/templates/default/src/scripts/checkout/tracking.ts +74 -74
- package/templates/default/src/scripts/countdown.ts +29 -29
- package/templates/default/src/scripts/events.ts +4 -4
- package/templates/default/src/scripts/hero.ts +49 -49
- package/templates/default/src/scripts/listing.ts +13 -13
- package/templates/default/src/scripts/order-form.ts +100 -100
- package/templates/default/src/scripts/product.ts +306 -306
- package/templates/default/src/scripts/public-config.ts +79 -79
- package/templates/default/src/scripts/reviews.ts +358 -358
- package/templates/default/src/scripts/site.ts +131 -131
- package/templates/default/src/scripts/thank-you.ts +11 -11
- package/templates/default/src/scripts/voice-note.ts +94 -94
- package/templates/default/src/styles/base.css +1030 -1030
- package/templates/default/src/styles/checkout.css +1111 -1111
- package/templates/default/src/styles/global.css +12 -12
- package/templates/default/src/styles/product.css +871 -871
- package/templates/default/src/styles/reviews.css +533 -533
- package/templates/default/src/styles/sections.css +931 -931
- package/templates/default/src/styles/shell.css +970 -970
- package/templates/default/src/styles/tokens.css +583 -583
- package/templates/default/src/theme/api-routes.ts +10 -10
- package/templates/default/src/theme/content/catalog.ts +117 -117
- package/templates/default/src/theme/content/checkout.ts +168 -168
- package/templates/default/src/theme/content/editor.ts +21 -21
- package/templates/default/src/theme/content/index.ts +45 -45
- package/templates/default/src/theme/content/reviews.ts +76 -76
- package/templates/default/src/theme/content/shell.ts +59 -59
- package/templates/default/src/theme/content/types.ts +12 -12
- package/templates/default/src/theme/documents/catalog.json +11 -11
- package/templates/default/src/theme/documents/category.json +11 -11
- package/templates/default/src/theme/documents/checkout.json +11 -11
- package/templates/default/src/theme/documents/collection.json +11 -11
- package/templates/default/src/theme/documents/contact.json +11 -11
- package/templates/default/src/theme/documents/footer.area.json +11 -11
- package/templates/default/src/theme/documents/header.area.json +16 -16
- package/templates/default/src/theme/documents/home.json +313 -313
- package/templates/default/src/theme/documents/landing.json +8 -8
- package/templates/default/src/theme/documents/page.json +11 -11
- package/templates/default/src/theme/documents/product.json +125 -125
- package/templates/default/src/theme/documents/search.json +11 -11
- package/templates/default/src/theme/documents/thank-you.json +11 -11
- package/templates/default/src/theme/documents/track-order.json +11 -11
- package/templates/default/src/theme/fields.ts +61 -61
- package/templates/default/src/theme/key.ts +11 -11
- package/templates/default/src/theme/labels.ts +231 -231
- package/templates/default/src/theme/locales.ts +11 -11
- package/templates/default/src/theme/palette.ts +14 -14
- package/templates/default/src/theme/sections/collection-cards.ts +65 -65
- package/templates/default/src/theme/sections/faq.ts +74 -74
- package/templates/default/src/theme/sections/featured-product.ts +42 -42
- package/templates/default/src/theme/sections/hero.ts +47 -47
- package/templates/default/src/theme/sections/image-banner.ts +25 -25
- package/templates/default/src/theme/sections/index.ts +40 -40
- package/templates/default/src/theme/sections/landing.ts +150 -150
- package/templates/default/src/theme/sections/listing.ts +84 -84
- package/templates/default/src/theme/sections/product-grid.ts +42 -42
- package/templates/default/src/theme/sections/product.ts +297 -297
- package/templates/default/src/theme/sections/rich-text.ts +39 -39
- package/templates/default/src/theme/sections/shared.ts +54 -54
- package/templates/default/src/theme/sections/shell.ts +85 -85
- package/templates/default/src/theme/sections/store-pages.ts +101 -101
- package/templates/default/src/theme/sections/testimonials.ts +61 -61
- package/templates/default/src/theme/sections/thank-you.ts +35 -35
- package/templates/default/src/theme/settings.ts +124 -124
- package/templates/default/src/theme/theme.ts +65 -65
- package/templates/default/tests/fixtures/canvas-tote.json +62 -62
- package/templates/default/tests/fixtures/linen-shirt.json +128 -128
- package/templates/default/tests/unit/checkout.test.ts +241 -241
- package/templates/default/tests/unit/contract.test.ts +170 -169
- package/templates/default/tests/unit/contrast.test.ts +68 -68
- package/templates/default/tests/unit/copy.test.ts +101 -101
- package/templates/default/tests/unit/design-values.test.ts +95 -95
- package/templates/default/tests/unit/editability.test.ts +180 -180
- package/templates/default/tests/unit/fixtures.ts +91 -91
- package/templates/default/tests/unit/footer.test.ts +54 -54
- package/templates/default/tests/unit/guards.test.ts +340 -340
- package/templates/default/tests/unit/images.test.ts +26 -26
- package/templates/default/tests/unit/landing.test.ts +151 -151
- package/templates/default/tests/unit/languages.test.ts +42 -42
- package/templates/default/tests/unit/middleware.test.ts +53 -53
- package/templates/default/tests/unit/offer-tiles.test.ts +75 -75
- package/templates/default/tests/unit/render.ts +38 -38
- package/templates/default/tests/unit/reviews.test.ts +25 -25
- package/templates/default/tests/unit/rules.test.ts +59 -59
- package/templates/default/tests/unit/source.ts +75 -75
- package/templates/default/tests/unit/store-pages.test.ts +147 -147
- package/templates/default/tests/unit/studio.test.ts +202 -202
- package/templates/default/tests/unit/testimonials.test.ts +52 -52
- package/templates/default/tests/unit/thank-you.test.ts +52 -52
- package/templates/default/tests/unit/tracking.test.ts +29 -29
- package/templates/default/tests/unit/voice-note.test.ts +42 -42
- package/templates/default/tsconfig.json +13 -13
- package/templates/default/vitest.config.ts +15 -15
- package/templates/default/wrangler.jsonc +16 -16
package/src/create.mjs
CHANGED
|
@@ -1,82 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A new theme from the template: every file copied, and the project stamped
|
|
3
|
-
* with its own name and key. Every theme is whole: both hosts and every
|
|
4
|
-
* platform feature. Writes only inside the target, never over a file that is
|
|
5
|
-
* already there, and deletes nothing.
|
|
6
|
-
*/
|
|
7
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
9
|
-
import { titleFromKey, workerNameFromName } from "./args.mjs";
|
|
10
|
-
import { withOverrides } from "./package-manager.mjs";
|
|
11
|
-
|
|
12
|
-
/** Never copied: what a maintainer's working copy of the template makes. */
|
|
13
|
-
const LEFT_OUT = new Set(["node_modules", "dist", ".astro", ".wrangler", ".vercel", ".dev.vars", "package-lock.json", ".DS_Store"]);
|
|
14
|
-
/** The files a stamp goes into; everything else is copied as it is. */
|
|
15
|
-
const STAMPED = new Set(["package.json", "src/theme/key.ts", "wrangler.jsonc", "README.md"]);
|
|
16
|
-
/** Published under another name: npm drops a `.gitignore` from every package. */
|
|
17
|
-
const RENAMED = { _gitignore: ".gitignore" };
|
|
18
|
-
|
|
19
|
-
/** The platform the template's SDK pair needs (`@abcart/storefront` 4.1.0 requires platform v9.0.0). */
|
|
20
|
-
export const MIN_PLATFORM = "9.0.0";
|
|
21
|
-
|
|
22
|
-
function walk(dir, root = dir) {
|
|
23
|
-
return readdirSync(dir)
|
|
24
|
-
.filter((name) => !LEFT_OUT.has(name))
|
|
25
|
-
.flatMap((name) => {
|
|
26
|
-
const full = join(dir, name);
|
|
27
|
-
return statSync(full).isDirectory() ? walk(full, root) : [relative(root, full).split(sep).join("/")];
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const target = (path) => path.split("/").map((part) => RENAMED[part] ?? part).join("/");
|
|
32
|
-
|
|
33
|
-
/** Replaces one placeholder that must appear exactly once: a template that drifted fails here, not in a project. */
|
|
34
|
-
function stamp(text, file, from, to) {
|
|
35
|
-
const count = text.split(from).length - 1;
|
|
36
|
-
if (count !== 1) throw new Error(`template ${file}: expected "${from}" once, found it ${count} times`);
|
|
37
|
-
return text.replace(from, to);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The files the project gets, as `{ path, content }`, without writing them.
|
|
42
|
-
* `options`: `name`, `key`, `generatorVersion`, `packageManager`, `template`.
|
|
43
|
-
*/
|
|
44
|
-
export function planProject(templateDir, options) {
|
|
45
|
-
const { name, key, generatorVersion, packageManager = "npm" } = options;
|
|
46
|
-
return walk(templateDir).map((path) => {
|
|
47
|
-
if (!STAMPED.has(path)) return { path: target(path), content: readFileSync(join(templateDir, path)) };
|
|
48
|
-
let text = readFileSync(join(templateDir, path), "utf8");
|
|
49
|
-
if (path === "package.json") {
|
|
50
|
-
const pkg = withOverrides(JSON.parse(text), packageManager);
|
|
51
|
-
text = `${JSON.stringify({ ...pkg, name, version: "0.1.0",
|
|
52
|
-
}
|
|
53
|
-
if (path === "src/theme/key.ts") text = stamp(text, path, 'export const THEME_KEY = "my-theme";', `export const THEME_KEY = "${key}";`);
|
|
54
|
-
if (path === "wrangler.jsonc") text = stamp(text, path, '"name": "my-
|
|
55
|
-
if (path === "README.md")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
if (!
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A new theme from the template: every file copied, and the project stamped
|
|
3
|
+
* with its own name and key. Every theme is whole: both hosts and every
|
|
4
|
+
* platform feature. Writes only inside the target, never over a file that is
|
|
5
|
+
* already there, and deletes nothing.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
9
|
+
import { titleFromKey, workerNameFromName } from "./args.mjs";
|
|
10
|
+
import { withOverrides } from "./package-manager.mjs";
|
|
11
|
+
|
|
12
|
+
/** Never copied: what a maintainer's working copy of the template makes. */
|
|
13
|
+
const LEFT_OUT = new Set(["node_modules", "dist", ".astro", ".wrangler", ".vercel", ".dev.vars", "package-lock.json", ".DS_Store"]);
|
|
14
|
+
/** The files a stamp goes into; everything else is copied as it is. */
|
|
15
|
+
const STAMPED = new Set(["package.json", "src/theme/key.ts", "wrangler.jsonc", "README.md"]);
|
|
16
|
+
/** Published under another name: npm drops a `.gitignore` from every package. */
|
|
17
|
+
const RENAMED = { _gitignore: ".gitignore" };
|
|
18
|
+
|
|
19
|
+
/** The platform the template's SDK pair needs (`@abcart/storefront` 4.1.0 requires platform v9.0.0). */
|
|
20
|
+
export const MIN_PLATFORM = "9.0.0";
|
|
21
|
+
|
|
22
|
+
function walk(dir, root = dir) {
|
|
23
|
+
return readdirSync(dir)
|
|
24
|
+
.filter((name) => !LEFT_OUT.has(name))
|
|
25
|
+
.flatMap((name) => {
|
|
26
|
+
const full = join(dir, name);
|
|
27
|
+
return statSync(full).isDirectory() ? walk(full, root) : [relative(root, full).split(sep).join("/")];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const target = (path) => path.split("/").map((part) => RENAMED[part] ?? part).join("/");
|
|
32
|
+
|
|
33
|
+
/** Replaces one placeholder that must appear exactly once: a template that drifted fails here, not in a project. */
|
|
34
|
+
function stamp(text, file, from, to) {
|
|
35
|
+
const count = text.split(from).length - 1;
|
|
36
|
+
if (count !== 1) throw new Error(`template ${file}: expected "${from}" once, found it ${count} times`);
|
|
37
|
+
return text.replace(from, to);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The files the project gets, as `{ path, content }`, without writing them.
|
|
42
|
+
* `options`: `name`, `key`, `generatorVersion`, `packageManager`, `template`.
|
|
43
|
+
*/
|
|
44
|
+
export function planProject(templateDir, options) {
|
|
45
|
+
const { name, key, generatorVersion, packageManager = "npm" } = options;
|
|
46
|
+
return walk(templateDir).map((path) => {
|
|
47
|
+
if (!STAMPED.has(path)) return { path: target(path), content: readFileSync(join(templateDir, path)) };
|
|
48
|
+
let text = readFileSync(join(templateDir, path), "utf8");
|
|
49
|
+
if (path === "package.json") {
|
|
50
|
+
const pkg = withOverrides(JSON.parse(text), packageManager);
|
|
51
|
+
text = `${JSON.stringify({ ...pkg, name, version: "0.1.0", abcart: { template: options.template ?? "default", generator: generatorVersion, platform: `>=${MIN_PLATFORM}` } }, null, 2)}\n`;
|
|
52
|
+
}
|
|
53
|
+
if (path === "src/theme/key.ts") text = stamp(text, path, 'export const THEME_KEY = "my-theme";', `export const THEME_KEY = "${key}";`);
|
|
54
|
+
if (path === "wrangler.jsonc") text = stamp(text, path, '"name": "my-abcart-theme"', `"name": "${workerNameFromName(name)}"`);
|
|
55
|
+
if (path === "README.md") {
|
|
56
|
+
const eol = text.includes("# My Theme\r\n") ? "\r\n" : "\n";
|
|
57
|
+
text = stamp(text, path, `# My Theme${eol}`, `# ${titleFromKey(key)}${eol}`);
|
|
58
|
+
}
|
|
59
|
+
return { path: target(path), content: text };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Why the project cannot be written to `targetDir`, or null. */
|
|
64
|
+
export function targetProblem(targetDir, planned, { force = false } = {}) {
|
|
65
|
+
if (!existsSync(targetDir)) return null;
|
|
66
|
+
if (!statSync(targetDir).isDirectory()) return `${targetDir} is a file`;
|
|
67
|
+
const present = readdirSync(targetDir).filter((name) => name !== ".DS_Store");
|
|
68
|
+
if (present.length === 0) return null;
|
|
69
|
+
if (!force) return `${targetDir} is not empty (pass --force to add the theme beside what is there)`;
|
|
70
|
+
const collisions = planned.filter(({ path }) => existsSync(join(targetDir, path))).map(({ path }) => path);
|
|
71
|
+
return collisions.length > 0 ? `${targetDir} already has ${collisions.slice(0, 5).join(", ")}${collisions.length > 5 ? ` and ${collisions.length - 5} more` : ""}; nothing is overwritten` : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Writes the planned files under `targetDir`; every path is checked to stay inside it. */
|
|
75
|
+
export function writeProject(targetDir, planned) {
|
|
76
|
+
const root = resolve(targetDir);
|
|
77
|
+
for (const { path, content } of planned) {
|
|
78
|
+
const file = resolve(root, path);
|
|
79
|
+
if (!file.startsWith(root + sep)) throw new Error(`refusing to write outside ${root}: ${path}`);
|
|
80
|
+
if (existsSync(file)) throw new Error(`refusing to overwrite ${file}`);
|
|
81
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
82
|
+
writeFileSync(file, content);
|
|
83
|
+
}
|
|
84
|
+
return planned.map(({ path }) => path);
|
|
85
|
+
}
|
package/src/package-manager.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The package manager that ran the generator (`npm create`, `pnpm create`,
|
|
3
|
-
* `yarn create`, `bun create`), so the project installs and runs with it.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
7
|
-
|
|
8
|
-
/** The manager named by `npm_config_user_agent` ("pnpm/9.12.0 npm/? node/v22…"), npm when unknown. */
|
|
9
|
-
export function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? "") {
|
|
10
|
-
const name = userAgent.split(" ")[0]?.split("/")[0];
|
|
11
|
-
return MANAGERS.includes(name) ? name : "npm";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** How to run a package.json script with a manager. */
|
|
15
|
-
export function runCommand(manager, script) {
|
|
16
|
-
if (manager === "npm") return script === "test" ? "npm test" : `npm run ${script}`;
|
|
17
|
-
return `${manager} ${script === "test" ? "test" : `run ${script}`}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The template's `overrides` in the manager's own field: npm and bun read
|
|
22
|
-
* `overrides`, pnpm `pnpm.overrides`, yarn `resolutions`. They pin what the
|
|
23
|
-
* build depends on (Vite's major for Astro and Vitest), so every manager
|
|
24
|
-
* must see them.
|
|
25
|
-
*/
|
|
26
|
-
export function withOverrides(pkg, manager) {
|
|
27
|
-
const overrides = pkg.overrides;
|
|
28
|
-
if (!overrides) return pkg;
|
|
29
|
-
if (manager === "pnpm") return { ...pkg, pnpm: { ...pkg.pnpm, overrides: { ...pkg.pnpm?.overrides, ...overrides } } };
|
|
30
|
-
if (manager === "yarn") return { ...pkg, resolutions: { ...pkg.resolutions, ...overrides } };
|
|
31
|
-
return pkg;
|
|
32
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* The package manager that ran the generator (`npm create`, `pnpm create`,
|
|
3
|
+
* `yarn create`, `bun create`), so the project installs and runs with it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
7
|
+
|
|
8
|
+
/** The manager named by `npm_config_user_agent` ("pnpm/9.12.0 npm/? node/v22…"), npm when unknown. */
|
|
9
|
+
export function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? "") {
|
|
10
|
+
const name = userAgent.split(" ")[0]?.split("/")[0];
|
|
11
|
+
return MANAGERS.includes(name) ? name : "npm";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** How to run a package.json script with a manager. */
|
|
15
|
+
export function runCommand(manager, script) {
|
|
16
|
+
if (manager === "npm") return script === "test" ? "npm test" : `npm run ${script}`;
|
|
17
|
+
return `${manager} ${script === "test" ? "test" : `run ${script}`}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The template's `overrides` in the manager's own field: npm and bun read
|
|
22
|
+
* `overrides`, pnpm `pnpm.overrides`, yarn `resolutions`. They pin what the
|
|
23
|
+
* build depends on (Vite's major for Astro and Vitest), so every manager
|
|
24
|
+
* must see them.
|
|
25
|
+
*/
|
|
26
|
+
export function withOverrides(pkg, manager) {
|
|
27
|
+
const overrides = pkg.overrides;
|
|
28
|
+
if (!overrides) return pkg;
|
|
29
|
+
if (manager === "pnpm") return { ...pkg, pnpm: { ...pkg.pnpm, overrides: { ...pkg.pnpm?.overrides, ...overrides } } };
|
|
30
|
+
if (manager === "yarn") return { ...pkg, resolutions: { ...pkg.resolutions, ...overrides } };
|
|
31
|
+
return pkg;
|
|
32
|
+
}
|
package/src/style.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminal colour for the generator's own output. Colour is used only when the
|
|
3
|
-
* output is a terminal and NO_COLOR is not set to a non-empty value (no-color.org);
|
|
4
|
-
* a dumb terminal gets plain text. Plain output is the same text without codes.
|
|
5
|
-
*/
|
|
6
|
-
const BRAND = [101, 33, 238];
|
|
7
|
-
|
|
8
|
-
export function styler(stream, env = {}) {
|
|
9
|
-
const on = Boolean(stream.isTTY) && !env.NO_COLOR && env.TERM !== "dumb";
|
|
10
|
-
const wrap = (open, close) => (text) => (on ? `\x1b[${open}m${text}\x1b[${close}m` : text);
|
|
11
|
-
return {
|
|
12
|
-
on,
|
|
13
|
-
brand: wrap(`38;2;${BRAND.join(";")}`, "39"),
|
|
14
|
-
bold: wrap("1", "22"),
|
|
15
|
-
dim: wrap("2", "22"),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Terminal colour for the generator's own output. Colour is used only when the
|
|
3
|
+
* output is a terminal and NO_COLOR is not set to a non-empty value (no-color.org);
|
|
4
|
+
* a dumb terminal gets plain text. Plain output is the same text without codes.
|
|
5
|
+
*/
|
|
6
|
+
const BRAND = [101, 33, 238];
|
|
7
|
+
|
|
8
|
+
export function styler(stream, env = {}) {
|
|
9
|
+
const on = Boolean(stream.isTTY) && !env.NO_COLOR && env.TERM !== "dumb";
|
|
10
|
+
const wrap = (open, close) => (text) => (on ? `\x1b[${open}m${text}\x1b[${close}m` : text);
|
|
11
|
+
return {
|
|
12
|
+
on,
|
|
13
|
+
brand: wrap(`38;2;${BRAND.join(";")}`, "39"),
|
|
14
|
+
bold: wrap("1", "22"),
|
|
15
|
+
dim: wrap("2", "22"),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
---
|
|
2
|
-
name:
|
|
3
|
-
description: Where to find the truth about the
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Looking things up in
|
|
7
|
-
|
|
8
|
-
`
|
|
9
|
-
platform claim, and whenever a check fails. So does `shopify-theme-asset-collector`
|
|
10
|
-
when its output is used to build a theme.
|
|
11
|
-
Return to the step that sent you once you have the answer.
|
|
12
|
-
|
|
13
|
-
## The rule
|
|
14
|
-
|
|
15
|
-
Look an answer up before any SDK call, field or claim about the platform.
|
|
16
|
-
Three sources agree, and you read them together:
|
|
17
|
-
|
|
18
|
-
1. **The installed declarations**, `node_modules/@
|
|
19
|
-
export, field and type of the version this theme runs, with its
|
|
20
|
-
documentation comment. They are the final authority.
|
|
21
|
-
2. **This starter**: its code under `src/`, its tests under `tests/`,
|
|
22
|
-
`AGENTS.md` and `README.md`. It shows how each SDK piece is used, and each
|
|
23
|
-
rule below is enforced by a test.
|
|
24
|
-
3. **The documentation** at `https://docs.
|
|
25
|
-
and around this starter. It explains why things work as they do and how
|
|
26
|
-
the pieces fit. Every page is also Markdown at its URL plus `.md`.
|
|
27
|
-
|
|
28
|
-
If the three ever disagree, the installed declarations win: say so to the
|
|
29
|
-
developer. If the answer is in none of them, stop and ask. Never guess an
|
|
30
|
-
export, a field, a store setting or a platform behaviour.
|
|
31
|
-
|
|
32
|
-
## Finding an export
|
|
33
|
-
|
|
34
|
-
The packages publish these entry points only (each package's
|
|
35
|
-
`package.json` `exports`):
|
|
36
|
-
|
|
37
|
-
- `@abcart/storefront`, `@abcart/storefront/server` (server only),
|
|
38
|
-
`@abcart/storefront/astro` (server only), `@abcart/storefront/review-media`
|
|
39
|
-
- `@abcart/theme`, `@abcart/theme/astro`, `@abcart/theme/lifecycle`,
|
|
40
|
-
`@abcart/theme/messages`, `@abcart/theme/preview`,
|
|
41
|
-
`@abcart/theme/image-service`, and the four components
|
|
42
|
-
`@abcart/theme/astro/InstanceView.astro`, `@abcart/theme/astro/Blocks.astro`,
|
|
43
|
-
`@abcart/theme/astro/Block.astro` and `@abcart/theme/astro/ThemeStyles.astro`
|
|
44
|
-
|
|
45
|
-
To find a name and read its documentation comment:
|
|
46
|
-
|
|
47
|
-
```sh
|
|
48
|
-
grep -rn "createQuoter" node_modules/@abcart/storefront/dist/*.d.ts
|
|
49
|
-
grep -rn "type FieldKind" node_modules/@abcart/theme/dist/*.d.ts
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Then find how the starter already uses it (`grep -rn "createQuoter" src`),
|
|
53
|
-
and do it the same way.
|
|
54
|
-
|
|
55
|
-
## SDK names the starter uses
|
|
56
|
-
|
|
57
|
-
Each name below is exported by that entry point in the installed version.
|
|
58
|
-
Check any other name the same way before you use it.
|
|
59
|
-
|
|
60
|
-
| Entry point | Names |
|
|
61
|
-
| --- | --- |
|
|
62
|
-
| `@abcart/storefront` | `storefrontPath`, `localizeHref`, `localeRouting`, `servedLanguage`, `unavailableStoreConfig`, `whatsAppContact`, `canonicalUrl`, `pictureOf`, `mediaImageUrl`, `mediaImageSrcset`, `createQuoter`, `createBrowserAbandonedCheckoutTracker`, `Review`, `PickedImage` |
|
|
63
|
-
| `@abcart/storefront/server` | `createStoreClient`, `readPreviewRequest`, `readRevalidateRequest`, `StoreClient` |
|
|
64
|
-
| `@abcart/storefront/astro` | `resolveStoreRequest`, `resolvePreviewStore`, `runFormAction`, `executePlaceOrder`, `placeOrderInput
|
|
65
|
-
| `@abcart/storefront/review-media` | `createReviewSession` |
|
|
66
|
-
| `@abcart/theme` | `defineTheme`, `defineComponent`, `defineCapabilities`, `resolveSurfaceDocument`, `resolveThemeSettings`, `schemeClass`, `styleClasses`, `richTextToHtml`, `formatMessage`, `pluralFormIssues`, `validateThemeDefinition`, `validatePageData`, `validateThemeManifest`, `themeManifest`, `diffThemeManifests`, `THEME_PREVIEW_PATH`, `SCHEME_MARKER_CLASS`, `FieldKind`, `ResolvedImage`, `StyleValue` |
|
|
67
|
-
| `@abcart/theme/astro` | `createReadCache`, `isPreview`, `themeManifestEndpoint`, `themeStylesEndpoint`, `previewTarget` |
|
|
68
|
-
| `@abcart/theme/lifecycle` | `bindEach`, `onEachPage` |
|
|
69
|
-
|
|
70
|
-
## Where to look
|
|
71
|
-
|
|
72
|
-
| Question | The starter file that answers it | The declaration to check | Documentation |
|
|
73
|
-
| --- | --- | --- | --- |
|
|
74
|
-
| How is this project laid out, and how does a request become a page? | `AGENTS.md`, `README.md` | | https://docs.
|
|
75
|
-
| How does the theme reach the store? | `src/lib/store.ts` (the only `createStoreClient()`), `src/lib/context.ts`, `src/middleware.ts` | `@abcart/storefront/server`, `@abcart/storefront/astro` | https://docs.
|
|
76
|
-
| What does a page know about its store? | `src/lib/context.ts` (`Astro.locals.store`) | `StoreConfig` in `@abcart/storefront` | https://docs.
|
|
77
|
-
| How is an order placed? | `src/components/checkout/OrderForm.astro`, `src/scripts/order-form.ts`, `src/scripts/checkout/`, `src/actions/index.ts` | `executePlaceOrder`, `placeOrderInput` | https://docs.
|
|
78
|
-
| How are prices, offers and delivery fees shown? | `src/scripts/checkout/quote.ts`, `src/scripts/cart.ts`, `src/pages/api/cart/validate.ts` | `createQuoter` | https://docs.
|
|
79
|
-
| Wilayas, communes, delivery types? | `src/scripts/checkout/delivery.ts`, `src/pages/api/communes/[wilayaId].ts` | `@abcart/storefront` | https://docs.
|
|
80
|
-
| Images? | `src/lib/images.ts`, `src/components/ui/Photo.astro` | `pictureOf`, `mediaImageUrl`, `mediaImageSrcset` | https://docs.
|
|
81
|
-
| WhatsApp? | `src/lib/whatsapp.ts` (`storeWhatsApp()`) | `whatsAppContact` | https://docs.
|
|
82
|
-
| Reviews? | `src/components/product/ProductReviews.astro`, `src/scripts/reviews.ts`, `src/pages/api/reviews/` | `createReviewSession` | https://docs.
|
|
83
|
-
| Studio's preview and the revalidation after a publish? | `src/pages/
|
|
84
|
-
| The manifest Studio reads? | `src/theme/theme.ts`, `src/pages/
|
|
85
|
-
| Sections, fields, page documents? | `src/theme/sections/`, `src/theme/fields.ts`, `src/theme/documents/`, `src/components/surface/Sections.astro` | `defineComponent`, `FieldKind`, `resolveSurfaceDocument` | https://docs.
|
|
86
|
-
| Restyling, words, a new field or section? | `src/styles/tokens.css`, `src/theme/settings.ts`, `src/theme/content/`, `src/theme/sections/index.ts` | | https://docs.
|
|
87
|
-
| Words, translations and plurals? | `src/theme/content/`, `src/lib/i18n.ts`, `src/lib/browser-copy.ts` | `formatMessage`, `pluralFormIssues` | https://docs.
|
|
88
|
-
| Settings, colours and the look? | `src/theme/palette.ts`, `src/theme/settings.ts`, `src/styles/tokens.css`, `src/components/ui/Section.astro` | `resolveThemeSettings`, `schemeClass`, `styleClasses` | https://docs.
|
|
89
|
-
| Languages and links? | `src/lib/context.ts`, `src/lib/nav.ts` | `storefrontPath`, `localizeHref`, `localeRouting`, `isSingleLanguagePage` | https://docs.
|
|
90
|
-
| Building and deploying? | `package.json` scripts, `astro.config.mjs`, `wrangler.jsonc`, `README.md` | | https://docs.
|
|
91
|
-
| Testing? | `tests/unit/` | `validateThemeDefinition`, `validatePageData` | https://docs.
|
|
92
|
-
| Something renders wrong? | The server log: `src/components/surface/Sections.astro` warns about each document issue and section error, and `src/lib/store.ts` warns about each failed store read, both prefixed with the theme key | `RendererIssue` in `@abcart/theme/astro` | https://docs.
|
|
93
|
-
|
|
94
|
-
## The rules the starter relies on
|
|
95
|
-
|
|
96
|
-
Each rule is enforced by a test you can run on its own.
|
|
97
|
-
|
|
98
|
-
| # | Rule | Check |
|
|
99
|
-
| --- | --- | --- |
|
|
100
|
-
| 1 | Import `@
|
|
101
|
-
| 2 | Only `src/lib/store.ts` creates an SDK client, with the theme key. Everything else reads `Astro.locals.store.client`. | `npx vitest run tests/unit/guards.test.ts -t "creates SDK clients in one place only"` |
|
|
102
|
-
| 3 | A store that cannot be read renders the SDK's unavailable store (`unavailableStoreConfig`), built once in `src/middleware.ts`. | `npx vitest run tests/unit/guards.test.ts -t "unavailable store"` |
|
|
103
|
-
| 4 | Every platform page type is a surface with one required main section (twelve surfaces), plus the header and footer areas. | `npx vitest run tests/unit/contract.test.ts -t "every page the platform defines"` |
|
|
104
|
-
| 5 | The product and landing pages always hold an order form, and the theme definition is valid with every content key. | `npx vitest run tests/unit/contract.test.ts -t "is a valid catalog"` and `-t "guarantees an order form"` |
|
|
105
|
-
| 6 | Pages render their saved document, or the theme's default, through `src/components/surface/Sections.astro` (`resolveSurfaceDocument`), and settings through `resolveThemeSettings` (`src/lib/context.ts`). | `npx vitest run tests/unit/contract.test.ts -t "every page, rendered through the SDK"` |
|
|
106
|
-
| 7 | Every word is a copy key in ar, fr and en. A count is a plural message with each language's forms (Arabic has six). No key goes unread. | `npx vitest run tests/unit/copy.test.ts` |
|
|
107
|
-
| 8 | No copy, default or preset states a fact about a store (delivery reach, periods, percentages, hours, phone calls). | `npx vitest run tests/unit/copy.test.ts -t "states no fact about a store"` |
|
|
108
|
-
| 9 | Every link to a platform page uses `storefrontPath` and `localizeHref`, never a hand-written path. | `npx vitest run tests/unit/guards.test.ts -t "storefrontPath"` |
|
|
109
|
-
| 10 | Every WhatsApp link comes from `storeWhatsApp()` in `src/lib/whatsapp.ts`. No file writes a `wa.me` link. | `npx vitest run tests/unit/guards.test.ts -t "is reached one way"` |
|
|
110
|
-
| 11 | Colours come from colour schemes: every section has a `scheme` field, tokens derive from `--
|
|
111
|
-
| 12 | A photo a merchant picks is an `image` field, drawn from the store's media delivery (`src/lib/images.ts`). Never type a URL into it, and never hot-link a photo. | `npx vitest run tests/unit/contract.test.ts -t "never type an image URL"`, then `npx vitest run tests/unit/images.test.ts` |
|
|
112
|
-
| 13 | Layout uses logical properties. A physical left or right appears only in a rule that names one direction or the WhatsApp widget's side. | `npx vitest run tests/unit/guards.test.ts -t "logical properties"` |
|
|
113
|
-
| 14 | Browser behaviour binds through `bindEach` and `onEachPage` (`@abcart/theme/lifecycle`), so Studio's preview can swap a section. | `npx vitest run tests/unit/guards.test.ts -t "binds every behaviour through the SDK's lifecycle"` |
|
|
114
|
-
| 15 | Browser code never imports Zod, a schema or a server-only module, and takes only `/lifecycle` and `/messages` from `@abcart/theme`. | `npx vitest run tests/unit/guards.test.ts -t "the theme's browser code"` |
|
|
115
|
-
| 16 | The browser never decides a price, a fee, a discount or an order. The order form posts to the `placeOrder` action, which calls `executePlaceOrder`, and quotes come from `createQuoter`. | `npx vitest run tests/unit/guards.test.ts -t "gives every order form its checkout key"` |
|
|
116
|
-
| 17 | The theme writes nothing to the store's documents, settings or text. Its only routes are the shopper's API calls the browser makes, and Studio's revalidation. | `npx vitest run tests/unit/guards.test.ts -t "mounts a route file at every API path"`, then `npx vitest run tests/unit/studio.test.ts -t "answers only POST"` |
|
|
117
|
-
| 18 | A missing product, collection, category, page or landing page answers with `notFound(Astro)`, never cached. | `npx vitest run tests/unit/guards.test.ts -t "through the SDK's notFound"` |
|
|
118
|
-
| 19 | Every cached page carries the `pages` tag, so a publish shows at once. | `npx vitest run tests/unit/studio.test.ts -t "caches every composed route"` |
|
|
119
|
-
| 20 | The theme builds for Cloudflare Workers and for Vercel from the same code. Never remove a host or a feature. | `npx vitest run tests/unit/guards.test.ts -t "builds for Cloudflare Workers and for Vercel"`, then `npm run build` and `npm run build:vercel` |
|
|
120
|
-
| 21 | No design value is a literal in a stylesheet: sizes, line heights, letter-spacing, weights, colours, radii, shadows, borders, surfaces, filters, aspect ratios, motion and opacity are tokens in `src/styles/tokens.css`. Layout geometry stays in the stylesheets. | `npx vitest run tests/unit/design-values.test.ts -t "names every design value"` |
|
|
121
|
-
| 22 | A script reads every timing it runs from a motion token (`motionMs` in `src/lib/motion.ts`), except the behaviour timers the guard names. | `npx vitest run tests/unit/design-values.test.ts -t "reads every timing"` |
|
|
122
|
-
| 23 | An inline style carries data only (an index, a merchant's value), never a design number of its own. | `npx vitest run tests/unit/design-values.test.ts -t "keeps inline styles"` |
|
|
123
|
-
| 24 | Every motion token a script reads is defined in `tokens.css` with a value. | `npx vitest run tests/unit/design-values.test.ts -t "gives every motion value"` |
|
|
124
|
-
| 25 | A token that reads a colour of the colour scheme is defined in the `:root, .
|
|
125
|
-
| 26 | Done means `npm run check` (0 errors, 0 warnings), `npm test`, `npm run build` and `npm run build:vercel` pass, and you quote their output. | Run all four. |
|
|
126
|
-
| 27 | Every colour scheme keeps its text, headings and accents at WCAG AA (4.5:1) on its background, and its button words on its button. A light band takes dark ink. | `npx vitest run tests/unit/contrast.test.ts` |
|
|
127
|
-
| 28 | A person's name (a reviewer, a testimonial) carries `dir="auto"`, so a Latin name's full stop stays after it. | `npx vitest run tests/unit/rules.test.ts -t "own direction"` |
|
|
128
|
-
| 29 | The add-to-cart confirmation shows only when no cart drawer opens with it, so it never covers the drawer. | `npx vitest run tests/unit/rules.test.ts -t "drawer"` |
|
|
129
|
-
| 30 | A phone-width token is named `-narrow`, never `-phone`; a row of testimonials or reviews fills its row (`repeat(auto-fit, …)`). | `npx vitest run tests/unit/rules.test.ts -t "phone-width"`, then `-t "fills a row"` |
|
|
130
|
-
|
|
131
|
-
A new rule gets a guard test in `tests/unit/`, and you prove the guard by
|
|
132
|
-
breaking the code once and watching it fail.
|
|
133
|
-
|
|
134
|
-
## Stop and ask instead of going on when
|
|
135
|
-
|
|
136
|
-
- the export, field or option you need is not in the installed declarations;
|
|
137
|
-
- the only way forward is a deep import (`@
|
|
138
|
-
code into the theme, a `@ts-ignore`, or a cast that hides an SDK type error;
|
|
139
|
-
- a change would rename `THEME_KEY`, a section type, a field key or a shipped
|
|
140
|
-
instance id, or remove a section, a field or a copy key merchants may have
|
|
141
|
-
edited (that needs a new major version);
|
|
142
|
-
- a check fails and fixing it would mean changing the SDK;
|
|
143
|
-
- a design or a request asks the theme to state a fact about a store;
|
|
144
|
-
- a design asks for a feature the platform does not have (shopper accounts,
|
|
145
|
-
a wishlist, card payments, a blog, a newsletter): leave it out and say so;
|
|
146
|
-
- you cannot run the checks. Say so, and never claim the work is done.
|
|
1
|
+
---
|
|
2
|
+
name: abcart-docs
|
|
3
|
+
description: Where to find the truth about the AbCart SDKs and this theme's contract before you use or state any of it — the starter file that already does it, the installed declaration that defines it, the documentation page that explains it, and the rules the starter's tests enforce. Use before calling an SDK function, adding a field or a section, answering a question about how AbCart behaves, or when a check fails.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Looking things up in an AbCart theme
|
|
7
|
+
|
|
8
|
+
`abcart-theme-from-design` sends you here before every SDK name, field or
|
|
9
|
+
platform claim, and whenever a check fails. So does `shopify-theme-asset-collector`
|
|
10
|
+
when its output is used to build a theme.
|
|
11
|
+
Return to the step that sent you once you have the answer.
|
|
12
|
+
|
|
13
|
+
## The rule
|
|
14
|
+
|
|
15
|
+
Look an answer up before any SDK call, field or claim about the platform.
|
|
16
|
+
Three sources agree, and you read them together:
|
|
17
|
+
|
|
18
|
+
1. **The installed declarations**, `node_modules/@abcart/*/dist/*.d.ts`: every
|
|
19
|
+
export, field and type of the version this theme runs, with its
|
|
20
|
+
documentation comment. They are the final authority.
|
|
21
|
+
2. **This starter**: its code under `src/`, its tests under `tests/`,
|
|
22
|
+
`AGENTS.md` and `README.md`. It shows how each SDK piece is used, and each
|
|
23
|
+
rule below is enforced by a test.
|
|
24
|
+
3. **The documentation** at `https://docs.abcart.store`, written from the SDKs
|
|
25
|
+
and around this starter. It explains why things work as they do and how
|
|
26
|
+
the pieces fit. Every page is also Markdown at its URL plus `.md`.
|
|
27
|
+
|
|
28
|
+
If the three ever disagree, the installed declarations win: say so to the
|
|
29
|
+
developer. If the answer is in none of them, stop and ask. Never guess an
|
|
30
|
+
export, a field, a store setting or a platform behaviour.
|
|
31
|
+
|
|
32
|
+
## Finding an export
|
|
33
|
+
|
|
34
|
+
The packages publish these entry points only (each package's
|
|
35
|
+
`package.json` `exports`):
|
|
36
|
+
|
|
37
|
+
- `@abcart/storefront`, `@abcart/storefront/server` (server only),
|
|
38
|
+
`@abcart/storefront/astro` (server only), `@abcart/storefront/review-media`
|
|
39
|
+
- `@abcart/theme`, `@abcart/theme/astro`, `@abcart/theme/lifecycle`,
|
|
40
|
+
`@abcart/theme/messages`, `@abcart/theme/preview`,
|
|
41
|
+
`@abcart/theme/image-service`, and the four components
|
|
42
|
+
`@abcart/theme/astro/InstanceView.astro`, `@abcart/theme/astro/Blocks.astro`,
|
|
43
|
+
`@abcart/theme/astro/Block.astro` and `@abcart/theme/astro/ThemeStyles.astro`
|
|
44
|
+
|
|
45
|
+
To find a name and read its documentation comment:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
grep -rn "createQuoter" node_modules/@abcart/storefront/dist/*.d.ts
|
|
49
|
+
grep -rn "type FieldKind" node_modules/@abcart/theme/dist/*.d.ts
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Then find how the starter already uses it (`grep -rn "createQuoter" src`),
|
|
53
|
+
and do it the same way.
|
|
54
|
+
|
|
55
|
+
## SDK names the starter uses
|
|
56
|
+
|
|
57
|
+
Each name below is exported by that entry point in the installed version.
|
|
58
|
+
Check any other name the same way before you use it.
|
|
59
|
+
|
|
60
|
+
| Entry point | Names |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `@abcart/storefront` | `storefrontPath`, `localizeHref`, `localeRouting`, `servedLanguage`, `unavailableStoreConfig`, `whatsAppContact`, `canonicalUrl`, `pictureOf`, `mediaImageUrl`, `mediaImageSrcset`, `createQuoter`, `createBrowserAbandonedCheckoutTracker`, `Review`, `PickedImage`, `StoreConfigSchema` (with `phoneValidationEnabled`), `CheckoutFormPolicySchema` (with `stopDeskSavingsBadge`) |
|
|
63
|
+
| `@abcart/storefront/server` | `createStoreClient`, `readPreviewRequest`, `readRevalidateRequest`, `StoreClient` |
|
|
64
|
+
| `@abcart/storefront/astro` | `resolveStoreRequest`, `resolvePreviewStore`, `runFormAction`, `executePlaceOrder`, `placeOrderInput` (strict DZ mobile or relaxed 8–30 chars when phone validation disabled), `lookupOrder`, `orderLookupInput`, `notFound` |
|
|
65
|
+
| `@abcart/storefront/review-media` | `createReviewSession` |
|
|
66
|
+
| `@abcart/theme` | `defineTheme`, `defineComponent`, `defineCapabilities`, `resolveSurfaceDocument`, `resolveThemeSettings`, `schemeClass`, `styleClasses`, `richTextToHtml`, `formatMessage`, `pluralFormIssues`, `validateThemeDefinition`, `validatePageData`, `validateThemeManifest`, `themeManifest`, `diffThemeManifests`, `THEME_PREVIEW_PATH`, `SCHEME_MARKER_CLASS`, `FieldKind`, `ResolvedImage`, `StyleValue` |
|
|
67
|
+
| `@abcart/theme/astro` | `createReadCache`, `isPreview`, `themeManifestEndpoint`, `themeStylesEndpoint`, `previewTarget` |
|
|
68
|
+
| `@abcart/theme/lifecycle` | `bindEach`, `onEachPage` |
|
|
69
|
+
|
|
70
|
+
## Where to look
|
|
71
|
+
|
|
72
|
+
| Question | The starter file that answers it | The declaration to check | Documentation |
|
|
73
|
+
| --- | --- | --- | --- |
|
|
74
|
+
| How is this project laid out, and how does a request become a page? | `AGENTS.md`, `README.md` | | https://docs.abcart.store/sdk/theme/project |
|
|
75
|
+
| How does the theme reach the store? | `src/lib/store.ts` (the only `createStoreClient()`), `src/lib/context.ts`, `src/middleware.ts` | `@abcart/storefront/server`, `@abcart/storefront/astro` | https://docs.abcart.store/sdk/storefront/how-it-works |
|
|
76
|
+
| What does a page know about its store? | `src/lib/context.ts` (`Astro.locals.store`) | `StoreConfig` in `@abcart/storefront` (including `phoneValidationEnabled`) | https://docs.abcart.store/sdk/storefront/config |
|
|
77
|
+
| How is an order placed? | `src/components/checkout/OrderForm.astro`, `src/scripts/order-form.ts`, `src/scripts/checkout/`, `src/actions/index.ts` | `executePlaceOrder`, `placeOrderInput` (strict or relaxed phone, `stopDeskSavingsBadge`) | https://docs.abcart.store/sdk/storefront/checkout |
|
|
78
|
+
| How are prices, offers and delivery fees shown? | `src/scripts/checkout/quote.ts`, `src/scripts/cart.ts`, `src/pages/api/cart/validate.ts` | `createQuoter` | https://docs.abcart.store/sdk/storefront/basket |
|
|
79
|
+
| Wilayas, communes, delivery types? | `src/scripts/checkout/delivery.ts`, `src/pages/api/communes/[wilayaId].ts` | `@abcart/storefront` | https://docs.abcart.store/sdk/storefront/delivery |
|
|
80
|
+
| Images? | `src/lib/images.ts`, `src/components/ui/Photo.astro` | `pictureOf`, `mediaImageUrl`, `mediaImageSrcset` | https://docs.abcart.store/sdk/theme/images |
|
|
81
|
+
| WhatsApp? | `src/lib/whatsapp.ts` (`storeWhatsApp()`) | `whatsAppContact` | https://docs.abcart.store/sdk/storefront/presentation |
|
|
82
|
+
| Reviews? | `src/components/product/ProductReviews.astro`, `src/scripts/reviews.ts`, `src/pages/api/reviews/` | `createReviewSession` | https://docs.abcart.store/sdk/storefront/reviews |
|
|
83
|
+
| Studio's preview and the revalidation after a publish? | `src/pages/abcart-preview.astro`, `src/pages/abcart-revalidate.ts`, `src/lib/store.ts`, `routeRules` in `astro.config.mjs`, `tests/unit/studio.test.ts` | `readPreviewRequest`, `readRevalidateRequest` | https://docs.abcart.store/sdk/theme/preview |
|
|
84
|
+
| The manifest Studio reads? | `src/theme/theme.ts`, `src/pages/abcart-theme.json.ts` | `themeManifestEndpoint`, `validateThemeManifest` | https://docs.abcart.store/sdk/theme/manifest |
|
|
85
|
+
| Sections, fields, page documents? | `src/theme/sections/`, `src/theme/fields.ts`, `src/theme/documents/`, `src/components/surface/Sections.astro` | `defineComponent`, `FieldKind`, `resolveSurfaceDocument` | https://docs.abcart.store/sdk/theme/fields, https://docs.abcart.store/sdk/theme/composition, https://docs.abcart.store/sdk/theme/pages |
|
|
86
|
+
| Restyling, words, a new field or section? | `src/styles/tokens.css`, `src/theme/settings.ts`, `src/theme/content/`, `src/theme/sections/index.ts` | | https://docs.abcart.store/sdk/theme/customize |
|
|
87
|
+
| Words, translations and plurals? | `src/theme/content/`, `src/lib/i18n.ts`, `src/lib/browser-copy.ts` | `formatMessage`, `pluralFormIssues` | https://docs.abcart.store/sdk/theme/settings-copy |
|
|
88
|
+
| Settings, colours and the look? | `src/theme/palette.ts`, `src/theme/settings.ts`, `src/styles/tokens.css`, `src/components/ui/Section.astro` | `resolveThemeSettings`, `schemeClass`, `styleClasses` | https://docs.abcart.store/sdk/theme/style |
|
|
89
|
+
| Languages and links? | `src/lib/context.ts`, `src/lib/nav.ts` | `storefrontPath`, `localizeHref`, `localeRouting`, `isSingleLanguagePage` | https://docs.abcart.store/sdk/storefront/content |
|
|
90
|
+
| Building and deploying? | `package.json` scripts, `astro.config.mjs`, `wrangler.jsonc`, `README.md` | | https://docs.abcart.store/sdk/theme/starter, https://docs.abcart.store/sdk/theme/production |
|
|
91
|
+
| Testing? | `tests/unit/` | `validateThemeDefinition`, `validatePageData` | https://docs.abcart.store/sdk/theme/testing |
|
|
92
|
+
| Something renders wrong? | The server log: `src/components/surface/Sections.astro` warns about each document issue and section error, and `src/lib/store.ts` warns about each failed store read, both prefixed with the theme key | `RendererIssue` in `@abcart/theme/astro` | https://docs.abcart.store/sdk/theme/troubleshooting |
|
|
93
|
+
|
|
94
|
+
## The rules the starter relies on
|
|
95
|
+
|
|
96
|
+
Each rule is enforced by a test you can run on its own.
|
|
97
|
+
|
|
98
|
+
| # | Rule | Check |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| 1 | Import `@abcart/*` through the published entry points only, and find every name in the installed declarations. | `npx vitest run tests/unit/guards.test.ts -t "published entry points only"`, then `npm run check` |
|
|
101
|
+
| 2 | Only `src/lib/store.ts` creates an SDK client, with the theme key. Everything else reads `Astro.locals.store.client`. | `npx vitest run tests/unit/guards.test.ts -t "creates SDK clients in one place only"` |
|
|
102
|
+
| 3 | A store that cannot be read renders the SDK's unavailable store (`unavailableStoreConfig`), built once in `src/middleware.ts`. | `npx vitest run tests/unit/guards.test.ts -t "unavailable store"` |
|
|
103
|
+
| 4 | Every platform page type is a surface with one required main section (twelve surfaces), plus the header and footer areas. | `npx vitest run tests/unit/contract.test.ts -t "every page the platform defines"` |
|
|
104
|
+
| 5 | The product and landing pages always hold an order form, and the theme definition is valid with every content key. | `npx vitest run tests/unit/contract.test.ts -t "is a valid catalog"` and `-t "guarantees an order form"` |
|
|
105
|
+
| 6 | Pages render their saved document, or the theme's default, through `src/components/surface/Sections.astro` (`resolveSurfaceDocument`), and settings through `resolveThemeSettings` (`src/lib/context.ts`). | `npx vitest run tests/unit/contract.test.ts -t "every page, rendered through the SDK"` |
|
|
106
|
+
| 7 | Every word is a copy key in ar, fr and en. A count is a plural message with each language's forms (Arabic has six). No key goes unread. | `npx vitest run tests/unit/copy.test.ts` |
|
|
107
|
+
| 8 | No copy, default or preset states a fact about a store (delivery reach, periods, percentages, hours, phone calls). | `npx vitest run tests/unit/copy.test.ts -t "states no fact about a store"` |
|
|
108
|
+
| 9 | Every link to a platform page uses `storefrontPath` and `localizeHref`, never a hand-written path. | `npx vitest run tests/unit/guards.test.ts -t "storefrontPath"` |
|
|
109
|
+
| 10 | Every WhatsApp link comes from `storeWhatsApp()` in `src/lib/whatsapp.ts`. No file writes a `wa.me` link. | `npx vitest run tests/unit/guards.test.ts -t "is reached one way"` |
|
|
110
|
+
| 11 | Colours come from colour schemes: every section has a `scheme` field, tokens derive from `--ab-color-*` on the SDK's marker class, and every brand value lives in `src/styles/tokens.css`. | `npx vitest run tests/unit/contract.test.ts -t "colour scheme"`, then `npx vitest run tests/unit/guards.test.ts -t "keeps every brand value in tokens.css"` and `-t "scheme marker"` |
|
|
111
|
+
| 12 | A photo a merchant picks is an `image` field, drawn from the store's media delivery (`src/lib/images.ts`). Never type a URL into it, and never hot-link a photo. | `npx vitest run tests/unit/contract.test.ts -t "never type an image URL"`, then `npx vitest run tests/unit/images.test.ts` |
|
|
112
|
+
| 13 | Layout uses logical properties. A physical left or right appears only in a rule that names one direction or the WhatsApp widget's side. | `npx vitest run tests/unit/guards.test.ts -t "logical properties"` |
|
|
113
|
+
| 14 | Browser behaviour binds through `bindEach` and `onEachPage` (`@abcart/theme/lifecycle`), so Studio's preview can swap a section. | `npx vitest run tests/unit/guards.test.ts -t "binds every behaviour through the SDK's lifecycle"` |
|
|
114
|
+
| 15 | Browser code never imports Zod, a schema or a server-only module, and takes only `/lifecycle` and `/messages` from `@abcart/theme`. | `npx vitest run tests/unit/guards.test.ts -t "the theme's browser code"` |
|
|
115
|
+
| 16 | The browser never decides a price, a fee, a discount or an order. The order form posts to the `placeOrder` action, which calls `executePlaceOrder`, and quotes come from `createQuoter`. | `npx vitest run tests/unit/guards.test.ts -t "gives every order form its checkout key"` |
|
|
116
|
+
| 17 | The theme writes nothing to the store's documents, settings or text. Its only routes are the shopper's API calls the browser makes, and Studio's revalidation. | `npx vitest run tests/unit/guards.test.ts -t "mounts a route file at every API path"`, then `npx vitest run tests/unit/studio.test.ts -t "answers only POST"` |
|
|
117
|
+
| 18 | A missing product, collection, category, page or landing page answers with `notFound(Astro)`, never cached. | `npx vitest run tests/unit/guards.test.ts -t "through the SDK's notFound"` |
|
|
118
|
+
| 19 | Every cached page carries the `pages` tag, so a publish shows at once. | `npx vitest run tests/unit/studio.test.ts -t "caches every composed route"` |
|
|
119
|
+
| 20 | The theme builds for Cloudflare Workers and for Vercel from the same code. Never remove a host or a feature. | `npx vitest run tests/unit/guards.test.ts -t "builds for Cloudflare Workers and for Vercel"`, then `npm run build` and `npm run build:vercel` |
|
|
120
|
+
| 21 | No design value is a literal in a stylesheet: sizes, line heights, letter-spacing, weights, colours, radii, shadows, borders, surfaces, filters, aspect ratios, motion and opacity are tokens in `src/styles/tokens.css`. Layout geometry stays in the stylesheets. | `npx vitest run tests/unit/design-values.test.ts -t "names every design value"` |
|
|
121
|
+
| 22 | A script reads every timing it runs from a motion token (`motionMs` in `src/lib/motion.ts`), except the behaviour timers the guard names. | `npx vitest run tests/unit/design-values.test.ts -t "reads every timing"` |
|
|
122
|
+
| 23 | An inline style carries data only (an index, a merchant's value), never a design number of its own. | `npx vitest run tests/unit/design-values.test.ts -t "keeps inline styles"` |
|
|
123
|
+
| 24 | Every motion token a script reads is defined in `tokens.css` with a value. | `npx vitest run tests/unit/design-values.test.ts -t "gives every motion value"` |
|
|
124
|
+
| 25 | A token that reads a colour of the colour scheme is defined in the `:root, .ab-scheme` block, never in the plain `:root` block. | `npx vitest run tests/unit/design-values.test.ts -t "keeps colour-dependent tokens"` |
|
|
125
|
+
| 26 | Done means `npm run check` (0 errors, 0 warnings), `npm test`, `npm run build` and `npm run build:vercel` pass, and you quote their output. | Run all four. |
|
|
126
|
+
| 27 | Every colour scheme keeps its text, headings and accents at WCAG AA (4.5:1) on its background, and its button words on its button. A light band takes dark ink. | `npx vitest run tests/unit/contrast.test.ts` |
|
|
127
|
+
| 28 | A person's name (a reviewer, a testimonial) carries `dir="auto"`, so a Latin name's full stop stays after it. | `npx vitest run tests/unit/rules.test.ts -t "own direction"` |
|
|
128
|
+
| 29 | The add-to-cart confirmation shows only when no cart drawer opens with it, so it never covers the drawer. | `npx vitest run tests/unit/rules.test.ts -t "drawer"` |
|
|
129
|
+
| 30 | A phone-width token is named `-narrow`, never `-phone`; a row of testimonials or reviews fills its row (`repeat(auto-fit, …)`). | `npx vitest run tests/unit/rules.test.ts -t "phone-width"`, then `-t "fills a row"` |
|
|
130
|
+
|
|
131
|
+
A new rule gets a guard test in `tests/unit/`, and you prove the guard by
|
|
132
|
+
breaking the code once and watching it fail.
|
|
133
|
+
|
|
134
|
+
## Stop and ask instead of going on when
|
|
135
|
+
|
|
136
|
+
- the export, field or option you need is not in the installed declarations;
|
|
137
|
+
- the only way forward is a deep import (`@abcart/*/dist/…`), copying SDK
|
|
138
|
+
code into the theme, a `@ts-ignore`, or a cast that hides an SDK type error;
|
|
139
|
+
- a change would rename `THEME_KEY`, a section type, a field key or a shipped
|
|
140
|
+
instance id, or remove a section, a field or a copy key merchants may have
|
|
141
|
+
edited (that needs a new major version);
|
|
142
|
+
- a check fails and fixing it would mean changing the SDK;
|
|
143
|
+
- a design or a request asks the theme to state a fact about a store;
|
|
144
|
+
- a design asks for a feature the platform does not have (shopper accounts,
|
|
145
|
+
a wishlist, card payments, a blog, a newsletter): leave it out and say so;
|
|
146
|
+
- you cannot run the checks. Say so, and never claim the work is done.
|