Skip to content
This repository was archived by the owner on Jun 16, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions _util/download-module.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
const cp = require('child_process');
const getConfig = require('./get-config');
const fse = require('fs-extra');
const request = require('request');
const tar = require('tar');
const zlib = require('zlib');
const getUrl = require('./get-module-download-url');
const getTag = require('./get-tag-info');
const moduleParentPath = require('./module-parent-path');

module.exports = function downloadModule() {
return getUrl()
.then(download);
const useGitClone = getConfig('use_git_clone');

if (!useGitClone) {
return getUrl()
.then(downloadTarball);
}

return gitCloneRepo();
};

function download(url) {
function gitCloneRepo() {
const token = getConfig('gh_token');
const module = getConfig('module');

if (!token) {
return Promise.reject(new Error("The `gh_token` config isn't set. You're Gonna Have A Bad Time."));
}

if (!module) {
return Promise.reject(new Error("The `module` config isn't set. You're Gonna Have A Bad Time."));
}

return getTag()
.then(({moduleVersion}) => {
const url = `https://${token}@github.com/${module}`;
const cwd = moduleParentPath();


fse.removeSync(cwd);
fse.ensureDirSync(cwd);

return new Promise((resolve, reject) => {
cp.exec(`git clone ${url} --branch ${moduleVersion} --depth=1`, {cwd}, (error, stderr, stdout) => {
if (error) {
console.log(`Could not clone. Error code: ${error}`);
console.log(stderr);
return reject(error);
}

resolve();
});
});
})
}

function downloadTarball(url) {
console.log(`${new Date().toString()} downloading module from ${url}`)
const opts = {
headers: {
Expand Down