Skip to content

Commit

Permalink
feat: publish to registries + build process (#14)
Browse files Browse the repository at this point in the history
* publish to registries + build process

* feat: add pnpm lockfile

---------

Co-authored-by: 0xsign <0xsign@protonmail.com>
  • Loading branch information
o-az and 0xsign authored May 8, 2023
1 parent 60a623d commit 99b6f71
Show file tree
Hide file tree
Showing 26 changed files with 3,397 additions and 1,545 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV="development"
103 changes: 103 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: 'Release'

on:
workflow_dispatch:
push:
tags:
- 'v*'
branches:
# for debugging purposes
- 'debug-*'

defaults:
run:
shell: bash

env:
# Enable debug logging for actions
ACTIONS_RUNNER_DEBUG: true

jobs:
changelog:
name: 'Generate Changelog'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: 'Generate Changelog'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bunx changelogithub --no-group
continue-on-error: true

publish-npm:
name: 'NPM Registry'
needs: [changelog]
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3

- name: 'Setup Node.js'
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

- name: 'Install Dependencies'
run: yarn install --frozen-lockfile

- name: 'Build'
env:
NODE_ENV: 'production'
run: yarn build

- name: 'Publish'
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn publish --access='public' --registry='https://registry.npmjs.org' --no-git-checks
publish-gpr:
name: 'GitHub Package Registry'
needs: [changelog]
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3

- name: 'Setup Node.js'
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'yarn'
registry-url: 'https://npm.pkg.github.com'

- name: 'Install Dependencies'
run: yarn install --frozen-lockfile

- name: 'Build'
env:
NODE_ENV: 'production'
run: yarn build

- name: 'Update ~/.npmrc'
run: |
echo "//npm.pkg.github.com:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
- name: 'Publish'
env:
NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn publish --access='public' --registry='https://npm.pkg.github.com' --no-git-checks
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ yarn-error.log*
# package directories
jspm_packages

# Serverless directories
.serverless

tests/local
.esbuild

build

package-lock.json
node_modules
*.tgz
*.lockb
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
auto-install-peers=true
enable-pre-post-scripts=true
strict-peer-dependencies=false
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ Using Coingecko:

```sh
npm run add-token coingecko <coingecko_id>
```
```

If you're using `CommonJS`, this will only work if you import the package asynchronously: <https://nodejs.org/docs/latest-v18.x/api/esm.html#require>

You should switch to `ESM`.
5 changes: 5 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test'
}
}
64 changes: 33 additions & 31 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import arbitrum from "./arbitrum/tokenlist.json";
import avalanche from "./avalanche/tokenlist.json";
import bsc from "./bsc/tokenlist.json";
import celo from "./celo/tokenlist.json";
import ethereum from "./ethereum/tokenlist.json";
import fantom from "./fantom/tokenlist.json";
import gnosis from "./gnosis/tokenlist.json";
import harmony from "./harmony/tokenlist.json";
import optimism from "./optimism/tokenlist.json";
import polygon from "./polygon/tokenlist.json";
import arbitrum from './arbitrum/tokenlist.json'
import avalanche from './avalanche/tokenlist.json'
import bsc from './bsc/tokenlist.json'
import celo from './celo/tokenlist.json'
import ethereum from './ethereum/tokenlist.json'
import fantom from './fantom/tokenlist.json'
import gnosis from './gnosis/tokenlist.json'
import harmony from './harmony/tokenlist.json'
import optimism from './optimism/tokenlist.json'
import polygon from './polygon/tokenlist.json'

export interface Token {
address: string;
name: string;
symbol: string;
decimals: number;
coingeckoId: string | null;
wallet: boolean;
stable: boolean;
native?: boolean;
address: string
name: string
symbol: string
decimals: number
coingeckoId: string | null
wallet: boolean
stable: boolean
native?: boolean
}

export interface ChainToken extends Token {
chain: string;
chain: string
}

export type ChainTokenRegistry = { [key: string]: ChainToken };
export type ChainTokenRegistry = { [key: string]: ChainToken }

export const chains: { [chain: string]: Token[] } = {
export const chains = {
arbitrum,
avalanche,
bsc,
Expand All @@ -36,16 +36,18 @@ export const chains: { [chain: string]: Token[] } = {
gnosis,
harmony,
optimism,
polygon,
};
polygon
} satisfies { [chain: string]: Token[] }

const registries: { [chain: string]: ChainTokenRegistry } = {};
export type Chain = keyof typeof chains

const registries: { [chain: string]: ChainTokenRegistry } = {}

for (const chain in chains) {
const registry: ChainTokenRegistry = (registries[chain] = {});
const registry: ChainTokenRegistry = (registries[chain] = {})

for (const token of chains[chain]) {
registry[token.address] = { ...token, chain };
for (const token of chains[chain as Chain]) {
registry[token.address] = { ...token, chain }
}
}

Expand All @@ -55,11 +57,11 @@ for (const chain in chains) {
*/
export function getToken(
chain: string,
address: string = "0x0000000000000000000000000000000000000000"
address: string = '0x0000000000000000000000000000000000000000'
) {
if (!registries[chain]) {
console.error(`Chain '${chain}' not supported yet`);
return;
console.error(`Chain '${chain}' not supported yet`)
return
}
return registries[chain][address];
return registries[chain][address]
}
Loading

0 comments on commit 99b6f71

Please sign in to comment.