@eldrajs/theme-cli 0.2.1 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
5
5
  "keywords": [
6
6
  "cli",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {
43
43
  "citty": "^0.1.6",
44
44
  "tar": "^7.4.3",
45
- "@eldrajs/theme-core": "^0.3.0",
46
- "@eldrajs/vite-plugin-theme": "^0.3.0"
45
+ "@eldrajs/theme-core": "^0.3.1",
46
+ "@eldrajs/vite-plugin-theme": "^0.3.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "execa": "^9.5.2"
@@ -10,7 +10,7 @@
10
10
  "cta": "c77c1ad7ee168c9b9a21ba3829fbf7d49ce553eb44e55e24048054440ff1b9b9",
11
11
  "faq": "4f6545197383c27ffa047f127f66689a579f471a813abb8077ee02acdc5042c3",
12
12
  "feature-grid": "42a3e8c3ed8ba59c47808072e7bd75134f0dd5cd6601890aaefe4d9d680a758d",
13
- "footer": "18b3e8d7c29a044b2bac93ca16a72c78dbf7d9f744a036b6fbec3af3de70229e",
13
+ "footer": "b8abd478dea9527a12eb16df8bbc77c0138f72c3b9ccd187a42e35519aca8d2e",
14
14
  "form": "215c423696dc865cc11b65680dd4bea7d015fe934605843338aa6a90a49fc491",
15
15
  "gallery": "66757de8c7f8450ac115826353352010a31883260dae2f963cb17d186f64843b",
16
16
  "hero": "cd9f9ae50828278eedd8e8a71c5b2955ad4d1fc5d6d0373ab3ba6f30df1bc293",
@@ -5,7 +5,9 @@ on:
5
5
  repository_dispatch:
6
6
  types: [eldra.rebuild]
7
7
  jobs:
8
- deploy:
8
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it never gets
9
+ # the deploy token. Only the build token, which is read-only.
10
+ build:
9
11
  runs-on: ubuntu-latest
10
12
  steps:
11
13
  - uses: actions/checkout@v4
@@ -17,10 +19,35 @@ jobs:
17
19
  env:
18
20
  ELDRA_GATEWAY_URL: ${{ vars.ELDRA_GATEWAY_URL }}
19
21
  ELDRA_ORG_ID: ${{ vars.ELDRA_ORG_ID }}
22
+ # Read-only build token (Studio → Settings → Developers → Build tokens): gives the build's
23
+ # gateway reads their own rate-limit bucket.
24
+ ELDRA_BUILD_TOKEN: ${{ secrets.ELDRA_BUILD_TOKEN }}
20
25
  # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
21
26
  ELDRA_SITE_URL: ${{ vars.ELDRA_SITE_URL }}
22
- - run: pnpm exec eldra-theme deploy
27
+ - uses: actions/upload-artifact@v4
28
+ with:
29
+ name: eldra-build
30
+ path: .output/public
31
+ # The manifest lives in .output/public/.eldra, a hidden directory.
32
+ include-hidden-files: true
33
+ if-no-files-found: error
34
+ retention-days: 1
35
+ # The deploy job has the deploy token (it can publish the site) and runs none of the project's
36
+ # code: no checkout, no `pnpm install`, only the pinned CLI, installed with scripts disabled.
37
+ deploy:
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/setup-node@v4
42
+ with: { node-version: 20 }
43
+ - uses: actions/download-artifact@v4
44
+ with:
45
+ name: eldra-build
46
+ path: .output/public
47
+ # Keep this version in step with @eldrajs/theme-cli in package.json.
48
+ - run: npx --yes @eldrajs/theme-cli@0.2.1 deploy
23
49
  env:
50
+ npm_config_ignore_scripts: 'true'
24
51
  ELDRA_API_URL: ${{ vars.ELDRA_API_URL }}
25
52
  ELDRA_DEPLOY_TOKEN: ${{ secrets.ELDRA_DEPLOY_TOKEN }}
26
53
  ELDRA_TRIGGER_DEPLOYMENT_ID: ${{ github.event.client_payload.deploymentId }}
@@ -1,18 +1,45 @@
1
- stages: [deploy]
1
+ stages: [build, deploy]
2
2
 
3
- eldra-deploy:
4
- stage: deploy
3
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it must never
4
+ # receive the deploy token. Create these in Settings → CI/CD → Variables:
5
+ # ELDRA_BUILD_TOKEN masked. A read-only build token (Studio → Settings → Developers → Build
6
+ # tokens): gives the build's gateway reads their own rate-limit bucket.
7
+ # ELDRA_DEPLOY_TOKEN masked, protected, with the environment scope `production`. It can publish
8
+ # the site; scoped like this only the deploy job (environment: production, on
9
+ # a protected branch) receives it, never the build job.
10
+ # ELDRA_GATEWAY_URL, ELDRA_ORG_ID, ELDRA_SITE_URL (the public origin) and ELDRA_API_URL: plain
11
+ # variables.
12
+ # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
13
+ # The platform's trigger passes ELDRA_TRIGGER_DEPLOYMENT_ID as a pipeline variable.
14
+
15
+ .rules: &rules
16
+ - if: '$CI_PIPELINE_SOURCE == "trigger"'
17
+ - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
18
+
19
+ eldra-build:
20
+ stage: build
5
21
  image: node:20
6
- rules:
7
- - if: '$CI_PIPELINE_SOURCE == "trigger"'
8
- - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
22
+ rules: *rules
9
23
  before_script:
10
24
  - corepack enable && corepack prepare pnpm@9.15.0 --activate
11
25
  script:
12
26
  - pnpm install --frozen-lockfile
13
27
  - pnpm exec nuxi generate
14
- - pnpm exec eldra-theme deploy
28
+ artifacts:
29
+ # .output/public/.eldra/manifest.json is a hidden path; artifacts keep it.
30
+ paths:
31
+ - .output/public
32
+ expire_in: 1 hour
33
+
34
+ # Runs none of the project's code: no `pnpm install`, only the pinned CLI, installed with scripts
35
+ # disabled. Keep the version in step with @eldrajs/theme-cli in package.json.
36
+ eldra-deploy:
37
+ stage: deploy
38
+ image: node:20
39
+ needs: [eldra-build]
40
+ rules: *rules
41
+ environment: production
15
42
  variables:
16
- # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
17
- # ELDRA_SITE_URL (the public origin) is a CI/CD variable set on the project.
18
- ELDRA_TRIGGER_DEPLOYMENT_ID: $ELDRA_TRIGGER_DEPLOYMENT_ID
43
+ npm_config_ignore_scripts: 'true'
44
+ script:
45
+ - npx --yes @eldrajs/theme-cli@0.2.1 deploy
@@ -296,10 +296,10 @@ The deploy command uploads the generated static site and exact `.eldra/manifest.
296
296
 
297
297
  ## Wiring rebuilds
298
298
 
299
- The starter includes GitHub Actions, GitLab CI, and Bitbucket Pipelines examples. All build locally with Node 20 and pnpm, run `nuxi generate`, then push the static output with `eldra-theme deploy`.
299
+ The starter includes GitHub Actions, GitLab CI, and Bitbucket Pipelines examples. Each is split into a **build job** and a **deploy job**. The build job checks out the theme, installs with Node 20 and pnpm, runs `nuxi generate` (with `ELDRA_BUILD_TOKEN`, a read-only build token, so the build's gateway reads get their own rate-limit budget; it is sent only from the build in `X-Eldra-Build-Token`) and uploads `.output/public` as an artifact. The deploy job downloads the artifact and pushes it with `eldra-theme deploy` and `ELDRA_DEPLOY_TOKEN`, which can publish the site. The build job never receives the deploy token, because it runs every npm dependency's code. The deploy job installs none of the project's dependencies: it runs the pinned `@eldrajs/theme-cli` with install scripts disabled (keep its version in step with `package.json`).
300
300
 
301
- - GitHub: set repository variables `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` (the public origin, for canonical and `og:url`), plus secret `ELDRA_DEPLOY_TOKEN`. In Studio choose the GitHub trigger and configure `https://api.github.com/repos/<owner>/<repo>/dispatches` with a token allowed to dispatch workflows.
302
- - GitLab: configure those four names as project CI/CD variables, masking `ELDRA_DEPLOY_TOKEN`. In Studio use the project pipeline-trigger URL, trigger token, and branch/tag ref.
303
- - Bitbucket: configure repository variables, securing `ELDRA_DEPLOY_TOKEN`. In Studio use the pipelines endpoint, `username:app-password` token, and ref; the backend selects the `eldra-rebuild` custom pipeline.
301
+ - GitHub: set repository variables `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` (the public origin, for canonical and `og:url`), plus repository secrets `ELDRA_BUILD_TOKEN` (used by the `build` job only) and `ELDRA_DEPLOY_TOKEN` (used by the `deploy` job only). Create the build token in Studio under Settings → Developers → Build tokens. In Studio choose the GitHub trigger and configure `https://api.github.com/repos/<owner>/<repo>/dispatches` with a token allowed to dispatch workflows.
302
+ - GitLab: configure `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` as project CI/CD variables and `ELDRA_BUILD_TOKEN` as a masked variable. Create `ELDRA_DEPLOY_TOKEN` as a **masked, protected variable scoped to the `production` environment**; the deploy job declares `environment: production`, so the build job never receives it. In Studio use the project pipeline-trigger URL, trigger token, and branch/tag ref.
303
+ - Bitbucket: configure `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID` and `ELDRA_SITE_URL` as repository variables, securing `ELDRA_BUILD_TOKEN`. Define `ELDRA_DEPLOY_TOKEN` (secured) and `ELDRA_API_URL` as **deployment variables** of the Production environment, not repository variables; the deploy step declares `deployment: production`, so the build step never receives them. In Studio use the pipelines endpoint, `username:app-password` token, and ref; the backend selects the `eldra-rebuild` custom pipeline.
304
304
 
305
305
  Trigger tokens and app passwords are write-only in Studio. Rebuild requests supply `ELDRA_TRIGGER_DEPLOYMENT_ID`; the deploy command returns it as multipart `triggerDeploymentId`, completing the existing MANUAL or CONTENT_PUBLISH deployment rather than creating a duplicate.
@@ -43,6 +43,7 @@ export function useFormSpam(formKey: Ref<string>) {
43
43
  }
44
44
 
45
45
  return {
46
+ definition: definition.data,
46
47
  honeypot,
47
48
  honeypotField,
48
49
  siteKey,
@@ -187,6 +187,9 @@ export default defineNuxtPlugin({
187
187
  // @eldrajs/theme-nuxt's, and a rate limit that only one of them waits
188
188
  // out still fails the build.
189
189
  retry: publicConfig.eldra?.retry ?? undefined,
190
+ // The read-only build token (`ELDRA_BUILD_TOKEN`), from the build environment and only during a prerender (`undefined` in
191
+ // the browser): it gives the build its own rate-limit budget at the gateway.
192
+ buildToken: useEldraBuildToken(),
190
193
  });
191
194
 
192
195
  let source: StorefrontSource | null = null;
@@ -2,20 +2,40 @@ image: node:20
2
2
 
3
3
  definitions:
4
4
  steps:
5
- - step: &eldra-deploy
6
- name: Build and deploy to Eldra
5
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it must never
6
+ # receive the deploy token. Define these variables:
7
+ # ELDRA_BUILD_TOKEN, ELDRA_GATEWAY_URL, ELDRA_ORG_ID, ELDRA_SITE_URL (the public origin):
8
+ # repository variables. ELDRA_BUILD_TOKEN is secured (a read-only build token: Studio →
9
+ # Settings → Developers → Build tokens).
10
+ # ELDRA_DEPLOY_TOKEN and ELDRA_API_URL: deployment variables of the Production environment
11
+ # (Repository settings → Deployments), NOT repository variables. The deploy token can
12
+ # publish the site; as a deployment variable only the deploy step receives it.
13
+ # A build is production unless ELDRA_BUILD_TARGET=preview (noindex, `Disallow: /`).
14
+ - step: &eldra-build
15
+ name: Build the theme
7
16
  script:
8
17
  - corepack enable && corepack prepare pnpm@9.15.0 --activate
9
18
  - pnpm install --frozen-lockfile
10
- # A build is production unless ELDRA_BUILD_TARGET=preview (noindex, `Disallow: /`).
11
- # Set ELDRA_SITE_URL as a repository variable.
12
- - ELDRA_SITE_URL="$ELDRA_SITE_URL" pnpm exec nuxi generate
13
- - pnpm exec eldra-theme deploy
19
+ - pnpm exec nuxi generate
20
+ artifacts:
21
+ # The manifest is in .output/public/.eldra, a hidden directory: listed explicitly.
22
+ - .output/public/**
23
+ - .output/public/.eldra/**
24
+ # Runs none of the project's code: no `pnpm install`, only the pinned CLI, installed with
25
+ # scripts disabled. Keep the version in step with @eldrajs/theme-cli in package.json.
26
+ - step: &eldra-deploy
27
+ name: Deploy to Eldra
28
+ deployment: production
29
+ script:
30
+ - export npm_config_ignore_scripts=true
31
+ - npx --yes @eldrajs/theme-cli@0.2.1 deploy
14
32
 
15
33
  pipelines:
16
34
  branches:
17
35
  main:
36
+ - step: *eldra-build
18
37
  - step: *eldra-deploy
19
38
  custom:
20
39
  eldra-rebuild:
40
+ - step: *eldra-build
21
41
  - step: *eldra-deploy
@@ -316,6 +316,7 @@ const showNewsletter = computed(
316
316
  );
317
317
  // Only a footer that shows the sign-up reads the form's definition (its honeypot and Turnstile).
318
318
  const {
319
+ definition,
319
320
  honeypot,
320
321
  honeypotField,
321
322
  siteKey,
@@ -326,6 +327,11 @@ const {
326
327
  reset,
327
328
  } = useFormSpam(computed(() => (showNewsletter.value ? NEWSLETTER_FORM_KEY : '')));
328
329
  const consentSentenceId = `footer-consent-sentence-${useUiId()}`;
330
+ // The merchant's own label and placeholder on the form's email field; the theme's wording stands in until the
331
+ // definition has loaded.
332
+ const emailField = computed(() => definition.value?.fields.find((field) => field.type === 'email'));
333
+ const emailLabel = computed(() => emailField.value?.label || t('footer.emailLabel'));
334
+ const emailPlaceholder = computed(() => emailField.value?.placeholder || undefined);
329
335
 
330
336
  /** Mirrors `blocks/newsletter/Block.vue`'s own comment: an error has to clear itself the moment
331
337
  * its own condition is fixed (the visitor edits the address), not only inside a later successful
@@ -521,6 +527,7 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
521
527
  :heading-level="3"
522
528
  :aria-label="data.newsletterTitle ? undefined : t('footer.newsletterAriaLabel')"
523
529
  :submitting="newsletterState === 'submitting'"
530
+ :classes="{ actions: 'w-full mt-3' }"
524
531
  @submit="onNewsletterSubmit"
525
532
  @invalid="onNewsletterInvalid"
526
533
  >
@@ -532,23 +539,23 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
532
539
  </p>
533
540
  <div ref="emailFieldRoot" class="contents">
534
541
  <FieldWrapper
535
- :label="t('footer.emailLabel')"
542
+ :label="emailLabel"
536
543
  :error="emailError ?? undefined"
537
- :classes="{ label: 'sr-only' }"
544
+ :classes="{ root: 'block w-full' }"
538
545
  >
539
546
  <Input
540
547
  v-model="email"
541
548
  type="email"
542
549
  name="email"
543
550
  autocomplete="email"
544
- :placeholder="t('footer.emailLabel')"
551
+ :placeholder="emailPlaceholder"
545
552
  />
546
553
  </FieldWrapper>
547
554
  </div>
548
555
  <FormHoneypot v-model="honeypot" :name="honeypotField" />
549
556
  <div v-if="siteKey" ref="turnstileRoot" class="w-full" />
550
557
  <template #actions>
551
- <div class="grid w-full gap-2">
558
+ <div class="grid w-full grid-cols-[minmax(0,1fr)] gap-2">
552
559
  <Button
553
560
  type="submit"
554
561
  variant="primary"
@@ -1,4 +1,5 @@
1
1
  // @vitest-environment jsdom
2
+ import { computed } from 'vue';
2
3
  import { flushPromises, mount } from '@vue/test-utils';
3
4
  import { afterEach, describe, expect, it, vi } from 'vitest';
4
5
  import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
@@ -11,6 +12,7 @@ import { STOREFRONT_KEY } from '../../../app/storefront/types';
11
12
  import type {
12
13
  StorefrontCommerce,
13
14
  StorefrontFormSubmitResult,
15
+ StorefrontSource,
14
16
  StorefrontForms,
15
17
  } from '../../../app/storefront/types';
16
18
  import { createDemoStorefront } from '../../../app/storefront/demo';
@@ -79,6 +81,8 @@ function mountFooter(
79
81
  options: {
80
82
  failForms?: boolean;
81
83
  subscribe?: StorefrontForms['submit'];
84
+ /** A whole storefront, for a spec that needs a form definition the demo does not have. */
85
+ storefront?: StorefrontSource;
82
86
  /** Turn Cloudflare Turnstile on for the sign-up form (with `subscribe` as its submit). */
83
87
  turnstile?: boolean;
84
88
  /** Studio's edit mode — what `useEditing()` reads, and the only state that shows hints. */
@@ -113,14 +117,15 @@ function mountFooter(
113
117
  context.preview.mode = 'edit';
114
118
  }
115
119
  const storefront =
116
- options.subscribe && options.turnstile
120
+ options.storefront ??
121
+ (options.subscribe && options.turnstile
117
122
  ? storefrontWithTurnstile(options.subscribe)
118
123
  : options.subscribe
119
124
  ? (() => {
120
125
  const demo = createDemoStorefront();
121
126
  return { ...demo, forms: { ...demo.forms, submit: options.subscribe! } };
122
127
  })()
123
- : undefined;
128
+ : undefined);
124
129
  return mount(Block, {
125
130
  ...base,
126
131
  // Real focus tracking (`document.activeElement`, and `Select`'s own focus-return behaviour)
@@ -316,7 +321,67 @@ describe('footer block', () => {
316
321
  const label = wrapper.find(`label[for="${id}"]`);
317
322
  expect(label.exists()).toBe(true);
318
323
  expect(label.text()).toBe(enUS.footer.emailLabel);
319
- expect(label.classes()).toContain('sr-only');
324
+ expect(label.classes()).not.toContain('sr-only');
325
+ });
326
+
327
+ it("labels the email field with the form definition's own label", async () => {
328
+ const demo = createDemoStorefront();
329
+ const storefront = {
330
+ ...demo,
331
+ forms: {
332
+ ...demo.forms,
333
+ definition: (key: string) => {
334
+ const result = demo.forms.definition(key);
335
+ return {
336
+ ...result,
337
+ data: computed(() =>
338
+ result.data.value === null
339
+ ? null
340
+ : {
341
+ ...result.data.value,
342
+ fields: result.data.value.fields.map((field) =>
343
+ field.type === 'email' ? { ...field, label: 'Where should we write?' } : field
344
+ ),
345
+ }
346
+ ) as typeof result.data,
347
+ };
348
+ },
349
+ },
350
+ };
351
+ const wrapper = mountFooter(mock, { storefront });
352
+ await flushPromises();
353
+ const input = wrapper.get('input[type="email"]');
354
+ expect(wrapper.get(`label[for="${input.attributes('id')}"]`).text()).toBe(
355
+ 'Where should we write?'
356
+ );
357
+ });
358
+
359
+ it("shows the placeholder the form's email field carries, not its label", async () => {
360
+ const wrapper = mountFooter(mock);
361
+ await flushPromises();
362
+ expect(wrapper.get('input[type="email"]').attributes('placeholder')).toBe('name@example.com');
363
+ });
364
+
365
+ it('keeps the email error in the field cell, directly under the input', async () => {
366
+ const wrapper = mountFooter(mock);
367
+ await flushPromises();
368
+ // The field wrapper is `display: contents` by default, which turns its error into a flex item of
369
+ // its own that lands after the button row; a real block keeps the two together.
370
+ const cell = wrapper.get('input[type="email"]').element.closest('.content-start');
371
+ expect(cell?.parentElement?.classList.contains('block')).toBe(true);
372
+ });
373
+
374
+ it('keeps the sign-up button and its consent sentence in one column as wide as the form', async () => {
375
+ const wrapper = mountFooter(mock);
376
+ await flushPromises();
377
+ // The library's actions row is `shrink-0` and the grid's auto column follows the sentence's
378
+ // max-content, so both pushed the button past the footer column; happy-dom has no layout,
379
+ // so this guards the two classes that prevent it.
380
+ const actions = wrapper.get('[data-part="consent-sentence"]').element.parentElement;
381
+ expect(actions?.classList.contains('grid-cols-[minmax(0,1fr)]')).toBe(true);
382
+ expect(actions?.parentElement?.classList.contains('w-full')).toBe(true);
383
+ // The form's own 0.25rem row gap leaves the button touching the field; the row adds the rest.
384
+ expect(actions?.parentElement?.classList.contains('mt-3')).toBe(true);
320
385
  });
321
386
 
322
387
  it('shows the platform consent sentence under the sign-up button, tied to it with aria-describedby', async () => {
Binary file