From e1e483a2b0641c755e4ad0a23b4d929bfdb9f087 Mon Sep 17 00:00:00 2001 From: Ghali El Ouarzazi Date: Fri, 16 Jun 2023 19:28:41 +0200 Subject: [PATCH] fix build for optimized npm package, add example, improve tsconfig fo d.ts files --- .gitignore | 2 +- package.json | 3 ++- src/index.ts | 28 ++++++++++++++++------------ tsconfig.json | 6 ++++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index dd4bafa..1511d56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules -/build +build .env* .vscode .DS_Store diff --git a/package.json b/package.json index 2b1eb10..bd2ff2f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "avail-js-sdk", - "version": "0.0.3", + "version": "0.0.6", "description": "Avail library of functions to interact with blockchain and manipulate transactions", "main": "./build/index.js", "scripts": { "start": "ts-node src/index.ts", "dev": "nodemon src/index.ts", "build": "rimraf build && tsc && node ./src/_scripts/build.mjs", + "publish-avail": "npm run lint && npm run format && npm run build && cd build && npm publish && cd ..", "test": "npx jest --config jest.config.ts", "format": "prettier --write .", "lint": "eslint ./src --ext .js,.ts" diff --git a/src/index.ts b/src/index.ts index 84d1111..dbcf397 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,20 @@ import { disconnect, initialize, isConnected } from "./chain" -const main = async () => { - const api = await initialize() - const chain = await api.rpc.system.chain() - console.log(`Chain: ${chain} - Is connected: ${isConnected()}`) - await disconnect() -} -main() +// const main = async () => { +// const api = await initialize() +// const chain = await api.rpc.system.chain() +// console.log(`Chain: ${chain} - Is connected: ${isConnected()}`) +// await disconnect() +// } +// main() -export * from './chain' -export * from './spec' -export * from '@polkadot/api' +// Allows for generic imports (eg. import {...} from 'avail-js-sdk') +export * from "./chain" +export * from "./spec" -export * as chain from './chain' -export * as spec from './spec' +// Allows for custom imports (eg. import {...} from 'avail-js-sdk/chain') +export * as chain from "./chain" +export * as spec from "./spec" + +// Re-exports to avoid duplicattion +export * from "@polkadot/api" diff --git a/tsconfig.json b/tsconfig.json index 54d7e23..0807f47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,11 +2,13 @@ "compilerOptions": { "target": "es2016", "module": "commonjs", - "outDir": "./build", + "outDir": "build", + "declaration": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, - "skipLibCheck": true + "skipLibCheck": true, + "noUnusedParameters": true }, "include": ["src"], "exclude": ["node_modules", "build"]