@anvil-works/anvil-cli 0.4.2 → 0.5.0

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 (4) hide show
  1. package/README.md +208 -145
  2. package/dist/cli.js +847 -141
  3. package/dist/index.js +12 -5
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -17,83 +17,38 @@ A CLI tool for syncing Anvil apps between your local filesystem and the Anvil ID
17
17
  npm install -g @anvil-works/anvil-cli
18
18
  ```
19
19
 
20
- ## Quick Start
21
-
22
- ### 0. Clone Your App (Required)
23
-
24
- `anvil` watches a local clone of your Anvil app. If you haven't cloned the
25
- app yet, follow the [cloning guide](https://anvil.works/docs/version-control/git/direct-checkout#cloning-your-app)
26
- first:
27
-
28
- ```bash
29
- git clone https://anvil.works/git/YOUR_APP_ID my-app
30
- cd my-app
31
- ```
32
-
33
- > **SSH-only tip:** If you sign in to Anvil with Google (and therefore don't
34
- > have an Anvil password), Git requires SSH. Add your public key in the Anvil
35
- > account settings, start `ssh-agent`, run `ssh-add`, then use the `git clone`
36
- > command above.
37
-
38
- ### 1. Login
39
-
40
- Authenticate with Anvil using OAuth:
41
-
42
- ```bash
43
- anvil login
44
- ```
45
-
46
- This will:
47
-
48
- 1. Open your browser to the Anvil OAuth authorization page
49
- 2. Prompt you to authorize anvil-cli to access your Anvil account
50
- 3. Automatically complete the authentication flow
51
-
52
- Your access and refresh tokens are stored in:
53
- - **macOS**: `~/Library/Preferences/anvil-cli/config.json`
54
- - **Linux**: `~/.config/anvil-cli/config.json`
55
- - **Windows**: `%APPDATA%\anvil-cli\Config\config.json`
56
-
57
- **Smart URL Handling:** You can specify the Anvil server URL directly:
58
-
59
- ```bash
60
- # These all work - anvil automatically adds https://
61
- anvil login anvil.works
62
- anvil login anvil.mycompany.com
63
-
64
- # localhost automatically uses http://
65
- anvil login localhost:3000
66
-
67
- # Full URLs also work
68
- anvil login https://anvil.works
69
- ```
70
-
71
- **Multiple Accounts:** anvil-cli supports multiple Anvil installations simultaneously. Each URL has its own authentication tokens, so you can work with different enterprise installations or switch between them easily.
72
-
73
- ### 2. Watch Your Changes
74
-
75
- Navigate to your local Anvil app directory and start watching:
76
-
77
- ```bash
78
- cd /path/to/your/anvil/app
79
- anvil watch
80
- ```
81
-
82
- Or use the short form:
83
-
84
- ```bash
85
- anvil w
86
- ```
87
-
88
- > **Note:** `anvil sync` still works but is deprecated. Use `anvil watch` instead.
89
-
90
- You can specify the app ID explicitly:
91
-
92
- ```bash
93
- anvil watch -A YOUR_APP_ID
94
- ```
95
-
96
- **Watch Options:**
20
+ ## Quick Start
21
+
22
+ ### 1. Run Onboarding (Recommended First Step)
23
+
24
+ Start with guided setup for your default server URL, login, and optional checkout:
25
+
26
+ ```bash
27
+ anvil onboard
28
+ ```
29
+
30
+ When prompted for **Default Anvil server URL**, press Enter unless you're
31
+ running a dedicated enterprise/on-prem Anvil installation.
32
+
33
+ ### 2. Check Out Your App from the IDE URL
34
+
35
+ Copy your app URL from the Anvil IDE (for example
36
+ `https://anvil.works/build/apps/W36XUTXGNPDK6VEA`) and run:
37
+
38
+ ```bash
39
+ anvil checkout https://anvil.works/build/apps/W36XUTXGNPDK6VEA my-app
40
+ cd my-app
41
+ ```
42
+
43
+ ### 3. Watch Your Changes
44
+
45
+ When you're ready to sync local edits in real-time:
46
+
47
+ ```bash
48
+ anvil watch
49
+ ```
50
+
51
+ **Watch Options:**
97
52
 
98
53
  - `-A, --appid <APP_ID>` - Specify app ID directly
99
54
  - `-f, --first` - Auto-select first detected app ID without confirmation
@@ -124,12 +79,13 @@ The diagram shows bidirectional sync:
124
79
 
