forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
83 lines (74 loc) · 2.33 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { GitProcess } = require('dugite')
const fs = require('fs')
const path = require('path')
const ELECTRON_DIR = path.resolve(__dirname, '..', '..')
const SRC_DIR = path.resolve(ELECTRON_DIR, '..')
require('colors')
const pass = '✓'.green
const fail = '✗'.red
function getElectronExec () {
const OUT_DIR = getOutDir()
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')
}
}
function getOutDir (shouldLog) {
if (process.env.ELECTRON_OUT_DIR) {
return process.env.ELECTRON_OUT_DIR
} else {
for (const buildType of ['Debug', 'Testing', 'Release', 'Default']) {
const outPath = path.resolve(SRC_DIR, 'out', buildType)
if (fs.existsSync(outPath)) {
if (shouldLog) console.log(`OUT_DIR is: ${buildType}`)
return buildType
}
}
}
}
function getAbsoluteElectronExec () {
return path.resolve(SRC_DIR, getElectronExec())
}
async function handleGitCall (args, gitDir) {
const details = await GitProcess.exec(args, gitDir)
if (details.exitCode === 0) {
return details.stdout.replace(/^\*|\s+|\s+$/, '')
} else {
const error = GitProcess.parseError(details.stderr)
console.log(`${fail} couldn't parse git process call: `, error)
process.exit(1)
}
}
async function getCurrentBranch (gitDir) {
let branch = await handleGitCall(['rev-parse', '--abbrev-ref', 'HEAD'], gitDir)
if (branch !== 'master' && !branch.match(/[0-9]+-[0-9]+-x$/) && !branch.match(/[0-9]+-x-y$/)) {
const lastCommit = await handleGitCall(['rev-parse', 'HEAD'], gitDir)
const branches = (await handleGitCall([
'branch',
'--contains',
lastCommit,
'--remote'
], gitDir)).split('\n')
branch = branches.filter(b => b.trim() === 'master' || b.trim().match(/^[0-9]+-[0-9]+-x$/) || b.trim().match(/^[0-9]+-x-y$/))[0]
if (!branch) {
console.log(`${fail} no release branch exists for this ref`)
process.exit(1)
}
if (branch.startsWith('origin/')) branch = branch.substr('origin/'.length)
}
return branch.trim()
}
module.exports = {
getCurrentBranch,
getElectronExec,
getOutDir,
getAbsoluteElectronExec,
ELECTRON_DIR,
SRC_DIR
}