Skip to content

Instantly share code, notes, and snippets.

@simonrenoult
Last active March 1, 2019 09:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simonrenoult/b7a926440d08ebe364e5dbdd3a15398c to your computer and use it in GitHub Desktop.
Save simonrenoult/b7a926440d08ebe364e5dbdd3a15398c to your computer and use it in GitHub Desktop.
Script to bootstrap a nodejs project
project_name=$1
project_description=$2
location=$HOME/code/$project_name
pkg=$location/package.json
readme=$location/readme.md
node_version=$(node --version)
npm_version=$(npm --version)
if [ -z "$project_name" ]; then
echo "Error: a project name must be provided."
exit 1
fi
echo "\n> Creating $location..."
mkdir -p $location
cd $location
echo "Done!"
echo "\n> Cloning template from simonrenoult/nodejs-project-template..."
git clone git@github.com:simonrenoult/nodejs-project-template.git .
rm -rf .git
echo "Done!"
echo "\n> Customizing template..."
sed -i "s/{{name}}/$project_name/" $pkg $readme
sed -i "s/{{node}}/$node_version/" $pkg $readme
sed -i "s/{{npm}}/$npm_version/" $pkg $readme
if [ -z "$project_description" ]; then
sed -i "s/{{description}}/$project_description/" $pkg $readme
else
sed -i "s/{{description}}//" $pkg $readme
fi
echo "Done!"
echo "\n> Installing NPM dependencies..."
npm install
git init
git remote add origin git@github.com:simonrenoult/$project_name.git
git add --all
echo "Done!"
echo "\n> Commiting everything..."
git commit --message="Initial commit"
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment