2018-12-06 19:00:10 +00:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const semver = require('semver')
|
|
|
|
const { GitProcess } = require('dugite')
|
|
|
|
const { promisify } = require('util')
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
const { ELECTRON_DIR } = require('../lib/utils')
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
const readFile = promisify(fs.readFile)
|
|
|
|
|
2019-01-07 21:41:07 +00:00
|
|
|
const preType = {
|
|
|
|
NONE: 'none',
|
|
|
|
PARTIAL: 'partial',
|
|
|
|
FULL: 'full'
|
|
|
|
}
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
const getCurrentDate = () => {
|
|
|
|
const d = new Date()
|
|
|
|
const dd = `${d.getDate()}`.padStart(2, '0')
|
|
|
|
const mm = `${d.getMonth() + 1}`.padStart(2, '0')
|
|
|
|
const yyyy = d.getFullYear()
|
|
|
|
return `${yyyy}${mm}${dd}`
|
|
|
|
}
|
|
|
|
|
|
|
|
const isNightly = v => v.includes('nightly')
|
|
|
|
const isBeta = v => v.includes('beta')
|
|
|
|
const isStable = v => {
|
|
|
|
const parsed = semver.parse(v)
|
|
|
|
return !!(parsed && parsed.prerelease.length === 0)
|
|
|
|
}
|
|
|
|
|
2019-01-07 21:41:07 +00:00
|
|
|
const makeVersion = (components, delim, pre = preType.NONE) => {
|
2018-12-06 19:00:10 +00:00
|
|
|
let version = [components.major, components.minor, components.patch].join(delim)
|
2019-01-07 21:41:07 +00:00
|
|
|
if (pre === preType.PARTIAL) {
|
2019-04-30 18:36:39 +00:00
|
|
|
version += `${delim}${components.pre[1] || 0}`
|
2019-01-07 21:41:07 +00:00
|
|
|
} else if (pre === preType.FULL) {
|
2018-12-06 19:00:10 +00:00
|
|
|
version += `-${components.pre[0]}${delim}${components.pre[1]}`
|
|
|
|
}
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
async function nextBeta (v) {
|
|
|
|
const next = semver.coerce(semver.clean(v))
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
const tagBlob = await GitProcess.exec(['tag', '--list', '-l', `v${next}-beta.*`], ELECTRON_DIR)
|
2018-12-06 19:00:10 +00:00
|
|
|
const tags = tagBlob.stdout.split('\n').filter(e => e !== '')
|
|
|
|
tags.sort((t1, t2) => semver.gt(t1, t2))
|
|
|
|
|
|
|
|
// increment the latest existing beta tag or start at beta.1 if it's a new beta line
|
2019-07-31 18:04:19 +00:00
|
|
|
return tags.length === 0 ? `${next}-beta.1` : semver.inc(tags.pop(), 'prerelease')
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getElectronVersion () {
|
2019-06-24 17:18:04 +00:00
|
|
|
const versionPath = path.resolve(ELECTRON_DIR, 'ELECTRON_VERSION')
|
2018-12-06 19:00:10 +00:00
|
|
|
const version = await readFile(versionPath, 'utf8')
|
|
|
|
return version.trim()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function nextNightly (v) {
|
|
|
|
let next = semver.valid(semver.coerce(v))
|
|
|
|
const pre = `nightly.${getCurrentDate()}`
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
const branch = (await GitProcess.exec(['rev-parse', '--abbrev-ref', 'HEAD'], ELECTRON_DIR)).stdout.trim()
|
2018-12-06 19:00:10 +00:00
|
|
|
if (branch === 'master') {
|
|
|
|
next = semver.inc(await getLastMajorForMaster(), 'major')
|
|
|
|
} else if (isStable(v)) {
|
|
|
|
next = semver.inc(next, 'patch')
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${next}-${pre}`
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
async function getLastMajorForMaster () {
|
|
|
|
let branchNames
|
2019-11-12 16:36:03 +00:00
|
|
|
const result = await GitProcess.exec(['branch', '-a', '--remote', '--list', 'origin/[0-9]*-x-y'], ELECTRON_DIR)
|
2019-06-24 17:18:04 +00:00
|
|
|
if (result.exitCode === 0) {
|
|
|
|
branchNames = result.stdout.trim().split('\n')
|
|
|
|
const filtered = branchNames.map(b => b.replace('origin/', ''))
|
|
|
|
return getNextReleaseBranch(filtered)
|
|
|
|
} else {
|
|
|
|
throw new Error('Release branches could not be fetched.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNextReleaseBranch (branches) {
|
2019-11-12 16:36:03 +00:00
|
|
|
const converted = branches.map(b => b.replace(/-/g, '.').replace('x', '0').replace('y', '0'))
|
2019-06-24 17:18:04 +00:00
|
|
|
return converted.reduce((v1, v2) => semver.gt(v1, v2) ? v1 : v2)
|
|
|
|
}
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
module.exports = {
|
|
|
|
isStable,
|
|
|
|
isBeta,
|
|
|
|
isNightly,
|
|
|
|
nextBeta,
|
|
|
|
makeVersion,
|
|
|
|
getElectronVersion,
|
2019-01-08 20:04:27 +00:00
|
|
|
nextNightly,
|
|
|
|
preType
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|