@hapico/cli 0.0.12 → 0.0.13

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 CHANGED
@@ -71,10 +71,10 @@ const getStoredToken = () => {
71
71
  if (fs.existsSync(TOKEN_FILE)) {
72
72
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
73
73
  const json = JSON.parse(data);
74
- return json !== null && json !== void 0 ? json : {
74
+ return (json !== null && json !== void 0 ? json : {
75
75
  accessToken: null,
76
76
  refreshToken: null,
77
- };
77
+ });
78
78
  }
79
79
  return {
80
80
  accessToken: null,
@@ -300,7 +300,7 @@ class RoomState {
300
300
  return this.isConnected;
301
301
  }
302
302
  }
303
- commander_1.program.version("0.0.12").description("Hapico CLI for project management");
303
+ commander_1.program.version("0.0.13").description("Hapico CLI for project management");
304
304
  commander_1.program
305
305
  .command("clone <id>")
306
306
  .description("Clone a project by ID")
@@ -373,11 +373,13 @@ commander_1.program
373
373
  devSpinner.fail("Source directory 'src' does not exist. Please clone a project first.");
374
374
  return;
375
375
  }
376
- const projectId = JSON.stringify({
376
+ const info = JSON.stringify({
377
377
  id: (0, crypto_1.randomUUID)(),
378
378
  createdAt: new Date().toISOString(),
379
379
  viewId: getStoredProjectId(pwd),
380
380
  });
381
+ // convert info info to base64
382
+ const projectId = Buffer.from(info).toString("base64");
381
383
  if (!projectId) {
382
384
  devSpinner.fail("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
383
385
  return;
@@ -400,10 +402,37 @@ commander_1.program
400
402
  });
401
403
  room.updateState("view", updatedView);
402
404
  });
403
- qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
404
- console.log("Scan this QR code to connect to the project:");
405
- console.log(qrcode);
405
+ // LẤy thông tin về project
406
+ const projectInfo = getStoredProjectId(pwd);
407
+ if (!projectInfo) {
408
+ console.error("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
409
+ return;
410
+ }
411
+ const project = await axios_1.default.get(`https://base.myworkbeast.com/api/views/${projectInfo}`, {
412
+ headers: {
413
+ Authorization: `Bearer ${accessToken}`,
414
+ "Content-Type": "application/json",
415
+ },
406
416
  });
417
+ if (project.status !== 200) {
418
+ console.error(`Error fetching project info: ${project.statusText}`);
419
+ return;
420
+ }
421
+ const projectType = project.data.type || "view";
422
+ console.log("Project type:", projectType);
423
+ if (projectType === "zalominiapp") {
424
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
425
+ console.log("Scan this QR code to connect to the project:");
426
+ console.log(qrcode);
427
+ });
428
+ return;
429
+ }
430
+ else {
431
+ // show link https://com.ai.vn/dev_preview/{projectId}
432
+ const previewUrl = `https://com.ai.vn/dev_preview/${projectId}`;
433
+ console.log(`Open this URL in your browser to preview the project: \n${previewUrl}`);
434
+ await (0, open_1.default)(previewUrl);
435
+ }
407
436
  });
408
437
  });
409
438
  commander_1.program
package/dist/index.js CHANGED
@@ -71,10 +71,10 @@ const getStoredToken = () => {
71
71
  if (fs.existsSync(TOKEN_FILE)) {
72
72
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
73
73
  const json = JSON.parse(data);
74
- return json !== null && json !== void 0 ? json : {
74
+ return (json !== null && json !== void 0 ? json : {
75
75
  accessToken: null,
76
76
  refreshToken: null,
77
- };
77
+ });
78
78
  }
79
79
  return {
80
80
  accessToken: null,
@@ -300,7 +300,7 @@ class RoomState {
300
300
  return this.isConnected;
301
301
  }
302
302
  }
303
- commander_1.program.version("0.0.12").description("Hapico CLI for project management");
303
+ commander_1.program.version("0.0.13").description("Hapico CLI for project management");
304
304
  commander_1.program
305
305
  .command("clone <id>")
306
306
  .description("Clone a project by ID")
@@ -373,11 +373,13 @@ commander_1.program
373
373
  devSpinner.fail("Source directory 'src' does not exist. Please clone a project first.");
374
374
  return;
375
375
  }
376
- const projectId = JSON.stringify({
376
+ const info = JSON.stringify({
377
377
  id: (0, crypto_1.randomUUID)(),
378
378
  createdAt: new Date().toISOString(),
379
379
  viewId: getStoredProjectId(pwd),
380
380
  });
381
+ // convert info info to base64
382
+ const projectId = Buffer.from(info).toString("base64");
381
383
  if (!projectId) {
382
384
  devSpinner.fail("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
383
385
  return;
@@ -400,10 +402,37 @@ commander_1.program
400
402
  });
401
403
  room.updateState("view", updatedView);
402
404
  });
403
- qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
404
- console.log("Scan this QR code to connect to the project:");
405
- console.log(qrcode);
405
+ // LẤy thông tin về project
406
+ const projectInfo = getStoredProjectId(pwd);
407
+ if (!projectInfo) {
408
+ console.error("Project ID not found. Please ensure hapico.config.json exists in the project directory.");
409
+ return;
410
+ }
411
+ const project = await axios_1.default.get(`https://base.myworkbeast.com/api/views/${projectInfo}`, {
412
+ headers: {
413
+ Authorization: `Bearer ${accessToken}`,
414
+ "Content-Type": "application/json",
415
+ },
406
416
  });
