Skip to content

Commit

Permalink
fix latest build
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Oct 5, 2023
1 parent 65ef2ec commit 120d511
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 77 deletions.
6 changes: 3 additions & 3 deletions build/npm/v2-jf/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function downloadWithProxy(myUrl) {
method: "CONNECT",
path: myUrlParts.hostname + ":443",
})
.on("connect", function (res, socket, head) {
.on("connect", function (res, socket, _) {
get(
{
host: myUrlParts.hostname,
Expand Down Expand Up @@ -115,7 +115,7 @@ function writeToFile(response) {
})
.on("error", function (err) {
console.error(err);
});
});
}

function getArchitecture() {
Expand Down Expand Up @@ -153,4 +153,4 @@ function getFileName() {
executable += ".exe";
}
return executable;
}
}
2 changes: 1 addition & 1 deletion build/npm/v2-jf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified build/npm/v2/bin/jfrog
100644 → 100755
Empty file.
168 changes: 96 additions & 72 deletions build/npm/v2/init.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,91 @@
validateNpmVersion();

var https = require('https');
var http = require('http');
var url = require('url');
var fs = require('fs');
var packageJson = require('./package.json');
var fileName = getFileName();
var filePath = "bin/" + fileName;
var version = packageJson.version;
var pkgName = "jfrog-cli-" + getArchitecture();
const {get} = require("https");
const {request} = require("http");
const {URL} = require("url");
const {createWriteStream, chmodSync} = require("fs");
const packageJson = require("./package.json");
const fileName = getFileName();
const filePath = "bin/" + fileName;
const version = packageJson.version;
const pkgName = "jfrog-cli-" + getArchitecture();

downloadCli();

function validateNpmVersion() {
if (!isValidNpmVersion()) {
throw new Error("JFrog CLI can be installed using npm version 5.0.0 or above.");
throw new Error(
"JFrog CLI can be installed using npm version 5.0.0 or above."
);
}
}

function downloadWithProxy(myUrl) {
var proxyparts = url.parse(process.env.https_proxy);
var myUrlParts = url.parse(myUrl);
const proxyParts = new URL(process.env.https_proxy);
const myUrlParts = new URL(myUrl);

http.request({
host: proxyparts.hostname,
port: proxyparts.port,
method: 'CONNECT',
path: myUrlParts.hostname + ':443'
}).on('connect', function (res, socket, head) {
https.get({
host: myUrlParts.hostname,
socket: socket,
path: myUrlParts.path,
agent: false
}, function (res) {
if (res.statusCode == 301 || res.statusCode == 302) {
downloadWithProxy(res.headers.location);
} else if (res.statusCode == 200) {
writeToFile(res);
} else {
console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download');
}
}).on('error', function (err) {
console.error(err);
});
}).end();
request({
host: proxyParts.hostname,
port: proxyParts.port,
method: "CONNECT",
path: myUrlParts.hostname + ":443",
})
.on("connect", function (res, socket, _) {
get(
{
host: myUrlParts.hostname,
socket: socket,
path: myUrlParts.path,
agent: false,
},
function (res) {
if (res.statusCode === 301 || res.statusCode === 302) {
downloadWithProxy(res.headers.location);
} else if (res.statusCode === 200) {
writeToFile(res);
} else {
console.log(
"Unexpected status code " +
res.statusCode +
" during JFrog CLI download"
);
}
}
).on("error", function (err) {
console.error(err);
});
})
.end();
}

function download(url) {
https.get(url, function (res) {
if (res.statusCode == 301 || res.statusCode == 302) {
get(url, function (res) {
if (res.statusCode === 301 || res.statusCode === 302) {
download(res.headers.location);
} else if (res.statusCode == 200) {
} else if (res.statusCode === 200) {
writeToFile(res);
} else {
console.log('Unexpected status code ' + res.statusCode + ' during JFrog CLI download');
console.log(
"Unexpected status code " +
res.statusCode +
" during JFrog CLI download"
);
}
}).on('error', function (err) {
}).on("error", function (err) {
console.error(err);
});
}

function downloadCli() {
console.log("Downloading JFrog CLI " + version);
var startUrl = 'https://releases.jfrog.io/artifactory/jfrog-cli/v2/' + version + '/' + pkgName + '/' + fileName;
// We detect outbount proxy by looking at the environment variable
const startUrl =
"https://releases.jfrog.io/artifactory/jfrog-cli/v2/" +
version +
"/" +
pkgName +
"/" +
fileName;
// We detect outbound proxy by looking at the environment variable
if (process.env.https_proxy && process.env.https_proxy.length > 0) {
downloadWithProxy(startUrl);
} else {
Expand All @@ -73,58 +94,61 @@ function downloadCli() {
}

function isValidNpmVersion() {
var child_process = require('child_process');
var npmVersionCmdOut = child_process.execSync("npm version -json");
var npmVersion = JSON.parse(npmVersionCmdOut).npm;
const child_process = require("child_process");
const npmVersionCmdOut = child_process.execSync("npm version -json");
const npmVersion = JSON.parse(npmVersionCmdOut).npm;
// Supported since version 5.0.0
return parseInt(npmVersion.charAt(0)) > 4;
}

function writeToFile(response) {
var file = fs.createWriteStream(filePath);
response.on('data', function (chunk) {
file.write(chunk);
}).on('end', function () {
file.end();
if (!process.platform.startsWith("win")) {
fs.chmodSync(filePath, 0555);
}
}).on('error', function (err) {
console.error(err);
});
const file = createWriteStream(filePath);
response
.on("data", function (chunk) {
file.write(chunk);
})
.on("end", function () {
file.end();
if (!process.platform.startsWith("win")) {
chmodSync(filePath, 755);
}
})
.on("error", function (err) {
console.error(err);
});
}

function getArchitecture() {
const platform = process.platform;
if (platform.startsWith('win')) {
if (platform.startsWith("win")) {
// Windows architecture:
return 'windows-amd64';
return "windows-amd64";
}
const arch = process.arch;
if (platform.includes('darwin')) {
if (platform.includes("darwin")) {
// macOS architecture:
return arch === 'arm64' ? 'mac-arm64' : 'mac-386';
return arch === "arm64" ? "mac-arm64" : "mac-386";
}

// linux architecture:
switch (arch) {
case 'x64':
return 'linux-amd64';
case 'arm64':
return 'linux-arm64';
case 'arm':
return 'linux-arm';
case 's390x':
return 'linux-s390x';
case 'ppc64':
return 'linux-ppc64';
case "x64":
return "linux-amd64";
case "arm64":
return "linux-arm64";
case "arm":
return "linux-arm";
case "s390x":
return "linux-s390x";
case "ppc64":
return "linux-ppc64";
default:
return 'linux-386';
return "linux-386";
}
}

function getFileName() {
var executable = "jfrog";
let executable = "jfrog";
if (process.platform.startsWith("win")) {
executable += ".exe";
}
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 120d511

Please sign in to comment.