github-desktop/script/dist-info.js

187 lines
4.5 KiB
JavaScript
Raw Normal View History

2016-05-25 14:37:27 +00:00
'use strict'
const path = require('path')
const os = require('os')
2017-06-19 20:35:46 +00:00
const fs = require('fs')
2016-05-25 14:37:27 +00:00
const projectRoot = path.join(__dirname, '..')
const appPackage = require(path.join(projectRoot, 'app', 'package.json'))
2016-05-25 14:37:27 +00:00
2017-07-13 15:11:04 +00:00
function getDistPath() {
return path.join(
projectRoot,
'dist',
2017-07-14 14:20:20 +00:00
`${getExecutableName()}-${process.platform}-x64`
2017-07-13 15:11:04 +00:00
)
2016-05-25 14:37:27 +00:00
}
2017-07-14 14:20:20 +00:00
function getExecutableName() {
const suffix = process.env.NODE_ENV === 'development' ? '-dev' : ''
return process.platform === 'win32'
? `${getWindowsIdentifierName()}${suffix}`
: getProductName()
}
2017-07-13 15:11:04 +00:00
function getProductName() {
const productName = appPackage.productName
2017-07-13 15:11:04 +00:00
return process.env.NODE_ENV === 'development'
? `${productName}-dev`
: productName
2016-05-25 14:37:27 +00:00
}
2017-07-13 15:11:04 +00:00
function getCompanyName() {
return appPackage.companyName
}
2016-05-25 20:48:45 +00:00
2017-07-13 15:11:04 +00:00
function getVersion() {
2016-05-25 20:48:45 +00:00
return appPackage.version
}
2017-07-13 15:11:04 +00:00
function getOSXZipName() {
2016-06-16 19:42:35 +00:00
const productName = getProductName()
return `${productName}.zip`
}
2017-07-13 15:11:04 +00:00
function getOSXZipPath() {
2016-06-16 19:42:35 +00:00
return path.join(getDistPath(), '..', getOSXZipName())
}
2017-07-13 15:11:04 +00:00
function getWindowsInstallerName() {
2017-07-14 14:20:20 +00:00
const productName = getExecutableName()
2016-06-16 19:42:35 +00:00
return `${productName}Setup.msi`
2016-05-25 20:48:45 +00:00
}
2017-07-13 15:11:04 +00:00
function getWindowsInstallerPath() {
2016-06-16 19:42:35 +00:00
return path.join(getDistPath(), '..', 'installer', getWindowsInstallerName())
}
2017-07-13 15:11:04 +00:00
function getWindowsStandaloneName() {
2017-07-14 14:20:20 +00:00
const productName = getExecutableName()
2016-06-16 19:42:35 +00:00
return `${productName}Setup.exe`
}
2017-07-13 15:11:04 +00:00
function getWindowsStandalonePath() {
2016-06-16 19:42:35 +00:00
return path.join(getDistPath(), '..', 'installer', getWindowsStandaloneName())
}
2017-07-13 15:11:04 +00:00
function getWindowsFullNugetPackageName() {
2017-05-12 18:32:51 +00:00
return `${getWindowsIdentifierName()}-${getVersion()}-full.nupkg`
2016-06-16 19:42:35 +00:00
}
2017-07-13 15:11:04 +00:00
function getWindowsFullNugetPackagePath() {
return path.join(
getDistPath(),
'..',
'installer',
getWindowsFullNugetPackageName()
)
2016-05-25 20:48:45 +00:00
}
2017-07-13 15:49:16 +00:00
function getWindowsDeltaNugetPackageName() {
return `${getWindowsIdentifierName()}-${getVersion()}-delta.nupkg`
}
function getWindowsDeltaNugetPackagePath() {
return path.join(
getDistPath(),
'..',
'installer',
getWindowsDeltaNugetPackageName()
)
}
2017-07-13 15:11:04 +00:00
function getBundleID() {
return appPackage.bundleID
}
2017-07-13 15:11:04 +00:00
function getUserDataPath() {
if (process.platform === 'win32') {
2017-07-14 14:20:20 +00:00
return path.join(process.env.APPDATA, getExecutableName())
} else if (process.platform === 'darwin') {
const home = os.homedir()
return path.join(home, 'Library', 'Application Support', getProductName())
2017-07-20 18:32:14 +00:00
} else if (process.platform === 'linux') {
if (process.env.XDG_CONFIG_HOME) {
return path.join(process.env.XDG_CONFIG_HOME, getProductName())
}
2017-07-20 18:32:14 +00:00
const home = os.homedir()
return path.join(home, '.config', getProductName())
} else {
2017-07-20 18:32:14 +00:00
console.error(
`I dunno how to resolve the user data path for ${process.platform} ${process.arch} :(`
2017-07-20 18:32:14 +00:00
)
process.exit(1)
}
}
2017-07-13 15:11:04 +00:00
function getWindowsIdentifierName() {
2017-05-12 18:32:51 +00:00
return 'GitHubDesktop'
}
2017-07-13 15:11:04 +00:00
function getBundleSizes() {
const rendererStats = fs.statSync(
path.join(projectRoot, 'out', 'renderer.js')
)
2017-06-19 20:35:46 +00:00
const mainStats = fs.statSync(path.join(projectRoot, 'out', 'main.js'))
return { rendererSize: rendererStats.size, mainSize: mainStats.size }
}
2017-07-13 18:39:33 +00:00
function getReleaseBranchName() {
2017-07-13 15:01:57 +00:00
let branchName
2017-07-13 14:28:20 +00:00
if (process.platform === 'darwin') {
branchName = process.env.TRAVIS_BRANCH
} else if (process.platform === 'win32') {
branchName = process.env.APPVEYOR_REPO_BRANCH
}
2017-07-13 18:39:33 +00:00
return branchName || ''
}
function getReleaseChannel() {
2017-07-13 14:28:20 +00:00
// Branch name format: __release-CHANNEL-DEPLOY_ID
2017-07-13 18:39:33 +00:00
const pieces = getReleaseBranchName().split('-')
2017-07-13 14:28:20 +00:00
if (pieces.length < 3 || pieces[0] !== '__release') {
return process.env.NODE_ENV || 'development'
2017-07-13 14:28:20 +00:00
}
return pieces[1]
}
function getUpdatesURL() {
return `https://central.github.com/api/deployments/desktop/desktop/latest?version=${getVersion()}&env=${getReleaseChannel()}`
}
function shouldMakeDelta() {
// Only production and beta channels include deltas. Test releases aren't
// necessarily sequential so deltas wouldn't make sense.
const channelsWithDeltas = ['production', 'beta']
2017-07-13 18:19:13 +00:00
return channelsWithDeltas.indexOf(getReleaseChannel()) > -1
}
2016-06-16 19:42:35 +00:00
module.exports = {
getDistPath,
getProductName,
getCompanyName,
getVersion,
getOSXZipName,
getOSXZipPath,
getWindowsInstallerName,
getWindowsInstallerPath,
getWindowsStandaloneName,
getWindowsStandalonePath,
getWindowsFullNugetPackageName,
getWindowsFullNugetPackagePath,
getBundleID,
getUserDataPath,
2017-06-19 20:57:44 +00:00
getWindowsIdentifierName,
2017-07-13 15:11:04 +00:00
getBundleSizes,
2017-07-13 14:28:20 +00:00
getReleaseChannel,
getUpdatesURL,
2017-07-13 15:49:16 +00:00
getWindowsDeltaNugetPackageName,
getWindowsDeltaNugetPackagePath,
shouldMakeDelta,
2017-07-13 18:39:33 +00:00
getReleaseBranchName,
2017-07-14 14:20:20 +00:00
getExecutableName,
2016-06-16 19:42:35 +00:00
}