-
Notifications
You must be signed in to change notification settings - Fork 16
/
semantic-release.ts
67 lines (57 loc) · 1.7 KB
/
semantic-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
import { ExecutorContext } from '@nrwl/devkit';
import release from 'semantic-release';
import { setExecutorContext } from '../../config';
import { resolvePlugins } from './plugins';
import { getDefaultProjectRoot } from '../../common/project';
import { exec } from '../../utils/exec';
export type SemanticReleaseOptions = Omit<release.Options, 'extends'> & {
npm: boolean;
github: boolean;
buildTarget?: string;
changelog: boolean;
git: boolean;
changelogFile: string;
outputPath?: string;
commitMessage: string;
gitAssets?: string[];
packageJsonDir?: string;
parserOpts?: Record<string, unknown>;
writerOpts?: Record<string, unknown>
};
export async function semanticRelease(
options: SemanticReleaseOptions,
context: ExecutorContext
) {
const resolvedOptions = resolveOptions(options, context);
if (resolvedOptions.buildTarget) {
await exec(`npx nx run ${options.buildTarget}`, {
verbose: true,
});
}
setExecutorContext(context);
const plugins = resolvePlugins(resolvedOptions, context);
await release({
extends: '@theunderscorer/nx-semantic-release',
...resolvedOptions,
plugins,
});
return {
success: true,
};
}
const applyProjectRoot = (value: string, root: string) =>
value.replace('${PROJECT_DIR}', root);
const resolveOptions = (
options: SemanticReleaseOptions,
context: ExecutorContext
) => {
const root = getDefaultProjectRoot(context);
return {
...options,
changelogFile: applyProjectRoot(options.changelogFile, root),
tagFormat: options.tagFormat ?? `${context.projectName}-v\${version}`,
packageJsonDir: options.packageJsonDir
? applyProjectRoot(options.packageJsonDir, root)
: undefined,
};
};