pdfn 0.6.0 → 0.6.1

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/dist/cli.js CHANGED
@@ -1451,7 +1451,7 @@ var require_react = __commonJS({
1451
1451
  });
1452
1452
 
1453
1453
  // src/cli.ts
1454
- import { Command as Command4 } from "commander";
1454
+ import { Command as Command3 } from "commander";
1455
1455
 
1456
1456
  // src/commands/dev.ts
1457
1457
  import { Command } from "commander";
@@ -3369,148 +3369,12 @@ var devCommand = new Command("dev").description("Start development server with l
3369
3369
  });
3370
3370
  });
3371
3371
 
3372
- // src/commands/serve.ts
3373
- import { Command as Command2 } from "commander";
3374
- import { execSync, spawn as spawn2 } from "child_process";
3375
- import chalk2 from "chalk";
3376
- var CONTAINER_NAME = "pdfn-server";
3377
- var GOTENBERG_IMAGE = "gotenberg/gotenberg:8";
3378
- var DEFAULT_PORT = 3456;
3379
- function hasDocker() {
3380
- try {
3381
- execSync("docker --version", { stdio: "ignore" });
3382
- return true;
3383
- } catch {
3384
- return false;
3385
- }
3386
- }
3387
- function isContainerRunning(name) {
3388
- try {
3389
- const result = execSync(`docker ps --filter "name=${name}" --format "{{.Names}}"`, {
3390
- encoding: "utf-8"
3391
- });
3392
- return result.trim() === name;
3393
- } catch {
3394
- return false;
3395
- }
3396
- }
3397
- function stopContainer(name) {
3398
- try {
3399
- execSync(`docker stop ${name}`, { stdio: "ignore" });
3400
- } catch {
3401
- }
3402
- try {
3403
- execSync(`docker rm ${name}`, { stdio: "ignore" });
3404
- } catch {
3405
- }
3406
- }
3407
- async function isServerHealthy(port) {
3408
- try {
3409
- const response = await fetch(`http://localhost:${port}/health`, {
3410
- signal: AbortSignal.timeout(2e3)
3411
- });
3412
- return response.ok;
3413
- } catch {
3414
- return false;
3415
- }
3416
- }
3417
- async function waitForHealthy(port, timeoutMs = 6e4) {
3418
- const start = Date.now();
3419
- while (Date.now() - start < timeoutMs) {
3420
- if (await isServerHealthy(port)) {
3421
- return true;
3422
- }
3423
- await new Promise((r) => setTimeout(r, 500));
3424
- }
3425
- return false;
3426
- }
3427
- var serveCommand = new Command2("serve").description("Start production PDF server (powered by Gotenberg)").option("--port <number>", "Server port (env: PDFN_PORT)", String(DEFAULT_PORT)).option("--mode <mode>", "Environment mode (loads .env.[mode])", "production").action(async (options) => {
3428
- loadEnv(options.mode);
3429
- const port = parseInt(process.env.PDFN_PORT ?? options.port, 10);
3430
- console.log();
3431
- if (await isServerHealthy(port)) {
3432
- console.log(chalk2.green(" \u2713"), `Server already running on port ${port}`);
3433
- console.log(chalk2.dim(` http://localhost:${port}`));
3434
- console.log();
3435
- console.log(chalk2.dim(" Press Ctrl+C to exit"));
3436
- await new Promise(() => {
3437
- });
3438
- return;
3439
- }
3440
- if (!hasDocker()) {
3441
- console.log(chalk2.red(" \u2717"), "Docker not found");
3442
- console.log();
3443
- console.log(chalk2.dim(" pdfn serve requires Docker to run Gotenberg."));
3444
- console.log(chalk2.dim(" Install Docker: https://docs.docker.com/get-docker/"));
3445
- console.log();
3446
- console.log(chalk2.dim(" Alternatively, start Gotenberg manually:"));
3447
- console.log(chalk2.dim(` docker run -p ${port}:3000 ${GOTENBERG_IMAGE}`));
3448
- console.log();
3449
- process.exit(1);
3450
- }
3451
- if (isContainerRunning(CONTAINER_NAME)) {
3452
- console.log(chalk2.dim(" Stopping existing container..."));
3453
- stopContainer(CONTAINER_NAME);
3454
- }
3455
- console.log(chalk2.dim(` Starting Gotenberg on port ${port}...`));
3456
- let dockerProcess;
3457
- try {
3458
- dockerProcess = spawn2(
3459
- "docker",
3460
- [
3461
- "run",
3462
- "--rm",
3463
- "--name",
3464
- CONTAINER_NAME,
3465
- "-p",
3466
- `${port}:3000`,
3467
- GOTENBERG_IMAGE
3468
- ],
3469
- { stdio: "inherit" }
3470
- );
3471
- } catch (error) {
3472
- console.log(chalk2.red(" \u2717"), "Failed to start Docker container");
3473
- console.error(chalk2.dim(" "), error);
3474
- process.exit(1);
3475
- }
3476
- dockerProcess.on("error", (err) => {
3477
- console.log(chalk2.red(" \u2717"), "Docker process error:", err.message);
3478
- process.exit(1);
3479
- });
3480
- dockerProcess.on("exit", (code) => {
3481
- if (code !== null && code !== 0) {
3482
- console.log(chalk2.red(" \u2717"), `Docker exited with code ${code}`);
3483
- process.exit(1);
3484
- }
3485
- });
3486
- const healthy = await waitForHealthy(port);
3487
- if (!healthy) {
3488
- console.log(chalk2.red(" \u2717"), "Server failed to start (timeout)");
3489
- stopContainer(CONTAINER_NAME);
3490
- process.exit(1);
3491
- }
3492
- console.log(chalk2.green(" \u2713"), `Ready at ${chalk2.cyan(`http://localhost:${port}`)}`);
3493
- console.log();
3494
- const shutdown = async () => {
3495
- console.log();
3496
- console.log(chalk2.dim(" Stopping server..."));
3497
- stopContainer(CONTAINER_NAME);
3498
- console.log(chalk2.green(" \u2713"), "Server stopped");
3499
- console.log();
3500
- process.exit(0);
3501
- };
3502
- process.on("SIGTERM", shutdown);
3503
- process.on("SIGINT", shutdown);
3504
- await new Promise(() => {
3505
- });
3506
- });
3507
-
3508
3372
  // src/commands/add.ts
3509
- import { Command as Command3 } from "commander";
3373
+ import { Command as Command2 } from "commander";
3510
3374
  import { existsSync as existsSync3, mkdirSync, copyFileSync, readFileSync as readFileSync2 } from "fs";
3511
3375
  import { join as join2, dirname } from "path";
3512
3376
  import { fileURLToPath } from "url";
3513
- import chalk3 from "chalk";
3377
+ import chalk2 from "chalk";
3514
3378
  var __dirname = dirname(fileURLToPath(import.meta.url));
3515
3379
  var TEMPLATES = {
3516
3380
  invoice: {
@@ -3561,36 +3425,36 @@ function isTailwindInstalled(cwd) {
3561
3425
  const tailwindPath = join2(cwd, "node_modules", "@pdfn", "tailwind");
3562
3426
  return existsSync3(tailwindPath);
3563
3427
  }
3564
- var addCommand = new Command3("add").description("Add a starter template to your project").argument("[template]", "Template name (e.g., invoice, letter, contract)").option("--list", "List available templates").option("--tailwind", "Use Tailwind CSS styling (requires @pdfn/tailwind)").option("--inline", "Use inline styles (default)").option("--force", "Overwrite existing files").action(async (template, options) => {
3428
+ var addCommand = new Command2("add").description("Add a starter template to your project").argument("[template]", "Template name (e.g., invoice, letter, contract)").option("--list", "List available templates").option("--tailwind", "Use Tailwind CSS styling (requires @pdfn/tailwind)").option("--inline", "Use inline styles (default)").option("--force", "Overwrite existing files").action(async (template, options) => {
3565
3429
  const cwd = process.cwd();
3566
3430
  const outputDir = "./pdfn-templates";
3567
3431
  if (options.list || !template) {
3568
- console.log(chalk3.bold("\nAvailable templates:\n"));
3432
+ console.log(chalk2.bold("\nAvailable templates:\n"));
3569
3433
  for (const [id, info] of Object.entries(TEMPLATES)) {
3570
- console.log(` ${chalk3.cyan(id.padEnd(12))} ${info.description} ${chalk3.dim(`(${info.pageSize})`)}`);
3571
- }
3572
- console.log(chalk3.dim("\nUsage: pdfn add <template> [--tailwind]"));
3573
- console.log(chalk3.dim("Example: pdfn add invoice"));
3574
- console.log(chalk3.dim("Example: pdfn add invoice --tailwind\n"));
3575
- console.log(chalk3.bold("Options:"));
3576
- console.log(chalk3.dim(" --inline Use inline styles (default)"));
3577
- console.log(chalk3.dim(" --tailwind Use Tailwind CSS (requires @pdfn/tailwind)\n"));
3434
+ console.log(` ${chalk2.cyan(id.padEnd(12))} ${info.description} ${chalk2.dim(`(${info.pageSize})`)}`);
3435
+ }
3436
+ console.log(chalk2.dim("\nUsage: pdfn add <template> [--tailwind]"));
3437
+ console.log(chalk2.dim("Example: pdfn add invoice"));
3438
+ console.log(chalk2.dim("Example: pdfn add invoice --tailwind\n"));
3439
+ console.log(chalk2.bold("Options:"));
3440
+ console.log(chalk2.dim(" --inline Use inline styles (default)"));
3441
+ console.log(chalk2.dim(" --tailwind Use Tailwind CSS (requires @pdfn/tailwind)\n"));
3578
3442
  return;
3579
3443
  }
3580
3444
  if (!TEMPLATES[template]) {
3581
- console.error(chalk3.red(`
3445
+ console.error(chalk2.red(`
3582
3446
  Error: Unknown template "${template}"`));
3583
- console.log(chalk3.dim("Run 'pdfn add --list' to see available templates\n"));
3447
+ console.log(chalk2.dim("Run 'pdfn add --list' to see available templates\n"));
3584
3448
  process.exit(1);
3585
3449
  }
3586
3450
  const style = options.tailwind ? "tailwind" : "inline";
3587
3451
  if (style === "tailwind" && !isTailwindInstalled(cwd)) {
3588
- console.error(chalk3.yellow(`
3452
+ console.error(chalk2.yellow(`
3589
3453
  \u26A0 @pdfn/tailwind is not installed.`));
3590
- console.log(chalk3.dim("Install it first to use Tailwind templates:\n"));
3591
- console.log(chalk3.cyan(" npm install @pdfn/tailwind\n"));
3592
- console.log(chalk3.dim("Or use inline styles (default):\n"));
3593
- console.log(chalk3.cyan(` pdfn add ${template}
3454
+ console.log(chalk2.dim("Install it first to use Tailwind templates:\n"));
3455
+ console.log(chalk2.cyan(" npm install @pdfn/tailwind\n"));
3456
+ console.log(chalk2.dim("Or use inline styles (default):\n"));
3457
+ console.log(chalk2.cyan(` pdfn add ${template}
3594
3458
  `));
3595
3459
  process.exit(1);
3596
3460
  }
@@ -3598,47 +3462,46 @@ Error: Unknown template "${template}"`));
3598
3462
  const sourceFile = join2(templatesDir, `${template}.tsx`);
3599
3463
  const outputFile = join2(outputDir, `${template}.tsx`);
3600
3464
  if (!existsSync3(sourceFile)) {
3601
- console.error(chalk3.red(`
3465
+ console.error(chalk2.red(`
3602
3466
  Error: Template file not found: ${sourceFile}`));
3603
- console.log(chalk3.dim("This may be a package installation issue.\n"));
3467
+ console.log(chalk2.dim("This may be a package installation issue.\n"));
3604
3468
  process.exit(1);
3605
3469
  }
3606
3470
  if (!existsSync3(outputDir)) {
3607
3471
  mkdirSync(outputDir, { recursive: true });
3608
- console.log(chalk3.dim(`Created ${outputDir}/`));
3472
+ console.log(chalk2.dim(`Created ${outputDir}/`));
3609
3473
  }
3610
3474
  if (existsSync3(outputFile) && !options.force) {
3611
- console.error(chalk3.yellow(`
3475
+ console.error(chalk2.yellow(`
3612
3476
  File already exists: ${outputFile}`));
3613
- console.log(chalk3.dim("Use --force to overwrite\n"));
3477
+ console.log(chalk2.dim("Use --force to overwrite\n"));
3614
3478
  process.exit(1);
3615
3479
  }
3616
3480
  try {
3617
3481
  copyFileSync(sourceFile, outputFile);
3618
3482
  const info = TEMPLATES[template];
3619
- const styleLabel = style === "tailwind" ? chalk3.cyan(" (Tailwind)") : chalk3.dim(" (inline styles)");
3620
- console.log(chalk3.green(`
3483
+ const styleLabel = style === "tailwind" ? chalk2.cyan(" (Tailwind)") : chalk2.dim(" (inline styles)");
3484
+ console.log(chalk2.green(`
3621
3485
  \u2713 Added ${info.name} template`) + styleLabel);
3622
- console.log(chalk3.dim(` ${outputFile}
3486
+ console.log(chalk2.dim(` ${outputFile}
3623
3487
  `));
3624
- console.log(chalk3.bold("Next steps:"));
3625
- console.log(chalk3.dim(` 1. Edit ${outputFile} to customize`));
3626
- console.log(chalk3.dim(` 2. Run 'npx pdfn dev' to preview
3488
+ console.log(chalk2.bold("Next steps:"));
3489
+ console.log(chalk2.dim(` 1. Edit ${outputFile} to customize`));
3490
+ console.log(chalk2.dim(` 2. Run 'npx pdfn dev' to preview
3627
3491
  `));
3628
3492
  if (style === "tailwind") {
3629
- console.log(chalk3.dim("Note: Tailwind templates require @pdfn/tailwind to be installed.\n"));
3493
+ console.log(chalk2.dim("Note: Tailwind templates require @pdfn/tailwind to be installed.\n"));
3630
3494
  }
3631
3495
  } catch (error) {
3632
- console.error(chalk3.red(`
3496
+ console.error(chalk2.red(`
3633
3497
  Error copying template: ${error}`));
3634
3498
  process.exit(1);
3635
3499
  }
3636
3500
  });
3637
3501
 
3638
3502
  // src/cli.ts
3639
- var program = new Command4().name("pdfn").description("PDFN CLI - PDF generation from React components").version("0.0.1-alpha.1");
3503
+ var program = new Command3().name("pdfn").description("PDFN CLI - PDF generation from React components").version("0.0.1-alpha.1");
3640
3504
  program.addCommand(devCommand);
3641
- program.addCommand(serveCommand);
3642
3505
  program.addCommand(addCommand);
3643
3506
  program.parse();
3644
3507
  /*! Bundled license information: