@uxf/scripts 1.4.0 → 1.5.1

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/.eslintrc.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "parser": "babel-eslint"
2
+ "parser": "@babel/eslint-parser"
3
3
  }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ babel.config.js with useful plugins.
4
+ */
5
+ module.exports = function (api) {
6
+ api.cache(true);
7
+ api.assertVersion("^7.4.5");
8
+
9
+ return {
10
+ presets: [
11
+ [
12
+ "@babel/preset-env",
13
+ {
14
+ targets: {
15
+ esmodules: true,
16
+ node: true,
17
+ },
18
+ },
19
+ ],
20
+ ],
21
+ };
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -23,8 +23,9 @@
23
23
  "yargs": "^16.0.3"
24
24
  },
25
25
  "devDependencies": {
26
- "babel-eslint": "^10.1.0",
27
- "eslint": "^7.20.0",
26
+ "@babel/eslint-parser": "^7.17.0",
27
+ "@babel/preset-env": "^7.16.11",
28
+ "eslint": "^8.8.0",
28
29
  "prettier": "^2.1.2"
29
30
  },
30
31
  "scripts": {
package/src/Slack.js CHANGED
@@ -19,7 +19,7 @@ async function chatPostMessage(channel, data, dryRun = false) {
19
19
  process.stdout.write("SLACK: chat.postMessage error - " + JSON.stringify(res.data));
20
20
  }
21
21
  } else {
22
- process.stdout.write("SLACK: chat.postMessage - skipped");
22
+ process.stdout.write("SLACK: chat.postMessage - skipped\n");
23
23
  }
24
24
  }
25
25
 
@@ -39,13 +39,19 @@ Environment variables:
39
39
  type: "string",
40
40
  group: "Options",
41
41
  })
42
+ .option("skip", {
43
+ describe: "Number of skipped urls.",
44
+ type: "string",
45
+ group: "Options",
46
+ })
42
47
  .option("h", { alias: "help", group: "Options" })
43
48
  .strict(false)
44
49
  .exitProcess(false);
45
50
 
46
51
  try {
47
52
  const { help, url, ...options } = cli.parse(argv.slice(2));
48
- const webUrl = options["web-url"] ?? null;
53
+ const skip = options.skip ? Number.parseInt(options.skip) : null;
54
+ const webUrl = options["web-url"] || null;
49
55
 
50
56
  if (Boolean(help)) {
51
57
  return 0;
@@ -56,7 +62,7 @@ Environment variables:
56
62
  env.HTTP_PASSWORD = options["http-password"];
57
63
  }
58
64
 
59
- await require("./index")(url, webUrl, options["slack-channel"]);
65
+ await require("./index")(url, webUrl, options["slack-channel"], skip);
60
66
  } catch (e) {
61
67
  console.error(e);
62
68
  return 1;
@@ -35,7 +35,7 @@ async function tryUrl(url, ttl = 1) {
35
35
  }
36
36
  }
37
37
 
38
- module.exports = async function run(sitemapUrl, webUrl, slackChannel) {
38
+ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip) {
39
39
  if (!sitemapUrl) {
40
40
  stdout.write("⛔ Required parameter --url is empty.\n");
41
41
  return process.exit(1);
@@ -55,16 +55,13 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel) {
55
55
 
56
56
  const results = [];
57
57
 
58
- let i = 0;
59
- for (const url of urls) {
60
- if (i > 4) {
61
- continue;
62
- }
58
+ for (let i = skip || 0; i < urls.length; i++) {
59
+ const url = urls[i];
63
60
  const changedUrl = webUrl ? `${webUrl}${new URL(url).pathname}` : null;
64
61
 
65
- stdout.write(`${++i} / ${urls.length} ${url}${changedUrl ? ` => ${changedUrl}` : ""}`);
62
+ stdout.write(`${i + 1} / ${urls.length} ${url}${changedUrl ? ` => ${changedUrl}` : ""}`);
66
63
 
67
- const result = await tryUrl(changedUrl ?? url);
64
+ const result = await tryUrl(changedUrl || url);
68
65
  results.push(result);
69
66
  const { ttl, status, time } = result;
70
67
 
@@ -74,14 +71,20 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel) {
74
71
  const avgTime = Math.round(results.reduce((prev, curr) => prev + curr.time, 0) / results.length);
75
72
  const maxTime = Math.round(results.reduce((prev, curr) => (curr.time > prev ? curr.time : prev), 0));
76
73
  const minTime = Math.round(results.reduce((prev, curr) => (curr.time < prev ? curr.time : prev), Number.MAX_VALUE));
74
+ const resultErrors = results.filter(r => r.status !== 200);
75
+
76
+ if (resultErrors.length > 0) {
77
+ stdout.write("\nErrors:\n");
78
+ stdout.write(resultErrors.map(re => ` ${re.url} ${re.status}`)).join("\n");
79
+ stdout.write("\n");
80
+ }
81
+
77
82
  stdout.write("\n");
78
83
  stdout.write("Summary:\n");
79
84
  stdout.write(` Average time ${avgTime}ms\n`);
80
85
  stdout.write(` Min time ${minTime}ms\n`);
81
86
  stdout.write(` Max time ${maxTime}ms\n\n`);
82
87
 
83
- const resultErrors = results.filter(r => r.status !== 200);
84
-
85
88
  if (resultErrors.length > 0) {
86
89
  await Slack.chatPostMessage(slackChannel, {
87
90
  text: ":warning: Odkazy uvedené v sitemap.xml nejsou dostupné",