mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Add LICENSE.md when packaging the app
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
'use strict'
|
||||
|
||||
require('coffee-script/register')
|
||||
require('babel-core/register')
|
||||
|
||||
const cleanOutputDirectory = require('./lib/clean-output-directory')
|
||||
const copyAssets = require('./lib/copy-assets')
|
||||
|
||||
@@ -4,6 +4,7 @@ const path = require('path')
|
||||
const CSON = require('season')
|
||||
const fs = require('fs-extra')
|
||||
const normalizePackageData = require('normalize-package-data')
|
||||
const deprecatedPackagesMetadata = require('./deprecated-packages')
|
||||
const semver = require('semver')
|
||||
|
||||
const CONFIG = require('../config')
|
||||
@@ -121,7 +122,6 @@ function buildPlatformKeymapsMetadata () {
|
||||
}
|
||||
|
||||
function buildDeprecatedPackagesMetadata () {
|
||||
const deprecatedPackagesMetadata = require('../deprecated-packages')
|
||||
for (let packageName of Object.keys(deprecatedPackagesMetadata)) {
|
||||
const packageMetadata = deprecatedPackagesMetadata[packageName]
|
||||
if (packageMetadata.version && !semver.validRange(packageMetadata.version)) {
|
||||
|
||||
38
build/lib/get-license-text.js
Normal file
38
build/lib/get-license-text.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const legalEagle = require('legal-eagle')
|
||||
|
||||
const licenseOverrides = require('./license-overrides')
|
||||
const CONFIG = require('../config')
|
||||
|
||||
module.exports = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
legalEagle({path: CONFIG.repositoryRootPath, overrides: licenseOverrides}, (err, packagesLicenses) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
throw new Error(err)
|
||||
} else {
|
||||
let text =
|
||||
fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'LICENSE.md'), 'utf8') + '\n\n' +
|
||||
'This application bundles the following third-party packages in accordance\n' +
|
||||
'with the following licenses:\n\n'
|
||||
for (let packageName of Object.keys(packagesLicenses).sort()) {
|
||||
const packageLicense = packagesLicenses[packageName]
|
||||
text += "-------------------------------------------------------------------------\n\n"
|
||||
text += `Package: ${packageName}\n`
|
||||
text += `License: ${packageLicense.license}\n`
|
||||
if (packageLicense.source) {
|
||||
text += `License Source: ${packageLicense.source}\n`
|
||||
}
|
||||
if (packageLicense.sourceText) {
|
||||
text += `Source Text:\n\n${packageLicense.sourceText}`
|
||||
}
|
||||
text += '\n'
|
||||
}
|
||||
resolve(text)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
84
build/lib/license-overrides.js
Normal file
84
build/lib/license-overrides.js
Normal file
File diff suppressed because one or more lines are too long
@@ -5,12 +5,13 @@ const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const electronPackager = require('electron-packager')
|
||||
const includePathInPackagedApp = require('./include-path-in-packaged-app')
|
||||
const getLicenseText = require('./get-license-text')
|
||||
|
||||
const CONFIG = require('../config')
|
||||
|
||||
module.exports = function () {
|
||||
module.exports = async function () {
|
||||
console.log(`Running electron-packager on ${CONFIG.intermediateAppPath}`)
|
||||
electronPackager({
|
||||
const packagedAppPath = await runPackager({
|
||||
'app-version': CONFIG.appMetadata.version,
|
||||
'arch': process.arch,
|
||||
'asar': {unpack: buildAsarUnpackGlobExpression()},
|
||||
@@ -22,26 +23,21 @@ module.exports = function () {
|
||||
'overwrite': true,
|
||||
'platform': process.platform,
|
||||
'version': CONFIG.appMetadata.electronVersion
|
||||
}, (err, packagedAppPaths) => {
|
||||
if (err) throw new Error(err)
|
||||
assert(packagedAppPaths.length === 1, 'Generated more than one electron application!')
|
||||
|
||||
const packagedAppPath = packagedAppPaths[0]
|
||||
let bundledResourcesPath
|
||||
if (process.platform === 'darwin') {
|
||||
bundledResourcesPath = path.join(packagedAppPath, 'Atom.app', 'Contents', 'Resources')
|
||||
} else {
|
||||
throw new Error('TODO: handle this case!')
|
||||
}
|
||||
|
||||
copyNonASARResources(bundledResourcesPath)
|
||||
console.log(`Application bundle(s) created on ${packagedAppPath}`)
|
||||
})
|
||||
let bundledResourcesPath
|
||||
if (process.platform === 'darwin') {
|
||||
bundledResourcesPath = path.join(packagedAppPath, 'Atom.app', 'Contents', 'Resources')
|
||||
} else {
|
||||
throw new Error('TODO: handle this case!')
|
||||
}
|
||||
|
||||
await copyNonASARResources(bundledResourcesPath)
|
||||
console.log(`Application bundle created on ${packagedAppPath}`)
|
||||
}
|
||||
|
||||
function copyNonASARResources (bundledResourcesPath) {
|
||||
async function copyNonASARResources (bundledResourcesPath) {
|
||||
const bundledShellCommandsPath = path.join(bundledResourcesPath, 'app')
|
||||
console.log(`Copying shell commands to ${bundledShellCommandsPath}...`);
|
||||
console.log(`Copying shell commands to ${bundledShellCommandsPath}...`)
|
||||
fs.copySync(
|
||||
path.join(CONFIG.repositoryRootPath, 'apm', 'node_modules', 'atom-package-manager'),
|
||||
path.join(bundledShellCommandsPath, 'apm'),
|
||||
@@ -56,6 +52,9 @@ function copyNonASARResources (bundledResourcesPath) {
|
||||
if (process.platform === 'darwin') {
|
||||
fs.copySync(path.join(CONFIG.repositoryRootPath, 'resources', 'mac', 'file.icns'), path.join(bundledResourcesPath, 'file.icns'))
|
||||
}
|
||||
|
||||
console.log(`Writing LICENSE.md to ${bundledResourcesPath}...`)
|
||||
fs.writeFileSync(path.join(bundledResourcesPath, 'LICENSE.md'), await getLicenseText())
|
||||
}
|
||||
|
||||
function buildAsarUnpackGlobExpression () {
|
||||
@@ -71,3 +70,29 @@ function buildAsarUnpackGlobExpression () {
|
||||
|
||||
return `{${unpack.join(',')}}`
|
||||
}
|
||||
|
||||
function runPackager (options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
electronPackager({
|
||||
'app-version': CONFIG.appMetadata.version,
|
||||
'arch': process.arch,
|
||||
'asar': {unpack: buildAsarUnpackGlobExpression()},
|
||||
'build-version': CONFIG.appMetadata.version,
|
||||
'download': {cache: CONFIG.cachePath},
|
||||
'dir': CONFIG.intermediateAppPath,
|
||||
'icon': path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'atom.icns'),
|
||||
'out': CONFIG.buildOutputPath,
|
||||
'overwrite': true,
|
||||
'platform': process.platform,
|
||||
'version': CONFIG.appMetadata.electronVersion
|
||||
}, (err, packagedAppPaths) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
throw new Error(err)
|
||||
} else {
|
||||
assert(packagedAppPaths.length === 1, 'Generated more than one electron application!')
|
||||
resolve(packagedAppPaths[0])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"electron-packager": "7.3.0",
|
||||
"fs-extra": "0.30.0",
|
||||
"glob": "7.0.3",
|
||||
"legal-eagle": "0.13.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"normalize-package-data": "2.3.5",
|
||||
"npm": "3.10.5",
|
||||
|
||||
Reference in New Issue
Block a user