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.
- package/dist/cli.cjs +28 -15
- 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
|
-
|
|
365
|
-
|
|
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
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
export * from './${camelCaseModuleName}.endpoints'
|
|
385
|
-
|
|
386
|
-
export * from '
|
|
387
|
-
|
|
388
|
-
export * from './${
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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)..."));
|