417
+ if (project.status !== 200) {
418
+ console.error(`Error fetching project info: ${project.statusText}`);
419
+ return;
420
+ }
421
+ const projectType = project.data.type || "view";
422
+ console.log("Project type:", projectType);
423
+ if (projectType === "zalominiapp") {
424
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
425
+ console.log("Scan this QR code to connect to the project:");
426
+ console.log(qrcode);
427
+ });
428
+ return;
429
+ }
430
+ else {
431
+ // show link https://com.ai.vn/dev_preview/{projectId}
432
+ const previewUrl = `https://com.ai.vn/dev_preview/${projectId}`;
433
+ console.log(`Open this URL in your browser to preview the project: \n${previewUrl}`);
434
+ await (0, open_1.default)(previewUrl);
435
+ }
407
436
  });
408
437
  });
409
438
  commander_1.program
package/index.ts CHANGED
@@ -31,13 +31,9 @@ const saveToken = (tokens: { accessToken: string; refreshToken?: string }) => {
31
31
  if (!tokens || !tokens.accessToken) {
32
32
  throw new Error("Invalid token data");
33
33
  }
34
- fs.writeFileSync(
35
- TOKEN_FILE,
36
- JSON.stringify(tokens, null, 2),
37
- {
38
- encoding: "utf8",
39
- }
40
- );
34
+ fs.writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), {
35
+ encoding: "utf8",
36
+ });
41
37
  };
42
38
 
43
39
  // Function to get stored token
@@ -48,10 +44,12 @@ const getStoredToken = (): {
48
44
  if (fs.existsSync(TOKEN_FILE)) {
49
45
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
50
46
  const json = JSON.parse(data);
51
- return json ?? {
52
- accessToken: null,
53
- refreshToken: null,
54
- };
47
+ return (
48
+ json ?? {
49
+ accessToken: null,
50
+ refreshToken: null,
51
+ }
52
+ );
55
53
  }
56
54
  return {
57
55
  accessToken: null,
@@ -292,9 +290,7 @@ class RoomState {
292
290
  this.isConnected = false;
293
291
 
294
292
  this.reconnectAttempts++;
295
- connected.start(
296
- `Retry connection...`
297
- );
293
+ connected.start(`Retry connection...`);
298
294
 
299
295
  this.connect();
300
296
  });
@@ -350,7 +346,7 @@ class RoomState {
350
346
  }
351
347
  }
352
348
 
353
- program.version("0.0.12").description("Hapico CLI for project management");
349
+ program.version("0.0.13").description("Hapico CLI for project management");
354
350
 
355
351
  program
356
352
  .command("clone <id>")
@@ -446,11 +442,13 @@ program
446
442
  );
447
443
  return;
448
444
  }
449
- const projectId = JSON.stringify({
445
+ const info = JSON.stringify({
450
446
  id: randomUUID(),
451
447
  createdAt: new Date().toISOString(),
452
448
  viewId: getStoredProjectId(pwd),
453
449
  });
450
+ // convert info info to base64
451
+ const projectId = Buffer.from(info).toString("base64");
454
452
  if (!projectId) {
455
453
  devSpinner.fail(
456
454
  "Project ID not found. Please ensure hapico.config.json exists in the project directory."
@@ -480,14 +478,51 @@ program
480
478
  room.updateState("view", updatedView);
481
479
  });
482
480
 
483
- QRCode.generate(
484
- `https://zalo.me/s/3218692650896662017/player/${projectId}`,
485
- { small: true },
486
- (qrcode: string) => {
487
- console.log("Scan this QR code to connect to the project:");
488
- console.log(qrcode);
481
+ // LẤy thông tin về project
482
+ const projectInfo = getStoredProjectId(pwd);
483
+ if (!projectInfo) {
484
+ console.error(
485
+ "Project ID not found. Please ensure hapico.config.json exists in the project directory."
486
+ );
487
+ return;
488
+ }
489
+ const project = await axios.get(
490
+ `https://base.myworkbeast.com/api/views/${projectInfo}`,
491
+ {
492
+ headers: {
493
+ Authorization: `Bearer ${accessToken}`,
494
+ "Content-Type": "application/json",
495
+ },
489
496
  }
490
497
  );
498
+
499
+ if (project.status !== 200) {
500
+ console.error(`Error fetching project info: ${project.statusText}`);
501
+ return;
502
+ }
503
+
504
+ const projectType = project.data.type || "view";
505
+
506
+ console.log("Project type:", projectType);
507
+
508
+ if (projectType === "zalominiapp") {
509
+ QRCode.generate(
510
+ `https://zalo.me/s/3218692650896662017/player/${projectId}`,
511
+ { small: true },
512
+ (qrcode: string) => {
513
+ console.log("Scan this QR code to connect to the project:");
514
+ console.log(qrcode);
515
+ }
516
+ );
517
+ return;
518
+ } else {
519
+ // show link https://com.ai.vn/dev_preview/{projectId}
520
+ const previewUrl = `https://com.ai.vn/dev_preview/${projectId}`;
521
+ console.log(
522
+ `Open this URL in your browser to preview the project: \n${previewUrl}`
523
+ );
524
+ await open(previewUrl);
525
+ }
491
526
  });
492
527
  });
493
528
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hapico/cli",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "A simple CLI tool for project management",
5
5
  "main": "index.js",
6
6
  "bin": {