forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateThirdPartyLicense.js
More file actions
76 lines (60 loc) · 1.91 KB
/
generateThirdPartyLicense.js
File metadata and controls
76 lines (60 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict'
const path = require('path')
const fs = require('fs')
const thirdPartyChecker = require('../.electron-vue/thirdPartyChecker.js')
const rootDir = path.resolve(__dirname, '..')
const additionalPackages = {
hunspell: {
packageName: 'Hunspell',
licenses: 'LGPL 2.1',
licenseText: fs.readFileSync(path.join(rootDir, 'resources/hunspell_dictionaries/LICENSE-hunspell.txt'))
}
}
thirdPartyChecker.getLicenses(rootDir, (err, packages, checker) => {
if (err) {
console.log(`[ERROR] ${err}`)
return
}
Object.assign(packages, additionalPackages)
let summary = ''
let licenseList = ''
let index = 1
const addedKeys = {}
Object.keys(packages).forEach(key => {
if (/^babel-helper-vue-jsx-merge-props/.test(key) ||
/^marktext/.test(key)) {
// babel-helper-vue-jsx-merge-props: MIT licensed used by element-ui
return
}
let packageName = key
const nameRegex = /(^.+)(?:@)/.exec(key)
if (nameRegex && nameRegex[1]) {
packageName = nameRegex[1]
}
// Check if we already added this package
if (addedKeys.hasOwnProperty(packageName)) {
return
}
addedKeys[packageName] = 1
const { licenses, licenseText } = packages[key]
summary += `${index++}. ${packageName} (${licenses})\n`
licenseList += `# ${packageName} (${licenses})
-------------------------------------------------\
${licenseText}
\n\n
`
})
const output = `# Third Party Notices
-------------------------------------------------
This file contains all third-party packages that are bundled and shipped with MarkText.
-------------------------------------------------
# Summary
-------------------------------------------------
${summary}
-------------------------------------------------
# Licenses
-------------------------------------------------
${licenseList}
`
fs.writeFileSync(path.resolve(rootDir, 'resources', 'THIRD-PARTY-LICENSES.txt'), output)
})