# Alpha CLI > A comprehensive command-line interface for building, managing, and publishing plugin-based applications in the Alpha ecosystem. [![Version](https://img.shields.io/badge/version-1.0.19-blue.svg)](https://www.npmjs.com/package/@jatahworx/alpha-cli) [![License](https://img.shields.io/badge/license-ISC-green.svg)](LICENSE) Alpha CLI streamlines the development workflow for creating modular, reusable components and modules that integrate seamlessly into the Alpha platform. Built on modern web standards (Lit, TypeScript, Vite), it provides scaffolding, live development, building, and publishing capabilities. --- ## Table of Contents - [Overview](#overview) - [Features](#features) - [Installation](#installation) - [Quick Start](#quick-start) - [Core Concepts](#core-concepts) - [Workspaces](#workspaces) - [Components vs Modules](#components-vs-modules) - [Attribute System](#attribute-system) - [Commands](#commands) - [new](#new-name) - [generate](#generate--g) - [build](#build-type-pluginname) - [start](#start-options) - [serve](#serve) - [auth](#auth-command) - [publish](#publish-packagename-options) - [deprecate](#deprecate-packagename-options) - [Architecture](#architecture) - [Configuration](#configuration) - [Development Workflow](#development-workflow) - [Best Practices](#best-practices) - [Docker & Kubernetes Deployment](#docker--kubernetes-deployment) - [Troubleshooting](#troubleshooting) - [API Reference](#api-reference) - [Contributing](#contributing) --- ## Overview Alpha CLI is a professional development tool for creating plugin-based applications. It supports two fundamental plugin types: | Plugin Type | Purpose | Access Pattern | Use Cases | |---------------|------------------------------------------|-------------------------|----------------------------------------| | **Components** | UI elements with drag-and-drop capability | Canvas placement | Buttons, forms, data grids, charts | | **Modules** | Globally accessible utilities | `alpha.plugins` or `ap` | API clients, helpers, services, utilities | ### Key Capabilities - **Project Scaffolding**: Complete workspace setup with TypeScript, Docker, and Kubernetes support - **Code Generation**: Handlebars-based templates with automatic formatting - **Live Development**: Vite-powered dev server with hot reload - **Build System**: Production-optimized builds with minification - **Authentication**: OpenID Connect integration for secure publishing - **Publishing**: One-command deployment to Alpha marketplace - **Version Management**: Semantic versioning with automatic package.json updates --- ## Features ### Development Features - ✅ TypeScript-first with full type safety - ✅ Lit-based web components (standards-compliant) - ✅ Hot module reload for rapid iteration - ✅ Automatic code formatting with Prettier - ✅ Interactive CLI prompts for streamlined workflows - ✅ Component testing interface auto-generated ### Build Features - ✅ Vite bundling with ES modules - ✅ TypeScript compilation - ✅ Production minification - ✅ Docker containerization - ✅ Kubernetes Helm charts ### Publishing Features - ✅ OpenID Connect authentication - ✅ Automatic version bumping (patch/minor/major) - ✅ Asset management (icons, screenshots) - ✅ Metadata tracking (packageId, versionId) - ✅ Package deprecation support --- ## Installation ### Prerequisites - Node.js 20+ (recommended: 22.x) - npm 9+ - Git - Docker (optional, for containerization) ### Global Installation ```sh npm install -g @jatahworx/alpha-cli ``` ### Verify Installation ```sh alpha --version # Output: 1.0.0 ``` ### Post-Installation Alpha CLI automatically creates configuration files on first install: ``` ~/.alphaconfigs/ ├── auth.json # Authentication tokens └── preferences.json # User preferences ``` --- ## Quick Start ### 1. Create a New Workspace ```sh alpha new my-app cd my-app ``` **What gets created:** ``` my-app/ ├── .configs/ # Workspace configuration │ ├── auth.json # Auth config (placeholders) │ └── preferences.json # User preferences ├── .vscode/ # VSCode settings ├── helmchart/ # Kubernetes deployment ├── packages/ # Plugin directory (empty initially) ├── Dockerfile # Container definition ├── index.html # Entry HTML with test interface ├── index.ts # Application entry point ├── public-api.ts # Public exports ├── tsconfig.json # TypeScript config ├── plugin.json # Workspace metadata ├── package.json # npm workspace configuration └── ATTRIBUTE.md # Attribute documentation ``` ### 2. Generate Your First Component ```sh alpha generate component counter --description "A simple counter" # Alias: alpha g c counter ``` **Generated structure:** ``` packages/counter/ ├── package.json ├── counter.component.ts # Main component class ├── counter.spec.ts # Test file ├── counter.styles.ts # Lit CSS styles └── assets/ ├── icon/ │ └── default-icon.png └── images/ ``` **Generated component code:** ```typescript @AlphaComponent({ componentName: 'counter', componentVersion: '1.0.0', label: 'Counter', selector: 'comp-counter', category: 'Input', icon: 'sample.png' }) export class Counter extends LitElement { @AlphaAttribute({ type: ATTRIBUTE_TYPE.PROPERTY, uiType: UI_TYPE.INPUT, label: 'Initial Count', defaultValue: 0, placeholder: 'Enter label', fieldMappings: 'value' }) @property({ type: Number }) value = 0; // Event handlers with decorators... @AlphaAttribute({ type: ATTRIBUTE_TYPE.EVENT, label: 'On Increment', event: 'onIncrement' }) increment(event) { this.value++; this.dispatchEvent(new CustomEvent('onIncrement', { detail: { event, element: this, value: this.value }, bubbles: true, composed: true })); } } ``` ### 3. Start Development Server ```sh alpha start # Server running at http://localhost:6969 ``` The dev server provides: - **Hot reload**: Changes reflect instantly - **Testing interface**: Auto-generated UI to test components - **Component registry**: All components available in `globalThis.aci` ### 4. Build for Production ```sh alpha build plugins # or build specific plugin: alpha build plugins counter ``` ### 5. Publish to Marketplace ```sh # Authenticate first alpha auth login # Publish with version bump alpha publish counter --version-type patch ``` --- ## Core Concepts ### Workspaces Alpha projects are **npm workspaces** containing multiple plugins. Every workspace has: #### `plugin.json` (Required) ```json { "name": "my-app", "componentSelectorPrefix": "comp", "moduleSelectorPrefix": "mod" } ``` - **name**: Workspace identifier - **componentSelectorPrefix**: Prefix for component selectors (e.g., `comp-button`) - **moduleSelectorPrefix**: Prefix for module IDs (e.g., `mod-api-client`) #### Workspace Validation Most commands require a valid workspace with both `plugin.json` and `package.json`. Exceptions: - `alpha new` (creates workspace) - `alpha auth login` (global authentication) --- ### Components vs Modules #### Components: UI Building Blocks **Characteristics:** - Extend `LitElement` from Lit framework - Draggable onto canvas in Alpha builder - Configurable via **attribute system** (properties, events, validations) - Have visual representation (render method) - Support lifecycle hooks - Can dispatch custom events **Selector Pattern:** ```typescript selector: '{prefix}-{kebab-case-name}' // Example: 'comp-user-profile' ``` **Component Example:** ```typescript @AlphaComponent({ selector: 'comp-user-card', label: 'User Card', category: 'Display' }) export class UserCard extends LitElement { @property({ type: Object }) user = null; render() { return html`

