2014-02-21 23:35:05 +04:00
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
2014-02-15 05:54:00 +04:00
|
|
|
|
|
|
|
module.exports = (grunt) ->
|
2014-02-21 23:35:05 +04:00
|
|
|
grunt.registerTask 'generate-license', 'Generate the license, including the licenses of all dependencies', (mode) ->
|
2014-02-15 05:54:00 +04:00
|
|
|
legalEagle = require 'legal-eagle'
|
|
|
|
done = @async()
|
|
|
|
|
|
|
|
options =
|
|
|
|
path: process.cwd()
|
|
|
|
overrides: require './license-overrides'
|
|
|
|
|
2014-02-21 23:35:05 +04:00
|
|
|
legalEagle options, (err, dependencyLicenses) ->
|
2014-02-15 05:54:00 +04:00
|
|
|
if err?
|
|
|
|
console.error(err)
|
|
|
|
exit 1
|
2014-02-21 23:35:05 +04:00
|
|
|
|
|
|
|
licenseText = getLicenseText(dependencyLicenses)
|
|
|
|
if mode is 'save'
|
2014-05-06 02:55:34 +04:00
|
|
|
targetPath = path.join(grunt.config.get('atom.appDir'), 'LICENSE.md')
|
2014-02-21 23:35:05 +04:00
|
|
|
fs.writeFileSync(targetPath, licenseText)
|
|
|
|
else
|
|
|
|
console.log licenseText
|
2014-02-15 05:54:00 +04:00
|
|
|
done()
|
|
|
|
|
2014-02-21 23:35:05 +04:00
|
|
|
getLicenseText = (dependencyLicenses) ->
|
2014-02-15 05:54:00 +04:00
|
|
|
{keys} = require 'underscore-plus'
|
2014-02-21 23:35:05 +04:00
|
|
|
text = """
|
2014-05-06 17:38:28 +04:00
|
|
|
#{fs.readFileSync('LICENSE.md', 'utf8')}
|
2014-02-21 23:35:05 +04:00
|
|
|
|
|
|
|
This application bundles the following third-party packages in accordance
|
|
|
|
with the following licenses:\n\n
|
|
|
|
"""
|
|
|
|
names = keys(dependencyLicenses).sort()
|
2014-02-15 05:54:00 +04:00
|
|
|
for name in names
|
2014-02-21 23:35:05 +04:00
|
|
|
{license, source, sourceText} = dependencyLicenses[name]
|
2014-02-21 22:53:32 +04:00
|
|
|
|
|
|
|
text += "-------------------------------------------------------------------------\n\n"
|
|
|
|
text += "Package: #{name}\n"
|
|
|
|
text += "License: #{license}\n"
|
|
|
|
text += "License Source: #{source}\n" if source?
|
2014-02-15 05:54:00 +04:00
|
|
|
if sourceText?
|
2014-02-21 22:53:32 +04:00
|
|
|
text += "Source Text:\n\n"
|
|
|
|
text += sourceText
|
2014-02-15 05:54:00 +04:00
|
|
|
text += '\n'
|
|
|
|
text
|