Skip to content

Instantly share code, notes, and snippets.

@vicnaum
Last active May 12, 2025 08:40
Show Gist options
  • Save vicnaum/46bae58adb119d0f6570d785940fa266 to your computer and use it in GitHub Desktop.
Save vicnaum/46bae58adb119d0f6570d785940fa266 to your computer and use it in GitHub Desktop.
Quickly initialize an empty node typescript project with prettier and yarn
#!/bin/bash
set -e
#####################################
### MODERN 2025 VERSION WITH PNPM ###
#####################################
# Initialize pnpm project
pnpm init
# Add TypeScript and essential dev dependencies
pnpm add -D typescript tsx @types/node prettier eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
# Initialize TypeScript with a modern config
pnpm tsc --init --target es2022 --strict --esModuleInterop --skipLibCheck --forceConsistentCasingInFileNames --module nodenext --moduleResolution nodenext
# Create .prettierrc
cat > .prettierrc << EOF
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
EOF
# Create .eslintrc
cat > .eslintrc << EOF
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
]
}
EOF
# Add useful scripts to package.json
cat > tmp_package.json << EOF
{
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "tsx src/index.ts",
"build": "tsc",
"lint": "eslint . --ext .ts",
"format": "prettier --write \"src/**/*.ts\""
}
}
EOF
# Merge the scripts into package.json (requires jq)
if command -v jq >/dev/null 2>&1; then
jq -s '.[0] * .[1]' package.json tmp_package.json > package.json.tmp && mv package.json.tmp package.json
rm tmp_package.json
else
echo "Warning: jq not found. Please manually add the scripts from tmp_package.json to your package.json"
fi
# Create src directory and sample index.ts
mkdir -p src
cat > src/index.ts << EOF
console.log('TypeScript project initialized successfully!');
EOF
# Create .gitignore
cat > .gitignore << EOF
node_modules/
dist/
.DS_Store
*.log
EOF
echo "TypeScript project initialized successfully!"
echo "You can now run:"
echo " pnpm dev - to start development with hot reload"
echo " pnpm start - to run the project"
echo " pnpm build - to build for production"
echo " pnpm lint - to run ESLint"
echo " pnpm format - to format code with Prettier"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment