Skip to content

Commit

Permalink
docs: add READMEs
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Termont <woutermont@gmail.com>
  • Loading branch information
woutermont committed Apr 30, 2021
1 parent e3cdedb commit 1f1a3d6
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 19 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Digita configuration repository

Standard configuration of repos, packages etc. Easy to copy or inherit from.
# Digita Configuration Repository

This repository provides a standard configuration for repositories and packages, used internally at Digita to adopt a uniform clean coding environment. It contains the following configuration packages:

- [`commitlint-config`](./packages/commitlint-config#readme)
- [`eslint-config`](./packages/eslint-config#readme)
- [`jest-config`](./packages/jest-config#readme)
- [`lerna-config`](./packages/lerna-config#readme)
- [`typescript-config`](./packages/typescript-config#readme)

## Git hooks

The Git hooks of this repository also serve as an instantly copyable base for new (mono)repos. We use Husky to share them via Git. Set it up by installing `husky` in the repo root and adding `husky install` as `postinstall` script to the root `package.json`. Then copy the `.husky` directory from this repo, and make sure to make the hooks themselves executable (e.g. `chmod a+x .husky/*`).
18 changes: 18 additions & 0 deletions packages/commitlint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Digita Commitlint Configuration

This package provides a shareable Commitlint configuration, used internally at Digita to adopt a uniform commit message style.

## Installation

In the root of your (mono)repo, install `@digita-ai/commitlint-config` as a development dependency. From NPM v7 onwards,, this will automatically add `@commitlint/cli` as a peer dependency as well (if you use an earlier version, install this yourself). Add the following `commitlint` object to the `package.json`.

```
"commitlint": {
"extends": [
"@digita-ai/commitlint-config"
]
}
```

In a pre-commit git hook (e.g. with Husky), call `./node_modules/.bin/commitlint --edit $1`, or use Commitlint in any other way that fits your project. For an example of a git hook, check the `.husky/pre-commit` script of this repository.
38 changes: 21 additions & 17 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

# Digita ESLint Configuration

This package provides a shareable ESLint configuration, used internally at Digita to adopt a uniform clean cody style.
This package provides a shareable ESLint configuration, used internally at Digita to adopt a uniform clean code style.

## Installation

In the root of your (mono)repo, install `@digita-ai/eslint-config` as a development dependency. From NPM v7 onwards,, this will automatically add the following peer dependencies as well (when using an earlier version, install these yourself):
In the root of your (mono)repo, install `@digita-ai/eslint-config` as a development dependency. From NPM v7 onwards,, this will automatically add the following peer dependencies as well (if you use an earlier version, install these yourself).

- `eslint`
- `eslint-plugin-jsdoc`
- `eslint-plugin-import`
- `eslint-plugin-prefer-arrow`
- `eslint-import-resolver-typescript`
- `@typescript-eslint/eslint-plugin`
- `lint-staged`

When working in monorepo, install `eslint` as a development dependency in each subrepo as well.

In the root `package.json`, add the following `eslintConfig` object.
In the root `package.json`, add the following `eslintConfig` and `lint-staged` objects.

```
"eslintConfig": {
"extends": [
"@digita-ai/eslint-config"
],
"env": {
"browser": true,
"es2020": true,
"es6": true,
"jest": true,
"node": true,
"serviceworker": true,
"worker": true
}
"extends": [
"@digita-ai/eslint-config"
]
}
```

```
"lint-staged": {
"**/*.(js|ts)": [
"eslint --fix"
]
}
```

Expand All @@ -45,11 +45,15 @@ Auto-fix-on-save functionality can be enabled with VSCode's `dbaeumer.vscode-esl
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.eol": "\n"
}
}
```

## Prettier & EditorConfig

The Prettier and EditorConfig projects also provide ways to ensure a uniform coding style. Often these are held to provide the visual style, limiting ESLint to lint for good coding practices. However, ESLint provides a lot more possibilities to fine-tune the visual aspect than either of these projects do. Moreover, all functionality provided by these projects can be subsumed by ESLint rules. We therefore adopt ESLint as a single point of truth. Rules subsuming functionality of Prettier (`P`) and EditorConfig (`EC`) have been indicated as such in comments.


## Only lint staged files

For efficiency, either in your scripts or in you git hooks, you can run `lint-staged`, which is initially set up for `.ts` and `.js` files with `eslint`, but can be extended with different commands for other extensions.
54 changes: 54 additions & 0 deletions packages/jest-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

# Digita Jest Configuration

This package provides a Jest preset configuration, used internally at Digita to adopt a uniform testing habit.

## Installation

In the root of your (mono)repo, install `@digita-ai/jest-config` as a development dependency. From NPM v7 onwards,, this will automatically add the following peer dependencies as well (if you use an earlier version, install these yourself).

- `jest`
- `@types/jest`
- `jest-extended`
- `jest-mock-extended`
- `jest-coverage-thresholds-bumper`

It will also suggest the following optional dependencies.

- `@testing-library/jest-dom`
- `jest-fetch-mock`

When working in monorepo, install `jest` and `jest-coverage-thresholds-bumper` as development dependencies in each subrepo as well.

In each `package.json`, add the following `jest` object.

```
"jest": {
"coverageThreshold": {
"global": {
"branches": 0,
"functions": 0,
"lines": 0,
"statements": 0
}
},
"displayName": "core",
"preset": "@digita-ai/jest-config",
"rootDir": "lib"
}
```

Coverage thresholds will automatically be raised when running tests. Optionally, you can tell Jest to look for tests in multiple directories by setting and extending the `"roots": [ "<rootDir>" ]` list. You can also switch testing environment between `node` and `jsdom` with `"testEnvironment": "node"`, and set configuration for these environments with `"testEnvironmentOptions": { /* ... */ }`.

## Testing from the root of a monorepo

When using git hooks in a monorepo, you might want to run Jest from the root `node_modules` of your repository, without having the test search for relative paths in the wrong place. To prevent this, add the following `jest` object to the root `package.json`, pointing to all packages where you wish to run Jest.

```
"jest": {
"preset": "@digita-ai/jest-config",
"projects": [
"<rootDir>/packages/*/"
]
}
```
17 changes: 17 additions & 0 deletions packages/lerna-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Digita Lerna Configuration

This package provides an extendable Lerna configuration, used internally at Digita to adopt a uniform monorepo setup.

## Installation

In the root of your (mono)repo, install `@digita-ai/lerna-config` as a development dependency. From NPM v7 onwards,, this will automatically add `lerna` as a peer dependency as well (if you use an earlier version, install this yourself).

In the root `package.json`, add the following `lerna` object, with an initial version number. Lerna will find this and change it on each release.

```
"lerna": {
"extends": "@digita-ai/lerna-config",
"version": "0.1.0"
},
```
42 changes: 42 additions & 0 deletions packages/typescript-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Digita Typescript Configuration

This package provides a Typescript configurations, one for building and one for testing, used internally at Digita to adopt a uniform build mechanism.

## Installation

In the root of your (mono)repo, install `@digita-ai/typescript-config` as a development dependency. From NPM v7 onwards, this will automatically add the following peer dependencies as well (if you use an earlier version, install these yourself).

- `typescript`
- `@types/node`
- `ts-node`

Put the following in the `tsconfig.json` of your Typescript package(s).

```
{
"extends": "@digita-ai/typescript-config/tsconfig.json",
"compilerOptions": {
"baseUrl": "./lib",
"outDir": "./dist",
"rootDir": "./lib",
"module": "commonjs"
}
}
```

Put the following in the `tsconfig.spec.json` of your Typescript package(s).

```
{
"extends": "@digita-ai/typescript-config/tsconfig.spec.json",
"compilerOptions": {
"baseUrl": "./lib",
"outDir": "./dist",
"rootDir": "./lib",
"module": "commonjs"
}
}
```

In each of the above config files, change the `baseUrl` (base for relative imports), `outDir` (output directory for builds) and `rootDir` (root directory of source files) to the relevant paths (`rootDir` maps on `outDir` during build). Also set the `module` type to `commonjs` for Node.js packages or to the desired ECMAScript version (e.g. `es2020`) for browser packages. Overwrite any of the preset directives if needed.

0 comments on commit 1f1a3d6

Please sign in to comment.