makiwara 2.2.1 → 2.3.0

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/bin/cli.js CHANGED
@@ -5,10 +5,8 @@ const https = require("https");
5
5
  http.globalAgent.maxSockets = https.globalAgent.maxSockets = 512;
6
6
  // http.globalAgent.maxFreeSockets = https.globalAgent.maxFreeSockets = 512;
7
7
 
8
- const { Command } = require("commander");
9
- const program = new Command();
8
+ const minimist = require("minimist");
10
9
 
11
- const ora = require("ora");
12
10
  const isUrl = require("is-url");
13
11
  const bold = require("ansi-bold");
14
12
 
@@ -21,37 +19,61 @@ const { makeRequest } = require("../src/make-requests");
21
19
  const pkg = require("../package.json");
22
20
  const STRATEGY_REGEXP = /^(concurrent|sequence)$/;
23
21
 
24
- program
25
- .version(pkg.version)
26
- .option(
27
- "-u, --url <url>",
28
- "Define URL to benchmark. Ex. https://example.org/"
29
- )
30
- .option(
31
- "-t, --timelimit [numbers]",
32
- "Define list of time thresholds (in seconds). Ex. 10,100,1000"
33
- )
34
- .option(
35
- "-s, --strategy <concurrent|sequence>",
36
- "Define strategy for making requests"
37
- )
38
- .description(
39
- "Example:\n\tmakiwara -u https://localhost:3000 -t 10 -s sequence"
40
- )
41
- .parse(process.argv);
42
-
43
- const options = program.opts();
22
+ const argv = minimist(process.argv.slice(2), {
23
+ string: ["url", "timelimit", "strategy"],
24
+ alias: {
25
+ u: "url",
26
+ t: "timelimit",
27
+ s: "strategy",
28
+ v: "version",
29
+ h: "help",
30
+ },
31
+ });
32
+
33
+ function displayHelp() {
34
+ console.log(`
35
+ ${pkg.name} v${pkg.version}
36
+
37
+ Usage: makiwara [options]
38
+
39
+ Options:
40
+ -u, --url <url> Define URL to benchmark. Ex. https://example.org/
41
+ -t, --timelimit [numbers] Define list of time thresholds (in seconds). Ex. 10,100,1000
42
+ -s, --strategy <concurrent|sequence> Define strategy for making requests
43
+ -v, --version Show version number
44
+ -h, --help Show help
45
+
46
+ Example:
47
+ makiwara -u https://localhost:3000 -t 10 -s sequence
48
+ `);
49
+ process.exit(0);
50
+ }
51
+
52
+ if (argv.version) {
53
+ console.log(pkg.version);
54
+ process.exit(0);
55
+ }
56
+
57
+ if (argv.help) {
58
+ displayHelp();
59
+ }
60
+
61
+ const options = {
62
+ url: argv.url,
63
+ timelimit: argv.timelimit,
64
+ strategy: argv.strategy,
65
+ };
44
66
 
45
67
  if (typeof options.url !== "string") {
46
68
  displayHeader();
47
69
  logger.red("Error: url is not a string\n");
48
- program.help();
70
+ displayHelp();
49
71
  }
50
72
 
51
73
  if (!isUrl(options.url)) {
52
74
  displayHeader();
53
75
  logger.red("Error: url is not correct format\n");
54
- program.help();
76
+ displayHelp();
55
77
  }
56
78
 
