saturn-core-cli 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/changelog.js +26 -10
- package/package.json +1 -1
package/lib/changelog.js
CHANGED
|
@@ -20,24 +20,26 @@ async function tagExists(tag) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async function resolveBaseTag(previousVersion) {
|
|
23
|
+
async function resolveBaseTag(previousVersion, head) {
|
|
24
24
|
if (previousVersion && (await tagExists(previousVersion))) {
|
|
25
25
|
return previousVersion;
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
|
-
|
|
28
|
+
// HEAD is not tagged yet while publishing; a past tag has to look behind itself.
|
|
29
|
+
let from = head === "HEAD" ? "HEAD" : `${head}^`;
|
|
30
|
+
return (await git(["describe", "--tags", "--abbrev=0", from])).trim();
|
|
29
31
|
} catch (e) {
|
|
30
32
|
return null;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
async function readCommits(base) {
|
|
36
|
+
async function readCommits(base, head) {
|
|
35
37
|
let output = await git([
|
|
36
38
|
"log",
|
|
37
39
|
"--no-merges",
|
|
38
40
|
"--reverse",
|
|
39
41
|
"--format=%h%x1f%s%x1f%b%x1e",
|
|
40
|
-
`${base}
|
|
42
|
+
`${base}..${head}`,
|
|
41
43
|
]);
|
|
42
44
|
return output
|
|
43
45
|
.split("\x1e")
|
|
@@ -71,25 +73,39 @@ async function uncommittedFiles() {
|
|
|
71
73
|
.filter((file) => file !== "package.json");
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
// `sc publish` commits whatever is uncommitted as "SC Publish"; for a past tag, list what that
|
|
77
|
+
// commit swept in.
|
|
78
|
+
async function publishCommitFiles(tag) {
|
|
79
|
+
let subject = (await git(["log", "-1", "--format=%s", tag])).trim();
|
|
80
|
+
if (!PUBLISH_SUBJECT.test(subject)) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
let output = await git(["diff-tree", "--no-commit-id", "--name-only", "-r", tag]);
|
|
84
|
+
return output
|
|
85
|
+
.split("\n")
|
|
86
|
+
.filter((file) => file.trim() && file !== "package.json");
|
|
87
|
+
}
|
|
88
|
+
|
|
74
89
|
function formatUncommitted(files) {
|
|
75
90
|
let listed = files.slice(0, MAX_LISTED_FILES).join(", ");
|
|
76
91
|
let more = files.length > MAX_LISTED_FILES ? ` +${files.length - MAX_LISTED_FILES} more` : "";
|
|
77
|
-
return `-
|
|
92
|
+
return `- Changed without a commit message: ${listed}${more}`;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
/**
|
|
81
96
|
* Builds markdown release notes from the commits since the previous published tag, for the
|
|
82
|
-
* Saturn Instance description. Returns "" when there is no tag to compare against.
|
|
97
|
+
* Saturn Instance description. Returns "" when there is no tag to compare against. Pass `head`
|
|
98
|
+
* (a tag) to build the notes of an already published version instead of the working tree.
|
|
83
99
|
*/
|
|
84
|
-
async function buildChangelog(previousVersion) {
|
|
85
|
-
let base = await resolveBaseTag(previousVersion);
|
|
100
|
+
async function buildChangelog(previousVersion, { head = "HEAD" } = {}) {
|
|
101
|
+
let base = await resolveBaseTag(previousVersion, head);
|
|
86
102
|
if (!base) {
|
|
87
103
|
console.log("No previous git tag found, skipping changelog");
|
|
88
104
|
return "";
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
let entries = (await readCommits(base)).map(formatCommit);
|
|
92
|
-
let files = await uncommittedFiles();
|
|
107
|
+
let entries = (await readCommits(base, head)).map(formatCommit);
|
|
108
|
+
let files = head === "HEAD" ? await uncommittedFiles() : await publishCommitFiles(head);
|
|
93
109
|
if (files.length) {
|
|
94
110
|
entries.push(formatUncommitted(files));
|
|
95
111
|
}
|