@hapico/cli 0.0.9 → 0.0.10
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/bin/index.js +39 -16
- package/dist/index.js +39 -16
- package/index.ts +51 -19
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -47,6 +47,7 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
47
47
|
const ws_1 = require("ws");
|
|
48
48
|
const Babel = __importStar(require("@babel/standalone"));
|
|
49
49
|
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
50
|
+
const open_1 = __importDefault(require("open"));
|
|
50
51
|
// Directory to store the token and project config
|
|
51
52
|
const CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".hapico");
|
|
52
53
|
const TOKEN_FILE = path.join(CONFIG_DIR, "auth_token.json");
|
|
@@ -435,28 +436,50 @@ commander_1.program
|
|
|
435
436
|
commander_1.program
|
|
436
437
|
.command("login")
|
|
437
438
|
.description("Login to the system")
|
|
438
|
-
.action(() => {
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
439
|
+
.action(async () => {
|
|
440
|
+
const loginSpinner = (0, ora_1.default)("Initiating login...").start();
|
|
441
|
+
try {
|
|
442
|
+
const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
|
|
443
|
+
const { device_code, user_code, verification_url, expires_in, interval } = response.data;
|
|
444
|
+
loginSpinner.succeed("Login initiated!");
|
|
445
|
+
console.log(`Please open this URL in your browser: ${verification_url}`);
|
|
446
|
+
console.log(`And enter this code: ${user_code}`);
|
|
447
|
+
console.log("Waiting for authentication...");
|
|
448
|
+
await (0, open_1.default)(verification_url);
|
|
449
|
+
const pollSpinner = (0, ora_1.default)("Waiting for authentication...").start();
|
|
450
|
+
let tokens = null;
|
|
451
|
+
const startTime = Date.now();
|
|
452
|
+
while (Date.now() - startTime < expires_in * 1000) {
|
|
453
|
+
try {
|
|
454
|
+
const pollResponse = await axios_1.default.post("https://auth.myworkbeast.com/auth/device/poll", { device_code });
|
|
455
|
+
if (pollResponse.data.accessToken) {
|
|
456
|
+
tokens = pollResponse.data;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
// Ignore temporary errors and continue polling
|
|
462
|
+
}
|
|
463
|
+
await new Promise((resolve) => setTimeout(resolve, interval * 1000));
|
|
464
|
+
}
|
|
465
|
+
if (tokens) {
|
|
466
|
+
pollSpinner.succeed("Login successful!");
|
|
467
|
+
saveToken(tokens);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
pollSpinner.fail("Login failed: Timeout or user did not complete authentication.");
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
loginSpinner.fail(`Login error: ${error.message}`);
|
|
443
475
|
}
|
|
444
|
-
const readline = require("readline").createInterface({
|
|
445
|
-
input: process.stdin,
|
|
446
|
-
output: process.stdout,
|
|
447
|
-
});
|
|
448
|
-
readline.question("Please enter your token: ", (inputToken) => {
|
|
449
|
-
saveToken(inputToken);
|
|
450
|
-
console.log("Login successful!");
|
|
451
|
-
readline.close();
|
|
452
|
-
});
|
|
453
476
|
});
|
|
454
477
|
commander_1.program
|
|
455
478
|
.command("logout")
|
|
456
479
|
.description("Logout from the system")
|
|
457
480
|
.action(() => {
|
|
458
|
-
const
|
|
459
|
-
if (!
|
|
481
|
+
const accessToken = getStoredToken();
|
|
482
|
+
if (!accessToken) {
|
|
460
483
|
console.log("You are not logged in.");
|
|
461
484
|
return;
|
|
462
485
|
}
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
47
47
|
const ws_1 = require("ws");
|
|
48
48
|
const Babel = __importStar(require("@babel/standalone"));
|
|
49
49
|
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
50
|
+
const open_1 = __importDefault(require("open"));
|
|
50
51
|
// Directory to store the token and project config
|
|
51
52
|
const CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".hapico");
|
|
52
53
|
const TOKEN_FILE = path.join(CONFIG_DIR, "auth_token.json");
|
|
@@ -435,28 +436,50 @@ commander_1.program
|
|
|
435
436
|
commander_1.program
|
|
436
437
|
.command("login")
|
|
437
438
|
.description("Login to the system")
|
|
438
|
-
.action(() => {
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
439
|
+
.action(async () => {
|
|
440
|
+
const loginSpinner = (0, ora_1.default)("Initiating login...").start();
|
|
441
|
+
try {
|
|
442
|
+
const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
|
|
443
|
+
const { device_code, user_code, verification_url, expires_in, interval } = response.data;
|
|
444
|
+
loginSpinner.succeed("Login initiated!");
|
|
445
|
+
console.log(`Please open this URL in your browser: ${verification_url}`);
|
|
446
|
+
console.log(`And enter this code: ${user_code}`);
|
|
447
|
+
console.log("Waiting for authentication...");
|
|
448
|
+
await (0, open_1.default)(verification_url);
|
|
449
|
+
const pollSpinner = (0, ora_1.default)("Waiting for authentication...").start();
|
|
450
|
+
let tokens = null;
|
|
451
|
+
const startTime = Date.now();
|
|
452
|
+
while (Date.now() - startTime < expires_in * 1000) {
|
|
453
|
+
try {
|
|
454
|
+
const pollResponse = await axios_1.default.post("https://auth.myworkbeast.com/auth/device/poll", { device_code });
|
|
455
|
+
if (pollResponse.data.accessToken) {
|
|
456
|
+
tokens = pollResponse.data;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
// Ignore temporary errors and continue polling
|
|
462
|
+
}
|
|
463
|
+
await new Promise((resolve) => setTimeout(resolve, interval * 1000));
|
|
464
|
+
}
|
|
465
|
+
if (tokens) {
|
|
466
|
+
pollSpinner.succeed("Login successful!");
|
|
467
|
+
saveToken(tokens);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
pollSpinner.fail("Login failed: Timeout or user did not complete authentication.");
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
loginSpinner.fail(`Login error: ${error.message}`);
|
|
443
475
|
}
|
|
444
|
-
const readline = require("readline").createInterface({
|
|
445
|
-
input: process.stdin,
|
|
446
|
-
output: process.stdout,
|
|
447
|
-
});
|
|
448
|
-
readline.question("Please enter your token: ", (inputToken) => {
|
|
449
|
-
saveToken(inputToken);
|
|
450
|
-
console.log("Login successful!");
|
|
451
|
-
readline.close();
|
|
452
|
-
});
|
|
453
476
|
});
|
|
454
477
|
commander_1.program
|
|
455
478
|
.command("logout")
|
|
456
479
|
.description("Logout from the system")
|
|
457
480
|
.action(() => {
|
|
458
|
-
const
|
|
459
|
-
if (!
|
|
481
|
+
const accessToken = getStoredToken();
|
|
482
|
+
if (!accessToken) {
|
|
460
483
|
console.log("You are not logged in.");
|
|
461
484
|
return;
|
|
462
485
|
}
|
package/index.ts
CHANGED
|
@@ -146,7 +146,9 @@ class FileManager {
|
|
|
146
146
|
} else if (entry.isFile()) {
|
|
147
147
|
const content = fs.readFileSync(fullPath, { encoding: "utf8" });
|
|
148
148
|
files.push({
|
|
149
|
-
path: this.replaceSplashWithSeparator(
|
|
149
|
+
path: this.replaceSplashWithSeparator(
|
|
150
|
+
fullPath.replace(this.basePath + path.sep, "./")
|
|
151
|
+
),
|
|
150
152
|
content,
|
|
151
153
|
es5: compileES5(content, fullPath) ?? "",
|
|
152
154
|
});
|
|
@@ -522,37 +524,67 @@ program
|
|
|
522
524
|
program
|
|
523
525
|
.command("login")
|
|
524
526
|
.description("Login to the system")
|
|
525
|
-
.action(() => {
|
|
526
|
-
const
|
|
527
|
-
if (token) {
|
|
528
|
-
console.log("You are already logged in.");
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
const readline = require("readline").createInterface({
|
|
532
|
-
input: process.stdin,
|
|
533
|
-
output: process.stdout,
|
|
534
|
-
});
|
|
527
|
+
.action(async () => {
|
|
528
|
+
const loginSpinner: Ora = ora("Initiating login...").start();
|
|
535
529
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
530
|
+
try {
|
|
531
|
+
const response = await axios.post(
|
|
532
|
+
"https://auth.myworkbeast.com/auth/device"
|
|
533
|
+
);
|
|
534
|
+
const { device_code, user_code, verification_url, expires_in, interval } =
|
|
535
|
+
response.data;
|
|
536
|
+
|
|
537
|
+
loginSpinner.succeed("Login initiated!");
|
|
538
|
+
console.log(`Please open this URL in your browser: ${verification_url}`);
|
|
539
|
+
console.log(`And enter this code: ${user_code}`);
|
|
540
|
+
console.log("Waiting for authentication...");
|
|
541
|
+
|
|
542
|
+
await open(verification_url);
|
|
543
|
+
|
|
544
|
+
const pollSpinner: Ora = ora("Waiting for authentication...").start();
|
|
545
|
+
let tokens = null;
|
|
546
|
+
const startTime = Date.now();
|
|
547
|
+
while (Date.now() - startTime < expires_in * 1000) {
|
|
548
|
+
try {
|
|
549
|
+
const pollResponse = await axios.post(
|
|
550
|
+
"https://auth.myworkbeast.com/auth/device/poll",
|
|
551
|
+
{ device_code }
|
|
552
|
+
);
|
|
553
|
+
if (pollResponse.data.accessToken) {
|
|
554
|
+
tokens = pollResponse.data;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
} catch (error) {
|
|
558
|
+
// Ignore temporary errors and continue polling
|
|
559
|
+
}
|
|
560
|
+
await new Promise((resolve) => setTimeout(resolve, interval * 1000));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (tokens) {
|
|
564
|
+
pollSpinner.succeed("Login successful!");
|
|
565
|
+
saveToken(tokens);
|
|
566
|
+
} else {
|
|
567
|
+
pollSpinner.fail(
|
|
568
|
+
"Login failed: Timeout or user did not complete authentication."
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
} catch (error) {
|
|
572
|
+
loginSpinner.fail(`Login error: ${(error as Error).message}`);
|
|
573
|
+
}
|
|
541
574
|
});
|
|
542
575
|
|
|
543
576
|
program
|
|
544
577
|
.command("logout")
|
|
545
578
|
.description("Logout from the system")
|
|
546
579
|
.action(() => {
|
|
547
|
-
const
|
|
548
|
-
if (!
|
|
580
|
+
const accessToken = getStoredToken();
|
|
581
|
+
if (!accessToken) {
|
|
549
582
|
console.log("You are not logged in.");
|
|
550
583
|
return;
|
|
551
584
|
}
|
|
552
585
|
fs.unlinkSync(TOKEN_FILE);
|
|
553
586
|
console.log("Logout successful!");
|
|
554
587
|
});
|
|
555
|
-
|
|
556
588
|
// Pull command to fetch the latest project files from the server
|
|
557
589
|
program
|
|
558
590
|
.command("pull")
|