2018-12-03 21:28:10 +00:00
|
|
|
const { GitProcess } = require('dugite')
|
2019-06-05 23:30:39 +00:00
|
|
|
const fs = require('fs')
|
2018-09-13 16:57:39 +00:00
|
|
|
const path = require('path')
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
const ELECTRON_DIR = path.resolve(__dirname, '..', '..')
|
|
|
|
const SRC_DIR = path.resolve(ELECTRON_DIR, '..')
|
2019-06-05 23:30:39 +00:00
|
|
|
|
2019-12-18 22:57:46 +00:00
|
|
|
const RELEASE_BRANCH_PATTERN = /(\d)+-(?:(?:[0-9]+-x$)|(?:x+-y$))/
|
|
|
|
|
2018-12-03 21:28:10 +00:00
|
|
|
require('colors')
|
2019-08-29 14:46:54 +00:00
|
|
|
const pass = '✓'.green
|
|
|
|
const fail = '✗'.red
|
2018-12-03 21:28:10 +00:00
|
|
|
|
2018-09-13 16:57:39 +00:00
|
|
|
function getElectronExec () {
|
2019-08-21 17:41:35 +00:00
|
|
|
const OUT_DIR = getOutDir()
|
2018-09-13 16:57:39 +00:00
|
|
|
switch (process.platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return `out/${OUT_DIR}/Electron.app/Contents/MacOS/Electron`
|
|
|
|
case 'win32':
|
|
|
|
return `out/${OUT_DIR}/electron.exe`
|
|
|
|
case 'linux':
|
|
|
|
return `out/${OUT_DIR}/electron`
|
|
|
|
default:
|
|
|
|
throw new Error('Unknown platform')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 22:00:42 +00:00
|
|
|
function getOutDir (options = {}) {
|
|
|
|
const shouldLog = options.shouldLog || false
|
|
|
|
|
|
|
|
if (options.outDir || process.env.ELECTRON_OUT_DIR) {
|
|
|
|
const outDir = options.outDir || process.env.ELECTRON_OUT_DIR
|
|
|
|
const outPath = path.resolve(SRC_DIR, 'out', outDir)
|
|
|
|
|
|
|
|
// Check that user-set variable is a valid/existing directory
|
|
|
|
if (fs.existsSync(outPath)) {
|
|
|
|
if (shouldLog) console.log(`OUT_DIR is: ${outDir}`)
|
|
|
|
return outDir
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw error if user passed/set nonexistent directory.
|
|
|
|
throw new Error(`${outDir} directory not configured on your machine.`)
|
2019-08-21 17:41:35 +00:00
|
|
|
} else {
|
2019-12-17 22:00:42 +00:00
|
|
|
for (const buildType of ['Testing', 'Release', 'Default', 'Debug']) {
|
2019-08-21 17:41:35 +00:00
|
|
|
const outPath = path.resolve(SRC_DIR, 'out', buildType)
|
|
|
|
if (fs.existsSync(outPath)) {
|
|
|
|
if (shouldLog) console.log(`OUT_DIR is: ${buildType}`)
|
|
|
|
return buildType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:57:39 +00:00
|
|
|
function getAbsoluteElectronExec () {
|
2019-06-24 17:18:04 +00:00
|
|
|
return path.resolve(SRC_DIR, getElectronExec())
|
2018-09-13 16:57:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 03:56:43 +00:00
|
|
|
async function handleGitCall (args, gitDir) {
|
|
|
|
const details = await GitProcess.exec(args, gitDir)
|
|
|
|
if (details.exitCode === 0) {
|
2019-06-20 20:12:05 +00:00
|
|
|
return details.stdout.replace(/^\*|\s+|\s+$/, '')
|
2018-12-03 21:28:10 +00:00
|
|
|
} else {
|
2019-06-17 03:56:43 +00:00
|
|
|
const error = GitProcess.parseError(details.stderr)
|
|
|
|
console.log(`${fail} couldn't parse git process call: `, error)
|
2018-12-03 21:28:10 +00:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 03:56:43 +00:00
|
|
|
async function getCurrentBranch (gitDir) {
|
|
|
|
let branch = await handleGitCall(['rev-parse', '--abbrev-ref', 'HEAD'], gitDir)
|
2019-12-18 22:57:46 +00:00
|
|
|
if (branch !== 'master' && !RELEASE_BRANCH_PATTERN.test(branch)) {
|
2019-06-17 03:56:43 +00:00
|
|
|
const lastCommit = await handleGitCall(['rev-parse', 'HEAD'], gitDir)
|
2019-06-21 20:59:00 +00:00
|
|
|
const branches = (await handleGitCall([
|
|
|
|
'branch',
|
|
|
|
'--contains',
|
|
|
|
lastCommit,
|
|
|
|
'--remote'
|
|
|
|
], gitDir)).split('\n')
|
|
|
|
|
2019-12-18 22:57:46 +00:00
|
|
|
branch = branches.filter(b => b.trim() === 'master' || RELEASE_BRANCH_PATTERN.test(b.trim()))[0]
|
2019-06-18 14:54:32 +00:00
|
|
|
if (!branch) {
|
|
|
|
console.log(`${fail} no release branch exists for this ref`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2019-06-21 20:59:00 +00:00
|
|
|
if (branch.startsWith('origin/')) branch = branch.substr('origin/'.length)
|
2019-06-17 03:56:43 +00:00
|
|
|
}
|
2019-06-20 20:12:05 +00:00
|
|
|
return branch.trim()
|
2019-06-17 03:56:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:57:39 +00:00
|
|
|
module.exports = {
|
2018-12-03 21:28:10 +00:00
|
|
|
getCurrentBranch,
|
2018-09-13 16:57:39 +00:00
|
|
|
getElectronExec,
|
2019-08-21 17:41:35 +00:00
|
|
|
getOutDir,
|
2018-09-13 16:57:39 +00:00
|
|
|
getAbsoluteElectronExec,
|
2019-06-24 17:18:04 +00:00
|
|
|
ELECTRON_DIR,
|
|
|
|
SRC_DIR
|
2018-09-13 16:57:39 +00:00
|
|
|
}
|