A Better Node Repository Init

A Better Node Repository Init

Git Ignore

Git Attributes

*.* text eol=lf
yarn.lock binary
.gitattributes

NPM

@cdiscount:registry=http://tfsdropserver.cdbdx.biz:8082/repository/npm/
.npmrc

Yarn VS NPM

  • yarn.lock and package.lock.json

Git Hooks

  • lint-staged and husky
  • yarn add -D husky lint-staged
    npm set-script prepare "husky install"
    yarn prepare
    yarn husky add .husky/pre-commit "lint-staged"
  • git-cz and commitlint
  • yarn add -D git-cz @commitlint/config-conventional @commitlint/cli
    yarn husky add .husky/commit-msg 'yarn commitlint --edit "$1"'
  • yarn-deduplicate
  • yarn add yarn-deduplicate

  • prettier et prettier-plugin-packagejson
  • yarn add -D prettier prettier-plugin-packagejson @cdiscount/prettier-config

    {
      "scripts": {
    		"commit": "git-cz",
        "format": "prettier --write **/*.{css,html,js,jsx,json,md}"
      },
    	"lint-staged": {
        "*.{css,html,js,jsx,json,md}": "prettier --write",
        "yarn.lock": "yarn-deduplicate yarn.lock"
      },
      "prettier": "@cdiscount/prettier-config",
    	"commitlint": {
        "extends": [
          "@commitlint/config-conventional"
        ]
      }
    }
    package.json
    _templates
    build
    coverage
    
    .prettierignore

Editor Config

# editorconfig.org
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
.editorconfig

Visual Studio Code Recommended Extensions

{
  "recommendations": [
    "patbenatar.advanced-new-file",
    "formulahendry.auto-rename-tag",
    "naumovs.color-highlight",
    "carbonid1.emmet-jss",
    "irongeek.vscode-env",
    "dsznajder.es7-react-js-snippets",
    "dbaeumer.vscode-eslint",
    "wix.vscode-import-cost",
    "christian-kohler.npm-intellisense",
    "esbenp.prettier-vscode",
    "richie5um2.vscode-sort-json",
    "editorconfig.editorconfig"
  ]
}
.vscode/extensions.json
{
  "files.autoSave": "onFocusChange",
  "editor.formatOnSave": true,
  "files.eol": "\n"
}
.vscode/settings.json

ESLint

yarn add -D typescript @cdiscount/eslint-config-cdiscount-react

{
  "scripts": {
    "lint": "eslint --cache ."
  }
	"lint-staged": {
    "*.{js,jsx,json}": "eslint --fix"
  },
	"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest",
      "@cdiscount/cdiscount-react"
    ],
		"rules": {
			"react/react-in-jsx-scope": "off"
		}
  },
  "eslintIgnore": [
    "_templates",
    "build",
    "storybook-static",
    "coverage"
  ]
}
package.json