Standardise your npm scripts

  1. In multi-repo projects, CI/CD pipelines become very easy to create with templates; you can rely on them and use templates instead of hardcoding scripts/jobs.
  2. For Monorepos using Lerna, for example, you can safely run a standard script and know that every package is following that structure.
  3. It’s easy to create a new package, either copy-paste from another one, or create a package creator script. If this is easy to do, people will eventually do it more often.
  4. Scripts can be long and prone to error when copying.
"format:all": "prettier '**/*.{js,jsx,ts,tsx,json,md,css}' --write",
"format:check": "prettier '**/*.{js,jsx,ts,tsx,json,md,css}' --check",

Solution

  1. package.json
{
"name": "@company/prettier-config",
"version": "1.0.0",
"main": "index.js",
"prettier": "./index.js",
"bin": {
"company-format-check": "bin/format-check.sh",
"company-format-all": "bin/format-all.sh"
},
"dependencies": {
"prettier": "1.19.1"
}
}
  1. index.js
module.exports = {
useTabs: false,
tabWidth: 2,
printWidth: 80,
semi: false,
trailingComma: 'all',
bracketSpacing: true,
arrowParens: 'avoid',
singleQuote: true,
}
  1. bin/format-check.sh
prettier '**/*.{js,jsx,ts,tsx,json,md,css,yaml}' --check
  1. bin/format-all.sh
prettier '**/*.{js,jsx,ts,tsx,json,md,css,yaml}' --write
yarn add @company/prettier-config -D
{
"prettier": "@company/prettier-config",
"scripts": {
"format:check": "company-format-check",
"format:all": "company-format-all"
},
"devDependencies": {
"@company/prettier-config": "1.0.0"
}
}

Conclusion

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Modern JavaScript at Clause

A pink flower

Datawave 2 tips: Remove all variables from the event

Promises and UI states in Ember.js

Regular Functions and Arrow Functions in this keyword

How to solve “undefined method 'rich_text_area_tag'”

How to write a comment in JavaScript?

Clojure Re-Frame Exercise

Article Summary: If your building a Node/Express web application and have never used or added the…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Flavio Carvalho

Flavio Carvalho

More from Medium

Best practices any team can use with their typescript projects

Top 3 Casts of the Week #3

My TypeScript journey

Change VS Code “Find” Search Result Highlight Color