-
-
Save mistical2008/dd780ea6ff00e7b031d49e1d88fe080c to your computer and use it in GitHub Desktop.
init-ts-package.sh
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
#!/usr/bin/env bash | |
generate_file() { | |
if [ ! -f "$1" ]; then | |
echo "$2" > "$1" | |
fi | |
} | |
# --- | |
# package.json | |
# | |
if [ ! -f "package.json" ]; then | |
npm init -y | |
jq '.main = "dist/index.js" | | |
.engines.node = ">= 12" | | |
.scripts.lint = "eslint ." | | |
.scripts.build = "tsc -p tsconfig.json" | | |
.scripts.prepublishOnly = "run-s lint depcheck build test" | | |
.scripts.depcheck = "depcheck" | | |
.scripts.test = "jest"' \ | |
package.json > package.tmp.json | |
mv package.tmp.json package.json | |
fi | |
mkdir -p src | |
touch src/index.ts | |
# --- | |
# gitignore | |
# | |
if [ ! -f ".gitignore" ]; then | |
curl "https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,intellij+all,visualstudiocode" > .gitignore | |
fi | |
# --- | |
# devDependencies | |
# | |
yarn add -D \ | |
@types/jest \ | |
@typescript-eslint/eslint-plugin \ | |
@typescript-eslint/parser \ | |
eslint \ | |
eslint-config-google \ | |
eslint-plugin-jest \ | |
eslint-plugin-node \ | |
jest \ | |
npm-run-all \ | |
ts-jest \ | |
typescript \ | |
depcheck | |
# --- | |
# eslintrc | |
# | |
generate_file ".eslintrc" '{ | |
"root": true, | |
"parser": "@typescript-eslint/parser", | |
"plugins": [ | |
"@typescript-eslint", | |
"jest" | |
], | |
"extends": [ | |
"google", | |
"eslint:recommended", | |
"plugin:jest/recommended", | |
"plugin:@typescript-eslint/recommended" | |
], | |
"parserOptions": { | |
"ecmaVersion": 2020 | |
}, | |
"rules": { | |
"object-curly-spacing": ["error", "always"], | |
"comma-dangle": ["error", "never"], | |
"require-jsdoc": "off", | |
"no-multiple-empty-lines": "error", | |
"node/no-unsupported-features/es-syntax": "off", | |
"@typescript-eslint/no-unused-vars": 2, | |
"@typescript-eslint/semi": [2, "always"], | |
"no-console": [1, { "allow": ["warn", "error", "info"] }], | |
"jest/no-standalone-expect": "off" | |
} | |
} | |
' | |
# --- | |
# editorconfig | |
# | |
generate_file ".editorconfig" 'root = true | |
[*] | |
charset = utf-8 | |
end_of_line = lf | |
insert_final_newline = true | |
indent_style = space | |
indent_size = 2 | |
[*.py] | |
indent_style = space | |
indent_size = 4 | |
[Makefile] | |
indent_style = tab | |
' | |
# --- | |
# jest config | |
# | |
generate_file "jest.config.json" '{ | |
"preset": "ts-jest", | |
"testEnvironment": "node", | |
"collectCoverageFrom": [ | |
"!src/**/*.spec.ts", | |
"src/**/*.ts" | |
] | |
} | |
' | |
# --- | |
# tsconfig | |
# | |
generate_file "tsconfig.json" '{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
"strict": true, | |
"outDir": "dist", | |
"sourceMap": true, | |
"esModuleInterop": true, | |
"forceConsistentCasingInFileNames": true | |
} | |
} | |
' | |
# --- | |
# .depcheckrc | |
# | |
generate_file ".depcheckrc" 'ignores: ["@types/jest", "eslint-plugin-node"] | |
' | |
# --- | |
# git | |
# | |
if [ ! -d ".git" ]; then | |
git init | |
git add . | |
git commit -am 'Initial commit' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment