marktext/tools/generateThirdPartyLicense.js
Felix Häusler 603ed04ab1 Add experimental spellchecker (#1424)
* Experimental spellchecker for testing purpose

* Fix 'apache' license validation

* Use local electron-spellchecker for development

* Add settings and bug fixes

* Fix Hunspell switchLanguage bug and improvements

* Fix attach to editor when enabling spell check again

* Add Hunspell license

* Copy default Huspell dictionary on first start

* Fix full language name

* Some code improvements

* Allow to add words to user dict and  bug fixes

* Allow to change Muya's spellcheck container attribute

* feat: Don't underline misspelled words

* Allow to set Hunspell on macOS

* Fix spellchecker changed value

* Refactor switchLanguage, init and enableSpellchecker

* Refactor and some fixes

* Code improvements

* electron-spellchecker cleanup and optimization

* Disable automatic language detection for Hunspell

* Fix init on macOS and update JSDoc

* Fix macOS issues and some improvements

* Load single settings value only

* Fix rebase

* Remove debug code

* Move electron-spellchecker to scoped npm repo

* Fix dictionary of ignored words on macOS

* Move replaceWordInline to core API

* Remove comment block

* Fix upstream lint error
2019-10-17 15:54:09 +08:00

77 lines
1.9 KiB
JavaScript

'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 Mark Text.
-------------------------------------------------
# Summary
-------------------------------------------------
${summary}
-------------------------------------------------
# Licenses
-------------------------------------------------
${licenseList}
`
fs.writeFileSync(path.resolve(rootDir, 'resources', 'THIRD-PARTY-LICENSES.txt'), output)
})