api-core-lib 12.0.85 → 12.0.86

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/cli.cjs +28 -15
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -256,13 +256,26 @@ async function generateModuleFiles(module2, allSchemas, allEnums, outputDir) {
256
256
  if (!import_fs.default.existsSync(moduleOutputPath)) import_fs.default.mkdirSync(moduleOutputPath, { recursive: true });
257
257
  console.log(import_chalk.default.cyan(`
258
258
  Generating module: ${import_chalk.default.bold(module2.moduleName)}`));
259
+ const schemasToImport = [...module2.schemas].sort();
260
+ const enumsToImport = [...module2.enums].sort();
261
+ const indexExports = ["config"];
262
+ if (schemasToImport.length > 0) {
263
+ if (enumsToImport.length > 0) indexExports.push("enums");
264
+ indexExports.push("types", "validation", "mocks");
265
+ }
266
+ const initialIndexContent = `// This file is auto-generated. Do not edit directly.
267
+
268
+ ` + indexExports.map((e) => `export * from './${e}';`).join("\n");
269
+ const indexFilePath = import_path.default.join(moduleOutputPath, "index.ts");
270
+ import_fs.default.writeFileSync(indexFilePath, initialIndexContent);
271
+ console.log(import_chalk.default.gray(` \u2713 index.ts (Initial)`));
259
272
  const moduleBaseName = module2.moduleName.replace(/Api$/, "");
260
273
  const camelCaseModuleName = toCamelCase(moduleBaseName);
261
274
  const allPathParams = /* @__PURE__ */ new Set();
262
275
  Object.values(module2.actions).forEach((action) => {
263
276
  action.pathParams.forEach((param) => allPathParams.add(param));
264
277
  });
265
- const pathParamsType = allPathParams.size > 0 ? `{ ${[...allPathParams].map((p) => `${p}?: string | number`).join("; ")} }` : "never";
278
+ const pathParamsType = allPathParams.size > 0 ? `{ ${[...allPathParams].map((p) => `${p}?: string | number`).join("; ")} }` : "Record<string, never>";
266
279
  let endpointsContent = `// This file is auto-generated. Do not edit directly.
267
280
 
268
281
  `;
@@ -361,8 +374,9 @@ export function ${moduleBaseName}Provider({ children, options = {} }: ${moduleBa
361
374
  return <ApiModuleProvider value={api}>{children}</ApiModuleProvider>;
362
375
  }
363
376
  `;
364
- import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${moduleBaseName}.provider.tsx`), providerContent);
365
- console.log(import_chalk.default.gray(` \u2713 ${moduleBaseName}.provider.tsx (React Provider)`));
377
+ const providerFileName = `${moduleBaseName}.provider.tsx`;
378
+ import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, providerFileName), providerContent);
379
+ console.log(import_chalk.default.gray(` \u2713 ${providerFileName} (React Provider)`));
366
380
  const serverContent = `// This file is auto-generated. For server-side use only.
367
381
 
368
382
  import { createServerApi } from 'api-core-lib/server';
@@ -378,18 +392,17 @@ export const create${moduleBaseName}ServerApi = () => {
378
392
  `;
379
393
  import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.server.ts`), serverContent);
380
394
  console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.server.ts (Server-Side Helper)`));
381
- const indexFilePath = import_path.default.join(moduleOutputPath, "index.ts");
382
- let indexFileContent = import_fs.default.readFileSync(indexFilePath, "utf-8");
383
- indexFileContent += `
384
- export * from './${camelCaseModuleName}.endpoints';`;
385
- indexFileContent += `
386
- export * from './use${moduleBaseName}';`;
387
- indexFileContent += `
388
- export * from './${moduleBaseName}.provider';`;
389
- indexFileContent += `
390
- export * from './${camelCaseModuleName}.server';`;
391
- import_fs.default.writeFileSync(indexFilePath, indexFileContent);
392
- console.log(import_chalk.default.gray(` \u2713 index.ts (Updated with new exports)`));
395
+ const newExports = [
396
+ `
397
+ // Generated API helpers`,
398
+ `export * from './${camelCaseModuleName}.endpoints';`,
399
+ `export * from './use${moduleBaseName}';`,
400
+ `export * from './${moduleBaseName}.provider';`,
401
+ // <-- Note: no .tsx in export
402
+ `export * from './${camelCaseModuleName}.server';`
403
+ ].join("\n");
404
+ import_fs.default.appendFileSync(indexFilePath, newExports);
405
+ console.log(import_chalk.default.gray(` \u2713 index.ts (Updated with helpers)`));
393
406
  }
394
407
  async function runGenerator(options) {
395
408
  console.log(import_chalk.default.cyan.bold("\u{1F680} Starting API Development Platform Generator (Sapphire Edition)..."));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.85",
3
+ "version": "12.0.86",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {