Skip to content

Instantly share code, notes, and snippets.

@kasir-barati
Last active September 20, 2022 10:54
Show Gist options
  • Save kasir-barati/5590e1420aedc2dc321571b4b9df7d33 to your computer and use it in GitHub Desktop.
Save kasir-barati/5590e1420aedc2dc321571b4b9df7d33 to your computer and use it in GitHub Desktop.
A simple script which forces you to select pnpm as the package manager and install prettier as devDep
#!/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 specify package manager";
exit 1;
fi
ng new "$@"
# Go into the created project directory
cd "$1"
# Prettier
pnpm add -D prettier
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')); packageJson.scripts = { ...packageJson.scripts, \"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";
git branch -m main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment