@onexapis/cli 1.0.0 → 1.0.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/README.md CHANGED
@@ -1,330 +1,333 @@
1
- # @duongthiu/onex-cli
1
+ # @onexapis/cli
2
2
 
3
- CLI tool for OneX theme development - scaffold themes, sections, blocks, and components with ease.
4
-
5
- Uses `@duongthiu/onex-core` for the core theme system.
3
+ CLI tool for OneX theme development scaffold, build, validate, and deploy themes using `@onexapis/core`.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  ```bash
10
- # Install in your OneX project
11
- npm install -D @duongthiu/onex-cli
12
-
13
- # Or use globally
14
- npm install -g @duongthiu/onex-cli
8
+ # Install globally
9
+ npm install -g @onexapis/cli
15
10
 
16
- # Or use via npx
17
- npx @duongthiu/onex-cli <command>
11
+ # Or within the monorepo
12
+ cd packages/cli
13
+ pnpm build
14
+ npm install -g .
18
15
  ```
19
16
 
20
- ## Commands
17
+ Requires Node.js >= 18.
21
18
 
22
- ### `onex init [theme-name]`
19
+ ## Quick Start
23
20
 
24
- Initialize a new OneX theme with complete structure.
21
+ ```bash
22
+ # Create a new theme project
23
+ onex init my-theme
25
24
 
26
- **Options:**
25
+ # List all themes, sections, blocks, and components
26
+ onex list
27
27
 
28
- - `-t, --template <template>` - Template to use (default, minimal)
28
+ # Create a section in a theme
29
+ onex create:section hero --theme simple
29
30
 
30
- **Example:**
31
+ # Validate theme structure
32
+ onex validate --theme simple
31
33
 
32
- ```bash
33
- onex init my-theme
34
- onex init my-store -t ecommerce
35
- ```
34
+ # Build a theme
35
+ onex build --theme simple
36
36
 
37
- **Generated structure:**
37
+ # Upload to S3
38
+ onex upload --theme simple
38
39
 
39
- ```
40
- src/themes/my-theme/
41
- ├── manifest.ts # Theme metadata and exports
42
- ├── theme.config.ts # Design tokens (colors, typography, spacing)
43
- ├── theme.layout.ts # Header/footer configuration
44
- ├── index.ts # Main exports
45
- ├── sections/ # Theme-specific sections
46
- ├── blocks/ # Theme-specific blocks
47
- └── pages/
48
- └── home.ts # Default home page config
40
+ # Clone a theme from S3
41
+ onex clone simple
49
42
  ```
50
43
 
51
- ### `onex create:section <name>` (alias: `cs`)
44
+ ## Commands
52
45
 
53
- Create a new section with schema and template files.
46
+ ### `onex init [project-name]`
54
47
 
55
- **Options:**
48
+ Create a new OneX theme project from a template.
56
49
 
57
- - `-t, --theme <theme>` - Theme to create section in
58
- - `-c, --category <category>` - Section category (headers, content, footers, etc.)
59
- - `--template <template>` - Initial template variant
50
+ | Option | Description |
51
+ |---|---|
52
+ | `-t, --template <template>` | Template to use (`default`, `minimal`) |
53
+ | `--no-install` | Skip installing dependencies |
54
+ | `--git` | Initialize a git repository |
55
+ | `-y, --yes` | Skip prompts and use defaults |
60
56
 
61
- **Example:**
57
+ ### `onex create:section <name>` (alias: `cs`)
62
58
 
63
- ```bash
64
- onex create:section hero -t my-theme -c heroes
65
- onex cs featured-products -t my-store -c ecommerce
66
- ```
59
+ Scaffold a new section inside a theme.
67
60
 
68
- **Generated files:**
61
+ | Option | Description |
62
+ |---|---|
63
+ | `-t, --theme <theme>` | Target theme |
64
+ | `-c, --category <category>` | Section category (`headers`, `content`, `footers`) |
65
+ | `--template <template>` | Initial template variant (`default`, `minimal`) |
69
66
 
70
- ```
71
- src/themes/my-theme/sections/hero/
72
- ├── hero.schema.ts # Section schema with settings
73
- ├── hero-default.tsx # Default template component
74
- └── index.ts # Exports
67
+ ```bash
68
+ onex create:section hero -t my-theme -c heroes
69
+ onex cs featured-products -t my-store
75
70
  ```
