├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md └── init.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: carlosazaustre 2 | custom: ["https://www.paypal.me/cazaustre"] 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | project/ 2 | test.sh 3 | .vscode 4 | .idea 5 | *.log 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Carlos Azaustre 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 2 | 3 | ## Description 4 | 5 | This tool allows you to quickly initialize a Node.js project with TypeScript fully configured and ready to use. The main goal is to save time and effort by eliminating the need to manually create each configuration file, install dependencies one by one, and configure each tool from scratch. 6 | 7 | With this script, you get a complete modern development environment in seconds, with all essential tools preconfigured according to best practices. What would normally take hours of manual setup is reduced to a simple command, allowing you to immediately focus on what really matters: developing your application. 8 | 9 | ## Features 10 | 11 | - Ready to use TypeScript 12 | - ESLint and Prettier configured 13 | - Husky for git hooks 14 | - Commit validation with commitlint 15 | - GitHub Actions CI configured 16 | - Environment variables support with dotenv 17 | 18 | ## Installation 19 | 20 | ```bash 21 | # Clone the repository 22 | git clone https://github.com/username/$(basename "$PWD").git 23 | cd $(basename "$PWD") 24 | 25 | # Install dependencies 26 | npm install 27 | ``` 28 | 29 | ## Usage 30 | 31 | ### Development 32 | 33 | To start the development server: 34 | 35 | ```bash 36 | npm run dev 37 | ``` 38 | 39 | ### Build 40 | 41 | To compile the project: 42 | 43 | ```bash 44 | npm run build 45 | ``` 46 | 47 | ### Production 48 | 49 | To run the compiled version: 50 | 51 | ```bash 52 | npm start 53 | ``` 54 | 55 | ## Available Scripts 56 | 57 | - `npm run dev`: Starts the development server with hot-reload 58 | - `npm run build`: Compiles the project for production 59 | - `npm start`: Runs the compiled version of the project 60 | - `npm run lint`: Runs the linter to check the code 61 | 62 | ## Project Structure 63 | 64 | ``` 65 | ├── .github/ # GitHub Actions configuration 66 | ├── node_modules/ # Dependencies (generated) 67 | ├── src/ # Source code 68 | ├── dist/ # Compiled code (generated) 69 | ├── .env # Environment variables 70 | ├── .eslintrc.json # ESLint configuration 71 | ├── .gitignore # Files ignored by git 72 | ├── .prettierrc # Prettier configuration 73 | ├── package.json # Dependencies and scripts 74 | └── tsconfig.json # TypeScript configuration 75 | ``` 76 | 77 | ## License 78 | 79 | © Carlos Azaustre. 80 | 81 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 82 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script initializes a Node.js project with TypeScript, ESLint, Prettier, and Husky. 3 | # It sets up a basic project structure, installs necessary dependencies, and configures Git and GitHub Actions. 4 | # Check if the script is run from the root directory of the project 5 | 6 | 7 | # Colors for messages 8 | GREEN='\033[0;32m' 9 | BLUE='\033[0;34m' 10 | NC='\033[0m' 11 | 12 | echo -e "${BLUE}🚀 Starting Node.js with TypeScript project setup...${NC}" 13 | 14 | # Get Git information 15 | GIT_NAME=$(git config --get user.name) 16 | GIT_EMAIL=$(git config --get user.email) 17 | 18 | if [ -z "$GIT_NAME" ] || [ -z "$GIT_EMAIL" ]; then 19 | echo "❌ Error: Git user.name or user.email are not configured" 20 | exit 1 21 | fi 22 | 23 | echo -e "${GREEN}✅ Initializing Node.js project${NC}" 24 | npm init -y 25 | 26 | echo -e "${GREEN}✅ Initializing Git repository${NC}" 27 | git init 28 | 29 | echo -e "${GREEN}✅ Creating .gitignore${NC}" 30 | cat > .gitignore << EOF 31 | # Dependencies 32 | node_modules/ 33 | npm-debug.log 34 | yarn-debug.log 35 | yarn-error.log 36 | 37 | # TypeScript 38 | dist/ 39 | build/ 40 | *.tsbuildinfo 41 | 42 | # Environment variables 43 | .env 44 | .env.local 45 | .env.*.local 46 | 47 | # IDE - VSCode 48 | .vscode 49 | .vscode/* 50 | !.vscode/settings.json 51 | !.vscode/tasks.json 52 | !.vscode/launch.json 53 | !.vscode/extensions.json 54 | 55 | # System Files 56 | .DS_Store 57 | Thumbs.db 58 | 59 | # Logs 60 | logs 61 | *.log 62 | 63 | # Coverage directory used by tools like istanbul 64 | coverage/ 65 | 66 | # Optional npm cache directory 67 | .npm 68 | 69 | # Optional eslint cache 70 | .eslintcache 71 | 72 | # Optional REPL history 73 | .node_repl_history 74 | 75 | # Output of 'npm pack' 76 | *.tgz 77 | EOF 78 | 79 | echo -e "${GREEN}✅ Creating README.md${NC}" 80 | echo "# $(basename "$PWD")" > README.md 81 | 82 | echo -e "${GREEN}✅ Creating LICENSE${NC}" 83 | cat > LICENSE << EOF 84 | MIT License 85 | 86 | Copyright (c) $(date +%Y) $GIT_NAME 87 | 88 | Permission is hereby granted, free of charge, to any person obtaining a copy 89 | of this software and associated documentation files (the "Software"), to deal 90 | in the Software without restriction, including without limitation the rights 91 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 92 | copies of the Software, and to permit persons to whom the Software is 93 | furnished to do so, subject to the following conditions: 94 | 95 | The above copyright notice and this permission notice shall be included in all 96 | copies or substantial portions of the Software. 97 | 98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 99 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 100 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 101 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 102 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 103 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 104 | SOFTWARE. 105 | EOF 106 | 107 | echo -e "${GREEN}✅ Installing TypeScript dependencies${NC}" 108 | npm install --save-dev typescript tsx pkgroll @types/node @types/jest 109 | 110 | echo -e "${GREEN}✅ Creating tsconfig.json${NC}" 111 | cat > tsconfig.json << EOF 112 | { 113 | "\$schema": "https://json.schemastore.org/tsconfig", 114 | "compilerOptions": { 115 | "target": "ES2022", 116 | "module": "ESNext", 117 | "moduleResolution": "Node", 118 | "strict": true, 119 | "esModuleInterop": true, 120 | "forceConsistentCasingInFileNames": true, 121 | "skipLibCheck": true, 122 | "isolatedModules": true, 123 | "resolveJsonModule": true, 124 | "outDir": "./dist", 125 | "rootDir": "./src", 126 | "noEmit": false, 127 | "types": ["node", "jest"], 128 | "verbatimModuleSyntax": false, 129 | "incremental": true, 130 | "allowJs": true 131 | }, 132 | "include": ["src/**/*.ts"], 133 | "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"] 134 | } 135 | 136 | EOF 137 | 138 | echo -e "${GREEN}✅ Installing and configuring ESLint${NC}" 139 | npm install --save-dev eslint @eslint/js@9 @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-love 140 | 141 | cat > eslint.config.js << EOF 142 | import globals from 'globals' 143 | import pluginJs from '@eslint/js' 144 | import tseslint from 'typescript-eslint' 145 | import love from 'eslint-config-love' 146 | 147 | export default [ 148 | { 149 | ...love, 150 | files: ['**/*.{js,mjs,cjs,ts}'] 151 | }, 152 | { 153 | languageOptions: { globals: globals.node } 154 | }, 155 | pluginJs.configs.recommended, 156 | ...tseslint.configs.recommended, 157 | ] 158 | EOF 159 | 160 | echo -e "${GREEN}✅ Installing and configuring Prettier${NC}" 161 | npm install --save-dev prettier 162 | 163 | cat > .prettierrc << EOF 164 | { 165 | "semi": true, 166 | "trailingComma": "all", 167 | "singleQuote": false, 168 | "printWidth": 100, 169 | "tabWidth": 2, 170 | "endOfLine": "auto" 171 | } 172 | EOF 173 | 174 | echo -e "${GREEN}✅ Installing lint-staged and husky${NC}" 175 | npm install --save-dev lint-staged husky @commitlint/cli @commitlint/config-conventional 176 | 177 | cat > .lintstagedrc << EOF 178 | { 179 | "*.ts": ["prettier --list-different", "eslint"], 180 | "*.md": "prettier --list-different" 181 | } 182 | EOF 183 | 184 | cat > commitlint.config.js << EOF 185 | export default { extends: ['@commitlint/config-conventional'] }; 186 | 187 | EOF 188 | 189 | echo -e "${GREEN}✅ Creating project structure${NC}" 190 | mkdir -p src 191 | cat > src/index.ts << EOF 192 | import 'dotenv/config'; 193 | 194 | console.log('Hello Node'); 195 | console.log('Environment:', process.env.NODE_ENV); 196 | EOF 197 | 198 | echo -e "${GREEN}✅ Setting up environment variables${NC}" 199 | echo "NODE_ENV=development" > .env 200 | 201 | echo -e "${GREEN}✅ Setting up GitHub Actions${NC}" 202 | mkdir -p .github/workflows 203 | 204 | cat > .github/workflows/ci.yml << EOF 205 | name: CI 206 | 207 | on: 208 | pull_request: 209 | branches: 210 | - main 211 | push: 212 | branches: 213 | - main 214 | 215 | jobs: 216 | lint: 217 | runs-on: ubuntu-latest 218 | steps: 219 | - name: Checkout code 220 | uses: actions/checkout@v2 221 | 222 | - name: Set up Node.js 223 | uses: actions/setup-node@v2 224 | with: 225 | node-version: "23" 226 | 227 | - name: Install dependencies 228 | run: npm install 229 | 230 | - name: Run linter 231 | run: npm run lint 232 | 233 | test: 234 | runs-on: ubuntu-latest 235 | needs: lint 236 | steps: 237 | - name: Checkout code 238 | uses: actions/checkout@v2 239 | 240 | - name: Set up Node.js 241 | uses: actions/setup-node@v2 242 | with: 243 | node-version: "23" 244 | 245 | - name: Install dependencies 246 | run: npm install 247 | 248 | - name: Run tests 249 | run: npm test 250 | 251 | build: 252 | runs-on: ubuntu-latest 253 | needs: test 254 | steps: 255 | - name: Checkout code 256 | uses: actions/checkout@v2 257 | 258 | - name: Set up Node.js 259 | uses: actions/setup-node@v2 260 | with: 261 | node-version: "23" 262 | 263 | - name: Install dependencies 264 | run: npm install 265 | 266 | - name: Build TypeScript 267 | run: npm run build 268 | EOF 269 | 270 | echo -e "${GREEN}✅ Installing dotenv${NC}" 271 | npm install dotenv 272 | 273 | echo -e "${GREEN}✅ Setting up Husky${NC}" 274 | # Inicializar husky con el nuevo comando 275 | npx husky init 276 | 277 | # Crear los hooks manualmente 278 | echo "npm run lint" > .husky/pre-commit 279 | echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg 280 | echo "npm run test" > .husky/pre-push 281 | 282 | # Dar permisos de ejecución a los hooks 283 | chmod +x .husky/pre-commit .husky/commit-msg .husky/pre-push 284 | 285 | echo -e "${GREEN}✅ Configuring npm scripts${NC}" 286 | npm install rimraf@4 -D 287 | npm pkg set scripts.dev="tsx watch src/index.ts" 288 | npm pkg set scripts.start="node dist/index.js" 289 | npm pkg set scripts.build="rimraf dist && pkgroll --minify" 290 | npm pkg set scripts.lint="eslint . --ext .ts ./src" 291 | npm pkg set scripts.test="echo \"Error: no test specified\" && exit 1" 292 | npm pkg set scripts.prepare="husky install" 293 | npm pkg set type="module" 294 | npm pkg set engines.node=">=22.0.0" 295 | npm pkg set exports="./dist/index.js" 296 | npm pkg set private=true 297 | npm pkg set license="MIT" 298 | npm pkg set author="$GIT_NAME <$GIT_EMAIL>" 299 | npm pkg set repository.type="git" 300 | 301 | echo "${BLUE}🎉 Project setup completed successfully!${NC}" 302 | echo "${BLUE}📝 You can start developing with:${NC}" 303 | echo "${GREEN} npm run dev${NC}" 304 | --------------------------------------------------------------------------------