@anvil-works/anvil-cli 0.4.3 → 0.5.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.
package/README.md CHANGED
@@ -11,87 +11,64 @@ A CLI tool for syncing Anvil apps between your local filesystem and the Anvil ID
11
11
  - **Form Support**: Syncs forms with templates and code
12
12
  - **Theme Assets**: Syncs theme assets and configuration
13
13
 
14
- ## Installation
15
-
16
- ```bash
17
- npm install -g @anvil-works/anvil-cli
18
- ```
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
- You can specify the app ID explicitly:
89
-
90
- ```bash
91
- anvil watch -A YOUR_APP_ID
92
- ```
14
+ ## Installation
15
+
16
+ ### macOS/Linux
17
+
18
+ ```bash
19
+ curl -fsSL https://anvil.works/install/anvil-cli/install.sh | sh
20
+ ```
21
+
22
+ ### Windows PowerShell
23
+
24
+ ```powershell
25
+ irm https://anvil.works/install/anvil-cli/install.ps1 | iex
26
+ ```
27
+
28
+ ### Windows CMD
29
+
30
+ ```cmd
31
+ curl -fsSL https://anvil.works/install/anvil-cli/install.cmd -o install.cmd && install.cmd && del install.cmd
32
+ ```
33
+
34
+ ### Manual Fallback
35
+
36
+ ```bash
37
+ npm install -g @anvil-works/anvil-cli
38
+ ```
93
39
 
94
- **Watch Options:**
40
+ ## Quick Start
41
+
42
+ ### 1. Run Onboarding (Recommended First Step)
43
+
44
+ Start with guided setup for your default server URL, login, and optional checkout:
45
+
46
+ ```bash
47
+ anvil onboard
48
+ ```
49
+
50
+ When prompted for **Default Anvil server URL**, press Enter unless you're
51
+ running a dedicated enterprise/on-prem Anvil installation.
52
+
53
+ ### 2. Check Out Your App from the IDE URL
54
+
55
+ Copy your app URL from the Anvil IDE (for example
56
+ `https://anvil.works/build/apps/W36XUTXGNPDK6VEA`) and run:
57
+
58
+ ```bash
59
+ anvil checkout https://anvil.works/build/apps/W36XUTXGNPDK6VEA my-app
60
+ cd my-app
61
+ ```
62
+
63
+ ### 3. Watch Your Changes
64
+
65
+ When you're ready to sync local edits in real-time:
66
+
67
+ ```bash
68
+ anvil watch
69
+ ```
70
+
71
+ **Watch Options:**
95
72
 
96
73
  - `-A, --appid <APP_ID>` - Specify app ID directly
97
74
  - `-f, --first` - Auto-select first detected app ID without confirmation
@@ -122,11 +99,13 @@ The diagram shows bidirectional sync:
122
99
 
123
100
  | Command | Description |
124
101
  | -------------------------------------- | -------------------------------------------------------------------- |
125
- | `anvil watch [path]` | Watch directory for changes and sync to Anvil |
126
- | `anvil watch -V` or `--verbose` | Watch with verbose logging (detailed output) |
127
- | `anvil w [path]` | Short form for watch |
128
- | `anvil login [anvil-server-url]` | Authenticate with Anvil using OAuth (supports smart URL handling) |
129
- | `anvil l [anvil-server-url]` | Short form for login |
102
+ | `anvil watch [path]` | Watch directory for changes and sync to Anvil |
103
+ | `anvil watch -V` or `--verbose` | Watch with verbose logging (detailed output) |
104
+ | `anvil w [path]` | Short form for watch |
105
+ | `anvil onboard` | Guided setup for default URL, login, and optional checkout |
106
+ | `anvil checkout <input> [directory]` | Check out an Anvil app locally from editor URL, git URL, or app ID |
107
+ | `anvil login [anvil-server-url]` | Authenticate with Anvil using OAuth (supports smart URL handling) |
108
+ | `anvil l [anvil-server-url]` | Short form for login |
130
109
  | `anvil logout [anvil-server-url]` | Logout from Anvil (optionally specify URL for specific installation) |
