Skip to content

Instantly share code, notes, and snippets.

@Titiaiev
Created April 14, 2023 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Titiaiev/2f8fc8bf5e937996578602e88779e67f to your computer and use it in GitHub Desktop.
Save Titiaiev/2f8fc8bf5e937996578602e88779e67f to your computer and use it in GitHub Desktop.
генерация проекта нода плюс тс
#!/bin/bash
# создаёт новый nodejs typescript
# настраивает eslint, prettier, nodemon, устанавливает рабочие зависимости
# инициализирует гит репозиторий и делает инит комит
echo "(Будет использовано для name в package.json и создания директории проекта)"
echo -n "Введите название проекта: "
read PROJECT_NAME
echo -n "Описание проекта: "
read DESCRIPTION
# важно выйти здесь, если директория существует, чтобы не затереть там что либо
mkdir $PROJECT_NAME || exit 1
cd $PROJECT_NAME
git init
touch package.json
cat > package.json <<End-of-package
{
"name": "$PROJECT_NAME",
"version": "1.0.0",
"description": "$DESCRIPTION",
"main": "build/main.js",
"type": "module",
"engines": {
"node": "^18.15.0"
},
"private": true,
"scripts": {
"dev": "npx nodemon",
"build": "rimraf ./build && npx tsc",
"start": "npm run build && node build/main.js",
"lint": "npx eslint ./src",
"format": "npx eslint ./src --fix",
"prepare": "husky install"
},
"keywords": [],
"author": "",
"license": "ISC"
}
End-of-package
npm i -D typescript @types/node ts-node nodemon rimraf eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser prettier husky
npm run prepare
npx husky add .husky/pre-commit "npx prettier --write --config .prettierrc ./src && npm run lint"
mkdir src
touch src/main.ts
cat > src/main.ts <<End-of-main
const msg = 'Hello NodeJS'
console.log(msg)
End-of-main
npx tsc --init
touch nodemon.json
cat > nodemon.json <<End-of-nodemon
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": ["node_modules"],
"exec": "npx ts-node ./src/main.ts"
}
End-of-nodemon
touch .eslintrc
cat > .eslintrc <<End-of-eslintrc
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {}
}
End-of-eslintrc
touch .gitignore
cat > .gitignore <<End-of-gitignore
node_modules
build
End-of-gitignore
touch .prettierrc
cat > .prettierrc <<End-of-prettierrc
{
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2
}
End-of-prettierrc
touch README.md
cat > README.md <<End-of-README
внесите в \`tsconfig.json\` следущие изменения
\`\`\` json
{
"compilerOptions": {
"target": "ES2018",
"lib": [
"ES6"
],
"module": "NodeNext",
"rootDir": "./src",
"resolveJsonModule": true,
"allowJs": true,
"sourceMap": true,
"outDir": "./build",
"removeComments": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"lib": [
"esnext"
],
"ts-node": {
"esm": true
}
}
\`\`\`
End-of-README
git add .
git commit -m "initial commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment