Skip to content

Commit

Permalink
extract config from common as a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Jan 25, 2024
1 parent df0ae4e commit bcf8303
Show file tree
Hide file tree
Showing 38 changed files with 258 additions and 317 deletions.
8 changes: 0 additions & 8 deletions common/build-config.ts

This file was deleted.

11 changes: 0 additions & 11 deletions common/build-others.ts

This file was deleted.

3 changes: 0 additions & 3 deletions common/config/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion common/lib/apis/api-covalent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getChecksumAddress } from "@lib/common/config";
import { DEFAULT_NAME, DEFAULT_SYMBOL } from "@lib/common/config";
import { fetchJson, FETCH_LIMIT } from "@lib/common/fetch";
import { keyCollection, keyNft } from "@lib/common/keys";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";
import { networks } from "@lib/common/networks";

const _covalentUrlPath = (chainId: number, path: string): string => {
Expand Down
2 changes: 1 addition & 1 deletion common/lib/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Fragment, Interface } from "@ethersproject/abi";

import type { CollectionType, NftType, RefPageType, AddressesType } from "@lib/common/types";

import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";
import addressesRaw from "@kredeum/contracts/addresses.json";

import { formatEther } from "ethers/lib/utils";
Expand Down
2 changes: 1 addition & 1 deletion common/lib/common/ens-get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { providers } from "ethers";

import { JsonRpcProvider } from "@ethersproject/providers";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";

const ens = (() => {
const ensProvider: JsonRpcProvider = new providers.JsonRpcProvider(config.ens.rpcUrl);
Expand Down
4 changes: 2 additions & 2 deletions common/lib/common/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NetworkType, NftType } from "@lib/common/types";
import mainnetsJson from "@config/mainnets.json";
import testnetsJson from "@config/testnets.json";
import mainnetsJson from "@kredeum/config/dist/mainnets.json";
import testnetsJson from "@kredeum/config/dist/testnets.json";

const networks = (() => {
const _networksMap = new Map(
Expand Down
2 changes: 1 addition & 1 deletion common/lib/nft/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { NftType, StorageConfigType, StorageParamsType, StorageType } from "@lib/common/types";
import { ipfsGateway, ipfsGatewayUrl, ipfsLinkToUrlHttp, ipfsGetLink } from "./ipfs";
import { swarmGateway, swarmGatewayUrl, swarmLinkToUrlHttp, swarmGetLink } from "./swarm";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";

// IN MEMORY Storage Config
let _storageConfig: StorageConfigType;
Expand Down
9 changes: 4 additions & 5 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"lib": "lib"
},
"scripts": {
"clean": "rm -rf node_modules types abis config/networks.json",
"format": "prettier lib/**/*.ts --write --list-different --loglevel log",
"check": "eslint lib/**/*.ts",
"build": "pnpx ts-node build-config && pnpx ts-node build-others"
"clean": "rm -rf node_modules types abis",
"format": "prettier lib/**/*.ts --write --list-different",
"check": "eslint lib/**/*.ts"
},
"keywords": [],
"author": "",
Expand All @@ -36,7 +35,6 @@
"ethers": "^5.7.2",
"findup-sync": "^5.0.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",
"multiformats": "^12.1.3",
"pdfjs-dist": "^3.11.174",
"prettier": "^3.2.4",
Expand All @@ -45,6 +43,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@kredeum/config": "workspace:^",
"@kredeum/contracts": "workspace:^"
}
}
1 change: 0 additions & 1 deletion common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"paths": {
"@lib/*": ["common/lib/*"],
"@utils/*": ["common/utils/*"],
"@config/*": ["common/config/*"],
"@soltypes/*": ["contracts/types/*"],
"@artifacts/*": ["contracts/out/*"]
}
Expand Down
17 changes: 0 additions & 17 deletions common/turbo.json

This file was deleted.

19 changes: 0 additions & 19 deletions common/utils/getNonce.ts

This file was deleted.

18 changes: 0 additions & 18 deletions common/utils/runHandlebarsConfig.ts

This file was deleted.

31 changes: 0 additions & 31 deletions common/utils/runHandlebarsEnv.ts

This file was deleted.

1 change: 1 addition & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
19 changes: 19 additions & 0 deletions config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@kredeum/config",
"version": "1.4.0",
"description": "",
"main": "index.ts",
"scripts": {
"clean": "rm -rf node_modules dist",
"build": "pnpx ts-node scripts/build.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.6",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8"
}
}
9 changes: 9 additions & 0 deletions config/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { runHandlebarsEnv, runHandlebarsConfig } from "./handlebars";

const main = async (): Promise<void> => {
await runHandlebarsEnv("src/config.handlebars.json", "dist/config.json");
await runHandlebarsEnv("src/mainnets.handlebars.json", "dist/mainnets.json");
await runHandlebarsEnv("src/testnets.handlebars.json", "dist/testnets.json");
};

main().catch(console.error);
33 changes: 33 additions & 0 deletions config/scripts/handlebars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { outputFile, readFile } from "fs-extra";
import Handlebars from "handlebars";

const runHandlebars = (buffer: string, vars: any): string => {
const template = Handlebars.compile(buffer);

const result = template(vars);
// console.log("runHandlebars ~ result:", result);

return result;
};

const runHandlebarsEnv = async (pathIN: string, pathOUT: string): Promise<void> => {
const buffer = String(await readFile(pathIN));

const result = runHandlebars(buffer, process.env);

await outputFile(pathOUT, result);

console.log("runHandlebarsEnv ", pathIN, "=>", pathOUT);
};

const runHandlebarsConfig = async (pathIN: string, pathOUT: string, config: any): Promise<void> => {
const buffer = String(await readFile(pathIN));

const result = runHandlebars(buffer, config);

await outputFile(pathOUT, result);

console.log("runHandlebarsConfig", pathIN, "=>", pathOUT);
};

export { runHandlebars, runHandlebarsConfig, runHandlebarsEnv };
File renamed without changes.
Loading

0 comments on commit bcf8303

Please sign in to comment.