125
80
  | Command | Description |
126
81
  | -------------------------------------- | -------------------------------------------------------------------- |
127
- | `anvil watch [path]` | Watch directory for changes and sync to Anvil |
128
- | `anvil watch -V` or `--verbose` | Watch with verbose logging (detailed output) |
129
- | `anvil sync [path]` | Deprecated alias for `watch` |
130
- | `anvil w [path]` | Short form for watch |
131
- | `anvil login [anvil-server-url]` | Authenticate with Anvil using OAuth (supports smart URL handling) |
132
- | `anvil l [anvil-server-url]` | Short form for login |
82
+ | `anvil watch [path]` | Watch directory for changes and sync to Anvil |
83
+ | `anvil watch -V` or `--verbose` | Watch with verbose logging (detailed output) |
84
+ | `anvil w [path]` | Short form for watch |
85
+ | `anvil onboard` | Guided setup for default URL, login, and optional checkout |
86
+ | `anvil checkout <input> [directory]` | Check out an Anvil app locally from editor URL, git URL, or app ID |
87
+ | `anvil login [anvil-server-url]` | Authenticate with Anvil using OAuth (supports smart URL handling) |
88
+ | `anvil l [anvil-server-url]` | Short form for login |
133
89
  | `anvil logout [anvil-server-url]` | Logout from Anvil (optionally specify URL for specific installation) |
134
90
  | `anvil config <action> [key] [value]` | Manage configuration (set, get, list) |
135
91
  | `anvil c <action> [key] [value]` | Short form for config |
@@ -153,13 +109,15 @@ anvil watch -A YOUR_APP_ID
153
109
 
154
110
  ### Anvil URL Detection
155
111
 
156
- anvil-cli automatically detects which Anvil server to use:
157
-
158
- 1. **Explicit URL**: If you specify `--url` or `-u` flag
159
- 2. **Git Remotes**: Automatically extracts URL from git remotes in your repository
160
- 3. **User Prompt**: If multiple accounts are available, prompts you to select one
161
- 4. **Global Config**: Falls back to `anvilUrl` in config file
162
- 5. **Default**: Uses `https://anvil.works` (or `http://localhost:3000` in dev mode)
112
+ anvil-cli automatically detects which Anvil server to use:
113
+
114
+ 1. **Explicit URL**: If you specify `--url` or `-u` flag
115
+ 2. **Git Remotes**: Automatically extracts URL from git remotes in your repository
116
+ 3. **Logged-in URLs**:
117
+ - If one logged-in URL is available, uses it automatically
118
+ - If multiple logged-in URLs are available, prompts you to select one
119
+ 4. **Global Config**: Falls back to `anvilUrl` in config file
120
+ 5. **Default**: Uses `https://anvil.works` (or `http://localhost:3000` in dev mode)
163
121
 
164
122
  **Examples:**
165
123
 
@@ -172,46 +130,133 @@ anvil watch --url anvil.works
172
130
  anvil watch --url localhost:3000
173
131
  anvil watch --url anvil.mycompany.com
174
132
 
175
- # If multiple accounts, you'll be prompted to select
176
- anvil watch
177
- # ? Multiple Anvil installations found. Which one would you like to use?
178
- # ❯ https://anvil.works
179
- # https://anvil.company.com
180
- # Cancel
181
- ```
182
-
183
- ## Configuration
184
-
185
- ### Config File Location
133
+ # If multiple logged-in URLs, you'll be prompted to select
134
+ anvil watch
135
+ # ? Multiple Anvil installations found. Which one would you like to use?
136
+ # ❯ https://anvil.works
137
+ # https://anvil.company.com
138
+ # Cancel
139
+ ```
140
+
141
+ ### Checkout Apps
142
+
143
+ `anvil checkout` accepts an editor URL, git URL, or bare app ID:
144
+
145
+ ```bash
146
+ # Checkout from editor URL
147
+ anvil checkout http://localhost:3000/build/apps/MHVELZG5SZXK2POE/code/assets/theme.css
148
+
149
+ # Checkout from git URL
150
+ anvil checkout https://anvil.works/git/MHVELZG5SZXK2POE.git
151
+
152
+ # Checkout from app ID (specify URL when needed)
153
+ anvil checkout MHVELZG5SZXK2POE --url anvil.works
154
+
155
+ # Explicit destination directory
156
+ anvil checkout MHVELZG5SZXK2POE my-local-app --url anvil.works
157
+
158
+ # Clone-style options
159
+ anvil checkout MHVELZG5SZXK2POE --branch master --depth 1 --single-branch
160
+ anvil checkout MHVELZG5SZXK2POE --origin upstream
161
+ anvil checkout MHVELZG5SZXK2POE --quiet
162
+ ```
163
+
164
+ Safety behavior:
165
+
166
+ - Blocks checkout into non-empty destination directories (unless `--force`).
167
+ - Blocks checkout into paths inside an existing git repository (unless `--force`).
168
+
169
+ Git HTTPS credentials:
170
+
171
+ - Checkout configures a clean HTTPS remote URL plus a repo-local Git credential helper (`anvil git-credential`).
172
+ - The helper retrieves short-lived access tokens from your logged-in account and refreshes them as needed.
173
+ - Per-app bindings are stored in local git config (`anvil.auth.<APPID>.url` and `anvil.auth.<APPID>.username`) so multi-account repos stay deterministic.
174
+
175
+ Checkout options:
176
+
177
+ - `-O, --open` - Open destination after checkout
178
+ - `-b, --branch <BRANCH>` - Checkout a specific branch
179
+ - `--depth <N>` - Shallow clone with `N` commits of history
180
+ - `--single-branch` - Clone only one branch
181
+ - `--origin <NAME>` - Use custom remote name instead of `origin`
182
+ - `-q, --quiet` - Suppress git clone progress output
183
+ - `--verbose` - Verbose git clone output
184
+ - `-f, --force` - Override destination safety checks
185
+ - `-u, --url <ANVIL_URL>` - Override detected Anvil URL
186
+ - `-U, --user <USERNAME>` - Use a specific logged-in account
187
+
188
+ If multiple accounts are logged in for the same URL, `anvil checkout` will
189
+ prompt you to select one (interactive mode) or require `--user` in
190
+ non-interactive mode.
191
+
192
+ ## Configuration
193
+
194
+ ### Authentication
195
+
196
+ Use `anvil login` to authenticate with Anvil:
197
+
198
+ ```bash
199
+ anvil login
200
+ ```
201
+
202
+ The login flow will:
203
+
204
+ 1. Open your browser to the Anvil OAuth authorization page
205
+ 2. Prompt you to authorize anvil-cli
206
+ 3. Complete authentication automatically in the CLI
207
+
208
+ Your access and refresh tokens are stored in:
209
+ - **macOS**: `~/Library/Preferences/anvil-cli/config.json`
210
+ - **Linux**: `~/.config/anvil-cli/config.json`
211
+ - **Windows**: `%APPDATA%\anvil-cli\Config\config.json`
212
+
213
+ Smart URL handling:
214
+
215
+ ```bash
216
+ # anvil automatically adds https://
217
+ anvil login anvil.works
218
+ anvil login anvil.mycompany.com
219
+
220
+ # localhost uses http://localhost:3000
221
+ anvil login localhost:3000
222
+
223
+ # full URLs also work
224
+ anvil login https://anvil.works
225
+ ```
226
+
227
+ anvil-cli supports multiple Anvil installations simultaneously. Each URL has
228
+ its own authentication tokens.
229
+
230
+ ### Config File Location
186
231
 
187
232
  - **macOS**: `~/Library/Preferences/anvil-cli/config.json`
188
233
  - **Linux**: `~/.config/anvil-cli/config.json`
189
234
  - **Windows**: `%APPDATA%\anvil-cli\Config\config.json`
190
235
 
191
- ### Stored Configuration
192
-
193
- ```json
194
- {
195
- "authTokens": {
196
- "https://anvil.works": {
197
- "authToken": "your-access-token",
198
- "refreshToken": "your-refresh-token",
199
- "authTokenExpiresAt": 1234567890,
200
- "username": "user@example.com"
201
- },
202
- "https://anvil.company.com": {
203
- "authToken": "another-token",
204
- "refreshToken": "another-refresh",
205
- "authTokenExpiresAt": 1234567890,
206
- "username": "user@company.com"
207
- }
208
- },
209
- "anvilUrl": "https://anvil.works",
210
- "verbose": false
211
- }
212
- ```
213
-
214
- **Note:** The `authTokens` object stores tokens per URL, allowing you to work with multiple Anvil installations simultaneously. Legacy `authToken`, `refreshToken`, and `authTokenExpiresAt` fields are maintained for backward compatibility.
236
+ ### Stored Configuration
237
+
238
+ `config.json` stores settings and auth metadata. OAuth secrets are stored in the
239
+ OS keychain when available.
240
+
241
+ ```json
242
+ {
243
+ "anvilUrl": "https://anvil.works",
244
+ "verbose": false,
245
+ "preferredEditor": "cursor",
246
+ "authTokens": {
247
+ "https://anvil.works": {
248
+ "user@example.com": {
249
+ "authToken": null,
250
+ "refreshToken": null,
251
+ "authTokenExpiresAt": 1735689600
252
+ }
253
+ }
254
+ }
255
+ }
256
+ ```
257
+
258
+ If keychain is unavailable (for example some CI/headless environments), tokens
259
+ fall back to `config.json`.
215
260
 
