@ottoai/base
v1.0.1
Published
Shareable base configurations for modern node/npm development with typescript, jest and eslint
Readme
Base
Finnish for "start"
So this repo acts as a base - start - module which should be ideally part of every node/npm repo. So we use a consistent base configuration for certain libs we basically use everywhere.
What does it provide
- Release with changelog Create new versions based on conventional commits and update/create
CHANGELOG.md - engine definition to give a basic hint which node version we support
- peerDependencies to give basic hints which versions and modules we are using/needed to use the configs
- eslint config for eslint together with typescript linting
- tsconfig for typescript
- jest config for jest
Notable defined versions
| module | version | description |
| ---------- | ---------- | ------------------------------------------------------------------------------------------------------ |
| node | >=16.0.0 | Actual version, which will go to be LTS version from october 2020 on |
| typescript | ~4.3 | Fix version, as typescript isn't strictly following semver. So minor updates can have breaking changes |
How to use
Install using cli
From your project's root directory:
npx @ottoai/base init💡 If you want to use all of Base's features, you can pass the --all flag
npx @ottoai/base init --all
Note: If any of the files Base uses were already present, Base will create a .bkp file with the existing file. Please make sure to check these files and merge them with the ones Base created or delete them.
Install manually
npm install @ottoai/base --save-devAs npm prints, make sure to install the peer depedencies.
How to use release
Simple make sure to add a release script to the package.json:
{
"scripts": {
"release": "npx standard-version"
}
}And then instead of running npm version major|minor|patch run npm run release (similiar with yarn).
This will take care of identifying the next version tag based on the conventional commits, creates/updates the CHANGELOG.md, adds everything into a commit and creates the tag.
Push the new tag and the commit after that -> done :tada:
How to use eslint config
Simply create a .eslintrc.js file with following content:
const baseConfig = require('@ottoai/base/eslint');
module.exports = {
...baseConfig,
};Add/Update the following script to package.json:
{
"lint": "eslint --ext .js,.ts \"src/**\""
}Done! :tada:
Its recommended to create a .eslintignore file with following content
node_modules
dist
coverage
.eslintrc.js
jest.config.jsHow to use tsconfig
Simply create a tsconfig.json file with following content:
{
"extends": "@ottoai/base/tsconfig",
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.test.ts"],
"compilerOptions": {
"outDir": "dist" // So we get builds in the our current folder :/
}
}NOTE:
includeandexcludearen't shareable and relative to thetsconfig.jsonwhere there are defined.
NOTE: This will set
"module": "es6", which will maketsccompile to ES Modules instead of CommonJS. If you need to be compatible with CommonJS (node<14), set the following in yourtsconfig.json"compilerOptions": { "module": "commonjs" }
Because this compiles to ES Modules, you should set "type": "module" in your package.json to indicate this to users of your library.
Done! :tada:
How to use jest config
Simply create a jest.config.js file with following content:
const base = require('@ottoai/base/jest.config');
module.exports = {
...base,
};Done! :tada:
Recommendation for scripts in `package.json
{
"build": "tsc",
"test": "jest --config jest.config.js",
"lint": "eslint --ext .js,.ts \"src/**\"",
"ci": "npm run test -- --coverage && npm run lint && npm run build -- --noEmit",
"release": "npx standard-version"
}Local Development
For local development and to try out new configurations the easiest way is to link the module.
Contributing
Do your changes in separate branch and then create a PR to start a discussion. Please add reasons/explanations why certain configurations should be applied basically everywhere.
