@pdfme/cli 6.1.5-dev.16 → 6.1.5-dev.19

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## @pdfme/cli
2
2
 
3
- This package provides the `pdfme` command-line interface for JSON-first pdfme workflows, including PDF generation, validation, diagnostics, example export, and PDF conversion utilities.
3
+ This package provides the `pdfme` command-line interface for JSON-first pdfme workflows, including PDF generation, validation, diagnostics, and PDF conversion utilities.
4
4
 
5
5
  Node.js 20 or later is required.
6
6
 
package/dist/index.js CHANGED
@@ -478,7 +478,7 @@ function validateTemplate(template) {
478
478
  } catch (error) {
479
479
  errors.push(error instanceof Error ? error.message : String(error));
480
480
  }
481
- const schemaPages = normalizeSchemaPages$2(template.schemas);
481
+ const schemaPages = normalizeSchemaPages$1(template.schemas);
482
482
  if (schemaPages.length === 0) return {
483
483
  errors,
484
484
  warnings,
@@ -531,7 +531,7 @@ function validateTemplate(template) {
531
531
  };
532
532
  }
533
533
  function inspectTemplate(template, templateDir) {
534
- const flattenedSchemas = normalizeSchemaPages$2(template.schemas).flat();
534
+ const flattenedSchemas = normalizeSchemaPages$1(template.schemas).flat();
535
535
  const collectedSchemaTypes = getUniqueStringValues(flattenedSchemas.map((schema) => schema.type));
536
536
  const requiredFonts = getUniqueStringValues(flattenedSchemas.map((schema) => schema.fontName));
537
537
  return {
@@ -543,7 +543,7 @@ function inspectTemplate(template, templateDir) {
543
543
  }
544
544
  function collectInputHints(template) {
545
545
  const hintMap = /* @__PURE__ */ new Map();
546
- const schemaPages = normalizeSchemaPages$2(template.schemas);
546
+ const schemaPages = normalizeSchemaPages$1(template.schemas);
547
547
  const radioGroupMembers = collectRadioGroupMembers(schemaPages);
548
548
  for (let pageIdx = 0; pageIdx < schemaPages.length; pageIdx++) for (const schema of schemaPages[pageIdx]) {
549
549
  const name = typeof schema.name === "string" ? schema.name : "";
@@ -645,7 +645,7 @@ function assertRecordObject(value, label) {
645
645
  });
646
646
  return value;
647
647
  }
648
- function normalizeSchemaPages$2(rawSchemas) {
648
+ function normalizeSchemaPages$1(rawSchemas) {
649
649
  if (!Array.isArray(rawSchemas)) return [];
650
650
  return rawSchemas.map((page) => {
651
651
  if (Array.isArray(page)) return page.filter((schema) => typeof schema === "object" && schema !== null);
@@ -1854,7 +1854,7 @@ var generate_default = defineCommand({
1854
1854
  });
1855
1855
  const template = resolveBasePdf(rawTemplate, args.basePdf, templateDir);
1856
1856
  const mode = args.file ? "job" : "template+inputs";
1857
- const templatePageCount = normalizeSchemaPages$1(template.schemas).length;
1857
+ const templatePageCount = normalizeSchemaPages(template.schemas).length;
1858
1858
  const jobOptions = normalizeJobOptions(rawJobOptions);
1859
1859
  assertSupportedSchemaTypes(template);
1860
1860
  const resolvedFont = await resolveFont({
@@ -1969,7 +1969,7 @@ function hasExplicitFontEntries(jobFont) {
1969
1969
  }
1970
1970
  function assertSupportedSchemaTypes(template) {
1971
1971
  const unsupported = [];
1972
- for (const page of normalizeSchemaPages$1(template.schemas)) for (const schema of page) {
1972
+ for (const page of normalizeSchemaPages(template.schemas)) for (const schema of page) {
1973
1973
  const type = schema.type;
1974
1974
  if (typeof type === "string" && !schemaTypes.has(type)) {
1975
1975
  const name = typeof schema.name === "string" && schema.name.length > 0 ? schema.name : null;
@@ -1986,7 +1986,7 @@ function describeGenerateInput(file, template, inputs) {
1986
1986
  if (template || inputs) return `${template ?? "(missing template)"} + ${inputs ?? "(missing inputs)"}`;
1987
1987
  return "(unknown)";
1988
1988
  }
1989
- function normalizeSchemaPages$1(rawSchemas) {
1989
+ function normalizeSchemaPages(rawSchemas) {
1990
1990
  if (!Array.isArray(rawSchemas)) return [];
1991
1991
  return rawSchemas.map((page) => {
1992
1992
  if (Array.isArray(page)) return page.filter((schema) => typeof schema === "object" && schema !== null);
@@ -2270,307 +2270,7 @@ var pdf2size_default = defineCommand({
2270
2270
  });
2271
2271
  //#endregion
2272
2272
  //#region src/version.ts
2273
- var CLI_VERSION = "6.1.5-dev.16";
2274
- //#endregion
2275
- //#region src/example-templates.ts
2276
- function getExamplesBaseUrl() {
2277
- return process.env.PDFME_EXAMPLES_BASE_URL ?? "https://playground.pdfme.com/template-assets";
2278
- }
2279
- async function fetchJson(url) {
2280
- const response = await fetch(url, { signal: AbortSignal.timeout(15e3) });
2281
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
2282
- return await response.json();
2283
- }
2284
- async function getExampleManifest() {
2285
- let lastError;
2286
- for (const url of getManifestUrls()) try {
2287
- return {
2288
- manifest: normalizeManifest(await fetchJson(url)),
2289
- source: "remote",
2290
- url
2291
- };
2292
- } catch (error) {
2293
- lastError = error;
2294
- }
2295
- throw new Error(`Could not load examples manifest. ${formatError(lastError)}`);
2296
- }
2297
- async function fetchExampleTemplateWithSource(name, options = {}) {
2298
- const entry = (options.manifest ?? (await getExampleManifest()).manifest).templates.find((template) => template.name === name);
2299
- if (!entry) throw new Error(`Template "${name}" is not present in the examples manifest.`);
2300
- const relativePath = entry.path;
2301
- const templateUrl = `${getExamplesBaseUrl().replace(/\/$/, "")}/${relativePath}`;
2302
- return {
2303
- template: await fetchJson(templateUrl),
2304
- source: "remote",
2305
- url: templateUrl
2306
- };
2307
- }
2308
- function getManifestUrls() {
2309
- const baseUrl = getExamplesBaseUrl().replace(/\/$/, "");
2310
- return [`${baseUrl}/manifest.json`, `${baseUrl}/index.json`];
2311
- }
2312
- function normalizeManifest(raw) {
2313
- if (Array.isArray(raw)) return {
2314
- schemaVersion: 1,
2315
- cliVersion: CLI_VERSION,
2316
- templates: normalizeEntries(raw)
2317
- };
2318
- if (typeof raw !== "object" || raw === null) throw new Error("Examples manifest must be a JSON object or array.");
2319
- const record = raw;
2320
- const rawTemplates = Array.isArray(record.templates) ? record.templates : Array.isArray(record.entries) ? record.entries : void 0;
2321
- if (!rawTemplates) throw new Error("Examples manifest is missing templates.");
2322
- return {
2323
- schemaVersion: typeof record.schemaVersion === "number" && Number.isFinite(record.schemaVersion) ? record.schemaVersion : 1,
2324
- cliVersion: typeof record.cliVersion === "string" ? record.cliVersion : CLI_VERSION,
2325
- templates: normalizeEntries(rawTemplates)
2326
- };
2327
- }
2328
- function normalizeEntries(rawTemplates) {
2329
- return rawTemplates.filter((entry) => typeof entry === "object" && entry !== null).map((entry) => {
2330
- const name = typeof entry.name === "string" ? entry.name : "";
2331
- return {
2332
- name,
2333
- author: typeof entry.author === "string" && entry.author.length > 0 ? entry.author : "pdfme",
2334
- path: typeof entry.path === "string" && entry.path.length > 0 ? entry.path : `${name}/template.json`,
2335
- thumbnailPath: typeof entry.thumbnailPath === "string" && entry.thumbnailPath.length > 0 ? entry.thumbnailPath : `${name}/thumbnail.png`,
2336
- ...typeof entry.sourcePath === "string" && entry.sourcePath.length > 0 ? { sourcePath: entry.sourcePath } : {},
2337
- ...typeof entry.description === "string" ? { description: entry.description } : {},
2338
- ...typeof entry.order === "number" && Number.isFinite(entry.order) ? { order: entry.order } : {},
2339
- pageCount: typeof entry.pageCount === "number" && Number.isFinite(entry.pageCount) ? entry.pageCount : 0,
2340
- fieldCount: typeof entry.fieldCount === "number" && Number.isFinite(entry.fieldCount) ? entry.fieldCount : 0,
2341
- schemaTypes: normalizeStringArray(entry.schemaTypes),
2342
- fontNames: normalizeStringArray(entry.fontNames),
2343
- hasCJK: typeof entry.hasCJK === "boolean" ? entry.hasCJK : false,
2344
- basePdfKind: typeof entry.basePdfKind === "string" && entry.basePdfKind.length > 0 ? entry.basePdfKind : "unknown",
2345
- ...typeof entry.sourceKind === "string" ? { sourceKind: entry.sourceKind } : {},
2346
- ...Array.isArray(entry.tags) ? { tags: normalizeStringArray(entry.tags) } : {},
2347
- ...typeof entry.title === "string" ? { title: entry.title } : {}
2348
- };
2349
- }).filter((entry) => entry.name.length > 0);
2350
- }
2351
- function normalizeStringArray(value) {
2352
- if (!Array.isArray(value)) return [];
2353
- return value.filter((item) => typeof item === "string" && item.length > 0);
2354
- }
2355
- function formatError(error) {
2356
- return error instanceof Error ? error.message : String(error);
2357
- }
2358
- //#endregion
2359
- //#region src/example-fonts.ts
2360
- var OFFICIAL_EXAMPLE_FONT_URLS = {
2361
- NotoSansJP: "https://fonts.gstatic.com/s/notosansjp/v53/-F6jfjtqLzI2JPCgQBnw7HFyzSD-AsregP8VFBEj75vY0rw-oME.ttf",
2362
- NotoSerifJP: "https://fonts.gstatic.com/s/notoserifjp/v30/xn71YHs72GKoTvER4Gn3b5eMRtWGkp6o7MjQ2bwxOubAILO5wBCU.ttf",
2363
- "PinyonScript-Regular": "https://fonts.gstatic.com/s/pinyonscript/v22/6xKpdSJbL9-e9LuoeQiDRQR8aOLQO4bhiDY.ttf"
2364
- };
2365
- function collectTemplateFontNames(template) {
2366
- const schemas = template.schemas;
2367
- if (!Array.isArray(schemas)) return [];
2368
- const fontNames = /* @__PURE__ */ new Set();
2369
- for (const page of schemas) {
2370
- const pageSchemas = Array.isArray(page) ? page : typeof page === "object" && page !== null ? Object.values(page) : [];
2371
- for (const schema of pageSchemas) {
2372
- if (typeof schema !== "object" || schema === null) continue;
2373
- const fontName = schema.fontName;
2374
- if (typeof fontName === "string" && fontName.length > 0) fontNames.add(fontName);
2375
- }
2376
- }
2377
- return [...fontNames].sort();
2378
- }
2379
- function getOfficialExampleFonts(template) {
2380
- const entries = collectTemplateFontNames(template).flatMap((fontName) => {
2381
- const url = OFFICIAL_EXAMPLE_FONT_URLS[fontName];
2382
- return url ? [[fontName, {
2383
- data: url,
2384
- fallback: false,
2385
- subset: true
2386
- }]] : [];
2387
- });
2388
- if (entries.length === 0) return;
2389
- return Object.fromEntries(entries);
2390
- }
2391
- //#endregion
2392
- //#region src/commands/examples.ts
2393
- var examplesArgs = {
2394
- name: {
2395
- type: "positional",
2396
- description: "Template name to output",
2397
- required: false
2398
- },
2399
- list: {
2400
- type: "boolean",
2401
- description: "List available templates",
2402
- default: false
2403
- },
2404
- output: {
2405
- type: "string",
2406
- alias: "o",
2407
- description: "Output file path"
2408
- },
2409
- withInputs: {
2410
- type: "boolean",
2411
- alias: "w",
2412
- description: "Output unified format with sample inputs",
2413
- default: false
2414
- },
2415
- verbose: {
2416
- type: "boolean",
2417
- alias: "v",
2418
- description: "Verbose output",
2419
- default: false
2420
- },
2421
- json: {
2422
- type: "boolean",
2423
- description: "Machine-readable JSON output",
2424
- default: false
2425
- }
2426
- };
2427
- function generateSampleInputs(template) {
2428
- const fields = normalizeSchemaPages(template.schemas).flat();
2429
- if (fields.length === 0) return [{}];
2430
- const input = {};
2431
- for (const schema of fields) {
2432
- if (typeof schema !== "object" || schema === null) continue;
2433
- const name = schema.name;
2434
- const content = schema.content;
2435
- const readOnly = schema.readOnly;
2436
- const type = schema.type;
2437
- if (readOnly) continue;
2438
- if (name) input[name] = content || (type === "image" || type === "signature" ? "" : `Sample ${name}`);
2439
- }
2440
- return [input];
2441
- }
2442
- var examples_default = defineCommand({
2443
- meta: {
2444
- name: "examples",
2445
- description: "List and output example pdfme templates"
2446
- },
2447
- args: examplesArgs,
2448
- async run({ args, rawArgs }) {
2449
- return runWithContract({ json: Boolean(args.json) }, async () => {
2450
- assertNoUnknownFlags(rawArgs, examplesArgs);
2451
- let manifestResult;
2452
- try {
2453
- manifestResult = await getExampleManifest();
2454
- } catch (error) {
2455
- fail(`Failed to load examples manifest. ${error instanceof Error ? error.message : String(error)}`, {
2456
- code: "EIO",
2457
- exitCode: 3,
2458
- cause: error
2459
- });
2460
- }
2461
- const templateEntries = manifestResult.manifest.templates;
2462
- const templateNames = templateEntries.map((entry) => entry.name).filter((name) => typeof name === "string" && name.length > 0).sort();
2463
- if (args.verbose) {
2464
- console.error(`Base URL: ${getExamplesBaseUrl()}`);
2465
- console.error(`Manifest source: ${manifestResult.source}`);
2466
- if (manifestResult.url) console.error(`Manifest URL: ${manifestResult.url}`);
2467
- console.error(`Templates: ${templateNames.length}`);
2468
- }
2469
- if (args.list || !args.name) {
2470
- if (args.json) printJson({
2471
- ok: true,
2472
- command: "examples",
2473
- mode: "list",
2474
- templateCount: templateNames.length,
2475
- source: manifestResult.source,
2476
- baseUrl: getExamplesBaseUrl(),
2477
- manifest: manifestResult.manifest
2478
- });
2479
- else {
2480
- console.log("Available templates:");
2481
- for (const name of templateNames) console.log(` ${name}`);
2482
- }
2483
- return;
2484
- }
2485
- if (!templateEntries.find((template) => template.name === args.name)) fail(`Template "${args.name}" not found. Available templates: ${templateNames.join(", ")}`, {
2486
- code: "EARG",
2487
- exitCode: 1
2488
- });
2489
- let templateResult;
2490
- try {
2491
- templateResult = await fetchExampleTemplateWithSource(args.name, { manifest: manifestResult.manifest });
2492
- } catch (error) {
2493
- fail(`Failed to load example template "${args.name}". ${error instanceof Error ? error.message : String(error)}`, {
2494
- code: "EIO",
2495
- exitCode: 3,
2496
- cause: error
2497
- });
2498
- }
2499
- const output = args.withInputs ? buildExampleJob(templateResult.template) : templateResult.template;
2500
- const mode = args.withInputs ? "job" : "template";
2501
- const stats = countTemplateStats(templateResult.template);
2502
- const inputCount = args.withInputs ? output.inputs?.length ?? 0 : void 0;
2503
- if (args.verbose) {
2504
- console.error(`Template: ${args.name}`);
2505
- console.error(`Template source: ${templateResult.source}`);
2506
- if (templateResult.url) console.error(`Template URL: ${templateResult.url}`);
2507
- console.error(`Mode: ${mode}`);
2508
- console.error(`Template pages: ${stats.templatePageCount}`);
2509
- console.error(`Fields: ${stats.fieldCount}`);
2510
- if (inputCount !== void 0) console.error(`Inputs: ${inputCount} set(s)`);
2511
- console.error(`Output: ${args.output ?? "stdout"}`);
2512
- }
2513
- if (args.output) {
2514
- writeOutput(args.output, new TextEncoder().encode(JSON.stringify(output, null, 2)));
2515
- if (args.json) printJson({
2516
- ok: true,
2517
- command: "examples",
2518
- name: args.name,
2519
- mode,
2520
- source: templateResult.source,
2521
- templatePageCount: stats.templatePageCount,
2522
- fieldCount: stats.fieldCount,
2523
- ...inputCount !== void 0 ? { inputCount } : {},
2524
- outputPath: args.output
2525
- });
2526
- else {
2527
- const label = args.withInputs ? "Job file" : "Template";
2528
- console.log(`\u2713 ${label} written to ${args.output}`);
2529
- }
2530
- return;
2531
- }
2532
- if (args.json) printJson({
2533
- ok: true,
2534
- command: "examples",
2535
- name: args.name,
2536
- source: templateResult.source,
2537
- mode,
2538
- templatePageCount: stats.templatePageCount,
2539
- fieldCount: stats.fieldCount,
2540
- ...inputCount !== void 0 ? { inputCount } : {},
2541
- data: output
2542
- });
2543
- else console.log(JSON.stringify(output, null, 2));
2544
- });
2545
- }
2546
- });
2547
- function buildExampleJob(template) {
2548
- const job = {
2549
- template,
2550
- inputs: generateSampleInputs(template)
2551
- };
2552
- const font = getOfficialExampleFonts(template);
2553
- if (font) job.options = { font };
2554
- return job;
2555
- }
2556
- function countTemplateStats(template) {
2557
- const schemaPages = normalizeSchemaPages(template.schemas);
2558
- return {
2559
- templatePageCount: schemaPages.length,
2560
- fieldCount: schemaPages.reduce((count, page) => count + page.length, 0)
2561
- };
2562
- }
2563
- function normalizeSchemaPages(rawSchemas) {
2564
- if (!Array.isArray(rawSchemas)) return [];
2565
- return rawSchemas.map((page) => {
2566
- if (Array.isArray(page)) return page.filter((schema) => typeof schema === "object" && schema !== null);
2567
- if (typeof page === "object" && page !== null) return Object.entries(page).map(([name, schema]) => typeof schema === "object" && schema !== null ? {
2568
- ...schema,
2569
- name: schema.name ?? name
2570
- } : null).filter((schema) => schema !== null);
2571
- return [];
2572
- });
2573
- }
2273
+ var CLI_VERSION = "6.1.5-dev.19";
2574
2274
  //#endregion
2575
2275
  //#region src/commands/doctor.ts
2576
2276
  var doctorArgs = {
@@ -3130,7 +2830,6 @@ runMain(defineCommand({
3130
2830
  validate: validate_default,
3131
2831
  pdf2img: pdf2img_default,
3132
2832
  pdf2size: pdf2size_default,
3133
- examples: examples_default,
3134
2833
  doctor: doctor_default
3135
2834
  }
3136
2835
  }));