216
261
  ### Verbose Logging
217
262
 
@@ -223,13 +268,25 @@ By default, anvil-cli shows minimal output. For more detailed logging:
223
268
  anvil watch --verbose
224
269
  ```
225
270
 
226
- **Persistent:** Set verbose mode in config:
271
+ **Persistent:** Set verbose mode in config:
227
272
 
228
273
  ```bash
229
- anvil config set verbose true
230
- ```
231
-
232
- Verbose output is prefixed with `[VERBOSE]` and includes file routing details, sync status checks, and other internal processing information.
274
+ anvil config set verbose true
275
+ ```
276
+
277
+ ### Preferred Editor
278
+
279
+ Set this during `anvil onboard`.
280
+
281
+ If needed later, you can still set it manually with:
282
+
283
+ ```bash
284
+ anvil config set preferredEditor <editor>
285
+ ```
286
+
287
+ `preferredEditor` is used by checkout for post-checkout guidance and `-O/--open`.
288
+
289
+ Verbose output includes timestamped diagnostic lines with file routing details, sync status checks, and other internal processing information.
233
290
 
234
291
  ### Enterprise Configuration
235
292
 
@@ -269,18 +326,21 @@ anvil login anvil.works
269
326
  anvil login anvil.company-a.com
270
327
  anvil login anvil.company-b.com
271
328
 
272
- # When syncing, you'll be prompted to select which one to use
273
- # Or specify explicitly:
274
- anvil watch --url anvil.company-a.com
275
- ```
329
+ # If URL is not resolved from git remotes and multiple logged-in URLs exist,
330
+ # you'll be prompted to select which one to use
331
+ # Or specify explicitly:
332
+ anvil watch --url anvil.company-a.com
333
+ ```
276
334
 
277
335
  **URL Resolution Priority:**
278
336
 
279
- 1. Explicit `--url` flag
280
- 2. Git remote detection (from current repository)
281
- 3. User prompt (if multiple accounts available)
282
- 4. `anvilUrl` in config file
283
- 5. Default based on `NODE_ENV`:
337
+ 1. Explicit `--url` flag
338
+ 2. Git remote detection (from current repository)
339
+ 3. Logged-in URL selection:
340
+ - One URL: auto-select
341
+ - Multiple URLs: prompt to select
342
+ 4. `anvilUrl` in config file
343
+ 5. Default based on `NODE_ENV`:
284
344
  - Production: `https://anvil.works`
285
345
  - Development: `http://localhost:3000`
286
346
 
@@ -308,10 +368,13 @@ anvil logout anvil.mycompany.com
308
368
  anvil logout --url localhost:3000
309
369
  ```
310
370
 
311
- **Multiple accounts:** If you have multiple accounts and run `anvil logout` without specifying a URL, you'll be prompted to:
312
-
313
- - Logout from one account (then select which one)
314
- - Logout from all accounts
371
+ **Without URL:** `anvil logout` uses total logged-in account count across all URLs:
372
+
373
+ - If you have **one account total**, it logs out immediately
374
+ - If you have **multiple accounts total**, you'll be prompted to:
375
+
376
+ - Logout from one account (then select which one)
377
+ - Logout from all accounts
315
378
  - Cancel
316
379
 
317
380
  ## Troubleshooting
@@ -343,7 +406,7 @@ anvil login https://anvil.mycompany.com
343
406
  anvil config set anvilUrl https://anvil.works
344
407
  ```
345
408
 
346
- - Or reset all config values (also clears custom URLs):
409
+ - Or reset all config values (also clears custom URLs and logs out all accounts):
347
410
 
348
411
  ```bash
349
412
  anvil config reset
@@ -351,4 +414,4 @@ anvil login https://anvil.mycompany.com
351
414
 
352
415
  ## License
353
416
 
354
- ISC
417
+ MIT