Skip to content

Commit

Permalink
Add prettier, lint, workflows and fixes for API
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturDolzan committed Jan 3, 2025
1 parent 1aa7b1d commit a5bde49
Show file tree
Hide file tree
Showing 183 changed files with 4,060 additions and 2,305 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module.exports = {
parserOptions: {
project: false,
},
}
};
6 changes: 3 additions & 3 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: "Staging"
on:
push:
branches: [ "master" ]
branches: ["master"]
workflow_dispatch:

concurrency:
Expand All @@ -23,7 +23,7 @@ jobs:
packages: write # Needed to push to the GitHub Container Registry
strategy:
matrix:
component: [ "api", "web" ]
component: ["api", "web"]
with:
version: "${{ github.sha }}"
context: "."
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
deploy:
name: "Deploy to staging"
uses: hemilabs/actions/.github/workflows/deploy-kustomize.yml@main
needs: [ "docker", "deploy-registry" ]
needs: ["docker", "deploy-registry"]
permissions:
contents: read
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ jobs:
docker:
name: "Docker (${{ matrix.component }})"
uses: hemilabs/actions/.github/workflows/docker.yml@main
needs: [ "prepare" ]
needs: ["prepare"]
permissions:
contents: read
packages: write # Needed to push to the GitHub Container Registry
strategy:
matrix:
component: [ "api", "web" ]
component: ["api", "web"]
with:
version: "${{ needs.prepare.outputs.version }}"
context: "."
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
deploy:
name: "Deploy to testnet"
uses: hemilabs/actions/.github/workflows/deploy-kustomize.yml@main
needs: [ "prepare", "docker", "deploy-registry" ]
needs: ["prepare", "docker", "deploy-registry"]
permissions:
contents: read
with:
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/js-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: JS Checks

on:
pull_request:
push:

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

jobs:
build-shared:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Dependencies
run: npm install --workspaces --include-workspace-root

- name: Build Shared Package
run: npm run build --workspaces --include-workspace-root

- name: Save Build Output
run: tar -czf shared-build.tar.gz packages/shared/dist

- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: shared-build
path: shared-build.tar.gz

prepare-environment:
needs: build-shared
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Download Shared Build
uses: actions/download-artifact@v3
with:
name: shared-build

- name: Create Directory for Shared Build
run: mkdir -p packages/shared/dist

- name: Extract Shared Build
run: tar -xzf shared-build.tar.gz -C packages/shared/dist

- name: Install Dependencies
run: npm install --workspaces --include-workspace-root

js-checks:
needs: prepare-environment
uses: hemilabs/actions/.github/workflows/js-checks.yml@main
with:
node-versions: '["16", "18", "20", "22"]'
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,3 @@ While the prerequisites above must be satisfied prior to having your pull reques
| `bug` | Confirmed bugs or reports that are very likely to be bugs. |
| `question` | Questions more than bug reports or feature requests (e.g. how do I do X). |
| `feedback` | General feedback more than bug reports or feature requests. |

5 changes: 5 additions & 0 deletions CodingChallenge.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Coding Challenge Submission <br><br>

## Description

Describe your project here

## Prerequisites, Dependencies, Versions

Please add anything here you've built that requires the above specifics

## Licensing

Please state if license is CC, MIT or ISC or other (please no GPL)

## Outside Libraries

Link any outside open source libraries used

## Steps

Tell us how to run it locally
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# CryptoChords

CryptoChords is a tool for visualizing activities on the [Hemi network](https://hemi.xyz). It features a web application that enables users to explore the network and visualize transactions in a user-friendly manner.

This document provides instructions on how to set up, run, and contribute to the project.

## Visual Representation of the Network

CryptoChords provides a visual representation of the Hemi network using a piano keyboard as a metaphor. Every time a new transaction is added to the network, a cube appears on a piano key, representing the transaction. The transaction details are displayed on the screen, and if sound is enabled, the corresponding piano note is played simultaneously.

There are four types of transactions, each represented by a different color and associated with a different quadrant of the piano keyboard:
Expand All @@ -15,15 +17,16 @@ There are four types of transactions, each represented by a different color and

A random key within the corresponding quadrant is selected to represent each transaction.


## Folder Structure

The project is organized into the following folders:

- `apps`: Contains the API and the Web application.
- `packages`: Contains the components shared between the apps.
- `infrastucture`: Contains the necessary files to deploy the project.

## Architecture

This project is a monorepo composed of two applications: the API and the Web application and it is managed by [Turborepo](https://turbo.build/repo/docs).

Both the API and the Web application follow the Domain-Driven Design (DDD) principles. You can find more information about the architecture in the `readme.md` file of each project.
Expand Down Expand Up @@ -85,18 +88,23 @@ npm run lint
```

## Deployment

We have two environments: `stage` and `production`.
The project is automatically deployed using GitHub Actions.
The project is automatically deployed using GitHub Actions.

### Stage

The `stage` environment is automatically deployed when a new tag is created. The tag must follow the pattern `v*.*.*`. For example, `v1.0.0`.

### Production

The `production` environment is automatically deployed when a Commit is pushed to the `main` branch.

## Contributing

If you want to contribute to this project and make it better, your help is very welcome.
You can find more information about how to contribute in the [`CONTRIBUTING.md`](./CONTRIBUTING.md) file.

## License

This project is licensed under the MIT License - see the [`LICENSE`](./LICENSE) file for details.
10 changes: 0 additions & 10 deletions apps/api/.eslintrc.js

This file was deleted.

26 changes: 26 additions & 0 deletions apps/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": ["bloq", "prettier"],
"ignorePatterns": ["dist", "_esm/*", "_cjs/*", "_types/*"],
"overrides": [
{
"extends": ["bloq/typescript", "prettier"],
"files": ["src/**/*.ts"]
},
{
"extends": ["bloq/markdown"],
"files": ["*.md"]
},
{
"extends": ["bloq/vitest", "prettier"],
"files": ["*.spec.{js,ts}"]
}
],
"parserOptions": {
"sourceType": "module"
},
"root": true,
"rules": {
"arrow-body-style": "off",
"no-console": "off"
}
}
7 changes: 7 additions & 0 deletions apps/api/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"quoteProps": "consistent",
"semi": false,
"singleQuote": true,
"tabWidth": 2
}
3 changes: 2 additions & 1 deletion apps/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ The environment variables are defined in the `.env` file. The following variable

- `ENABLE_MAINNET`: A boolean that enables mainnet.[Hemi Docs](https://github.com/hemilabs/infrastructure/blob/main/NETWORK_INFO.md).


Example of the .env file

```
Expand All @@ -99,8 +98,10 @@ ENABLE_MAINNET=false
```

## Contribution

If you want to contribute to this project and make it better, your help is very welcome.
You can find more information about how to contribute in the [`CONTRIBUTING.md`](../../CONTRIBUTING.md) file.

## License

This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
11 changes: 8 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"test:cov": "vitest run src --coverage",
"test:watch": "vitest watch src",
"dev": "nodemon",
"format:check": "prettier --check .",
"format:fix": "npx prettier --write .",
"build": "tsc -p tsconfig.build.json",
"lint": "eslint . --ext ts --report-unused-disable-directives --max-warnings 0",
"lint": "eslint . --ext ts",
"start:api": "node dist/server.js"
},
"author": "",
"license": "MIT",
"dependencies": {
"@cryptochords/shared": "*",
"@typescript-eslint/eslint-plugin": "8.18.0",
"dotenv": "16.4.7",
"express": "4.21.2",
"web3": "4.16.0"
Expand All @@ -27,8 +28,12 @@
"@types/node": "22.10.2",
"@types/ws": "8.5.13",
"@vitest/coverage-v8": "2.1.8",
"eslint": "8.56.0",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"eslint": "^8.57.1",
"eslint-config-bloq": "^4.4.1",
"nodemon": "3.1.9",
"prettier": "^3.3.3",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"vitest": "2.1.8"
Expand Down
14 changes: 7 additions & 7 deletions apps/api/src/application/helpers/BroadcastToClients.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import WebSocket, { WebSocketServer } from 'ws';
import { L2Block } from '@cryptochords/shared';
import WebSocket, { WebSocketServer } from 'ws'
import { L2Block } from '@cryptochords/shared'

const BroadcastToClients = (wss: WebSocketServer, l2Block: L2Block): void => {
const broadcastToClients = (wss: WebSocketServer, l2Block: L2Block): void => {
wss.clients.forEach((client: WebSocket) => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(l2Block.toJSON()));
client.send(JSON.stringify(l2Block.toJSON()))
}
});
};
})
}

export default BroadcastToClients
export default broadcastToClients
24 changes: 12 additions & 12 deletions apps/api/src/application/helpers/broadcastToClients.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, it, expect, vi } from 'vitest';
import WebSocket, { WebSocketServer } from 'ws';
import BroadcastToClients from './BroadcastToClients';
import { describe, it, expect, vi } from 'vitest'
import WebSocket, { WebSocketServer } from 'ws'
import broadcastToClients from './BroadcastToClients'

describe('BroadcastToClients', () => {
it('should send a message to all connected clients', () => {
const mockSend = vi.fn();
const wss: any = new WebSocketServer({ noServer: true });
const mockSend = vi.fn()
const wss: any = new WebSocketServer({ noServer: true })
wss.clients = new Set([
{
readyState: WebSocket.OPEN,
Expand All @@ -16,15 +16,15 @@ describe('BroadcastToClients', () => {
readyState: WebSocket.CLOSED,
send: mockSend,
},
]);
])

const l2Block = {
toJSON: () => ({ key: 'value' }),
};
}

BroadcastToClients(wss, l2Block as any);
broadcastToClients(wss, l2Block as any)

expect(mockSend).toHaveBeenCalledTimes(1);
expect(mockSend).toHaveBeenCalledWith(JSON.stringify({ key: 'value' }));
});
});
expect(mockSend).toHaveBeenCalledTimes(1)
expect(mockSend).toHaveBeenCalledWith(JSON.stringify({ key: 'value' }))
})
})
Loading

0 comments on commit a5bde49

Please sign in to comment.