@hexonet/semantic-release-whmcs 4.0.3 → 5.0.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.
Files changed (44) hide show
  1. package/.github/dependabot.yml +7 -7
  2. package/.github/workflows/release.yml +29 -0
  3. package/.github/workflows/{pull-request.yml → test.yml} +13 -16
  4. package/.releaserc.json +1 -5
  5. package/CONTRIBUTING.md +1 -1
  6. package/HISTORY.md +81 -62
  7. package/README.md +5 -5
  8. package/index.js +36 -30
  9. package/lib/definitions/errors.js +26 -13
  10. package/lib/delete-marketplace-version.js +48 -48
  11. package/lib/get-error.js +6 -6
  12. package/lib/get-github-releases.js +17 -18
  13. package/lib/publish.js +10 -13
  14. package/lib/puppet.js +73 -74
  15. package/lib/resolve-config.js +5 -6
  16. package/lib/scrape-marketplace-versions.js +30 -28
  17. package/lib/set-compatible-versions.js +42 -41
  18. package/lib/verify.js +14 -11
  19. package/package.json +35 -31
  20. package/whmcs.js +81 -53
  21. package/.eslintignore +0 -3
  22. package/.eslintrc.js +0 -14
  23. package/.github/workflows/push.yml +0 -79
  24. package/coverage/base.css +0 -224
  25. package/coverage/block-navigation.js +0 -87
  26. package/coverage/coverage-final.json +0 -11
  27. package/coverage/favicon.png +0 -0
  28. package/coverage/index.html +0 -131
  29. package/coverage/lib/definitions/errors.js.html +0 -136
  30. package/coverage/lib/definitions/index.html +0 -116
  31. package/coverage/lib/delete-marketplace-version.js.html +0 -343
  32. package/coverage/lib/get-error.js.html +0 -106
  33. package/coverage/lib/get-github-releases.js.html +0 -184
  34. package/coverage/lib/index.html +0 -236
  35. package/coverage/lib/publish.js.html +0 -370
  36. package/coverage/lib/puppet.js.html +0 -424
  37. package/coverage/lib/resolve-config.js.html +0 -118
  38. package/coverage/lib/scrape-marketplace-versions.js.html +0 -220
  39. package/coverage/lib/set-compatible-versions.js.html +0 -298
  40. package/coverage/lib/verify.js.html +0 -148
  41. package/coverage/prettify.css +0 -1
  42. package/coverage/prettify.js +0 -2
  43. package/coverage/sort-arrow-sprite.png +0 -0
  44. package/coverage/sorter.js +0 -196
package/lib/verify.js CHANGED
@@ -1,21 +1,24 @@
1
- const AggregateError = require('aggregate-error')
2
- const resolveConfig = require('./resolve-config')
3
- const getError = require('./get-error')
1
+ import AggregateError from "aggregate-error";
2
+ import resolveConfig from "./resolve-config.js";
3
+ import getError from "./get-error.js";
4
4
 
5
- module.exports = async (pluginConfig, context) => {
6
- const cfg = resolveConfig(context)
7
- const errors = []
5
+ export default async (pluginConfig, context) => {
6
+ const cfg = resolveConfig(context);
7
+ const errors = [];
8
+ if (cfg.ghtoken === false) {
9
+ errors.push(getError("ENOGHTOKEN"));
10
+ }
8
11
  if (cfg.login === false || cfg.password === false) {
9
- errors.push(getError('EWHMCSNOCREDENTIALS'))
12
+ errors.push(getError("EWHMCSNOCREDENTIALS"));
10
13
  }
11
14
  // TODO: we might test Marketplace login using given credentials
12
15
  if (cfg.productid === false) {
13
- errors.push(getError('EWHMCSNOPRODUCTID'))
16
+ errors.push(getError("EWHMCSNOPRODUCTID"));
14
17
  }
15
18
  if (!/^[0-9]+$/.test(cfg.productid) || !parseInt(cfg.productid, 10)) {
16
- errors.push(getError('EWHMCSINVALIDPRODUCTID'))
19
+ errors.push(getError("EWHMCSINVALIDPRODUCTID"));
17
20
  }
18
21
  if (errors.length > 0) {
19
- throw new AggregateError(errors)
22
+ throw new AggregateError(errors);
20
23
  }
21
- }
24
+ };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@hexonet/semantic-release-whmcs",
3
3
  "description": "`semantic-release` plugin for auto-publishing on WHMCS marketplace",
