@gatling.io/cli 3.11.3 → 3.11.4-M1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gatling.io/cli",
3
- "version": "3.11.3",
3
+ "version": "3.11.4-M1",
4
4
  "license": "Apache-2.0",
5
5
  "bin": {
6
6
  "gatling": "target/index.js"
@@ -8,6 +8,7 @@
8
8
  "main": "target/index.js",
9
9
  "types": "target/index.d.ts",
10
10
  "dependencies": {
11
+ "archiver": "7.0.1",
11
12
  "axios": "1.6.8",
12
13
  "commander": "12.0.0",
13
14
  "decompress": "4.2.1",
@@ -15,6 +16,7 @@
15
16
  "esbuild-plugin-tsc": "0.4.0"
16
17
  },
17
18
  "devDependencies": {
19
+ "@types/archiver": "6.0.2",
18
20
  "@types/decompress": "4.2.7",
19
21
  "@types/node": "20.12.12",
20
22
  "prettier": "3.2.5",
@@ -1,6 +1,8 @@
1
+ import { SimulationFile } from "./simulations";
1
2
  export interface BundleOptions {
2
3
  sourcesFolder: string;
3
4
  bundleFile: string;
4
5
  typescript: boolean;
6
+ simulations: SimulationFile[];
5
7
  }
6
8
  export declare const bundle: (options: BundleOptions) => Promise<void>;
package/target/bundle.js CHANGED
@@ -29,17 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.bundle = void 0;
30
30
  const esbuild = __importStar(require("esbuild"));
31
31
  const esbuild_plugin_tsc_1 = __importDefault(require("esbuild-plugin-tsc"));
32
- const promises_1 = __importDefault(require("fs/promises"));
33
32
  const log_1 = require("./log");
34
33
  const bundle = async (options) => {
35
- log_1.logger.info(`Packaging a Gatling simulation with options:
34
+ log_1.logger.info(`Bundling a Gatling simulation with options:
36
35
  - sourcesFolder: ${options.sourcesFolder}
37
- - bundleFile: ${options.bundleFile}`);
38
- const children = await promises_1.default.readdir(options.sourcesFolder, { recursive: false });
39
- const contents = children
40
- .filter((f) => (options.typescript ? f.endsWith(".gatling.ts") : f.endsWith(".gatling.js")))
41
- .map((f) => `export { default as "${f.slice(0, -11)}" } from "./${f}";`)
42
- .join("\n");
36
+ - bundleFile: ${options.bundleFile}
37
+ - typescript: ${options.typescript}`);
38
+ const contents = options.simulations.map((s) => `export { default as "${s.name}" } from "./${s.path}";`).join("\n");
43
39
  const plugins = options.typescript ? [(0, esbuild_plugin_tsc_1.default)({ force: true })] : [];
44
40
  await esbuild.build({
45
41
  stdin: {
@@ -9,6 +9,6 @@ exports.versions = {
9
9
  coursier: "2.1.10",
10
10
  gatling: {
11
11
  core: "3.11.3",
12
- jsAdapter: "3.11.3"
12
+ jsAdapter: "3.11.4-M1"
13
13
  }
14
14
  };
@@ -0,0 +1,8 @@
1
+ import { SimulationFile } from "./simulations";
2
+ export interface EnterprisePackageOptions {
3
+ bundleFile: string;
4
+ resourcesFolder: string;
5
+ enterprisePackageFile: string;
6
+ simulations: SimulationFile[];
7
+ }
8
+ export declare const enterprisePackage: (options: EnterprisePackageOptions) => Promise<void>;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.enterprisePackage = void 0;
7
+ const archiver_1 = __importDefault(require("archiver"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const promises_1 = require("stream/promises");
10
+ const zlib_1 = require("zlib");
11
+ const versions_1 = require("./dependencies/versions");
12
+ const log_1 = require("./log");
13
+ const enterprisePackage = async (options) => {
14
+ log_1.logger.info(`Packaging a Gatling simulation with options:
15
+ - bundleFile: ${options.bundleFile}
16
+ - enterprisePackageFile: ${options.enterprisePackageFile}`);
17
+ const manifest = generateManifest(options.simulations.map((s) => s.name));
18
+ const output = fs_1.default.createWriteStream(options.enterprisePackageFile);
19
+ const archive = (0, archiver_1.default)("zip", {
20
+ zlib: { level: zlib_1.constants.Z_MAX_LEVEL }
21
+ });
22
+ archive.on("warning", (err) => {
23
+ // The pipeline will rethrow errors but not warnings. We don't want to ignore warnings from the archiver, because
24
+ // they include things like 'no such file or directory'.
25
+ throw err;
26
+ });
27
+ archive.file(options.bundleFile, { name: "bundle.js" });
28
+ archive.append(Buffer.from(manifest), { name: "META-INF/MANIFEST.MF" });
29
+ archive.directory(options.resourcesFolder + "/", false);
30
+ archive.finalize();
31
+ await (0, promises_1.pipeline)(archive, output);
32
+ log_1.logger.info(`Package for Gatling Enterprise created at ${options.enterprisePackageFile}`);
33
+ };
34
+ exports.enterprisePackage = enterprisePackage;
35
+ const generateManifest = (simulationNames) => {
36
+ const utf8Encoder = new TextEncoder();
37
+ const eol = utf8Encoder.encode("\n");
38
+ const continuation = utf8Encoder.encode("\n ");
39
+ const lines = [
40
+ "Manifest-Version: 1.0",
41
+ "Implementation-Title: gatling-javascript",
42
+ `Implementation-Version: ${versions_1.versions.gatling.jsAdapter}`,
43
+ "Implementation-Vendor: GatlingCorp",
44
+ "Specification-Vendor: GatlingCorp",
45
+ "Gatling-Context: js",
46
+ `Gatling-Version: ${versions_1.versions.gatling.core}`,
47
+ "Gatling-Packager: javascript",
48
+ `Gatling-Packager-Version: ${versions_1.versions.gatling.jsAdapter}`,
49
+ `Gatling-Simulations: ${simulationNames.join(",")}`,
50
+ `Java-Version: ${versions_1.versions.graalvm.jdk.split(".")[0]}`
51
+ ];
52
+ let totalLength = 0;
53
+ const buffer = [];
54
+ for (const line of lines) {
55
+ let lineLength = 0;
56
+ for (const char of line) {
57
+ const bytes = utf8Encoder.encode(char);
58
+ const byteLength = bytes.byteLength;
59
+ if (lineLength + byteLength > 71) {
60
+ buffer.push(continuation);
61
+ buffer.push(bytes);
62
+ // reset length for the new line (with +1 for leading space)
63
+ lineLength = byteLength + 1;
64
+ totalLength += byteLength + 2;
65
+ }
66
+ else {
67
+ buffer.push(bytes);
68
+ lineLength += byteLength;
69
+ totalLength += byteLength;
70
+ }
71
+ }
72
+ buffer.push(eol);
73
+ totalLength += 1;
74
+ }
75
+ const manifest = new Uint8Array(totalLength);
76
+ let cursor = 0;
77
+ for (const elt of buffer) {
78
+ manifest.set(elt, cursor);
79
+ cursor += elt.byteLength;
80
+ }
81
+ return manifest;
82
+ };
package/target/index.js CHANGED
@@ -8,6 +8,8 @@ const commander_1 = require("commander");
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const bundle_1 = require("./bundle");
10
10
  const dependencies_1 = require("./dependencies");
11
+ const enterprisePackage_1 = require("./enterprisePackage");
12
+ const simulations_1 = require("./simulations");
11
13
  const log_1 = require("./log");
12
14
  const run_1 = require("./run");
13
15
  const program = new commander_1.Command()
@@ -17,11 +19,30 @@ const program = new commander_1.Command()
17
19
  const gatlingHomeOption = new commander_1.Option("--gatling-home <value>", 'The folder used to download and install Gatling components (default: "~/.gatling")');
18
20
  const gatlingHomeDirWithDefaults = (options) => options.gatlingHome || `${os_1.default.homedir()}/.gatling`;
19
21
  const sourcesFolderOption = new commander_1.Option("--sources-folder <value>", "The sources folder path").default("src");
20
- const simulationOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name").default("default", '"default", compatible with using "export default"');
21
- const bundleFileOption = new commander_1.Option("--bundle-file <value>", "The simulation target bundle file path").default("target/bundle.js");
22
+ const simulationOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name (default: if only one *.gatling.js or *.gatling.ts file is found, will execute that simulation)");
23
+ const simulationWithDefaults = (options, simulationsFound) => {
24
+ if (options.simulation !== undefined) {
25
+ return options.simulation;
26
+ }
27
+ else if (simulationsFound.length === 1) {
28
+ return simulationsFound[0].name;
29
+ }
30
+ else if (simulationsFound.length === 0) {
31
+ throw new Error("No simulation found, simulations must be defined in a <simulation name>.gatling.js or <simulation name>.gatling.ts file)");
32
+ }
33
+ else {
34
+ throw new Error(`Several simulations found, specify one using the --simulation option (available simulations: ${simulationsFound.map((s) => s.name)})`);
35
+ }
36
+ };
37
+ const simulationRequiredOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name").makeOptionMandatory(true);
38
+ const bundleFileOption = new commander_1.Option("--bundle-file <value>", "The target bundle file path when building simulations").default("target/bundle.js");
39
+ const enterprisePackageFileOption = new commander_1.Option("--enterprise-package-file <value>", "The target package file path when packaging simulations for Gatling Enterprise").default("target/package.jar");
22
40
  const resourcesFolderOption = new commander_1.Option("--resources-folder <value>", "The resources folder path").default("resources");
23
41
  const resultsFolderOption = new commander_1.Option("--results-folder <value>", "The results folder path").default("target/gatling");
24
- const typescriptOption = new commander_1.Option("--typescript", "Use the typescript compiler to compile your code").default(false);
42
+ const typescriptOption = new commander_1.Option("--typescript", "Use the typescript compiler to compile your code (default: true if the sourcesFolder contains any *.gatling.ts file, false otherwise)");
43
+ const typescriptWithDefaults = (options, simulationsFound) => options.typescript !== undefined
44
+ ? options.typescript
45
+ : simulationsFound.findIndex((s) => s.type === "typescript") >= 0;
25
46
  const graalvmHomeMandatoryOption = new commander_1.Option("--graalvm-home <value>", "Path to the GraalVM home").makeOptionMandatory(true);
26
47
  const jvmClasspathMandatoryOption = new commander_1.Option("--jvm-classpath <value>", "The classpath containing all Gatling JVM components").makeOptionMandatory(true);
27
48
  program
@@ -37,22 +58,23 @@ program
37
58
  });
38
59
  program
39
60
  .command("build")
40
- .description("Build a Gatling simulation")
61
+ .description("Build Gatling simulations")
41
62
  .addOption(sourcesFolderOption)
42
63
  .addOption(bundleFileOption)
43
64
  .addOption(typescriptOption)
44
65
  .action(async (options) => {
45
66
  const sourcesFolder = options.sourcesFolder;
46
67
  const bundleFile = options.bundleFile;
47
- const typescript = options.typescript;
48
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript });
68
+ const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
69
+ const typescript = typescriptWithDefaults(options, simulations);
70
+ await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
49
71
  });
50
72
  program
51
73
  .command("run-only")
52
- .description("Run a Gatling simulation")
74
+ .description("Run a Gatling simulation from an already built bundle")
53
75
  .addOption(graalvmHomeMandatoryOption)
54
76
  .addOption(jvmClasspathMandatoryOption)
55
- .addOption(simulationOption)
77
+ .addOption(simulationRequiredOption)
56
78
  .addOption(bundleFileOption)
57
79
  .addOption(resourcesFolderOption)
58
80
  .addOption(resultsFolderOption)
@@ -85,16 +107,17 @@ program
85
107
  .action(async (options) => {
86
108
  const gatlingHome = gatlingHomeDirWithDefaults(options);
87
109
  const sourcesFolder = options.sourcesFolder;
88
- const simulation = options.simulation;
89
110
  const bundleFile = options.bundleFile;
90
111
  const resourcesFolder = options.resourcesFolder;
91
112
  const resultsFolder = options.resultsFolder;
92
- const typescript = options.typescript;
113
+ const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
114
+ const typescript = typescriptWithDefaults(options, simulations);
115
+ const simulation = simulationWithDefaults(options, simulations);
93
116
  const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installGatlingJs)({ gatlingHome });
94
117
  log_1.logger.debug(`graalvmHome=${graalvmHome}`);
95
118
  log_1.logger.debug(`coursierBinary=${coursierBinary}`);
96
119
  log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
97
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript });
120
+ await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
98
121
  await (0, run_1.runSimulation)({ graalvmHome, jvmClasspath, simulation, bundleFile, resourcesFolder, resultsFolder });
99
122
  });
100
123
  program
@@ -108,11 +131,30 @@ program
108
131
  const gatlingHome = gatlingHomeDirWithDefaults(options);
109
132
  const sourcesFolder = options.sourcesFolder;
110
133
  const resourcesFolder = options.resourcesFolder;
111
- const typescript = options.typescript;
134
+ const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
135
+ const typescript = typescriptWithDefaults(options, simulations);
112
136
  const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installRecorder)({ gatlingHome });
