From a09a6a843f5186cbad1a25d648198a12448c8cfa Mon Sep 17 00:00:00 2001 From: Zakaria Lounes Date: Mon, 12 Aug 2024 12:12:42 +0200 Subject: [PATCH] chore: restructure before moving to app-api-v2 --- .gitignore | 1 + .nvmrc | 1 + build/.gitkeep | 0 package.json | 4 +-- scripts/build.sh | 3 +- scripts/genconfig.ts | 86 -------------------------------------------- 6 files changed, 5 insertions(+), 90 deletions(-) create mode 100644 .nvmrc delete mode 100644 build/.gitkeep delete mode 100644 scripts/genconfig.ts diff --git a/.gitignore b/.gitignore index 7a1537b..6bf67d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea node_modules +public diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..af9754b --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20.8.1 diff --git a/build/.gitkeep b/build/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 1772ec1..aaee232 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,7 @@ "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" + "make": "NODE_OPTIONS='--experimental-specifier-resolution=node --loader ts-node/esm --experimental-modules' node scripts/make.mjs" }, "repository": { "type": "git", diff --git a/scripts/build.sh b/scripts/build.sh index 38051b2..249bc74 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,8 +2,9 @@ shopt -s dotglob +rm -rf public mkdir public cp -r chains public -cp vercel.json public +# cp vercel.json public exit 0 diff --git a/scripts/genconfig.ts b/scripts/genconfig.ts deleted file mode 100644 index bcf7e85..0000000 --- a/scripts/genconfig.ts +++ /dev/null @@ -1,86 +0,0 @@ -require("dotenv").config({path: ["ui/.env.local", "ui/.env"]}); - -const processIcs = (network, provider) => { - if (network.isAConsumerChain && network.providerChain && provider) { - network.providerRpcUrl = provider.rpcUrl; - network.providerRestUrl = provider.restUrl; - } - - return network; -}; - -const getNetworks = (isMainnet) => { - const fs = require("node:fs"); - const env = isMainnet ? "mainnets" : "testnets"; - const files = fs.readdirSync(`./chains/${env}`); - - const networksData = {}; - - // Retrieve data first to avoid consumers not having providers already populated. - for (let i = 0; i < files.length; i++) { - networksData[files[i]] = require( - `./../chains/${env}/${files[i]}/chain.json`, - ); - } - - // Update data for consumers chains. - for (let i = 0; i < files.length; i++) { - if (networksData[files[i]].providerChain) { - networksData[files[i]] = processIcs( - networksData[files[i]], - networksData[networksData[files[i]].providerChain], - ); - } - } - - return networksData; -}; - -const writeConfig = (content, path) => { - const fs = require("node:fs"); - fs.writeFile(path, content, (err) => { - if (err) { - console.error(err); - } - }); -}; - -(function () { - console.log( - "Generate Config...", - { - isMainnet: process.env.NUXT_PUBLIC_PROTOCOLS_TESTNET_MODE !== "true", - }, - typeof process.env.NUXT_PUBLIC_PROTOCOLS_TESTNET_MODE, - ); - - const networks = getNetworks( - process.env.NUXT_PUBLIC_PROTOCOLS_TESTNET_MODE !== "true", - ); - - const featuredNetworksAsArray = Object.keys(networks).filter( - (network) => networks[network].isFeatured, - ); - - const config = JSON.stringify( - { - version: "beta " + process.env.NUXT_ENV_APP_VERSION, - protocolsStyles: { - // @important: any changes here should be replicated to `./assets/root.sass` - default: { - primary: "#424242", - light: "#FFF", - dark: "#000", - }, - }, - networks, - featuredNetworksAsArray, - }, - null, - 2, - ); - - writeConfig(config, "./build/raw-config.json"); - - console.debug("Generated."); -})();