Skip to content

Commit

Permalink
feat: update changelog file
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt committed Jan 23, 2023
1 parent 53be9af commit 4fa3ca2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { promisify } = require('node:util');
const exec = promisify(require('node:child_process').exec);
const AggregateError = require('aggregate-error');

const { updateChangelog } = require('./lib/changelog');
const { verifyToken, uploadMod } = require('./lib/mod-portal.js');
const { isInfoValid, readInfoFile, updateInfo } = require('./lib/mod-info.js');

Expand Down Expand Up @@ -36,6 +37,7 @@ async function prepare(config, context) {

try {
await updateInfo(config, context);
await updateChangelog(config, context);
} catch (error) {
errors.push(error);
}
Expand Down
61 changes: 61 additions & 0 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { readFile, writeFile, access } = require('node:fs/promises');
const { join } = require('node:path');

const { getMiscError } = require('./get-error');


function getChangelogPath(config, context) {
return join(context.cwd, "./changelog.txt");
}

async function readChangelogFile(config, context) {
try {
return (await readFile(getChangelogPath(config, context), "utf-8")).toString();
} catch (error) {
throw getMiscError(error);
}
}

async function writeChangelogFile(config, context, changelog) {
try {
await writeFile(getChangelogPath(config, context), changelog);
} catch (error) {
throw getMiscError(error);
}
}

async function updateChangelog(config, context) {
const { logger, nextRelease: { notes } } = context;

if (notes) {
var changelogContent = notes.split("\n");

try {
await access(getChangelogPath(config, context));
logger.log("appending release notes to changelog.txt");

try {
changelogContent = [...changelogContent, ...(await readChangelogFile(config, context)).split("\n")];
} catch (error) {
throw getMiscError(error);
}
} catch {
logger.log("creating new changelog.txt");
}

changelogContent = changelogContent.filter(a => a.trim() != '');

try {
await writeChangelogFile(config, context, changelogContent.join("\n"));
} catch (error) {
throw getMiscError(error);
}
}
}

module.exports = {
getChangelogPath,
readChangelogFile,
writeChangelogFile,
updateChangelog
};

0 comments on commit 4fa3ca2

Please sign in to comment.