113
137
  log_1.logger.debug(`graalvmHome=${graalvmHome}`);
114
138
  log_1.logger.debug(`coursierBinary=${coursierBinary}`);
115
139
  log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
116
140
  await (0, run_1.runRecorder)({ graalvmHome, jvmClasspath, sourcesFolder, typescript, resourcesFolder });
117
141
  });
142
+ program
143
+ .command("enterprise-package")
144
+ .description("Build Gatling simulations and package them for Gatling Enterprise")
145
+ .addOption(sourcesFolderOption)
146
+ .addOption(resourcesFolderOption)
147
+ .addOption(bundleFileOption)
148
+ .addOption(enterprisePackageFileOption)
149
+ .addOption(typescriptOption)
150
+ .action(async (options) => {
151
+ const sourcesFolder = options.sourcesFolder;
152
+ const resourcesFolder = options.resourcesFolder;
153
+ const bundleFile = options.bundleFile;
154
+ const enterprisePackageFile = options.enterprisePackageFile;
155
+ const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
156
+ const typescript = typescriptWithDefaults(options, simulations);
157
+ await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
158
+ await (0, enterprisePackage_1.enterprisePackage)({ bundleFile, resourcesFolder, enterprisePackageFile, simulations });
159
+ });
118
160
  program.parse(process.argv);
