@yoamigo.com/cli 0.1.26 → 0.1.27

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.
Files changed (2) hide show
  1. package/dist/index.js +93 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/index.ts
4
4
  import "dotenv/config";
5
- import { Command as Command5 } from "commander";
5
+ import { Command as Command6 } from "commander";
6
6
  import { createRequire } from "module";
7
7
 
8
8
  // src/commands/deploy.ts
@@ -472,13 +472,104 @@ var initCommand = new Command4("init").description("Create a new template projec
472
472
  }
473
473
  });
474
474
 
475
+ // src/commands/pull.ts
476
+ import { Buffer } from "buffer";
477
+ import { Command as Command5 } from "commander";
478
+ import chalk5 from "chalk";
479
+ import ora4 from "ora";
480
+ import fs5 from "fs-extra";
481
+ import path5 from "path";
482
+ var API_BASE_URL3 = getApiBaseUrl();
483
+ var pullCommand = new Command5("pull").description("Download a website from YoAmigo").argument("<siteId>", "The website ID to download").option("-o, --output <path>", "Output path for the ZIP file").option("-v, --verbose", "Show detailed logging for debugging").action(async (siteId, options) => {
484
+ const verbose = options.verbose;
485
+ if (verbose) {
486
+ console.log(chalk5.dim(`API URL: ${API_BASE_URL3}`));
487
+ console.log();
488
+ }
489
+ const credentials = await getCredentials();
490
+ if (!credentials) {
491
+ console.error(chalk5.red("Error: Not logged in. Run `yoamigo login` first."));
492
+ process.exit(1);
493
+ }
494
+ if (!siteId || siteId.trim().length === 0) {
495
+ console.error(chalk5.red("Error: Site ID is required."));
496
+ console.log(chalk5.dim("Usage: yoamigo pull <siteId>"));
497
+ process.exit(1);
498
+ }
499
+ const spinner = ora4("Downloading website...").start();
500
+ try {
501
+ const downloadUrl = `${API_BASE_URL3}/api/cli/download/${encodeURIComponent(siteId)}`;
502
+ if (verbose) {
503
+ spinner.stop();
504
+ console.log(chalk5.dim(`GET ${downloadUrl}`));
505
+ spinner.start();
506
+ }
507
+ const response = await fetch(downloadUrl, {
508
+ method: "GET",
509
+ headers: {
510
+ "X-API-Key": credentials.apiKey
511
+ }
512
+ });
513
+ if (!response.ok) {
514
+ const errorText = await response.text();
515
+ let errorMessage = "Failed to download website";
516
+ try {
517
+ const error = JSON.parse(errorText);
518
+ errorMessage = error.error || error.message || errorMessage;
519
+ } catch {
520
+ errorMessage = errorText || errorMessage;
521
+ }
522
+ if (response.status === 401) {
523
+ throw new Error("Invalid or expired API key. Run `yoamigo login` again.");
524
+ } else if (response.status === 403) {
525
+ throw new Error(errorMessage);
526
+ } else if (response.status === 404) {
527
+ throw new Error(`Website not found: ${siteId}`);
528
+ } else {
529
+ throw new Error(errorMessage);
530
+ }
531
+ }
532
+ const contentDisposition = response.headers.get("content-disposition");
533
+ let filename = `${siteId}.zip`;
534
+ if (contentDisposition) {
535
+ const filenameMatch = contentDisposition.match(/filename="?([^";\n]+)"?/);
536
+ if (filenameMatch) {
537
+ filename = filenameMatch[1];
538
+ }
539
+ }
540
+ const outputPath = options.output ? path5.resolve(options.output) : path5.join(process.cwd(), filename);
541
+ spinner.text = "Saving file...";
542
+ const arrayBuffer = await response.arrayBuffer();
543
+ const buffer = Buffer.from(arrayBuffer);
544
+ await fs5.ensureDir(path5.dirname(outputPath));
545
+ await fs5.writeFile(outputPath, buffer);
546
+ const fileSizeKB = Math.round(buffer.length / 1024);
547
+ const fileSizeMB = (buffer.length / (1024 * 1024)).toFixed(2);
548
+ spinner.succeed(`Website downloaded successfully!`);
549
+ console.log();
550
+ console.log(chalk5.green("Saved to:"));
551
+ console.log(chalk5.cyan(` ${outputPath}`));
552
+ console.log();
553
+ console.log(chalk5.dim(`File size: ${fileSizeMB} MB (${fileSizeKB} KB)`));
554
+ } catch (error) {
555
+ spinner.fail("Failed to download website");
556
+ if (verbose && error instanceof Error && error.stack) {
557
+ console.error(chalk5.red(error.stack));
558
+ } else {
559
+ console.error(chalk5.red(error instanceof Error ? error.message : "Unknown error"));
560
+ }
561
+ process.exit(1);
562
+ }
563
+ });
564
+
475
565
  // src/index.ts
476
566
  var require2 = createRequire(import.meta.url);
477
567
  var pkg = require2("../package.json");
478
- var program = new Command5();
568
+ var program = new Command6();
479
569
  program.name("yoamigo").description("CLI for creating and managing YoAmigo templates").version(pkg.version, "-v, --version", "output the current version");
480
570
  program.addCommand(loginCommand);
481
571
  program.addCommand(initCommand);
482
572
  program.addCommand(devCommand);
483
573
  program.addCommand(deployCommand);
574
+ program.addCommand(pullCommand);
484
575
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/cli",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "CLI for creating and managing YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",