-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.ts
75 lines (54 loc) · 2.24 KB
/
release.ts
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
import fs from 'fs';
import { execSync } from 'child_process';
import dotenv from 'dotenv-safe';
const argv = require('yargs').argv
import semverRegex from 'semver-regex';
import semverDiff from 'semver-diff';
import conventionalGithubReleaser from 'conventional-github-releaser';
import rootPackageJson from './package.json';
import backendPackageJson from './backend/package.json';
import clientPackageJson from './client/package.json';
dotenv.config()
const ready = (err) => {
if (err) {
console.log(err)
return
}
console.log(`new release ${argv.v} generated`)
}
const AUTH = {
token: process.env.GITHUB_RELEASE_TOKEN,
url: 'https://api.github.com'
};
if (semverRegex().test(argv.v) && semverDiff(rootPackageJson.version, argv.v)) {
console.log('start generating a new release')
console.log('bumping the package version with given input')
rootPackageJson.version = argv.v
fs.writeFileSync('./package.json', JSON.stringify(rootPackageJson, null, 2) + '\n');
execSync(`npm i --loglevel=error`)
backendPackageJson.version = argv.v
fs.writeFileSync('./backend/package.json', JSON.stringify(backendPackageJson, null, 2) + '\n');
execSync(`cd backend && npm i --loglevel=error && cd ../`)
clientPackageJson.version = argv.v
fs.writeFileSync('./client/package.json', JSON.stringify(clientPackageJson, null, 2) + '\n');
execSync(`cd client && npm i --loglevel=error && cd ../`)
execSync('git add .')
execSync('git commit -m "bump version"')
execSync(`git push origin master`)
console.log('create a release tag with given input')
execSync(`git tag ${argv.v}`)
execSync(`git push origin ${argv.v}`)
console.log('generate the release output')
conventionalGithubReleaser(AUTH, {
preset: 'angular'
}, ready);
} else {
console.log('specified tag is not valid or lower or equal then the current one')
const numbers = rootPackageJson.version.split('.').map(n => parseInt(n))
const patch = `${numbers[0]}.${numbers[1]}.${numbers[2] + 1}`
const minor = `${numbers[0]}.${numbers[1] + 1}.0`
const major = `${numbers[0] + 1}.0.0`
console.log(`${patch} for patch`)
console.log(`${minor} for minor`)
console.log(`${major} for major`)
}