76
71
 
77
72
  ### `onex create:block <name>` (alias: `cb`)
78
73
 
79
- Create a new block component (shared or theme-specific).
80
-
81
- **Options:**
74
+ Scaffold a new block.
82
75
 
83
- - `-t, --theme <theme>` - Theme to create block in (optional, defaults to shared)
84
-
85
- **Example:**
76
+ | Option | Description |
77
+ |---|---|
78
+ | `-t, --theme <theme>` | Target theme (optional) |
86
79
 
87
80
  ```bash
88
81
  onex create:block product-card
89
82
  onex cb testimonial-item -t my-theme
90
83
  ```
91
84
 
92
- **Generated files:**
93
-
94
- ```
95
- src/features/blocks/product-card/
96
- ├── product-card.schema.ts # Block schema with settings
97
- ├── product-card.tsx # Block component
98
- └── index.ts # Exports
99
- ```
100
-
101
85
  ### `onex create:component <name>` (alias: `cc`)
102
86
 
103
- Create a new UI component.
104
-
105
- **Options:**
87
+ Scaffold a new UI component.
106
88
 
107
- - `-t, --type <type>` - Component type (ui, form, layout, content)
108
-
109
- **Example:**
89
+ | Option | Description |
90
+ |---|---|
91
+ | `-t, --type <type>` | Component type (`ui`, `layout`, `form`) |
110
92
 
111
93
  ```bash
112
94
  onex create:component icon-badge
113
95
  onex cc custom-input -t form
114
96
  ```
115
97
 
116
- **Generated files:**
98
+ ### `onex list`
117
99
 
118
- ```
119
- src/features/components/icon-badge/
120
- ├── icon-badge.schema.ts # Component schema with content/style fields
121
- ├── icon-badge.tsx # Component implementation
122
- └── index.ts # Exports
123
- ```
100
+ List available themes, sections, blocks, and components in the project.
124
101
 
125
- ### `onex list`
102
+ | Option | Description |
103
+ |---|---|
104
+ | `-s, --sections` | List sections only |
105
+ | `-b, --blocks` | List blocks only |
106
+ | `-c, --components` | List components only |
107
+ | `-t, --theme <theme>` | Filter by theme |
126
108
 
127
- Display project inventory (themes, sections, blocks, components).
109
+ ### `onex validate`
128
110
 
129
- **Options:**
111
+ Validate theme structure and files.
130
112
 
131
- - `-s, --sections` - List sections only
132
- - `-b, --blocks` - List blocks only
133
- - `-c, --components` - List components only
134
- - `-t, --theme <theme>` - Filter by theme
113
+ | Option | Description |
114
+ |---|---|
115
+ | `-t, --theme <theme>` | Theme to validate |
116
+ | `-f, --fix` | Auto-fix issues (not yet implemented) |
135
117
 
136
- **Example:**
118
+ ### `onex build`
137
119
 
138
- ```bash
139
- onex list
140
- onex list -s -t my-theme
141
- onex list --blocks
142
- ```
120
+ Build a theme for production. Runs type-check, lint, and compilation.
143
121
 
144
- ## Features
122
+ | Option | Description |
123
+ |---|---|
124
+ | `-t, --theme <theme>` | Theme to build |
125
+ | `-p, --production` | Production build with optimizations |
126
+ | `-w, --watch` | Watch mode for development |
145
127
 
146
- ### Interactive Prompts
128
+ > **Note:** The theme's `package.json` must have `type-check` and `lint` scripts for the build to pass. Example:
129
+ > ```json
130
+ > { "scripts": { "type-check": "tsc --noEmit", "lint": "eslint src" } }
131
+ > ```
147
132
 
