Skip to content

Commit

Permalink
feat(ts): implement exports generation
Browse files Browse the repository at this point in the history
refs #akash-network/console/566, #akash-network/support#212
  • Loading branch information
ygrishajev committed Dec 19, 2024
1 parent f441e78 commit dceb5d1
Show file tree
Hide file tree
Showing 87 changed files with 631 additions and 1,285 deletions.
4 changes: 2 additions & 2 deletions buf.gen.ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins:
strategy: all
path: ./ts/node_modules/.bin/protoc-gen-ts_proto
out: ./ts/src/generated
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true"
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,exportCommonSymbols=false"
- name: grpc-gateway-ts
path: ./ts/node_modules/.bin/protoc-gen-ts_proto
out: ./.cache/tmp/ts/generated-grpc-js
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputServices=grpc-js"
opt: "esModuleInterop=true,forceLong=long,useExactTypes=false,exportCommonSymbols=false,outputServices=grpc-js"
2 changes: 1 addition & 1 deletion docs/proto/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ the granter's account for a deployment.
<a name="akash.deployment.v1.MsgDepositDeploymentResponse"></a>

### MsgDepositDeploymentResponse
MsgCreateDeploymentResponse defines the Msg/CreateDeployment response type.
MsgDepositDeploymentResponse defines response type for the MsgDepositDeployment.



