Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from PhilippeWeidmann/main
Browse files Browse the repository at this point in the history
Fix action
  • Loading branch information
pepicrft authored Dec 14, 2021
2 parents 42bb6d5 + 02d65c9 commit e874fba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const process = require("process");
const path = require("path");

exports.tuistEnvPath = path.join(process.cwd(), "tuist");
exports.tuistEnvPath = path.join(process.cwd(), "tuistexec");
26 changes: 21 additions & 5 deletions src/downloadFile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
const https = require("https");
const fs = require("fs");

module.exports = (url, into) => {
const file = fs.createWriteStream(into);
https.get(url, (response) => {
response.pipe(file);
});
function downloadFileFollowRedirect(url, file, resolve) {
https.get(url, (response) => {
if (response.statusCode === 301 || response.statusCode === 302) {
return downloadFileFollowRedirect(response.headers.location, file, resolve)
} else {
response.pipe(file);
file.on('finish', function () {
file.close(function () {
resolve();
})
});
}
});
}

module.exports = async (url, into) => {
const file = fs.createWriteStream(into);
let promise = new Promise((resolve, reject) => {
downloadFileFollowRedirect(url, file, resolve);
});
await promise;
};
5 changes: 3 additions & 2 deletions src/installTuist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ module.exports = async () => {
const tmpobj = tmp.dirSync();
const tuistEnvTmpZipPath = path.join(tmpobj.name, "tuistenv.zip");
const tuistEnvUnzippedPath = path.join(tmpobj.name, "tuistenv");
const tuistExecEnvUnzippedPath = path.join(tuistEnvUnzippedPath, "tuistenv");
const tuistEnvURL = await latestReleaseTuistEnvDownloadURL();
console.log("Downloading Tuist...");
downloadFile(tuistEnvURL, tuistEnvTmpZipPath);
await downloadFile(tuistEnvURL, tuistEnvTmpZipPath);
execSync(`unzip -o ${tuistEnvTmpZipPath} -d ${tuistEnvUnzippedPath}`);
execSync(`cp ${tuistEnvUnzippedPath} ${tuistEnvPath}`);
execSync(`cp ${tuistExecEnvUnzippedPath} ${tuistEnvPath}`);
execSync(`chmod +x ${tuistEnvPath}`);
console.log("Tuist has been installed.");
};

0 comments on commit e874fba

Please sign in to comment.