@hexonet/semantic-release-whmcs 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,79 +1,45 @@
1
1
  const debug = require('debug')('semantic-release:whmcs')
2
- const resolveConfig = require('./resolve-config')
3
2
  const puppet = require('./puppet')
3
+ const path = require('path')
4
4
 
5
5
  /**
6
6
  * A method to publish the module update on whmcs market place
7
7
  */
8
8
  module.exports = async (pluginConfig, context) => {
9
- const {
10
- logger
11
- } = context
9
+ const sep = '+++++++++++++++++++++++++++++++++++++++++++++++++++'
10
+ const out = `\n${sep}\n${path.basename(__filename)}\n${sep}\n`
12
11
 
13
- let success = true
14
- const { whmcsLOGIN, whmcsPASSWORD, whmcsPRODUCTID, withHEAD, DEBUG } = resolveConfig(context)
15
- const { gotoOpts, navOpts, selectorOpts, page } = await puppet(DEBUG, withHEAD, logger)
16
-
17
- debug(`WHMCS Marketplace Product ID: ${whmcsPRODUCTID}`)
18
- logger.log(`WHMCS Marketplace Product ID: ${whmcsPRODUCTID}`)
19
-
20
- const wmbase = 'https://marketplace.whmcs.com'
21
- let url = `${wmbase}/user/login`
12
+ const püppi = await puppet(context)
13
+ const result = await püppi.login()
14
+ if (!result) {
15
+ return result
16
+ }
17
+ const { page, gotoOpts, selectorOpts, productid, urlbase } = püppi.config
22
18
 
19
+ let marketplaceVersions = []
23
20
  try {
21
+ // scrap versions from WHMCS marketplace
22
+ const url = `${urlbase}/product/${productid}/edit#versions`
24
23
  await page.goto(url, gotoOpts)
25
- // do login
26
- const selector = 'div.login-leftcol form button[type="submit"]'
24
+ debug(`${out}product page loaded at %s`, url)
25
+ const selector = 'div#versions tr strong'
27
26
  await page.waitForSelector(selector, selectorOpts)
28
- debug('login form loaded at %s', url)
29
- await page.type('#email', whmcsLOGIN)
30
- await page.type('#password', whmcsPASSWORD)
31
- debug('WHMCS Marketplace credentials entered')
32
- const nav = page.waitForNavigation(navOpts)
33
- await page.hover(selector)
34
- await page.click(selector)
35
- await nav
36
- debug('Login form successfully submitted.')
37
- logger.log('WHMCS Marketplace Login Form successfully submitted.')
38
- } catch (error) {
39
- debug('WHMCS Marketplace login failed.', error.message)
40
- logger.error('WHMCS Marketplace login failed.', error.message)
41
- success = false
42
- }
43
- let marketplaceVersions = false
44
- if (success) {
45
- try {
46
- if (!parseInt(whmcsPRODUCTID, 10)) {
47
- return false
48
- }
49
-
50
- // scrap versions from WHMCS marketplace
51
- url = `${wmbase}/product/${whmcsPRODUCTID}/edit#versions`
52
- await page.goto(url, gotoOpts)
53
- debug('product page loaded at %s', url)
54
- const selector = 'div#versions tr strong'
55
- await page.waitForSelector(selector, selectorOpts)
56
- debug('product version table found')
57
- /* istanbul ignore next */
58
- marketplaceVersions = await page.$$eval('div#versions tr td strong', tds => tds.map((td) => {
27
+ debug('product version table found')
28
+ /* istanbul ignore next */
29
+ marketplaceVersions = await page.$$eval(selector, (tds) =>
30
+ tds.map((td) => {
59
31
  return td.innerText.substring(8)
60
- }))
61
- marketplaceVersions.reverse()
62
- marketplaceVersions.forEach(v => logger.log(`Detected WHMCS version ${v}`))
63
-
64
- debug('publishing new product version succeeded.')
65
- logger.log('WHMCS Marketplace publishing new product version succeeded.')
66
- success = true
67
- } catch (error) {
68
- debug('publishing new product version failed.', error.message)
69
- logger.error('WHMCS Marketplace publishing new product version failed.', error.message)
70
- success = false
71
- }
32
+ })
33
+ )
34
+ marketplaceVersions.reverse()
35
+ marketplaceVersions.forEach((v) => debug(`Detected WHMCS version ${v}`))
36
+ } catch (error) {
37
+ debug('Publishing new product version failed.', error.message)
38
+ await page.browser().close()
39
+ return false
72
40
  }
73
41
 
42
+ debug('Publishing new product version succeeded.')
74
43
  await page.browser().close()
75
- if (!success) {
76
- return false
77
- }
78
44
  return marketplaceVersions
79
45
  }
@@ -1,97 +1,71 @@
1
1
  const debug = require('debug')('semantic-release:whmcs')
2
- const resolveConfig = require('./resolve-config')
3
2
  const puppet = require('./puppet')
3
+ const path = require('path')
4
4
 
5
5
  /**
6
6
  * A method to publish the module update on whmcs market place
7
7
  */
8
8
  module.exports = async (pluginConfig, context) => {
9
- const {
10
- logger
11
- } = context
9
+ const sep = '+++++++++++++++++++++++++++++++++++++++++++++++++++'
10
+ const out = `\n${sep}\n${path.basename(__filename)}\n${sep}\n`
12
11
 
13
- let success = true
14
- const { whmcsLOGIN, whmcsPASSWORD, whmcsPRODUCTID, whmcsMINVERSION, withHEAD, DEBUG } = resolveConfig(context)
15
- const { gotoOpts, navOpts, selectorOpts, page } = await puppet(withHEAD, DEBUG, logger)
16
-
17
- debug(`WHMCS Marketplace Product ID: ${whmcsPRODUCTID}`)
18
- logger.log(`WHMCS Marketplace Product ID: ${whmcsPRODUCTID}`)
19
-
20
- const wmbase = 'https://marketplace.whmcs.com'
21
- let url = `${wmbase}/user/login`
12
+ const püppi = await puppet(context)
13
+ const result = await püppi.login()
14
+ if (!result) {
15
+ return result
16
+ }
17
+ const { page, gotoOpts, selectorOpts, productid, urlbase, minversion } =
18
+ püppi.config
22
19
 
20
+ debug(out)
23
21
  try {
22
+ // scrap versions from WHMCS marketplace
23
+ const url = `${urlbase}/product/${productid}/edit#compatibility`
24
24
  await page.goto(url, gotoOpts)
25
- // do login
26
- const selector = 'div.login-leftcol form button[type="submit"]'
27
- await page.waitForSelector(selector, selectorOpts)
28
- debug('login form loaded at %s', url)
29
- await page.type('#email', whmcsLOGIN)
30
- await page.type('#password', whmcsPASSWORD)
31
- debug('WHMCS Marketplace credentials entered')
32
- const nav = page.waitForNavigation(navOpts)
33
- await page.hover(selector)
34
- await page.click(selector)
35
- await nav
36
- debug('Login form successfully submitted.')
37
- logger.log('WHMCS Marketplace Login Form successfully submitted.')
38
- } catch (error) {
39
- debug('WHMCS Marketplace login failed.', error.message)
40
- logger.error('WHMCS Marketplace login failed.', error.message)
41
- success = false
42
- }
43
-
44
- if (success) {
45
- try {
46
- if (!parseInt(whmcsPRODUCTID, 10)) {
47
- return false
48
- }
25
+ debug('product page loaded at %s', url)
49
26
 
50
- // scrap versions from WHMCS marketplace
51
- url = `${wmbase}/product/${whmcsPRODUCTID}/edit#compatibility`
52
- await page.goto(url, gotoOpts)
53
- debug('product page loaded at %s', url)
54
-
55
- const selector = 'input[name="versionIds[]"]'
56
- const submitSelector = 'div#compatibility button[type="submit"]'
57
- await page.waitForSelector(selector, selectorOpts)
58
- await page.waitForSelector(submitSelector, selectorOpts)
59
- debug('compatibility version table found')
60
-
61
- logger.log(`Minimum required WHMCS version: ${whmcsMINVERSION}`)
62
- /* istanbul ignore next */
63
- await page.$$eval(selector, (checkboxes, whmcsMINVERSION) => checkboxes.forEach(function (c, i) {
64
- const checkParts = c.className.split('-')[0].split('_')
65
- const minParts = whmcsMINVERSION.split('.')
66
- let check = true
67
- for (let i = 0; i < 2; i++) {
68
- const a = ~~checkParts[i]
69
- const b = ~~minParts[i]
70
- if (a > b) {
71
- break
72
- }
73
- if (a < b) {
74
- check = false
75
- break
76
- }
77
- }
78
- c.checked = check
79
- }), whmcsMINVERSION)
80
- const submitNav = page.waitForNavigation(navOpts)
81
- await page.hover(submitSelector)
82
- await page.click(submitSelector)
83
- await submitNav
27
+ const selector = 'input[name="versionIds[]"]'
28
+ const submitSelector = 'div#compatibility button[type="submit"]'
29
+ await page.waitForSelector(selector, selectorOpts)
30
+ await page.waitForSelector(submitSelector, selectorOpts)
31
+ debug('compatibility version table found')
84
32
 
85
- debug('updating whmcs compatibility list succeeded.')
86
- logger.log('WHMCS Marketplace updating whmcs compatibility list succeeded.')
87
- success = true
88
- } catch (error) {
89
- debug('updating whmcs compatibility list failed.', error.message)
90
- logger.error('WHMCS Marketplace updating whmcs compatibility list failed.', error.message)
91
- success = false
33
+ let tmp = minversion
34
+ if (tmp) {
35
+ tmp = tmp.replace(/(.)/g, '$&\u200E')
92
36
  }
37
+ debug(`Minimum required WHMCS version: ${tmp}`)
38
+ /* istanbul ignore next */
39
+ await page.$$eval(
40
+ selector,
41
+ (checkboxes, minversion) =>
42
+ checkboxes.forEach(function (c) {
43
+ const checkParts = c.className.split('-')[0].split('_')
44
+ const minParts = minversion.split('.')
45
+ let check = true
46
+ for (let i = 0; i < 2; i++) {
47
+ const a = ~~checkParts[i]
48
+ const b = ~~minParts[i]
49
+ if (a > b) {
50
+ break
51
+ }
52
+ if (a < b) {
53
+ check = false
54
+ break
55
+ }
56
+ }
57
+ c.checked = check
58
+ }),
59
+ minversion
60
+ )
61
+ await page.clickAndNavigate(submitSelector)
62
+ } catch (error) {
63
+ debug('Updating whmcs compatibility list failed.', error.message)
64
+ await page.browser().close()
65
+ return false
93
66
  }
94
67
 
68
+ debug('Updating whmcs compatibility list succeeded.')
95
69
  await page.browser().close()
96
- return success
70
+ return true
97
71
  }
package/lib/verify.js CHANGED
@@ -5,13 +5,14 @@ const getError = require('./get-error')
5
5
  module.exports = async (pluginConfig, context) => {
6
6
  const cfg = resolveConfig(context)
7
7
  const errors = []
8
- if (cfg.whmcsLOGIN === false || cfg.whmcsPASSWORD === false) {
8
+ if (cfg.login === false || cfg.password === false) {
9
9
  errors.push(getError('EWHMCSNOCREDENTIALS'))
10
10
  }
11
- if (cfg.whmcsPRODUCTID === false) {
11
+ // TODO: we might test Marketplace login using given credentials
12
+ if (cfg.productid === false) {
12
13
  errors.push(getError('EWHMCSNOPRODUCTID'))
13
14
  }
14
- if (!/^[0-9]+$/.test(cfg.whmcsPRODUCTID)) {
15
+ if (!/^[0-9]+$/.test(cfg.productid) || !parseInt(cfg.productid, 10)) {
15
16
  errors.push(getError('EWHMCSINVALIDPRODUCTID'))
16
17
  }
17
18
  if (errors.length > 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.2",
4
+ "version": "4.0.3",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  "license": "MIT",
15
15
  "engines": {
16
16
  "node": ">=16.15.1",
17
- "npm": ">=8.11.1"
17
+ "npm": ">=8.11.0"
18
18
  },
19
19
  "homepage": "https://github.com/hexonet/semantic-release-whmcs#readme",
20
20
  "repository": "github:hexonet/semantic-release-whmcs",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "scripts": {
54
54
  "coverage": "nyc npm run test",
55
- "test": "ava --verbose --timeout=2m",
55
+ "test": "ava --fail-fast --verbose --timeout=2m",
56
56
  "lint": "eslint --fix --config=./.eslintrc.js *.js lib/*.js lib/definitions/*.js README.md *.json test/*.test.js"
57
57
  },
58
58
  "devDependencies": {
@@ -64,7 +64,7 @@
64
64
  "eslint-config-standard": "^17.0.0",
65
65
  "eslint-plugin-import": "^2.25.2",
66
66
  "eslint-plugin-json": "^3.0.0",
67
- "eslint-plugin-markdown": "^2.1.0",
67
+ "eslint-plugin-markdown": "^3.0.0",
68
68
  "eslint-plugin-n": "^15.2.2",
69
69
  "eslint-plugin-promise": "^6.0.0",
70
70
  "esm": "^3.2.25",
@@ -77,7 +77,7 @@
77
77
  "aggregate-error": "^3.1.0",
78
78
  "debug": "^4.3.4",
79
79
  "github-api": "^3.4.0",
80
- "puppeteer": "^15.1.1",
80
+ "puppeteer": "^16.0.0",
81
81
  "yargs": "^17.0.1"
82
82
  }
83
83
  }