Skip to content

Commit

Permalink
feat: add dymension's osmosis-fork's protobufs
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCQL committed Feb 22, 2024
1 parent 79e3f27 commit c6c5d0d
Show file tree
Hide file tree
Showing 148 changed files with 10,013 additions and 9,556 deletions.
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version: v1
plugins:
- plugin: es
opt: target=ts
out: src/protobufs
out: .
- plugin: cosmes
path: ./scripts/protoc-gen-cosmes.mjs
opt: target=ts
out: src/protobufs
out: .
60 changes: 54 additions & 6 deletions scripts/gen-protobufs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

import { spawnSync } from "child_process";
import degit from "degit";
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import {
mkdirSync,
readFileSync,
readdirSync,
renameSync,
rmSync,
statSync,
writeFileSync,
} from "fs";
import { globSync } from "glob";
import { capitalize } from "lodash-es";
import { dirname, join } from "path";
Expand All @@ -27,7 +35,7 @@ import { fileURLToPath } from "url";
*/
const REPOS = [
{
repo: "cosmos/cosmos-sdk#main",
repo: "cosmos/cosmos-sdk#v0.47.9",
paths: ["proto"],
},
{
Expand All @@ -54,6 +62,10 @@ const REPOS = [
repo: "evmos/ethermint#main",
paths: ["proto"],
},
{
repo: "dymensionxyz/osmosis#main-dym",
paths: ["proto"],
},
];

const __dirname = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -81,15 +93,51 @@ console.log("Generating TS files from proto files...");
{
for (const { repo, paths } of REPOS) {
for (const path of paths) {
spawnSync("pnpm", ["buf", "generate", join(TMP_DIR, id(repo), path)], {
cwd: process.cwd(),
stdio: "inherit",
});
spawnSync(
"pnpm",
[
"buf",
"generate",
join(TMP_DIR, id(repo), path),
"--output",
join(
PROTOBUFS_DIR,
repo.startsWith("dymensionxyz") ? "dymension" : ""
),
],
{
cwd: process.cwd(),
stdio: "inherit",
}
);
}
console.log(`✔️ [${repo}]`);
}
}

console.log("Flattening dymension protobufs...");
{
// Move all dirs in protobufs/dymension/osmosis out into protobufs/dymension
const dymensionDir = join(PROTOBUFS_DIR, "dymension");
const dymensionOsmosisDir = join(dymensionDir, "osmosis");
// Move all subdirs up one level
readdirSync(dymensionOsmosisDir).forEach((file) => {
const currentFile = join(dymensionOsmosisDir, file);
const stats = statSync(currentFile);
if (stats.isDirectory()) {
renameSync(currentFile, join(dymensionDir, file));
}
});
// Remove all empty dirs
readdirSync(dymensionDir).forEach((file) => {
const currentFile = join(dymensionDir, file);
const stats = statSync(currentFile);
if (stats.isDirectory() && stats.size === 0) {
rmSync(currentFile, { recursive: true, force: true });
}
});
}

console.log("Generating src/index.ts file and renaming exports...");
{
const LAST_SEGMENT_REGEX = /[^/]+$/;
Expand Down
Loading

0 comments on commit c6c5d0d

Please sign in to comment.