|
@@ -0,0 +1,94 @@
|
|
1
|
+const fs = require("fs");
|
|
2
|
+const util = require("util");
|
|
3
|
+const exec = util.promisify(require("child_process").exec);
|
|
4
|
+
|
|
5
|
+const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
|
6
|
+const excalidrawPackage = `${excalidrawDir}/package.json`;
|
|
7
|
+const pkg = require(excalidrawPackage);
|
|
8
|
+const lastVersion = pkg.version;
|
|
9
|
+const existingChangeLog = fs.readFileSync(
|
|
10
|
+ `${excalidrawDir}/CHANGELOG.md`,
|
|
11
|
+ "utf8",
|
|
12
|
+);
|
|
13
|
+
|
|
14
|
+const supportedTypes = ["feat", "fix", "style", "refactor", "perf", "build"];
|
|
15
|
+const headerForType = {
|
|
16
|
+ feat: "Features",
|
|
17
|
+ fix: "Fixes",
|
|
18
|
+ style: "Styles",
|
|
19
|
+ refactor: " Refactor",
|
|
20
|
+ perf: "Performance",
|
|
21
|
+ build: "Build",
|
|
22
|
+};
|
|
23
|
+
|
|
24
|
+const getCommitHashForLastVersion = async () => {
|
|
25
|
+ try {
|
|
26
|
+ const commitMessage = `"release @excalidraw/excalidraw@${lastVersion}"`;
|
|
27
|
+ const { stdout } = await exec(
|
|
28
|
+ `git log --format=format:"%H" --grep=${commitMessage}`,
|
|
29
|
+ );
|
|
30
|
+ return stdout;
|
|
31
|
+ } catch (e) {
|
|
32
|
+ console.error(e);
|
|
33
|
+ }
|
|
34
|
+};
|
|
35
|
+
|
|
36
|
+const getLibraryCommitsSinceLastRelease = async () => {
|
|
37
|
+ const commitHash = await getCommitHashForLastVersion();
|
|
38
|
+ const { stdout } = await exec(
|
|
39
|
+ `git log --pretty=format:%s ${commitHash}...master`,
|
|
40
|
+ );
|
|
41
|
+ const commitsSinceLastRelease = stdout.split("\n");
|
|
42
|
+ const commitList = {};
|
|
43
|
+ supportedTypes.forEach((type) => {
|
|
44
|
+ commitList[type] = [];
|
|
45
|
+ });
|
|
46
|
+
|
|
47
|
+ commitsSinceLastRelease.forEach((commit) => {
|
|
48
|
+ const indexOfColon = commit.indexOf(":");
|
|
49
|
+ const type = commit.slice(0, indexOfColon);
|
|
50
|
+ if (!supportedTypes.includes(type)) {
|
|
51
|
+ return;
|
|
52
|
+ }
|
|
53
|
+ const messageWithoutType = commit.slice(indexOfColon + 1).trim();
|
|
54
|
+ const messageWithCapitalizeFirst =
|
|
55
|
+ messageWithoutType.charAt(0).toUpperCase() + messageWithoutType.slice(1);
|
|
56
|
+ const prNumber = commit.match(/\(#([0-9]*)\)/)[1];
|
|
57
|
+
|
|
58
|
+ // return if the changelog already contains the pr number which would happen for package updates
|
|
59
|
+ if (existingChangeLog.includes(prNumber)) {
|
|
60
|
+ return;
|
|
61
|
+ }
|
|
62
|
+ const prMarkdown = `[#${prNumber}](https://github.com/excalidraw/excalidraw/pull/${prNumber})`;
|
|
63
|
+ const messageWithPRLink = messageWithCapitalizeFirst.replace(
|
|
64
|
+ /\(#[0-9]*\)/,
|
|
65
|
+ prMarkdown,
|
|
66
|
+ );
|
|
67
|
+ commitList[type].push(messageWithPRLink);
|
|
68
|
+ });
|
|
69
|
+ return commitList;
|
|
70
|
+};
|
|
71
|
+
|
|
72
|
+const updateChangelog = async () => {
|
|
73
|
+ const commitList = await getLibraryCommitsSinceLastRelease();
|
|
74
|
+ let changelogForLibrary =
|
|
75
|
+ "## Excalidraw Library\n\n**_This section lists the updates made to the excalidraw library and will not affect the integration._**\n\n";
|
|
76
|
+ supportedTypes.forEach((type) => {
|
|
77
|
+ if (commitList[type].length) {
|
|
78
|
+ changelogForLibrary += `### ${headerForType[type]}\n\n`;
|
|
79
|
+ const commits = commitList[type];
|
|
80
|
+ commits.forEach((commit) => {
|
|
81
|
+ changelogForLibrary += `- ${commit}\n\n`;
|
|
82
|
+ });
|
|
83
|
+ }
|
|
84
|
+ });
|
|
85
|
+ changelogForLibrary += "---\n";
|
|
86
|
+ const lastVersionIndex = existingChangeLog.indexOf(`## ${lastVersion}`);
|
|
87
|
+ const updatedContent =
|
|
88
|
+ existingChangeLog.slice(0, lastVersionIndex) +
|
|
89
|
+ changelogForLibrary +
|
|
90
|
+ existingChangeLog.slice(lastVersionIndex + 1);
|
|
91
|
+ fs.writeFileSync(`${excalidrawDir}/CHANGELOG.md`, updatedContent, "utf8");
|
|
92
|
+};
|
|
93
|
+
|
|
94
|
+updateChangelog();
|