lib/utils/downloadTemplateFromRepo.js/downloadTemplateFromRepo
function downloadTemplateFromRepo(inputUrl, templateName, downloadPath) {
  const repoInformation = parseRepoURL(inputUrl);

  let serviceName;
  let dirName;
  let downloadServicePath;

  if (repoInformation.isSubdirectory) {
    const folderName = repoInformation.pathToDirectory.split('/').splice(-1)[0];
    serviceName = folderName;
    dirName = downloadPath || templateName || folderName;
    downloadServicePath = path.join(os.tmpdir(), repoInformation.repo);
  } else {
    serviceName = repoInformation.repo;
    dirName = downloadPath || templateName || repoInformation.repo;
    downloadServicePath = path.join(process.cwd(), dirName);
  }

  const servicePath = path.join(process.cwd(), dirName);
  const renamed = dirName !== repoInformation.repo;

  if (dirExistsSync(path.join(process.cwd(), dirName))) {
    const errorMessage = `A folder named "${dirName}" already exists.`;
    throw new ServerlessError(errorMessage);
  }

  log(`Downloading and installing "${serviceName}"...`);

  // download service
  return download(
    repoInformation.downloadUrl,
    downloadServicePath,
    { timeout: 30000, extract: true, strip: 1, mode: '755' }
  ).then(() => {
    // if it's a directory inside of git
    if (repoInformation.isSubdirectory) {
      const directory = path.join(downloadServicePath, repoInformation.pathToDirectory);
      copyDirContentsSync(directory, servicePath);
      fse.removeSync(downloadServicePath);
    }
  }).then(() => {
    if (renamed) renameService(dirName, servicePath);

    return BbPromise.resolve(serviceName);
  });
}