Skip to content

CMS Integration - #14

Merged
tlgimenes merged 8 commits into
masterfrom
feature/cms
Jun 24, 2020
Merged

tlgimenes merged 8 commits into
masterfrom
feature/cms

Conversation

@tlgimenes

Copy link
Copy Markdown
Contributor

This PR creates a transformer from CMS's json into .tsx files.

@tlgimenes
tlgimenes merged commit cdf6585 into master Jun 24, 2020
@tlgimenes
tlgimenes deleted the feature/cms branch June 24, 2020 01:36
gvc pushed a commit that referenced this pull request Feb 7, 2023
* Feat: Input Text Theming (#15)

* Adds `InputText` to Storybook

* Adds `HasError` option to Storybook

* Fixes `HasError` focus state

* Updates Small Button size

* Adds new tokens to `Input Text`

* Adds Disabled args

* Fixes Atoms section

* Updates Changelog

* Removes unused `data-fs-input-text-button` data-attribute

* Updates ButtonIcon size

* Adds link to Changelog

Co-authored-by: Lucas Feijó <[email protected]>

* Tweaks tokens

* Update `InputText` local tokens to ease readability

* Changes Interactive to Actionable

* Unifies `Button small` font-size

* Adds arg types especifications

* Specifies `disabled` prop for the entire component

* Removes actions from `InputText` when disabled

Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Lucas Feijó <[email protected]>

* Updates Changelog

Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
lemagnetic added a commit that referenced this pull request Jul 1, 2026
## What's the purpose of this pull request?

Store developers on Content Platform (CP) had to run `vtex content
generate-schema` and `upload-schema` manually, easy to get wrong and a
recurring source of support tickets. This PR extends `cms-sync` to
detect `contentSource.type` in `discovery.config.js` and run the right
flow in one command: legacy Headless CMS unchanged, CP with generate +
upload built in.

When `experimental.enableFaststoreMyAccount` is on, CP mode also merges
the core My Account CMS schemas (kept out of the published base / Schema
Registry) into the same generated schema so merchants don't have to copy
JSONC by hand.

**Jira:**
[SFS-3243](https://vtex-dev.atlassian.net/jira/software/c/projects/SFS/boards/1051?selectedIssue=SFS-3243)

## How it works?

**Content-source detection**

- Reads the store's own `discovery.config.js` at `basePath` (not
`.faststore` tmp).
- `contentSource.type` absent or `CMS` → legacy flow unchanged
(`generate` + `mergeCMSFiles` + `vtex cms sync`).
- `CP` → CP flow: pre-flight, then `generate-schema` (no `-l`) and
`upload-schema`.
- Unknown `type` → fail fast with a clear error.
- Logs detected mode at startup (`CMS` vs `CP`).

**CP flow**

- **Pre-flight first** (`utils/vtex.ts`, `assertVtexReadyForAccount`):
checks `vtex --version` (installed) and `vtex whoami` (logged in,
account matches `api.storeId` case-insensitively). Fails fast with an
install / `vtex login <account>` / `vtex switch <account>` hint — avoids
the toolbelt stalling on a login prompt.
- Uses existing `cms/faststore/components` and/or `pages` when present;
fails if neither exists (before any toolbelt call).
- All directory and `-o` paths are passed **relative to the store root**
— the toolbelt resolves them against the cwd, so absolute paths would be
doubled into `<store>/<store>/…` and fail with `ENOENT`.
- `generate-schema`/`upload-schema` run **synchronously, in order, and
interactively** (`runCommandSync` with `stdio: 'inherit'`):
`generate-schema` has no `--yes` and prompts to confirm overriding a
base definition; `upload-schema` prompts for the version to publish.
`--dry-run` stops after generation.

**My Account merge (opt-in)**

- When `experimental.enableFaststoreMyAccount === true` in CP mode:
- **File-level merge** of the core My Account JSONC
(`coreCMSDir/my-account/{components,pages}`) with the store's own
`cms/faststore/{components,pages}` into a staging dir with exactly two
subdirs (`components`, `pages`), created under the store's
**`.faststore`** folder. Core is copied first, the store's files on top
→ store wins on name collision.
- These two merged dirs **replace** the store dirs as the two positional
args to a single `generate-schema` (`generate-schema` accepts only two
positional dirs, so the merge has to be at the file level).
  - Announces the merge in the log.
  - Removes the staging dir in `finally` (success, dry-run, or failure).
  - Proceeds even if the store has no own `components`/`pages`.
  - Fails fast if core My Account schemas are missing.

**Package scope:** `@faststore/cli` (`cms-sync.ts`,
`utils/cp-schema.ts`, `utils/config.ts`, new `utils/vtex.ts`,
`utils/runCommandSync.ts` interactive flag) + docs in
`packages/core/README.md` and `packages/cli/AGENTS.md`.

```mermaid
flowchart TD
    A([faststore cms-sync PATH --dry-run]) --> B["basePath = getBasePath(PATH ?? cwd)"]
    B --> E["storeConfig = discovery.config.js em basePath (ou null)"]
    E --> F["resolveContentSource(storeConfig?.contentSource?.type)"]

    F --> G{"type (uppercase)"}
    G -- "undefined / 'CMS'" --> H["source = CMS"]
    G -- "'CP'" --> I["source = CP"]
    G -- "outro (ex: 'WORDPRESS')" --> X1["logger.error<br/>Unsupported contentSource.type"]:::err
    X1 --> X2([process.exit 1]):::exit

    H --> LOG["logger.info — Detected contentSource ... + ação"]
    I --> LOG
    LOG --> SW{"switch(source)"}

    %% ===== Legacy CMS =====
    SW -- CMS --> L1["runLegacySync"]
    L1 --> L3["generate({ setup }) + mergeCMSFiles(basePath)"]
    L3 --> L5{"--dry-run?"}
    L5 -- sim --> L6([return — sem sync]):::ok
    L5 -- não --> L7["spawn('vtex cms sync <project>',<br/>cwd = .faststore tmpDir)"]
    L7 --> L8([fim]):::ok

    %% ===== CP =====
    SW -- CP --> PF["assertVtexReadyForAccount(api.storeId)<br/>vtex --version + vtex whoami"]
    PF -- "ausente / deslogado / conta errada" --> XPF["logger.error<br/>install / vtex login / vtex switch"]:::err
    XPF --> XPF2([process.exit 1]):::exit
    PF -- ok --> P3{"isMyAccountEnabled?"}

    P3 -- sim --> M1["logger.info — Merging My Account ..."]
    M1 --> M3{"coreCMSDir/my-account<br/>existe?"}
    M3 -- não --> X3["logger.error — core My Account não encontrado"]:::err
    X3 --> X4([process.exit 1]):::exit
    M3 -- sim --> M4["prepareMyAccountMergeDir:<br/>mkdtemp em .faststore;<br/>cpSync core + loja (loja vence)"]
    M4 --> M5["dirs = [merge/components, merge/pages]<br/>(relativos; substituem dirs da loja)"]
    M5 --> P4

    P3 -- não --> PD["dirs = getExistingCpDirs(basePath)<br/>(subset relativo de components/pages)"]
    PD --> P4{"dirs.length === 0?"}
    P4 -- sim --> X5["errorNoCustomization()"]:::err
    X5 --> X6([process.exit 1]):::exit
    P4 -- não --> P5["schemaOut = cms/faststore/schema.json (relativo)"]

    P5 --> T1["try: generateAndUploadSchema"]
    T1 --> G1["runCommandSync (interactive)<br/>vtex content generate-schema &lt;dirs&gt; -o schemaOut<br/>(sem -l, cwd = basePath)<br/>prompt: confirmar override do base"]
    G1 --> G2{"--dry-run?"}
    G2 -- sim --> G3["return (sem upload)"]
    G2 -- não --> G4["runCommandSync (interactive)<br/>vtex content upload-schema schemaOut<br/>prompt: versão a publicar"]
    G3 --> FIN["finally"]
    G4 --> FIN
    T1 -. erro do toolbelt .-> FIN
    FIN --> FZ{"merge criado?"}
    FZ -- sim --> FC["cleanupMyAccountMergeDir(mergeDir)<br/>rmSync recursive/force"]
    FZ -- não --> FE([fim]):::ok
    FC --> FE

    classDef err fill:#5c1a1a,stroke:#ff6b6b,color:#fff;
    classDef exit fill:#3a0d0d,stroke:#ff6b6b,color:#fff;
    classDef ok fill:#10391f,stroke:#3ddc84,color:#fff;

```

## How to test it?

**Legacy CMS (regression)**

1. Store with `contentSource: { type: 'CMS' }` (or no `contentSource`).
2. Run `pnpm faststore cms-sync` — expect merge + `vtex cms sync` as
before.
3. Run with `--dry-run` — expect no `vtex cms sync`.

**CP — customizations only**

1. Set `contentSource: { type: 'CP' }` in `discovery.config.js`.
2. Add schemas under `cms/faststore/components/` and/or `pages/`.
3. Run `pnpm faststore cms-sync` — expect `generate-schema` (no `-l`)
then `upload-schema`.
4. Run with `--dry-run` — schema generated, no upload.
5. Remove both dirs — expect exit 1 with "No CMS customization found".

**CP pre-flight**

1. With the `vtex` toolbelt not installed → exit 1 with an install hint.
2. Logged out → exit 1 with `vtex login <account>`.
3. Logged into a different account than `api.storeId` → exit 1 with
`vtex switch <account>`.
4. Logged into the matching account → flow proceeds.

**CP + My Account**

1. Set `contentSource: { type: 'CP' }` and `experimental: {
enableFaststoreMyAccount: true }`.
2. Run `pnpm faststore cms-sync` — log mentions the My Account merge;
the generated schema includes the store's components/content-types
**and** the My Account ones.
3. Repeat with no store `components`/`pages` — should still generate
from the core My Account schemas.
4. Repeat with `--dry-run` — generate only; staging dir under
`.faststore` cleaned up.
5. With flag off — My Account must not be included (same as CP-only
case).

**End-to-end validation (`brandless` store)**

Validated against a real CP store:

- `yarn cms-sync --dry-run` → generates `cms/faststore/schema.json`
containing the store's `Banner example` component, the `landingPage`
content-type, and the 14 core My Account components + 6 content-types
(confirmed answering the `landingPage` base-override prompt).
- `yarn cms-sync` → answered the override prompt, picked the version
(`4.22.0`), confirmed the upload → `Schema uploaded successfully with ID
[email protected]`.

**Automated**

```sh
cd packages/cli && pnpm test   # matrix #1–#14 + pre-flight #15–#18
pnpm lint
```

## References

-
[SFS-3243](https://vtex-dev.atlassian.net/jira/software/c/projects/SFS/boards/1051?selectedIssue=SFS-3243)
- Spec: `specs/005-cms-sync-content-source/`


[SFS-3243]:
https://vtex-dev.atlassian.net/browse/SFS-3243?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[SFS-3243]:
https://vtex-dev.atlassian.net/browse/SFS-3243?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant