2021-03-04 17:49:52 +03:00
|
|
|
import { command } from 'execa'
|
2019-02-10 15:26:50 +03:00
|
|
|
import fs from 'fs'
|
|
|
|
|
|
|
|
import log from '@/helpers/log'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update version number in files which need version number
|
|
|
|
*/
|
|
|
|
export default version => new Promise(async (resolve, reject) => {
|
|
|
|
const changelog = 'CHANGELOG.md'
|
|
|
|
const tmpChangelog = 'TMP-CHANGELOG.md'
|
|
|
|
|
|
|
|
log.info(`Generating ${changelog}...`)
|
|
|
|
|
|
|
|
try {
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`git-changelog --changelogrc .changelogrc --template scripts/assets/CHANGELOG-TEMPLATE.md --file scripts/tmp/${tmpChangelog} --version_name ${version}`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
} catch (e) {
|
|
|
|
log.error(`Error during git-changelog: ${e}`)
|
|
|
|
reject(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
log.info('Getting remote origin URL...')
|
|
|
|
log.info('Getting previous tag...')
|
|
|
|
|
2021-03-04 17:49:52 +03:00
|
|
|
const sh = await command('git config --get remote.origin.url && git tag | tail -n1', { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
|
|
|
|
const repoUrl = sh.stdout.substr(0, sh.stdout.lastIndexOf('.git'))
|
|
|
|
const previousTag = sh.stdout.substr(sh.stdout.indexOf('\n') + 1).trim()
|
|
|
|
const changelogData = fs.readFileSync(changelog, 'utf8')
|
2019-04-24 02:19:01 +03:00
|
|
|
const compareUrl = `${repoUrl}/compare/${previousTag}...${version}`
|
2019-02-10 15:26:50 +03:00
|
|
|
let tmpData = fs.readFileSync(`scripts/tmp/${tmpChangelog}`, 'utf8')
|
|
|
|
|
|
|
|
log.success(`Remote origin URL gotten: ${repoUrl}.git`)
|
|
|
|
log.success(`Previous tag gotten: ${previousTag}`)
|
|
|
|
|
|
|
|
if (previousTag !== '') {
|
|
|
|
tmpData = tmpData.replace(version, `[${version}](${compareUrl})`)
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFile(changelog, `${tmpData}${changelogData}`, (err) => {
|
|
|
|
if (err) log.error(`Failed to write into file: ${err}`)
|
|
|
|
else {
|
|
|
|
fs.unlinkSync(`scripts/tmp/${tmpChangelog}`)
|
|
|
|
log.success(`${changelog} generated`)
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
log.error(`Error during git commands: ${e}`)
|
|
|
|
reject(e)
|
|
|
|
}
|
|
|
|
})
|