Skip to content

Instantly share code, notes, and snippets.

@kasir-barati
Last active September 20, 2022 11:00
Show Gist options
  • Save kasir-barati/7877d6668188fad0b0765ef8ffe32a05 to your computer and use it in GitHub Desktop.
Save kasir-barati/7877d6668188fad0b0765ef8ffe32a05 to your computer and use it in GitHub Desktop.
My NestJS bash script for creating a new NestJS project
#!/bin/bash
isPackageManagerSpecified="false";
for ((i=1; i<=$#; i++))
do
nextArgumentIndex=$((i+1));
if [[ "${!i}" == "--package-manager" ]] && [[ "${!nextArgumentIndex}" == "pnpm" ]];
then
isPackageManagerSpecified="true";
fi
done
if [[ $isPackageManagerSpecified != "true" ]]
then
echo "Please chose pnpm as the package manager";
exit 1;
fi
nest new "$@"
# Go into the created project directory
cd "$1"
# Prettier
rm -rf .prettierrc &> /dev/null
rm -rf .prettierignore &> /dev/null
wget https://gist.githubusercontent.com/kasir-barati/2bcdeea964f88712eca171adb3fbd979/raw/.prettierrc
wget https://gist.githubusercontent.com/kasir-barati/8b32cf62e69e6f87a6bed899eefe1cb5/raw/.prettierignore
node -e "const { readFileSync, writeFileSync } = require('fs'); const packageJson = JSON.parse(readFileSync('package.json', 'utf-8')); const {format, ...rest} = packageJson.scripts; packageJson.scripts = { ...rest, \"format\": \"prettier -w . -u\" }; writeFileSync('package.json', JSON.stringify(packageJson))"
# Add License
wget https://gist.githubusercontent.com/kasir-barati/7574fdf252e2648ebeb119264bcd442d/raw/LICENCE
node -e "const { readFileSync, writeFileSync } = require('fs'); const packageJson = JSON.parse(readFileSync('package.json', 'utf-8')); packageJson.license = 'GPL-3.0'; writeFileSync('package.json', JSON.stringify(packageJson))"
# Later works
pnpm format
git add .
git commit -m "cleanup: prettified";
# Change the project directory as I wanted
mkdir src/app src/modules src/shared
mv src/app.* src/app
git add .
git commit -m "cleanup: change directory structure";
git branch -m main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment