-
Notifications
You must be signed in to change notification settings - Fork 6
/
release.ts
64 lines (55 loc) · 1.88 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
import * as fs from 'fs';
import * as inquirer from 'inquirer';
import * as path from 'path';
import { cd, echo, exec } from 'shelljs';
const prompt = inquirer.createPromptModule();
function updatePackageJSON(pkgJSONLocation: string, version: string) {
const pkgJSON = require(pkgJSONLocation);
pkgJSON.version = version;
if (pkgJSON.peerDependencies) {
for (let i of Object.keys(pkgJSON.peerDependencies)) {
if (i.startsWith('rest-ts')) {
pkgJSON.peerDependencies[i] = `^${version}`;
}
}
}
fs.writeFileSync(pkgJSONLocation, JSON.stringify(pkgJSON, null, 4), { encoding: 'utf-8' });
}
(async () => {
if (exec('git status --porcelain').stdout.trim() !== '') {
echo('Your repository is dirty. Aborting');
process.exit(1);
return;
}
const { version, message } = await prompt<{version: string, message: string}>([{
type: 'input',
name: 'version',
message: 'Version?',
filter: (val) => {
return val.toLowerCase();
}
}, {
type: 'input',
name: 'message',
message: 'Short release message'
}]);
echo(`About to release ${version}: ${message}.`);
const { proceed } = await prompt<{proceed: boolean}>([{
type: 'confirm',
name: 'proceed',
message: 'Proceed?',
default: false
}]);
if (proceed !== true) {
echo('Aborting');
process.exit(1);
return;
}
updatePackageJSON('./packages/rest-ts-core/package.json', version);
updatePackageJSON('./packages/rest-ts-axios/package.json', version);
updatePackageJSON('./packages/rest-ts-express/package.json', version);
exec(`make test`);
exec(`git add -u && git commit -m "release v${version}"`);
exec(`git tag -s -m "${message}" "v${version}"`);
exec('git push --tags origin master');
})();