How adobe/aio-cli-plugin-app-storage works
Project type and purpose
• This is an open-source Node.js CLI plugin (“aio-cli-plugin-app-storage”) built on the oclif framework.
• Its purpose is to add “app state” commands to the Adobe I/O CLI, allowing users to list, get, put, delete, and view stats on key-value state storage.
Main architectural components
a. CLI entrypoint (bin/)
• bin/run.js & bin/dev.js: small wrappers that invoke oclif’s command dispatch.
• They bootstrap the plugin when a user types aio app state ….
b. CLI framework core (external)
• oclif (the Adobe CLI core) loads the plugin, parses arguments, locates the appropriate command class.
c. Command classes (src/commands/app/state/*.js)
• One class per operation: delete.js, get.js, list.js, put.js, stats.js.
• Each extends BaseCommand.js (handles common flags like --json, --region) and implements run() to call the state library.
d. State library (external dependency)
• @adobe/aio-lib-state: encapsulates HTTP/API calls to the Adobe State service. Commands delegate to it for all storage operations.
e. Configuration & constants (src/constants.js)
• Stores default region, TTL defaults, JSON‐output logic.
f. Testing & CI
• Unit tests (test/) verify each command’s behavior via Jest.
• End-to-end script (e2e/e2e.js) exercises the CLI binary against a live or mock service.
• GitHub workflows (.github/workflows/) automate linting, testing, publishing to NPM.
Relationships and data flow
1. User invokes CLI: aio app state <command> [args]
2. bin/run.js → oclif CLI core → plugin loader
3. oclif maps to the appropriate Command class in src/commands
4. Command.run():
• Parses flags & args (via BaseCommand).
• Calls a helper in @adobe/aio-lib-state (passing key, value, region, ttl).
5. aio-lib-state makes HTTP requests to Adobe’s state service API
6. API responds → library returns a JavaScript object
7. Command formats output (plain text or JSON) → writes to stdout
8. e2e or unit tests assert on exit code and stdout content
9. GitHub Actions ensure each step passes on push or PR, then auto-publish on release.
Architectural patterns & design principles
• Command pattern: each CLI command is an isolated class.
• Dependency inversion: commands depend on an abstraction (@adobe/aio-lib-state) instead of HTTP details.
• Single responsibility: BaseCommand handles common flags; each subclass handles only one operation.
• Modular plugins: the Adobe CLI core loads this plugin at runtime—easy to add/remove functionality.
Detailed callouts
• Flags parsing in BaseCommand (common across commands).
• Default region resolution (env var vs. amer).
• How TTL flag is passed into aio-lib-state for put command.
• Tests mocking the state library vs. e2e hitting the real service.