Skip to content

Commit

Permalink
chore: update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
vafanassieff committed Feb 6, 2024
1 parent c98760a commit 685c0e5
Show file tree
Hide file tree
Showing 24 changed files with 7,219 additions and 2,281 deletions.
25 changes: 8 additions & 17 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const typescript = {
files: ['*.ts'],
module.exports = {
env: { node: true },
parser: '@typescript-eslint/parser',
parserOptions: {
project: `${__dirname}/tsconfig.eslint.json`,
tsconfigRootDir: __dirname,
project: `tsconfig.eslint.json`,
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:promise/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
settings: {
'import/parsers': {
Expand All @@ -25,24 +30,10 @@ const typescript = {
},
},
},
}

module.exports = {
env: { es2022: true, node: true },
overrides: [typescript],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:promise/recommended',
'prettier',
],
plugins: ['import'],
rules: {
'no-console': 'error',
'promise/no-callback-in-promise': 'off',
'space-before-function-paren': 'off',
'import/no-unresolved': ['error', { commonjs: true }],
'import/no-extraneous-dependencies': 'error',
'no-global-assign': ['error', { exceptions: ['require'] }],
'no-empty': ['error', { allowEmptyCatch: true }],
camelcase: 'off',
Expand Down
13 changes: 0 additions & 13 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

19 changes: 0 additions & 19 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

41 changes: 41 additions & 0 deletions .github/actions/base/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Base
description: Install node, pnpm and setup cache

inputs:
token:
description: NPM token
required: true
default: null

runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
run_install: false

- name: Expose pnpm config through "$GITHUB_OUTPUT"
id: pnpm-config
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Cache rotation keys
id: cache-rotation
shell: bash
run: echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-

- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
shell: bash
45 changes: 15 additions & 30 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
name: Check

concurrency:
group: ${{ github.workflow }}.${{ github.ref }}
cancel-in-progress: true

on:
push:
paths: ['*.ts']
branches:
- master
pull_request:
paths: ['*.ts']
types: [opened, synchronize, reopened]
workflow_call:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- uses: pnpm/action-setup@v2
with:
run_install: false

- run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
shell: bash
id: pnpm-config

- run: echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
shell: bash
id: cache-rotation

- uses: actions/cache@v3
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-

- run: pnpm install --frozen-lockfile --prefer-offline --silent
shell: bash
env:
HUSKY: 0
- uses: actions/checkout@v4

- uses: ./.github/actions/base

- run: pnpm knip

- run: pnpm spell-check

- run: pnpm type-check

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
release:
types: [published]

jobs:
check:
uses: ./.github/workflows/check.yml
secrets: inherit

release:
name: Release
runs-on: ubuntu-latest
needs: [check]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/base

- run: npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
13 changes: 11 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env bash

set -e

result=$(pnpm cspell --show-context --no-progress --no-summary "$1" | sed 's/.* - / ➜ /' 2>&1 || true)
if ! [ -z "$result" ]; then
echo "✗ Commit message didn't pass spellcheck:"
echo "$result"
exit 1
fi


pnpm commitlint --edit "$1"
7 changes: 5 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env bash

set -e

exec git diff --cached --name-only | pnpm cspell --show-suggestions --show-context --no-progress --no-must-find-files --file-list stdin

pnpm lint-staged
5 changes: 5 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
'*': 'prettier --ignore-unknown --write',
'*.ts': 'eslint --fix',
'*.md': 'markdownlint --fix',
}
9 changes: 9 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"default": true,
"MD033": {
"allowed_elements": ["table"]
},
"MD013": {
"line_length": 1000
}
}
7 changes: 7 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
strict-peer-dependencies=false
auto-install-peers=false
use-lockfile-v6=true
resolution-mode=highest
dedupe-direct-deps=false
save-prefix=''
save-workspace-protocol=rolling
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
printWidth: 80,
useTabs: false,
tabWidth: 2,
semi: false,
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'always',
plugins: ['prettier-plugin-packagejson'],
}
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
extends: ['@commitlint/config-conventional'],
}
16 changes: 16 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dictionaries": ["node", "npm", "en-gb"],
"ignorePaths": ["node_modules", "build", "dist", "pnpm-lock.yaml"],
"language": "en",
"words": [
"Afanassieff",
"Cashin",
"commitlint",
"Knip",
"lintstagedrc",
"lnmarkets",
"packagejson",
"sats",
"undici"
]
}
12 changes: 12 additions & 0 deletions example/rest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createRestClient } from '../src/index.js'
import console from 'node:console'

const client = createRestClient({ network: 'testnet' })

const ticker = await client.futuresGetTicker()

console.log(ticker)

const user = await client.userGet()

console.log(user)
3 changes: 2 additions & 1 deletion example/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebsocketClient } from '../src/websocket'
import { createWebsocketClient } from '../src/index.js'
import console from 'node:console'

const client = await createWebsocketClient({ network: 'testnet' })
Expand All @@ -10,5 +10,6 @@ console.log(channels)
await client.publicSubscribe(['futures:btc_usd:last-price'])

client.ws.on('message', (data) => {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
console.log(data.toString())
})
21 changes: 21 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { KnipConfig } from 'knip'

export default {
ignoreExportsUsedInFile: true,
ignore: ['./example/**'],
ignoreDependencies: [
'eslint-import-resolver-typescript',
'lint-staged',
'@commitlint/cli',
],
ignoreBinaries: [],
typescript: { config: ['tsconfig.*.json'] },
prettier: { config: ['.prettierrc.js'] },
eslint: { config: ['.eslintrc.cjs'] },
'lint-staged': { config: ['.lintstagedrc.js'] },
commitlint: { config: ['commitlint.config.js'] },
'github-actions': {
config: ['.github/workflows/*.yml', '.github/actions/**/*.yml'],
},
cspell: { config: ['cspell.json'] },
} satisfies KnipConfig
Loading

0 comments on commit 685c0e5

Please sign in to comment.