Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP 2916 configure husky lint staged and prettier #200

Merged
merged 9 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
},
"postCreateCommand": "bash -i -c 'nvm install $(cat .nvmrc) -y && nvm use && corepack enable && pnpm clean && pnpm install'",
"remoteUser": "node",
"runArgs": [
"--network=host"
],
"runArgs": ["--network=host"],
"mounts": [
"type=bind,src=${localEnv:HOME}/.npmrc,dst=/home/node/.npmrc",
"type=bind,src=${localEnv:HOME}/.ssh,dst=/home/node/.ssh",
"type=bind,src=${localEnv:HOME}/movai/src/feapps,dst=/workspaces/"
]
}
}
1 change: 1 addition & 0 deletions .github/workflows/TestOnPR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: MOV-AI/.github/.github/workflows/[email protected]
with:
deploy: "false"
run_lint_staged: "true"
run_tests: "true"
use_nvmrc: "true"
pm: "pnpm"
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm exec lint-staged
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
pnpm-lock.yaml
5 changes: 1 addition & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
{
"trailingComma": "none",
"arrowParens": "avoid"
}
{}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"liveServer.settings.port": 5501
}
"prettier.configPath": ".prettierrc.json",
"editor.formatOnSave": true
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TBD

- [FP-2916](https://movai.atlassian.net/browse/FP-2916): Configure husky, lint-staged and prettier for lib-core

# 1.2.3

- [FP-2926](https://movai.atlassian.net/browse/FP-2926): Clear console and app errors
Expand Down
124 changes: 68 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ Its main use will be to build Mov.AI applications.
# Table of Content

<!-- TOC -->
* [MOV.AI Core](#movai-core)
* [Table of Content](#table-of-content)
* [Setting Up Your Development Environment](#setting-up-your-development-environment)
* [Common Configuration](#common-configuration)
* [Configure ~/.npmrc](#configure-npmrc)
* [Using a DevContainer (recommended)](#using-a-devcontainer-recommended)
* [Using a Local Setup](#using-a-local-setup)
* [Tools Required](#tools-required)
* [Install Node with NVM](#install-node-with-nvm)
* [Install PNPM](#install-pnpm)
* [Using a DevContainer Setup](#using-a-devcontainer-setup)
* [Tools Required](#tools-required-1)
* [Development](#development)
* [How to install this library to an app](#how-to-install-this-library-to-an-app)
* [How to Link this library locally to an App](#how-to-link-this-library-locally-to-an-app)
* [Testing](#testing)
* [Running tests](#running-tests)
* [Running test on html](#running-test-on-html)
<!-- TOC -->

- [MOV.AI Core](#movai-core)
- [Table of Content](#table-of-content)
- [Setting Up Your Development Environment](#setting-up-your-development-environment)
- [Common Configuration](#common-configuration)
- [Configure ~/.npmrc](#configure-npmrc)
- [Using a DevContainer (recommended)](#using-a-devcontainer-recommended)
- [Using a Local Setup](#using-a-local-setup)
- [Tools Required](#tools-required)
- [Install Node with NVM](#install-node-with-nvm)
- [Install PNPM](#install-pnpm)
- [Using a DevContainer Setup](#using-a-devcontainer-setup)
- [Tools Required](#tools-required-1)
- [Development](#development)
- [How to install this library to an app](#how-to-install-this-library-to-an-app)
- [How to Link this library locally to an App](#how-to-link-this-library-locally-to-an-app)
- [Testing](#testing)
- [Running tests](#running-tests)
- [Running test on html](#running-test-on-html)
<!-- TOC -->

# Setting Up Your Development Environment

You can set up your development environment in two ways:

- In a DevContainer (recommended)
- Locally

Expand Down Expand Up @@ -76,58 +78,61 @@ To install Node.js using `nvm` (Node Version Manager), follow these steps:

Open your terminal and run the following command to install `nvm`:

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
```
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
```

2. **Load `nvm`:**

After installing `nvm`, you need to load it. Close and reopen your terminal, or run:

```bash
source ~/.nvm/nvm.sh
```
```bash
source ~/.nvm/nvm.sh
```

3. **Install the required Node.js version:**

With `nvm` installed and loaded, run the following command to use the required Node.js version:

```bash
nvm install && nvm use # uses the node version specify in the .nvmrc file
```
```bash
nvm install && nvm use # uses the node version specify in the .nvmrc file
```

4. **Set the used Node.js as the default version:**

```bash
nvm current # prints the node.js version being used
nvm alias default xx.xx.x # sets xx.xx.x as default
```
```bash
nvm current # prints the node.js version being used
nvm alias default xx.xx.x # sets xx.xx.x as default
```

5. **Verify the installation:**

```bash
node -v
```
```bash
node -v
```

This should output the node version specified in `.nvmrc` file.


#### Install PNPM

To install `pnpm`, follow these steps:

1. Using the required pnpm version:

The pnpm version required is specify in the `package.json` file as:
```json
{
"packageManager": "[email protected]"
}
```
The pnpm version required is specify in the `package.json` file as:

```json
{
"packageManager": "[email protected]"
}
```

In order to have Node.js use the specified version, run:
```bash

```bash
corepack enable
```
```

Upon first use, Corepack downloads the latest version from the network and uses it when running pnpm commands.

### Using a DevContainer Setup
Expand All @@ -143,9 +148,9 @@ To install `pnpm`, follow these steps:
## How to install this library to an app

1. - Install package:
```bash
"pnpm install @mov-ai/mov-fe-lib-core"
```
```bash
"pnpm install @mov-ai/mov-fe-lib-core"
```

## How to Link this library locally to an App

Expand All @@ -154,29 +159,36 @@ Here's how it can be done:

1. In the app, identify this library in the `package.json`:

```
"@mov-ai/mov-fe-lib-core": "^x.x.x-X",
```
```
"@mov-ai/mov-fe-lib-core": "^x.x.x-X",
```

2. Replace the library version with the path of this local library:

```
```
"@mov-ai/mov-fe-lib-core": "file:/home/username/path/to/library/frontend-npm-lib-core"
```
```

3. Build this local library:

```bash
```bash
pnpm install # installs dependencies
pnpm buildDev # builds the app and watches for changes
```
```

4. Install and build the app:

```bash
```bash
pnpm install # installs dependencies including the local library
pnpm start # runs the app
```
```

## How to setup linting git hook

1. Install husky git hook:
```bash
"pnpm prepare"
```

# Testing

Expand Down
13 changes: 7 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ module.exports = {
chrome: "78",
node: "12",
},
modules: "auto"
modules: "auto",
},
]
],
],
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-transform-runtime", {
"@babel/plugin-transform-runtime",
{
loose: true,
useESModules: false,
}
]
]
},
],
],
};
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
transform: {
"^.+\\.(ts|tsx)?$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest"
"^.+\\.(js|jsx)$": "babel-jest",
},
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
Expand Down
Loading
Loading