lib/utils/downloadTemplateFromRepo.js/downloadTemplateFromRepo
function downloadTemplateFromRepo(inputUrl, templateName, downloadPath) {
  return parseRepoURL(inputUrl).then(repoInformation => {
    let serviceName;
    let dirName;
    let downloadServicePath;
    const { auth } = repoInformation;

    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}"...`);

    const downloadOptions = {
      timeout: 30000,
      extract: true,
      strip: 1,
      mode: '755',
      auth,
    };
    // download service
    return download(repoInformation.downloadUrl, downloadServicePath, downloadOptions)
      .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);
      });
  });
}