#! /bin/bash

set -e

REPONAME=$1

if [ "x$REPONAME" = "x" ]; then
    echo "Bootstrap a new nodejs-based project"
    echo
    echo "USAGE: $0 <reponame>"
    exit -1
fi

if [ -e $REPONAME ]; then
    echo "$REPONAME already exists"
    exit -2
fi

echo Making $REPONAME
git clone git@github.yandex-team.ru:admins/node-bootstrap.git $REPONAME
cd $REPONAME

rm -rf .git common README.md
cat >package.json <<EOD
{
  "name": "$REPONAME",
  "version": "1.0.0",
  "description": "The $REPONAME admins project",
  "repository": {
    "type": "git",
    "url": "https://github.yandex-team.ru/admins/$REPONAME.git"
  },
  "author": "$DEBFULLNAME <$DEBEMAIL>",
  "license": "GPL-3.0",
  "devDependencies": {
      "node-common": "file:common/node-admins-deps"
  }
}
EOD
cat >README.md <<EOD
# $REPONAME
This is a new admins project. It was cloned from [node-common](https://github.yandex-team.ru/admins/node-common) and has a default readme... hopefully this is temporarily.
EOD
git init
git submodule add git@github.yandex-team.ru:admins/node-common.git common
git add .
git ci -m "Initial import from bootstrap"
npm install

echo Done
