Skip to content

Commit

Permalink
feat: api mode with vercel deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarialounes committed Jul 5, 2024
1 parent 25ae4c8 commit f21de1b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "./scripts/build.sh && npm run make",
"make": "NODE_OPTIONS='--experimental-specifier-resolution=node --loader ts-node/esm --experimental-modules' node scripts/make.mjs",
"utils:gen:config": "NODE_OPTIONS='--experimental-specifier-resolution=node --loader ts-node/esm --experimental-modules' node scripts/genconfig.ts",
"utils:gen:predoc": "npx jsonschema2mk --schema chains/chain.schema.json >PREDOC.md"
},
Expand Down
7 changes: 7 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

shopt -s dotglob

cp chains/* public

exit 0
5 changes: 5 additions & 0 deletions scripts/make.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { default as writeFile } from "./utils/useWriteFile.mjs";
import { default as chainList } from "./utils/useChainList.mjs";

writeFile(JSON.stringify(chainList(true)), "./public/mainnet-chains.json");
writeFile(JSON.stringify(chainList(false)), "./public/testnet-chains.json");
35 changes: 35 additions & 0 deletions scripts/utils/useChainList.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as fs from "fs";
import { default as loadJson } from "./useLoadJson.mjs";

export default function (isMainnet) {
const env = isMainnet ? 'mainnets' : 'testnets';
const files = fs.readdirSync(`./chains/${env}`).sort()
const data = {};

for (let i = 0; i < files.length; i++) {
if (["protocol.schema.json", "_template"].includes(files[i])) {
continue;
}

const {
name,
chainName,
logo_URIs,
denomUpper,
coinGeckoId,
isExplorerEnabled,
isFeatured,
} = loadJson(`./../../chains/${env}/${files[i]}/chain.json`);

data[name] = {
chainName,
logo_URIs,
denomUpper,
coinGeckoId,
isExplorerEnabled,
isFeatured,
}
}

return data;
};
5 changes: 5 additions & 0 deletions scripts/utils/useLoadJson.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as fs from "fs";

export default function (path) {
return JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
}
9 changes: 9 additions & 0 deletions scripts/utils/useWriteFile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as fs from "fs";

export default function (content, path) {
fs.writeFile(path, content, (err) => {
if (err) {
console.error(err);
}
});
};

0 comments on commit f21de1b

Please sign in to comment.