forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifyChangelogFileAndBumpVersion.ts
More file actions
84 lines (63 loc) · 4.07 KB
/
modifyChangelogFileAndBumpVersion.ts
File metadata and controls
84 lines (63 loc) · 4.07 KB
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
import {Changelog} from "../../changelog/changelogGenerator";
const fs = require('fs');
const path = require('path');
const todayDate = new Date();
const dd = String(todayDate.getDate()).padStart(2, '0');
const mm = String(todayDate.getMonth() + 1).padStart(2, '0'); //January is 0!
const yyyy = todayDate.getFullYear();
const date = yyyy + '-' + mm + '-' + dd;
export function makeChangesForFirstRelease(packageFolderPath: string, isStableRelease: boolean) {
const packageJsonData: any = JSON.parse(fs.readFileSync(path.join(packageFolderPath, 'package.json'), 'utf8'));
const newVersion = isStableRelease? '1.0.0' : '1.0.0-beta.1';
const content = `# Release History
## ${newVersion} (${date})
The package of ${packageJsonData.name} is using our next generation design principles. To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/js/mgmt/quickstart).
`;
fs.writeFileSync(path.join(packageFolderPath, 'CHANGELOG.md'), content, 'utf8');
changePackageJSON(packageFolderPath, newVersion);
changeClientFile(packageFolderPath, newVersion);
}
export function makeChangesForMigrateTrack1ToTrack2(packageFolderPath: string, nextPackageVersion: string) {
const packageJsonData: any = JSON.parse(fs.readFileSync(path.join(packageFolderPath, 'package.json'), 'utf8'));
const content = `# Release History
## ${nextPackageVersion} (${date})
The package of ${packageJsonData.name} is using our next generation design principles since version ${nextPackageVersion}, which contains breaking changes.
To understand the detail of the change, please refer to [Changelog](https://aka.ms/js-track2-changelog).
To migrate the existing applications to the latest version, please refer to [Migration Guide](https://aka.ms/js-track2-migration-guide).
To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/js/mgmt/quickstart).
`;
fs.writeFileSync(path.join(packageFolderPath, 'CHANGELOG.md'), content, 'utf8');
changePackageJSON(packageFolderPath, nextPackageVersion);
changeClientFile(packageFolderPath, nextPackageVersion)
}
function changePackageJSON(packageFolderPath: string, packageVersion: string) {
const data: string = fs.readFileSync(path.join(packageFolderPath, 'package.json'), 'utf8');
const result = data.replace(/"version": "[0-9.a-z-]+"/g, '"version": "' + packageVersion + '"');
fs.writeFileSync(path.join(packageFolderPath, 'package.json'), result, 'utf8');
}
function changeClientFile(packageFolderPath: string, packageVersion: string) {
const packageJsonData: any = JSON.parse(fs.readFileSync(path.join(packageFolderPath, 'package.json'), 'utf8'));
const packageName = packageJsonData.name.replace("@azure/", "");
const files: string[] = fs.readdirSync(path.join(packageFolderPath, 'src'));
files.forEach(file => {
if (file.endsWith('.ts')) {
const data: string = fs.readFileSync(path.join(packageFolderPath, 'src', file), 'utf8');
const result = data.replace(/const packageDetails = `azsdk-js-[0-9a-z-]+\/[0-9.a-z-]+`;/g, 'const packageDetails = `azsdk-js-' + packageName + '/' + packageVersion + '`;');
fs.writeFileSync(path.join(packageFolderPath, 'src', file), result, 'utf8');
}
})
}
export function makeChangesForReleasingTrack2(packageFolderPath: string, packageVersion: string, changeLog: Changelog, changeLogContent: string) {
const originalChangeLogContent = changeLogContent;
const modifiedChangelogContent = `# Release History
## ${packageVersion} (${date})
${changeLog.displayChangeLog()}
${originalChangeLogContent.replace(/.*Release History[\n\r]*/g, '')}`;
fs.writeFileSync(path.join(packageFolderPath, 'CHANGELOG.md'), modifiedChangelogContent, {encoding: 'utf-8'});
changePackageJSON(packageFolderPath, packageVersion);
changeClientFile(packageFolderPath, packageVersion);
}
export function makeChangesForPatchReleasingTrack2(packageFolderPath: string, packageVersion: string) {
changePackageJSON(packageFolderPath, packageVersion);
changeClientFile(packageFolderPath, packageVersion);
}