Skip to content

Commit 94fab2d

Browse files
guilgalynotdryft
authored andcommittedDec 10, 2024
feat: Automatically download bundle as needed
1 parent f855f97 commit 94fab2d

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed
 

‎install-all-with-links.sh

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ cd "$root_dir/js"
1212
npm install
1313
"$root_dir/build-js.sh"
1414

15-
# Install bundle
16-
"$root_dir/build-bundle.sh"
17-
1815
# Install js-simulation
1916
cd "$root_dir/js-simulation"
2017
# Multiple packages MUST be linked all at once (executing 'npm link <pkg>' again will remove previous links...):

‎js/cli/src/dependencies/index.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import * as fsSync from "node:fs";
12
import fs from "node:fs/promises";
23
import path from "node:path";
34

45
import StreamZip from "node-stream-zip";
56

7+
import { downloadFile } from "./download";
68
import { logger } from "../log";
7-
import { osType } from "./os";
9+
import { osArch, osType } from "./os";
810
import { versions } from "./versions";
911

1012
export { versions } from "./versions";
@@ -67,11 +69,10 @@ export const resolveBundle = async (options: BundleOptions): Promise<ResolvedBun
6769
if (version !== versions.gatling.jsAdapter) {
6870
throw Error(`Inconsistent bundle content found at ${bundlePath}`);
6971
}
72+
return getResolvedBundle(bundlePath);
7073
} else {
71-
throw Error("TODO try to install the bundle automatically");
74+
return await downloadAndInstallBundle(options);
7275
}
73-
74-
return getResolvedBundle(bundlePath);
7576
};
7677

7778
const getBundlePath = (options: BundleOptions, version: string) =>
@@ -96,3 +97,34 @@ const getResolvedBundle = (bundlePath: string): ResolvedBundle => ({
9697
graalvmHome: path.join(bundlePath, "graalvm"),
9798
jvmClasspath: path.join(bundlePath, "lib", "java", "*")
9899
});
100+
101+
const downloadAndInstallBundle = async (options: BundleOptions) => {
102+
const tmpFolder = path.join(options.gatlingHome, "tmp");
103+
if (!fsSync.existsSync(tmpFolder)) {
104+
await fs.mkdir(tmpFolder);
105+
}
106+
107+
const tmpFile = path.join(tmpFolder, "bundle-download.zip");
108+
if (fsSync.existsSync(tmpFile)) {
109+
await fs.rm(tmpFile);
110+
}
111+
112+
const version = versions.gatling.jsAdapter;
113+
const url = `https://github.com/gatling/gatling-js/releases/download/v${version}/gatling-js-bundle-${version}-${osType}-${osArch}.zip`;
114+
try {
115+
logger.info(`Downloading bundle file from ${url} to temporary file ${tmpFile}`);
116+
await downloadFile(url, tmpFile);
117+
118+
const resolvedBundle = await installBundleFile({ ...options, bundleFilePath: tmpFile });
119+
120+
logger.info(`Deleting temporary file ${tmpFile}`);
121+
await fs.rm(tmpFile);
122+
123+
return resolvedBundle;
124+
} catch (e) {
125+
logger.error(`Failed to automatically download and install the Gatling dependency bundle. You can try to:
126+
1. Make sure you have access to https://github.com/gatling/gatling-js/releases/; and if you connect to the Internet through a proxy, make sure it is configured in your NPM configuration file (.npmrc).
127+
2. Alternatively, you can try manually downloading the file from ${url}, and install it with the command 'npx gatling install <path-to-downloaded-file.zip>'.`);
128+
throw e;
129+
}
130+
};

0 commit comments

Comments
 (0)
Please sign in to comment.