Support branch for code generation (#883)
This commit is contained in:
committed by
delvedor
parent
6707a8603e
commit
a4f893d563
@ -35,12 +35,12 @@ const {
|
|||||||
} = require('./utils')
|
} = require('./utils')
|
||||||
|
|
||||||
start(minimist(process.argv.slice(2), {
|
start(minimist(process.argv.slice(2), {
|
||||||
string: ['tag']
|
string: ['tag', 'branch']
|
||||||
}))
|
}))
|
||||||
|
|
||||||
function start (opts) {
|
function start (opts) {
|
||||||
const log = ora('Loading Elasticsearch Repository').start()
|
const log = ora('Loading Elasticsearch Repository').start()
|
||||||
if (semver.valid(opts.tag) === null) {
|
if (opts.branch == null && semver.valid(opts.tag) === null) {
|
||||||
log.fail(`Missing or invalid tag: ${opts.tag}`)
|
log.fail(`Missing or invalid tag: ${opts.tag}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ function start (opts) {
|
|||||||
log.text = 'Cleaning API folder...'
|
log.text = 'Cleaning API folder...'
|
||||||
rimraf.sync(join(apiOutputFolder, '*.js'))
|
rimraf.sync(join(apiOutputFolder, '*.js'))
|
||||||
|
|
||||||
cloneAndCheckout({ log, tag: opts.tag }, (err, { apiFolder, xPackFolder }) => {
|
cloneAndCheckout({ log, tag: opts.tag, branch: opts.branch }, (err, { apiFolder, xPackFolder }) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.fail(err.message)
|
log.fail(err.message)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const apiFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'r
|
|||||||
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
|
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
|
||||||
|
|
||||||
function cloneAndCheckout (opts, callback) {
|
function cloneAndCheckout (opts, callback) {
|
||||||
const { log, tag } = opts
|
const { log, tag, branch } = opts
|
||||||
withTag(tag, callback)
|
withTag(tag, callback)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,13 +57,19 @@ function cloneAndCheckout (opts, callback) {
|
|||||||
|
|
||||||
if (fresh) {
|
if (fresh) {
|
||||||
clone(checkout)
|
clone(checkout)
|
||||||
|
} else if (opts.branch) {
|
||||||
|
checkout(true)
|
||||||
} else {
|
} else {
|
||||||
checkout()
|
checkout()
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkout () {
|
function checkout (alsoPull = false) {
|
||||||
log.text = `Checking out tag '${tag}'`
|
if (branch) {
|
||||||
git.checkout(tag, err => {
|
log.text = `Checking out branch '${branch}'`
|
||||||
|
} else {
|
||||||
|
log.text = `Checking out tag '${tag}'`
|
||||||
|
}
|
||||||
|
git.checkout(branch || tag, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (retry++ > 0) {
|
if (retry++ > 0) {
|
||||||
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
|
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
|
||||||
@ -71,6 +77,9 @@ function cloneAndCheckout (opts, callback) {
|
|||||||
}
|
}
|
||||||
return pull(checkout)
|
return pull(checkout)
|
||||||
}
|
}
|
||||||
|
if (alsoPull) {
|
||||||
|
return pull(checkout)
|
||||||
|
}
|
||||||
callback(null, { apiFolder, xPackFolder })
|
callback(null, { apiFolder, xPackFolder })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user