github-desktop/script/dist-info.js

247 lines
6.2 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, '..')
// eslint-disable-next-line import/no-dynamic-require
const appPackage = require(path.join(projectRoot, 'app', 'package.json'))
2016-05-25 14:37:27 +00:00
function getDistRoot() {
return path.join(projectRoot, 'dist')
}
2017-07-13 15:11:04 +00:00
function getDistPath() {
return path.join(
getDistRoot(),
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 {
throw new Error(
`I dunno how to resolve the user data path for ${process.platform} ${process.arch} :(`
2017-07-20 18:32:14 +00:00
)
}
}
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') {
2017-09-12 12:29:55 +00:00
branchName = process.env.CIRCLE_BRANCH
2017-07-13 14:28:20 +00:00
} 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 getReleaseSHA() {
// Branch name format: __release-CHANNEL-DEPLOY_ID
const pieces = getReleaseBranchName().split('-')
if (pieces.length < 3 || pieces[0] !== '__release') {
return null
}
return pieces[2]
}
2017-07-13 14:28:20 +00:00
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
}
function getCLICommands() {
2017-08-21 11:14:31 +00:00
return fs
2017-08-21 16:14:16 +00:00
.readdirSync(path.resolve(projectRoot, 'app', 'src', 'cli', 'commands'))
.filter(name => name.endsWith('.ts'))
.map(name => name.replace(/\.ts$/, ''))
}
/**
* Attempt to dereference the given ref without requiring a Git environment
* to be present. Note that this method will not be able to dereference packed
* refs but should suffice for simple refs like 'HEAD'.
*
* Will throw an error for unborn HEAD.
*
* @param {string} gitDir The path to the Git repository's .git directory
* @param {string} ref A qualified git ref such as 'HEAD' or 'refs/heads/master'
*/
function revParse(gitDir, ref) {
const refPath = path.join(gitDir, ref)
const refContents = fs.readFileSync(refPath)
const refRe = /^([a-f0-9]{40})|(?:ref: (refs\/.*))$/m
const refMatch = refRe.exec(refContents)
if (!refMatch) {
throw new Error(
`Could not de-reference HEAD to SHA, invalid ref in ${refPath}: ${refContents}`
)
}
return refMatch[1] || revParse(gitDir, refMatch[2])
}
function getSHA() {
// CircleCI does some funny stuff where HEAD points to an packed ref, but
// luckily it gives us the SHA we want in the environment.
const circleSHA = process.env.CIRCLE_SHA1
if (circleSHA) {
return circleSHA
}
return revParse(path.resolve(__dirname, '../.git'), 'HEAD')
}
2016-06-16 19:42:35 +00:00
module.exports = {
getDistRoot,
2016-06-16 19:42:35 +00:00
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,
getReleaseSHA,
2017-07-13 14:28:20 +00:00
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,
getCLICommands,
getSHA,
2016-06-16 19:42:35 +00:00
}