@leeguoo/wrangler-accounts 0.1.1 → 0.1.3
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 +2 -0
- package/bin/wrangler-accounts.js +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ node bin/wrangler-accounts.js <command>
|
|
|
34
34
|
```bash
|
|
35
35
|
wrangler-accounts list
|
|
36
36
|
wrangler-accounts status
|
|
37
|
+
wrangler-accounts login work
|
|
37
38
|
wrangler-accounts save work
|
|
38
39
|
wrangler-accounts use personal
|
|
39
40
|
wrangler-accounts remove old
|
|
@@ -74,3 +75,4 @@ The profiles directory defaults to:
|
|
|
74
75
|
|
|
75
76
|
- Profile names accept only letters, numbers, dot, underscore, and dash.
|
|
76
77
|
- On `use`, the current config is backed up into `__backup-YYYYMMDD-HHMMSS` unless you pass `--no-backup`.
|
|
78
|
+
- `login <name>` overwrites an existing profile with the same name.
|
package/bin/wrangler-accounts.js
CHANGED
|
@@ -5,6 +5,7 @@ const fs = require("fs");
|
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
const crypto = require("crypto");
|
|
8
|
+
const { spawnSync } = require("child_process");
|
|
8
9
|
|
|
9
10
|
function die(message) {
|
|
10
11
|
console.error(`Error: ${message}`);
|
|
@@ -20,6 +21,7 @@ Usage:
|
|
|
20
21
|
Commands:
|
|
21
22
|
list
|
|
22
23
|
status
|
|
24
|
+
login <name>
|
|
23
25
|
save <name>
|
|
24
26
|
use <name>
|
|
25
27
|
remove <name>
|
|
@@ -233,6 +235,16 @@ function saveProfile(name, configPath, profilesDir, force) {
|
|
|
233
235
|
writeMeta(profileDir, name, configPath);
|
|
234
236
|
}
|
|
235
237
|
|
|
238
|
+
function runWranglerLogin() {
|
|
239
|
+
const result = spawnSync("wrangler", ["login"], { stdio: "inherit" });
|
|
240
|
+
if (result.error) {
|
|
241
|
+
die(`Failed to run 'wrangler login': ${result.error.message}`);
|
|
242
|
+
}
|
|
243
|
+
if (result.status !== 0) {
|
|
244
|
+
die(`'wrangler login' exited with code ${result.status}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
236
248
|
function useProfile(name, configPath, profilesDir, backup) {
|
|
237
249
|
if (!isValidName(name)) {
|
|
238
250
|
die(`Invalid profile name: ${name}`);
|
|
@@ -330,6 +342,22 @@ function main() {
|
|
|
330
342
|
return;
|
|
331
343
|
}
|
|
332
344
|
|
|
345
|
+
if (command === "login") {
|
|
346
|
+
const name = rest[1];
|
|
347
|
+
if (!name) die("Missing profile name for login");
|
|
348
|
+
ensureDir(profilesDir);
|
|
349
|
+
runWranglerLogin();
|
|
350
|
+
if (!fs.existsSync(configPath)) {
|
|
351
|
+
die(`Config file not found after login: ${configPath}`);
|
|
352
|
+
}
|
|
353
|
+
const profileDir = path.join(profilesDir, name);
|
|
354
|
+
const existed = fs.existsSync(profileDir);
|
|
355
|
+
saveProfile(name, configPath, profilesDir, true);
|
|
356
|
+
const note = existed ? " (overwritten)" : "";
|
|
357
|
+
console.log(`Logged in and saved profile '${name}' from ${configPath}${note}`);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
333
361
|
if (command === "use") {
|
|
334
362
|
const name = rest[1];
|
|
335
363
|
if (!name) die("Missing profile name for use");
|