@tanqory/partner-cli 0.0.0-stage → 0.1.0-alpha.2

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/bin/tanqory-partner.mjs +10 -0
  3. package/config/mirror-allowlist.json +17 -0
  4. package/config/theme-licences.json +108 -0
  5. package/config/third-party-toolchains.json +45 -0
  6. package/lib/api.mjs +109 -0
  7. package/lib/auth.mjs +211 -0
  8. package/lib/check.mjs +66 -0
  9. package/lib/cli.mjs +217 -0
  10. package/lib/mcp.mjs +177 -0
  11. package/lib/ops.mjs +179 -0
  12. package/lib/theme.mjs +121 -0
  13. package/lib/vendor/partner-checks.cjs +2420 -0
  14. package/package.json +59 -4
  15. package/starter/LICENSE +18 -0
  16. package/starter/README.md +44 -0
  17. package/starter/config/settings.json +5 -0
  18. package/starter/gitignore +3 -0
  19. package/starter/locales/en.json +22 -0
  20. package/starter/locales/en.schema.json +69 -0
  21. package/starter/locales/th.json +22 -0
  22. package/starter/locales/th.schema.json +69 -0
  23. package/starter/package.json +29 -0
  24. package/starter/regions/footer.json +35 -0
  25. package/starter/regions/header.json +13 -0
  26. package/starter/scripts/build.mjs +211 -0
  27. package/starter/scripts/probe.ts +4 -0
  28. package/starter/src/bundle.ts +15 -0
  29. package/starter/src/components/parts.tsx +32 -0
  30. package/starter/src/entry.client.tsx +6 -0
  31. package/starter/src/entry.server.tsx +13 -0
  32. package/starter/src/sections/chrome.tsx +132 -0
  33. package/starter/src/sections/commerce.tsx +242 -0
  34. package/starter/src/sections/content.tsx +115 -0
  35. package/starter/src/sections/editorial.tsx +232 -0
  36. package/starter/src/settings.ts +12 -0
  37. package/starter/src/styles/theme.css +241 -0
  38. package/starter/src/templates.ts +14 -0
  39. package/starter/src/theme.tsx +86 -0
  40. package/starter/templates/404.json +14 -0
  41. package/starter/templates/account.json +14 -0
  42. package/starter/templates/article.json +14 -0
  43. package/starter/templates/blog.json +14 -0
  44. package/starter/templates/cart.json +14 -0
  45. package/starter/templates/collection.json +14 -0
  46. package/starter/templates/index.json +116 -0
  47. package/starter/templates/page.contact.json +22 -0
  48. package/starter/templates/page.json +14 -0
  49. package/starter/templates/product.json +18 -0
  50. package/starter/templates/search.json +14 -0
  51. package/starter/tsconfig.json +17 -0
  52. package/starter/vite.client.config.ts +17 -0
  53. package/starter/vite.probe.config.ts +16 -0
  54. package/starter/vite.server.config.ts +32 -0
  55. package/README.md +0 -3
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@tanqory/partner-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "Build, check and upload Tanqory partner themes: a starter that passes every partner check, the platform's own partner source checks run locally, packaging, upload through the Partner API with your partner sign-in, and an MCP server with the same operations.",
5
+ "license": "MIT",
6
+ "author": "Tanqory",
7
+ "keywords": [
8
+ "tanqory",
9
+ "theme",
10
+ "partner",
11
+ "cli",
12
+ "mcp",
13
+ "model-context-protocol"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tanqory/tanqory-platform-v2.git",
18
+ "directory": "packages/partner-cli"
19
+ },
20
+ "type": "module",
21
+ "bin": {
22
+ "tanqory-partner": "./bin/tanqory-partner.mjs"
23
+ },
24
+ "exports": {
25
+ ".": "./lib/ops.mjs",
26
+ "./mcp": "./lib/mcp.mjs",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "bin",
31
+ "lib",
32
+ "config",
33
+ "starter",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "engines": {
38
+ "node": ">=20.11.0"
39
+ },
40
+ "dependencies": {
41
+ "@tanqory/theme-abi": "2.0.0-alpha.14",
42
+ "acorn": "^8.15.0",
43
+ "acorn-walk": "^8.3.4",
44
+ "tar": "^7.5.2",
45
+ "yaml": "^2.9.1",
46
+ "zod": "^3.25.76"
47
+ },
48
+ "devDependencies": {
49
+ "esbuild": "0.28.2"
50
+ },
51
+ "scripts": {
52
+ "prepare:vendor": "node scripts/prepare.mjs",
53
+ "check:vendor": "node scripts/prepare.mjs --check",
54
+ "test": "node --test test/*.test.mjs"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org/",
59
+ "tag": "next"
60
+ }
61
+ }
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 the author of this theme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+
18
+ Third-party software this theme runs on: @tanqory/theme-kit (MIT) and React (MIT).
@@ -0,0 +1,44 @@
1
+ # Tanqory partner theme starter
2
+
3
+ A small, plain theme for Tanqory stores on Theme Runtime ABI v2 and `@tanqory/theme-kit/headless`. It passes every
4
+ partner check as it is, so you start from a green version and keep it green.
5
+
6
+ ```sh
7
+ npm install -g @tanqory/partner-cli@next
8
+ tanqory-partner theme init my-theme
9
+ cd my-theme && npm install
10
+ tanqory-partner theme check # build, then the partner checks that need no sandbox
11
+ tanqory-partner theme package # dist/partner/<name>-<version>.tgz and manifest.json
12
+ tanqory-partner login
13
+ tanqory-partner theme push --org <organization id> --theme <handle>
14
+ ```
15
+
16
+ ## What is here
17
+
18
+ | Path | What it is |
19
+ |---|---|
20
+ | `src/theme.tsx` | `defineTheme`: the sections list and the layout |
21
+ | `src/sections/*.tsx` | Header, footer, home sections, product, collection, cart, search, page, blog, account, 404 |
22
+ | `src/components/`, `src/styles/` | Your markup and all of the theme's CSS (the kit ships none) |
23
+ | `src/settings.ts`, `src/templates.ts` | Theme settings (the editor's Theme panel) and the page types |
24
+ | `templates/*.json`, `regions/*.json`, `config/settings.json` | Starter content a merchant sees first |
25
+ | `locales/en.json`, `locales/th.json` | Interface words in English and Thai (buttons, form labels, the cart). Shop words are section settings |
26
+ | `locales/en.schema.json`, `locales/th.schema.json` | The editor's words for your section, block and setting names (`t:` labels) |
27
+ | `scripts/build.mjs`, `vite.*.config.ts`, `src/entry.*`, `src/bundle.ts` | The build into `dist/abi` (the platform runs this same build in its sandbox) |
28
+ | `LICENSE` | Your theme's licence. Put your name in it. The licences check needs it. |
29
+
30
+ ## Rules the checks hold you to
31
+
32
+ - Editable (`EDITABILITY.md` of `@tanqory/theme-standard`): every word, image and link a shopper sees in a section is
33
+ a setting whose default is the real words, every list is blocks, every addable section has a preset with sample
34
+ settings and blocks, colours are theme settings, labels are `t:` keys with words in `locales/en.schema.json` and
35
+ `locales/th.schema.json`, and images are store files (never a guessed address). The starter's sections show each pattern.
36
+
37
+ - `package.json` pins `@tanqory/theme-kit` and `@tanqory/theme-abi` exactly to versions the platform's builder
38
+ carries. Other runtime dependencies are not installed by the builder; bundle what you need into `src/`.
39
+ - No `pnpm.overrides`, `resolutions`, workspaces, patches, `.npmrc`, `.env` files, shell scripts or native addons.
40
+ - The uploaded source has no lockfile: `theme package` leaves `package-lock.json` and `pnpm-lock.yaml` out (the builder
41
+ never installs from one, and the licences check would list your local developer tools as shipped).
42
+ - No network calls from the theme, no `eval` or `new Function`, no other commerce platform's name in any file.
43
+ - WCAG 2.2 AA: no serious or critical axe-core violation, touch targets at least 24 by 24 px, Lighthouse accessibility
44
+ 90 or more and performance 60 or more on the home, product and collection pages.
@@ -0,0 +1,5 @@
1
+ {
2
+ "colorBackground": "#ffffff",
3
+ "colorText": "#1f2328",
4
+ "colorAccent": "#1f2328"
5
+ }
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+ dist/
3
+ src/generated/
@@ -0,0 +1,22 @@
1
+ {
2
+ "starter.nav.main": "Main menu",
3
+ "starter.footer.menu": "More",
4
+ "starter.footer.rights": "Copyright {name}. All rights reserved.",
5
+ "starter.price.from": "From {price}",
6
+ "starter.shelf.viewAll": "View all",
7
+ "starter.shelf.empty": "Nothing on this shelf yet.",
8
+ "starter.product.missing": "This product is not available.",
9
+ "starter.collection.kicker": "Collection",
10
+ "starter.collection.none": "This collection is empty for now.",
11
+ "starter.cart.continue": "Continue shopping",
12
+ "starter.cart.view": "View cart",
13
+ "starter.cart.taxes": "Taxes and shipping are calculated at checkout.",
14
+ "starter.drawer.qty": "Qty {count}",
15
+ "starter.journal.read": "Read more",
16
+ "starter.journal.back": "Back to {blog}",
17
+ "starter.journal.by": "By {author}",
18
+ "starter.notFound.title": "Page not found",
19
+ "starter.notFound.body": "The link may be old, or the page has moved.",
20
+ "starter.notFound.home": "Back to home",
21
+ "seo.homeDescription": "{name}: shop online."
22
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "descriptions": {
3
+ "a_city_or_what_they_bought": "A city, or what they bought.",
4
+ "a_heading_a_short_line_an": "A heading, a short line, an optional image and one link.",
5
+ "a_heading_and_a_paragraph_set": "A heading and a paragraph, set narrow.",
6
+ "a_heading_and_a_row_of": "A heading and a row of short points, each with an optional image and link. Add, remove and reorder them.",
7
+ "a_message_form_that_reaches_the": "A message form that reaches the store.",
8
+ "a_row_of_products_from_one": "A row of products from one collection.",
9
+ "an_email_sign_up_for_the": "An email sign-up for the store’s newsletter.",
10
+ "products_shoppers_buy_with_this_one": "Products shoppers buy with this one.",
11
+ "the_collections_products_with_sort_filters": "The collection’s products with sort, filters and paging.",
12
+ "the_product_image_title_price_options": "The product: image, title, price, options and add to cart.",
13
+ "the_shop_name_menu_columns_and": "The shop name, menu columns and the legal line.",
14
+ "the_shop_name_the_main_menu": "The shop name, the main menu, search, region and the cart.",
15
+ "what_customers_say_a_heading_and": "What customers say: a heading and quotations. Add, remove and reorder them.",
16
+ "what_the_picture_shows_for_people": "What the picture shows, for people who cannot see it."
17
+ },
18
+ "labels": {
19
+ "account": "Account",
20
+ "article": "Article",
21
+ "background": "Background",
22
+ "blog": "Blog",
23
+ "brand": "Brand",
24
+ "button_label": "Button label",
25
+ "button_link": "Button link",
26
+ "buttons_and_links": "Buttons and links",
27
+ "cart": "Cart",
28
+ "collection": "Collection",
29
+ "colours": "Colours",
30
+ "columns": "Columns",
31
+ "contact_form": "Contact form",
32
+ "detail": "Detail",
33
+ "feature": "Feature",
34
+ "features": "Features",
35
+ "footer": "Footer",
36
+ "four": "Four",
37
+ "header": "Header",
38
+ "heading": "Heading",
39
+ "hero": "Hero",
40
+ "image": "Image",
41
+ "image_description": "Image description",
42
+ "kicker": "Kicker",
43
+ "link": "Link",
44
+ "link_label": "Link label",
45
+ "menu": "Menu",
46
+ "menu_column": "Menu column",
47
+ "name": "Name",
48
+ "newsletter": "Newsletter",
49
+ "not_found": "Not found",
50
+ "page": "Page",
51
+ "product": "Product",
52
+ "product_grid": "Product grid",
53
+ "products_to_show": "Products to show",
54
+ "quotation": "Quotation",
55
+ "recommendations": "Recommendations",
56
+ "rich_text": "Rich text",
57
+ "search_results": "Search results",
58
+ "show_country_and_language": "Show country and language",
59
+ "show_the_brand": "Show the brand",
60
+ "show_the_description": "Show the description",
61
+ "tagline": "Tagline",
62
+ "testimonial": "Testimonial",
63
+ "testimonials": "Testimonials",
64
+ "text": "Text",
65
+ "text_above_the_form": "Text above the form",
66
+ "three": "Three",
67
+ "two": "Two"
68
+ }
69
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "starter.nav.main": "เมนูหลัก",
3
+ "starter.footer.menu": "เพิ่มเติม",
4
+ "starter.footer.rights": "ลิขสิทธิ์ {name} สงวนลิขสิทธิ์",
5
+ "starter.price.from": "เริ่มต้น {price}",
6
+ "starter.shelf.viewAll": "ดูทั้งหมด",
7
+ "starter.shelf.empty": "ยังไม่มีสินค้าบนชั้นนี้",
8
+ "starter.product.missing": "สินค้านี้ไม่มีจำหน่าย",
9
+ "starter.collection.kicker": "คอลเลกชัน",
10
+ "starter.collection.none": "คอลเลกชันนี้ยังไม่มีสินค้า",
11
+ "starter.cart.continue": "เลือกซื้อสินค้าต่อ",
12
+ "starter.cart.view": "ดูตะกร้า",
13
+ "starter.cart.taxes": "ภาษีและค่าจัดส่งคำนวณตอนชำระเงิน",
14
+ "starter.drawer.qty": "จำนวน {count}",
15
+ "starter.journal.read": "อ่านต่อ",
16
+ "starter.journal.back": "กลับไปที่ {blog}",
17
+ "starter.journal.by": "โดย {author}",
18
+ "starter.notFound.title": "ไม่พบหน้านี้",
19
+ "starter.notFound.body": "ลิงก์อาจเก่าแล้ว หรือหน้านี้ถูกย้ายไป",
20
+ "starter.notFound.home": "กลับหน้าแรก",
21
+ "seo.homeDescription": "{name}: ช้อปออนไลน์"
22
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "descriptions": {
3
+ "a_city_or_what_they_bought": "เมือง หรือสิ่งที่ลูกค้าซื้อ",
4
+ "a_heading_a_short_line_an": "หัวข้อ ข้อความสั้น รูป (ไม่บังคับ) และลิงก์หนึ่งลิงก์",
5
+ "a_heading_and_a_paragraph_set": "หัวข้อและย่อหน้า จัดในคอลัมน์แคบ",
6
+ "a_heading_and_a_row_of": "หัวข้อและแถวของจุดเด่นสั้น ๆ แต่ละจุดมีรูปและลิงก์ได้ เพิ่ม ลบ และเรียงลำดับได้",
7
+ "a_message_form_that_reaches_the": "ฟอร์มส่งข้อความถึงร้าน",
8
+ "a_row_of_products_from_one": "แถวสินค้าจากคอลเลกชันเดียว",
9
+ "an_email_sign_up_for_the": "ช่องสมัครรับจดหมายข่าวของร้านทางอีเมล",
10
+ "products_shoppers_buy_with_this_one": "สินค้าที่ลูกค้ามักซื้อคู่กับชิ้นนี้",
11
+ "the_collections_products_with_sort_filters": "สินค้าในคอลเลกชัน พร้อมการเรียง ตัวกรอง และการแบ่งหน้า",
12
+ "the_product_image_title_price_options": "สินค้า: รูป ชื่อ ราคา ตัวเลือก และปุ่มหยิบใส่ตะกร้า",
13
+ "the_shop_name_menu_columns_and": "ชื่อร้าน คอลัมน์เมนู และข้อความทางกฎหมาย",
14
+ "the_shop_name_the_main_menu": "ชื่อร้าน เมนูหลัก ช่องค้นหา ภูมิภาค และตะกร้า",
15
+ "what_customers_say_a_heading_and": "ลูกค้าพูดถึงเรา: หัวข้อและคำรีวิว เพิ่ม ลบ และเรียงลำดับได้",
16
+ "what_the_picture_shows_for_people": "รูปนี้แสดงอะไร สำหรับผู้ที่มองไม่เห็นรูป"
17
+ },
18
+ "labels": {
19
+ "account": "บัญชี",
20
+ "article": "บทความ",
21
+ "background": "พื้นหลัง",
22
+ "blog": "บล็อก",
23
+ "brand": "แบรนด์",
24
+ "button_label": "ข้อความบนปุ่ม",
25
+ "button_link": "ลิงก์ของปุ่ม",
26
+ "buttons_and_links": "ปุ่มและลิงก์",
27
+ "cart": "ตะกร้า",
28
+ "collection": "คอลเลกชัน",
29
+ "colours": "สี",
30
+ "columns": "จำนวนคอลัมน์",
31
+ "contact_form": "ฟอร์มติดต่อ",
32
+ "detail": "รายละเอียด",
33
+ "feature": "จุดเด่น",
34
+ "features": "จุดเด่น",
35
+ "footer": "ส่วนท้าย",
36
+ "four": "สี่",
37
+ "header": "ส่วนหัว",
38
+ "heading": "หัวข้อ",
39
+ "hero": "แบนเนอร์หลัก",
40
+ "image": "รูปภาพ",
41
+ "image_description": "คำอธิบายรูป",
42
+ "kicker": "ข้อความนำ",
43
+ "link": "ลิงก์",
44
+ "link_label": "ข้อความลิงก์",
45
+ "menu": "เมนู",
46
+ "menu_column": "คอลัมน์เมนู",
47
+ "name": "ชื่อ",
48
+ "newsletter": "จดหมายข่าว",
49
+ "not_found": "ไม่พบหน้า",
50
+ "page": "หน้า",
51
+ "product": "สินค้า",
52
+ "product_grid": "ตารางสินค้า",
53
+ "products_to_show": "จำนวนสินค้าที่แสดง",
54
+ "quotation": "คำพูด",
55
+ "recommendations": "สินค้าแนะนำ",
56
+ "rich_text": "ข้อความจัดรูปแบบ",
57
+ "search_results": "ผลการค้นหา",
58
+ "show_country_and_language": "แสดงประเทศและภาษา",
59
+ "show_the_brand": "แสดงแบรนด์",
60
+ "show_the_description": "แสดงคำอธิบาย",
61
+ "tagline": "สโลแกน",
62
+ "testimonial": "คำรีวิว",
63
+ "testimonials": "คำรีวิว",
64
+ "text": "ข้อความ",
65
+ "text_above_the_form": "ข้อความเหนือฟอร์ม",
66
+ "three": "สาม",
67
+ "two": "สอง"
68
+ }
69
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "tanqory-partner-starter",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "A partner theme starter for Tanqory stores (Theme Runtime ABI v2, @tanqory/theme-kit/headless). Made with `tanqory-partner theme init`; checked with `tanqory-partner theme check`; uploaded with `tanqory-partner theme push`.",
7
+ "license": "SEE LICENSE IN LICENSE",
8
+ "tanqory": {
9
+ "build": "scripts/build.mjs",
10
+ "out": "dist/abi"
11
+ },
12
+ "scripts": {
13
+ "build": "node scripts/build.mjs",
14
+ "typecheck": "tsc --noEmit"
15
+ },
16
+ "dependencies": {
17
+ "@tanqory/theme-kit": "2.0.0-alpha.17",
18
+ "react": "18.3.1",
19
+ "react-dom": "18.3.1"
20
+ },
21
+ "devDependencies": {
22
+ "@tanqory/theme-abi": "2.0.0-alpha.14",
23
+ "@types/react": "^18.3.12",
24
+ "@types/react-dom": "^18.3.1",
25
+ "@vitejs/plugin-react": "^4.3.4",
26
+ "typescript": "~5.9.3",
27
+ "vite": "^5.4.10"
28
+ }
29
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "contentVersion": 1,
3
+ "region": "footer",
4
+ "sections": [
5
+ {
6
+ "id": "footer",
7
+ "type": "footer",
8
+ "blocks": [
9
+ {
10
+ "id": "footer-brand",
11
+ "type": "footer-brand",
12
+ "settings": {
13
+ "tagline": "Thank you for shopping with us."
14
+ }
15
+ },
16
+ {
17
+ "id": "footer-menu",
18
+ "type": "footer-menu",
19
+ "settings": {
20
+ "heading": "Explore",
21
+ "menu": "main-menu"
22
+ }
23
+ },
24
+ {
25
+ "id": "footer-menu-2",
26
+ "type": "footer-menu",
27
+ "settings": {
28
+ "heading": "Help",
29
+ "menu": "footer"
30
+ }
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "contentVersion": 1,
3
+ "region": "header",
4
+ "sections": [
5
+ {
6
+ "id": "header",
7
+ "type": "header",
8
+ "settings": {
9
+ "menu": "main-menu"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Build the theme as a Theme ABI v2 theme directory (the layout `theme-conformance` runs and the platform's build
3
+ * service packages into an artifact):
4
+ *
5
+ * dist/abi/manifest.json ThemeManifest v2, JCS + "\n" (from the theme's declarations)
6
+ * dist/abi/server/entry.mjs render(request, ctx) + manifest: one file, no imports
7
+ * dist/abi/client/client-manifest.json every browser file with its sha256 digest and SRI; one isEntry script
8
+ * dist/abi/client/assets/* content-hashed browser files
9
+ * dist/abi/defaults/{settings.json, regions/*.json, templates/*.json}
10
+ * dist/abi/locales/<lang>.json the theme's strings over the kit's
11
+ *
12
+ * node scripts/build.mjs exit 1 on any contract problem or hard size limit
13
+ *
14
+ * Vite and every package resolve from this theme's own node_modules.
15
+ */
16
+ import { execFileSync } from 'node:child_process'
17
+ import { createRequire } from 'node:module'
18
+ import { createHash } from 'node:crypto'
19
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
20
+ import { dirname, join, relative } from 'node:path'
21
+ import { fileURLToPath, pathToFileURL } from 'node:url'
22
+ import { gzipSync } from 'node:zlib'
23
+
24
+ const theme = join(dirname(fileURLToPath(import.meta.url)), '..')
25
+ const out = join(theme, 'dist', 'abi')
26
+ const require = createRequire(join(theme, 'package.json'))
27
+ const pkg = JSON.parse(readFileSync(join(theme, 'package.json'), 'utf8'))
28
+ const vitePkg = require.resolve('vite/package.json')
29
+ const vite = join(dirname(vitePkg), JSON.parse(readFileSync(vitePkg, 'utf8')).bin.vite)
30
+ const load = (spec) => import(pathToFileURL(require.resolve(spec)).href)
31
+
32
+ const { buildManifest, checkContent, withKitStrings, canonicalize } = await load('@tanqory/theme-kit/build')
33
+ const { validateManifest, validateFieldValue, PLATFORM_ROUTES } = await load('@tanqory/theme-abi')
34
+ const { LIMITS } = await load('@tanqory/theme-abi/limits')
35
+
36
+ const fail = (msg, list = []) => {
37
+ console.error(`✗ ${msg}`)
38
+ for (const l of list) console.error(` - ${l}`)
39
+ process.exit(1)
40
+ }
41
+ const readJson = (p) => JSON.parse(readFileSync(p, 'utf8'))
42
+ const writeJcs = (path, value) => {
43
+ mkdirSync(dirname(path), { recursive: true })
44
+ writeFileSync(path, `${canonicalize(value)}\n`)
45
+ }
46
+ const viteBuild = (config) => execFileSync(process.execPath, [vite, 'build', '--config', config, '--logLevel', 'warn'], { cwd: theme, stdio: 'inherit' })
47
+
48
+ // The kit's browser wire uses the contract's two prefixes.
49
+ if (PLATFORM_ROUTES.data !== '/_tq/data/' || PLATFORM_ROUTES.actions !== '/_tq/actions/') fail('PLATFORM_ROUTES changed: update @tanqory/theme-kit')
50
+
51
+ // Registry 2 (Appendix B.2): image/video may name a shipped `asset:client/assets/<file>`; text_alignment adds start/end.
52
+ const ASSET = /^asset:client\/assets\/([A-Za-z0-9._-]+)$/
53
+ const assetDir = join(theme, 'assets')
54
+ const shipped = new Set(existsSync(assetDir) ? readdirSync(assetDir) : [])
55
+ const checkValue = (type, value, spec) => {
56
+ if (type === 'text_alignment' && (value === 'start' || value === 'end')) return { ok: true }
57
+ if ((type === 'image' || type === 'video') && typeof value === 'string' && value.startsWith('asset:')) {
58
+ const m = ASSET.exec(value)
59
+ return m && shipped.has(m[1]) ? { ok: true } : { ok: false, errors: [{ message: `${value} is not a file under assets/`, code: 'asset_ref_missing' }] }
60
+ }
61
+ return validateFieldValue(type, value, spec)
62
+ }
63
+
64
+ // 1. the theme's declarations, loaded in Node
65
+ viteBuild('vite.probe.config.ts')
66
+ const probe = await import(pathToFileURL(join(theme, 'dist', '.probe', 'probe.mjs')).href)
67
+
68
+ // 2. the manifest + starter content, every stored value checked
69
+ const { manifest, problems } = buildManifest({
70
+ name: pkg.name,
71
+ version: pkg.version,
72
+ theme: probe.theme,
73
+ settings: probe.settings,
74
+ templates: probe.TEMPLATES,
75
+ forms: { newsletter: true, contact: true },
76
+ // Stock counts on the product page ("Only 3 left").
77
+ capabilities: { server: ['data:inventory'], browser: ['data:inventory'] },
78
+ checkValue,
79
+ })
80
+ const templates = {}
81
+ for (const f of readdirSync(join(theme, 'templates')).filter((n) => n.endsWith('.json')).sort()) {
82
+ const name = f.replace(/\.json$/, '')
83
+ if (!probe.TEMPLATES[name]) problems.push(`templates/${f}: not in src/templates.ts`)
84
+ const doc = readJson(join(theme, 'templates', f))
85
+ if (doc.template !== name) problems.push(`templates/${f}: "template" must be "${name}"`)
86
+ for (const [rid, r] of Object.entries(doc.regions ?? {})) problems.push(...checkContent(`templates/${f}.regions.${rid}`, r.sections ?? [], manifest, checkValue))
87
+ templates[name] = doc
88
+ }
89
+ for (const name of Object.keys(probe.TEMPLATES)) if (!templates[name]) problems.push(`templates/${name}.json is missing`)
90
+ const regions = {}
91
+ for (const r of ['header', 'footer']) {
92
+ const doc = readJson(join(theme, 'regions', `${r}.json`))
93
+ problems.push(...checkContent(`regions/${r}.json`, doc.sections ?? [], manifest, checkValue))
94
+ regions[r] = doc
95
+ }
96
+ const values = readJson(join(theme, 'config', 'settings.json'))
97
+ const specs = new Map(manifest.settingsSchema.flatMap((g) => g.items.map((it) => [it.key, it])))
98
+ for (const [k, v] of Object.entries(values)) {
99
+ const spec = specs.get(k)
100
+ if (!spec) problems.push(`config/settings.json.${k}: not a theme setting`)
101
+ else {
102
+ const r = checkValue(spec.type, v, spec)
103
+ if (!r.ok) problems.push(`config/settings.json.${k}: ${r.errors.map((e) => e.message).join('; ')}`)
104
+ }
105
+ }
106
+ // The editor's words for the theme's own section, block and setting names: labels written `t:<key>` are read from
107
+ // locales/<lang>.schema.json (the reference's schema translations), carried in the manifest's vendor key so the editor
108
+ // shows them in its language (packages/theme-standard EDITABILITY.md E9). The runtime never reads them.
109
+ {
110
+ const schemaLocales = {}
111
+ const flat = (o, p, out) => {
112
+ for (const [k, v] of Object.entries(o ?? {})) {
113
+ const key = p ? `${p}.${k}` : k
114
+ if (v && typeof v === 'object' && !Array.isArray(v)) flat(v, key, out)
115
+ else if (typeof v === 'string') out[key] = v
116
+ }
117
+ return out
118
+ }
119
+ for (const f of readdirSync(join(theme, 'locales')).filter((n) => n.endsWith('.schema.json'))) schemaLocales[f.replace(/\.schema\.json$/, '')] = flat(readJson(join(theme, 'locales', f)), '', {})
120
+ if (Object.keys(schemaLocales).length) manifest['x-tanqory-schema-locales'] = schemaLocales
121
+ }
122
+ const valid = validateManifest(manifest)
123
+ if (!valid.ok) for (const e of valid.errors) problems.push(`manifest${e.path}: ${e.message} (${e.code ?? e.keyword})`)
124
+ if (problems.length) fail(`${problems.length} contract problem(s)`, problems)
125
+
126
+ // 3. strings: the theme's over the kit's, for the bundle and for the artifact
127
+ const locales = {}
128
+ for (const f of readdirSync(join(theme, 'locales')).filter((n) => n.endsWith('.json') && !n.endsWith('.schema.json'))) locales[f.replace(/\.json$/, '')] = readJson(join(theme, 'locales', f))
129
+ const merged = withKitStrings(locales)
130
+ const gen = join(theme, 'src', 'generated')
131
+ rmSync(gen, { recursive: true, force: true })
132
+ for (const [lang, map] of Object.entries(merged)) writeJcs(join(gen, 'locales', `${lang}.json`), map)
133
+ writeJcs(join(gen, 'manifest.json'), manifest)
134
+
135
+ // 4. the browser bundle, then the serve entry (which imports the generated manifest)
136
+ rmSync(out, { recursive: true, force: true })
137
+ viteBuild('vite.client.config.ts')
138
+ viteBuild('vite.server.config.ts')
139
+
140
+ // 5. the theme directory
141
+ mkdirSync(join(out, 'server'), { recursive: true })
142
+ writeFileSync(join(out, 'server', 'entry.mjs'), readFileSync(join(theme, 'dist', 'build', 'server', 'entry.mjs')))
143
+ writeJcs(join(out, 'manifest.json'), manifest)
144
+ const built = join(theme, 'dist', 'build', 'client')
145
+ const clientDir = join(out, 'client')
146
+ const viteManifest = readJson(join(built, '.vite', 'manifest.json'))
147
+ const files = []
148
+ const walk = (dir) => {
149
+ for (const name of readdirSync(dir)) {
150
+ const p = join(dir, name)
151
+ if (statSync(p).isDirectory()) {
152
+ if (name !== '.vite') walk(p)
153
+ } else files.push(relative(built, p).split('\\').join('/'))
154
+ }
155
+ }
156
+ walk(built)
157
+ for (const f of shipped) files.push(`assets/${f}`)
158
+ const source = (f) => (f.startsWith('assets/') && shipped.has(f.slice(7)) && !existsSync(join(built, f)) ? join(assetDir, f.slice(7)) : join(built, f))
159
+ const kindOf = (f) => (/\.m?js$/.test(f) ? 'script' : /\.css$/.test(f) ? 'style' : /\.(woff2?|ttf|otf)$/.test(f) ? 'font' : /\.(png|jpe?g|gif|svg|webp|avif|ico)$/.test(f) ? 'image' : 'other')
160
+ const entryKey = Object.keys(viteManifest).find((k) => viteManifest[k].isEntry)
161
+ if (!entryKey) fail('vite produced no entry chunk')
162
+ const importsOf = (key, seen = new Set()) => {
163
+ for (const imp of viteManifest[key]?.imports ?? []) if (!seen.has(imp)) importsOf(imp, seen.add(imp))
164
+ return seen
165
+ }
166
+ const entryImports = [...importsOf(entryKey)].map((k) => viteManifest[k].file)
167
+ const entryCss = [...new Set([entryKey, ...importsOf(entryKey)].flatMap((k) => viteManifest[k].css ?? []))]
168
+ const clientManifest = {}
169
+ for (const f of [...new Set(files)].sort()) {
170
+ const bytes = readFileSync(source(f))
171
+ mkdirSync(dirname(join(clientDir, f)), { recursive: true })
172
+ writeFileSync(join(clientDir, f), bytes)
173
+ const sha = createHash('sha256').update(bytes).digest()
174
+ const isEntry = f === viteManifest[entryKey].file
175
+ clientManifest[isEntry ? 'main' : f] = {
176
+ file: f,
177
+ kind: kindOf(f),
178
+ ...(isEntry ? { isEntry: true, css: entryCss, imports: entryImports } : {}),
179
+ size: bytes.length,
180
+ digest: `sha256:${sha.toString('hex')}`,
181
+ integrity: `sha256-${sha.toString('base64')}`,
182
+ }
183
+ }
184
+ writeJcs(join(clientDir, 'client-manifest.json'), clientManifest)
185
+ writeJcs(join(out, 'defaults', 'settings.json'), { contentVersion: manifest.contentVersion, values })
186
+ for (const [name, doc] of Object.entries(regions)) writeJcs(join(out, 'defaults', 'regions', `${name}.json`), doc)
187
+ for (const [name, doc] of Object.entries(templates)) writeJcs(join(out, 'defaults', 'templates', `${name}.json`), doc)
188
+ for (const [lang, map] of Object.entries(merged)) writeJcs(join(out, 'locales', `${lang}.json`), map)
189
+ // the theme's licence (the licences check reads dist/abi/LICENSE)
190
+ writeFileSync(join(out, 'LICENSE'), readFileSync(join(theme, 'LICENSE')))
191
+
192
+ // 6. sizes against the limits table (§8): over budget warns, over hard fails
193
+ const entry = readFileSync(join(out, 'server', 'entry.mjs'))
194
+ const gz = (b) => gzipSync(b, { level: 9 }).length
195
+ const initial = [viteManifest[entryKey].file, ...entryImports, ...entryCss].reduce((n, f) => n + gz(readFileSync(join(clientDir, f))), 0)
196
+ const rows = [
197
+ ['ssrEntryRawBytes', entry.length],
198
+ ['ssrEntryGzipBytes', gz(entry)],
199
+ ['manifestBytes', readFileSync(join(out, 'manifest.json')).length],
200
+ ['clientInitialGzipBytes', initial],
201
+ ['clientTotalRawBytes', files.reduce((n, f) => n + statSync(join(clientDir, f)).size, 0)],
202
+ ]
203
+ let over = false
204
+ for (const [k, v] of rows) {
205
+ const { budget, hard } = LIMITS[k]
206
+ const verdict = v > hard ? 'OVER HARD' : budget !== null && v > budget ? 'over budget' : 'ok'
207
+ if (v > hard) over = true
208
+ console.log(`${k.padEnd(24)} ${String(v).padStart(10)} budget ${String(budget).padStart(10)} hard ${String(hard).padStart(10)} ${verdict}`)
209
+ }
210
+ if (over) fail('a hard size limit is exceeded')
211
+ console.log(`✓ ${relative(process.cwd(), out) || out}`)
@@ -0,0 +1,4 @@
1
+ /** The theme's declarations, for the build (bundled by vite.probe.config.ts and imported in Node). */
2
+ export { default as theme } from '../src/theme'
3
+ export { settings } from '../src/settings'
4
+ export { TEMPLATES } from '../src/templates'
@@ -0,0 +1,15 @@
1
+ /** What the kit runtime is handed: the theme and its strings (store-independent, module scope). */
2
+ import type { ThemeBundle } from '@tanqory/theme-kit/headless'
3
+ import theme from './theme'
4
+
5
+ export const bundle: ThemeBundle = {
6
+ theme,
7
+ templates: {},
8
+ groups: {},
9
+ // The build lays locales/*.json over the kit's own strings into generated/locales.
10
+ locales: import.meta.glob('./generated/locales/*.json', { eager: true }),
11
+ settings: {},
12
+ settingsSchema: {},
13
+ customSections: {},
14
+ manifest: null,
15
+ }