Skip to content

Commit

Permalink
Export x packages from the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSchwert committed Jan 15, 2024
1 parent a057b27 commit b70dae5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
24 changes: 23 additions & 1 deletion sdk/scripts/generateIndex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import fs from 'fs';
import path from 'path';

const deprecateMessage = (message) => (
`/**
* @deprecated ${message}
*/\n`
);

const dirname = path.dirname(new URL(import.meta.url).pathname);

// Read the JSON file
Expand All @@ -12,8 +18,17 @@ const moduleData = JSON.parse(fileData);
// Get the release type from the environment variable or default to 'alpha'
const releaseType = process.env.RELEASE_TYPE || 'alpha';


let indexFileContent = `import * as imxClient from './immutablex_client';
import * as imxProvider from './provider';
export const x = {
client: imxClient,
provider: imxProvider,
};
`;

// Generate the index.ts file contents based on the release type
let indexFileContent = '';
Object.keys(moduleData.modules).forEach((moduleName) => {
const moduleReleaseType = moduleData.modules[moduleName];

Expand All @@ -31,6 +46,13 @@ Object.keys(moduleData.modules).forEach((moduleName) => {
})
.join('');

if (moduleName === 'immutablex_client') {
indexFileContent += deprecateMessage(`Use x.client or /x/client instead.`);
};
if (moduleName === 'provider') {
indexFileContent += deprecateMessage(`Use x.provider or /x/provider instead.`);
};

const modulePath = `./${moduleName}`;
const exportStatement = `export * as ${moduleNameCapitalized} from '${modulePath}';\n`;
indexFileContent += exportStatement;
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import * as imxClient from './immutablex_client';
import * as imxProvider from './provider';

export const x = {
client: imxClient,
provider: imxProvider,
};
export * as config from './config';
export * as blockchainData from './blockchain_data';
/**
* @deprecated Use x.client or /x/client instead.
*/
export * as immutablexClient from './immutablex_client';
export * as passport from './passport';
export * as orderbook from './orderbook';
/**
* @deprecated Use x.provider or /x/provider instead.
*/
export * as provider from './provider';
export * as checkout from './checkout';

0 comments on commit b70dae5

Please sign in to comment.