@leeguoo/wrangler-accounts 0.1.1 → 0.1.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 +1 -0
- package/bin/wrangler-accounts.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
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,19 @@ 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
|
+
saveProfile(name, configPath, profilesDir, opts.force);
|
|
354
|
+
console.log(`Logged in and saved profile '${name}' from ${configPath}`);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
333
358
|
if (command === "use") {
|
|
334
359
|
const name = rest[1];
|
|
335
360
|
if (!name) die("Missing profile name for use");
|