UNPKG

938 BJavaScriptView Raw
1'use strict';
2
3let child_process = require('child_process');
4
5module.exports = function (context) {
6
7 function exec (args) {
8 return new Promise(function (fulfill, reject) {
9 child_process.execFile('git', args, function (error, stdout) {
10 if (error) { return reject(error); }
11 fulfill(stdout.trim());
12 });
13 });
14 }
15
16 function spawn (args) {
17 return new Promise(function (fulfill, reject) {
18 let s = child_process.spawn('git', args, {stdio: [0,1,2]});
19 s.on('error', reject);
20 s.on('close', fulfill);
21 });
22 }
23
24 function remoteFromGitConfig () {
25 return exec(['config', 'heroku.remote']).catch(function () {});
26 }
27
28 function sshGitUrl(app) {
29 return `git@${context.gitHost}:${app}.git`;
30 }
31
32 function httpGitUrl(app) {
33 return `https://${context.httpGitHost}/${app}.git`;
34 }
35
36 return {
37 exec,
38 spawn,
39 remoteFromGitConfig,
40 sshGitUrl,
41 httpGitUrl
42 };
43};