From 6a1837c4af7b9d266043e4d0f513ec52004f73fe Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Fri, 25 Nov 2016 15:28:08 +0100 Subject: [PATCH] Make users able to deploy GitHub repos --- bin/now-deploy.js | 13 +++++++++---- lib/github.js | 31 ++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 332bf54..69a8ea4 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -195,6 +195,8 @@ async function sync(token) { const start = Date.now() const rawPath = argv._[0] + let gitHubRepo + const stopDeployment = msg => { error(msg) process.exit(1) @@ -206,18 +208,21 @@ async function sync(token) { const repo = await onGitHub(rawPath, debug) if (repo) { - path = repo + path = repo.path + gitHubRepo = repo } else if (isRepoPath(rawPath)) { stopDeployment(`This path neither exists, nor is there a repository named "${rawPath}" on GitHub`) } else { stopDeployment(`Could not read directory ${chalk.bold(path)}`) } - - console.log(repo) } if (!quiet) { - console.log(`> Deploying ${chalk.bold(toHumanPath(path))}`) + if (gitHubRepo) { + console.log(`> Deploying GitHub repository "${chalk.bold(toHumanPath(rawPath))}"`) + } else { + console.log(`> Deploying ${chalk.bold(toHumanPath(path))}`) + } } process.exit() diff --git a/lib/github.js b/lib/github.js index 12525e4..530026e 100644 --- a/lib/github.js +++ b/lib/github.js @@ -1,4 +1,8 @@ +// Native +import path from 'path' + // Packages +import fs from 'fs-promise' import fetch from 'node-fetch' import download from 'download' import tmp from 'tmp-promise' @@ -29,17 +33,16 @@ const exists = async repoPath => { const downloadRepo = async repoPath => { const url = `https://api.github.com/repos/${repoPath}/tarball` - const tmpDir = await tmp.dir({ + let tmpDir = await tmp.dir({ keep: true }) - try { - await download(url, tmpDir.path, { - extract: true - }) - } catch (err) { - error(`Not able to download repo: ${err.stack}`) - } + await download(url, tmpDir.path, { + extract: true + }) + + const tmpContents = await fs.readdir(tmpDir.path) + tmpDir.path = path.join(tmpDir.path, tmpContents[0]) return tmpDir } @@ -75,8 +78,14 @@ export const onGitHub = async (path, debug) => { return false } - const tmpDir = await downloadRepo(path) - console.log(tmpDir) + let tmpDir - return 'test' + try { + tmpDir = await downloadRepo(path) + } catch (err) { + error(`Not able to download repo: ${err.stack}`) + process.exit(1) + } + + return tmpDir }