148
- All commands feature interactive prompts for missing options:
133
+ ### `onex package`
149
134
 
150
- - Theme selection from available themes
151
- - Category selection with validation
152
- - Display names and descriptions
153
- - Template preferences
135
+ Compile and package a theme as a distributable zip file.
154
136
 
155
- ### Validation
137
+ | Option | Description |
138
+ |---|---|
139
+ | `-t, --theme <theme>` | Theme to package |
140
+ | `-o, --output <dir>` | Output directory |
141
+ | `-n, --name <name>` | Custom package name |
142
+ | `-m, --minify` | Minify compiled output |
143
+ | `--skip-build` | Skip compilation, use existing compiled theme |
156
144
 
157
- - **Name Validation**: Ensures kebab-case format (e.g., `my-section`, `product-card`)
158
- - **Theme Validation**: Checks theme existence before creating sections/blocks
159
- - **Category Validation**: Validates against predefined categories
160
- - **Project Detection**: Ensures commands run within a OneX project
145
+ ### `onex deploy`
161
146
 
162
- ### Smart Templates
147
+ Upload a theme package to the API server.
163
148
 
164
- Generated files include:
149
+ | Option | Description |
150
+ |---|---|
151
+ | `-t, --theme <theme>` | Theme to deploy |
152
+ | `-p, --package <file>` | Specific package file to upload |
153
+ | `--api-url <url>` | API server URL (default: `http://localhost:3001`) |
154
+ | `-k, --api-key <key>` | API key for authentication |
155
+ | `-e, --environment <env>` | Environment (`production`, `staging`, `development`) |
165
156
 
166
- - Proper TypeScript types from `@onex/core`
167
- - Best practice component structure
168
- - Commented TODOs for customization
169
- - Responsive design patterns
170
- - Accessibility considerations
157
+ ### `onex upload`
171
158
 
172
- ### Beautiful Output
159
+ Upload compiled theme to S3 as `bundle.zip` + `source.zip`.
173
160
 
174
- - Color-coded messages (success, error, warning, info)
175
- - Loading spinners for file operations
176
- - Clear next steps after each command
177
- - Relative file paths for easy navigation
161
+ | Option | Description |
162
+ |---|---|
163
+ | `-t, --theme <theme>` | Theme to upload |
164
+ | `-b, --bucket <name>` | S3 bucket name |
165
+ | `-v, --version <version>` | Theme version |
166
+ | `-e, --environment <env>` | Environment (`staging` or `production`) |
167
+ | `--dry-run` | Show what would be uploaded without uploading |
168
+ | `--skip-source` | Skip uploading `source.zip` |
169
+ | `--source-dir <dir>` | Source directory path |
178
170
 
179
- ## Usage in Project
171
+ ```bash
172
+ # Dry run first
173
+ onex upload --theme simple --dry-run
180
174
 
181
- ### Option 1: Via pnpm scripts
175
+ # Upload to staging
176
+ onex upload --theme simple
182
177
 
183
- Add to `package.json`:
178
+ # Upload to production
179
+ onex upload --theme simple -e production
184
180
 
185
- ```json
186
- {
187
- "scripts": {
188
- "onex": "node packages/cli/bin/onex.js"
189
- }
190
- }
181
+ # Override bucket
182
+ onex upload --theme simple --bucket custom-bucket
191
183
  ```
192
184
 
193
- Then use:
185
+ ### `onex download`
194
186
 
195
- ```bash
196
- pnpm onex list
197
- pnpm onex create:section hero -t my-theme
198
- ```
187
+ Download a compiled theme from S3.
199
188
 
200
- ### Option 2: Direct execution
189
+ | Option | Description |
190
+ |---|---|
191
+ | `-t, --theme-id <id>` | Theme ID to download |
192
+ | `-v, --version <version>` | Theme version (default: `latest`) |
193
+ | `-b, --bucket <name>` | S3 bucket name |
194
+ | `-e, --environment <env>` | Environment (`staging` or `production`) |
195
+ | `-o, --output <dir>` | Output directory (default: `./active-theme`) |
201
196
 
202
- ```bash
203
- node packages/cli/bin/onex.js list
204
- node packages/cli/bin/onex.js create:section hero
205
- ```
197
+ ### `onex clone <theme-name>`
198
+
199
+ Clone theme source code from S3.
206
200
 
207
- ### Option 3: Global installation
201
+ | Option | Description |
202
+ |---|---|
203
+ | `-v, --version <version>` | Theme version (default: `latest`) |
204
+ | `-o, --output <dir>` | Output directory |
205
+ | `-b, --bucket <name>` | S3 bucket name |
206
+ | `-e, --environment <env>` | Environment (`staging` or `production`) |
207
+ | `--no-install` | Skip running `pnpm install` after clone |
208
208
 
209
209
  ```bash
