Skip to content

Commit

Permalink
Re-export all models as a top-level export (#534)
Browse files Browse the repository at this point in the history
This PR re-exports all models in the entrypoint `nylas.ts` file, allowing users to easily import all models; e.g:

```ts
import Nylas, { WebhookTriggers } from "nylas";
```

The nylas entrypoint exports everything fro models/index.ts, which is a file that's generated by script in the prebuild step of `npm build`.
  • Loading branch information
mrashed-dev authored Feb 7, 2024
1 parent 19678d9 commit ede9b1a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Models can now directly be imported from the top-level `nylas` package

### 7.0.0 / 2024-02-05
* **BREAKING CHANGE**: Node SDK v7 supports the Nylas API v3 exclusively, dropping support for any endpoints that are not available in v3.
* **BREAKING CHANGE**: Convert `Nylas` class from a static to a non-static class
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"lint:prettier:check": "prettier --check '**/*.{ts,js}'",
"export-version": "node scripts/exportVersion.js",
"generate-lib-package-json": "node scripts/generateLibPackageJson.js",
"prebuild": "npm run export-version",
"generate-model-index": "node scripts/generateModelIndex.js",
"prebuild": "npm run export-version && npm run generate-model-index",
"build": "rm -rf lib && npm run build-esm && npm run build-cjs && npm run generate-lib-package-json",
"build-esm": "tsc -p tsconfig.esm.json",
"build-cjs": "tsc -p tsconfig.cjs.json",
Expand Down
15 changes: 15 additions & 0 deletions scripts/generateModelIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs');
const path = require('path');

const comment = '// This file is generated by scripts/generateModelIndex.js\n';
const modelsDir = path.join(__dirname, '..', 'src', 'models');
let indexContent = '';

fs.readdirSync(modelsDir).forEach(file => {
if (file.endsWith('.ts') && file !== 'index.ts') {
const modelName = file.replace('.ts', '.js');
indexContent += `export * from './${modelName}';\n`;
}
});

fs.writeFileSync(path.join(modelsDir, 'index.ts'), comment + indexContent);
22 changes: 22 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is generated by scripts/generateModelIndex.js
export * from './applicationDetails.js';
export * from './attachments.js';
export * from './auth.js';
export * from './availability.js';
export * from './calendars.js';
export * from './connectors.js';
export * from './contacts.js';
export * from './credentials.js';
export * from './drafts.js';
export * from './error.js';
export * from './events.js';
export * from './folders.js';
export * from './freeBusy.js';
export * from './grants.js';
export * from './listQueryParams.js';
export * from './messages.js';
export * from './redirectUri.js';
export * from './response.js';
export * from './smartCompose.js';
export * from './threads.js';
export * from './webhooks.js';
2 changes: 2 additions & 0 deletions src/nylas.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './models/index.js';

import APIClient from './apiClient.js';
import { NylasConfig, DEFAULT_SERVER_URL } from './config.js';
import { Calendars } from './resources/calendars.js';
Expand Down

0 comments on commit ede9b1a

Please sign in to comment.