-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): exports all the generated namespaces (#184)
- Loading branch information
1 parent
14b1f7d
commit 4148a5c
Showing
213 changed files
with
552 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env ts-node | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const distDir = path.resolve(__dirname, '../dist/generated'); | ||
const files = fs.readdirSync(distDir); | ||
const paths = files.reduce( | ||
(acc, file) => { | ||
const match = file.match(/index.(.*)\.d\.ts/); | ||
|
||
if (match) { | ||
const dottedPath = match[1]; | ||
const slashedPath = dottedPath.replace(/\./g, '/'); | ||
const resolvedPath = `./dist/generated/index.${dottedPath}`; | ||
|
||
acc.tsconfig[`@akashnetwork/akash-api/${slashedPath}`] = [resolvedPath]; | ||
acc.package[`./${slashedPath}`] = `${resolvedPath}.js`; | ||
} | ||
|
||
return acc; | ||
}, | ||
{ package: {}, tsconfig: {} }, | ||
); | ||
|
||
const tsconfigPaths = path.resolve(__dirname, '../tsconfig.paths.json'); | ||
fs.writeFileSync( | ||
tsconfigPaths, | ||
JSON.stringify({ compilerOptions: { paths: paths.tsconfig } }, null, 2), | ||
); | ||
|
||
const packageJson = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'), | ||
); | ||
packageJson.exports = paths.package; | ||
fs.writeFileSync( | ||
path.resolve(__dirname, '../package.json'), | ||
JSON.stringify(packageJson, null, 2), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ts-node | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const packageJson = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'), | ||
); | ||
delete packageJson.exports; | ||
fs.writeFileSync( | ||
path.resolve(__dirname, '../package.json'), | ||
JSON.stringify(packageJson, null, 2), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/dist | ||
/build | ||
/node_modules | ||
tsconfig.paths.json | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ts/node_modules/.bin/lint-staged --cwd ts | ||
ts/node_modules/.bin/lint-staged --cwd ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Akash API TypeScript Bindings | ||
|
||
[![npm version](https://badge.fury.io/js/%40akashnetwork%2Fakash-api.svg)](https://badge.fury.io/js/%40akashnetwork%2Fakash-api) | ||
[![License: Apache-2.0](https://img.shields.io/badge/License-apache2.0-yellow.svg)](https://opensource.org/license/apache-2-0) | ||
|
||
This package provides TypeScript bindings for the Akash API, generated from protobuf definitions. | ||
|
||
## Installation | ||
|
||
To install the package, run: | ||
|
||
```bash | ||
npm install @akashnetwork/akash-api | ||
``` | ||
|
||
## Usage | ||
|
||
You can import the generated namespaces from the package like this: | ||
```typescript | ||
import * as akashDeploymentV1beta1 from '@akashnetwork/akash-api/akash/deployment/v1beta1'; | ||
import * as akashDiscoveryV1 from '@akashnetwork/akash-api/akash/discovery/v1'; | ||
// ... and so on for other namespaces | ||
``` | ||
|
||
### TypeScript 4.5 and above | ||
If you're using TypeScript 4.5 or above, the package exports all the paths of the generated namespaces, so you can import them directly. | ||
|
||
### TypeScript below 4.5 | ||
If you're using a version of TypeScript below 4.5, the package provides a tsconfig.paths.json file that you can extend in your local TypeScript configuration to resolve the paths. Here's how you can do it: In your tsconfig.json file, add the following: | ||
```json | ||
{ | ||
"extends": "@akashnetwork/akash-api/tsconfig.paths.json" | ||
} | ||
``` | ||
|
||
### Contributing | ||
Contributions are welcome. Please submit a pull request or create an issue to discuss the changes you want to make. | ||
|
||
### License | ||
This package is licensed under the Apache-2.0. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.