Expand Down
4 changes: 2 additions & 2 deletions docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43721,8 +43721,8 @@ definitions:
akash.deployment.v1.MsgDepositDeploymentResponse:
type: object
description: >-
MsgCreateDeploymentResponse defines the Msg/CreateDeployment response
type.
MsgDepositDeploymentResponse defines response type for the
MsgDepositDeployment.
akash.deployment.v1beta4.MsgCloseDeploymentResponse:
type: object
description: MsgCloseDeploymentResponse defines the Msg/CloseDeployment response type.
Expand Down
2 changes: 1 addition & 1 deletion go/node/deployment/v1/msg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 1 addition & 80 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json && npm run format",
"postbuild": "script/generate-exports.js",
"postbuild": "script/generate-exports.js && script/generate-exports.js",
"format": "prettier --write \"$AKASH_TS_ROOT/**/*.{js,jsx,ts,tsx,css,json}\" --config ./.prettierrc --log-level silent",
"lint": "eslint src",
"lint:fix": "npm run lint -- --fix",
Expand Down Expand Up @@ -65,84 +65,5 @@
},
"peerDependencies": {
"@grpc/grpc-js": "^1.10.6"
},
"exports": {
"./": "./dist/index.js",
"./typeRegistry": "./dist/generated/typeRegistry.js",
"./akash/deployment/v1beta3/query": "./dist/generated/akash/deployment/v1beta3/query.js",
"./deprecated/akash/cert/v1beta1": "./dist/deprecated/index.akash.cert.v1beta1.js",
"./deprecated/akash/market/v1beta1": "./dist/deprecated/index.akash.market.v1beta1.js",
"./v1beta1": "./dist/index.v1beta1.js",
"./v1beta2": "./dist/index.v1beta2.js",
"./v1beta3": "./dist/index.v1beta3.js",
"./v1beta4": "./dist/index.v1beta4.js",
"./akash/audit": "./dist/generated/index.akash.audit.js",
"./akash/audit/v1": "./dist/generated/index.akash.audit.v1.js",
"./akash/audit/v1/grpc-js": "./dist/generated/index.akash.audit.v1.grpc-js.js",
"./akash/base/attributes": "./dist/generated/index.akash.base.attributes.js",
"./akash/base/attributes/v1": "./dist/generated/index.akash.base.attributes.v1.js",
"./akash/base": "./dist/generated/index.akash.base.js",
"./akash/base/resources": "./dist/generated/index.akash.base.resources.js",
"./akash/base/resources/v1beta4": "./dist/generated/index.akash.base.resources.v1beta4.js",
"./akash/cert": "./dist/generated/index.akash.cert.js",
"./akash/cert/v1": "./dist/generated/index.akash.cert.v1.js",
"./akash/cert/v1/grpc-js": "./dist/generated/index.akash.cert.v1.grpc-js.js",
"./akash": "./dist/generated/index.akash.js",
"./akash/deployment": "./dist/generated/index.akash.deployment.js",
"./akash/deployment/v1": "./dist/generated/index.akash.deployment.v1.js",
"./akash/deployment/v1beta4": "./dist/generated/index.akash.deployment.v1beta4.js",
"./akash/deployment/v1beta4/grpc-js": "./dist/generated/index.akash.deployment.v1beta4.grpc-js.js",
"./akash/discovery": "./dist/generated/index.akash.discovery.js",
"./akash/discovery/v1": "./dist/generated/index.akash.discovery.v1.js",
"./akash/escrow": "./dist/generated/index.akash.escrow.js",
"./akash/escrow/v1": "./dist/generated/index.akash.escrow.v1.js",
"./akash/gov": "./dist/generated/index.akash.gov.js",
"./akash/gov/v1beta3": "./dist/generated/index.akash.gov.v1beta3.js",
"./akash/inflation": "./dist/generated/index.akash.inflation.js",
"./akash/inflation/v1beta2": "./dist/generated/index.akash.inflation.v1beta2.js",
"./akash/inflation/v1beta3": "./dist/generated/index.akash.inflation.v1beta3.js",
"./akash/inventory": "./dist/generated/index.akash.inventory.js",
"./akash/inventory/v1": "./dist/generated/index.akash.inventory.v1.js",
"./akash/inventory/v1/grpc-js": "./dist/generated/index.akash.inventory.v1.grpc-js.js",
"./akash/manifest": "./dist/generated/index.akash.manifest.js",
"./akash/manifest/v2beta3": "./dist/generated/index.akash.manifest.v2beta3.js",
"./akash/manifest/v2beta3/grpc-js": "./dist/generated/index.akash.manifest.v2beta3.grpc-js.js",
"./akash/market": "./dist/generated/index.akash.market.js",
"./akash/market/v1": "./dist/generated/index.akash.market.v1.js",
"./akash/market/v1beta5": "./dist/generated/index.akash.market.v1beta5.js",
"./akash/market/v1beta5/grpc-js": "./dist/generated/index.akash.market.v1beta5.grpc-js.js",
"./akash/provider": "./dist/generated/index.akash.provider.js",
"./akash/provider/lease": "./dist/generated/index.akash.provider.lease.js",
"./akash/provider/lease/v1": "./dist/generated/index.akash.provider.lease.v1.js",
"./akash/provider/lease/v1/grpc-js": "./dist/generated/index.akash.provider.lease.v1.grpc-js.js",
"./akash/provider/v1": "./dist/generated/index.akash.provider.v1.js",
"./akash/provider/v1/grpc-js": "./dist/generated/index.akash.provider.v1.grpc-js.js",
"./akash/provider/v1beta4": "./dist/generated/index.akash.provider.v1beta4.js",
"./akash/provider/v1beta4/grpc-js": "./dist/generated/index.akash.provider.v1beta4.grpc-js.js",
"./akash/staking": "./dist/generated/index.akash.staking.js",
"./akash/staking/v1beta3": "./dist/generated/index.akash.staking.v1beta3.js",
"./akash/staking/v1beta3/grpc-js": "./dist/generated/index.akash.staking.v1beta3.grpc-js.js",
"./akash/take": "./dist/generated/index.akash.take.js",
"./akash/take/v1": "./dist/generated/index.akash.take.v1.js",
"./akash/take/v1/grpc-js": "./dist/generated/index.akash.take.v1.grpc-js.js",
"./amino": "./dist/generated/index.amino.js",
"./cosmos/base": "./dist/generated/index.cosmos.base.js",
"./cosmos/base/query": "./dist/generated/index.cosmos.base.query.js",
"./cosmos/base/query/v1beta1": "./dist/generated/index.cosmos.base.query.v1beta1.js",
"./cosmos/base/v1beta1": "./dist/generated/index.cosmos.base.v1beta1.js",
"./cosmos": "./dist/generated/index.cosmos.js",
"./cosmos/msg": "./dist/generated/index.cosmos.msg.js",
"./cosmos/msg/v1": "./dist/generated/index.cosmos.msg.v1.js",
"./cosmos_proto": "./dist/generated/index.cosmos_proto.js",
"./gogoproto": "./dist/generated/index.gogoproto.js",
"./google/api": "./dist/generated/index.google.api.js",
"./google": "./dist/generated/index.google.js",
"./google/protobuf": "./dist/generated/index.google.protobuf.js",
"./k8s": "./dist/generated/index.k8s.js",
"./k8s/io/apimachinery": "./dist/generated/index.k8s.io.apimachinery.js",
"./k8s/io/apimachinery/pkg/api": "./dist/generated/index.k8s.io.apimachinery.pkg.api.js",
"./k8s/io/apimachinery/pkg/api/resource": "./dist/generated/index.k8s.io.apimachinery.pkg.api.resource.js",
"./k8s/io/apimachinery/pkg": "./dist/generated/index.k8s.io.apimachinery.pkg.js",
"./k8s/io": "./dist/generated/index.k8s.io.js"
}
}
4 changes: 2 additions & 2 deletions ts/script/generate-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
const path = require("path");
const staticExports = require("../static-exports.json");

const distDir = path.resolve(__dirname, "../dist/generated");
const distDir = path.resolve(__dirname, "../dist");
const files = fs.readdirSync(distDir);
const paths = files.reduce((acc, file) => {
const match = file.match(/index.(.*)\.d\.ts/);
Expand All @@ -14,7 +14,7 @@ const paths = files.reduce((acc, file) => {
const slashedPath = dottedPath.replace(/\./g, "/");
const resolvedPath = fs.existsSync(`./dist/patch/index.${dottedPath}.js`)
? `./dist/patch/index.${dottedPath}`
: `./dist/generated/index.${dottedPath}`;
: `./dist/index.${dottedPath}`;

acc.tsconfig[`@akashnetwork/akash-api/${slashedPath}`] = [resolvedPath];
acc.package[`./${slashedPath}`] = `${resolvedPath}.js`;
Expand Down
78 changes: 78 additions & 0 deletions ts/script/generate-index-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

const fs = require("fs/promises");
const path = require("path");

async function getAllPaths(dir) {
let results = [];

const entries = await fs.readdir(dir, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const subEntries = await getAllPaths(fullPath);
results = results.concat(subEntries);
} else {
results.push(fullPath);
}
}

return results;
}

const EXCLUSIONS = ["genesis", "params", "service", "query"];

(async () => {
const directory = path.resolve(__dirname, "../src/generated");
const allPaths = await getAllPaths(directory);
const root = `${process.cwd()}/ts/src/generated/`;
const nsWithExports = allPaths
.filter((path) => !path.endsWith("d.ts") && path.endsWith(".ts"))
.reduce((acc, path) => {
const relativePath = path.replace(root, "").replace(".ts", "");
const pathParts = relativePath.split("/");
const [fileName] = pathParts.splice(pathParts.length - 1, 1);

const ns = pathParts.join(".");

if (!ns || !ns.includes("akash")) {
return acc;
}

if (!acc[ns]) {
acc[ns] = [];
}

acc[ns].push(relativePath);

const version = pathParts[pathParts.length - 1];

if (EXCLUSIONS.includes(fileName)) {
return acc;
}

if (!acc[version]) {
acc[version] = [];
}

acc[version].push(relativePath);

return acc;
}, {});

const namespaces = Object.keys(nsWithExports);

namespaces.forEach((ns) => {
const nsExports = nsWithExports[ns];
const content = nsExports.reduce((acc, file) => {
return `${acc}export * from "./${file}";\n`;
}, "");

fs.writeFile(
path.resolve(__dirname, `../src/generated/index.${ns}.ts`),
content,
"utf8",
);
});
})();
2 changes: 0 additions & 2 deletions ts/src/generated/akash/audit/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions ts/src/generated/akash/cert/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ts/src/generated/akash/deployment/v1/msg.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions ts/src/generated/akash/deployment/v1beta4/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions ts/src/generated/akash/inventory/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dceb5d1

Please sign in to comment.