210
- npm install -g @duongthiu/onex-cli
211
- onex list
212
- onex create:section hero
210
+ onex clone simple
211
+ onex clone simple -v 1.0.0 -o ./my-clone --no-install
213
212
  ```
214
213
 
215
- ## Development
214
+ ## S3 Configuration
216
215
 
217
- ### Building the CLI
216
+ The `upload`, `download`, and `clone` commands use S3 for storage. The CLI **automatically loads `.env.local` and `.env`** from the project root, so you only need to configure once:
218
217
 
219
218
  ```bash
220
- cd packages/cli
221
- pnpm build
219
+ # .env.local (at project root)
220
+ BUCKET_NAME=my-bucket
221
+ AWS_REGION=ap-southeast-1
222
+ AWS_ACCESS_KEY_ID=your-access-key
223
+ AWS_SECRET_ACCESS_KEY=your-secret-key
222
224
  ```
223
225
 
224
- ### Testing locally
226
+ Then all S3 commands just work without extra flags:
225
227
 
226
228
  ```bash
227
- # From project root
228
- node packages/cli/bin/onex.js --help
229
- node packages/cli/bin/onex.js list
229
+ onex upload --theme simple # picks up bucket + credentials from .env.local
230
+ onex clone simple # same
231
+ onex download -t simple # same
230
232
  ```
231
233
 
232
- ### Type Checking
234
+ ### Adapter Modes
233
235
 
234
236
  ```bash
235
- pnpm type-check
237
+ # MinIO (set ADAPTER_MODE=vps)
238
+ ADAPTER_MODE=vps
239
+ MINIO_ENDPOINT=localhost:9000
240
+ MINIO_ACCESS_KEY=minioadmin
241
+ MINIO_SECRET_KEY=minioadmin
242
+
243
+ # LocalStack (set ADAPTER_MODE=local)
244
+ ADAPTER_MODE=local
236
245
  ```
237
246
 
238
- ### Linting
247
+ ### Bucket Name Resolution
248
+
249
+ Priority order:
250
+ 1. `--bucket` CLI flag
251
+ 2. `BUCKET_NAME` environment variable
252
+ 3. Default: `onex-themes-staging` or `onex-themes-prod` (based on `--environment`)
253
+
254
+ ## Theme Structure
255
+
256
+ Themes live in the `themes/` directory at the project root:
239
257
 
240
- ```bash
241
- pnpm lint
258
+ ```
259
+ themes/
260
+ my-theme/
261
+ theme.config.ts # Theme metadata (name, version, description)
262
+ bundle-entry.ts # Build entry point
263
+ index.ts # Theme exports
264
+ sections-registry.ts # Section registry
265
+ theme.layout.ts # Layout definition
266
+ package.json
267
+ tsconfig.json
268
+ sections/ # Section components
269
+ hero/
270
+ features/
271
+ ...
272
+ pages/ # Page configurations
273
+ home.ts
274
+ about.ts
275
+ ...
242
276
  ```
243
277
 
244
- ## Architecture
278
+ ## Project Detection
245
279
 
