Skip to content

Commit

Permalink
chore: setup monorepo
Browse files Browse the repository at this point in the history
add readme
  • Loading branch information
compojoom committed Dec 19, 2024
1 parent 31656b0 commit a363a78
Show file tree
Hide file tree
Showing 8 changed files with 5,300 additions and 5,706 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.11.0
File renamed without changes.
158 changes: 158 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Safe Global Monorepo 🙋‍♂️

## Overview

Welcome to the Safe Global Monorepo! This repository houses multiple applications and packages managed under a unified
structure using Yarn Workspaces. The monorepo setup simplifies dependency management and ensures consistent development
practices across projects.

### Key Components

- **apps/**: Contains application projects (e.g., `mobile` for the Safe Mobile App).
- **packages/**: Shared libraries and utilities.
- **config/**: Configuration files for the monorepo.

## Getting Started

To get started, ensure you have the required tools installed and follow these steps:

### Prerequisites

- **Node.js**: Install the latest stable version from [Node.js](https://nodejs.org/).
- **Yarn**: Use Yarn version 4.5.3 or later

to install it with the latest node version you can simply do

```bash
corepack enable
```

and then just run

```bash
yarn
```

This will install the required version of yarn and resolve all dependencies.

> [!INFO]
>
> Corepack is a tool to help with managing versions of your package managers. It exposes binary proxies for each supported package manager that, when called, will identify whatever package manager is
> configured for the current project, download it if needed, and finally run it.
### Initial Setup

1. Clone the repository:

```bash
git clone <repo-url>
cd monorepo
```

2. Install dependencies:

```bash
yarn install
```

## Monorepo Commands

Here are some essential commands to help you navigate the monorepo:

### Workspace Management

- **Run a script in a specific workspace:**

```bash
yarn workspace <workspace-name> <script>
```

Example:

```bash
yarn workspace @safe-global/web start
```

- **Add a dependency to a specific workspace:**

```bash
yarn workspace <workspace-name> add <package-name>
```

- **Remove a dependency from a specific workspace:**

```bash
yarn workspace <workspace-name> remove <package-name>
```

> [!Note]
>
> Yarn treats commands that contain a semicolon as global commands. For example if you have a
> command in a workspace that has a semicolon and there isn't another workspace that has the same command,
> you can run the command without specifying the workspace name. For example:
>
> ```bash
> yarn cypress:open
> ```
>
> is equivalent to:
>
> ```bash
> yarn workspace @safe-global/web cypress:open
> ```
### Linting and Formatting
- **Run ESLint across all workspaces:**
```bash
yarn lint
```
### Testing

- **Run unit tests across all workspaces:**

```bash
yarn test
```

## Contributing

### Adding a New Workspace

1. Create a new directory under `apps/` or `packages/`.
2. Add a `package.json` file with the appropriate configuration.
3. Run:

```bash
yarn install
```

### Best Practices

- Use Yarn Workspaces commands for managing dependencies.
- Ensure tests and linting pass before pushing changes.
- Follow the commit message guidelines.

### Tools & Configurations

- **Husky**: Pre-commit hooks for linting and tests.
- **ESLint & Prettier**: Enforce coding standards and formatting.
- **Jest**: Unit testing framework.
- **Expo**: Mobile app framework for the `mobile` workspace.
- **Next.js**: React framework for the `web` workspace.

## Useful Links

- [Yarn Workspaces Documentation](https://classic.yarnpkg.com/en/docs/workspaces/)
- [Expo Documentation](https://docs.expo.dev/)
- [Next.js Documentation](https://nextjs.org/docs)
- [Jest Documentation](https://jestjs.io/)
- [ESLint Documentation](https://eslint.org/)
- [Prettier Documentation](https://prettier.io/)

---

If you have any questions or run into issues, feel free to open a discussion or contact the maintainers. Happy coding!
🚀
78 changes: 40 additions & 38 deletions apps/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/safe-global/safe-wallet-web)
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/safe-global/safe-wallet-web/badge)](https://www.gitpoap.io/gh/safe-global/safe-wallet-web)

# Safe{Wallet} Web 💻

This project is now part of the **@safe-global/safe-wallet** monorepo! The monorepo setup allows centralized management
of multiple
applications and shared libraries. This workspace (`apps/web`) is the frontend of the Safe{Wallet} web app.

Safe{Wallet} is a smart contract wallet for Ethereum and other EVM chains. Based on Gnosis Safe multisig contracts.

This repository is the frontend of the Safe{Wallet} app.
You can run commands for this workspace in two ways:

1. **From the root of the monorepo using `yarn workspace` commands**
2. **From within the `apps/web` directory**

## Prerequisites

Except for the main monorepo prerequisites, no additional prerequisites are required for this workspace.

## Setup the Project

1. Install all dependencies from the **root of the monorepo**:

```bash
yarn install
```

## Contributing

Contributions, be it a bug report or a pull request, are very welcome. Please check our [contribution guidelines](CONTRIBUTING.md) beforehand.
Contributions, be it a bug report or a pull request, are very welcome. Please check
our [contribution guidelines](CONTRIBUTING.md) beforehand.

## Getting started with local development

Expand Down Expand Up @@ -54,85 +76,64 @@ If you don't provide some of the variables, the corresponding features will be d

### Running the app locally

#### Prerequisites

- **Node.js**: Install the latest stable version from [Node.js](https://nodejs.org/).

We use Yarn v4 for package management. If you are running on Node.js v16 or later, you can run:
From the root of the monorepo:

```bash
corepack enable
yarn workspace @safe-global/web start
```

and then when you run `yarn` in the repository root, it will install the required version of yarn and resolve all
dependencies.

> [!INFO]
>
> Corepack is a tool to help with managing versions of your package managers. It exposes binary proxies for each
> supported package manager that, when called, will identify whatever package manager is
> configured for the current project, download it if needed, and finally run it.
Install the dependencies:

```bash
yarn
```

Generate types:

```bash
yarn postinstall
```

Run the development server:
Or directly from the `apps/web` directory:

```bash
yarn start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the app.

> [!NOTE]
>
> From now on for brevity we will only show the command to run from the root of the monorepo. You can always run the command from the `apps/web` directory you just need to omit the `workspace @safe-global/web`.
## Lint

ESLint:

```
yarn lint --fix
yarn workspace @safe-global/web lint --fix
```

Prettier:

```
yarn prettier
yarn workspace @safe-global/web prettier
```

## Tests

Unit tests:

```
yarn test --watch
yarn workspace @safe-global/web test --watch
```

### Cypress tests

Build a static site:

```
yarn build
yarn workspace @safe-global/web build
```

Serve the static files:

```
yarn serve
yarn workspace @safe-global/web serve
```

Launch the Cypress UI:

```
yarn cypress:open
yarn workspace @safe-global/web cypress:open
```

You can then choose which e2e tests to run.
Expand All @@ -143,12 +144,13 @@ Some tests will require signer private keys, please include them in your .env fi
To create a new component from a template:

```
yarn cmp MyNewComponent
yarn workspace @safe-global/web cmp MyNewComponent
```

## Pre-push hooks

This repo has a pre-push hook that runs the linter (always) and the tests (if the `RUN_TESTS_ON_PUSH` env variable is set to true)
This repo has a pre-push hook that runs the linter (always) and the tests (if the `RUN_TESTS_ON_PUSH` env variable is
set to true)
before pushing. If you want to skip the hooks, you can use the `--no-verify` flag.

## Frameworks
Expand Down
4 changes: 2 additions & 2 deletions apps/web/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const nextConfig = {

config.resolve.alias = {
...config.resolve.alias,
'bn.js': path.resolve('./node_modules/bn.js/lib/bn.js'),
'mainnet.json': path.resolve('./node_modules/@ethereumjs/common/dist.browser/genesisStates/mainnet.json'),
'bn.js': path.resolve('../../node_modules/bn.js/lib/bn.js'),
'mainnet.json': path.resolve('../..node_modules/@ethereumjs/common/dist.browser/genesisStates/mainnet.json'),
'@mui/material$': path.resolve('./src/components/common/Mui'),
}

Expand Down
8 changes: 1 addition & 7 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "safe-wallet-web",
"name": "@safe-global/web",
"homepage": "https://github.com/safe-global/safe-wallet-web",
"license": "GPL-3.0",
"version": "1.48.1",
Expand Down Expand Up @@ -32,12 +32,6 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build --quiet"
},
"resolutions": {
"@safe-global/safe-core-sdk-types/ethers": "6.13.4",
"@safe-global/protocol-kit/ethers": "6.13.4",
"@safe-global/api-kit/ethers": "6.13.4",
"@gnosis.pm/zodiac/ethers": "6.13.4"
},
"engines": {
"node": ">=18"
},
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"name": "@safe-global/safe-wallet",
"version": "1.0.0",
"workspaces": [
"apps/*",
"packages/*"
],
"scripts": {
"lint": "yarn workspaces foreach --all -pt run lint",
"test": "yarn workspaces foreach --all -pt run test",
"prettier:fix": "yarn workspaces foreach --all -pt run prettier:fix",
"eslint": "yarn workspaces foreach --all -pt run eslint"
},
"resolutions": {
"@safe-global/safe-core-sdk-types/ethers": "6.13.4",
"@safe-global/protocol-kit/ethers": "6.13.4",
"@safe-global/api-kit/ethers": "6.13.4",
"@gnosis.pm/zodiac/ethers": "6.13.4"
},
"devDependencies": {
"husky": "^9.1.6",
"lint-staged": "^15.2.10"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit a363a78

Please sign in to comment.