adorn-api 1.0.17 → 1.0.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/dist/cli.js CHANGED
@@ -1574,7 +1574,12 @@ function generateOpenAPI(controllers, checker, options = {}) {
1574
1574
  mode: "response"
1575
1575
  };
1576
1576
  const paths = {};
1577
- for (const controller of controllers) {
1577
+ const { onProgress } = options;
1578
+ for (let i = 0; i < controllers.length; i++) {
1579
+ const controller = controllers[i];
1580
+ if (onProgress) {
1581
+ onProgress(`Processing controller ${controller.className}`, i + 1, controllers.length);
1582
+ }
1578
1583
  for (const operation of controller.operations) {
1579
1584
  const fullPath = convertToOpenApiPath(controller.basePath, operation.path);
1580
1585
  if (!paths[fullPath]) {
@@ -1585,6 +1590,9 @@ function generateOpenAPI(controllers, checker, options = {}) {
1585
1590
  }
1586
1591
  }
1587
1592
  const schemas = Object.fromEntries(components);
1593
+ if (onProgress) {
1594
+ onProgress("Generating and cleaning schemas", controllers.length, controllers.length);
1595
+ }
1588
1596
  cleanupMetalOrmWrappers(schemas, paths);
1589
1597
  return {
1590
1598
  openapi: "3.1.0",
@@ -2373,7 +2381,7 @@ var ProgressTracker = class {
2373
2381
  }
2374
2382
  if (!this.quiet) {
2375
2383
  const elapsed = phase ? this.formatElapsed(phase.startTime, phase.endTime) : "";
2376
- const status = this.verbose ? `\u2713 ${message || name} ${elapsed}` : `\u2713 ${message || name}`;
2384
+ const status = this.verbose ? `\u2713 ${message || name} ${elapsed}` : `\u2713 ${message || name} ${elapsed}`;
2377
2385
  this.log(status);
2378
2386
  }
2379
2387
  }
@@ -2445,7 +2453,6 @@ var ProgressTracker = class {
2445
2453
  */
2446
2454
  printSummary(stats) {
2447
2455
  if (this.quiet) return;
2448
- const totalTime = this.getTotalElapsed();
2449
2456
  this.log("");
2450
2457
  this.log("Build Summary:");
2451
2458
  this.log(` Controllers: ${stats.controllers}`);
@@ -2495,12 +2502,17 @@ var Spinner = class {
2495
2502
  let frameIndex = 0;
2496
2503
  this.interval = setInterval(() => {
2497
2504
  const frame = this.frames[frameIndex];
2505
+ let output;
2498
2506
  if (this.customStatus) {
2499
- process.stdout.write(`\r${frame} ${this.customStatus}`);
2507
+ output = `\r${frame} ${this.customStatus}`;
2500
2508
  } else if (this.total > 0) {
2501
- process.stdout.write(`\r${frame} ${this.message} (${this.current}/${this.total})`);
2509
+ output = `\r${frame} ${this.message} (${this.current}/${this.total})`;
2502
2510
  } else {
2503
- process.stdout.write(`\r${frame} ${this.message}`);
2511
+ output = `\r${frame} ${this.message}`;
2512
+ }
2513
+ process.stdout.write(output);
2514
+ if (process.stdout.writable) {
2515
+ process.stdout.write("");
2504
2516
  }
2505
2517
  frameIndex = (frameIndex + 1) % this.frames.length;
2506
2518
  }, 80);
@@ -2517,6 +2529,11 @@ var Spinner = class {
2517
2529
  */
2518
2530
  setStatus(status) {
2519
2531
  this.customStatus = status;
2532
+ const frame = this.frames[this.current];
2533
+ process.stdout.write(`\r${frame} ${status}`);
2534
+ if (process.stdout.writable) {
2535
+ process.stdout.write("");
2536
+ }
2520
2537
  }
2521
2538
  /**
2522
2539
  * Clear the custom status message.
@@ -2536,6 +2553,9 @@ var Spinner = class {
2536
2553
  if (completedMessage) {
2537
2554
  process.stdout.write(completedMessage + "\n");
2538
2555
  }
2556
+ if (process.stdout.writable) {
2557
+ process.stdout.write("");
2558
+ }
2539
2559
  }
2540
2560
  /**
2541
2561
  * Stop the spinner with a failure message.
@@ -2930,12 +2950,17 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2930
2950
  outputDir,
2931
2951
  schemasDir = "schemas",
2932
2952
  createIndexFile = true,
2933
- prettyPrint = true
2953
+ prettyPrint = true,
2954
+ onProgress
2934
2955
  } = config;
2935
2956
  const indent = prettyPrint ? 2 : 0;
2936
2957
  let totalSize = 0;
2937
2958
  const schemaFiles = [];
2959
+ mkdirSync(outputDir, { recursive: true });
2938
2960
  if (!partitioning.shouldSplit || partitioning.groups.length === 1) {
2961
+ if (onProgress) {
2962
+ onProgress("Writing single OpenAPI file", 1, 1);
2963
+ }
2939
2964
  const mainPath2 = resolve2(outputDir, "openapi.json");
2940
2965
  writeFileSync(mainPath2, JSON.stringify(openapi, null, indent));
2941
2966
  totalSize = Buffer.byteLength(JSON.stringify(openapi));
@@ -2948,9 +2973,16 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2948
2973
  }
2949
2974
  const schemasPath = resolve2(outputDir, schemasDir);
2950
2975
  mkdirSync(schemasPath, { recursive: true });
2976
+ if (onProgress) {
2977
+ onProgress("Creating schemas directory", 0, partitioning.groups.length + 2);
2978
+ }
2951
2979
  const schemaMap = collectAllSchemas(partitioning.groups);
2952
2980
  const schemaToFile = /* @__PURE__ */ new Map();
2953
- for (const group of partitioning.groups) {
2981
+ for (let i = 0; i < partitioning.groups.length; i++) {
2982
+ const group = partitioning.groups[i];
2983
+ if (onProgress) {
2984
+ onProgress(`Writing schema group ${group.name} (${group.schemas.size} schemas)`, i + 1, partitioning.groups.length + 2);
2985
+ }
2954
2986
  const filename = getSchemaFilename(group);
2955
2987
  const filePath = resolve2(outputDir, filename);
2956
2988
  const content = generateSchemaFileContent(group, schemaMap);
@@ -2963,12 +2995,18 @@ function generateModularOpenAPI(openapi, partitioning, config) {
2963
2995
  }
2964
2996
  let indexFile;
2965
2997
  if (createIndexFile) {
2998
+ if (onProgress) {
2999
+ onProgress("Generating index file", partitioning.groups.length + 1, partitioning.groups.length + 2);
3000
+ }
2966
3001
  const indexPath = resolve2(outputDir, "schemas/index.json");
2967
3002
  const indexContent = generateSchemaIndex(partitioning.groups, schemaMap);
2968
3003
  writeFileSync(indexPath, JSON.stringify(indexContent, null, indent));
2969
3004
  totalSize += Buffer.byteLength(JSON.stringify(indexContent));
2970
3005
  indexFile = indexPath;
2971
3006
  }
3007
+ if (onProgress) {
3008
+ onProgress("Generating main OpenAPI spec", partitioning.groups.length + 2, partitioning.groups.length + 2);
3009
+ }
2972
3010
  const mainSpec = generateMainSpec(openapi, schemaMap, schemaToFile);
2973
3011
  const mainPath = resolve2(outputDir, "openapi.json");
2974
3012
  writeFileSync(mainPath, JSON.stringify(mainSpec, null, indent));
@@ -3300,22 +3338,40 @@ var SchemaGraph = class {
3300
3338
  import ts13 from "typescript";
3301
3339
  import process2 from "process";
3302
3340
  var ADORN_VERSION = (() => {
3303
- try {
3304
- const localPkgPath = resolve3(process2.cwd(), "package.json");
3341
+ const tryReadPackageJson = (filePath) => {
3305
3342
  try {
3306
- const localPkg = JSON.parse(readFileSync3(localPkgPath, "utf-8"));
3307
- if (localPkg.bin?.["adorn-api"] || localPkg.name === "adorn-api") {
3308
- return localPkg.version ?? "0.0.0";
3309
- }
3343
+ const pkg = JSON.parse(readFileSync3(filePath, "utf-8"));
3344
+ return pkg.version ?? null;
3310
3345
  } catch {
3346
+ return null;
3347
+ }
3348
+ };
3349
+ const potentialPaths = [];
3350
+ try {
3351
+ const importMetaUrl = import.meta?.url;
3352
+ if (importMetaUrl && typeof importMetaUrl === "string" && importMetaUrl.length > 0) {
3353
+ const cliDir = dirname3(fileURLToPath(importMetaUrl));
3354
+ potentialPaths.push(
3355
+ resolve3(cliDir, "..", "package.json"),
3356
+ resolve3(cliDir, "package.json")
3357
+ );
3311
3358
  }
3312
- const cliDir = dirname3(fileURLToPath(import.meta.url));
3313
- const bundledPkgPath = resolve3(cliDir, "..", "package.json");
3314
- const bundledPkg = JSON.parse(readFileSync3(bundledPkgPath, "utf-8"));
3315
- return bundledPkg.version ?? "0.0.0";
3316
3359
  } catch {
3317
- return "0.0.0";
3318
3360
  }
3361
+ const cwd = process2.cwd();
3362
+ potentialPaths.push(
3363
+ resolve3(cwd, "package.json"),
3364
+ resolve3(cwd, "node_modules", "adorn-api", "package.json"),
3365
+ resolve3(cwd, "..", "package.json"),
3366
+ resolve3(cwd, "..", "..", "package.json")
3367
+ );
3368
+ for (const pkgPath of potentialPaths) {
3369
+ const version = tryReadPackageJson(pkgPath);
3370
+ if (version) {
3371
+ return version;
3372
+ }
3373
+ }
3374
+ return "0.0.0";
3319
3375
  })();
3320
3376
  function log(msg, options) {
3321
3377
  if (options?.indent) {
@@ -3511,9 +3567,15 @@ async function buildCommand(args) {
3511
3567
  progress.startPhase("openapi", "Generating OpenAPI schema");
3512
3568
  const openapiSpinner = new Spinner("Processing schemas");
3513
3569
  if (!quiet) openapiSpinner.start();
3514
- let processedControllers = 0;
3515
- let processedOperations = 0;
3516
- const openapi = generateOpenAPI(controllers, checker, { title: "API", version: "1.0.0" });
3570
+ const openapi = generateOpenAPI(controllers, checker, {
3571
+ title: "API",
3572
+ version: "1.0.0",
3573
+ onProgress: (message, current, total) => {
3574
+ if (!quiet) {
3575
+ openapiSpinner.setStatus(`${message} (${current}/${total})`);
3576
+ }
3577
+ }
3578
+ });
3517
3579
  if (!quiet) {
3518
3580
  openapiSpinner.setStatus(`Processed ${controllers.length} controllers, ${totalOperations} operations`);
3519
3581
  }
@@ -3535,14 +3597,24 @@ async function buildCommand(args) {
3535
3597
  if (splitEnabled) {
3536
3598
  progress.verboseLog(`Partitioning result: ${partitioning.strategy} strategy`);
3537
3599
  progress.verboseLog(`Recommendation: ${partitioning.recommendation}`);
3600
+ if (!quiet) {
3601
+ log(` Auto-split enabled: ${partitioning.strategy} strategy`);
3602
+ }
3603
+ const splitSpinner = new Spinner("Writing split schema files");
3604
+ if (!quiet) splitSpinner.start();
3538
3605
  generateModularOpenAPI(openapi, partitioning, {
3539
3606
  outputDir: outputPath,
3540
3607
  schemasDir: "schemas",
3541
3608
  createIndexFile: true,
3542
- prettyPrint: true
3609
+ prettyPrint: true,
3610
+ onProgress: (step, index, total) => {
3611
+ if (!quiet) {
3612
+ progress.logSub(`${step} (${index}/${total})`);
3613
+ }
3614
+ }
3543
3615
  });
3616
+ if (!quiet) splitSpinner.stop();
3544
3617
  if (!quiet) {
3545
- log(` Auto-split enabled: ${partitioning.strategy} strategy`);
3546
3618
  log(` Schema groups: ${partitioning.groups.length}`);
3547
3619
  }
3548
3620
  } else {