Browse Source

Make users able to deploy GitHub repos

master
Leo Lamprecht 8 years ago
parent
commit
6a1837c4af
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 11
      bin/now-deploy.js
  2. 25
      lib/github.js

11
bin/now-deploy.js

@ -195,6 +195,8 @@ async function sync(token) {
const start = Date.now() const start = Date.now()
const rawPath = argv._[0] const rawPath = argv._[0]
let gitHubRepo
const stopDeployment = msg => { const stopDeployment = msg => {
error(msg) error(msg)
process.exit(1) process.exit(1)
@ -206,19 +208,22 @@ async function sync(token) {
const repo = await onGitHub(rawPath, debug) const repo = await onGitHub(rawPath, debug)
if (repo) { if (repo) {
path = repo path = repo.path
gitHubRepo = repo
} else if (isRepoPath(rawPath)) { } else if (isRepoPath(rawPath)) {
stopDeployment(`This path neither exists, nor is there a repository named "${rawPath}" on GitHub`) stopDeployment(`This path neither exists, nor is there a repository named "${rawPath}" on GitHub`)
} else { } else {
stopDeployment(`Could not read directory ${chalk.bold(path)}`) stopDeployment(`Could not read directory ${chalk.bold(path)}`)
} }
console.log(repo)
} }
if (!quiet) { if (!quiet) {
if (gitHubRepo) {
console.log(`> Deploying GitHub repository "${chalk.bold(toHumanPath(rawPath))}"`)
} else {
console.log(`> Deploying ${chalk.bold(toHumanPath(path))}`) console.log(`> Deploying ${chalk.bold(toHumanPath(path))}`)
} }
}
process.exit() process.exit()

25
lib/github.js

@ -1,4 +1,8 @@
// Native
import path from 'path'
// Packages // Packages
import fs from 'fs-promise'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import download from 'download' import download from 'download'
import tmp from 'tmp-promise' import tmp from 'tmp-promise'
@ -29,17 +33,16 @@ const exists = async repoPath => {
const downloadRepo = async repoPath => { const downloadRepo = async repoPath => {
const url = `https://api.github.com/repos/${repoPath}/tarball` const url = `https://api.github.com/repos/${repoPath}/tarball`
const tmpDir = await tmp.dir({ let tmpDir = await tmp.dir({
keep: true keep: true
}) })
try {
await download(url, tmpDir.path, { await download(url, tmpDir.path, {
extract: true extract: true
}) })
} catch (err) {
error(`Not able to download repo: ${err.stack}`) const tmpContents = await fs.readdir(tmpDir.path)
} tmpDir.path = path.join(tmpDir.path, tmpContents[0])
return tmpDir return tmpDir
} }
@ -75,8 +78,14 @@ export const onGitHub = async (path, debug) => {
return false return false
} }
const tmpDir = await downloadRepo(path) let tmpDir
console.log(tmpDir)
return 'test' try {
tmpDir = await downloadRepo(path)
} catch (err) {
error(`Not able to download repo: ${err.stack}`)
process.exit(1)
}
return tmpDir
} }

Loading…
Cancel
Save