163 |
return commits; |
return commits; |
164 |
} |
} |
165 |
|
|
166 |
|
function generateMarkdownChangelog(commits) { |
167 |
|
let output = "# Changelog\n\n"; |
168 |
|
|
169 |
|
const grouppedCommitsByDate = {}; |
170 |
|
|
171 |
|
for (const commit of commits) { |
172 |
|
const key = `${commit.createdAt |
173 |
|
.getUTCDate() |
174 |
|
.toString() |
175 |
|
.padStart(2, 0)}-${(commit.createdAt.getUTCMonth() + 1) |
176 |
|
.toString() |
177 |
|
.padStart(2, "0")}-${commit.createdAt.getUTCFullYear()}::${ |
178 |
|
Array.isArray(commit.author) |
179 |
|
? commit.author.join(":") |
180 |
|
: commit.author |
181 |
|
}`; |
182 |
|
grouppedCommitsByDate[key] ??= []; |
183 |
|
grouppedCommitsByDate[key].push(commit); |
184 |
|
} |
185 |
|
|
186 |
|
for (const key in grouppedCommitsByDate) { |
187 |
|
const [date, author] = key.split("::"); |
188 |
|
output += `### ${date} [${author}]\n\n`; |
189 |
|
|
190 |
|
for (const commit of grouppedCommitsByDate[key]) { |
191 |
|
const newLineIndex = commit.message.indexOf("\n"); |
192 |
|
output += `* ${commit.message.slice(0, newLineIndex === -1 ? undefined : newLineIndex)}\n`; |
193 |
|
} |
194 |
|
|
195 |
|
output += "\n"; |
196 |
|
} |
197 |
|
|
198 |
|
return output; |
199 |
|
} |
200 |
|
|
201 |
function generateChangelog(commits) { |
function generateChangelog(commits) { |
202 |
let output = ""; |
let output = ""; |
203 |
|
|
248 |
console.log("Options:"); |
console.log("Options:"); |
249 |
console.log(" -h, --help Show this help and exit."); |
console.log(" -h, --help Show this help and exit."); |
250 |
console.log(" -v, --version Show this script's version."); |
console.log(" -v, --version Show this script's version."); |
251 |
console.log(" -o, --output=[FILE] Write the generated changelog to"); |
console.log(" -f, --format= Set the changelog format."); |
252 |
|
console.log(" Supported formats are: plain,"); |
253 |
|
console.log(" markdown."); |
254 |
|
console.log(" -o, --output=<FILE> Write the generated changelog to"); |
255 |
console.log(" a file instead of standard output."); |
console.log(" a file instead of standard output."); |
256 |
console.log(" --no-overwrite Disallow overwriting of the output"); |
console.log(" --no-overwrite Disallow overwriting of the output"); |
257 |
console.log(" file if it exists already."); |
console.log(" file if it exists already."); |
297 |
"no-overwrite": { |
"no-overwrite": { |
298 |
type: "boolean", |
type: "boolean", |
299 |
}, |
}, |
300 |
|
format: { |
301 |
|
type: "string", |
302 |
|
short: "f" |
303 |
|
} |
304 |
}, |
}, |
305 |
}).values; |
}).values; |
306 |
} catch (error) { |
} catch (error) { |
318 |
exit(0); |
exit(0); |
319 |
} |
} |
320 |
|
|
321 |
|
if (options.format && !["markdown", "plain"].includes(options.format)) { |
322 |
|
perror("option `--format` or `-f` only accepts one of the following: markdown, plain"); |
323 |
|
exit(1); |
324 |
|
} |
325 |
|
|
326 |
if (!options.output && options["no-overwrite"]) { |
if (!options.output && options["no-overwrite"]) { |
327 |
perror( |
perror( |
328 |
"option `--no-overwrite' without `--output` does not make sense" |
"option `--no-overwrite' without `--output` does not make sense" |
348 |
commit.message |
commit.message |
349 |
) |
) |
350 |
); |
); |
351 |
const changelog = generateChangelog(filteredCommits); |
const changelog = options.format === "markdown" ? generateMarkdownChangelog(filteredCommits) : generateChangelog(filteredCommits); |
352 |
|
|
353 |
if (options.output) { |
if (options.output) { |
354 |
try { |
try { |