246
- ### File Structure
280
+ The CLI detects a OneX project by looking for a `themes/` directory (or legacy `src/themes/`) from the project root. Within themes, it recognizes any directory containing `theme.config.ts`, `bundle-entry.ts`, or `manifest.ts` as a valid theme.
281
+
282
+ ## Architecture
247
283
 
248
284
  ```
249
285
  packages/cli/
250
286
  ├── src/
251
287
  │ ├── cli.ts # Main CLI entry point
252
- │ ├── index.ts # Programmatic API
288
+ │ ├── index.ts # Programmatic API exports
253
289
  │ ├── commands/
254
290
  │ │ ├── init.ts # Theme initialization
255
291
  │ │ ├── create-section.ts # Section scaffolding
256
292
  │ │ ├── create-block.ts # Block scaffolding
257
293
  │ │ ├── create-component.ts # Component scaffolding
258
- │ │ └── list.ts # Project inventory
294
+ │ │ ├── list.ts # Project inventory
295
+ │ │ ├── validate.ts # Theme validation
296
+ │ │ ├── build.ts # Theme build
297
+ │ │ ├── package.ts # Theme packaging
298
+ │ │ ├── deploy.ts # Deploy to API server
299
+ │ │ ├── upload.ts # Upload to S3
300
+ │ │ ├── download.ts # Download from S3
301
+ │ │ └── clone.ts # Clone source from S3
259
302
  │ └── utils/
260
303
  │ ├── logger.ts # Console output utilities
261
- │ ├── file-helpers.ts # File operations
304
+ │ ├── file-helpers.ts # File operations & project detection
262
305
  │ └── validators.ts # Input validation
263
306
  ├── bin/
264
307
  │ └── onex.js # Executable entry point
308
+ ├── templates/ # Scaffolding templates
265
309
  └── package.json
266
310
  ```
267
311
 
268
- ### Dependencies
269
-
270
- - **commander**: CLI framework and command parsing
271
- - **inquirer**: Interactive prompts
272
- - **chalk**: Terminal string styling
273
- - **ora**: Elegant terminal spinners
274
- - **fs-extra**: Enhanced file system operations
275
- - **ejs**: Template rendering (for future template system)
276
- - **glob**: File pattern matching
277
-
278
- ## Next Steps
279
-
280
- After generating files:
281
-
282
- 1. **Sections**:
283
- - Customize `section.schema.ts` with your settings
284
- - Implement template component in `section-default.tsx`
285
- - Register in theme `manifest.ts`
286
-
287
- 2. **Blocks**:
288
- - Define settings in `block.schema.ts`
289
- - Implement component in `block.tsx`
290
- - Register in `src/lib/registry/block-registry.ts`
291
-
292
- 3. **Components**:
293
- - Customize content/style fields in `component.schema.ts`
294
- - Implement component in `component.tsx`
295
- - Register in `src/lib/registry/component-registry.ts`
296
-
297
- ## Examples
298
-
299
- ### Creating a complete feature section
312
+ ## Development
300
313
 
301
314
  ```bash
302
- # 1. Create theme
303
- onex init ecommerce-theme
304
-
305
- # 2. Create hero section
306
- onex create:section hero -t ecommerce-theme -c heroes
315
+ cd packages/cli
307
316
 
308
- # 3. Create product blocks
309
- onex create:block product-card
310
- onex create:block product-grid
317
+ # Build
318
+ pnpm build
311
319
 
312
- # 4. Create components
313
- onex create:component price-tag -t ui
314
- onex create:component add-to-cart -t ui
320
+ # Watch mode
321
+ pnpm dev
315
322
 
316
- # 5. Check inventory
317
- onex list -t ecommerce-theme
318
- ```
319
-
320
- ### Quick section creation
323
+ # Type check
324
+ pnpm type-check
321
325
 
322
- ```bash
323
- # Create with all options
324
- onex cs testimonials -t my-theme -c testimonials
326
+ # Lint
327
+ pnpm lint
325
328
 
326
- # Interactive mode (prompts for options)
327
- onex cs testimonials
329
+ # Install globally after building
330
+ npm install -g . --force
328
331
  ```
329
332
 
330
333
  ## License