Last active
August 21, 2019 19:48
-
-
Save nsfilho/88866616176dfab60140295888eb6616 to your computer and use it in GitHub Desktop.
Node.js Packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| yarn global add json | |
| yarn add typescript @types/node ts-node | |
| yarn add -D prettier husky eslint rimraf \ | |
| eslint-config-prettier \ | |
| eslint-config-airbnb \ | |
| eslint-plugin-react \ | |
| eslint-plugin-prettier \ | |
| eslint-plugin-import \ | |
| eslint-plugin-jsx-a11y \ | |
| eslint-plugin-react-hooks \ | |
| @typescript-eslint/parser \ | |
| @typescript-eslint/eslint-plugin \ | |
| eslint-import-resolver-typescript \ | |
| -P | |
| yarn add -D jest nodemon @types/jest @types/jest ts-jest typedoc | |
| cat << _EOF > jest.config.js | |
| module.exports = { | |
| preset: 'ts-jest', | |
| testEnvironment: 'node', | |
| roots: ['./src'], | |
| transform: { | |
| '^.+\\.tsx?$': 'ts-jest', | |
| }, | |
| moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx', 'node'], | |
| moduleDirectories: ['node_modules', 'bower_components', './src'], | |
| }; | |
| _EOF | |
| cat << _EOF > .prettierrc.js | |
| module.exports = { | |
| semi: true, | |
| trailingComma: 'all', | |
| singleQuote: true, | |
| printWidth: 120, | |
| tabWidth: 4, | |
| jsxBracketSameLine: true, | |
| }; | |
| _EOF | |
| cat << _EOF > .eslintrc.js | |
| module.exports = { | |
| parser: '@typescript-eslint/parser', | |
| env: { | |
| browser: true, | |
| es6: true, | |
| jest: true | |
| }, | |
| extends: [ | |
| 'react-app', | |
| 'airbnb', | |
| 'plugin:@typescript-eslint/recommended', | |
| 'prettier', | |
| 'prettier/@typescript-eslint' | |
| ], | |
| globals: { | |
| Atomics: 'readonly', | |
| SharedArrayBuffer: 'readonly' | |
| }, | |
| parserOptions: { | |
| ecmaFeatures: { | |
| jsx: true | |
| }, | |
| ecmaVersion: 2018, | |
| sourceType: 'module' | |
| }, | |
| plugins: ['@typescript-eslint', 'import', 'jsx-a11y', 'prettier'], | |
| rules: { | |
| 'react/jsx-filename-extension': [ | |
| 'error', | |
| { | |
| extensions: ['.tsx'] | |
| } | |
| ], | |
| 'import/prefer-default-export': 'off', | |
| '@typescript-eslint/explicit-function-return-type': 'off', | |
| '@typescript-eslint/explicit-member-accessibility': 'off' | |
| }, | |
| settings: { | |
| 'import/parsers': { | |
| '@typescript-eslint/parser': ['.ts', '.tsx'] | |
| }, | |
| 'import/resolver': { | |
| typescript: {} | |
| } | |
| } | |
| }; | |
| _EOF | |
| json -I -f package.json -e 'this.scripts={}' | |
| json -I -f package.json -e 'this.scripts.lint="eslint --ext .js,.jsx,.ts,.tsx ./src/"' | |
| json -I -f package.json -e 'this.scripts.format="prettier --write src/**/*.ts src/**/*.tsx src/**/*.css package.json"' | |
| json -I -f package.json -e 'this.scripts.start="ts-node src/index.ts"' | |
| json -I -f package.json -e 'this.scripts.build="tsc"' | |
| json -I -f package.json -e 'this.scripts.docs="typedoc --out docs ./src --exclude \"**/*.test.ts\""' | |
| json -I -f package.json -e 'this.scripts.test="jest --detectOpenHandles"' | |
| json -I -f package.json -e 'this.scripts.dev="nodemon --watch src/**/*.ts --exec ts-node src/index.ts"' | |
| cat << _EOF > tsconfig.json | |
| { | |
| "compilerOptions": { | |
| "target": "es5", | |
| "lib": ["esnext"], | |
| "allowJs": true, | |
| "skipLibCheck": true, | |
| "esModuleInterop": true, | |
| "allowSyntheticDefaultImports": true, | |
| "strict": true, | |
| "forceConsistentCasingInFileNames": true, | |
| "module": "commonjs", | |
| "moduleResolution": "node", | |
| "resolveJsonModule": true, | |
| "isolatedModules": true, | |
| "noEmit": true, | |
| "outDir": "build", | |
| "sourceMap": true, | |
| "jsx": "preserve" | |
| }, | |
| "include": ["src"] | |
| } | |
| _EOF | |
| cat << _EOF > husky.json | |
| { | |
| "husky": { | |
| "hooks": { | |
| "pre-commit": "npm run lint" | |
| } | |
| } | |
| } | |
| _EOF | |
| cat package.json husky.json | json --merge > package-new.json | |
| mv package-new.json package.json | |
| rm -f husky.json | |
| yarn format | |
| if [ ! -f .gitignore ] ; then | |
| curl 'https://www.gitignore.io/api/node,macos' -o .gitignore | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment