adapt-authoring-core 2.2.1 → 2.2.2

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.
@@ -40,6 +40,10 @@ export default class Licensing {
40
40
 
41
41
  async storeLicenseData (pkg) {
42
42
  if (!pkg.license) {
43
+ const l = 'Undefined'
44
+ if (!this.licenses[l]) this.licenses[l] = { count: 0, packages: [] }
45
+ this.licenses[l].count++
46
+ this.licenses[l].packages.push(pkg.name)
43
47
  return
44
48
  }
45
49
  if (typeof pkg.license === 'object') {
@@ -49,14 +53,17 @@ export default class Licensing {
49
53
  for (let l of licenses) {
50
54
  l = this.licenseNameMap(l)
51
55
  if (this.licenses[l]) {
52
- return this.licenses[l].count++
56
+ this.licenses[l].count++
57
+ this.licenses[l].packages.push(pkg.name)
58
+ return
53
59
  }
54
- this.licenses[l] = { count: 1 }
60
+ this.licenses[l] = { count: 1, packages: [pkg.name] }
55
61
  try {
56
62
  const { GITHUB_USER, GITHUB_TOKEN } = process.env
57
63
  const res = await fetch(`https://api.github.com/licenses/${l.toLowerCase()}`, { headers: { Authorization: `Basic ${Buffer.from(`${GITHUB_USER}:${GITHUB_TOKEN}`).toString('base64')}` } })
58
- if (res.status === 200) Object.assign(this.licenses[l], await res.json())
59
- if (res.status > 299) console.error(`Failed to fetch '${l}' license: (${res.status}) ${(await res.json()).message}`)
64
+ const body = await res.json()
65
+ if (res.ok) Object.assign(this.licenses[l], body)
66
+ else console.log(`Could not fetch '${l}' license from GitHub API (${res.status}), will list as unknown`)
60
67
  } catch (e) {
61
68
  console.error(e)
62
69
  }
@@ -92,10 +99,10 @@ export default class Licensing {
92
99
 
93
100
  async generateLicenseDetailsMd () {
94
101
  let md = ''
95
- Object.entries(this.licenses).forEach(([key, { name, spdxId, description, body, permissions }]) => {
102
+ Object.entries(this.licenses).forEach(([key, { name, spdx_id: spdxId, description, body, permissions }]) => {
96
103
  if (!name) return
97
104
  md += '<details>\n'
98
- md += `<summary>${name} (${spdxId})</summary>\n`
105
+ md += `<summary>${name}${spdxId ? ` (${spdxId})` : ''}</summary>\n`
99
106
  md += `<p>${description}</p>\n`
100
107
  md += `<p>This license allows the following:\n<ul>${permissions.map(p => `<li>${this.permissionsMap(p)}</li>`).join('\n')}</ul></p>\n`
101
108
  md += '<p>The original license text is as follows:</p>\n'
@@ -106,11 +113,13 @@ export default class Licensing {
106
113
  }
107
114
 
108
115
  generateUnknownLicenseMd () {
109
- const unknowns = []
110
- Object.entries(this.licenses).forEach(([key, { name }]) => !name && unknowns.push(key))
111
- if (unknowns.length) {
112
- return `No information is held on the following licenses, please do your own research to dermine their suitability.\n\n${unknowns.map(u => `- ${u}`).join('\n')}\n`
113
- }
116
+ const unknowns = Object.entries(this.licenses).filter(([, { name }]) => !name)
117
+ if (!unknowns.length) return ''
118
+ let md = 'No information is held on the following licenses, please do your own research to determine their suitability.\n\n'
119
+ unknowns.forEach(([key, { packages }]) => {
120
+ md += `- **${key}**: ${packages.join(', ')}\n`
121
+ })
122
+ return md
114
123
  }
115
124
 
116
125
  async generateMd () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-core",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "A bundle of reusable 'core' functionality",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-core",
6
6
  "license": "GPL-3.0",