package/target/run.js CHANGED
@@ -8,7 +8,9 @@ const os_1 = require("./dependencies/os");
8
8
  const runSimulation = async (options) => {
9
9
  log_1.logger.info(`Running a Gatling simulation with options:
10
10
  - simulation: ${options.simulation}
11
- - bundleFile: ${options.bundleFile}`);
11
+ - bundleFile: ${options.bundleFile}
12
+ - resourcesFolder: ${options.resourcesFolder}
13
+ - resultsFolder: ${options.resultsFolder}`);
12
14
  const additionalClasspathElements = [options.resourcesFolder];
13
15
  const javaArgs = [
14
16
  `-Dgatling.js.bundle.filePath=${options.bundleFile}`,
@@ -28,7 +30,10 @@ const runSimulation = async (options) => {
28
30
  };
29
31
  exports.runSimulation = runSimulation;
30
32
  const runRecorder = async (options) => {
31
- log_1.logger.info("Running the Gatling Recorder");
33
+ log_1.logger.info(`Running the Gatling Recorder with options:
34
+ - sourcesFolder: ${options.sourcesFolder}
35
+ - resourcesFolder: ${options.resourcesFolder}
36
+ - typescript: ${options.typescript}`);
32
37
  const recorderArgs = [
33
38
  "--simulations-folder",
34
39
  options.sourcesFolder,
@@ -0,0 +1,6 @@
1
+ export interface SimulationFile {
2
+ path: string;
3
+ name: string;
4
+ type: "javascript" | "typescript";
5
+ }
6
+ export declare const findSimulations: (sourcesFolder: string) => Promise<Array<SimulationFile>>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findSimulations = void 0;
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
+ const findSimulations = async (sourcesFolder) => {
9
+ const children = await promises_1.default.readdir(sourcesFolder, { recursive: false });
10
+ const simulations = children
11
+ .filter((path) => path.endsWith(".gatling.js") || path.endsWith(".gatling.ts"))
12
+ .map((path) => ({
13
+ path,
14
+ name: path.slice(0, -11),
15
+ type: path.endsWith(".ts") ? "typescript" : "javascript"
16
+ }));
17
+ const duplicates = simulations.filter((value, index) => simulations.findIndex((other) => other.name === value.name) !== index);
18
+ if (duplicates.length > 0) {
19
+ throw Error(`Found ambiguous simulation name(s) ${duplicates.map((s) => s.name)}: found as both *.gatling.js and *.gatling.ts file(s)`);
20
+ }
21
+ return simulations;
22
+ };
23
+ exports.findSimulations = findSimulations;