131
110
  | `anvil config <action> [key] [value]` | Manage configuration (set, get, list) |
132
111
  | `anvil c <action> [key] [value]` | Short form for config |
@@ -177,40 +156,127 @@ anvil watch
177
156
  # ❯ https://anvil.works
178
157
  # https://anvil.company.com
179
158
  # Cancel
180
- ```
181
-
182
- ## Configuration
183
-
184
- ### Config File Location
159
+ ```
160
+
161
+ ### Checkout Apps
162
+
163
+ `anvil checkout` accepts an editor URL, git URL, or bare app ID:
164
+
165
+ ```bash
166
+ # Checkout from editor URL
167
+ anvil checkout http://localhost:3000/build/apps/MHVELZG5SZXK2POE/code/assets/theme.css
168
+
169
+ # Checkout from git URL
170
+ anvil checkout https://anvil.works/git/MHVELZG5SZXK2POE.git
171
+
172
+ # Checkout from app ID (specify URL when needed)
173
+ anvil checkout MHVELZG5SZXK2POE --url anvil.works
174
+
175
+ # Explicit destination directory
176
+ anvil checkout MHVELZG5SZXK2POE my-local-app --url anvil.works
177
+
178
+ # Clone-style options
179
+ anvil checkout MHVELZG5SZXK2POE --branch master --depth 1 --single-branch
180
+ anvil checkout MHVELZG5SZXK2POE --origin upstream
181
+ anvil checkout MHVELZG5SZXK2POE --quiet
182
+ ```
183
+
184
+ Safety behavior:
185
+
186
+ - Blocks checkout into non-empty destination directories (unless `--force`).
187
+ - Blocks checkout into paths inside an existing git repository (unless `--force`).
188
+
189
+ Git HTTPS credentials:
190
+
191
+ - Checkout configures a clean HTTPS remote URL plus a repo-local Git credential helper (`anvil git-credential`).
192
+ - The helper retrieves short-lived access tokens from your logged-in account and refreshes them as needed.
193
+ - Per-app bindings are stored in local git config (`anvil.auth.<APPID>.url` and `anvil.auth.<APPID>.username`) so multi-account repos stay deterministic.
194
+
195
+ Checkout options:
196
+
197
+ - `-O, --open` - Open destination after checkout
198
+ - `-b, --branch <BRANCH>` - Checkout a specific branch
199
+ - `--depth <N>` - Shallow clone with `N` commits of history
200
+ - `--single-branch` - Clone only one branch
201
+ - `--origin <NAME>` - Use custom remote name instead of `origin`
202
+ - `-q, --quiet` - Suppress git clone progress output
203
+ - `--verbose` - Verbose git clone output
204
+ - `-f, --force` - Override destination safety checks
205
+ - `-u, --url <ANVIL_URL>` - Override detected Anvil URL
206
+ - `-U, --user <USERNAME>` - Use a specific logged-in account
207
+
208
+ If multiple accounts are logged in for the same URL, `anvil checkout` will
209
+ prompt you to select one (interactive mode) or require `--user` in
210
+ non-interactive mode.
211
+
212
+ ## Configuration
213
+
214
+ ### Authentication
215
+
216
+ Use `anvil login` to authenticate with Anvil:
217
+
218
+ ```bash
219
+ anvil login
220
+ ```
221
+
222
+ The login flow will:
223
+
224
+ 1. Open your browser to the Anvil OAuth authorization page
225
+ 2. Prompt you to authorize anvil-cli
226
+ 3. Complete authentication automatically in the CLI
227
+
228
+ Your access and refresh tokens are stored in:
229
+ - **macOS**: `~/Library/Preferences/anvil-cli/config.json`
230
+ - **Linux**: `~/.config/anvil-cli/config.json`
231
+ - **Windows**: `%APPDATA%\anvil-cli\Config\config.json`
232
+
233
+ Smart URL handling:
234
+
235
+ ```bash
236
+ # anvil automatically adds https://
237
+ anvil login anvil.works
238
+ anvil login anvil.mycompany.com
239
+
240
+ # localhost uses http://localhost:3000
241
+ anvil login localhost:3000
242
+
243
+ # full URLs also work
244
+ anvil login https://anvil.works
245
+ ```
246
+
247
+ anvil-cli supports multiple Anvil installations simultaneously. Each URL has
248
+ its own authentication tokens.
249
+
250
+ ### Config File Location
185
251
 
