@variantlab/cli 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +114 -3
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,7 +1,118 @@
1
1
  # @variantlab/cli
2
2
 
3
- Command-line tool for variantlab: init, generate, validate, eval.
3
+ > Command-line tool for variantlab — scaffold, generate types, validate configs, and evaluate experiments.
4
4
 
5
- > **Status:** Phase 1 — Pre-alpha. Not ready for production use.
5
+ ![npm version](https://img.shields.io/npm/v/@variantlab/cli/alpha?label=npm&color=blue)
6
6
 
7
- See the [root README](../../README.md) for project overview, motivation, and roadmap.
7
+ ## Install
8
+
9
+ ```bash
10
+ # Use via npx (no install needed)
11
+ npx @variantlab/cli@alpha init
12
+
13
+ # Or install globally
14
+ npm install -g @variantlab/cli@alpha
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### `variantlab init`
20
+
21
+ Scaffold an `experiments.json` file with starter experiments.
22
+
23
+ ```bash
24
+ variantlab init # Creates experiments.json
25
+ variantlab init --force # Overwrite existing file
26
+ ```
27
+
28
+ ### `variantlab generate`
29
+
30
+ Generate TypeScript types from your `experiments.json`. Experiment IDs and variant IDs become literal types — typos become compile errors.
31
+
32
+ ```bash
33
+ variantlab generate # Default: reads experiments.json, writes variantlab.d.ts
34
+ variantlab generate --config ./config.json # Custom config path
35
+ variantlab generate --out ./types/vl.d.ts # Custom output path
36
+ variantlab generate --watch # Regenerate on file changes
37
+ ```
38
+
39
+ The generated `.d.ts` file provides:
40
+ - `VariantLabExperiments` interface with all experiment IDs
41
+ - `ExperimentId` union type
42
+ - `VariantId<E>` mapped type per experiment
43
+ - `VariantValueType<E>` for value experiments
44
+ - Module augmentation for type-safe hooks
45
+
46
+ ### `variantlab validate`
47
+
48
+ Validate an experiments config file against the schema.
49
+
50
+ ```bash
51
+ variantlab validate # Validates ./experiments.json
52
+ variantlab validate ./custom-path.json # Validate a specific file
53
+ ```
54
+
55
+ Reports:
56
+ - JSON parse errors
57
+ - Schema violations (missing fields, wrong types)
58
+ - Duplicate experiment IDs
59
+ - Invalid default variant references
60
+ - Invalid targeting predicates
61
+
62
+ ### `variantlab eval`
63
+
64
+ Evaluate an experiment against a targeting context — useful for debugging why a user gets a specific variant.
65
+
66
+ ```bash
67
+ # Inline context
68
+ variantlab eval --experiment hero-layout --context '{"platform":"ios","screenSize":"small"}'
69
+
70
+ # Context from file
71
+ variantlab eval --experiment hero-layout --context-file ./test-context.json
72
+
73
+ # Custom config path
74
+ variantlab eval ./config.json --experiment hero-layout --context '{"userId":"user-123"}'
75
+ ```
76
+
77
+ Shows:
78
+ - Step-by-step targeting trace (pass/fail per field)
79
+ - Final resolved variant
80
+ - Assignment strategy used
81
+
82
+ ## Exit codes
83
+
84
+ | Code | Meaning |
85
+ |------|---------|
86
+ | 0 | Success |
87
+ | 1 | File not found |
88
+ | 2 | Validation error / invalid config |
89
+ | 3 | I/O error |
90
+ | 4 | Invalid arguments |
91
+
92
+ ## Global options
93
+
94
+ ```
95
+ --help Show help for any command
96
+ --version Show version
97
+ --verbose Enable verbose output
98
+ ```
99
+
100
+ ## Programmatic API
101
+
102
+ All commands are also available as functions:
103
+
104
+ ```ts
105
+ import { init, generate, validate, evalCommand } from "@variantlab/cli";
106
+
107
+ await init({ force: true });
108
+ await generate({ config: "./experiments.json", out: "./variantlab.d.ts" });
109
+ await validate("./experiments.json");
110
+ await evalCommand("./experiments.json", {
111
+ experiment: "hero-layout",
112
+ context: '{"platform":"ios"}',
113
+ });
114
+ ```
115
+
116
+ ## License
117
+
118
+ [MIT](./LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@variantlab/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Command-line tool for variantlab: init, generate, validate, eval.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "provenance": false
34
34
  },
35
35
  "dependencies": {
36
- "@variantlab/core": "0.1.0"
36
+ "@variantlab/core": "0.1.1"
37
37
  },
38
38
  "keywords": [
39
39
  "ab-testing",