UNPKG

@simplyhomes/sos-sdk

Version:

TypeScript SDK for Simply Homes SoS API v4

70 lines (64 loc) 2.45 kB
import { readFileSync, writeFileSync, existsSync } from 'fs'; import { resolve } from 'path'; /** * Auto-export all models from generated code with V4 namespace * This eliminates the need to manually configure models in config file */ export async function exportModels() { // Read generated models index (relative to project root) const generatedIndexPath = resolve(process.cwd(), 'src/generated/src/models/index.ts'); if (!existsSync(generatedIndexPath)) { throw new Error(`Generated models index not found at: ${generatedIndexPath}\n` + 'Please run "pnpm gen:openapi-types" first.'); } const generatedIndex = readFileSync(generatedIndexPath, 'utf-8'); // Extract all export statements // Pattern: export * from './SomeModel'; // export { type1, type2 } from './SomeModel'; // export type { Type1 } from './SomeModel'; const exportLines = generatedIndex .split('\n') .filter((line) => line.trim().startsWith('export')) .map((line) => line.trim()); // Generate src/index.ts with V4 namespace // Use import/re-export pattern instead of TypeScript namespace to avoid export declaration errors const indexContent = `/** * @simplyhomes/sos-sdk * * TypeScript SDK for Simply Homes SoS API v4 * * @example * \`\`\`typescript * import SimplyHomesSDK, { V4 } from '@simplyhomes/sos-sdk'; * * const sdk = new SimplyHomesSDK({ * environment: 'production', * authToken: 'Bearer your-token-here', * organizationId: 'your-org-id' * }); * * // Use the SDK * const transactions = await sdk.v4.transactions.list.all(); * * // Use types * const property: V4.SoSPropertyEntityBase = { ... }; * \`\`\` */ // Main client class export { SimplyHomesSDK } from './client'; export type { ClientOptions } from './client'; // V4 Namespace for models (future-proof for V5, V6, etc.) // Import all generated types and re-export as V4 namespace import * as V4 from './generated'; export { V4 }; // Also export all types directly for convenience export * from './generated'; // Export utilities - wildcard export for future-proofing export * from './utils'; // Default export for convenience import { SimplyHomesSDK } from './client'; export default SimplyHomesSDK; `; const outputPath = resolve(process.cwd(), 'src/index.ts'); writeFileSync(outputPath, indexContent, 'utf-8'); }