@hapico/cli 0.0.21 → 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 +31 -3
- package/dist/index.js +31 -3
- package/index.ts +47 -4
- 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) {
|
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) {
|
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.`
|