$npx -y skills add forcedotcom/sf-skills --skill commerce-b2b-open-code-components-integrateIntegrate Salesforce B2B Commerce open source components from GitHub into B2B Commerce stores. Use when users mention \"integrate open code components\", \"open source B2B commerce\", \"add open code components\", \"forcedotcom/b2b-commerce-open-source-components\", or want to ad
| 1 | ## When to Use This Skill |
| 2 | |
| 3 | Use this skill when you need to: |
| 4 | - Integrate all open source B2B Commerce components into a store |
| 5 | - Add open source components to a new or existing B2B Commerce store |
| 6 | - Make open code components available in Experience Builder |
| 7 | |
| 8 | ## Rules |
| 9 | |
| 10 | 1. **Always explain before executing.** Before running any command, you MUST tell the user what the command does and why you are running it. Never just show a raw command and ask for permission. The user should be able to read your explanation and understand the purpose before approving. |
| 11 | |
| 12 | ## Overview |
| 13 | |
| 14 | This skill copies all open source B2B Commerce components from the official Salesforce repository (https://github.com/forcedotcom/b2b-commerce-open-source-components) into a B2B Commerce store's site metadata. After integration, the components appear in the Experience Builder component palette. |
| 15 | |
| 16 | --- |
| 17 | |
| 18 | ## Startup Flow |
| 19 | |
| 20 | When this skill is triggered, perform these checks automatically before copying. |
| 21 | |
| 22 | ### Check 0: Resolve Package Directory |
| 23 | |
| 24 | Read `sfdx-project.json` and pick the active package directory. Extract `packageDirectories[]` and use the entry with `"default": true`; if no entry is flagged default, use the first entry. Use this value as `<package-dir>` everywhere below. If `sfdx-project.json` is missing or has no `packageDirectories`, tell the user and abort. |
| 25 | |
| 26 | ### Check 1: Open Source Repository |
| 27 | |
| 28 | Verify the repo is cloned at `.tmp/b2b-commerce-open-source-components`: |
| 29 | |
| 30 | 1. **If directory does not exist:** Tell user: "I'm cloning the official B2B Commerce open source components repository from GitHub into a local `.tmp/` folder. This gives us access to all the open code components." |
| 31 | Then run: `git clone https://github.com/forcedotcom/b2b-commerce-open-source-components .tmp/b2b-commerce-open-source-components` |
| 32 | 2. **If directory exists** and contains `force-app/main/default/sfdc_cms__lwc` and `sfdc_cms__label`, present options: |
| 33 | > "Open source repository is already cloned. How would you like to proceed?" |
| 34 | > 1. **Reuse existing** — Use the already cloned repository |
| 35 | > 2. **Re-clone** — Remove and clone fresh from GitHub |
| 36 | 3. **If directory exists but structure is invalid:** Tell user: "The cloned repository has an unexpected structure. I'll remove it and clone a fresh copy." |
| 37 | Then remove and re-clone. |
| 38 | 4. **If clone fails:** inform user and abort |
| 39 | |
| 40 | ### Check 2: Store and Site Metadata |
| 41 | |
| 42 | Verify a store is selected and site metadata is available locally: |
| 43 | |
| 44 | 1. Tell user: "I'm checking if your project already has B2B store metadata locally." |
| 45 | Check if `<package-dir>/main/default/digitalExperiences/site/` contains any store directories. |
| 46 | 2. **If store metadata exists:** use it. If multiple stores found, ask user to select one. |
| 47 | 3. **If no store metadata found:** Try retrieving from the connected org before delegating: |
| 48 | 1. Run `sf org list` (or check `sf config get target-org`) to find a connected org. Ask the user to confirm or pick one if more than one. |
| 49 | 2. List `DigitalExperienceBundle` site bundles in that org with `sf org list metadata --metadata-type DigitalExperienceBundle --target-org <alias>`. Filter to `site/*` entries. |
| 50 | 3. If at least one site bundle exists, ask the user which to use, then run: |
| 51 | `sf project retrieve start --metadata "DigitalExperienceBundle:site/<storeName>" --target-org <alias>` |
| 52 | The bundle lands at `<package-dir>/main/default/digitalExperiences/site/<storeName>/`. |
| 53 | 4. **Only if no connected org is available, or no site bundles are found, or retrieve fails:** delegate to the **commerce-b2b-store-create** skill. |
| 54 | |
| 55 | **Required state** after all checks: |
| 56 | - **Package dir** — the value resolved in Check 0 (e.g., `force-app`) |
| 57 | - **Store name** — the selected `fullName` value (e.g., `My_B2B_Store1`) |
| 58 | - **Site metadata path** — `<package-dir>/main/default/digitalExperiences/site/<store-name>/` |
| 59 | - **Repo path** — `.tmp/b2b-commerce-open-source-components/` |
| 60 | |
| 61 | --- |
| 62 | |
| 63 | ## Integration Task |
| 64 | |
| 65 | Copy all components and labels from cloned repo to site directory: |
| 66 | |
| 67 | - **Source:** `.tmp/b2b-commerce-open-source-components/force-app/main/default/sfdc_cms__lwc/*` and `sfdc_cms__label/*` (the open source repo's own layout — always `force-app`) |
| 68 | - **Destination:** `<package-dir>/main/default/digitalExperiences/site/<store-name>/sfdc_cms__lwc/` and `sfdc_cms__label/` (`<package-dir>` resolved in Check 0) |
| 69 | |
| 70 | **Steps:** |
| 71 | |
| 72 | 1. Tell user: "I'm checking if open code components already exist in your sto |