4
- "version": "4.0.3",
4
+ "version": "5.0.0",
5
5
  "private": false,
6
+ "type": "module",
6
7
  "publishConfig": {
7
8
  "access": "public"
8
9
  },
@@ -10,15 +11,14 @@
10
11
  "name": "Kai Schwarz",
11
12
  "email": "kschwarz@hexonet.net"
12
13
  },
13
- "main": "index.js",
14
14
  "license": "MIT",
15
15
  "engines": {
16
- "node": ">=16.15.1",
17
- "npm": ">=8.11.0"
16
+ "node": ">=18",
17
+ "npm": "8.11.0"
18
18
  },
19
- "homepage": "https://github.com/hexonet/semantic-release-whmcs#readme",
20
- "repository": "github:hexonet/semantic-release-whmcs",
21
- "bugs": "https://github.com/hexonet/semantic-release-whmcs/issues",
19
+ "homepage": "https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs#readme",
20
+ "repository": "github:centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs",
21
+ "bugs": "https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs/issues",
22
22
  "maintainers": [
23
23
  {
24
24
  "name": "Kai Schwarz",
@@ -34,9 +34,24 @@
34
34
  "semantic-release",
35
35
  "version"
36
36
  ],
37
- "nyc": {
37
+ "ava": {
38
+ "files": [
39
+ "test/**/*.test.js"
40
+ ],
41
+ "nodeArguments": [
42
+ "--no-warnings"
43
+ ],
44
+ "timeout": "2m"
45
+ },
46
+ "prettier": {
47
+ "printWidth": 120,
48
+ "trailingComma": "es5"
49
+ },
50
+ "c8": {
38
51
  "include": [
39
- "lib/**/*.js"
52
+ "lib/**/*.js",
53
+ "index.js",
54
+ "cli.js"
40
55
  ],
41
56
  "reporter": [
42
57
  "json",
@@ -45,39 +60,28 @@
45
60
  ],
46
61
  "all": true
47
62
  },
48
- "ava": {
49
- "require": [
50
- "esm"
51
- ]
52
- },
63
+ "main": "index.js",
53
64
  "scripts": {
54
- "coverage": "nyc npm run test",
55
- "test": "ava --fail-fast --verbose --timeout=2m",
56
- "lint": "eslint --fix --config=./.eslintrc.js *.js lib/*.js lib/definitions/*.js README.md *.json test/*.test.js"
65
+ "test": "c8 ava --verbose",
66
+ "lint": "prettier --check \"*.{js,json}\" \".github/**/*.{md,yml}\" \"{lib,test}/*.js\"",
67
+ "lint:fix": "prettier --write \"*.{js,json}\" \".github/**/*.{md,yml}\" \"{lib,test}/*.js\""
57
68
  },
58
69
  "devDependencies": {
59
70
  "@semantic-release/changelog": "^6.0.1",
60
71
  "@semantic-release/exec": "^6.0.2",
61
72
  "@semantic-release/git": "^10.0.1",
62
- "ava": "^4.0.0",
63
- "eslint": "^8.0.1",
64
- "eslint-config-standard": "^17.0.0",
65
- "eslint-plugin-import": "^2.25.2",
66
- "eslint-plugin-json": "^3.0.0",
67
- "eslint-plugin-markdown": "^3.0.0",
68
- "eslint-plugin-n": "^15.2.2",
69
- "eslint-plugin-promise": "^6.0.0",
70
- "esm": "^3.2.25",
71
- "nyc": "^15.1.0",
72
- "semantic-release": "^19.0.3",
73
+ "ava": "5.1.1",
74
+ "c8": "^7.12.0",
75
+ "prettier": "^2.8.3",
76
+ "semantic-release": "^20.0.2",
73
77
  "stream-buffers": "^3.0.2"
74
78
  },
75
79
  "dependencies": {
76
80
  "@semantic-release/error": "^3.0.0",
77
- "aggregate-error": "^3.1.0",
81
+ "aggregate-error": "^4.0.1",
78
82
  "debug": "^4.3.4",
79
83
  "github-api": "^3.4.0",
80
- "puppeteer": "^16.0.0",
81
- "yargs": "^17.0.1"
84
+ "puppeteer": "^19.4.1",
85
+ "yargs": "^17.5.1"
82
86
  }
83
87
  }
package/whmcs.js CHANGED
@@ -1,59 +1,87 @@
1
-
2
- const { publish, syncVersions, delVersion, updateCompatibility } = require('./index.js')
1
+ import { createRequire } from "node:module";
2
+ import { publish, syncVersions, delVersion, updateCompatibility } from "./index.js";
3
+ const require = createRequire(import.meta.url);
3
4
 
4
5
  const context = {
5
6
  env: process.env,
6
- logger: new class {
7
- log (msg) { console.log(msg) }
8
- info (msg) { console.log(msg) }
9
- error (msg, details) { console.error(msg + ' ' + details) }
10
- }()
11
- }
7
+ logger: new (class {
8
+ log(msg) {
9
+ console.log(msg);
10
+ }
11
+ info(msg) {
12
+ console.log(msg);
13
+ }
14
+ error(msg, details) {
15
+ console.error(msg + " " + details);
16
+ }
17
+ })(),
18
+ };
12
19
 