${this.user?.name}

${this.user?.email}

`; } } ``` #### Modules: Global Utilities **Characteristics:** - Plain JavaScript/TypeScript classes - No UI rendering - Globally accessible via `alpha.plugins` or `ap` namespace - Service classes, API clients, helpers - Lifecycle hooks: `init()` and `onRegister()` **Module Example:** ```javascript class ApiClient { init() { console.log('ApiClient initialized'); } onRegister() { console.log('ApiClient registered'); } async fetchData(url) { return fetch(url).then(r => r.json()); } } alpha.registerPlugins('mod-api-client', new ApiClient()); ``` **Access pattern:** ```javascript // In your application: const data = await alpha['mod-api-client'].fetchData('/api/users'); // or const data = await ap['mod-api-client'].fetchData('/api/users'); ``` --- ### Attribute System Attributes define the **configurable interface** for components. They use TypeScript decorators to annotate properties and methods. #### Three Attribute Types | Type | Purpose | Decorator Target | Example Use Case | |------|---------|------------------|------------------| | **PROPERTY** | Data input configuration | Class properties | Text inputs, toggles, dropdowns | | **EVENT** | User interaction handlers | Methods | Click handlers, form submissions | | **VALIDATION** | Input validation rules | Properties | Required fields, pattern matching | #### Supported UI Types | UI Type | Description | Options Format | Use Case | |---------|-------------|----------------|----------| | `input` | Text input field | `{ maxLength: number }` | Simple text values | | `toggle` | Boolean switch | None | On/off states | | `dropdown` | Single selection | `Array<{ displayText, value }>` | Predefined choices | | `multi-select` | Multiple selection | `Array<{ displayText, value }>` | Multiple choices | | `typed-input` | Data binding input | `Array<{ name, value }>` | Variable binding | | `range` | Numeric slider | `{ minLabel, maxLabel, minRange, maxRange }` | Numeric ranges | | `color-picker` | Color selector | None | Color values | | `data-source` | Data source binding | Field mappings | API endpoints | | `data-set` | Data collection | Field mappings | Arrays/lists | | `table-actions` | Table action buttons | Actions array | CRUD operations | | `data-mapping` | Field mapping interface | Complex mappings | Data transformation | #### Field Mappings Field mappings connect attribute values to component properties: **Simple mapping (string path):** ```typescript @AlphaAttribute({ uiType: UI_TYPE.INPUT, fieldMappings: 'userName' // Maps directly to this.userName }) userName = ''; ``` **Complex mapping (object with paths):** ```typescript @AlphaAttribute({ uiType: UI_TYPE.TYPED_INPUT, fieldMappings: { type: 'options.mappingType', // Nested path value: 'options.modelPath' // Nested path } }) options = { mappingType: '', modelPath: '' }; ``` **Data source mapping:** ```typescript @AlphaAttribute({ uiType: UI_TYPE.DATA_SOURCE, fieldMappings: { response: 'dataSource.response', label: 'dataSource.labelField', value: 'dataSource.valueField' } }) dataSource = { response: [], labelField: '', valueField: '' }; ``` #### Complete Attribute Example ```typescript @AlphaAttribute({ type: ATTRIBUTE_TYPE.PROPERTY, // Attribute type uiType: UI_TYPE.DROPDOWN, // UI control label: 'Select Theme', // Display label category: 'Appearance', // Grouping category placeholder: 'Choose a theme', // Placeholder text defaultValue: 'light', // Default selection options: [ // Dropdown options { displayText: 'Light Mode', value: 'light' }, { displayText: 'Dark Mode', value: 'dark' }, { displayText: 'Auto', value: 'auto' } ], fieldMappings: 'theme' // Maps to this.theme }) @property({ type: String }) theme = 'light'; ``` --- ## Commands ### `new ` Create a new Alpha workspace with complete project structure. **Syntax:** ```sh alpha new ``` **What happens:** 1. Creates directory structure 2. Initializes npm workspace (`workspaces: ["packages/*"]`) 3. Generates configuration files (`plugin.json`, `tsconfig.json`, `.env`) 4. Sets up Docker and Kubernetes templates 5. Creates VSCode settings 6. Installs dependencies: - **DevDependencies**: `lit`, `typescript` - **Dependencies**: `express`, `@jatahworx/alpha-annotations-lib` 7. Adds npm scripts: - `build`: Runs `alpha build` - `start`: Runs `alpha start` - `serve`: Runs `alpha serve` **Example:** ```sh alpha new ecommerce-components cd ecommerce-components ``` **Generated `plugin.json`:** ```json { "name": "ecommerce-components", "componentSelectorPrefix": "comp", "moduleSelectorPrefix": "mod" } ``` --- ### `generate` | `g` Generate components, modules, or attributes with pre-configured templates. #### Generate Component **Syntax:** ```sh alpha generate component [options] alpha g c [options] ``` **Options:** - `-d, --description ` - Component description **Example:** ```sh alpha g c product-card --description "Displays product information" ``` **Generated files:** ``` packages/product-card/ ├── package.json # npm package config ├── product-card.component.ts # Main component class ├── product-card.spec.ts # Test file ├── product-card.styles.ts # Lit CSS styles └── assets/ ├── icon/default-icon.png └── images/ ``` **Naming conventions applied:** - **File names**: `kebab-case` (`product-card.component.ts`) - **Class names**: `PascalCase` (`ProductCard`) - **Selectors**: `{prefix}-{kebab-case}` (`comp-product-card`) **Automatic updates:** - `public-api.ts` receives new export statement - Code formatted with Prettier - Component registered in workspace --- #### Generate Module **Syntax:** ```sh alpha generate module [options] alpha g m [options] ``` **Options:** - `-d, --description ` - Module description **Example:** ```sh alpha g m cart-service --description "Shopping cart management" ``` **Generated structure:** ``` packages/cart-service/ ├── package.json ├── index.js # Module class with lifecycle hooks └── assets/ ``` **Generated code pattern:** ```javascript class CartService { init() { // Initialization logic console.log('CartService initialized'); } onRegister() { // Registration hook console.log('CartService registered'); } // Your methods here } // Global registration alpha.registerPlugins('mod-cart-service', new CartService()); ``` --- #### Generate Attribute Add configurable attributes to existing components using interactive prompts or CLI options. **Syntax:** ```sh alpha generate attribute [componentName] [options] alpha g a [componentName] [options] ``` **Options:** - `-t, --type ` - Attribute type: `property`, `event`, or `validation` - `-u, --ui-type ` - UI control type (see [UI Types](#supported-ui-types)) - `-l, --label