This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an Adobe I/O CLI plugin (aio-cli-plugin-aem-edge-functions) that enables developers to build, deploy, and manage AEM Edge Functions — JavaScript that runs at the CDN layer via Fastly Compute.
Commands are invoked as: aio aem edge-functions <command>
npm test # Full test suite with coverage
npx mocha test/libs/fastly-cli.test.js # Run a single test file
npx mocha test/libs/fastly-cli.test.js --grep "pattern" # Run specific test(s)
npm run lint # Lint + auto-fix current directory
npm run lint-all # Lint + auto-fix entire project
npm run format # Prettier format all filesRequirements: Node.js 18.x (≥18.0.0), 20.x (≥20.11.0), or 22.x (≥22.15.0).
Uses oclif (@oclif/core v2) for command auto-discovery from src/commands/. The directory path maps directly to the CLI invocation — files in src/commands/aem/edge-functions/ become aio aem edge-functions <name>.
src/commands/aem/edge-functions/— 6 commands:setup,build,deploy,serve,tail-logs,infosrc/libs/base-command.js—BaseCommandextends oclif'sCommand; all commands extend thissrc/libs/fastly-cli.js— wraps@fastly/cliviaexecFileSync; handlesFASTLY_API_TOKEN/FASTLY_API_ENDPOINTenv varssrc/libs/cloudmanager.js— Cloud Manager API clientsrc/libs/developer-console.js— Adobe Developer Console API clientsrc/libs/request.js— Generic HTTP request wrapper
BaseCommand is the core of the plugin. It handles:
- Configuration layering: env vars (
AEM_EDGE_FUNCTIONS_*) > ADC config > aio config file (.aio) - Auth: IMS token (primary) and ADC OAuth Server-to-Server credentials (fallback path via
@adobe/aio-lib-ims) - Shared helpers: spinner management (
ora-classic), Fastly CLI initialization, API base path computation
Core config keys used throughout (stored in aio config under aem.edge-functions.*):
cloudmanager_orgid,cloudmanager_programid,cloudmanager_environmentidedgefunctions_edge_delivery,edgefunctions_site_domainedgefunctions_adc_client_id,edgefunctions_adc_client_secret,edgefunctions_adc_scopes
All have corresponding AEM_EDGE_FUNCTIONS_* environment variable overrides.
FastlyCli in src/libs/fastly-cli.js wraps the @fastly/cli npm package. It calls the Fastly binary via execFileSync and exposes build(), deploy(), serve(), and logTail(). Most commands (build, deploy, serve, tail-logs) are thin wrappers that delegate directly to this class.
- Framework: Mocha + NYC (coverage) + Sinon (mocking)
- Test files live in
test/libs/(onlyfastly-cli.test.jsanddeveloper-console.test.jsexist currently — no command-level tests yet) - Coverage excludes
src/index.jsand test files themselves - HTML coverage report generated to
coverage/
- Create
src/commands/aem/edge-functions/<name>.jsextendingBaseCommand - Define static
description,flags, andargsfollowing oclif patterns - Implement
async run()usingthis.flags,this.args,this.getConfig() - Export the class; oclif auto-discovers it