forked from umijs/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseCodemod.ts
66 lines (57 loc) · 1.84 KB
/
releaseCodemod.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
import { logger } from '@umijs/utils';
import getGitRepoInfo from 'git-repo-info';
import { join } from 'path';
import 'zx/globals';
function assert(v: unknown, message: string) {
if (!v) {
logger.error(message);
process.exit(1);
}
}
(async () => {
const cwd = process.cwd();
const pkg = '@umijs/codemod';
const dirName = 'codemod';
const { branch } = getGitRepoInfo();
logger.info(`branch: ${branch}`);
logger.info(`cwd: ${cwd}`);
// check git status
logger.event('check git status');
const isGitClean = (await $`git status --porcelain`).stdout.trim().length;
assert(!isGitClean, 'git status is not clean');
// check git remote update
logger.event('check git remote update');
await $`git fetch`;
const gitStatus = (await $`git status --short --branch`).stdout.trim();
assert(!gitStatus.includes('behind'), `git status is behind remote`);
// check npm ownership
logger.event('check npm ownership');
const whoami = (await $`npm whoami`).stdout.trim();
const owners = (await $`npm owner ls ${pkg}`).stdout
.trim()
.split('\n')
.map((line) => {
return line.split(' ')[0];
});
assert(owners.includes(whoami), `${pkg} is not owned by ${whoami}`);
// bump version
logger.event(`bump version of ${pkg}`);
const pkgPath = join(cwd, dirName);
logger.info(
`current version: ${require(join(pkgPath, 'package.json')).version}`,
);
const version = await question(`What's next version? `);
await $`cd ${pkgPath} && npm version ${version}`;
// npm publish
logger.event('npm publish');
$.verbose = false;
await $`cd ${pkgPath} && npm publish`;
logger.info(`+ ${pkg}@${version}`);
$.verbose = true;
// commit
logger.event('commit');
await $`git commit --all --message "release: ${pkg}@${version}"`;
// git push
logger.event('git push');
await $`git push origin ${branch}`;
})();