This repository has been archived by the owner on Oct 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have a github fallback if git isn't setup locally.
- Loading branch information
Blaine Schmeisser
committed
Dec 27, 2016
1 parent
6772c8a
commit 8983a0a
Showing
8 changed files
with
125 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const git = require('./git') | ||
const github = require('./github') | ||
|
||
module.exports = git.isInstalled() ? git : github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const request = require('request') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const json = require('./json') | ||
const jetpack = require('fs-jetpack') | ||
const decompress = require('decompress') | ||
|
||
const currentRemoteVersion = (name) => { | ||
return json({ host: 'api.github.com', | ||
path: '/repos/' + name + '/commits', | ||
}).then((response) => { | ||
return response[0] && response[0].sha || '' | ||
}) | ||
} | ||
|
||
const currentLocalVersion = (packagePath) => { | ||
const versionPath = path.join(packagePath, '.head.zazu.') | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(versionPath, (_, data) => { | ||
resolve(data || '') | ||
}) | ||
}) | ||
} | ||
|
||
const pull = (name, packagePath) => { | ||
const versions = [currentRemoteVersion(name), currentLocalVersion(packagePath)] | ||
return Promise.all(versions).then(([remoteVersion, localVersion]) => { | ||
if (remoteVersion === localVersion) return | ||
return jetpack.removeAsync(packagePath).then(() => { | ||
return clone(name, packagePath) | ||
}) | ||
}) | ||
} | ||
|
||
const download = (remote, local) => { | ||
return new Promise((resolve, reject) => { | ||
request(remote) | ||
.pipe(fs.createWriteStream(local)) | ||
.on('close', () => { | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
const clone = (name, packagePath) => { | ||
return currentRemoteVersion(name).then((version) => { | ||
const zipUrl = `https://github.com/${name}/archive/${version}.zip` | ||
const packageName = name.split('/')[1] | ||
const extractDir = path.join(packagePath, '..') | ||
const extractPath = path.join(extractDir, `${packageName}-${version}`) | ||
const tempPath = path.join(extractDir, `${packageName}-${version}.zip`) | ||
const versionPath = path.join(packagePath, '.head.zazu.') | ||
return download(zipUrl, tempPath).then(() => { | ||
return decompress(tempPath, extractDir) | ||
}).then(() => { | ||
return jetpack.removeAsync(tempPath) | ||
}).then(() => { | ||
return jetpack.renameAsync(extractPath, packageName) | ||
}).then(() => { | ||
return jetpack.writeAsync(versionPath, version) | ||
}) | ||
}) | ||
} | ||
|
||
const isInstalled = () => { | ||
return true | ||
} | ||
|
||
module.exports = { clone, pull, isInstalled } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const electron = require('electron') | ||
const https = require('https') | ||
const app = electron.app || electron.remote.app | ||
|
||
module.exports = (opts) => { | ||
const options = Object.assign({}, opts, { | ||
headers: { | ||
'User-Agent': `ZazuApp v${app.getVersion()}`, | ||
}, | ||
}) | ||
return new Promise((resolve) => { | ||
https.get(options, (res) => { | ||
var chunks = [] | ||
res.on('data', (chunk) => { | ||
chunks.push(chunk.toString()) | ||
}) | ||
res.on('end', () => { | ||
resolve(JSON.parse(chunks.join(''))) | ||
}) | ||
res.on('error', (e) => { | ||
throw e | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters