|
| 1 | +/* eslint-disable @typescript-eslint/no-var-requires */ |
| 2 | +/* eslint-disable no-undef */ |
| 3 | +const execSync = require('child_process').execSync |
| 4 | +const semver = require('semver') |
| 5 | +const glob = require('glob') |
| 6 | +const packageJson = require('../../package.json') |
| 7 | + |
| 8 | +const folderPath = '.changelog/' |
| 9 | +const majorPattern = `${folderPath}*breaking*.md` |
| 10 | +const minorPattern = `${folderPath}*feature*.md` |
| 11 | +const patchPattern = `${folderPath}*{process,cfg,bugfix,doc,internal,trivial}*.md` |
| 12 | + |
| 13 | +console.log('Assembling Change Log and updating package version') |
| 14 | + |
| 15 | +let version = packageJson.version |
| 16 | +if (glob.sync(majorPattern).length > 0) { |
| 17 | + console.log('\x1b[31m%s\x1b[0m', 'Warning: This release contains breaking changes.') |
| 18 | + version = semver.inc(version, 'major') |
| 19 | +} else if (glob.sync(minorPattern).length > 0) { |
| 20 | + version = semver.inc(version, 'minor') |
| 21 | +} else if (glob.sync(patchPattern).length > 0) { |
| 22 | + version = semver.inc(version, 'patch') |
| 23 | +} else { |
| 24 | + console.log('No Change Log fragments found. Aborting release...') |
| 25 | + process.exit(1) |
| 26 | +} |
| 27 | + |
| 28 | +if (!semver.valid(version)) { |
| 29 | + console.log(`Invalid version: ${version}`) |
| 30 | + process.exit(1) |
| 31 | +} |
| 32 | + |
| 33 | +if (semver.lte(version, packageJson.version)) { |
| 34 | + console.log(`Version ${version} is not greater than ${packageJson.version}`) |
| 35 | + process.exit(1) |
| 36 | +} |
| 37 | + |
| 38 | +execSync(`pnpm version --no-git-tag-version ${version}`, { stdio: 'inherit' }) |
| 39 | +execSync(`towncrier build --version ${version}`, { stdio: 'inherit' }) |
0 commit comments