13
20
  // eslint-disable-next-line no-unused-expressions
14
- require('yargs')
15
- .scriptName('whmcs.js')
16
- .usage('$0 <cmd> [args]')
17
- .command('publish [ver] [notes]', 'publishes the specified version to the WHMCS Marketplace', (yargs) => {
18
- yargs.positional('ver', {
19
- type: 'string',
20
- demandOption: true,
21
- describe: 'the version to publish'
22
- }).positional('notes', {
23
- type: 'string',
24
- demandOption: true,
25
- describe: 'the changelog'
26
- })
27
- }, function (argv) {
28
- context.nextRelease = {
29
- version: argv.ver,
30
- notes: argv.notes
21
+ require("yargs")
22
+ .scriptName("whmcs.js")
23
+ .usage("$0 <cmd> [args]")
24
+ .command(
25
+ "publish [ver] [notes]",
26
+ "publishes the specified version to the WHMCS Marketplace",
27
+ (yargs) => {
28
+ yargs
29
+ .positional("ver", {
30
+ type: "string",
31
+ demandOption: true,
32
+ describe: "the version to publish",
33
+ })
34
+ .positional("notes", {
35
+ type: "string",
36
+ demandOption: true,
37
+ describe: "the changelog",
38
+ });
39
+ },
40
+ function (argv) {
41
+ context.nextRelease = {
42
+ version: argv.ver,
43
+ notes: argv.notes,
44
+ };
45
+ publish({}, context).then((r) => {
46
+ console.log(r === false ? "Failed" : "Successful");
47
+ });
48
+ }
49
+ )
50
+ .command(
51
+ "sync",
52
+ "adds missing versions to the WHMCS Marketplace",
53
+ () => {},
54
+ function () {
55
+ syncVersions({}, context).then((r) => {
56
+ console.log(r === false ? "Failed" : "Successful");
57
+ });
58
+ }
59
+ )
60
+ .command(
61
+ "del [ver]",
62
+ "deletes the specified version from the WHMCS Marketplace",
63
+ (yargs) => {
64
+ yargs.positional("ver", {
65
+ type: "string",
66
+ demandOption: true,
67
+ describe: "the version to delete",
68
+ });
69
+ },
70
+ function (argv) {
71
+ context.version = argv.ver;
72
+ delVersion({}, context).then((r) => {
73
+ console.log(r === false ? "Failed" : "Successful");
74
+ });
75
+ }
76
+ )
77
+ .command(
78
+ "compatibility",
79
+ "set the compatible WHMCS versions in the Marketplace",
80
+ () => {},
81
+ function () {
82
+ updateCompatibility({}, context).then((r) => {
83
+ console.log(r === false ? "Failed" : "Successful");
84
+ });
31
85
  }
32
- publish({}, context).then(r => {
33
- console.log(r === false ? 'Failed' : 'Successful')
34
- })
35
- })
36
- .command('sync', 'adds missing versions to the WHMCS Marketplace', () => {}, function () {
37
- syncVersions({}, context).then(r => {
38
- console.log(r === false ? 'Failed' : 'Successful')
39
- })
40
- })
41
- .command('del [ver]', 'deletes the specified version from the WHMCS Marketplace', (yargs) => {
42
- yargs.positional('ver', {
43
- type: 'string',
44
- demandOption: true,
45
- describe: 'the version to delete'
46
- })
47
- }, function (argv) {
48
- context.version = argv.ver
49
- delVersion({}, context).then(r => {
50
- console.log(r === false ? 'Failed' : 'Successful')
51
- })
52
- })
53
- .command('compatibility', 'set the compatible WHMCS versions in the Marketplace', () => {}, function () {
54
- updateCompatibility({}, context).then(r => {
55
- console.log(r === false ? 'Failed' : 'Successful')
56
- })
57
- })
58
- .help()
59
- .argv
86
+ )
87
+ .help().argv;
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- coverage
2
- node_modules
3
- .nyc_output
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- env: {
3
- node: true,
4
- },
5
- parserOptions: {
6
- ecmaVersion: 2020,
7
- },
8
- extends: [
9
- "standard",
10
- "plugin:json/recommended",
11
- "plugin:markdown/recommended",
12
- "plugin:n/recommended",
13
- ],
14
- };
@@ -1,79 +0,0 @@
1
- # This workflow handle Push
2
- name: Receive Push
3
- on:
4
- push:
5
- branches:
6
- - "**"
7
- tags-ignore:
8
- - "**"
9
- jobs:
10
- test:
11
- name: Test @ NodeJS - x86 - ubuntu-latest
12
- runs-on: ubuntu-latest
13
- if: github.actor != 'dependabot[bot]' # ignore pushed brnaches by dependabot
14
- strategy:
15
- matrix:
16
- node-version: [lts/*]
17
- steps:
18
- - name: Checkout
19
- uses: actions/checkout@v3
20
- - name: Setup NodeJS ${{ matrix.node-version }}
21
- uses: actions/setup-node@v3
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
- check-latest: true
25
- - name: Install dependencies
26
- run: npm ci
27
- - name: Linting
28
- run: npm run lint
29
- - name: Tests
30
- env:
31
- GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
32
- GITHUB_REPO: ${{ secrets.GH_REPO }}
33
- WHMCSMP_LOGIN: ${{ secrets.WHMCSMP_LOGIN }}
34
- WHMCSMP_PASSWORD: ${{ secrets.WHMCSMP_PASSWORD }}
35
- WHMCSMP_PRODUCTID: ${{ secrets.WHMCSMP_PRODUCTID }}
36
- WHMCSMP_MINVERSION: ${{ secrets.WHMCSMP_MINVERSION }}
37
- DEBUG: ${{ secrets.DEBUG }}
38
- run: npm run coverage
39
- - name: Upload coverage folder
40
- uses: actions/upload-artifact@v3
41
- with:
42
- name: coverage-folder
43
- path: coverage
44
- - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v2
46
- with:
47
- languages: javascript
48
- - name: Perform CodeQL Analysis
49
- uses: github/codeql-action/analyze@v2
50
-
51
- release:
52
- name: Release @ NodeJS LTS - x86 - ubuntu-latest
53
- needs: test
54
- if: github.ref == 'refs/heads/master' # release when pushing on master branch only
55
- runs-on: ubuntu-latest
56
- steps:
57
- - name: Checkout
58
- uses: actions/checkout@v3
59
- with:
60
- fetch-depth: 0
61
- persist-credentials: false
62
- - name: Setup NodeJS LTS
63
- uses: actions/setup-node@v3
64
- with:
65
- node-version: lts/*
66
- check-latest: true
67
- - name: Install dependencies
68
- run: npm ci
69
- - name: Download coverage folder from Push workflow
70
- uses: actions/download-artifact@v3
71
- with:
72
- name: coverage-folder
73
- path: coverage
74
- - name: Release
75
- env:
76
- GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
77
- GITHUB_REPO: ${{ secrets.GH_REPO }}
78
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
79
- run: npx semantic-release
package/coverage/base.css DELETED
@@ -1,224 +0,0 @@
1
- body, html {
2
- margin:0; padding: 0;
3
- height: 100%;
4
- }
5
- body {
6
- font-family: Helvetica Neue, Helvetica, Arial;
7
- font-size: 14px;
8
- color:#333;
9
- }
10
- .small { font-size: 12px; }
11
- *, *:after, *:before {
12
- -webkit-box-sizing:border-box;
13
- -moz-box-sizing:border-box;
14
- box-sizing:border-box;
15
- }
16
- h1 { font-size: 20px; margin: 0;}
17
- h2 { font-size: 14px; }
18
- pre {
19
- font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
20
- margin: 0;
21
- padding: 0;
22
- -moz-tab-size: 2;
23
- -o-tab-size: 2;
24
- tab-size: 2;
25
- }
26
- a { color:#0074D9; text-decoration:none; }
27
- a:hover { text-decoration:underline; }
28
- .strong { font-weight: bold; }
29
- .space-top1 { padding: 10px 0 0 0; }
30
- .pad2y { padding: 20px 0; }
31
- .pad1y { padding: 10px 0; }
32
- .pad2x { padding: 0 20px; }
33
- .pad2 { padding: 20px; }
34
- .pad1 { padding: 10px; }
35
- .space-left2 { padding-left:55px; }
36
- .space-right2 { padding-right:20px; }
37
- .center { text-align:center; }
38
- .clearfix { display:block; }
39
- .clearfix:after {
40
- content:'';
41
- display:block;
42
- height:0;
43
- clear:both;
44
- visibility:hidden;
45
- }
46
- .fl { float: left; }
47
- @media only screen and (max-width:640px) {
48
- .col3 { width:100%; max-width:100%; }
49
- .hide-mobile { display:none!important; }
50
- }
51
-
52
- .quiet {
53
- color: #7f7f7f;
54
- color: rgba(0,0,0,0.5);
55
- }
56
- .quiet a { opacity: 0.7; }
57
-
58
- .fraction {
59
- font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
60
- font-size: 10px;
61
- color: #555;
62
- background: #E8E8E8;
63
- padding: 4px 5px;
64
- border-radius: 3px;
65
- vertical-align: middle;
66
- }
67
-
68
- div.path a:link, div.path a:visited { color: #333; }
69
- table.coverage {
70
- border-collapse: collapse;
71
- margin: 10px 0 0 0;
72
- padding: 0;
73
- }
74
-
75
- table.coverage td {
76
- margin: 0;
77
- padding: 0;
78
- vertical-align: top;
79
- }
80
- table.coverage td.line-count {
81
- text-align: right;
82
- padding: 0 5px 0 20px;
83
- }
84
- table.coverage td.line-coverage {
85
- text-align: right;
86
- padding-right: 10px;
87
- min-width:20px;
88
- }
89
-
90
- table.coverage td span.cline-any {
91
- display: inline-block;
92
- padding: 0 5px;
93
- width: 100%;
94
- }
95
- .missing-if-branch {
96
- display: inline-block;
97
- margin-right: 5px;
98
- border-radius: 3px;
99
- position: relative;
100
- padding: 0 4px;
101
- background: #333;
102
- color: yellow;
103
- }
104
-
105
- .skip-if-branch {
106
- display: none;
107
- margin-right: 10px;
108
- position: relative;
109
- padding: 0 4px;
110
- background: #ccc;
111
- color: white;
112
- }
113
- .missing-if-branch .typ, .skip-if-branch .typ {
114
- color: inherit !important;
115
- }
116
- .coverage-summary {
117
- border-collapse: collapse;
118
- width: 100%;
119
- }
120
- .coverage-summary tr { border-bottom: 1px solid #bbb; }
121
- .keyline-all { border: 1px solid #ddd; }
122
- .coverage-summary td, .coverage-summary th { padding: 10px; }
123
- .coverage-summary tbody { border: 1px solid #bbb; }
124
- .coverage-summary td { border-right: 1px solid #bbb; }
125
- .coverage-summary td:last-child { border-right: none; }
126
- .coverage-summary th {
127
- text-align: left;
128
- font-weight: normal;
129
- white-space: nowrap;
130
- }
131
- .coverage-summary th.file { border-right: none !important; }
132
- .coverage-summary th.pct { }
133
- .coverage-summary th.pic,
134
- .coverage-summary th.abs,
135
- .coverage-summary td.pct,
136
- .coverage-summary td.abs { text-align: right; }
137
- .coverage-summary td.file { white-space: nowrap; }
138
- .coverage-summary td.pic { min-width: 120px !important; }
139
- .coverage-summary tfoot td { }
140
-
141
- .coverage-summary .sorter {
142
- height: 10px;
143
- width: 7px;
144
- display: inline-block;
145
- margin-left: 0.5em;
146
- background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
147
- }
148
- .coverage-summary .sorted .sorter {
149
- background-position: 0 -20px;
150
- }
151
- .coverage-summary .sorted-desc .sorter {
152
- background-position: 0 -10px;
153
- }
154
- .status-line { height: 10px; }
155
- /* yellow */
156
- .cbranch-no { background: yellow !important; color: #111; }
157
- /* dark red */
158
- .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
159
- .low .chart { border:1px solid #C21F39 }
160
- .highlighted,
161
- .highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
162
- background: #C21F39 !important;
163
- }
164
- /* medium red */
165
- .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
166
- /* light red */
167
- .low, .cline-no { background:#FCE1E5 }
168
- /* light green */
169
- .high, .cline-yes { background:rgb(230,245,208) }
170
- /* medium green */
171
- .cstat-yes { background:rgb(161,215,106) }
172
- /* dark green */
173
- .status-line.high, .high .cover-fill { background:rgb(77,146,33) }
174
- .high .chart { border:1px solid rgb(77,146,33) }
175
- /* dark yellow (gold) */
176
- .status-line.medium, .medium .cover-fill { background: #f9cd0b; }
177
- .medium .chart { border:1px solid #f9cd0b; }
178
- /* light yellow */
179
- .medium { background: #fff4c2; }
180
-
181
- .cstat-skip { background: #ddd; color: #111; }
182
- .fstat-skip { background: #ddd; color: #111 !important; }
183
- .cbranch-skip { background: #ddd !important; color: #111; }
184
-
185
- span.cline-neutral { background: #eaeaea; }
186
-
187
- .coverage-summary td.empty {
188
- opacity: .5;
189
- padding-top: 4px;
190
- padding-bottom: 4px;
191
- line-height: 1;
192
- color: #888;
193
- }
194
-
195
- .cover-fill, .cover-empty {
196
- display:inline-block;
197
- height: 12px;
198
- }
199
- .chart {
200
- line-height: 0;
201
- }
202
- .cover-empty {
203
- background: white;
204
- }
205
- .cover-full {
206
- border-right: none !important;
207
- }
208
- pre.prettyprint {
209
- border: none !important;
210
- padding: 0 !important;
211
- margin: 0 !important;
212
- }
213
- .com { color: #999 !important; }
214
- .ignore-none { color: #999; font-weight: normal; }
215
-
216
- .wrapper {
217
- min-height: 100%;
218
- height: auto !important;
219
- height: 100%;
220
- margin: 0 auto -48px;
221
- }
222
- .footer, .push {
223
- height: 48px;
224
- }
@@ -1,87 +0,0 @@
1
- /* eslint-disable */
2
- var jumpToCode = (function init() {
3
- // Classes of code we would like to highlight in the file view
4
- var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
5
-
6
- // Elements to highlight in the file listing view
7
- var fileListingElements = ['td.pct.low'];
8
-
9
- // We don't want to select elements that are direct descendants of another match
10
- var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
11
-
12
- // Selecter that finds elements on the page to which we can jump
13
- var selector =
14
- fileListingElements.join(', ') +
15
- ', ' +
16
- notSelector +
17
- missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
18
-
19
- // The NodeList of matching elements
20
- var missingCoverageElements = document.querySelectorAll(selector);
21
-
22
- var currentIndex;
23
-
24
- function toggleClass(index) {
25
- missingCoverageElements
26
- .item(currentIndex)
27
- .classList.remove('highlighted');
28
- missingCoverageElements.item(index).classList.add('highlighted');
29
- }
30
-
31
- function makeCurrent(index) {
32
- toggleClass(index);
33
- currentIndex = index;
34
- missingCoverageElements.item(index).scrollIntoView({
35
- behavior: 'smooth',
36
- block: 'center',
37
- inline: 'center'
38
- });
39
- }
40
-
41
- function goToPrevious() {
42
- var nextIndex = 0;
43
- if (typeof currentIndex !== 'number' || currentIndex === 0) {
44
- nextIndex = missingCoverageElements.length - 1;
45
- } else if (missingCoverageElements.length > 1) {
46
- nextIndex = currentIndex - 1;
47
- }
48
-
49
- makeCurrent(nextIndex);
50
- }
51
-
52
- function goToNext() {
53
- var nextIndex = 0;
54
-
55
- if (
56
- typeof currentIndex === 'number' &&
57
- currentIndex < missingCoverageElements.length - 1
58
- ) {
59
- nextIndex = currentIndex + 1;
60
- }
61
-
62
- makeCurrent(nextIndex);
63
- }
64
-
65
- return function jump(event) {
66
- if (
67
- document.getElementById('fileSearch') === document.activeElement &&
68
- document.activeElement != null
69
- ) {
70
- // if we're currently focused on the search input, we don't want to navigate
71
- return;
72
- }
73
-
74
- switch (event.which) {
75
- case 78: // n
76
- case 74: // j
77
- goToNext();
78
- break;
79
- case 66: // b
80
- case 75: // k
81
- case 80: // p
82
- goToPrevious();
83
- break;
84
- }
85
- };
86
- })();
87
- window.addEventListener('keydown', jumpToCode);