diff --git a/js/cli/src/dependencies/coursier.ts b/js/cli/src/dependencies/coursier.ts deleted file mode 100644 index 1e4838c..0000000 --- a/js/cli/src/dependencies/coursier.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { existsSync } from "fs"; -import fs from "fs/promises"; - -import { downloadFile } from "./download"; -import { logger } from "../log"; -import { versions } from "./versions"; -import { promisify } from "util"; -import { exec } from "child_process"; -import { osType } from "./os"; - -export const installCoursier = async (gatlingHomeDir: string, downloadDir: string): Promise => { - const coursierRootPath = `${gatlingHomeDir}/coursier/${versions.coursier}`; - const coursierPath = `${coursierRootPath}/cs`; - - if (!existsSync(coursierPath)) { - const jarUrl = `https://github.com/coursier/coursier/releases/download/v${versions.coursier}/coursier`; - const windowsBatUrl = `https://github.com/coursier/launchers/raw/master/coursier.bat`; - const downloadPath = `${downloadDir}/cs`; - - if (existsSync(coursierRootPath)) { - await fs.rm(coursierRootPath, { recursive: true }); - } - if (existsSync(downloadPath)) { - await fs.rm(downloadPath); - } - await fs.mkdir(coursierRootPath, { recursive: true }); - - logger.info(`Downloading Coursier ${versions.coursier} to ${downloadPath}`); - await downloadFile(jarUrl, downloadPath); - if (osType === "Windows_NT") { - await downloadFile(windowsBatUrl, `${downloadPath}.bat`); - } else { - await fs.chmod(downloadPath, 0o744); - } - - logger.info(`Installing Coursier to ${coursierPath}`); - await fs.rename(downloadPath, coursierPath); - if (osType === "Windows_NT") { - await fs.rename(`${downloadPath}.bat`, `${coursierPath}.bat`); - } - } else { - logger.info(`Coursier ${versions.coursier} already installed at ${coursierPath}`); - } - - return coursierPath; -}; - -export const resolveGatlingJsDependencies = async ( - coursierPath: string, - javaHome: string, - postmanVersion?: string -): Promise => { - const dependencies = [ - `"io.gatling.highcharts:gatling-charts-highcharts:${versions.gatling.core}"`, - `"io.gatling:gatling-jvm-to-js-adapter:${versions.gatling.jsAdapter}"`, - `"io.gatling:gatling-enterprise-plugin-commons:${versions.gatling.enterprisePluginCommons}"`, - `"org.graalvm.polyglot:js-community:${versions.graalvm.js}"` - ]; - if (postmanVersion !== undefined) { - dependencies.push(`"io.gatling:gatling-postman-jvm-to-js-adapter:${postmanVersion}"`); - } - - return await resolveDependencies(coursierPath, javaHome, ...dependencies); -}; - -export const resolveRecorderDependencies = async (coursierPath: string, javaHome: string): Promise => { - const recorderDep = `io.gatling:gatling-recorder:${versions.gatling.core}`; - return await resolveDependencies(coursierPath, javaHome, recorderDep); -}; - -const resolveDependencies = async ( - coursierPath: string, - javaHome: string, - ...dependencies: string[] -): Promise => { - const command = `"${coursierPath}" fetch --classpath ${dependencies.join(" ")}`; - - // TODO could add a timeout - logger.info(`Resolving dependencies with Coursier`); - const { stdout } = await execAsync(command, { env: { ...process.env, JAVA_HOME: javaHome } }); - return stdout; -}; - -const execAsync = promisify(exec); diff --git a/js/cli/src/dependencies/graalVm.ts b/js/cli/src/dependencies/graalVm.ts deleted file mode 100644 index 9fbab73..0000000 --- a/js/cli/src/dependencies/graalVm.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { existsSync } from "fs"; -import fs from "fs/promises"; -import decompress from "decompress"; - -import { downloadFile } from "./download"; -import { logger } from "../log"; -import { osType, osArch } from "./os"; -import { versions } from "./versions"; - -export const installGraalVm = async (gatlingHomeDir: string, downloadDir: string): Promise => { - const { os, arch, extension, homePath, binPath } = graalVmPlatformParams(); - const graalvmRootPath = `${gatlingHomeDir}/graalvm/${versions.graalvm.jdk}`; - const graalvmHomePath = `${graalvmRootPath}${homePath}`; - const graalvmJavaPath = `${graalvmHomePath}${binPath}`; - - if (!existsSync(graalvmJavaPath)) { - const url = `https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${versions.graalvm.jdk}/graalvm-community-jdk-${versions.graalvm.jdk}_${os}-${arch}_bin.${extension}`; - const downloadPath = `${downloadDir}/graalvm.${extension}`; - - if (existsSync(graalvmRootPath)) { - await fs.rm(graalvmRootPath, { recursive: true }); - } - if (existsSync(downloadPath)) { - await fs.rm(downloadPath); - } - await fs.mkdir(graalvmRootPath, { recursive: true }); - - logger.info(`Downloading GraalVM Community Edition ${versions.graalvm.jdk} to ${downloadPath}`); - await downloadFile(url, downloadPath); - - logger.info(`Unpacking GraalVM to ${graalvmRootPath}`); - await decompress(downloadPath, graalvmRootPath, { - map: (file) => { - // Remove first level of file name, because it already contains a root directory - file.path = file.path.split("/").slice(1).join("/"); - return file; - } - }); - - await fs.rm(downloadPath); - } else { - logger.info(`GraalVM Community Edition ${versions.graalvm.jdk} already installed at ${graalvmRootPath}`); - } - - return graalvmHomePath; -}; - -const graalVmPlatformParams = () => { - if (osType === "Linux") { - const os = "linux"; - const extension = "tar.gz"; - const homePath = ""; - const binPath = "/bin/java"; - if (osArch === "x64") { - return { os, arch: "x64", extension, homePath, binPath }; - } else if (osArch === "arm64") { - return { os, arch: "aarch64", extension, homePath, binPath }; - } - } else if (osType === "Darwin") { - const os = "macos"; - const extension = "tar.gz"; - const homePath = "/Contents/Home"; - const binPath = "/bin/java"; - if (osArch === "x64") { - return { os, arch: "x64", extension, homePath, binPath }; - } else if (osArch === "arm64") { - return { os, arch: "aarch64", extension, homePath, binPath }; - } - } else if (osType === "Windows_NT" && osArch === "x64") { - return { os: "windows", arch: "x64", extension: "zip", homePath: "", binPath: "/bin/java.exe" }; - } - - throw Error(`Operating system type '${osType}' with architecture '${osArch}' is not currently supported.`); -};