2016-05-25 14:37:27 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const path = require('path')
|
2017-02-07 13:48:17 +00:00
|
|
|
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, '..')
|
2017-10-19 23:01:08 +00:00
|
|
|
// eslint-disable-next-line import/no-dynamic-require
|
2016-07-21 18:31:30 +00:00
|
|
|
const appPackage = require(path.join(projectRoot, 'app', 'package.json'))
|
2016-05-25 14:37:27 +00:00
|
|
|
|
2017-09-23 03:30:36 +00:00
|
|
|
function getDistRoot() {
|
|
|
|
return path.join(projectRoot, 'dist')
|
|
|
|
}
|
|
|
|
|
2017-07-13 15:11:04 +00:00
|
|
|
function getDistPath() {
|
|
|
|
return path.join(
|
2017-09-23 03:30:36 +00:00
|
|
|
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() {
|
2016-10-10 21:08:37 +00:00
|
|
|
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
|
|
|
}
|
2016-05-25 14:47:51 +00:00
|
|
|
|
2017-07-13 15:11:04 +00:00
|
|
|
function getCompanyName() {
|
2016-05-25 14:47:51 +00:00
|
|
|
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() {
|
2016-10-10 20:53:42 +00:00
|
|
|
return appPackage.bundleID
|
|
|
|
}
|
|
|
|
|
2017-07-13 15:11:04 +00:00
|
|
|
function getUserDataPath() {
|
2017-02-07 13:48:17 +00:00
|
|
|
if (process.platform === 'win32') {
|
2017-07-14 14:20:20 +00:00
|
|
|
return path.join(process.env.APPDATA, getExecutableName())
|
2017-02-07 13:48:17 +00:00
|
|
|
} 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') {
|
2017-07-24 20:42:42 +00:00
|
|
|
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()
|
2017-07-24 20:42:42 +00:00
|
|
|
return path.join(home, '.config', getProductName())
|
2017-02-07 13:48:17 +00:00
|
|
|
} else {
|
2017-09-23 03:19:43 +00:00
|
|
|
throw new Error(
|
2017-07-24 20:42:42 +00:00
|
|
|
`I dunno how to resolve the user data path for ${process.platform} ${process.arch} :(`
|
2017-07-20 18:32:14 +00:00
|
|
|
)
|
2017-02-07 13:48:17 +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') {
|
2017-07-13 14:31:56 +00:00
|
|
|
return process.env.NODE_ENV || 'development'
|
2017-07-13 14:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pieces[1]
|
|
|
|
}
|
|
|
|
|
2017-09-21 06:56:49 +00:00
|
|
|
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()}`
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:09:07 +00:00
|
|
|
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
|
2017-07-13 18:09:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 10:55:04 +00:00
|
|
|
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'))
|
2017-08-21 10:55:04 +00:00
|
|
|
.filter(name => name.endsWith('.ts'))
|
|
|
|
.map(name => name.replace(/\.ts$/, ''))
|
|
|
|
}
|
|
|
|
|
2017-09-21 06:56:41 +00:00
|
|
|
/**
|
|
|
|
* 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 = {
|
2017-09-23 03:30:36 +00:00
|
|
|
getDistRoot,
|
2016-06-16 19:42:35 +00:00
|
|
|
getDistPath,
|
|
|
|
getProductName,
|
|
|
|
getCompanyName,
|
|
|
|
getVersion,
|
|
|
|
getOSXZipName,
|
|
|
|
getOSXZipPath,
|
|
|
|
getWindowsInstallerName,
|
|
|
|
getWindowsInstallerPath,
|
|
|
|
getWindowsStandaloneName,
|
|
|
|
getWindowsStandalonePath,
|
|
|
|
getWindowsFullNugetPackageName,
|
2016-10-10 20:53:42 +00:00
|
|
|
getWindowsFullNugetPackagePath,
|
2017-02-07 13:48:17 +00:00
|
|
|
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,
|
2017-09-21 06:56:41 +00:00
|
|
|
getReleaseSHA,
|
2017-07-13 14:28:20 +00:00
|
|
|
getUpdatesURL,
|
2017-07-13 15:49:16 +00:00
|
|
|
getWindowsDeltaNugetPackageName,
|
|
|
|
getWindowsDeltaNugetPackagePath,
|
2017-07-13 18:09:07 +00:00
|
|
|
shouldMakeDelta,
|
2017-07-13 18:39:33 +00:00
|
|
|
getReleaseBranchName,
|
2017-07-14 14:20:20 +00:00
|
|
|
getExecutableName,
|
2017-08-21 10:55:04 +00:00
|
|
|
getCLICommands,
|
2017-09-21 06:56:41 +00:00
|
|
|
getSHA,
|
2016-06-16 19:42:35 +00:00
|
|
|
}
|