57
79
  if (!options.timelimit) {
@@ -71,7 +93,6 @@ if (!STRATEGY_REGEXP.test(options.strategy)) {
71
93
  const url = options.url;
72
94
  const timeLimit = options.timelimit.split(",").map(Number);
73
95
  const strategy = options.strategy;
74
- let spinner = null;
75
96
 
76
97
  function displayDelimiter() {
77
98
  logger.gray("----------------------------------------------------\n");
@@ -84,13 +105,13 @@ function displayHeader() {
84
105
  }
85
106
 
86
107
  async function sendTestRequest(testUrl) {
87
- spinner.succeed(`Start testing... ${bold(testUrl)}`);
108
+ console.log(`Start testing... ${bold(testUrl)}`);
88
109
  const response = await makeRequest(testUrl, { agent: false });
89
110
  if (response.status !== HTTP_STATUS.OK) {
90
111
  logger.red(`HTTP Status Code: ${bold(response.status)}`);
91
112
  logger.yellow(`Response Body: ${bold(response.text)}`);
92
113
  }
93
- spinner.succeed(
114
+ console.log(
94
115
  `Testing completed (response: ${bold(response.text.length)} Bytes)`
95
116
  );
96
117
  }
@@ -98,15 +119,12 @@ async function sendTestRequest(testUrl) {
98
119
  async function main() {
99
120
  displayHeader();
100
121
 
101
- spinner = ora("Loading").start();
102
-
103
122
  try {
104
123
  await sendTestRequest(url);
105
124
 
106
- spinner.succeed("Start benchmarking...");
125
+ console.log("Start benchmarking...");
107
126
  const results = await benchmark(url, timeLimit, strategy);
108
- spinner.stop();
109
- spinner.succeed("Benchmarking completed\n");
127
+ console.log("Benchmarking completed\n");
110
128
 
111
129
  results.forEach((result, index) => {
112
130
  displaySummary(result);
@@ -116,7 +134,6 @@ async function main() {
116
134
  }
117
135
  });
118
136
  } catch (err) {
119
- spinner.stop();
120
137
  logger.red(err);
121
138
  }
122
139
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "makiwara",
3
3
  "description": "🔨 CLI to benchmark URL to gain HTTP requests limits",
4
- "version": "2.2.1",
4
+ "version": "2.3.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Piotr Kowalski",
@@ -9,7 +9,7 @@
9
9
  "url": "https://piecioshka.pl/"
10
10
  },
11
11
  "scripts": {
12
- "clear": "rm -rf dist/ coverage/ .nyc_output/",
12
+ "clear": "rm -rf dist/ coverage/",
13
13
  "clear:all": "rm -rf node_modules/ && npm run clear",
14
14
  "test": "jest --watchAll=false",
15
15
  "test:watch": "jest",
@@ -19,26 +19,25 @@
19
19
  "prepare": "npm run snyk-protect"
20
20
  },
21
21
  "dependencies": {
22
- "@types/jest": "^29.5.14",
22
+ "@types/jest": "^30.0.0",
23
23
  "ansi-bold": "^0.1.1",
24
24
  "ansi-gray": "^0.1.1",
25
25
  "ansi-red": "^0.1.1",
26
26
  "ansi-yellow": "^0.1.1",
27
- "axios": "^1.7.9",
27
+ "axios": "^1.13.2",
28
28
  "http-status-codes": "^2.3.0",
29
29
  "is-url": "^1.2.4",
30
- "jest": "^29.7.0",
30
+ "jest": "^30.2.0",
31
+ "minimist": "^1.2.8",
31
32
  "node-fetch": "^3.3.2",
32
- "snyk": "^1.1295.0",
33
+ "snyk": "^1.1301.2",
33
34
  "table": "^6.9.0"
34
35
  },
35
36
  "devDependencies": {
36
- "@types/node": "^22.10.7",
37
- "commander": "^13.0.0",
37
+ "@types/node": "^25.0.6",
38
38
  "eslint": "^8.6.0",
39
- "eslint-config-piecioshka": "^2.3.6",
40
- "nock": "^13.5.6",
41
- "ora": "^5.4.1"
39
+ "eslint-config-piecioshka": "^2.3.7",
40
+ "nock": "^14.0.10"
42
41
  },
43
42
  "repository": {
44
43
  "type": "git",
@@ -48,7 +47,7 @@
48
47
  "url": "https://github.com/piecioshka/makiwara/issues"
49
48
  },
50
49
  "engines": {
51
- "node": ">=14"
50
+ "node": ">=18"
52
51
  },
53
52
  "files": [
54
53
  "bin",
@@ -12,10 +12,7 @@ function pause(timeoutInSeconds) {
12
12
  }
13
13
 
14
14
  function status(i) {
15
- if (global.spinner) {
16
- global.spinner.text = `Loading: ${i} time(s)`;
17
- global.spinner.render();
18
- }
15
+ process.stdout.write(`\rLoading: ${i} time(s)`);
19
16
  }
20
17
 
21
18
  async function makeRequestsInConcurrentMode(url, durationInSeconds) {