This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
forked from Azure/communication-ui-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog.mjs
46 lines (38 loc) · 1.83 KB
/
changelog.mjs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* A helper module to generate CHANGELOG files without bumping packlet versions.
* This module is a workaround because beachball doesn't expose changelog command currently.
* Upstream feature request: https://github.com/microsoft/beachball/issues/650
*
* This module is not a script entry-point. See ./collect.mjs for the script that uses this module.
*/
import { getPackageInfos } from '../../config/node_modules/beachball/lib/monorepo/getPackageInfos.js';
import {gatherBumpInfo} from '../../config/node_modules/beachball/lib/bump/gatherBumpInfo.js';
import {performBump} from '../../config/node_modules/beachball/lib/bump/performBump.js';
import { getOptions } from '../../config/node_modules/beachball/lib/options/getOptions.js';
import { CHANGE_DIR } from './constants.mjs';
import fs from 'fs';
export async function generateChangelogs() {
const options = getOptions([]);
const packageInfos = getPackageInfos(options.path);
// Preserve(deep clone) the current packageInfo before bump, we don't change version number using beachball
const preservedPackages = Object.fromEntries(Object.entries(packageInfos).map(([name, info]) => ([name, clone(info)])));
const bumpInfo = gatherBumpInfo(options, packageInfos);
// Restore packageInfo so no bump to versions by beachball
for (const name in bumpInfo.packageInfos) {
bumpInfo.packageInfos[name] = preservedPackages[name];
}
await performBump(bumpInfo, options);
// Beachball deletes the change file directory which causes confusion for scripts
// that manipulate working directory paths.
ensureDirectory(CHANGE_DIR);
}
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
function ensureDirectory(dir) {
if (!fs.statSync(dir, {throwIfNoEntry: false})) {
fs.mkdirSync(dir);
}
}