From 56b0cda2f3303137ff40d9a5c5a8b29b72060733 Mon Sep 17 00:00:00 2001 From: Hieu Phan Date: Tue, 17 May 2022 16:27:17 +0700 Subject: [PATCH] Export types (#4) * Export types * CI check format Signed-off-by: Nguyen Le Vu Long Co-authored-by: Nguyen Le Vu Long --- .eslintignore | 1 + .github/workflows/ci.yml | 4 ++-- .prettierignore | 1 + package-lock.json | 6 ++++++ package.json | 4 +++- scripts/pump-version.sh | 29 +++++++++++++++++++++++++++++ src/index.ts | 7 +++++-- src/tokens/aada.ts | 8 ++------ src/tokens/agix.ts | 7 ++----- src/tokens/clap.ts | 8 ++------ src/tokens/cneta.ts | 8 ++------ src/tokens/lq.ts | 8 ++------ src/tokens/meld.ts | 7 ++----- src/tokens/milk.ts | 8 ++------ src/tokens/min.ts | 8 ++------ src/tokens/mint.ts | 11 +++-------- src/tokens/ntx.ts | 7 ++----- src/tokens/sundae.ts | 8 ++------ src/types.ts | 19 +++++++++++++++++++ src/utils.ts | 18 +----------------- 20 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 .eslintignore create mode 100644 .prettierignore create mode 100755 scripts/pump-version.sh create mode 100644 src/types.ts diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a6cddfb..fb660afa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,11 @@ jobs: node-version: 14.x - name: Install dependencies run: npm ci + - name: Check format + run: npm run check-format - name: Run build run: npm run build - name: Run test run: npm test env: BLOCKFROST_PROJECT_ID: ${{ secrets.BLOCKFROST_PROJECT_ID }} - - name: Run lint - run: npm run lint diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +build diff --git a/package-lock.json b/package-lock.json index 8ad6c0ce..49261bf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4707,6 +4707,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz", + "integrity": "sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==", + "dev": true + }, "pretty-format": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", diff --git a/package.json b/package.json index a2be4246..c008c44d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "scripts": { "build": "rimraf build && rollup -c rollup.config.js", "test": "jest", - "lint": "eslint src --ext .ts" + "format": "prettier --write **/*.{ts,tsx} && eslint --fix --ext .ts,.tsx .", + "check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx ." }, "keywords": [ "minswap", @@ -46,6 +47,7 @@ "eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-unused-imports": "^2.0.0", "jest": "^28.0.1", + "prettier": "^2.6.2", "rollup": "^2.70.2", "rollup-plugin-dts": "^4.2.1", "rollup-plugin-esbuild": "^4.9.1", diff --git a/scripts/pump-version.sh b/scripts/pump-version.sh new file mode 100755 index 00000000..9b98f2b0 --- /dev/null +++ b/scripts/pump-version.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +version=$1 + +echo "update version field" +jq ".version = \"$version\"" package.json.tmp +mv package.json.tmp package.json + +jq ".version = \"$version\"" package-lock.json.tmp +mv package-lock.json.tmp package-lock.json + +echo "build" +npm run build + +echo "publish" +npm publish + +echo "commit new version" +git add package.json package-lock.json +git commit -m "publish version v$version" + +echo "tag version" +git tag v"$version" + +echo "push to remote" +git push origin main +git push origin v"$version" diff --git a/src/index.ts b/src/index.ts index 57b2cb17..09da3e66 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,9 @@ import minFetcher from "./tokens/min"; import mintFetcher from "./tokens/mint"; import ntxFetcher from "./tokens/ntx"; import sundaeFetcher from "./tokens/sundae"; -import { SupplyFetcher } from "./utils"; +import { SupplyFetcher } from "./types"; + +export * from "./types"; export const supplyFetchers: Record = { "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e": minFetcher, @@ -27,5 +29,6 @@ export const supplyFetchers: Record = { db30c7905f598ed0154de14f970de0f61f0cb3943ed82c891968480a434c4150: clapFetcher, b34b3ea80060ace9427bda98690a73d33840e27aaa8d6edb7f0c757a634e455441: cnetaFetcher, - "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74": mintFetcher, + "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74": + mintFetcher, }; diff --git a/src/tokens/aada.ts b/src/tokens/aada.ts index a77cad90..9e64d6f1 100644 --- a/src/tokens/aada.ts +++ b/src/tokens/aada.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const AADA = "8fef2d34078659493ce161a6c7fba4b56afefa8535296a5743f6958741414441"; diff --git a/src/tokens/agix.ts b/src/tokens/agix.ts index be1b3d38..c973f96c 100644 --- a/src/tokens/agix.ts +++ b/src/tokens/agix.ts @@ -1,8 +1,5 @@ -import { - defaultFetcherOptions, - getAxiosInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAxiosInstance } from "../utils"; const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => { const axios = getAxiosInstance(options); diff --git a/src/tokens/clap.ts b/src/tokens/clap.ts index 707573a9..007ed2bf 100644 --- a/src/tokens/clap.ts +++ b/src/tokens/clap.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const CLAP = "db30c7905f598ed0154de14f970de0f61f0cb3943ed82c891968480a434c4150"; diff --git a/src/tokens/cneta.ts b/src/tokens/cneta.ts index bdb79340..9a429cd4 100644 --- a/src/tokens/cneta.ts +++ b/src/tokens/cneta.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const CNETA = "b34b3ea80060ace9427bda98690a73d33840e27aaa8d6edb7f0c757a634e455441"; diff --git a/src/tokens/lq.ts b/src/tokens/lq.ts index 842e5865..8c156dff 100644 --- a/src/tokens/lq.ts +++ b/src/tokens/lq.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const LQ = "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d244c51"; diff --git a/src/tokens/meld.ts b/src/tokens/meld.ts index 3647bde6..45e6c1e7 100644 --- a/src/tokens/meld.ts +++ b/src/tokens/meld.ts @@ -1,8 +1,5 @@ -import { - defaultFetcherOptions, - getAxiosInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAxiosInstance } from "../utils"; const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => { const axios = getAxiosInstance(options); diff --git a/src/tokens/milk.ts b/src/tokens/milk.ts index f44197cf..f54da001 100644 --- a/src/tokens/milk.ts +++ b/src/tokens/milk.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const MILK = "8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa4d494c4b"; diff --git a/src/tokens/min.ts b/src/tokens/min.ts index c35f1f5c..52b9cd4e 100644 --- a/src/tokens/min.ts +++ b/src/tokens/min.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"; const TREASURY_ADDRESSES = [ diff --git a/src/tokens/mint.ts b/src/tokens/mint.ts index ec1b114a..fd499217 100644 --- a/src/tokens/mint.ts +++ b/src/tokens/mint.ts @@ -1,10 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, - SupplyFetcherResponse, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const MINT = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74"; const TREASURY_ADDRESSES = [ @@ -12,7 +7,7 @@ const TREASURY_ADDRESSES = [ "addr1w9p9akyhpqsy0xq79g8hspy90xl9htxfrd3mama6py42jjgtvfgn8", // DripDropz ]; -const fetcher: SupplyFetcher = async (options = defaultFetcherOptions): Promise => { +const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => { const blockFrost = getBlockFrostInstance(options); const total = 100_000_000; const treasury = diff --git a/src/tokens/ntx.ts b/src/tokens/ntx.ts index 44a5b253..4b88ead8 100644 --- a/src/tokens/ntx.ts +++ b/src/tokens/ntx.ts @@ -1,8 +1,5 @@ -import { - defaultFetcherOptions, - getAxiosInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAxiosInstance } from "../utils"; const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => { const axios = getAxiosInstance(options); diff --git a/src/tokens/sundae.ts b/src/tokens/sundae.ts index 0fe0b392..03eef2f2 100644 --- a/src/tokens/sundae.ts +++ b/src/tokens/sundae.ts @@ -1,9 +1,5 @@ -import { - defaultFetcherOptions, - getAmountInAddresses, - getBlockFrostInstance, - SupplyFetcher, -} from "../utils"; +import { defaultFetcherOptions, SupplyFetcher } from "../types"; +import { getAmountInAddresses, getBlockFrostInstance } from "../utils"; const SUNDAE = "9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145"; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..83cdcec2 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,19 @@ +export type FetcherOptions = { + /** + * Fetch timeout in milliseconds. Default to 20s + */ + timeout?: number; +}; + +export const defaultFetcherOptions: FetcherOptions = { + timeout: 20_000, +}; + +export type SupplyFetcherResponse = { + circulating: string; + total: string; +}; + +export type SupplyFetcher = ( + options?: FetcherOptions +) => Promise; diff --git a/src/utils.ts b/src/utils.ts index 680d1c0f..7f83989c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,23 +1,7 @@ import { BlockFrostAPI } from "@blockfrost/blockfrost-js"; import axios, { AxiosInstance } from "axios"; -export type FetcherOptions = { - /** - * Fetch timeout in milliseconds. Default to 20s - */ - timeout?: number; -}; - -export const defaultFetcherOptions: FetcherOptions = { - timeout: 20_000, -}; - -export type SupplyFetcherResponse = { - circulating: string; - total: string; -} - -export type SupplyFetcher = (options?: FetcherOptions) => Promise; +import { FetcherOptions } from "./types"; export function getBlockFrostInstance(options: FetcherOptions): BlockFrostAPI { return new BlockFrostAPI({