@hapico/cli 0.0.20 → 0.0.22
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 +35 -5
- package/dist/index.js +35 -5
- package/index.ts +52 -7
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -371,12 +371,12 @@ class RoomState {
|
|
|
371
371
|
return this.isConnected;
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
commander_1.program.version("0.0.
|
|
374
|
+
commander_1.program.version("0.0.22").description("Hapico CLI for project management");
|
|
375
375
|
commander_1.program
|
|
376
376
|
.command("clone <id>")
|
|
377
377
|
.description("Clone a project by ID")
|
|
378
378
|
.action(async (id) => {
|
|
379
|
-
var _a, _b;
|
|
379
|
+
var _a, _b, _c, _d;
|
|
380
380
|
const { accessToken } = getStoredToken();
|
|
381
381
|
if (!accessToken) {
|
|
382
382
|
console.error(chalk_1.default.red("✗ You need to login first. Use 'hapico login' command."));
|
|
@@ -390,11 +390,13 @@ commander_1.program
|
|
|
390
390
|
let files = [];
|
|
391
391
|
const apiSpinner = (0, ora_1.default)(chalk_1.default.blue("Fetching project data...")).start();
|
|
392
392
|
try {
|
|
393
|
+
// ===== 1. Lấy version public/published (giữ nguyên như cũ) =====
|
|
393
394
|
const response = await axios_1.default.get(`https://base.myworkbeast.com/api/views/${id}`);
|
|
394
395
|
const code = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.code;
|
|
395
396
|
const decompressedCode = pako_1.default.inflate(Uint8Array.from(atob(code), (c) => c.charCodeAt(0)), { to: "string" });
|
|
396
397
|
files = ((_b = (0, exports.tryJSONParse)(decompressedCode)) === null || _b === void 0 ? void 0 : _b.files) || [];
|
|
397
398
|
apiSpinner.succeed(chalk_1.default.green("Project data fetched successfully!"));
|
|
399
|
+
// ===== 2. Download + extract template =====
|
|
398
400
|
const templateSpinner = (0, ora_1.default)(chalk_1.default.blue("Downloading template...")).start();
|
|
399
401
|
const TEMPLATE_URL = "https://files.hcm04.vstorage.vngcloud.vn/assets/template_zalominiapp_devmode.zip";
|
|
400
402
|
const templateResponse = await axios_1.default.get(TEMPLATE_URL, {
|
|
@@ -412,9 +414,10 @@ commander_1.program
|
|
|
412
414
|
if (fs.existsSync(macosxDir)) {
|
|
413
415
|
fs.rmSync(macosxDir, { recursive: true, force: true });
|
|
414
416
|
}
|
|
415
|
-
// Save project ID
|
|
417
|
+
// Save project ID
|
|
416
418
|
saveProjectId(outputDir, id);
|
|
417
419
|
console.log(chalk_1.default.green("Project cloned successfully!"));
|
|
420
|
+
// ===== 3. Save file từ version public =====
|
|
418
421
|
const saveSpinner = (0, ora_1.default)(chalk_1.default.blue("Saving project files...")).start();
|
|
419
422
|
files.forEach((file) => {
|
|
420
423
|
const filePath = path.join(process.cwd(), id, "src", file.path);
|
|
@@ -425,6 +428,31 @@ commander_1.program
|
|
|
425
428
|
fs.writeFileSync(filePath, file.content);
|
|
426
429
|
});
|
|
427
430
|
saveSpinner.succeed(chalk_1.default.green("Project files saved successfully!"));
|
|
431
|
+
// ===== 4. TỰ ĐỘNG PULL PHIÊN BẢN MỚI NHẤT (draft) – ĐÂY LÀ PHẦN MỚI =====
|
|
432
|
+
const pullSpinner = (0, ora_1.default)(chalk_1.default.blue("Pulling latest changes from server...")).start();
|
|
433
|
+
try {
|
|
434
|
+
const pullResponse = await axios_1.default.get(`https://base.myworkbeast.com/api/views/v3/${id}`, {
|
|
435
|
+
headers: {
|
|
436
|
+
Authorization: `Bearer ${accessToken}`,
|
|
437
|
+
"Content-Type": "application/json",
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
const pullCode = (_c = pullResponse === null || pullResponse === void 0 ? void 0 : pullResponse.data) === null || _c === void 0 ? void 0 : _c.code;
|
|
441
|
+
if (!pullCode) {
|
|
442
|
+
pullSpinner.info(chalk_1.default.cyan("No draft version found – using published version."));
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
const pullDecompressed = pako_1.default.inflate(Uint8Array.from(atob(pullCode), (c) => c.charCodeAt(0)), { to: "string" });
|
|
446
|
+
const latestFiles = ((_d = (0, exports.tryJSONParse)(pullDecompressed)) === null || _d === void 0 ? void 0 : _d.files) || [];
|
|
447
|
+
const fileManager = new FileManager(path.join(outputDir, "src"));
|
|
448
|
+
fileManager.syncFiles(latestFiles);
|
|
449
|
+
pullSpinner.succeed(chalk_1.default.green("✓ Latest changes pulled successfully!"));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
catch (pullErr) {
|
|
453
|
+
pullSpinner.warn(chalk_1.default.yellow(`⚠ Could not pull latest changes: ${pullErr.message}\n Run "hapico pull" manually later.`));
|
|
454
|
+
}
|
|
455
|
+
// ===== 5. Hướng dẫn chạy dev =====
|
|
428
456
|
console.log(chalk_1.default.cyan(`💡 Run ${chalk_1.default.bold("cd ${id} && npm install && hapico dev")} to start the project.`));
|
|
429
457
|
}
|
|
430
458
|
catch (error) {
|
|
@@ -434,7 +462,8 @@ commander_1.program
|
|
|
434
462
|
commander_1.program
|
|
435
463
|
.command("dev")
|
|
436
464
|
.description("Start the project in development mode")
|
|
437
|
-
.
|
|
465
|
+
.option('--zversion <version>', 'Zalo version for QR code', '75')
|
|
466
|
+
.action((options) => {
|
|
438
467
|
var _a;
|
|
439
468
|
const { accessToken } = getStoredToken();
|
|
440
469
|
if (!accessToken) {
|
|
@@ -557,8 +586,9 @@ commander_1.program
|
|
|
557
586
|
return;
|
|
558
587
|
}
|
|
559
588
|
const projectType = project.data.type || "view";
|
|
589
|
+
const zversion = options.zversion || '75';
|
|
560
590
|
if (projectType === "zalominiapp") {
|
|
561
|
-
qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version
|
|
591
|
+
qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
|
|
562
592
|
console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
|
|
563
593
|
console.log(qrcode);
|
|
564
594
|
});
|
package/dist/index.js
CHANGED
|
@@ -371,12 +371,12 @@ class RoomState {
|
|
|
371
371
|
return this.isConnected;
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
commander_1.program.version("0.0.
|
|
374
|
+
commander_1.program.version("0.0.22").description("Hapico CLI for project management");
|
|
375
375
|
commander_1.program
|
|
376
376
|
.command("clone <id>")
|
|
377
377
|
.description("Clone a project by ID")
|
|
378
378
|
.action(async (id) => {
|
|
379
|
-
var _a, _b;
|
|
379
|
+
var _a, _b, _c, _d;
|
|
380
380
|
const { accessToken } = getStoredToken();
|
|
381
381
|
if (!accessToken) {
|
|
382
382
|
console.error(chalk_1.default.red("✗ You need to login first. Use 'hapico login' command."));
|
|
@@ -390,11 +390,13 @@ commander_1.program
|
|
|
390
390
|
let files = [];
|
|
391
391
|
const apiSpinner = (0, ora_1.default)(chalk_1.default.blue("Fetching project data...")).start();
|
|
392
392
|
try {
|
|
393
|
+
// ===== 1. Lấy version public/published (giữ nguyên như cũ) =====
|
|
393
394
|
const response = await axios_1.default.get(`https://base.myworkbeast.com/api/views/${id}`);
|
|
394
395
|
const code = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.code;
|
|
395
396
|
const decompressedCode = pako_1.default.inflate(Uint8Array.from(atob(code), (c) => c.charCodeAt(0)), { to: "string" });
|
|
396
397
|
files = ((_b = (0, exports.tryJSONParse)(decompressedCode)) === null || _b === void 0 ? void 0 : _b.files) || [];
|
|
397
398
|
apiSpinner.succeed(chalk_1.default.green("Project data fetched successfully!"));
|
|
399
|
+
// ===== 2. Download + extract template =====
|
|
398
400
|
const templateSpinner = (0, ora_1.default)(chalk_1.default.blue("Downloading template...")).start();
|
|
399
401
|
const TEMPLATE_URL = "https://files.hcm04.vstorage.vngcloud.vn/assets/template_zalominiapp_devmode.zip";
|
|
400
402
|
const templateResponse = await axios_1.default.get(TEMPLATE_URL, {
|
|
@@ -412,9 +414,10 @@ commander_1.program
|
|
|
412
414
|
if (fs.existsSync(macosxDir)) {
|
|
413
415
|
fs.rmSync(macosxDir, { recursive: true, force: true });
|
|
414
416
|
}
|
|
415
|
-
// Save project ID
|
|
417
|
+
// Save project ID
|
|
416
418
|
saveProjectId(outputDir, id);
|
|
417
419
|
console.log(chalk_1.default.green("Project cloned successfully!"));
|
|
420
|
+
// ===== 3. Save file từ version public =====
|
|
418
421
|
const saveSpinner = (0, ora_1.default)(chalk_1.default.blue("Saving project files...")).start();
|
|
419
422
|
files.forEach((file) => {
|
|
420
423
|
const filePath = path.join(process.cwd(), id, "src", file.path);
|
|
@@ -425,6 +428,31 @@ commander_1.program
|
|
|
425
428
|
fs.writeFileSync(filePath, file.content);
|
|
426
429
|
});
|
|
427
430
|
saveSpinner.succeed(chalk_1.default.green("Project files saved successfully!"));
|
|
431
|
+
// ===== 4. TỰ ĐỘNG PULL PHIÊN BẢN MỚI NHẤT (draft) – ĐÂY LÀ PHẦN MỚI =====
|
|
432
|
+
const pullSpinner = (0, ora_1.default)(chalk_1.default.blue("Pulling latest changes from server...")).start();
|
|
433
|
+
try {
|
|
434
|
+
const pullResponse = await axios_1.default.get(`https://base.myworkbeast.com/api/views/v3/${id}`, {
|
|
435
|
+
headers: {
|
|
436
|
+
Authorization: `Bearer ${accessToken}`,
|
|
437
|
+
"Content-Type": "application/json",
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
const pullCode = (_c = pullResponse === null || pullResponse === void 0 ? void 0 : pullResponse.data) === null || _c === void 0 ? void 0 : _c.code;
|
|
441
|
+
if (!pullCode) {
|
|
442
|
+
pullSpinner.info(chalk_1.default.cyan("No draft version found – using published version."));
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
const pullDecompressed = pako_1.default.inflate(Uint8Array.from(atob(pullCode), (c) => c.charCodeAt(0)), { to: "string" });
|
|
446
|
+
const latestFiles = ((_d = (0, exports.tryJSONParse)(pullDecompressed)) === null || _d === void 0 ? void 0 : _d.files) || [];
|
|
447
|
+
const fileManager = new FileManager(path.join(outputDir, "src"));
|
|
448
|
+
fileManager.syncFiles(latestFiles);
|
|
449
|
+
pullSpinner.succeed(chalk_1.default.green("✓ Latest changes pulled successfully!"));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
catch (pullErr) {
|
|
453
|
+
pullSpinner.warn(chalk_1.default.yellow(`⚠ Could not pull latest changes: ${pullErr.message}\n Run "hapico pull" manually later.`));
|
|
454
|
+
}
|
|
455
|
+
// ===== 5. Hướng dẫn chạy dev =====
|
|
428
456
|
console.log(chalk_1.default.cyan(`💡 Run ${chalk_1.default.bold("cd ${id} && npm install && hapico dev")} to start the project.`));
|
|
429
457
|
}
|
|
430
458
|
catch (error) {
|
|
@@ -434,7 +462,8 @@ commander_1.program
|
|
|
434
462
|
commander_1.program
|
|
435
463
|
.command("dev")
|
|
436
464
|
.description("Start the project in development mode")
|
|
437
|
-
.
|
|
465
|
+
.option('--zversion <version>', 'Zalo version for QR code', '75')
|
|
466
|
+
.action((options) => {
|
|
438
467
|
var _a;
|
|
439
468
|
const { accessToken } = getStoredToken();
|
|
440
469
|
if (!accessToken) {
|
|
@@ -557,8 +586,9 @@ commander_1.program
|
|
|
557
586
|
return;
|
|
558
587
|
}
|
|
559
588
|
const projectType = project.data.type || "view";
|
|
589
|
+
const zversion = options.zversion || '75';
|
|
560
590
|
if (projectType === "zalominiapp") {
|
|
561
|
-
qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version
|
|
591
|
+
qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
|
|
562
592
|
console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
|
|
563
593
|
console.log(qrcode);
|
|
564
594
|
});
|
package/index.ts
CHANGED
|
@@ -447,7 +447,7 @@ class RoomState {
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
program.version("0.0.
|
|
450
|
+
program.version("0.0.22").description("Hapico CLI for project management");
|
|
451
451
|
|
|
452
452
|
program
|
|
453
453
|
.command("clone <id>")
|
|
@@ -470,17 +470,19 @@ program
|
|
|
470
470
|
const apiSpinner: Ora = ora(chalk.blue("Fetching project data...")).start();
|
|
471
471
|
|
|
472
472
|
try {
|
|
473
|
+
// ===== 1. Lấy version public/published (giữ nguyên như cũ) =====
|
|
473
474
|
const response: ApiResponse = await axios.get(
|
|
474
475
|
`https://base.myworkbeast.com/api/views/${id}`
|
|
475
476
|
);
|
|
476
477
|
const code = response?.data?.code;
|
|
477
478
|
const decompressedCode = pako.inflate(
|
|
478
|
-
Uint8Array.from(atob(code), (c) => c.charCodeAt(0)),
|
|
479
|
+
Uint8Array.from(atob(code), (c) => c.charCodeAt(0)),
|
|
479
480
|
{ to: "string" }
|
|
480
481
|
);
|
|
481
482
|
files = tryJSONParse(decompressedCode)?.files || [];
|
|
482
483
|
apiSpinner.succeed(chalk.green("Project data fetched successfully!"));
|
|
483
484
|
|
|
485
|
+
// ===== 2. Download + extract template =====
|
|
484
486
|
const templateSpinner: Ora = ora(
|
|
485
487
|
chalk.blue("Downloading template...")
|
|
486
488
|
).start();
|
|
@@ -509,11 +511,11 @@ program
|
|
|
509
511
|
fs.rmSync(macosxDir, { recursive: true, force: true });
|
|
510
512
|
}
|
|
511
513
|
|
|
512
|
-
// Save project ID
|
|
514
|
+
// Save project ID
|
|
513
515
|
saveProjectId(outputDir, id);
|
|
514
|
-
|
|
515
516
|
console.log(chalk.green("Project cloned successfully!"));
|
|
516
517
|
|
|
518
|
+
// ===== 3. Save file từ version public =====
|
|
517
519
|
const saveSpinner: Ora = ora(
|
|
518
520
|
chalk.blue("Saving project files...")
|
|
519
521
|
).start();
|
|
@@ -528,6 +530,47 @@ program
|
|
|
528
530
|
fs.writeFileSync(filePath, file.content);
|
|
529
531
|
});
|
|
530
532
|
saveSpinner.succeed(chalk.green("Project files saved successfully!"));
|
|
533
|
+
|
|
534
|
+
// ===== 4. TỰ ĐỘNG PULL PHIÊN BẢN MỚI NHẤT (draft) – ĐÂY LÀ PHẦN MỚI =====
|
|
535
|
+
const pullSpinner: Ora = ora(
|
|
536
|
+
chalk.blue("Pulling latest changes from server...")
|
|
537
|
+
).start();
|
|
538
|
+
|
|
539
|
+
try {
|
|
540
|
+
const pullResponse = await axios.get(
|
|
541
|
+
`https://base.myworkbeast.com/api/views/v3/${id}`,
|
|
542
|
+
{
|
|
543
|
+
headers: {
|
|
544
|
+
Authorization: `Bearer ${accessToken}`,
|
|
545
|
+
"Content-Type": "application/json",
|
|
546
|
+
},
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
const pullCode = pullResponse?.data?.code;
|
|
551
|
+
if (!pullCode) {
|
|
552
|
+
pullSpinner.info(chalk.cyan("No draft version found – using published version."));
|
|
553
|
+
} else {
|
|
554
|
+
const pullDecompressed = pako.inflate(
|
|
555
|
+
Uint8Array.from(atob(pullCode), (c) => c.charCodeAt(0)),
|
|
556
|
+
{ to: "string" }
|
|
557
|
+
);
|
|
558
|
+
const latestFiles: FileContent[] = tryJSONParse(pullDecompressed)?.files || [];
|
|
559
|
+
|
|
560
|
+
const fileManager = new FileManager(path.join(outputDir, "src"));
|
|
561
|
+
fileManager.syncFiles(latestFiles);
|
|
562
|
+
|
|
563
|
+
pullSpinner.succeed(chalk.green("✓ Latest changes pulled successfully!"));
|
|
564
|
+
}
|
|
565
|
+
} catch (pullErr: any) {
|
|
566
|
+
pullSpinner.warn(
|
|
567
|
+
chalk.yellow(
|
|
568
|
+
`⚠ Could not pull latest changes: ${pullErr.message}\n Run "hapico pull" manually later.`
|
|
569
|
+
)
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// ===== 5. Hướng dẫn chạy dev =====
|
|
531
574
|
console.log(
|
|
532
575
|
chalk.cyan(
|
|
533
576
|
`💡 Run ${chalk.bold("cd ${id} && npm install && hapico dev")} to start the project.`
|
|
@@ -541,7 +584,8 @@ program
|
|
|
541
584
|
program
|
|
542
585
|
.command("dev")
|
|
543
586
|
.description("Start the project in development mode")
|
|
544
|
-
.
|
|
587
|
+
.option('--zversion <version>', 'Zalo version for QR code', '75')
|
|
588
|
+
.action((options) => {
|
|
545
589
|
const { accessToken } = getStoredToken();
|
|
546
590
|
if (!accessToken) {
|
|
547
591
|
console.error(
|
|
@@ -704,10 +748,11 @@ program
|
|
|
704
748
|
}
|
|
705
749
|
|
|
706
750
|
const projectType = project.data.type || "view";
|
|
751
|
+
const zversion = options.zversion || '75';
|
|
707
752
|
|
|
708
753
|
if (projectType === "zalominiapp") {
|
|
709
754
|
QRCode.generate(
|
|
710
|
-
`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version
|
|
755
|
+
`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`,
|
|
711
756
|
{ small: true },
|
|
712
757
|
(qrcode) => {
|
|
713
758
|
console.log(
|
|
@@ -1488,4 +1533,4 @@ ${file.content}
|
|
|
1488
1533
|
console.log(chalk.green(`✓ File list saved to ${outputFile}`));
|
|
1489
1534
|
});
|
|
1490
1535
|
|
|
1491
|
-
program.parse(process.argv);
|
|
1536
|
+
program.parse(process.argv);
|