186
252
  - **macOS**: `~/Library/Preferences/anvil-cli/config.json`
187
253
  - **Linux**: `~/.config/anvil-cli/config.json`
188
254
  - **Windows**: `%APPDATA%\anvil-cli\Config\config.json`
189
255
 
190
- ### Stored Configuration
191
-
192
- ```json
193
- {
194
- "authTokens": {
195
- "https://anvil.works": {
196
- "authToken": "your-access-token",
197
- "refreshToken": "your-refresh-token",
198
- "authTokenExpiresAt": 1234567890,
199
- "username": "user@example.com"
200
- },
201
- "https://anvil.company.com": {
202
- "authToken": "another-token",
203
- "refreshToken": "another-refresh",
204
- "authTokenExpiresAt": 1234567890,
205
- "username": "user@company.com"
206
- }
207
- },
208
- "anvilUrl": "https://anvil.works",
209
- "verbose": false
210
- }
211
- ```
212
-
213
- **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.
256
+ ### Stored Configuration
257
+
258
+ `config.json` stores settings and auth metadata. OAuth secrets are stored in the
259
+ OS keychain when available.
260
+
261
+ ```json
262
+ {
263
+ "anvilUrl": "https://anvil.works",
264
+ "verbose": false,
265
+ "preferredEditor": "cursor",
266
+ "authTokens": {
267
+ "https://anvil.works": {
268
+ "user@example.com": {
269
+ "authToken": null,
270
+ "refreshToken": null,
271
+ "authTokenExpiresAt": 1735689600
272
+ }
273
+ }
274
+ }
275
+ }
276
+ ```
277
+
278
+ If keychain is unavailable (for example some CI/headless environments), tokens
279
+ fall back to `config.json`.
214
280
 
215
281
  ### Verbose Logging
216
282
 
@@ -222,13 +288,25 @@ By default, anvil-cli shows minimal output. For more detailed logging:
222
288
  anvil watch --verbose
223
289
  ```
224
290
 
225
- **Persistent:** Set verbose mode in config:
291
+ **Persistent:** Set verbose mode in config:
226
292
 
227
293
  ```bash
228
- anvil config set verbose true
229
- ```
294
+ anvil config set verbose true
295
+ ```
296
+
297
+ ### Preferred Editor
298
+
299
+ Set this during `anvil onboard`.
300
+
301
+ If needed later, you can still set it manually with:
302
+
303
+ ```bash
304
+ anvil config set preferredEditor <editor>
305
+ ```
306
+
307
+ `preferredEditor` is used by checkout for post-checkout guidance and `-O/--open`.
230
308
 
231
- Verbose output is prefixed with `[VERBOSE]` and includes file routing details, sync status checks, and other internal processing information.
309
+ Verbose output includes timestamped diagnostic lines with file routing details, sync status checks, and other internal processing information.
232
310
 
233
311
  ### Enterprise Configuration
234
312
 
@@ -348,7 +426,7 @@ anvil login https://anvil.mycompany.com
348
426
  anvil config set anvilUrl https://anvil.works
349
427
  ```
350
428
 
351
- - Or reset all config values (also clears custom URLs):
429
+ - Or reset all config values (also clears custom URLs and logs out all accounts):
352
430
 
353
431
  ```bash
354
432
  anvil config reset
@@ -356,4 +434,4 @@ anvil login https://anvil.mycompany.com
356
434
 
357
435
  ## License
358
436
 
359
- ISC
437
+ MIT