-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
version.ts
104 lines (100 loc) · 2.55 KB
/
version.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { resolve } from 'path';
import { concat, forkJoin } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import * as standardVersion from 'standard-version';
import {
defaultHeader,
getChangelogPath,
updateChangelog,
} from './utils/changelog';
import { getPackageFiles, getProjectRoots } from './utils/workspace';
export interface CommonVersionOptions {
dryRun: boolean;
newVersion: string;
noVerify: boolean;
preset: string;
projectRoot: string;
tagPrefix: string;
}
export function versionWorkspace({
rootChangelog,
workspaceRoot,
...options
}: {
rootChangelog: boolean;
workspaceRoot: string;
} & CommonVersionOptions) {
return concat(
...[
getProjectRoots(workspaceRoot).pipe(
switchMap((projectRoots) =>
forkJoin(
projectRoots
/* Don't update the workspace's changelog as it will be
* dealt with by `standardVersion`. */
.filter((projectRoot) => projectRoot !== workspaceRoot)
.map((projectRoot) =>
updateChangelog({
dryRun: options.dryRun,
preset: options.preset,
projectRoot,
newVersion: options.newVersion,
})
)
)
)
),
getPackageFiles(workspaceRoot).pipe(
switchMap((packageFiles) =>
_runStandardVersion({
bumpFiles: packageFiles,
skipChangelog: !rootChangelog,
...options,
})
)
),
]
);
}
export function versionProject(options: CommonVersionOptions) {
return _runStandardVersion({
bumpFiles: [resolve(options.projectRoot, 'package.json')],
skipChangelog: false,
...options,
});
}
export function _runStandardVersion({
bumpFiles,
dryRun,
projectRoot,
newVersion,
noVerify,
preset,
tagPrefix,
skipChangelog,
}: {
bumpFiles: string[];
skipChangelog: boolean;
} & CommonVersionOptions) {
return standardVersion({
bumpFiles,
/* Make sure that we commit the manually generated changelogs that
* we staged. */
commitAll: true,
dryRun,
header: defaultHeader,
infile: getChangelogPath(projectRoot),
/* Control version to avoid different results between the value
* returned by `tryBump` and the one computed by standard-version. */
releaseAs: newVersion,
silent: false,
noVerify,
packageFiles: [resolve(projectRoot, 'package.json')],
path: projectRoot,
preset,
tagPrefix,
skip: {
changelog: skipChangelog,
},
});
}