@hapico/cli 0.0.10 → 0.0.12
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 +34 -17
- package/dist/index.js +34 -17
- package/index.ts +41 -18
- package/package.json +2 -1
package/bin/index.js
CHANGED
|
@@ -48,16 +48,21 @@ const ws_1 = require("ws");
|
|
|
48
48
|
const Babel = __importStar(require("@babel/standalone"));
|
|
49
49
|
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
50
50
|
const open_1 = __importDefault(require("open"));
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
51
52
|
// Directory to store the token and project config
|
|
52
53
|
const CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".hapico");
|
|
53
54
|
const TOKEN_FILE = path.join(CONFIG_DIR, "auth_token.json");
|
|
55
|
+
const connected = (0, ora_1.default)("Connected to WebSocket server");
|
|
54
56
|
// Ensure config directory exists
|
|
55
57
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
56
58
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
57
59
|
}
|
|
58
60
|
// Function to save token
|
|
59
|
-
const saveToken = (
|
|
60
|
-
|
|
61
|
+
const saveToken = (tokens) => {
|
|
62
|
+
if (!tokens || !tokens.accessToken) {
|
|
63
|
+
throw new Error("Invalid token data");
|
|
64
|
+
}
|
|
65
|
+
fs.writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), {
|
|
61
66
|
encoding: "utf8",
|
|
62
67
|
});
|
|
63
68
|
};
|
|
@@ -66,9 +71,15 @@ const getStoredToken = () => {
|
|
|
66
71
|
if (fs.existsSync(TOKEN_FILE)) {
|
|
67
72
|
const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
|
|
68
73
|
const json = JSON.parse(data);
|
|
69
|
-
return json
|
|
74
|
+
return json !== null && json !== void 0 ? json : {
|
|
75
|
+
accessToken: null,
|
|
76
|
+
refreshToken: null,
|
|
77
|
+
};
|
|
70
78
|
}
|
|
71
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
accessToken: null,
|
|
81
|
+
refreshToken: null,
|
|
82
|
+
};
|
|
72
83
|
};
|
|
73
84
|
// Function to save project ID
|
|
74
85
|
const saveProjectId = (projectDir, id) => {
|
|
@@ -235,13 +246,13 @@ class RoomState {
|
|
|
235
246
|
this.isConnected = true;
|
|
236
247
|
this.reconnectAttempts = 0;
|
|
237
248
|
onConnected === null || onConnected === void 0 ? void 0 : onConnected();
|
|
249
|
+
connected.succeed(`Connected to WebSocket server`);
|
|
238
250
|
});
|
|
239
251
|
this.ws.on("close", () => {
|
|
240
252
|
this.isConnected = false;
|
|
241
253
|
this.reconnectAttempts++;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.reconnectTimeout = setTimeout(() => this.connect(), delay);
|
|
254
|
+
connected.start(`Retry connection...`);
|
|
255
|
+
this.connect();
|
|
245
256
|
});
|
|
246
257
|
this.ws.on("message", (data) => {
|
|
247
258
|
try {
|
|
@@ -289,13 +300,13 @@ class RoomState {
|
|
|
289
300
|
return this.isConnected;
|
|
290
301
|
}
|
|
291
302
|
}
|
|
292
|
-
commander_1.program.version("0.0.
|
|
303
|
+
commander_1.program.version("0.0.12").description("Hapico CLI for project management");
|
|
293
304
|
commander_1.program
|
|
294
305
|
.command("clone <id>")
|
|
295
306
|
.description("Clone a project by ID")
|
|
296
307
|
.action(async (id) => {
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
308
|
+
const { accessToken } = getStoredToken();
|
|
309
|
+
if (!accessToken) {
|
|
299
310
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
300
311
|
return;
|
|
301
312
|
}
|
|
@@ -350,8 +361,8 @@ commander_1.program
|
|
|
350
361
|
.command("dev")
|
|
351
362
|
.description("Start the project in development mode")
|
|
352
363
|
.action(() => {
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
364
|
+
const { accessToken } = getStoredToken();
|
|
365
|
+
if (!accessToken) {
|
|
355
366
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
356
367
|
return;
|
|
357
368
|
}
|
|
@@ -362,12 +373,16 @@ commander_1.program
|
|
|
362
373
|
devSpinner.fail("Source directory 'src' does not exist. Please clone a project first.");
|
|
363
374
|
return;
|
|
364
375
|
}
|
|
365
|
-
const projectId =
|
|
376
|
+
const projectId = JSON.stringify({
|
|
377
|
+
id: (0, crypto_1.randomUUID)(),
|
|
378
|
+
createdAt: new Date().toISOString(),
|
|
379
|
+
viewId: getStoredProjectId(pwd),
|
|
380
|
+
});
|
|
366
381
|
if (!projectId) {
|
|
367
382
|
devSpinner.fail("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
|
|
368
383
|
return;
|
|
369
384
|
}
|
|
370
|
-
console.log(`Connecting to WebSocket server
|
|
385
|
+
console.log(`Connecting to WebSocket server`);
|
|
371
386
|
const room = new RoomState(`view_${projectId}`);
|
|
372
387
|
room.connect(async () => {
|
|
373
388
|
devSpinner.succeed("Project started in development mode!");
|
|
@@ -395,8 +410,9 @@ commander_1.program
|
|
|
395
410
|
.command("push")
|
|
396
411
|
.description("Push the project source code to the server")
|
|
397
412
|
.action(() => {
|
|
398
|
-
const
|
|
399
|
-
|
|
413
|
+
const data = getStoredToken();
|
|
414
|
+
const { accessToken } = data || {};
|
|
415
|
+
if (!accessToken) {
|
|
400
416
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
401
417
|
return;
|
|
402
418
|
}
|
|
@@ -422,7 +438,7 @@ commander_1.program
|
|
|
422
438
|
}),
|
|
423
439
|
}, {
|
|
424
440
|
headers: {
|
|
425
|
-
Authorization: `Bearer ${
|
|
441
|
+
Authorization: `Bearer ${accessToken}`,
|
|
426
442
|
"Content-Type": "application/json",
|
|
427
443
|
},
|
|
428
444
|
})
|
|
@@ -437,6 +453,7 @@ commander_1.program
|
|
|
437
453
|
.command("login")
|
|
438
454
|
.description("Login to the system")
|
|
439
455
|
.action(async () => {
|
|
456
|
+
console.log("Logging in to the system...");
|
|
440
457
|
const loginSpinner = (0, ora_1.default)("Initiating login...").start();
|
|
441
458
|
try {
|
|
442
459
|
const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
|
package/dist/index.js
CHANGED
|
@@ -48,16 +48,21 @@ const ws_1 = require("ws");
|
|
|
48
48
|
const Babel = __importStar(require("@babel/standalone"));
|
|
49
49
|
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
50
50
|
const open_1 = __importDefault(require("open"));
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
51
52
|
// Directory to store the token and project config
|
|
52
53
|
const CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".hapico");
|
|
53
54
|
const TOKEN_FILE = path.join(CONFIG_DIR, "auth_token.json");
|
|
55
|
+
const connected = (0, ora_1.default)("Connected to WebSocket server");
|
|
54
56
|
// Ensure config directory exists
|
|
55
57
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
56
58
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
57
59
|
}
|
|
58
60
|
// Function to save token
|
|
59
|
-
const saveToken = (
|
|
60
|
-
|
|
61
|
+
const saveToken = (tokens) => {
|
|
62
|
+
if (!tokens || !tokens.accessToken) {
|
|
63
|
+
throw new Error("Invalid token data");
|
|
64
|
+
}
|
|
65
|
+
fs.writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), {
|
|
61
66
|
encoding: "utf8",
|
|
62
67
|
});
|
|
63
68
|
};
|
|
@@ -66,9 +71,15 @@ const getStoredToken = () => {
|
|
|
66
71
|
if (fs.existsSync(TOKEN_FILE)) {
|
|
67
72
|
const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
|
|
68
73
|
const json = JSON.parse(data);
|
|
69
|
-
return json
|
|
74
|
+
return json !== null && json !== void 0 ? json : {
|
|
75
|
+
accessToken: null,
|
|
76
|
+
refreshToken: null,
|
|
77
|
+
};
|
|
70
78
|
}
|
|
71
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
accessToken: null,
|
|
81
|
+
refreshToken: null,
|
|
82
|
+
};
|
|
72
83
|
};
|
|
73
84
|
// Function to save project ID
|
|
74
85
|
const saveProjectId = (projectDir, id) => {
|
|
@@ -235,13 +246,13 @@ class RoomState {
|
|
|
235
246
|
this.isConnected = true;
|
|
236
247
|
this.reconnectAttempts = 0;
|
|
237
248
|
onConnected === null || onConnected === void 0 ? void 0 : onConnected();
|
|
249
|
+
connected.succeed(`Connected to WebSocket server`);
|
|
238
250
|
});
|
|
239
251
|
this.ws.on("close", () => {
|
|
240
252
|
this.isConnected = false;
|
|
241
253
|
this.reconnectAttempts++;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.reconnectTimeout = setTimeout(() => this.connect(), delay);
|
|
254
|
+
connected.start(`Retry connection...`);
|
|
255
|
+
this.connect();
|
|
245
256
|
});
|
|
246
257
|
this.ws.on("message", (data) => {
|
|
247
258
|
try {
|
|
@@ -289,13 +300,13 @@ class RoomState {
|
|
|
289
300
|
return this.isConnected;
|
|
290
301
|
}
|
|
291
302
|
}
|
|
292
|
-
commander_1.program.version("0.0.
|
|
303
|
+
commander_1.program.version("0.0.12").description("Hapico CLI for project management");
|
|
293
304
|
commander_1.program
|
|
294
305
|
.command("clone <id>")
|
|
295
306
|
.description("Clone a project by ID")
|
|
296
307
|
.action(async (id) => {
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
308
|
+
const { accessToken } = getStoredToken();
|
|
309
|
+
if (!accessToken) {
|
|
299
310
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
300
311
|
return;
|
|
301
312
|
}
|
|
@@ -350,8 +361,8 @@ commander_1.program
|
|
|
350
361
|
.command("dev")
|
|
351
362
|
.description("Start the project in development mode")
|
|
352
363
|
.action(() => {
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
364
|
+
const { accessToken } = getStoredToken();
|
|
365
|
+
if (!accessToken) {
|
|
355
366
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
356
367
|
return;
|
|
357
368
|
}
|
|
@@ -362,12 +373,16 @@ commander_1.program
|
|
|
362
373
|
devSpinner.fail("Source directory 'src' does not exist. Please clone a project first.");
|
|
363
374
|
return;
|
|
364
375
|
}
|
|
365
|
-
const projectId =
|
|
376
|
+
const projectId = JSON.stringify({
|
|
377
|
+
id: (0, crypto_1.randomUUID)(),
|
|
378
|
+
createdAt: new Date().toISOString(),
|
|
379
|
+
viewId: getStoredProjectId(pwd),
|
|
380
|
+
});
|
|
366
381
|
if (!projectId) {
|
|
367
382
|
devSpinner.fail("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
|
|
368
383
|
return;
|
|
369
384
|
}
|
|
370
|
-
console.log(`Connecting to WebSocket server
|
|
385
|
+
console.log(`Connecting to WebSocket server`);
|
|
371
386
|
const room = new RoomState(`view_${projectId}`);
|
|
372
387
|
room.connect(async () => {
|
|
373
388
|
devSpinner.succeed("Project started in development mode!");
|
|
@@ -395,8 +410,9 @@ commander_1.program
|
|
|
395
410
|
.command("push")
|
|
396
411
|
.description("Push the project source code to the server")
|
|
397
412
|
.action(() => {
|
|
398
|
-
const
|
|
399
|
-
|
|
413
|
+
const data = getStoredToken();
|
|
414
|
+
const { accessToken } = data || {};
|
|
415
|
+
if (!accessToken) {
|
|
400
416
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
401
417
|
return;
|
|
402
418
|
}
|
|
@@ -422,7 +438,7 @@ commander_1.program
|
|
|
422
438
|
}),
|
|
423
439
|
}, {
|
|
424
440
|
headers: {
|
|
425
|
-
Authorization: `Bearer ${
|
|
441
|
+
Authorization: `Bearer ${accessToken}`,
|
|
426
442
|
"Content-Type": "application/json",
|
|
427
443
|
},
|
|
428
444
|
})
|
|
@@ -437,6 +453,7 @@ commander_1.program
|
|
|
437
453
|
.command("login")
|
|
438
454
|
.description("Login to the system")
|
|
439
455
|
.action(async () => {
|
|
456
|
+
console.log("Logging in to the system...");
|
|
440
457
|
const loginSpinner = (0, ora_1.default)("Initiating login...").start();
|
|
441
458
|
try {
|
|
442
459
|
const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
|
package/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { WebSocket } from "ws";
|
|
|
10
10
|
import * as Babel from "@babel/standalone";
|
|
11
11
|
import QRCode from "qrcode-terminal";
|
|
12
12
|
import open from "open";
|
|
13
|
+
import { randomUUID } from "crypto";
|
|
13
14
|
|
|
14
15
|
// Directory to store the token and project config
|
|
15
16
|
const CONFIG_DIR = path.join(
|
|
@@ -18,16 +19,21 @@ const CONFIG_DIR = path.join(
|
|
|
18
19
|
);
|
|
19
20
|
const TOKEN_FILE = path.join(CONFIG_DIR, "auth_token.json");
|
|
20
21
|
|
|
22
|
+
const connected = ora("Connected to WebSocket server");
|
|
23
|
+
|
|
21
24
|
// Ensure config directory exists
|
|
22
25
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
23
26
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
// Function to save token
|
|
27
|
-
const saveToken = (
|
|
30
|
+
const saveToken = (tokens: { accessToken: string; refreshToken?: string }) => {
|
|
31
|
+
if (!tokens || !tokens.accessToken) {
|
|
32
|
+
throw new Error("Invalid token data");
|
|
33
|
+
}
|
|
28
34
|
fs.writeFileSync(
|
|
29
35
|
TOKEN_FILE,
|
|
30
|
-
JSON.stringify(
|
|
36
|
+
JSON.stringify(tokens, null, 2),
|
|
31
37
|
{
|
|
32
38
|
encoding: "utf8",
|
|
33
39
|
}
|
|
@@ -35,13 +41,22 @@ const saveToken = (token: string) => {
|
|
|
35
41
|
};
|
|
36
42
|
|
|
37
43
|
// Function to get stored token
|
|
38
|
-
const getStoredToken = ():
|
|
44
|
+
const getStoredToken = (): {
|
|
45
|
+
accessToken: string | null;
|
|
46
|
+
refreshToken: string | null;
|
|
47
|
+
} => {
|
|
39
48
|
if (fs.existsSync(TOKEN_FILE)) {
|
|
40
49
|
const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
|
|
41
50
|
const json = JSON.parse(data);
|
|
42
|
-
return json
|
|
51
|
+
return json ?? {
|
|
52
|
+
accessToken: null,
|
|
53
|
+
refreshToken: null,
|
|
54
|
+
};
|
|
43
55
|
}
|
|
44
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
accessToken: null,
|
|
58
|
+
refreshToken: null,
|
|
59
|
+
};
|
|
45
60
|
};
|
|
46
61
|
|
|
47
62
|
// Function to save project ID
|
|
@@ -270,16 +285,18 @@ class RoomState {
|
|
|
270
285
|
this.isConnected = true;
|
|
271
286
|
this.reconnectAttempts = 0;
|
|
272
287
|
onConnected?.();
|
|
288
|
+
connected.succeed(`Connected to WebSocket server`);
|
|
273
289
|
});
|
|
274
290
|
|
|
275
291
|
this.ws.on("close", () => {
|
|
276
292
|
this.isConnected = false;
|
|
277
293
|
|
|
278
294
|
this.reconnectAttempts++;
|
|
279
|
-
|
|
280
|
-
|
|
295
|
+
connected.start(
|
|
296
|
+
`Retry connection...`
|
|
297
|
+
);
|
|
281
298
|
|
|
282
|
-
this.
|
|
299
|
+
this.connect();
|
|
283
300
|
});
|
|
284
301
|
|
|
285
302
|
this.ws.on("message", (data: Buffer) => {
|
|
@@ -333,14 +350,14 @@ class RoomState {
|
|
|
333
350
|
}
|
|
334
351
|
}
|
|
335
352
|
|
|
336
|
-
program.version("0.0.
|
|
353
|
+
program.version("0.0.12").description("Hapico CLI for project management");
|
|
337
354
|
|
|
338
355
|
program
|
|
339
356
|
.command("clone <id>")
|
|
340
357
|
.description("Clone a project by ID")
|
|
341
358
|
.action(async (id: string) => {
|
|
342
|
-
const
|
|
343
|
-
if (!
|
|
359
|
+
const { accessToken } = getStoredToken();
|
|
360
|
+
if (!accessToken) {
|
|
344
361
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
345
362
|
return;
|
|
346
363
|
}
|
|
@@ -413,8 +430,8 @@ program
|
|
|
413
430
|
.command("dev")
|
|
414
431
|
.description("Start the project in development mode")
|
|
415
432
|
.action(() => {
|
|
416
|
-
const
|
|
417
|
-
if (!
|
|
433
|
+
const { accessToken } = getStoredToken();
|
|
434
|
+
if (!accessToken) {
|
|
418
435
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
419
436
|
return;
|
|
420
437
|
}
|
|
@@ -429,14 +446,18 @@ program
|
|
|
429
446
|
);
|
|
430
447
|
return;
|
|
431
448
|
}
|
|
432
|
-
const projectId =
|
|
449
|
+
const projectId = JSON.stringify({
|
|
450
|
+
id: randomUUID(),
|
|
451
|
+
createdAt: new Date().toISOString(),
|
|
452
|
+
viewId: getStoredProjectId(pwd),
|
|
453
|
+
});
|
|
433
454
|
if (!projectId) {
|
|
434
455
|
devSpinner.fail(
|
|
435
456
|
"Project ID not found. Please ensure hapico.config.json exists in the project directory."
|
|
436
457
|
);
|
|
437
458
|
return;
|
|
438
459
|
}
|
|
439
|
-
console.log(`Connecting to WebSocket server
|
|
460
|
+
console.log(`Connecting to WebSocket server`);
|
|
440
461
|
const room = new RoomState(`view_${projectId}`);
|
|
441
462
|
|
|
442
463
|
room.connect(async () => {
|
|
@@ -474,8 +495,9 @@ program
|
|
|
474
495
|
.command("push")
|
|
475
496
|
.description("Push the project source code to the server")
|
|
476
497
|
.action(() => {
|
|
477
|
-
const
|
|
478
|
-
|
|
498
|
+
const data = getStoredToken();
|
|
499
|
+
const { accessToken } = data || {};
|
|
500
|
+
if (!accessToken) {
|
|
479
501
|
console.error("You need to login first. Use 'hapico login' command.");
|
|
480
502
|
return;
|
|
481
503
|
}
|
|
@@ -508,7 +530,7 @@ program
|
|
|
508
530
|
},
|
|
509
531
|
{
|
|
510
532
|
headers: {
|
|
511
|
-
Authorization: `Bearer ${
|
|
533
|
+
Authorization: `Bearer ${accessToken}`,
|
|
512
534
|
"Content-Type": "application/json",
|
|
513
535
|
},
|
|
514
536
|
}
|
|
@@ -525,6 +547,7 @@ program
|
|
|
525
547
|
.command("login")
|
|
526
548
|
.description("Login to the system")
|
|
527
549
|
.action(async () => {
|
|
550
|
+
console.log("Logging in to the system...");
|
|
528
551
|
const loginSpinner: Ora = ora("Initiating login...").start();
|
|
529
552
|
|
|
530
553
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hapico/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "A simple CLI tool for project management",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc && cp -r dist/* ./bin/",
|
|
11
11
|
"start": "node dist/index.js",
|
|
12
|
+
"dev": "npm run build && bun link @hapico/cli",
|
|
12
13
|
"pub": "npm run build && npm publish --access public"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|